]>
Dogcows Code - chaz/openbox/blob - plugins/keyboard/keyboard.c
115c1182553c3c8947b191403d7b53be269901e9
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"
11 #include "translate.h"
14 void plugin_setup_config()
16 parse_reg_section("keyboard", keyparse
, NULL
);
19 KeyBindingTree
*firstnode
= NULL
;
21 static KeyBindingTree
*curpos
;
22 static guint reset_key
, reset_state
, button_return
, button_escape
;
23 static gboolean grabbed
;
25 static void grab_keys(gboolean grab
)
30 KeyBindingTree
*p
= firstnode
;
32 grab_key(p
->key
, p
->state
, GrabModeSync
);
38 static void reset_chains()
46 XAllowEvents(ob_display
, AsyncKeyboard
, event_lasttime
);
49 gboolean
kbind(GList
*keylist
, Action
*action
)
51 KeyBindingTree
*tree
, *t
;
54 g_assert(keylist
!= NULL
);
55 g_assert(action
!= NULL
);
57 if (!(tree
= tree_build(keylist
)))
59 if ((t
= tree_find(tree
, &conflict
)) != NULL
) {
60 /* already bound to something */
61 g_message("keychain is already bound");
66 g_message("conflict with binding");
71 /* grab the server here to make sure no key presses go missed */
77 while (t
->first_child
) t
= t
->first_child
;
79 /* assimilate this built tree into the main tree. assimilation
80 destroys/uses the tree */
81 tree_assimilate(tree
);
89 static void event(ObEvent
*e
, void *foo
)
91 static KeyBindingTree
*grabbed_key
= NULL
;
94 gboolean done
= FALSE
;
96 if ((e
->type
== Event_X_KeyRelease
&&
97 !(grabbed_key
->state
& e
->data
.x
.e
->xkey
.state
)))
99 else if (e
->type
== Event_X_KeyPress
) {
100 if (e
->data
.x
.e
->xkey
.keycode
== button_return
)
102 else if (e
->data
.x
.e
->xkey
.keycode
== button_escape
) {
103 grabbed_key
->action
->data
.cycle
.cancel
= TRUE
;
108 grabbed_key
->action
->data
.cycle
.final
= TRUE
;
109 grabbed_key
->action
->func(&grabbed_key
->action
->data
);
110 grab_keyboard(FALSE
);
116 if (e
->type
== Event_X_KeyRelease
)
119 g_assert(e
->type
== Event_X_KeyPress
);
121 if (e
->data
.x
.e
->xkey
.keycode
== reset_key
&&
122 e
->data
.x
.e
->xkey
.state
== reset_state
) {
129 p
= curpos
->first_child
;
131 if (p
->key
== e
->data
.x
.e
->xkey
.keycode
&&
132 p
->state
== e
->data
.x
.e
->xkey
.state
) {
133 if (p
->first_child
!= NULL
) { /* part of a chain */
138 XAllowEvents(ob_display
, AsyncKeyboard
,
143 if (p
->action
->func
!= NULL
) {
144 p
->action
->data
.any
.c
= focus_client
;
146 g_assert(!(p
->action
->func
== action_move
||
147 p
->action
->func
== action_resize
));
149 if (p
->action
->func
== action_cycle_windows
) {
150 p
->action
->data
.cycle
.final
= FALSE
;
151 p
->action
->data
.cycle
.cancel
= FALSE
;
154 p
->action
->func(&p
->action
->data
);
156 if (p
->action
->func
== action_cycle_windows
&&
172 void plugin_startup()
179 dispatch_register(Event_X_KeyPress
| Event_X_KeyRelease
, (EventHandler
)event
, NULL
);
181 translate_key("C-g", &reset_state
, &reset_key
);
182 translate_key("Escape", &i
, &button_escape
);
183 translate_key("Return", &i
, &button_return
);
186 void plugin_shutdown()
188 dispatch_register(0, (EventHandler
)event
, NULL
);
191 tree_destroy(firstnode
);
This page took 0.04396 seconds and 3 git commands to generate.