1 #include "kernel/focus.h"
2 #include "kernel/dispatch.h"
3 #include "kernel/openbox.h"
4 #include "kernel/event.h"
5 #include "kernel/grab.h"
6 #include "kernel/action.h"
7 #include "kernel/parse.h"
8 #include "kernel/timer.h"
12 #include "translate.h"
15 void plugin_setup_config()
17 parse_reg_section("keyboard", keyparse, NULL);
20 KeyBindingTree *firstnode = NULL;
22 static KeyBindingTree *curpos;
23 static guint reset_key, reset_state, button_return, button_escape;
24 static Timer *chain_timer;
26 static void grab_keys()
32 p = curpos ? curpos->first_child : firstnode;
34 grab_key(p->key, p->state, GrabModeAsync);
37 grab_key(reset_key, reset_state, GrabModeAsync);
40 static void reset_chains()
43 timer_stop(chain_timer);
52 static void chain_timeout(void *data)
57 gboolean kbind(GList *keylist, Action *action)
59 KeyBindingTree *tree, *t;
62 g_assert(keylist != NULL);
63 g_assert(action != NULL);
65 if (!(tree = tree_build(keylist)))
68 if ((t = tree_find(tree, &conflict)) != NULL) {
69 /* already bound to something, use the existing tree */
74 while (t->first_child) t = t->first_child;
77 g_message("conflict with binding");
83 t->actions = g_slist_append(t->actions, action);
84 /* assimilate this built tree into the main tree. assimilation
85 destroys/uses the tree */
86 if (tree) tree_assimilate(tree);
91 static void event(ObEvent *e, void *foo)
93 static KeyBindingTree *grabbed_key = NULL;
96 gboolean done = FALSE;
98 if ((e->type == Event_X_KeyRelease &&
99 !(grabbed_key->state & e->data.x.e->xkey.state)))
101 else if (e->type == Event_X_KeyPress) {
102 if (e->data.x.e->xkey.keycode == button_return)
104 else if (e->data.x.e->xkey.keycode == button_escape) {
106 for (it = grabbed_key->actions; it; it = it->next) {
107 Action *act = it->data;
108 act->data.cycle.cancel = TRUE;
115 for (it = grabbed_key->actions; it; it = it->next) {
116 Action *act = it->data;
117 act->data.cycle.final = TRUE;
118 act->func(&act->data);
120 grab_keyboard(FALSE);
126 if (e->type == Event_X_KeyRelease)
129 g_assert(e->type == Event_X_KeyPress);
131 if (e->data.x.e->xkey.keycode == reset_key &&
132 e->data.x.e->xkey.state == reset_state) {
139 p = curpos->first_child;
141 if (p->key == e->data.x.e->xkey.keycode &&
142 p->state == e->data.x.e->xkey.state) {
143 if (p->first_child != NULL) { /* part of a chain */
144 if (chain_timer) timer_stop(chain_timer);
145 /* 5 second timeout for chains */
146 chain_timer = timer_start(5000*1000, chain_timeout,
152 for (it = p->actions; it; it = it->next) {
153 Action *act = it->data;
154 if (act->func != NULL) {
155 act->data.any.c = focus_client;
157 if (act->func == action_cycle_windows) {
158 act->data.cycle.final = FALSE;
159 act->data.cycle.cancel = FALSE;
162 act->func(&act->data);
164 if (act->func == action_cycle_windows &&
182 void plugin_startup()
189 dispatch_register(Event_X_KeyPress | Event_X_KeyRelease,
190 (EventHandler)event, NULL);
192 translate_key("C-g", &reset_state, &reset_key);
193 translate_key("Escape", &i, &button_escape);
194 translate_key("Return", &i, &button_return);
199 void plugin_shutdown()
201 dispatch_register(0, (EventHandler)event, NULL);
203 tree_destroy(firstnode);