From: Dana Jansens Date: Sat, 12 Jan 2008 02:19:58 +0000 (-0500) Subject: dont reparse the config file when the keyboard map changes. just rebind everything... X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;ds=sidebyside;h=405d9a3e431b01a221be65f41bccb6c80c43b0a4;hp=-c;p=chaz%2Fopenbox dont reparse the config file when the keyboard map changes. just rebind everything. yay for mika as inspiration --- 405d9a3e431b01a221be65f41bccb6c80c43b0a4 diff --git a/openbox/event.c b/openbox/event.c index 6b0ecdd7..bc59d67e 100644 --- a/openbox/event.c +++ b/openbox/event.c @@ -639,9 +639,12 @@ static void event_process(const XEvent *ec, gpointer data) else if (e->type == MapRequest) client_manage(window); else if (e->type == MappingNotify) { - /* keyboard layout changes, reconfigure openbox. need to restart the - modkeys system, but also to reload the key bindings. */ - ob_reconfigure(); + /* keyboard layout changes for modifier mapping changes. reload the + modifier map, and rebind all the key bindings as appropriate */ + ob_debug("Kepboard map changed. Reloading keyboard bindings.\n"); + modkeys_shutdown(TRUE); + modkeys_startup(TRUE); + keyboard_rebind(); } else if (e->type == ClientMessage) { /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for diff --git a/openbox/keyboard.c b/openbox/keyboard.c index 0aade9ab..eddda577 100644 --- a/openbox/keyboard.c +++ b/openbox/keyboard.c @@ -51,8 +51,9 @@ static void grab_keys(gboolean grab) if (grab) { p = curpos ? curpos->first_child : keyboard_firstnode; while (p) { - grab_key(p->key, p->state, RootWindow(ob_display, ob_screen), - GrabModeAsync); + if (p->key) + grab_key(p->key, p->state, RootWindow(ob_display, ob_screen), + GrabModeAsync); p = p->next_sibling; } if (curpos) @@ -264,6 +265,12 @@ void keyboard_event(ObClient *client, const XEvent *e) } } +void keyboard_rebind() +{ + tree_rebind(keyboard_firstnode); + grab_keys(TRUE); +} + void keyboard_startup(gboolean reconfig) { grab_keys(TRUE); diff --git a/openbox/keyboard.h b/openbox/keyboard.h index 1c55e050..995cdbc5 100644 --- a/openbox/keyboard.h +++ b/openbox/keyboard.h @@ -34,6 +34,8 @@ extern KeyBindingTree *keyboard_firstnode; void keyboard_startup(gboolean reconfig); void keyboard_shutdown(gboolean reconfig); +void keyboard_rebind(); + void keyboard_chroot(GList *keylist); gboolean keyboard_bind(GList *keylist, struct _ObActionsAct *action); void keyboard_unbind_all(); diff --git a/openbox/keytree.c b/openbox/keytree.c index fb26624d..714fffda 100644 --- a/openbox/keytree.c +++ b/openbox/keytree.c @@ -63,14 +63,18 @@ KeyBindingTree *tree_build(GList *keylist) g_strdup(kit->data)); /* deep copy */ ret->first_child = p; if (p != NULL) p->parent = ret; - if (!translate_key(it->data, &ret->state, &ret->key)) { - tree_destroy(ret); - return NULL; - } + translate_key(it->data, &ret->state, &ret->key); } return ret; } +void tree_rebind(KeyBindingTree *node) { + GList *it = g_list_last(node->keylist); + translate_key(it->data, &node->state, &node->key); + if (node->next_sibling) tree_rebind(node->next_sibling); + if (node->first_child) tree_rebind(node->first_child); +} + void tree_assimilate(KeyBindingTree *node) { KeyBindingTree *a, *b, *tmp, *last; diff --git a/openbox/keytree.h b/openbox/keytree.h index 391cb154..0307378d 100644 --- a/openbox/keytree.h +++ b/openbox/keytree.h @@ -41,6 +41,7 @@ KeyBindingTree *tree_build(GList *keylist); void tree_assimilate(KeyBindingTree *node); KeyBindingTree *tree_find(KeyBindingTree *search, gboolean *conflict); gboolean tree_chroot(KeyBindingTree *tree, GList *keylist); +void tree_rebind(KeyBindingTree *node); #endif diff --git a/openbox/translate.c b/openbox/translate.c index 21015578..b2ae7d67 100644 --- a/openbox/translate.c +++ b/openbox/translate.c @@ -111,6 +111,8 @@ gboolean translate_key(const gchar *str, guint *state, guint *keycode) parsed = g_strsplit(str, "-", -1); + *state = *keycode = 0; + /* first, find the key (last token) */ l = NULL; for (i = 0; parsed[i] != NULL; ++i)