diff options
| author | Dana Jansens <danakj@orodu.net> | 2011-10-16 11:50:15 -0400 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2012-09-30 14:48:04 -0400 |
| commit | be9637e40317eb36e5a5357d3f58e3af21c81df4 (patch) | |
| tree | 5f7c1b4227522f36d25653e302c6f9ad3d45feab | |
| parent | ad5b92588fbe36100cdc4ae7064883cd16e13a1e (diff) | |
Use the KeyCode to directly find the modifier mask. (Fix bug 5173)
We were finding the KeySym first, and then converting back to a modifier mask.
But KeySym on a key's release can differ from on its press, and we don't need
them to determine the modmask from the keycode.
[setxkbmap -option "grp:shifts_toggle"] turns Shift_L into XK_ISO_Prev_Group on
key release, and Shift_R into XK_ISO_Next_Group.
| -rw-r--r-- | obt/keyboard.c | 40 | ||||
| -rw-r--r-- | obt/keyboard.h | 3 | ||||
| -rw-r--r-- | openbox/actions/desktop.c | 2 |
3 files changed, 11 insertions, 34 deletions
diff --git a/obt/keyboard.c b/obt/keyboard.c index ef2678b5..4e84f481 100644 --- a/obt/keyboard.c +++ b/obt/keyboard.c @@ -49,7 +49,7 @@ void obt_keyboard_context_renew(ObtIC *ic); static XModifierKeymap *modmap; static KeySym *keymap; static gint min_keycode, max_keycode, keysyms_per_keycode; -/* This is a bitmask of the different masks for each modifier key */ +/*! This is a bitmask of the different masks for each modifier key */ static guchar modkeys_keys[OBT_KEYBOARD_NUM_MODKEYS]; static gboolean alt_l = FALSE; @@ -190,40 +190,20 @@ void xim_init(void) g_free(aname); } -ObtModkeysKey obt_keyboard_keyevent_to_modkey(XEvent *e) +guint obt_keyboard_keyevent_to_modmask(XEvent *e) { - KeySym sym; + gint i, masknum; 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_HYPER; - case XK_Meta_L: - case XK_Meta_R: return OBT_KEYBOARD_MODKEY_META; - 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; - } -} - -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)); + for (masknum = 0; masknum < NUM_MASKS; ++masknum) + for (i = 0; i < modmap->max_keypermod; ++i) { + KeyCode c = modmap->modifiermap[masknum*modmap->max_keypermod + i]; + if (c == e->xkey.keycode) + return 1<<masknum; + } + return 0; } guint obt_keyboard_only_modmasks(guint mask) diff --git a/obt/keyboard.h b/obt/keyboard.h index 868cccf4..8f2badf8 100644 --- a/obt/keyboard.h +++ b/obt/keyboard.h @@ -59,9 +59,6 @@ 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); diff --git a/openbox/actions/desktop.c b/openbox/actions/desktop.c index 70d807db..8dadf550 100644 --- a/openbox/actions/desktop.c +++ b/openbox/actions/desktop.c @@ -352,7 +352,7 @@ static gboolean i_input_func(guint initial_state, static gboolean i_pre_func(guint initial_state, gpointer options) { guint initial_mods = obt_keyboard_only_modmasks(initial_state); - if (!inital_mods) { + if (!initial_mods) { Options *o = options; o->interactive = FALSE; return FALSE; |
