]>
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"
32 static gpointer
setup_go_func(xmlNodePtr node
,
33 ObActionsIPreFunc
*pre
,
34 ObActionsIInputFunc
*input
,
35 ObActionsICancelFunc
*cancel
,
36 ObActionsIPostFunc
*post
);
37 static gpointer
setup_send_func(xmlNodePtr node
,
38 ObActionsIPreFunc
*pre
,
39 ObActionsIInputFunc
*input
,
40 ObActionsICancelFunc
*cancel
,
41 ObActionsIPostFunc
*post
);
42 static void free_func(gpointer o
);
43 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
45 static gboolean
i_pre_func(guint state
, gpointer options
);
46 static gboolean
i_input_func(guint initial_state
,
51 static void i_post_func(gpointer options
);
53 /* 3.4-compatibility */
54 static gpointer
setup_go_last_func(xmlNodePtr node
);
55 static gpointer
setup_send_last_func(xmlNodePtr node
);
56 static gpointer
setup_go_abs_func(xmlNodePtr node
);
57 static gpointer
setup_go_next_func(xmlNodePtr node
,
58 ObActionsIPreFunc
*pre
,
59 ObActionsIInputFunc
*input
,
60 ObActionsICancelFunc
*cancel
,
61 ObActionsIPostFunc
*post
);
62 static gpointer
setup_send_next_func(xmlNodePtr node
,
63 ObActionsIPreFunc
*pre
,
64 ObActionsIInputFunc
*input
,
65 ObActionsICancelFunc
*cancel
,
66 ObActionsIPostFunc
*post
);
67 static gpointer
setup_go_prev_func(xmlNodePtr node
,
68 ObActionsIPreFunc
*pre
,
69 ObActionsIInputFunc
*input
,
70 ObActionsICancelFunc
*cancel
,
71 ObActionsIPostFunc
*post
);
72 static gpointer
setup_send_prev_func(xmlNodePtr node
,
73 ObActionsIPreFunc
*pre
,
74 ObActionsIInputFunc
*input
,
75 ObActionsICancelFunc
*cancel
,
76 ObActionsIPostFunc
*post
);
77 static gpointer
setup_go_left_func(xmlNodePtr node
,
78 ObActionsIPreFunc
*pre
,
79 ObActionsIInputFunc
*input
,
80 ObActionsICancelFunc
*cancel
,
81 ObActionsIPostFunc
*post
);
82 static gpointer
setup_send_left_func(xmlNodePtr node
,
83 ObActionsIPreFunc
*pre
,
84 ObActionsIInputFunc
*input
,
85 ObActionsICancelFunc
*cancel
,
86 ObActionsIPostFunc
*post
);
87 static gpointer
setup_go_right_func(xmlNodePtr node
,
88 ObActionsIPreFunc
*pre
,
89 ObActionsIInputFunc
*input
,
90 ObActionsICancelFunc
*cancel
,
91 ObActionsIPostFunc
*post
);
92 static gpointer
setup_send_right_func(xmlNodePtr node
,
93 ObActionsIPreFunc
*pre
,
94 ObActionsIInputFunc
*input
,
95 ObActionsICancelFunc
*cancel
,
96 ObActionsIPostFunc
*post
);
97 static gpointer
setup_go_up_func(xmlNodePtr node
,
98 ObActionsIPreFunc
*pre
,
99 ObActionsIInputFunc
*input
,
100 ObActionsICancelFunc
*cancel
,
101 ObActionsIPostFunc
*post
);
102 static gpointer
setup_send_up_func(xmlNodePtr node
,
103 ObActionsIPreFunc
*pre
,
104 ObActionsIInputFunc
*input
,
105 ObActionsICancelFunc
*cancel
,
106 ObActionsIPostFunc
*post
);
107 static gpointer
setup_go_down_func(xmlNodePtr node
,
108 ObActionsIPreFunc
*pre
,
109 ObActionsIInputFunc
*input
,
110 ObActionsICancelFunc
*cancel
,
111 ObActionsIPostFunc
*post
);
112 static gpointer
setup_send_down_func(xmlNodePtr node
,
113 ObActionsIPreFunc
*pre
,
114 ObActionsIInputFunc
*input
,
115 ObActionsICancelFunc
*cancel
,
116 ObActionsIPostFunc
*post
);
118 void action_desktop_startup(void)
120 actions_register_i("GoToDesktop", setup_go_func
, free_func
, run_func
);
121 actions_register_i("SendToDesktop", setup_send_func
, free_func
, run_func
);
122 /* 3.4-compatibility */
123 actions_register("DesktopLast", setup_go_last_func
, free_func
, run_func
);
124 actions_register("SendToDesktopLast", setup_send_last_func
,
125 free_func
, run_func
);
126 actions_register("Desktop", setup_go_abs_func
, free_func
, run_func
);
127 actions_register_i("DesktopNext", setup_go_next_func
, free_func
, run_func
);
128 actions_register_i("SendToDesktopNext", setup_send_next_func
,
129 free_func
, run_func
);
130 actions_register_i("DesktopPrevious", setup_go_prev_func
,
131 free_func
, run_func
);
132 actions_register_i("SendToDesktopPrevious", setup_send_prev_func
,
133 free_func
, run_func
);
134 actions_register_i("DesktopLeft", setup_go_left_func
, free_func
, run_func
);
135 actions_register_i("SendToDesktopLeft", setup_send_left_func
,
136 free_func
, run_func
);
137 actions_register_i("DesktopRight", setup_go_right_func
,
138 free_func
, run_func
);
139 actions_register_i("SendToDesktopRight", setup_send_right_func
,
140 free_func
, run_func
);
141 actions_register_i("DesktopUp", setup_go_up_func
, free_func
, run_func
);
142 actions_register_i("SendToDesktopUp", setup_send_up_func
,
143 free_func
, run_func
);
144 actions_register_i("DesktopDown", setup_go_down_func
, free_func
, run_func
);
145 actions_register_i("SendToDesktopDown", setup_send_down_func
,
146 free_func
, run_func
);
149 static gpointer
setup_func(xmlNodePtr node
,
150 ObActionsIPreFunc
*pre
,
151 ObActionsIInputFunc
*input
,
152 ObActionsICancelFunc
*cancel
,
153 ObActionsIPostFunc
*post
)
158 o
= g_slice_new0(Options
);
159 /* don't go anywhere if there are no options given */
161 o
->u
.abs
.desktop
= screen_desktop
;
162 /* wrap by default - it's handy! */
163 o
->u
.rel
.wrap
= TRUE
;
165 if ((n
= obt_xml_find_node(node
, "to"))) {
166 gchar
*s
= obt_xml_node_string(n
);
167 if (!g_ascii_strcasecmp(s
, "last"))
169 else if (!g_ascii_strcasecmp(s
, "current"))
171 else if (!g_ascii_strcasecmp(s
, "next")) {
173 o
->u
.rel
.linear
= TRUE
;
174 o
->u
.rel
.dir
= OB_DIRECTION_EAST
;
176 else if (!g_ascii_strcasecmp(s
, "previous")) {
178 o
->u
.rel
.linear
= TRUE
;
179 o
->u
.rel
.dir
= OB_DIRECTION_WEST
;
181 else if (!g_ascii_strcasecmp(s
, "north") ||
182 !g_ascii_strcasecmp(s
, "up")) {
184 o
->u
.rel
.dir
= OB_DIRECTION_NORTH
;
186 else if (!g_ascii_strcasecmp(s
, "south") ||
187 !g_ascii_strcasecmp(s
, "down")) {
189 o
->u
.rel
.dir
= OB_DIRECTION_SOUTH
;
191 else if (!g_ascii_strcasecmp(s
, "west") ||
192 !g_ascii_strcasecmp(s
, "left")) {
194 o
->u
.rel
.dir
= OB_DIRECTION_WEST
;
196 else if (!g_ascii_strcasecmp(s
, "east") ||
197 !g_ascii_strcasecmp(s
, "right")) {
199 o
->u
.rel
.dir
= OB_DIRECTION_EAST
;
203 o
->u
.abs
.desktop
= atoi(s
) - 1;
208 if ((n
= obt_xml_find_node(node
, "wrap")))
209 o
->u
.rel
.wrap
= obt_xml_node_bool(n
);
215 static gpointer
setup_go_func(xmlNodePtr node
,
216 ObActionsIPreFunc
*pre
,
217 ObActionsIInputFunc
*input
,
218 ObActionsICancelFunc
*cancel
,
219 ObActionsIPostFunc
*post
)
223 o
= setup_func(node
, pre
, input
, cancel
, post
);
224 if (o
->type
== RELATIVE
) {
225 o
->interactive
= TRUE
;
227 *input
= i_input_func
;
234 static gpointer
setup_send_func(xmlNodePtr node
,
235 ObActionsIPreFunc
*pre
,
236 ObActionsIInputFunc
*input
,
237 ObActionsICancelFunc
*cancel
,
238 ObActionsIPostFunc
*post
)
243 o
= setup_func(node
, pre
, input
, cancel
, post
);
244 if ((n
= obt_xml_find_node(node
, "desktop"))) {
245 /* 3.4 compatibility */
246 o
->u
.abs
.desktop
= obt_xml_node_int(n
) - 1;
252 if ((n
= obt_xml_find_node(node
, "follow")))
253 o
->follow
= obt_xml_node_bool(n
);
255 if (o
->type
== RELATIVE
&& o
->follow
) {
256 o
->interactive
= TRUE
;
258 *input
= i_input_func
;
265 static void free_func(gpointer o
)
267 g_slice_free(Options
, o
);
270 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
272 Options
*o
= options
;
277 d
= screen_last_desktop
;
283 d
= o
->u
.abs
.desktop
;
286 d
= screen_find_desktop(screen_desktop
,
287 o
->u
.rel
.dir
, o
->u
.rel
.wrap
, o
->u
.rel
.linear
);
290 g_assert_not_reached();
293 if (d
< screen_num_desktops
&&
294 (d
!= screen_desktop
||
295 (data
->client
&& data
->client
->desktop
!= screen_desktop
))) {
298 actions_client_move(data
, TRUE
);
299 if (o
->send
&& data
->client
&& client_normal(data
->client
)) {
300 client_set_desktop(data
->client
, d
, o
->follow
, FALSE
);
305 screen_set_desktop(d
, TRUE
);
307 client_bring_helper_windows(data
->client
);
310 actions_client_move(data
, FALSE
);
313 return o
->interactive
;
316 static gboolean
i_input_func(guint initial_state
,
324 mods
= obt_keyboard_only_modmasks(e
->xkey
.state
);
325 if (e
->type
== KeyRelease
) {
326 /* remove from the state the mask of the modifier key being
327 released, if it is a modifier key being released that is */
328 mods
&= ~obt_keyboard_keyevent_to_modmask(e
);
331 if (e
->type
== KeyPress
) {
332 KeySym sym
= obt_keyboard_keypress_to_keysym(e
);
334 /* Escape cancels no matter what */
335 if (sym
== XK_Escape
)
338 /* There were no modifiers and they pressed enter */
339 else if ((sym
== XK_Return
|| sym
== XK_KP_Enter
) && !initial_state
)
342 /* They released the modifiers */
343 else if (e
->type
== KeyRelease
&& initial_state
&& !(mods
& initial_state
))
351 static gboolean
i_pre_func(guint initial_state
, gpointer options
)
353 if (!initial_state
) {
354 Options
*o
= options
;
355 o
->interactive
= FALSE
;
359 screen_show_desktop_popup(screen_desktop
, TRUE
);
364 static void i_post_func(gpointer options
)
366 screen_hide_desktop_popup();
369 /* 3.4-compatilibity */
370 static gpointer
setup_follow(xmlNodePtr node
)
373 Options
*o
= g_slice_new0(Options
);
376 if ((n
= obt_xml_find_node(node
, "follow")))
377 o
->follow
= obt_xml_node_bool(n
);
381 static gpointer
setup_go_last_func(xmlNodePtr node
)
383 Options
*o
= g_slice_new0(Options
);
388 static gpointer
setup_send_last_func(xmlNodePtr node
)
390 Options
*o
= setup_follow(node
);
395 static gpointer
setup_go_abs_func(xmlNodePtr node
)
398 Options
*o
= g_slice_new0(Options
);
400 if ((n
= obt_xml_find_node(node
, "desktop")))
401 o
->u
.abs
.desktop
= obt_xml_node_int(n
) - 1;
403 o
->u
.abs
.desktop
= screen_desktop
;
407 static void setup_rel(Options
*o
, xmlNodePtr node
, gboolean lin
,
409 ObActionsIPreFunc
*pre
,
410 ObActionsIInputFunc
*input
,
411 ObActionsIPostFunc
*post
)
416 o
->u
.rel
.linear
= lin
;
418 o
->u
.rel
.wrap
= TRUE
;
420 if ((n
= obt_xml_find_node(node
, "wrap")))
421 o
->u
.rel
.wrap
= obt_xml_node_bool(n
);
424 o
->interactive
= TRUE
;
426 *input
= i_input_func
;
431 static gpointer
setup_go_next_func(xmlNodePtr node
,
432 ObActionsIPreFunc
*pre
,
433 ObActionsIInputFunc
*input
,
434 ObActionsICancelFunc
*cancel
,
435 ObActionsIPostFunc
*post
)
437 Options
*o
= g_slice_new0(Options
);
438 setup_rel(o
, node
, TRUE
, OB_DIRECTION_EAST
, pre
, input
, post
);
442 static gpointer
setup_send_next_func(xmlNodePtr node
,
443 ObActionsIPreFunc
*pre
,
444 ObActionsIInputFunc
*input
,
445 ObActionsICancelFunc
*cancel
,
446 ObActionsIPostFunc
*post
)
448 Options
*o
= setup_follow(node
);
449 setup_rel(o
, node
, TRUE
, OB_DIRECTION_EAST
,
450 pre
, (o
->follow
? input
: NULL
), post
);
454 static gpointer
setup_go_prev_func(xmlNodePtr node
,
455 ObActionsIPreFunc
*pre
,
456 ObActionsIInputFunc
*input
,
457 ObActionsICancelFunc
*cancel
,
458 ObActionsIPostFunc
*post
)
460 Options
*o
= g_slice_new0(Options
);
461 setup_rel(o
, node
, TRUE
, OB_DIRECTION_WEST
, pre
, input
, post
);
465 static gpointer
setup_send_prev_func(xmlNodePtr node
,
466 ObActionsIPreFunc
*pre
,
467 ObActionsIInputFunc
*input
,
468 ObActionsICancelFunc
*cancel
,
469 ObActionsIPostFunc
*post
)
471 Options
*o
= setup_follow(node
);
472 setup_rel(o
, node
, TRUE
, OB_DIRECTION_WEST
,
473 pre
, (o
->follow
? input
: NULL
), post
);
477 static gpointer
setup_go_left_func(xmlNodePtr node
,
478 ObActionsIPreFunc
*pre
,
479 ObActionsIInputFunc
*input
,
480 ObActionsICancelFunc
*cancel
,
481 ObActionsIPostFunc
*post
)
483 Options
*o
= g_slice_new0(Options
);
484 setup_rel(o
, node
, FALSE
, OB_DIRECTION_WEST
, pre
, input
, post
);
488 static gpointer
setup_send_left_func(xmlNodePtr node
,
489 ObActionsIPreFunc
*pre
,
490 ObActionsIInputFunc
*input
,
491 ObActionsICancelFunc
*cancel
,
492 ObActionsIPostFunc
*post
)
494 Options
*o
= setup_follow(node
);
495 setup_rel(o
, node
, FALSE
, OB_DIRECTION_WEST
,
496 pre
, (o
->follow
? input
: NULL
), post
);
500 static gpointer
setup_go_right_func(xmlNodePtr node
,
501 ObActionsIPreFunc
*pre
,
502 ObActionsIInputFunc
*input
,
503 ObActionsICancelFunc
*cancel
,
504 ObActionsIPostFunc
*post
)
506 Options
*o
= g_slice_new0(Options
);
507 setup_rel(o
, node
, FALSE
, OB_DIRECTION_EAST
, pre
, input
, post
);
511 static gpointer
setup_send_right_func(xmlNodePtr node
,
512 ObActionsIPreFunc
*pre
,
513 ObActionsIInputFunc
*input
,
514 ObActionsICancelFunc
*cancel
,
515 ObActionsIPostFunc
*post
)
517 Options
*o
= setup_follow(node
);
518 setup_rel(o
, node
, FALSE
, OB_DIRECTION_EAST
,
519 pre
, (o
->follow
? input
: NULL
), post
);
523 static gpointer
setup_go_up_func(xmlNodePtr node
,
524 ObActionsIPreFunc
*pre
,
525 ObActionsIInputFunc
*input
,
526 ObActionsICancelFunc
*cancel
,
527 ObActionsIPostFunc
*post
)
529 Options
*o
= g_slice_new0(Options
);
530 setup_rel(o
, node
, FALSE
, OB_DIRECTION_NORTH
, pre
, input
, post
);
534 static gpointer
setup_send_up_func(xmlNodePtr node
,
535 ObActionsIPreFunc
*pre
,
536 ObActionsIInputFunc
*input
,
537 ObActionsICancelFunc
*cancel
,
538 ObActionsIPostFunc
*post
)
540 Options
*o
= setup_follow(node
);
541 setup_rel(o
, node
, FALSE
, OB_DIRECTION_NORTH
,
542 pre
, (o
->follow
? input
: NULL
), post
);
546 static gpointer
setup_go_down_func(xmlNodePtr node
,
547 ObActionsIPreFunc
*pre
,
548 ObActionsIInputFunc
*input
,
549 ObActionsICancelFunc
*cancel
,
550 ObActionsIPostFunc
*post
)
552 Options
*o
= g_slice_new0(Options
);
553 setup_rel(o
, node
, FALSE
, OB_DIRECTION_SOUTH
, pre
, input
, post
);
557 static gpointer
setup_send_down_func(xmlNodePtr node
,
558 ObActionsIPreFunc
*pre
,
559 ObActionsIInputFunc
*input
,
560 ObActionsICancelFunc
*cancel
,
561 ObActionsIPostFunc
*post
)
563 Options
*o
= setup_follow(node
);
564 setup_rel(o
, node
, FALSE
, OB_DIRECTION_SOUTH
,
565 pre
, (o
->follow
? input
: NULL
), post
);
This page took 0.060593 seconds and 4 git commands to generate.