]>
Dogcows Code - chaz/openbox/blob - keyboard.c
acda951a452e59e0a46a3289fb109c3a2f5d7550
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
)))
60 if ((t
= tree_find(tree
, &conflict
)) != NULL
) {
61 /* already bound to something, use the existing tree */
66 while (t
->first_child
) t
= t
->first_child
;
69 g_message("conflict with binding");
74 /* grab the server here to make sure no key presses go missed */
79 t
->actions
= g_slist_append(t
->actions
, action
);
80 /* assimilate this built tree into the main tree. assimilation
81 destroys/uses the tree */
82 if (tree
) tree_assimilate(tree
);
90 static void event(ObEvent
*e
, void *foo
)
92 static KeyBindingTree
*grabbed_key
= NULL
;
95 gboolean done
= FALSE
;
97 if ((e
->type
== Event_X_KeyRelease
&&
98 !(grabbed_key
->state
& e
->data
.x
.e
->xkey
.state
)))
100 else if (e
->type
== Event_X_KeyPress
) {
101 if (e
->data
.x
.e
->xkey
.keycode
== button_return
)
103 else if (e
->data
.x
.e
->xkey
.keycode
== button_escape
) {
105 for (it
= grabbed_key
->actions
; it
; it
= it
->next
) {
106 Action
*act
= it
->data
;
107 act
->data
.cycle
.cancel
= TRUE
;
114 for (it
= grabbed_key
->actions
; it
; it
= it
->next
) {
115 Action
*act
= it
->data
;
116 act
->data
.cycle
.final
= TRUE
;
117 act
->func(&act
->data
);
118 grab_keyboard(FALSE
);
125 if (e
->type
== Event_X_KeyRelease
)
128 g_assert(e
->type
== Event_X_KeyPress
);
130 if (e
->data
.x
.e
->xkey
.keycode
== reset_key
&&
131 e
->data
.x
.e
->xkey
.state
== reset_state
) {
138 p
= curpos
->first_child
;
140 if (p
->key
== e
->data
.x
.e
->xkey
.keycode
&&
141 p
->state
== e
->data
.x
.e
->xkey
.state
) {
142 if (p
->first_child
!= NULL
) { /* part of a chain */
147 XAllowEvents(ob_display
, AsyncKeyboard
,
153 for (it
= p
->actions
; it
; it
= it
->next
) {
154 Action
*act
= it
->data
;
155 if (act
->func
!= NULL
) {
156 act
->data
.any
.c
= focus_client
;
158 if (act
->func
== action_cycle_windows
) {
159 act
->data
.cycle
.final
= FALSE
;
160 act
->data
.cycle
.cancel
= FALSE
;
163 act
->func(&act
->data
);
165 if (act
->func
== action_cycle_windows
&&
182 void plugin_startup()
189 dispatch_register(Event_X_KeyPress
| Event_X_KeyRelease
, (EventHandler
)event
, NULL
);
191 translate_key("C-g", &reset_state
, &reset_key
);
192 translate_key("Escape", &i
, &button_escape
);
193 translate_key("Return", &i
, &button_return
);
196 void plugin_shutdown()
198 dispatch_register(0, (EventHandler
)event
, NULL
);
201 tree_destroy(firstnode
);
This page took 0.040586 seconds and 3 git commands to generate.