X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=obt%2Fkeyboard.c;h=2d3a0553d7a864e9a8c55bf130b110961e72e106;hb=3f5403a916c73679a3f225fc1e6d8591a08a178d;hp=82161e592501f611f8a3fb37bef4639a42f98d14;hpb=41dbce908a981214d2d61e813c17d9415f938d87;p=chaz%2Fopenbox diff --git a/obt/keyboard.c b/obt/keyboard.c index 82161e59..2d3a0553 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; @@ -281,7 +290,7 @@ KeyCode* obt_keyboard_keysym_to_keycode(KeySym sym) return ret; } -gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XKeyPressedEvent *ev) +gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XEvent *ev) { gunichar unikey = 0; KeySym sym; @@ -290,6 +299,8 @@ gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XKeyPressedEvent *ev) gint len, bufsz; gboolean got_string = FALSE; + g_return_val_if_fail(ev->type == KeyPress, 0); + if (!ic) g_warning("Using obt_keyboard_keypress_to_unichar() without an " "Input Context. No i18n support!"); @@ -299,9 +310,9 @@ gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XKeyPressedEvent *ev) bufsz = sizeof(fixbuf); #ifdef X_HAVE_UTF8_STRING - len = Xutf8LookupString(ic->xic, ev, buf, bufsz, &sym, &status); + len = Xutf8LookupString(ic->xic, &ev->xkey, buf, bufsz, &sym, &status); #else - len = XmbLookupString(ic->xic, ev, buf, bufsz, &sym, &status); + len = XmbLookupString(ic->xic, &ev->xkey, buf, bufsz, &sym, &status); #endif if (status == XBufferOverflow) { @@ -309,9 +320,11 @@ gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XKeyPressedEvent *ev) bufsz = len; #ifdef X_HAVE_UTF8_STRING - len = Xutf8LookupString(ic->xic, ev, buf, bufsz, &sym, &status); + len = Xutf8LookupString(ic->xic, &ev->xkey, buf, bufsz, &sym, + &status); #else - len = XmbLookupString(ic->xic, ev, buf, bufsz, &sym, &status); + len = XmbLookupString(ic->xic, &ev->xkey, buf, bufsz, &sym, + &status); #endif } @@ -327,6 +340,9 @@ gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XKeyPressedEvent *ev) got_string = TRUE; } } + else if (status == XLookupKeySym) + /* this key doesn't have a text representation, it is a command + key of some sort */; else g_message("Bad keycode lookup. Keysym 0x%x Status: %s\n", (guint) sym, @@ -338,7 +354,7 @@ gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XKeyPressedEvent *ev) else { buf = fixbuf; bufsz = sizeof(fixbuf); - len = XLookupString(ev, buf, bufsz, &sym, NULL); + len = XLookupString(&ev->xkey, buf, bufsz, &sym, NULL); if ((guchar)buf[0] >= 32) /* not an ascii control character */ got_string = TRUE; } @@ -354,13 +370,20 @@ gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XKeyPressedEvent *ev) return unikey; } -void obt_keyboard_context_renew(ObtIC *ic) +KeySym obt_keyboard_keypress_to_keysym(XEvent *ev) { - if (ic->xic) { - XDestroyIC(ic->xic); - ic->xic = NULL; - } + KeySym sym; + gint r; + g_return_val_if_fail(ev->type == KeyPress, None); + + sym = None; + r = XLookupString(&ev->xkey, NULL, 0, &sym, NULL); + return sym; +} + +void obt_keyboard_context_renew(ObtIC *ic) +{ if (xim) { ic->xic = XCreateIC(xim, XNInputStyle, xim_style, @@ -379,7 +402,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; @@ -401,6 +424,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); } }