diff options
| author | Dana Jansens <danakj@orodu.net> | 2010-02-19 16:58:33 -0500 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2010-02-19 16:59:28 -0500 |
| commit | b7ddaa5728b5449449e3ea14cf84252285bbc794 (patch) | |
| tree | bae5a5da65a30256a22cf1206d5597edee278c27 /obt/keyboard.c | |
| parent | 4418e6988b5ea80acf0dee4f27a43b27a1fdf48f (diff) | |
get the modifier mask for a modifier key that is pressed/released more accurately, using the table we built already for other purposes
Diffstat (limited to 'obt/keyboard.c')
| -rw-r--r-- | obt/keyboard.c | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/obt/keyboard.c b/obt/keyboard.c index 2d3a0553..30aa7f93 100644 --- a/obt/keyboard.c +++ b/obt/keyboard.c @@ -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) |
