all repos — openbox @ b7ddaa5728b5449449e3ea14cf84252285bbc794

openbox fork - make it a bit more like ryudo

get the modifier mask for a modifier key that is pressed/released more accurately, using the table we built already for other purposes
Dana Jansens danakj@orodu.net
commit

b7ddaa5728b5449449e3ea14cf84252285bbc794

parent

4418e6988b5ea80acf0dee4f27a43b27a1fdf48f

M obt/keyboard.cobt/keyboard.c

@@ -191,23 +191,40 @@ g_free(aclass);

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; + KeySym sym; + + g_return_val_if_fail(e->type == KeyPress || e->type == KeyRelease, + OBT_KEYBOARD_MODKEY_NONE); - if (keycode == NoSymbol) return 0; + XLookupString(&e->xkey, NULL, 0, &sym, NULL); - /* 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); - } + 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)
M obt/keyboard.hobt/keyboard.h

@@ -28,6 +28,7 @@

/*! 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 */

@@ -56,6 +58,9 @@

/*! Get the modifier masks for a modifier key. This includes both the left and 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);
M openbox/actions/cyclewindows.copenbox/actions/cyclewindows.c

@@ -181,7 +181,7 @@ mods = obt_keyboard_only_modmasks(e->xkey.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) {
M openbox/actions/desktop.copenbox/actions/desktop.c

@@ -316,7 +316,7 @@ mods = obt_keyboard_only_modmasks(e->xkey.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) {
M openbox/actions/directionalwindows.copenbox/actions/directionalwindows.c

@@ -265,7 +265,7 @@ mods = obt_keyboard_only_modmasks(e->xkey.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) {