]>
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/event.h"
5 #include "kernel/grab.h"
6 #include "kernel/action.h"
7 #include "kernel/parse.h"
8 #include "kernel/timer.h"
12 #include "translate.h"
15 void plugin_setup_config()
17 parse_reg_section("keyboard", keyparse
, NULL
);
20 KeyBindingTree
*firstnode
= NULL
;
22 static KeyBindingTree
*curpos
;
23 static guint reset_key
, reset_state
, button_return
, button_escape
;
24 static Timer
*chain_timer
;
26 static void grab_keys()
32 p
= curpos
? curpos
->first_child
: firstnode
;
34 grab_key(p
->key
, p
->state
, GrabModeAsync
);
38 grab_key(reset_key
, reset_state
, GrabModeAsync
);
41 static void reset_chains()
44 timer_stop(chain_timer
);
53 static void chain_timeout(void *data
)
58 gboolean
kbind(GList
*keylist
, Action
*action
)
60 KeyBindingTree
*tree
, *t
;
63 g_assert(keylist
!= NULL
);
64 g_assert(action
!= NULL
);
66 if (!(tree
= tree_build(keylist
)))
69 if ((t
= tree_find(tree
, &conflict
)) != NULL
) {
70 /* already bound to something, use the existing tree */
75 while (t
->first_child
) t
= t
->first_child
;
78 g_message("conflict with binding");
84 t
->actions
= g_slist_append(t
->actions
, action
);
85 /* assimilate this built tree into the main tree. assimilation
86 destroys/uses the tree */
87 if (tree
) tree_assimilate(tree
);
92 static void event(ObEvent
*e
, void *foo
)
94 static KeyBindingTree
*grabbed_key
= NULL
;
97 gboolean done
= FALSE
;
99 if ((e
->type
== Event_X_KeyRelease
&&
100 !(grabbed_key
->state
& e
->data
.x
.e
->xkey
.state
)))
102 else if (e
->type
== Event_X_KeyPress
) {
103 if (e
->data
.x
.e
->xkey
.keycode
== button_return
)
105 else if (e
->data
.x
.e
->xkey
.keycode
== button_escape
) {
107 for (it
= grabbed_key
->actions
; it
; it
= it
->next
) {
108 Action
*act
= it
->data
;
109 act
->data
.cycle
.cancel
= TRUE
;
116 for (it
= grabbed_key
->actions
; it
; it
= it
->next
) {
117 Action
*act
= it
->data
;
118 act
->data
.cycle
.final
= TRUE
;
119 act
->func(&act
->data
);
121 grab_keyboard(FALSE
);
127 if (e
->type
== Event_X_KeyRelease
)
130 g_assert(e
->type
== Event_X_KeyPress
);
132 if (e
->data
.x
.e
->xkey
.keycode
== reset_key
&&
133 e
->data
.x
.e
->xkey
.state
== reset_state
) {
140 p
= curpos
->first_child
;
142 if (p
->key
== e
->data
.x
.e
->xkey
.keycode
&&
143 p
->state
== e
->data
.x
.e
->xkey
.state
) {
144 if (p
->first_child
!= NULL
) { /* part of a chain */
145 if (chain_timer
) timer_stop(chain_timer
);
146 /* 5 second timeout for chains */
147 chain_timer
= timer_start(5000*1000, chain_timeout
,
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
&&
183 void plugin_startup()
190 dispatch_register(Event_X_KeyPress
| Event_X_KeyRelease
,
191 (EventHandler
)event
, NULL
);
193 translate_key("C-g", &reset_state
, &reset_key
);
194 translate_key("Escape", &i
, &button_escape
);
195 translate_key("Return", &i
, &button_return
);
200 void plugin_shutdown()
202 dispatch_register(0, (EventHandler
)event
, NULL
);
204 tree_destroy(firstnode
);
This page took 0.040947 seconds and 4 git commands to generate.