From 56bbbdc7223989690a01feb8deb4792a00ee83ee Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Tue, 24 Jul 2007 01:44:15 +0200 Subject: [PATCH] Add grab option to to not grab the keycombo. This is for example to let you bind stuff to the Alt key while alt-tabbing, but you don't want those keys to be grabbed in normal usage. --- openbox/config.c | 6 ++++-- openbox/keyboard.c | 10 +++++----- openbox/keyboard.h | 2 +- openbox/keytree.c | 3 ++- openbox/keytree.h | 3 ++- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/openbox/config.c b/openbox/config.c index 76f48569..6c38eed1 100644 --- a/openbox/config.c +++ b/openbox/config.c @@ -447,11 +447,13 @@ static void parse_key(xmlNodePtr node, GList *keylist) gchar *keystring, **keys, **key; xmlNodePtr n; gboolean is_chroot = FALSE; + gboolean grab = TRUE; if (!obt_xml_attr_string(node, "key", &keystring)) return; obt_xml_attr_bool(node, "chroot", &is_chroot); + obt_xml_attr_bool(node, "grab", &grab); keys = g_strsplit(keystring, " ", 0); for (key = keys; *key; ++key) { @@ -469,7 +471,7 @@ static void parse_key(xmlNodePtr node, GList *keylist) action = actions_parse(n); if (action) - keyboard_bind(keylist, action); + keyboard_bind(keylist, action, grab); n = obt_xml_find_node(n->next, "action"); } } @@ -976,7 +978,7 @@ static void bind_default_keyboard(void) }; for (it = binds; it->key; ++it) { GList *l = g_list_append(NULL, g_strdup(it->key)); - keyboard_bind(l, actions_parse_string(it->actname)); + keyboard_bind(l, actions_parse_string(it->actname), TRUE); } } diff --git a/openbox/keyboard.c b/openbox/keyboard.c index 8f4424ea..dd552a23 100644 --- a/openbox/keyboard.c +++ b/openbox/keyboard.c @@ -51,7 +51,7 @@ static void grab_keys(gboolean grab) if (grab) { p = curpos ? curpos->first_child : keyboard_firstnode; while (p) { - if (p->key) + if (p->key && p->grab) grab_key(p->key, p->state, obt_root(ob_screen), GrabModeAsync); p = p->next_sibling; @@ -132,14 +132,14 @@ void keyboard_chroot(GList *keylist) chroot binding. so add it to the tree then. */ if (!tree_chroot(keyboard_firstnode, keylist)) { KeyBindingTree *tree; - if (!(tree = tree_build(keylist))) + if (!(tree = tree_build(keylist, TRUE))) return; tree_chroot(tree, keylist); tree_assimilate(tree); } } -gboolean keyboard_bind(GList *keylist, ObActionsAct *action) +gboolean keyboard_bind(GList *keylist, ObActionsAct *action, gboolean grab) { KeyBindingTree *tree, *t; gboolean conflict; @@ -147,7 +147,7 @@ gboolean keyboard_bind(GList *keylist, ObActionsAct *action) g_assert(keylist != NULL); g_assert(action != NULL); - if (!(tree = tree_build(keylist))) + if (!(tree = tree_build(keylist, grab))) return FALSE; if ((t = tree_find(tree, &conflict)) != NULL) { @@ -295,7 +295,7 @@ static void node_rebind(KeyBindingTree *node) 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); + keyboard_bind(node->keylist, node->actions->data, node->grab); node->actions = g_slist_delete_link(node->actions, node->actions); } diff --git a/openbox/keyboard.h b/openbox/keyboard.h index c89f67e9..8569b973 100644 --- a/openbox/keyboard.h +++ b/openbox/keyboard.h @@ -37,7 +37,7 @@ void keyboard_shutdown(gboolean reconfig); void keyboard_rebind(void); void keyboard_chroot(GList *keylist); -gboolean keyboard_bind(GList *keylist, struct _ObActionsAct *action); +gboolean keyboard_bind(GList *keylist, struct _ObActionsAct *action, gboolean grab); void keyboard_unbind_all(void); gboolean keyboard_event(struct _ObClient *client, const XEvent *e); diff --git a/openbox/keytree.c b/openbox/keytree.c index 93a0c7aa..87003a03 100644 --- a/openbox/keytree.c +++ b/openbox/keytree.c @@ -44,7 +44,7 @@ void tree_destroy(KeyBindingTree *tree) } } -KeyBindingTree *tree_build(GList *keylist) +KeyBindingTree *tree_build(GList *keylist, gboolean grab) { GList *it; KeyBindingTree *ret = NULL, *p; @@ -62,6 +62,7 @@ KeyBindingTree *tree_build(GList *keylist) ret->keylist = g_list_prepend(ret->keylist, g_strdup(kit->data)); /* deep copy */ ret->first_child = p; + ret->grab = grab; if (p != NULL) p->parent = ret; translate_key(it->data, &ret->state, &ret->key); } diff --git a/openbox/keytree.h b/openbox/keytree.h index 66edc3c7..6b376066 100644 --- a/openbox/keytree.h +++ b/openbox/keytree.h @@ -24,6 +24,7 @@ typedef struct KeyBindingTree { guint state; guint key; + gboolean grab; GList *keylist; GSList *actions; /* list of Action pointers */ gboolean chroot; @@ -37,7 +38,7 @@ typedef struct KeyBindingTree { } KeyBindingTree; void tree_destroy(KeyBindingTree *tree); -KeyBindingTree *tree_build(GList *keylist); +KeyBindingTree *tree_build(GList *keylist, gboolean grab); void tree_assimilate(KeyBindingTree *node); KeyBindingTree *tree_find(KeyBindingTree *search, gboolean *conflict); gboolean tree_chroot(KeyBindingTree *tree, GList *keylist); -- 2.39.2