[mutter/wip/keymap: 1/2] keybindings: Rewrite the modmap code so that it uses libxkbcommon



commit 550ee1f66a6d993ca39e813d63964a6e7f28576d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Aug 15 16:23:15 2014 -0400

    keybindings: Rewrite the modmap code so that it uses libxkbcommon
    
    This removes our Xwayland dependency in the native path. The direct
    grabs are still there for the X11 backend and are a bit disgusting,
    but that's OK. We can refactor it out later.

 src/core/keybindings-private.h |    9 ++--
 src/core/keybindings.c         |   94 ++++++++++-----------------------------
 2 files changed, 29 insertions(+), 74 deletions(-)
---
diff --git a/src/core/keybindings-private.h b/src/core/keybindings-private.h
index 9c84285..65204f5 100644
--- a/src/core/keybindings-private.h
+++ b/src/core/keybindings-private.h
@@ -29,6 +29,7 @@
 
 #include <gio/gio.h>
 #include <meta/keybindings.h>
+#include <xkbcommon/xkbcommon.h>
 
 typedef struct _MetaKeyHandler MetaKeyHandler;
 struct _MetaKeyHandler
@@ -100,10 +101,10 @@ typedef struct
   int             max_keycode;
   KeySym *keymap;
   int keysyms_per_keycode;
-  unsigned int ignored_modifier_mask;
-  unsigned int hyper_mask;
-  unsigned int super_mask;
-  unsigned int meta_mask;
+  xkb_mod_mask_t ignored_modifier_mask;
+  xkb_mod_mask_t hyper_mask;
+  xkb_mod_mask_t super_mask;
+  xkb_mod_mask_t meta_mask;
   MetaKeyCombo overlay_key_combo;
   gboolean overlay_key_only_pressed;
   MetaKeyCombo *iso_next_group_combos;
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 6c74635..3f31d55 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -49,8 +49,6 @@
 
 #include <linux/input.h>
 
-#include <xkbcommon/xkbcommon.h>
-
 #include <X11/XKBlib.h>
 
 #include "backends/x11/meta-backend-x11.h"
@@ -204,73 +202,31 @@ keysym_name (xkb_keysym_t keysym)
 static void
 reload_modmap (MetaKeyBindingManager *keys)
 {
-  XModifierKeymap *modmap;
-  int map_size;
-  int i;
-  int scroll_lock_mask = 0;
-
-  modmap = XGetModifierMapping (keys->xdisplay);
-  keys->ignored_modifier_mask = 0;
-
-  /* Multiple bits may get set in each of these */
-  keys->meta_mask = 0;
-  keys->hyper_mask = 0;
-  keys->super_mask = 0;
-
-  /* there are 8 modifiers, and the first 3 are shift, shift lock,
-   * and control
-   */
-  map_size = 8 * modmap->max_keypermod;
-  i = 3 * modmap->max_keypermod;
-  while (i < map_size)
+  MetaBackend *backend = meta_get_backend ();
+  struct xkb_keymap *keymap = meta_backend_get_keymap (backend);
+  xkb_mod_mask_t scroll_lock_mask;
+
+  /* Modifiers to find. */
+  struct {
+    char *name;
+    xkb_mod_mask_t *mask_p;
+  } mods[] = {
+    { "ScrollLock", &scroll_lock_mask },
+    { "Meta",       &keys->meta_mask },
+    { "Hyper",      &keys->hyper_mask },
+    { "Super",      &keys->super_mask },
+  };
+
+  gsize i;
+  for (i = 0; i < G_N_ELEMENTS (mods); i++)
     {
-      /* get the key code at this point in the map,
-       * see if its keysym is one we're interested in
-       */
-      int keycode = modmap->modifiermap[i];
-
-      if (keycode >= keys->min_keycode &&
-          keycode <= keys->max_keycode)
-        {
-          int j = 0;
-          KeySym *syms = keys->keymap +
-            (keycode - keys->min_keycode) * keys->keysyms_per_keycode;
+      xkb_mod_mask_t *mask_p = mods[i].mask_p;
+      xkb_mod_index_t idx = xkb_keymap_mod_get_index (keymap, mods[i].name);
 
-          while (j < keys->keysyms_per_keycode)
-            {
-              if (syms[j] != 0)
-                {
-                  meta_topic (META_DEBUG_KEYBINDINGS,
-                              "Keysym %s bound to modifier 0x%x\n",
-                              keysym_name (syms[j]),
-                              (1 << ( i / modmap->max_keypermod)));
-                }
-
-              if (syms[j] == XKB_KEY_Scroll_Lock)
-                {
-                  scroll_lock_mask |= (1 << ( i / modmap->max_keypermod));
-                }
-              else if (syms[j] == XKB_KEY_Super_L ||
-                       syms[j] == XKB_KEY_Super_R)
-                {
-                  keys->super_mask |= (1 << ( i / modmap->max_keypermod));
-                }
-              else if (syms[j] == XKB_KEY_Hyper_L ||
-                       syms[j] == XKB_KEY_Hyper_R)
-                {
-                  keys->hyper_mask |= (1 << ( i / modmap->max_keypermod));
-                }
-              else if (syms[j] == XKB_KEY_Meta_L ||
-                       syms[j] == XKB_KEY_Meta_R)
-                {
-                  keys->meta_mask |= (1 << ( i / modmap->max_keypermod));
-                }
-
-              ++j;
-            }
-        }
-
-      ++i;
+      if (idx != XKB_MOD_INVALID)
+        *mask_p = xkb_keymap_mod_get_mask (keymap, idx);
+      else
+        *mask_p = 0;
     }
 
   keys->ignored_modifier_mask = (scroll_lock_mask | Mod2Mask | LockMask);
@@ -282,8 +238,6 @@ reload_modmap (MetaKeyBindingManager *keys)
               keys->hyper_mask,
               keys->super_mask,
               keys->meta_mask);
-
-  XFreeModifiermap (modmap);
 }
 
 /* Original code from gdk_x11_keymap_get_entries_for_keyval() in


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