[mutter/wayland] keybindings: Eliminate the use of the stored modmap



commit 15cf804dbcb9978d76c548c91d70dda871dad0df
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Apr 7 15:41:37 2014 -0400

    keybindings: Eliminate the use of the stored modmap
    
    We can simply check the XKB keysym here to see if it's a modifier.

 src/core/display-private.h |    1 -
 src/core/keybindings.c     |   59 ++++++++++++++++++++-----------------------
 2 files changed, 27 insertions(+), 33 deletions(-)
---
diff --git a/src/core/display-private.h b/src/core/display-private.h
index 0d9524b..c46bafe 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -230,7 +230,6 @@ struct _MetaDisplay
   int             max_keycode;
   KeySym *keymap;
   int keysyms_per_keycode;
-  XModifierKeymap *modmap;
   unsigned int above_tab_keycode;
   unsigned int ignored_modifier_mask;
   unsigned int hyper_mask;
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index a59f996..cbe893d 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -48,6 +48,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <xkbcommon/xkbcommon.h>
+
 #ifdef HAVE_XKB
 #include <X11/XKBlib.h>
 #endif
@@ -203,12 +205,7 @@ reload_modmap (MetaDisplay *display)
   int num_lock_mask = 0;
   int scroll_lock_mask = 0;
 
-  if (display->modmap)
-    XFreeModifiermap (display->modmap);
-
   modmap = XGetModifierMapping (display->xdisplay);
-  display->modmap = modmap;
-
   display->ignored_modifier_mask = 0;
 
   /* Multiple bits may get set in each of these */
@@ -296,6 +293,8 @@ reload_modmap (MetaDisplay *display)
               display->hyper_mask,
               display->super_mask,
               display->meta_mask);
+
+  XFreeModifiermap (modmap);
 }
 
 /* Original code from gdk_x11_keymap_get_entries_for_keyval() in
@@ -1017,9 +1016,6 @@ meta_display_shutdown_keys (MetaDisplay *display)
   if (display->keymap)
     meta_XFree (display->keymap);
 
-  if (display->modmap)
-    XFreeModifiermap (display->modmap);
-
   g_hash_table_destroy (display->key_bindings_index);
   g_hash_table_destroy (display->key_bindings);
 }
@@ -1610,28 +1606,28 @@ meta_display_unfreeze_keyboard (MetaDisplay *display, guint32 timestamp)
 }
 
 static gboolean
-is_modifier (MetaDisplay *display,
-             unsigned int keycode)
-{
-  int i;
-  int map_size;
-  gboolean retval = FALSE;
-
-  g_assert (display->modmap);
-
-  map_size = 8 * display->modmap->max_keypermod;
-  i = 0;
-  while (i < map_size)
-    {
-      if (keycode == display->modmap->modifiermap[i])
-        {
-          retval = TRUE;
-          break;
-        }
-      ++i;
+is_modifier (xkb_keysym_t keysym)
+{
+  switch (keysym)
+    {
+    case XKB_KEY_Shift_L:
+    case XKB_KEY_Shift_R:
+    case XKB_KEY_Control_L:
+    case XKB_KEY_Control_R:
+    case XKB_KEY_Caps_Lock:
+    case XKB_KEY_Shift_Lock:
+    case XKB_KEY_Meta_L:
+    case XKB_KEY_Meta_R:
+    case XKB_KEY_Alt_L:
+    case XKB_KEY_Alt_R:
+    case XKB_KEY_Super_L:
+    case XKB_KEY_Super_R:
+    case XKB_KEY_Hyper_L:
+    case XKB_KEY_Hyper_R:
+      return TRUE;
+    default:
+      return FALSE;
     }
-
-  return retval;
 }
 
 static void
@@ -2009,7 +2005,7 @@ process_keyboard_move_grab (MetaDisplay     *display,
     return TRUE;
 
   /* don't end grab on modifier key presses */
-  if (is_modifier (display, event->hardware_keycode))
+  if (is_modifier (event->keyval))
     return TRUE;
 
   meta_window_get_position (window, &x, &y);
@@ -2251,7 +2247,7 @@ process_keyboard_resize_grab (MetaDisplay     *display,
     return TRUE;
 
   /* don't end grab on modifier key presses */
-  if (is_modifier (display, event->hardware_keycode))
+  if (is_modifier (event->keyval))
     return TRUE;
 
   if (event->keyval == CLUTTER_KEY_Escape)
@@ -3909,7 +3905,6 @@ meta_display_init_keys (MetaDisplay *display)
   /* Keybindings */
   display->keymap = NULL;
   display->keysyms_per_keycode = 0;
-  display->modmap = NULL;
   display->min_keycode = 0;
   display->max_keycode = 0;
   display->ignored_modifier_mask = 0;


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