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"
10 KeyBindingTree *firstnode;
12 static KeyBindingTree *curpos;
13 static guint reset_key, reset_state;
14 static gboolean grabbed;
16 static void grab_keys(gboolean grab)
19 XUngrabKey(ob_display, AnyKey, AnyModifier, ob_root);
21 KeyBindingTree *p = firstnode;
23 /* XXX grab all lock keys too */
24 XGrabKey(ob_display, p->key, p->state, ob_root, FALSE,
25 GrabModeAsync, GrabModeSync);
31 static void reset_chains()
41 static gboolean kbind(GList *keylist, Action *action)
43 KeyBindingTree *tree, *t;
46 g_assert(keylist != NULL);
47 g_assert(action != NULL);
49 if (!(tree = tree_build(keylist))) {
50 g_warning("invalid binding");
53 if ((t = tree_find(tree, &conflict)) != NULL) {
54 /* already bound to something */
55 g_warning("keychain is already bound");
60 g_warning("conflict with binding");
65 /* grab the server here to make sure no key presses go missed */
71 while (t->first_child) t = t->first_child;
73 /* assimilate this built tree into the main tree. assimilation
74 destroys/uses the tree */
75 tree_assimilate(tree);
83 static void press(ObEvent *e, void *foo)
85 if (e->data.x.e->xkey.keycode == reset_key &&
86 e->data.x.e->xkey.state == reset_state) {
88 XAllowEvents(ob_display, AsyncKeyboard, CurrentTime);
94 p = curpos->first_child;
96 if (p->key == e->data.x.e->xkey.keycode &&
97 p->state == e->data.x.e->xkey.state) {
98 if (p->first_child != NULL) { /* part of a chain */
103 XAllowEvents(ob_display, AsyncKeyboard, CurrentTime);
107 if (p->action->func != NULL) {
108 p->action->data.any.c = focus_client;
110 g_assert(!(p->action->func == action_move ||
111 p->action->func == action_resize));
113 p->action->func(&p->action->data);
116 XAllowEvents(ob_display, AsyncKeyboard, CurrentTime);
126 static void binddef()
128 GList *list = g_list_append(NULL, NULL);
131 /* When creating an Action struct, all of the data elements in the
132 appropriate struct need to be set, except the Client*, which will be set
133 at call-time when then action function is used.
136 list->data = "C-Right";
137 a = action_new(action_next_desktop);
138 a->data.nextprevdesktop.wrap = TRUE;
141 list->data = "C-Left";
142 a = action_new(action_previous_desktop);
143 a->data.nextprevdesktop.wrap = TRUE;
147 a = action_new(action_desktop);
148 a->data.desktop.desk = 0;
152 a = action_new(action_desktop);
153 a->data.desktop.desk = 1;
157 a = action_new(action_desktop);
158 a->data.desktop.desk = 2;
162 a = action_new(action_desktop);
163 a->data.desktop.desk = 3;
166 list->data = "C-space";
167 a = action_new(action_execute);
168 a->data.execute.path = g_strdup("xterm");
172 void plugin_startup()
174 dispatch_register(Event_X_KeyPress, (EventHandler)press, NULL);
176 /* XXX parse config file! */
180 void plugin_shutdown()
182 dispatch_register(0, (EventHandler)press, NULL);
185 tree_destroy(firstnode);