[mutter] events: Move keybindings event handling out of the giant switch



commit bbfdf5dd2ae47fd71452a058d8a33861d01d7078
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu May 8 14:53:50 2014 -0400

    events: Move keybindings event handling out of the giant switch

 src/core/events.c              |   28 ++++++++++-----------
 src/core/keybindings-private.h |    6 ++--
 src/core/keybindings.c         |   52 ++++++++++++++++++++++++++--------------
 3 files changed, 50 insertions(+), 36 deletions(-)
---
diff --git a/src/core/events.c b/src/core/events.c
index d97abaa..4424386 100644
--- a/src/core/events.c
+++ b/src/core/events.c
@@ -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;
     }
diff --git a/src/core/keybindings-private.h b/src/core/keybindings-private.h
index 01d619a..1e6816f 100644
--- a/src/core/keybindings-private.h
+++ b/src/core/keybindings-private.h
@@ -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,
-                                             MetaWindow      *window,
-                                             ClutterKeyEvent *event);
+gboolean meta_keybindings_process_event     (MetaDisplay        *display,
+                                             MetaWindow         *window,
+                                             const ClutterEvent *event);
 void     meta_display_process_mapping_event (MetaDisplay *display,
                                              XEvent      *event);
 
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 19c187c..751a244 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -1738,24 +1738,10 @@ 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,
-                                MetaWindow      *window,
-                                ClutterKeyEvent *event)
+static gboolean
+process_key_event (MetaDisplay     *display,
+                   MetaWindow      *window,
+                   ClutterKeyEvent *event)
 {
   gboolean keep_grab;
   gboolean all_keys_grabbed;
@@ -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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]