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)
21 KeyBindingTree *p = firstnode;
23 grab_key(p->key, p->state, GrabModeSync);
29 static void reset_chains()
39 static gboolean kbind(GList *keylist, Action *action)
41 KeyBindingTree *tree, *t;
44 g_assert(keylist != NULL);
45 g_assert(action != NULL);
47 if (!(tree = tree_build(keylist))) {
48 g_warning("invalid binding");
51 if ((t = tree_find(tree, &conflict)) != NULL) {
52 /* already bound to something */
53 g_warning("keychain is already bound");
58 g_warning("conflict with binding");
63 /* grab the server here to make sure no key presses go missed */
69 while (t->first_child) t = t->first_child;
71 /* assimilate this built tree into the main tree. assimilation
72 destroys/uses the tree */
73 tree_assimilate(tree);
81 static void press(ObEvent *e, void *foo)
83 if (e->data.x.e->xkey.keycode == reset_key &&
84 e->data.x.e->xkey.state == reset_state) {
86 XAllowEvents(ob_display, AsyncKeyboard, CurrentTime);
92 p = curpos->first_child;
94 if (p->key == e->data.x.e->xkey.keycode &&
95 p->state == e->data.x.e->xkey.state) {
96 if (p->first_child != NULL) { /* part of a chain */
101 XAllowEvents(ob_display, AsyncKeyboard, CurrentTime);
105 if (p->action->func != NULL) {
106 p->action->data.any.c = focus_client;
108 g_assert(!(p->action->func == action_move ||
109 p->action->func == action_resize));
111 p->action->func(&p->action->data);
114 XAllowEvents(ob_display, AsyncKeyboard, CurrentTime);
124 static void binddef()
126 GList *list = g_list_append(NULL, NULL);
129 /* When creating an Action struct, all of the data elements in the
130 appropriate struct need to be set, except the Client*, which will be set
131 at call-time when then action function is used.
134 list->data = "C-Right";
135 a = action_new(action_next_desktop);
136 a->data.nextprevdesktop.wrap = TRUE;
139 list->data = "C-Left";
140 a = action_new(action_previous_desktop);
141 a->data.nextprevdesktop.wrap = TRUE;
145 a = action_new(action_desktop);
146 a->data.desktop.desk = 0;
150 a = action_new(action_desktop);
151 a->data.desktop.desk = 1;
155 a = action_new(action_desktop);
156 a->data.desktop.desk = 2;
160 a = action_new(action_desktop);
161 a->data.desktop.desk = 3;
164 list->data = "C-space";
165 a = action_new(action_execute);
166 a->data.execute.path = g_strdup("xterm");
170 void plugin_startup()
172 dispatch_register(Event_X_KeyPress, (EventHandler)press, NULL);
174 /* XXX parse config file! */
178 void plugin_shutdown()
180 dispatch_register(0, (EventHandler)press, NULL);
183 tree_destroy(firstnode);