]>
Dogcows Code - chaz/openbox/blob - openbox/actions/desktop.c
1 #include "openbox/actions.h"
2 #include "openbox/screen.h"
3 #include "openbox/client.h"
4 #include "openbox/openbox.h"
5 #include "obt/keyboard.h"
31 static gpointer
setup_go_func(xmlNodePtr node
,
32 ObActionsIPreFunc
*pre
,
33 ObActionsIInputFunc
*input
,
34 ObActionsICancelFunc
*cancel
,
35 ObActionsIPostFunc
*post
);
36 static gpointer
setup_send_func(xmlNodePtr node
,
37 ObActionsIPreFunc
*pre
,
38 ObActionsIInputFunc
*input
,
39 ObActionsICancelFunc
*cancel
,
40 ObActionsIPostFunc
*post
);
41 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
43 static gboolean
i_pre_func(guint state
, gpointer options
);
44 static gboolean
i_input_func(guint initial_state
,
49 static void i_post_func(gpointer options
);
51 /* 3.4-compatibility */
52 static gpointer
setup_go_last_func(xmlNodePtr node
);
53 static gpointer
setup_send_last_func(xmlNodePtr node
);
54 static gpointer
setup_go_abs_func(xmlNodePtr node
);
55 static gpointer
setup_send_abs_func(xmlNodePtr node
);
56 static gpointer
setup_go_next_func(xmlNodePtr node
,
57 ObActionsIPreFunc
*pre
,
58 ObActionsIInputFunc
*input
,
59 ObActionsICancelFunc
*cancel
,
60 ObActionsIPostFunc
*post
);
61 static gpointer
setup_send_next_func(xmlNodePtr node
,
62 ObActionsIPreFunc
*pre
,
63 ObActionsIInputFunc
*input
,
64 ObActionsICancelFunc
*cancel
,
65 ObActionsIPostFunc
*post
);
66 static gpointer
setup_go_prev_func(xmlNodePtr node
,
67 ObActionsIPreFunc
*pre
,
68 ObActionsIInputFunc
*input
,
69 ObActionsICancelFunc
*cancel
,
70 ObActionsIPostFunc
*post
);
71 static gpointer
setup_send_prev_func(xmlNodePtr node
,
72 ObActionsIPreFunc
*pre
,
73 ObActionsIInputFunc
*input
,
74 ObActionsICancelFunc
*cancel
,
75 ObActionsIPostFunc
*post
);
76 static gpointer
setup_go_left_func(xmlNodePtr node
,
77 ObActionsIPreFunc
*pre
,
78 ObActionsIInputFunc
*input
,
79 ObActionsICancelFunc
*cancel
,
80 ObActionsIPostFunc
*post
);
81 static gpointer
setup_send_left_func(xmlNodePtr node
,
82 ObActionsIPreFunc
*pre
,
83 ObActionsIInputFunc
*input
,
84 ObActionsICancelFunc
*cancel
,
85 ObActionsIPostFunc
*post
);
86 static gpointer
setup_go_right_func(xmlNodePtr node
,
87 ObActionsIPreFunc
*pre
,
88 ObActionsIInputFunc
*input
,
89 ObActionsICancelFunc
*cancel
,
90 ObActionsIPostFunc
*post
);
91 static gpointer
setup_send_right_func(xmlNodePtr node
,
92 ObActionsIPreFunc
*pre
,
93 ObActionsIInputFunc
*input
,
94 ObActionsICancelFunc
*cancel
,
95 ObActionsIPostFunc
*post
);
96 static gpointer
setup_go_up_func(xmlNodePtr node
,
97 ObActionsIPreFunc
*pre
,
98 ObActionsIInputFunc
*input
,
99 ObActionsICancelFunc
*cancel
,
100 ObActionsIPostFunc
*post
);
101 static gpointer
setup_send_up_func(xmlNodePtr node
,
102 ObActionsIPreFunc
*pre
,
103 ObActionsIInputFunc
*input
,
104 ObActionsICancelFunc
*cancel
,
105 ObActionsIPostFunc
*post
);
106 static gpointer
setup_go_down_func(xmlNodePtr node
,
107 ObActionsIPreFunc
*pre
,
108 ObActionsIInputFunc
*input
,
109 ObActionsICancelFunc
*cancel
,
110 ObActionsIPostFunc
*post
);
111 static gpointer
setup_send_down_func(xmlNodePtr node
,
112 ObActionsIPreFunc
*pre
,
113 ObActionsIInputFunc
*input
,
114 ObActionsICancelFunc
*cancel
,
115 ObActionsIPostFunc
*post
);
117 void action_desktop_startup(void)
119 actions_register_i("GoToDesktop", setup_go_func
, g_free
, run_func
);
120 actions_register_i("SendToDesktop", setup_send_func
, g_free
, run_func
);
121 /* 3.4-compatibility */
122 actions_register("DesktopLast", setup_go_last_func
, g_free
, run_func
);
123 actions_register("SendToDesktopLast", setup_send_last_func
,
125 actions_register("Desktop", setup_go_abs_func
, g_free
, run_func
);
126 actions_register("SendToDesktop", setup_send_abs_func
, g_free
, run_func
);
127 actions_register_i("DesktopNext", setup_go_next_func
, g_free
, run_func
);
128 actions_register_i("SendToDesktopNext", setup_send_next_func
,
130 actions_register_i("DesktopPrevious", setup_go_prev_func
,
132 actions_register_i("SendToDesktopPrevious", setup_send_prev_func
,
134 actions_register_i("DesktopLeft", setup_go_left_func
, g_free
, run_func
);
135 actions_register_i("SendToDesktopLeft", setup_send_left_func
,
137 actions_register_i("DesktopRight", setup_go_right_func
, g_free
, run_func
);
138 actions_register_i("SendToDesktopRight", setup_send_right_func
,
140 actions_register_i("DesktopUp", setup_go_up_func
, g_free
, run_func
);
141 actions_register_i("SendToDesktopUp", setup_send_up_func
,
143 actions_register_i("DesktopDown", setup_go_down_func
, g_free
, run_func
);
144 actions_register_i("SendToDesktopDown", setup_send_down_func
,
148 static gpointer
setup_func(xmlNodePtr node
,
149 ObActionsIPreFunc
*pre
,
150 ObActionsIInputFunc
*input
,
151 ObActionsICancelFunc
*cancel
,
152 ObActionsIPostFunc
*post
)
157 o
= g_new0(Options
, 1);
158 /* don't go anywhere if there are no options given */
160 o
->u
.abs
.desktop
= screen_desktop
;
161 /* wrap by default - it's handy! */
162 o
->u
.rel
.wrap
= TRUE
;
164 if ((n
= obt_xml_find_node(node
, "to"))) {
165 gchar
*s
= obt_xml_node_string(n
);
166 if (!g_ascii_strcasecmp(s
, "last"))
168 else if (!g_ascii_strcasecmp(s
, "next")) {
170 o
->u
.rel
.linear
= TRUE
;
171 o
->u
.rel
.dir
= OB_DIRECTION_EAST
;
173 else if (!g_ascii_strcasecmp(s
, "previous")) {
175 o
->u
.rel
.linear
= TRUE
;
176 o
->u
.rel
.dir
= OB_DIRECTION_WEST
;
178 else if (!g_ascii_strcasecmp(s
, "north") ||
179 !g_ascii_strcasecmp(s
, "up")) {
181 o
->u
.rel
.dir
= OB_DIRECTION_NORTH
;
183 else if (!g_ascii_strcasecmp(s
, "south") ||
184 !g_ascii_strcasecmp(s
, "down")) {
186 o
->u
.rel
.dir
= OB_DIRECTION_SOUTH
;
188 else if (!g_ascii_strcasecmp(s
, "west") ||
189 !g_ascii_strcasecmp(s
, "left")) {
191 o
->u
.rel
.dir
= OB_DIRECTION_WEST
;
193 else if (!g_ascii_strcasecmp(s
, "east") ||
194 !g_ascii_strcasecmp(s
, "right")) {
196 o
->u
.rel
.dir
= OB_DIRECTION_EAST
;
200 o
->u
.abs
.desktop
= atoi(s
) - 1;
205 if ((n
= obt_xml_find_node(node
, "wrap")))
206 o
->u
.rel
.wrap
= obt_xml_node_bool(n
);
212 static gpointer
setup_go_func(xmlNodePtr node
,
213 ObActionsIPreFunc
*pre
,
214 ObActionsIInputFunc
*input
,
215 ObActionsICancelFunc
*cancel
,
216 ObActionsIPostFunc
*post
)
220 o
= setup_func(node
, pre
, input
, cancel
, post
);
221 if (o
->type
== RELATIVE
) {
222 o
->interactive
= TRUE
;
224 *input
= i_input_func
;
231 static gpointer
setup_send_func(xmlNodePtr node
,
232 ObActionsIPreFunc
*pre
,
233 ObActionsIInputFunc
*input
,
234 ObActionsICancelFunc
*cancel
,
235 ObActionsIPostFunc
*post
)
240 o
= setup_func(node
, pre
, input
, cancel
, post
);
244 if ((n
= obt_xml_find_node(node
, "follow")))
245 o
->follow
= obt_xml_node_bool(n
);
247 if (o
->type
== RELATIVE
&& o
->follow
) {
248 o
->interactive
= TRUE
;
250 *input
= i_input_func
;
257 /* Always return FALSE because its not interactive */
258 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
260 Options
*o
= options
;
265 d
= screen_last_desktop
;
268 d
= o
->u
.abs
.desktop
;
271 d
= screen_find_desktop(screen_desktop
,
272 o
->u
.rel
.dir
, o
->u
.rel
.wrap
, o
->u
.rel
.linear
);
275 g_assert_not_reached();
278 if (d
< screen_num_desktops
&& d
!= screen_desktop
) {
281 actions_client_move(data
, TRUE
);
282 if (o
->send
&& data
->client
&& client_normal(data
->client
)) {
283 client_set_desktop(data
->client
, d
, o
->follow
, FALSE
);
288 screen_set_desktop(d
, TRUE
);
290 client_bring_helper_windows(data
->client
);
293 actions_client_move(data
, FALSE
);
296 return o
->interactive
;
299 static gboolean
i_input_func(guint initial_state
,
307 mods
= obt_keyboard_only_modmasks(e
->xkey
.state
);
308 if (e
->type
== KeyRelease
) {
309 /* remove from the state the mask of the modifier key being
310 released, if it is a modifier key being released that is */
311 mods
&= ~obt_keyboard_keycode_to_modmask(e
->xkey
.keycode
);
314 if (e
->type
== KeyPress
) {
315 KeySym sym
= obt_keyboard_keypress_to_keysym(e
);
317 /* Escape cancels no matter what */
318 if (sym
== XK_Escape
)
321 /* There were no modifiers and they pressed enter */
322 else if (sym
== XK_Return
&& !initial_state
)
325 /* They released the modifiers */
326 else if (e
->type
== KeyRelease
&& initial_state
&& !(mods
& initial_state
))
334 static gboolean
i_pre_func(guint initial_state
, gpointer options
)
336 if (!initial_state
) {
337 Options
*o
= options
;
338 o
->interactive
= FALSE
;
342 screen_show_desktop_popup(screen_desktop
, TRUE
);
347 static void i_post_func(gpointer options
)
349 screen_hide_desktop_popup();
352 /* 3.4-compatilibity */
353 static gpointer
setup_follow(xmlNodePtr node
)
356 Options
*o
= g_new0(Options
, 1);
359 if ((n
= obt_xml_find_node(node
, "follow")))
360 o
->follow
= obt_xml_node_bool(n
);
364 static gpointer
setup_go_last_func(xmlNodePtr node
)
366 Options
*o
= g_new0(Options
, 1);
371 static gpointer
setup_send_last_func(xmlNodePtr node
)
373 Options
*o
= setup_follow(node
);
378 static gpointer
setup_go_abs_func(xmlNodePtr node
)
381 Options
*o
= g_new0(Options
, 1);
383 if ((n
= obt_xml_find_node(node
, "desktop")))
384 o
->u
.abs
.desktop
= obt_xml_node_int(n
) - 1;
386 o
->u
.abs
.desktop
= screen_desktop
;
390 static gpointer
setup_send_abs_func(xmlNodePtr node
)
393 Options
*o
= setup_follow(node
);
395 if ((n
= obt_xml_find_node(node
, "desktop")))
396 o
->u
.abs
.desktop
= obt_xml_node_int(n
) - 1;
398 o
->u
.abs
.desktop
= screen_desktop
;
402 static void setup_rel(Options
*o
, xmlNodePtr node
, gboolean lin
,
404 ObActionsIPreFunc
*pre
,
405 ObActionsIInputFunc
*input
,
406 ObActionsIPostFunc
*post
)
411 o
->u
.rel
.linear
= lin
;
413 o
->u
.rel
.wrap
= TRUE
;
415 if ((n
= obt_xml_find_node(node
, "wrap")))
416 o
->u
.rel
.wrap
= obt_xml_node_bool(n
);
419 o
->interactive
= TRUE
;
421 *input
= i_input_func
;
426 static gpointer
setup_go_next_func(xmlNodePtr node
,
427 ObActionsIPreFunc
*pre
,
428 ObActionsIInputFunc
*input
,
429 ObActionsICancelFunc
*cancel
,
430 ObActionsIPostFunc
*post
)
432 Options
*o
= g_new0(Options
, 1);
433 setup_rel(o
, node
, TRUE
, OB_DIRECTION_EAST
, pre
, input
, post
);
437 static gpointer
setup_send_next_func(xmlNodePtr node
,
438 ObActionsIPreFunc
*pre
,
439 ObActionsIInputFunc
*input
,
440 ObActionsICancelFunc
*cancel
,
441 ObActionsIPostFunc
*post
)
443 Options
*o
= setup_follow(node
);
444 setup_rel(o
, node
, TRUE
, OB_DIRECTION_EAST
,
445 pre
, (o
->follow
? input
: NULL
), post
);
449 static gpointer
setup_go_prev_func(xmlNodePtr node
,
450 ObActionsIPreFunc
*pre
,
451 ObActionsIInputFunc
*input
,
452 ObActionsICancelFunc
*cancel
,
453 ObActionsIPostFunc
*post
)
455 Options
*o
= g_new0(Options
, 1);
456 setup_rel(o
, node
, TRUE
, OB_DIRECTION_WEST
, pre
, input
, post
);
460 static gpointer
setup_send_prev_func(xmlNodePtr node
,
461 ObActionsIPreFunc
*pre
,
462 ObActionsIInputFunc
*input
,
463 ObActionsICancelFunc
*cancel
,
464 ObActionsIPostFunc
*post
)
466 Options
*o
= setup_follow(node
);
467 setup_rel(o
, node
, TRUE
, OB_DIRECTION_WEST
,
468 pre
, (o
->follow
? input
: NULL
), post
);
472 static gpointer
setup_go_left_func(xmlNodePtr node
,
473 ObActionsIPreFunc
*pre
,
474 ObActionsIInputFunc
*input
,
475 ObActionsICancelFunc
*cancel
,
476 ObActionsIPostFunc
*post
)
478 Options
*o
= g_new0(Options
, 1);
479 setup_rel(o
, node
, FALSE
, OB_DIRECTION_WEST
, pre
, input
, post
);
483 static gpointer
setup_send_left_func(xmlNodePtr node
,
484 ObActionsIPreFunc
*pre
,
485 ObActionsIInputFunc
*input
,
486 ObActionsICancelFunc
*cancel
,
487 ObActionsIPostFunc
*post
)
489 Options
*o
= setup_follow(node
);
490 setup_rel(o
, node
, FALSE
, OB_DIRECTION_WEST
,
491 pre
, (o
->follow
? input
: NULL
), post
);
495 static gpointer
setup_go_right_func(xmlNodePtr node
,
496 ObActionsIPreFunc
*pre
,
497 ObActionsIInputFunc
*input
,
498 ObActionsICancelFunc
*cancel
,
499 ObActionsIPostFunc
*post
)
501 Options
*o
= g_new0(Options
, 1);
502 setup_rel(o
, node
, FALSE
, OB_DIRECTION_EAST
, pre
, input
, post
);
506 static gpointer
setup_send_right_func(xmlNodePtr node
,
507 ObActionsIPreFunc
*pre
,
508 ObActionsIInputFunc
*input
,
509 ObActionsICancelFunc
*cancel
,
510 ObActionsIPostFunc
*post
)
512 Options
*o
= setup_follow(node
);
513 setup_rel(o
, node
, FALSE
, OB_DIRECTION_EAST
,
514 pre
, (o
->follow
? input
: NULL
), post
);
518 static gpointer
setup_go_up_func(xmlNodePtr node
,
519 ObActionsIPreFunc
*pre
,
520 ObActionsIInputFunc
*input
,
521 ObActionsICancelFunc
*cancel
,
522 ObActionsIPostFunc
*post
)
524 Options
*o
= g_new0(Options
, 1);
525 setup_rel(o
, node
, FALSE
, OB_DIRECTION_NORTH
, pre
, input
, post
);
529 static gpointer
setup_send_up_func(xmlNodePtr node
,
530 ObActionsIPreFunc
*pre
,
531 ObActionsIInputFunc
*input
,
532 ObActionsICancelFunc
*cancel
,
533 ObActionsIPostFunc
*post
)
535 Options
*o
= setup_follow(node
);
536 setup_rel(o
, node
, FALSE
, OB_DIRECTION_NORTH
,
537 pre
, (o
->follow
? input
: NULL
), post
);
541 static gpointer
setup_go_down_func(xmlNodePtr node
,
542 ObActionsIPreFunc
*pre
,
543 ObActionsIInputFunc
*input
,
544 ObActionsICancelFunc
*cancel
,
545 ObActionsIPostFunc
*post
)
547 Options
*o
= g_new0(Options
, 1);
548 setup_rel(o
, node
, FALSE
, OB_DIRECTION_SOUTH
, pre
, input
, post
);
552 static gpointer
setup_send_down_func(xmlNodePtr node
,
553 ObActionsIPreFunc
*pre
,
554 ObActionsIInputFunc
*input
,
555 ObActionsICancelFunc
*cancel
,
556 ObActionsIPostFunc
*post
)
558 Options
*o
= setup_follow(node
);
559 setup_rel(o
, node
, FALSE
, OB_DIRECTION_SOUTH
,
560 pre
, (o
->follow
? input
: NULL
), post
);
This page took 0.057967 seconds and 4 git commands to generate.