]>
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/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 XGrabKey(ob_display
, p
->key
, p
->state
, ob_root
, FALSE
,
24 GrabModeAsync
, GrabModeSync
);
30 static void reset_chains()
36 XUngrabKeyboard(ob_display
, CurrentTime
);
40 static void clearall()
43 tree_destroy(firstnode
);
48 static gboolean
bind(GList
*keylist
, KeyAction
*action
)
50 KeyBindingTree
*tree
, *t
;
53 if (!(tree
= tree_build(keylist
))) {
54 g_warning("invalid binding");
58 t
= tree_find(tree
, &conflict
);
60 g_warning("conflict with binding");
65 /* already bound to something */
66 g_warning("keychain is already bound");
71 /* grab the server here to make sure no key pressed go missed */
72 XGrabServer(ob_display
);
73 XSync(ob_display
, FALSE
);
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 */
91 XUngrabServer(ob_display
);
97 static void press(ObEvent
*e
, void *foo
)
99 if (e
->data
.x
.e
->xkey
.keycode
== reset_key
&&
100 e
->data
.x
.e
->xkey
.state
== reset_state
) {
102 XAllowEvents(ob_display
, AsyncKeyboard
, CurrentTime
);
108 p
= curpos
->first_child
;
110 if (p
->key
== e
->data
.x
.e
->xkey
.keycode
&&
111 p
->state
== e
->data
.x
.e
->xkey
.state
) {
112 if (p
->first_child
!= NULL
) { /* part of a chain */
115 /*grab should never fail because we should have a
116 sync grab at this point */
117 XGrabKeyboard(ob_display
, ob_root
, 0,
118 GrabModeAsync
, GrabModeSync
,
123 XAllowEvents(ob_display
, AsyncKeyboard
, CurrentTime
);
125 keyaction_do(&p
->action
, focus_client
);
127 XAllowEvents(ob_display
, AsyncKeyboard
, CurrentTime
);
137 static void binddef()
139 GList
*list
= g_list_append(NULL
, NULL
);
142 list
->data
= "C-Right";
143 a
.action
= Action_NextDesktop
;
144 keyaction_set_bool(&a
, 0, TRUE
);
145 keyaction_set_none(&a
, 1);
148 list
->data
= "C-Left";
149 a
.action
= Action_PreviousDesktop
;
150 keyaction_set_bool(&a
, 0, TRUE
);
151 keyaction_set_none(&a
, 1);
155 a
.action
= Action_Desktop
;
156 keyaction_set_uint(&a
, 0, 0);
157 keyaction_set_none(&a
, 1);
161 a
.action
= Action_Desktop
;
162 keyaction_set_uint(&a
, 0, 1);
163 keyaction_set_none(&a
, 1);
167 a
.action
= Action_Desktop
;
168 keyaction_set_uint(&a
, 0, 2);
169 keyaction_set_none(&a
, 1);
173 a
.action
= Action_Desktop
;
174 keyaction_set_uint(&a
, 0, 3);
175 keyaction_set_none(&a
, 1);
178 list
->data
= "C-space";
179 a
.action
= Action_Execute
;
180 keyaction_set_string(&a
, 0, "xterm");
181 keyaction_set_none(&a
, 1);
185 void plugin_startup()
187 dispatch_register(Event_X_KeyPress
, (EventHandler
)press
, NULL
);
189 /* XXX parse config file! */
193 void plugin_shutdown()
195 dispatch_register(0, (EventHandler
)press
, NULL
);
This page took 0.044161 seconds and 4 git commands to generate.