]>
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
) {
95 p
= curpos
->first_child
;
97 if (p
->key
== e
->data
.x
.e
->xkey
.keycode
&&
98 p
->state
== e
->data
.x
.e
->xkey
.state
) {
99 if (p
->first_child
!= NULL
) { /* part of a chain */
107 if (p
->action
->func
!= NULL
) {
108 p
->action
->data
.any
.c
= focus_client
;
110 g_assert(!(p
->action
->func
== action_move
||
111 p
->action
->func
== action_resize
));
113 p
->action
->func(&p
->action
->data
);
123 XAllowEvents(ob_display
, AsyncKeyboard
, e
->data
.x
.e
->xkey
.time
);
126 static void binddef()
128 GList
*list
= g_list_append(NULL
, NULL
);
131 /* When creating an Action struct, all of the data elements in the
132 appropriate struct need to be set, except the Client*, which will be set
133 at call-time when then action function is used.
136 list
->data
= "A-Right";
137 a
= action_new(action_next_desktop
);
138 a
->data
.nextprevdesktop
.wrap
= TRUE
;
141 list
->data
= "A-Left";
142 a
= action_new(action_previous_desktop
);
143 a
->data
.nextprevdesktop
.wrap
= TRUE
;
147 a
= action_new(action_desktop
);
148 a
->data
.desktop
.desk
= 0;
152 a
= action_new(action_desktop
);
153 a
->data
.desktop
.desk
= 1;
157 a
= action_new(action_desktop
);
158 a
->data
.desktop
.desk
= 2;
162 a
= action_new(action_desktop
);
163 a
->data
.desktop
.desk
= 3;
166 list
->data
= "A-space";
167 a
= action_new(action_execute
);
168 a
->data
.execute
.path
= g_strdup("xterm");
171 list
->data
= "C-A-Escape";
172 a
= action_new(action_execute
);
173 a
->data
.execute
.path
= g_strdup("xlock -nolock -mode puzzle");
177 void plugin_startup()
179 dispatch_register(Event_X_KeyPress
, (EventHandler
)press
, NULL
);
181 /* XXX parse config file! */
185 void plugin_shutdown()
187 dispatch_register(0, (EventHandler
)press
, NULL
);
190 tree_destroy(firstnode
);
This page took 0.041303 seconds and 4 git commands to generate.