]>
Dogcows Code - chaz/openbox/blob - plugins/keyboard/keyboard.c
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"
11 KeyBindingTree
*firstnode
;
13 static KeyBindingTree
*curpos
;
14 static guint reset_key
, reset_state
;
15 static gboolean grabbed
;
17 static void grab_keys(gboolean grab
)
20 XUngrabKey(ob_display
, AnyKey
, AnyModifier
, ob_root
);
22 KeyBindingTree
*p
= firstnode
;
24 XGrabKey(ob_display
, p
->key
, p
->state
, ob_root
, FALSE
,
25 GrabModeAsync
, GrabModeSync
);
31 static void reset_chains()
41 static void clearall()
44 tree_destroy(firstnode
);
49 static gboolean
bind(GList
*keylist
, KeyAction
*action
)
51 KeyBindingTree
*tree
, *t
;
54 if (!(tree
= tree_build(keylist
))) {
55 g_warning("invalid binding");
59 t
= tree_find(tree
, &conflict
);
61 g_warning("conflict with binding");
66 /* already bound to something */
67 g_warning("keychain is already bound");
72 /* grab the server here to make sure no key pressed go missed */
77 /* set the function */
79 while (t
->first_child
) t
= t
->first_child
;
80 t
->action
.action
= action
->action
;
81 t
->action
.type
[0] = action
->type
[0];
82 t
->action
.type
[1] = action
->type
[1];
83 t
->action
.data
[0] = action
->data
[0];
84 t
->action
.data
[1] = action
->data
[1];
86 /* assimilate this built tree into the main tree */
87 tree_assimilate(tree
); /* assimilation destroys/uses the tree */
96 static void press(ObEvent
*e
, void *foo
)
98 if (e
->data
.x
.e
->xkey
.keycode
== reset_key
&&
99 e
->data
.x
.e
->xkey
.state
== reset_state
) {
101 XAllowEvents(ob_display
, AsyncKeyboard
, CurrentTime
);
107 p
= curpos
->first_child
;
109 if (p
->key
== e
->data
.x
.e
->xkey
.keycode
&&
110 p
->state
== e
->data
.x
.e
->xkey
.state
) {
111 if (p
->first_child
!= NULL
) { /* part of a chain */
116 XAllowEvents(ob_display
, AsyncKeyboard
, CurrentTime
);
120 keyaction_do(&p
->action
, focus_client
);
122 XAllowEvents(ob_display
, AsyncKeyboard
, CurrentTime
);
132 static void binddef()
134 GList
*list
= g_list_append(NULL
, NULL
);
137 list
->data
= "C-Right";
138 a
.action
= Action_NextDesktop
;
139 keyaction_set_bool(&a
, 0, TRUE
);
140 keyaction_set_none(&a
, 1);
143 list
->data
= "C-Left";
144 a
.action
= Action_PreviousDesktop
;
145 keyaction_set_bool(&a
, 0, TRUE
);
146 keyaction_set_none(&a
, 1);
150 a
.action
= Action_Desktop
;
151 keyaction_set_uint(&a
, 0, 0);
152 keyaction_set_none(&a
, 1);
156 a
.action
= Action_Desktop
;
157 keyaction_set_uint(&a
, 0, 1);
158 keyaction_set_none(&a
, 1);
162 a
.action
= Action_Desktop
;
163 keyaction_set_uint(&a
, 0, 2);
164 keyaction_set_none(&a
, 1);
168 a
.action
= Action_Desktop
;
169 keyaction_set_uint(&a
, 0, 3);
170 keyaction_set_none(&a
, 1);
173 list
->data
= "C-space";
174 a
.action
= Action_Execute
;
175 keyaction_set_string(&a
, 0, "xterm");
176 keyaction_set_none(&a
, 1);
180 void plugin_startup()
182 dispatch_register(Event_X_KeyPress
, (EventHandler
)press
, NULL
);
184 /* XXX parse config file! */
188 void plugin_shutdown()
190 dispatch_register(0, (EventHandler
)press
, NULL
);
This page took 0.040144 seconds and 4 git commands to generate.