X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=obt%2Fkeyboard.c;h=4e84f4819e24a8b872cbbbcf52a4b72a477461aa;hb=be9637e40317eb36e5a5357d3f58e3af21c81df4;hp=f7a0f3bbee80cd83a3c12c336c33b824940fd006;hpb=7c2eb3a781b4434d243b3d135e3dc1ce288cf464;p=chaz%2Fopenbox diff --git a/obt/keyboard.c b/obt/keyboard.c index f7a0f3bb..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; @@ -147,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) @@ -191,23 +190,20 @@ void xim_init(void) g_free(aname); } -guint obt_keyboard_keycode_to_modmask(guint keycode) +guint obt_keyboard_keyevent_to_modmask(XEvent *e) { - gint i, j; - guint mask = 0; + gint i, masknum; - if (keycode == NoSymbol) return 0; + g_return_val_if_fail(e->type == KeyPress || e->type == KeyRelease, + OBT_KEYBOARD_MODKEY_NONE); - /* 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); + 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<type == KeyPress, None); sym = None; - r = XLookupString(&ev->xkey, NULL, 0, &sym, NULL); + XLookupString(&ev->xkey, NULL, 0, &sym, NULL); return sym; } @@ -402,7 +397,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; @@ -423,7 +418,8 @@ 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); + if (ic->xic) + XDestroyIC(ic->xic); + g_slice_free(ObtIC, ic); } }