1 #include "../../kernel/focus.h"
2 #include "../../kernel/dispatch.h"
3 #include "../../kernel/openbox.h"
4 #include "../../kernel/grab.h"
5 #include "../../kernel/action.h"
12 void plugin_setup_config()
16 KeyBindingTree *firstnode;
18 static KeyBindingTree *curpos;
19 static guint reset_key, reset_state;
20 static gboolean grabbed;
22 static void grab_keys(gboolean grab)
27 KeyBindingTree *p = firstnode;
29 grab_key(p->key, p->state, GrabModeSync);
35 static void reset_chains()
43 XAllowEvents(ob_display, AsyncKeyboard, CurrentTime);
46 gboolean kbind(GList *keylist, Action *action)
48 KeyBindingTree *tree, *t;
51 g_assert(keylist != NULL);
52 g_assert(action != NULL);
54 if (!(tree = tree_build(keylist)))
56 if ((t = tree_find(tree, &conflict)) != NULL) {
57 /* already bound to something */
58 g_warning("keychain is already bound");
63 g_warning("conflict with binding");
68 /* grab the server here to make sure no key presses go missed */
74 while (t->first_child) t = t->first_child;
76 /* assimilate this built tree into the main tree. assimilation
77 destroys/uses the tree */
78 tree_assimilate(tree);
86 static void press(ObEvent *e, void *foo)
88 if (e->data.x.e->xkey.keycode == reset_key &&
89 e->data.x.e->xkey.state == reset_state) {
96 p = curpos->first_child;
98 if (p->key == e->data.x.e->xkey.keycode &&
99 p->state == e->data.x.e->xkey.state) {
100 if (p->first_child != NULL) { /* part of a chain */
105 XAllowEvents(ob_display, AsyncKeyboard, CurrentTime);
109 if (p->action->func != NULL) {
110 p->action->data.any.c = focus_client;
112 g_assert(!(p->action->func == action_move ||
113 p->action->func == action_resize));
115 p->action->func(&p->action->data);
127 void plugin_startup()
129 dispatch_register(Event_X_KeyPress, (EventHandler)press, NULL);
131 translate_key("C-g", &reset_state, &reset_key);
136 void plugin_shutdown()
138 dispatch_register(0, (EventHandler)press, NULL);
141 tree_destroy(firstnode);