events: Move keybindings event handling out of the giant switch

This commit is contained in:
Jasper St. Pierre 2014-05-08 14:53:50 -04:00
parent 9b95eda42a
commit bbfdf5dd2a
3 changed files with 50 additions and 36 deletions

View File

@ -1927,6 +1927,19 @@ meta_display_handle_event (MetaDisplay *display,
}
}
/* For key events, it's important to enforce single-handling, or
* we can get into a confused state. So if a keybinding is
* handled (because it's one of our hot-keys, or because we are
* in a keyboard-grabbed mode like moving a window, we don't
* want to pass the key event to the compositor or Wayland at all.
*/
if (meta_keybindings_process_event (display, window, event))
{
bypass_clutter = TRUE;
bypass_wayland = TRUE;
goto out;
}
switch (event->type)
{
case CLUTTER_BUTTON_PRESS:
@ -2098,21 +2111,6 @@ meta_display_handle_event (MetaDisplay *display,
display->overlay_key_only_pressed = FALSE;
break;
case CLUTTER_KEY_PRESS:
case CLUTTER_KEY_RELEASE:
/* For key events, it's important to enforce single-handling, or
* we can get into a confused state. So if a keybinding is
* handled (because it's one of our hot-keys, or because we are
* in a keyboard-grabbed mode like moving a window, we don't
* want to pass the key event to the compositor or Wayland at all.
*/
if (meta_display_process_key_event (display, window, (ClutterKeyEvent *) event))
{
bypass_clutter = TRUE;
bypass_wayland = TRUE;
}
break;
default:
break;
}

View File

@ -100,9 +100,9 @@ gboolean meta_window_grab_all_keys (MetaWindow *window,
guint32 timestamp);
void meta_window_ungrab_all_keys (MetaWindow *window,
guint32 timestamp);
gboolean meta_display_process_key_event (MetaDisplay *display,
gboolean meta_keybindings_process_event (MetaDisplay *display,
MetaWindow *window,
ClutterKeyEvent *event);
const ClutterEvent *event);
void meta_display_process_mapping_event (MetaDisplay *display,
XEvent *event);

View File

@ -1738,22 +1738,8 @@ process_iso_next_group (MetaDisplay *display,
return activate;
}
/* Handle a key event. May be called recursively: some key events cause
* grabs to be ended and then need to be processed again in their own
* right. This cannot cause infinite recursion because we never call
* ourselves when there wasn't a grab, and we always clear the grab
* first; the invariant is enforced using an assertion. See #112560.
*
* The return value is whether we handled the key event.
*
* FIXME: We need to prove there are no race conditions here.
* FIXME: Does it correctly handle alt-Tab being followed by another
* grabbing keypress without letting go of alt?
* FIXME: An iterative solution would probably be simpler to understand
* (and help us solve the other fixmes).
*/
gboolean
meta_display_process_key_event (MetaDisplay *display,
static gboolean
process_key_event (MetaDisplay *display,
MetaWindow *window,
ClutterKeyEvent *event)
{
@ -1853,6 +1839,36 @@ meta_display_process_key_event (MetaDisplay *display,
return process_event (display, screen, window, event);
}
/* Handle a key event. May be called recursively: some key events cause
* grabs to be ended and then need to be processed again in their own
* right. This cannot cause infinite recursion because we never call
* ourselves when there wasn't a grab, and we always clear the grab
* first; the invariant is enforced using an assertion. See #112560.
*
* The return value is whether we handled the key event.
*
* FIXME: We need to prove there are no race conditions here.
* FIXME: Does it correctly handle alt-Tab being followed by another
* grabbing keypress without letting go of alt?
* FIXME: An iterative solution would probably be simpler to understand
* (and help us solve the other fixmes).
*/
gboolean
meta_keybindings_process_event (MetaDisplay *display,
MetaWindow *window,
const ClutterEvent *event)
{
switch (event->type)
{
case CLUTTER_KEY_PRESS:
case CLUTTER_KEY_RELEASE:
return process_key_event (display, window, (ClutterKeyEvent *) event);
default:
return FALSE;
}
}
static gboolean
process_mouse_move_resize_grab (MetaDisplay *display,
MetaScreen *screen,