13 #include "translate.h"
17 KeyBindingTree
*keyboard_firstnode
;
19 static KeyBindingTree
*curpos
;
20 static ObTimer
*chain_timer
;
21 static gboolean interactive_grab
;
22 static guint grabbed_state
;
23 static ObClient
*grabbed_client
;
24 static ObAction
*grabbed_action
;
25 static ObFrameContext grabbed_context
;
27 static void grab_for_window(Window win
, gboolean grab
)
34 p
= curpos
? curpos
->first_child
: keyboard_firstnode
;
36 grab_key(p
->key
, p
->state
, win
, GrabModeAsync
);
42 void keyboard_grab_for_client(ObClient
*c
, gboolean grab
)
44 grab_for_window(c
->window
, grab
);
47 static void grab_keys(gboolean grab
)
51 grab_for_window(screen_support_win
, grab
);
52 for (it
= client_list
; it
; it
= g_list_next(it
))
53 grab_for_window(((ObClient
*)it
->data
)->frame
->window
, grab
);
56 void keyboard_reset_chains()
59 timer_stop(chain_timer
);
68 static void chain_timeout(ObTimer
*t
, void *data
)
70 keyboard_reset_chains();
73 gboolean
keyboard_bind(GList
*keylist
, ObAction
*action
)
75 KeyBindingTree
*tree
, *t
;
78 g_assert(keylist
!= NULL
);
79 g_assert(action
!= NULL
);
81 if (!(tree
= tree_build(keylist
)))
84 if ((t
= tree_find(tree
, &conflict
)) != NULL
) {
85 /* already bound to something, use the existing tree */
90 while (t
->first_child
) t
= t
->first_child
;
93 g_warning("conflict with binding");
99 t
->actions
= g_slist_append(t
->actions
, action
);
100 /* assimilate this built tree into the main tree. assimilation
101 destroys/uses the tree */
102 if (tree
) tree_assimilate(tree
);
107 void keyboard_interactive_grab(guint state
, ObClient
*client
,
108 ObFrameContext context
, ObAction
*action
)
110 if (!interactive_grab
&& grab_keyboard(TRUE
)) {
111 interactive_grab
= TRUE
;
112 grabbed_state
= state
;
113 grabbed_client
= client
;
114 grabbed_action
= action
;
115 grabbed_context
= context
;
116 grab_pointer(TRUE
, None
);
120 gboolean
keyboard_process_interactive_grab(const XEvent
*e
,
122 ObFrameContext
*context
)
124 gboolean handled
= FALSE
;
125 gboolean done
= FALSE
;
127 if (interactive_grab
) {
128 *client
= grabbed_client
;
129 *context
= grabbed_context
;
131 if ((e
->type
== KeyRelease
&&
132 !(grabbed_state
& e
->xkey
.state
)))
134 else if (e
->type
== KeyPress
) {
135 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
))
137 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
)) {
138 if (grabbed_action
->func
== action_cycle_windows
) {
139 grabbed_action
->data
.cycle
.cancel
= TRUE
;
141 if (grabbed_action
->func
== action_desktop_dir
) {
142 grabbed_action
->data
.desktopdir
.cancel
= TRUE
;
144 if (grabbed_action
->func
== action_send_to_desktop_dir
)
146 grabbed_action
->data
.sendtodir
.cancel
= TRUE
;
152 if (grabbed_action
->func
== action_cycle_windows
) {
153 grabbed_action
->data
.cycle
.final
= TRUE
;
155 if (grabbed_action
->func
== action_desktop_dir
) {
156 grabbed_action
->data
.desktopdir
.final
= TRUE
;
158 if (grabbed_action
->func
== action_send_to_desktop_dir
) {
159 grabbed_action
->data
.sendtodir
.final
= TRUE
;
162 grabbed_action
->func(&grabbed_action
->data
);
164 interactive_grab
= FALSE
;
165 grab_keyboard(FALSE
);
166 grab_pointer(FALSE
, None
);
167 keyboard_reset_chains();
176 void keyboard_event(ObClient
*client
, const XEvent
*e
)
180 g_assert(e
->type
== KeyPress
);
183 p
= keyboard_firstnode
;
185 p
= curpos
->first_child
;
187 if (p
->key
== e
->xkey
.keycode
&&
188 p
->state
== e
->xkey
.state
) {
189 if (p
->first_child
!= NULL
) { /* part of a chain */
190 if (chain_timer
) timer_stop(chain_timer
);
191 /* 5 second timeout for chains */
192 chain_timer
= timer_start(5000*1000, chain_timeout
,
198 for (it
= p
->actions
; it
; it
= it
->next
) {
199 ObAction
*act
= it
->data
;
200 if (act
->func
!= NULL
) {
201 act
->data
.any
.c
= client
;
203 if (act
->func
== action_cycle_windows
)
205 act
->data
.cycle
.final
= FALSE
;
206 act
->data
.cycle
.cancel
= FALSE
;
208 if (act
->func
== action_desktop_dir
)
210 act
->data
.desktopdir
.final
= FALSE
;
211 act
->data
.desktopdir
.cancel
= FALSE
;
213 if (act
->func
== action_send_to_desktop_dir
)
215 act
->data
.sendtodir
.final
= FALSE
;
216 act
->data
.sendtodir
.cancel
= FALSE
;
219 if (act
->func
== action_moveresize
)
221 screen_pointer_pos(&act
->data
.moveresize
.x
,
222 &act
->data
.moveresize
.y
);
225 if ((act
->func
== action_cycle_windows
||
226 act
->func
== action_desktop_dir
||
227 act
->func
== action_send_to_desktop_dir
))
229 keyboard_interactive_grab(e
->xkey
.state
, client
,
233 if (act
->func
== action_showmenu
)
235 act
->data
.showmenu
.x
=
237 act
->data
.showmenu
.y
=
241 act
->data
.any
.c
= client
;
242 act
->func(&act
->data
);
246 keyboard_reset_chains();
254 void keyboard_startup()
259 void keyboard_shutdown()
261 tree_destroy(keyboard_firstnode
);
262 keyboard_firstnode
= NULL
;