]> Dogcows Code - chaz/openbox/commitdiff
get the modifier mask for a modifier key that is pressed/released more accurately...
authorDana Jansens <danakj@orodu.net>
Fri, 19 Feb 2010 21:58:33 +0000 (16:58 -0500)
committerDana Jansens <danakj@orodu.net>
Fri, 19 Feb 2010 21:59:28 +0000 (16:59 -0500)
obt/keyboard.c
obt/keyboard.h
openbox/actions/cyclewindows.c
openbox/actions/desktop.c
openbox/actions/directionalwindows.c

index 2d3a0553d7a864e9a8c55bf130b110961e72e106..30aa7f9366ea8abffe468183337624809f877abc 100644 (file)
@@ -191,23 +191,40 @@ void xim_init(void)
     g_free(aname);
 }
 
-guint obt_keyboard_keycode_to_modmask(guint keycode)
+ObtModkeysKey obt_keyboard_keyevent_to_modkey(XEvent *e)
 {
-    gint i, j;
-    guint mask = 0;
-
-    if (keycode == NoSymbol) return 0;
+    KeySym sym;
 
-    /* go through each of the modifier masks (eg ShiftMask, CapsMask...) */
-    for (i = 0; i < NUM_MASKS; ++i) {
-        /* go through each keycode that is bound to the mask */
-        for (j = 0; j < modmap->max_keypermod; ++j) {
-            /* compare with a keycode that is bound to the mask (i) */
-            if (modmap->modifiermap[i*modmap->max_keypermod + j] == keycode)
-                mask |= nth_mask(i);
-        }
+    g_return_val_if_fail(e->type == KeyPress || e->type == KeyRelease,
+                         OBT_KEYBOARD_MODKEY_NONE);
+
+    XLookupString(&e->xkey, NULL, 0, &sym, NULL);
+
+    switch (sym) {
+    case XK_Num_Lock: return OBT_KEYBOARD_MODKEY_NUMLOCK;
+    case XK_Scroll_Lock: return OBT_KEYBOARD_MODKEY_SCROLLLOCK;
+    case XK_Caps_Lock: return OBT_KEYBOARD_MODKEY_SHIFT;
+    case XK_Alt_L:
+    case XK_Alt_R: return OBT_KEYBOARD_MODKEY_ALT;
+    case XK_Super_L:
+    case XK_Super_R: return OBT_KEYBOARD_MODKEY_SUPER;
+    case XK_Hyper_L:
+    case XK_Hyper_R: return OBT_KEYBOARD_MODKEY_SUPER;
+    case XK_Meta_L:
+    case XK_Meta_R: return OBT_KEYBOARD_MODKEY_SUPER;
+    case XK_Control_L:
+    case XK_Control_R: return OBT_KEYBOARD_MODKEY_CONTROL;
+    case XK_Shift_L:
+    case XK_Shift_R: return OBT_KEYBOARD_MODKEY_SHIFT;
+    default: return OBT_KEYBOARD_MODKEY_NONE;
     }
-    return mask;
+}
+
+guint obt_keyboard_keyevent_to_modmask(XEvent *e)
+{
+    g_return_val_if_fail(e->type == KeyPress || e->type == KeyRelease, 0);
+
+    return obt_keyboard_modkey_to_modmask(obt_keyboard_keyevent_to_modkey(e));
 }
 
 guint obt_keyboard_only_modmasks(guint mask)
index 143921ff2fa927e667d40aa5792a32d08e9e6ad8..868cccf48d9922afbbc69fbb6c6723de609ceccf 100644 (file)
@@ -28,6 +28,7 @@ G_BEGIN_DECLS
 /*! These keys are bound to the modifier masks in any fashion,
   except for CapsLock, Shift, and Control. */
 typedef enum {
+    OBT_KEYBOARD_MODKEY_NONE,
     OBT_KEYBOARD_MODKEY_CAPSLOCK,
     OBT_KEYBOARD_MODKEY_NUMLOCK,
     OBT_KEYBOARD_MODKEY_SCROLLLOCK,
@@ -45,9 +46,10 @@ typedef struct _ObtIC ObtIC;
 
 void obt_keyboard_reload(void);
 
-/*! Get the modifier mask(s) for a KeyCode. (eg. a keycode bound to Alt_L could
-  return a mask of (Mod1Mask | Mask3Mask)) */
-guint obt_keyboard_keycode_to_modmask(guint keycode);
+/*! Get the modifier mask(s) for a keyboard event.
+  (eg. a keycode bound to Alt_L could return a mask of (Mod1Mask | Mask3Mask))
+*/
+guint obt_keyboard_keyevent_to_modmask(XEvent *e);
 
 /*! Strip off all modifiers except for the modifier keys. This strips stuff
   like Button1Mask, and also LockMask, NumlockMask, and ScrolllockMask */
@@ -57,6 +59,9 @@ guint obt_keyboard_only_modmasks(guint mask);
   right keys when there are both. */
 guint obt_keyboard_modkey_to_modmask(ObtModkeysKey key);
 
+/*! Get the modifier key which was pressed or released in a keyboard event */
+ObtModkeysKey obt_keyboard_keyevent_to_modkey(XEvent *e);
+
 /*! Convert a KeySym to all the KeyCodes which generate it. */
 KeyCode* obt_keyboard_keysym_to_keycode(KeySym sym);
 
index a038f31aaac29f876d013525327f08cdf870b881..6d852fdf8418ceafa65cc1cd06595e1f8d103074 100644 (file)
@@ -181,7 +181,7 @@ static gboolean i_input_func(guint initial_state,
     if (e->type == KeyRelease) {
         /* remove from the state the mask of the modifier key being
            released, if it is a modifier key being released that is */
-        mods &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);
+        mods &= ~obt_keyboard_keyevent_to_modmask(e);
     }
 
     if (e->type == KeyPress) {
index 10b31acd535c9fc6b086e106a8a007a312333b71..cc0d96538cba42ff7b41ffa56aa85fb8350df9a5 100644 (file)
@@ -316,7 +316,7 @@ static gboolean i_input_func(guint initial_state,
     if (e->type == KeyRelease) {
         /* remove from the state the mask of the modifier key being
            released, if it is a modifier key being released that is */
-        mods &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);
+        mods &= ~obt_keyboard_keyevent_to_modmask(e);
     }
 
     if (e->type == KeyPress) {
index f8393d2d9b035ca074b95440a32a8f0e70a63e1d..d67c3ef4466d6174c83f1dd7f26c01a119a19dfe 100644 (file)
@@ -265,7 +265,7 @@ static gboolean i_input_func(guint initial_state,
     if (e->type == KeyRelease) {
         /* remove from the state the mask of the modifier key being
            released, if it is a modifier key being released that is */
-        mods &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);
+        mods &= ~obt_keyboard_keyevent_to_modmask(e);
     }
 
     if (e->type == KeyPress) {
This page took 0.030653 seconds and 4 git commands to generate.