[mutter/wip/carlosg/locate-pointer-in-other-keybindings: 2/2] keybindings: Check the special modifiers specifically



commit 3213d92e2813401dee41d444faed6a5f395e074d
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Mar 12 19:43:15 2020 +0100

    keybindings: Check the special modifiers specifically
    
    Make it sure it is only the special modifier (optimized to 1 currently)
    which is being pressed before notifying that the special modifier is
    pressed, as we are interested on it being pressed alone and not in
    combination with other modifiers.
    
    This helps in two ways:
    - Pressing alt, then ctrl, then releasing both won't trigger the locate
      pointer action.
    - Pressing alt, then ctrl, then down/up to switch workspace won't interpret
      the last up/down keypress as an additional key on top of the special ctrl
      modifier, thus won't be forwarded down to the focused client in the last
      second.
    
    Closes: https://gitlab.gnome.org/GNOME/mutter/issues/812
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1014

 src/core/keybindings.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 2cf705598..938b4f968 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -63,6 +63,15 @@
 #define META_KEY_BINDING_PRIMARY_LAYOUT 0
 #define META_KEY_BINDING_SECONDARY_LAYOUT 1
 
+/* Only for special modifier keys */
+#define IGNORED_MODIFIERS (CLUTTER_LOCK_MASK |          \
+                           CLUTTER_MOD2_MASK |          \
+                           CLUTTER_BUTTON1_MASK |       \
+                           CLUTTER_BUTTON2_MASK |       \
+                           CLUTTER_BUTTON3_MASK |       \
+                           CLUTTER_BUTTON4_MASK |       \
+                           CLUTTER_BUTTON5_MASK)
+
 static gboolean add_builtin_keybinding (MetaDisplay          *display,
                                         const char           *name,
                                         GSettings            *settings,
@@ -101,6 +110,16 @@ resolved_key_combo_has_keycode (MetaResolvedKeyCombo *resolved_combo,
   return FALSE;
 }
 
+static gboolean
+resolved_key_combo_is_keycode (MetaResolvedKeyCombo *resolved_combo,
+                               int                   keycode)
+{
+  if (resolved_combo->len != 1)
+    return FALSE;
+
+  return resolved_combo->keycodes[0] == keycode;
+}
+
 static gboolean
 resolved_key_combo_intersect (MetaResolvedKeyCombo *a,
                               MetaResolvedKeyCombo *b)
@@ -2120,8 +2139,9 @@ process_special_modifier_key (MetaDisplay          *display,
       return TRUE;
     }
   else if (event->type == CLUTTER_KEY_PRESS &&
-           resolved_key_combo_has_keycode (resolved_key_combo,
-                                           event->hardware_keycode))
+           (event->modifier_state & ~(IGNORED_MODIFIERS)) == 0 &&
+           resolved_key_combo_is_keycode (resolved_key_combo,
+                                          event->hardware_keycode))
     {
       *modifier_press_only = TRUE;
       /* We keep the keyboard frozen - this allows us to use ReplayKeyboard


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