X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=obt%2Fkeyboard.c;h=f4761ed5e7b43757b812eca1b56e30173c0ed9ee;hb=d9d65b73853d485852f6d6bf6808af0ebb6a90f5;hp=57208aa2d1c1f9b79f9a70ecf436776d596b110a;hpb=35ce211ec3ba025b67b5b91ecf10c1b1b2294a43;p=chaz%2Fopenbox diff --git a/obt/keyboard.c b/obt/keyboard.c index 57208aa2..f4761ed5 100644 --- a/obt/keyboard.c +++ b/obt/keyboard.c @@ -116,10 +116,19 @@ void obt_keyboard_reload(void) void obt_keyboard_shutdown(void) { + GSList *it; + XFreeModifiermap(modmap); modmap = NULL; XFree(keymap); keymap = NULL; + for (it = xic_all; it; it = g_slist_next(it)) { + ObtIC* ic = it->data; + if (ic->xic) { + XDestroyIC(ic->xic); + ic->xic = NULL; + } + } if (xim) XCloseIM(xim); xim = NULL; xim_style = 0; @@ -138,7 +147,6 @@ void xim_init(void) if (g_ascii_islower(aclass[0])) aclass[0] = g_ascii_toupper(aclass[0]); - g_print("Opening Input Method for %s %s\n", aname, aclass); xim = XOpenIM(obt_display, NULL, aname, aclass); if (!xim) @@ -182,23 +190,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) @@ -274,7 +299,7 @@ KeyCode* obt_keyboard_keysym_to_keycode(KeySym sym) for (i = min_keycode; i <= max_keycode; ++i) for (j = 0; j < keysyms_per_keycode; ++j) if (sym == keymap[(i-min_keycode) * keysyms_per_keycode + j]) { - ret = g_renew(KeyCode, ret, ++n); + ret = g_renew(KeyCode, ret, ++n + 1); ret[n-1] = i; ret[n] = 0; } @@ -375,11 +400,6 @@ KeySym obt_keyboard_keypress_to_keysym(XEvent *ev) void obt_keyboard_context_renew(ObtIC *ic) { - if (ic->xic) { - XDestroyIC(ic->xic); - ic->xic = NULL; - } - if (xim) { ic->xic = XCreateIC(xim, XNInputStyle, xim_style, @@ -398,7 +418,7 @@ ObtIC* obt_keyboard_context_new(Window client, Window focus) g_return_val_if_fail(client != None && focus != None, NULL); - ic = g_new(ObtIC, 1); + ic = g_slice_new(ObtIC); ic->ref = 1; ic->client = client; ic->focus = focus; @@ -420,6 +440,6 @@ void obt_keyboard_context_unref(ObtIC *ic) if (--ic->ref < 1) { xic_all = g_slist_remove(xic_all, ic); XDestroyIC(ic->xic); - g_free(ic); + g_slice_free(ObtIC, ic); } }