]> Dogcows Code - chaz/openbox/commitdiff
fix a crash from chroot of invalid keys, and make keybindings reload better
authorDana Jansens <danakj@orodu.net>
Sat, 2 Feb 2008 05:59:59 +0000 (00:59 -0500)
committerDana Jansens <danakj@orodu.net>
Sat, 2 Feb 2008 06:25:59 +0000 (01:25 -0500)
since invalid(not translated) keybindings are allowed in the tree, the tree's structure may actually need to change when reconfiguring.  actually, it could need to anyways.  so when re-translating all the keybindings, actually rebuild the keybinding tree.  also, make the chroot building code not fail when translate fails, to match the rest of the code and avoid segfaults with chroots on invalid keys.

openbox/keyboard.c
openbox/keytree.c
openbox/keytree.h

index 4c570dfbe4a0b20aa89fae6519c008385adb16d7..82d6dfdcdc878bddb3a140802e8397f9f29d51cf 100644 (file)
@@ -265,9 +265,46 @@ void keyboard_event(ObClient *client, const XEvent *e)
     }
 }
 
+static void node_rebind(KeyBindingTree *node)
+{
+    if (node->first_child) {
+        /* find leaf nodes */
+        node_rebind(node->first_child);
+
+        /* for internal nodes, add them to the tree if they
+           are a chroot, but do this after adding their
+           children */
+        if (node->chroot)
+            keyboard_chroot(node->keylist);
+    }
+    else {
+        /* for leaf nodes, rebind each action assigned to it */
+        GSList *it;
+        while (node->actions) {
+            /* add each action, and remove them from the original tree so
+               they don't get free'd on us */
+            keyboard_bind(node->keylist, node->actions->data);
+            node->actions = g_slist_delete_link(node->actions, node->actions);
+        }
+
+        if (node->chroot)
+            keyboard_chroot(node->keylist);
+    }
+
+    /* go through each sibling */
+    if (node->next_sibling) node_rebind(node->next_sibling);
+}
+
 void keyboard_rebind(void)
 {
-    tree_rebind(keyboard_firstnode);
+    KeyBindingTree *old;
+
+    old = keyboard_firstnode;
+    keyboard_firstnode = NULL;
+    node_rebind(old);
+
+    tree_destroy(old);
+    set_curpos(NULL);
     grab_keys(TRUE);
 }
 
index 714fffda60bc6bbccdfe0bbd46e74f732865a73a..56cc96d41baf767dac67e8f9152e2fcb98475c60 100644 (file)
@@ -68,13 +68,6 @@ KeyBindingTree *tree_build(GList *keylist)
     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;
@@ -139,16 +132,15 @@ KeyBindingTree *tree_find(KeyBindingTree *search, gboolean *conflict)
 gboolean tree_chroot(KeyBindingTree *tree, GList *keylist)
 {
     guint key, state;
-    if (translate_key(keylist->data, &state, &key)) {
-        while (tree != NULL && !(tree->state == state && tree->key == key))
-            tree = tree->next_sibling;
-        if (tree != NULL) {
-            if (keylist->next == NULL) {
-                tree->chroot = TRUE;
-                return TRUE;
-            } else
-                return tree_chroot(tree->first_child, keylist->next);
-        }
+    translate_key(keylist->data, &state, &key);
+    while (tree != NULL && !(tree->state == state && tree->key == key))
+        tree = tree->next_sibling;
+    if (tree != NULL) {
+        if (keylist->next == NULL) {
+            tree->chroot = TRUE;
+            return TRUE;
+        } else
+            return tree_chroot(tree->first_child, keylist->next);
     }
     return FALSE;
 }
index 0307378d06e378ed590a45a743fba15655665b39..391cb154fb91a5cc61c2f12ac8771dd8a17b91b3 100644 (file)
@@ -41,7 +41,6 @@ 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
This page took 0.027626 seconds and 4 git commands to generate.