]>
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"
10 void plugin_setup_config()
14 KeyBindingTree
*firstnode
;
16 static KeyBindingTree
*curpos
;
17 static guint reset_key
, reset_state
;
18 static gboolean grabbed
;
20 static void grab_keys(gboolean grab
)
25 KeyBindingTree
*p
= firstnode
;
27 grab_key(p
->key
, p
->state
, GrabModeSync
);
33 static void reset_chains()
43 static gboolean
kbind(GList
*keylist
, Action
*action
)
45 KeyBindingTree
*tree
, *t
;
48 g_assert(keylist
!= NULL
);
49 g_assert(action
!= NULL
);
51 if (!(tree
= tree_build(keylist
))) {
52 g_warning("invalid binding");
55 if ((t
= tree_find(tree
, &conflict
)) != NULL
) {
56 /* already bound to something */
57 g_warning("keychain is already bound");
62 g_warning("conflict with binding");
67 /* grab the server here to make sure no key presses go missed */
73 while (t
->first_child
) t
= t
->first_child
;
75 /* assimilate this built tree into the main tree. assimilation
76 destroys/uses the tree */
77 tree_assimilate(tree
);
85 static void press(ObEvent
*e
, void *foo
)
87 if (e
->data
.x
.e
->xkey
.keycode
== reset_key
&&
88 e
->data
.x
.e
->xkey
.state
== reset_state
) {
90 XAllowEvents(ob_display
, AsyncKeyboard
, CurrentTime
);
96 p
= curpos
->first_child
;
98 if (p
->key
== e
->data
.x
.e
->xkey
.keycode
&&
99 p
->state
== e
->data
.x
.e
->xkey
.state
) {
100 if (p
->first_child
!= NULL
) { /* part of a chain */
107 XAllowEvents(ob_display
, AsyncKeyboard
, CurrentTime
);
109 if (p
->action
->func
!= NULL
) {
110 p
->action
->data
.any
.c
= focus_client
;
112 g_assert(!(p
->action
->func
== action_move
||
113 p
->action
->func
== action_resize
));
115 p
->action
->func(&p
->action
->data
);
118 XAllowEvents(ob_display
, AsyncKeyboard
, CurrentTime
);
128 static void binddef()
130 GList
*list
= g_list_append(NULL
, NULL
);
133 /* When creating an Action struct, all of the data elements in the
134 appropriate struct need to be set, except the Client*, which will be set
135 at call-time when then action function is used.
138 list
->data
= "A-Right";
139 a
= action_new(action_next_desktop
);
140 a
->data
.nextprevdesktop
.wrap
= TRUE
;
143 list
->data
= "A-Left";
144 a
= action_new(action_previous_desktop
);
145 a
->data
.nextprevdesktop
.wrap
= TRUE
;
149 a
= action_new(action_desktop
);
150 a
->data
.desktop
.desk
= 0;
154 a
= action_new(action_desktop
);
155 a
->data
.desktop
.desk
= 1;
159 a
= action_new(action_desktop
);
160 a
->data
.desktop
.desk
= 2;
164 a
= action_new(action_desktop
);
165 a
->data
.desktop
.desk
= 3;
168 list
->data
= "A-space";
169 a
= action_new(action_execute
);
170 a
->data
.execute
.path
= g_strdup("xterm");
173 list
->data
= "C-A-Escape";
174 a
= action_new(action_execute
);
175 a
->data
.execute
.path
= g_strdup("xlock -nolock -mode puzzle");
179 void plugin_startup()
181 dispatch_register(Event_X_KeyPress
, (EventHandler
)press
, NULL
);
183 /* XXX parse config file! */
187 void plugin_shutdown()
189 dispatch_register(0, (EventHandler
)press
, NULL
);
192 tree_destroy(firstnode
);
This page took 0.044359 seconds and 4 git commands to generate.