]>
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 void free_func(gpointer o
);
42 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
44 static gboolean
i_pre_func(guint state
, gpointer options
);
45 static gboolean
i_input_func(guint initial_state
,
50 static void i_post_func(gpointer options
);
52 /* 3.4-compatibility */
53 static gpointer
setup_go_last_func(xmlNodePtr node
);
54 static gpointer
setup_send_last_func(xmlNodePtr node
);
55 static gpointer
setup_go_abs_func(xmlNodePtr node
);
56 static gpointer
setup_send_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("SendToDesktop", setup_send_abs_func
,
128 free_func
, run_func
);
129 actions_register_i("DesktopNext", setup_go_next_func
, free_func
, run_func
);
130 actions_register_i("SendToDesktopNext", setup_send_next_func
,
131 free_func
, run_func
);
132 actions_register_i("DesktopPrevious", setup_go_prev_func
,
133 free_func
, run_func
);
134 actions_register_i("SendToDesktopPrevious", setup_send_prev_func
,
135 free_func
, run_func
);
136 actions_register_i("DesktopLeft", setup_go_left_func
, free_func
, run_func
);
137 actions_register_i("SendToDesktopLeft", setup_send_left_func
,
138 free_func
, run_func
);
139 actions_register_i("DesktopRight", setup_go_right_func
,
140 free_func
, run_func
);
141 actions_register_i("SendToDesktopRight", setup_send_right_func
,
142 free_func
, run_func
);
143 actions_register_i("DesktopUp", setup_go_up_func
, free_func
, run_func
);
144 actions_register_i("SendToDesktopUp", setup_send_up_func
,
145 free_func
, run_func
);
146 actions_register_i("DesktopDown", setup_go_down_func
, free_func
, run_func
);
147 actions_register_i("SendToDesktopDown", setup_send_down_func
,
148 free_func
, run_func
);
151 static gpointer
setup_func(xmlNodePtr node
,
152 ObActionsIPreFunc
*pre
,
153 ObActionsIInputFunc
*input
,
154 ObActionsICancelFunc
*cancel
,
155 ObActionsIPostFunc
*post
)
160 o
= g_slice_new0(Options
);
161 /* don't go anywhere if there are no options given */
163 o
->u
.abs
.desktop
= screen_desktop
;
164 /* wrap by default - it's handy! */
165 o
->u
.rel
.wrap
= TRUE
;
167 if ((n
= obt_xml_find_node(node
, "to"))) {
168 gchar
*s
= obt_xml_node_string(n
);
169 if (!g_ascii_strcasecmp(s
, "last"))
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
);
247 if ((n
= obt_xml_find_node(node
, "follow")))
248 o
->follow
= obt_xml_node_bool(n
);
250 if (o
->type
== RELATIVE
&& o
->follow
) {
251 o
->interactive
= TRUE
;
253 *input
= i_input_func
;
260 static void free_func(gpointer o
)
262 g_slice_free(Options
, o
);
265 /* Always return FALSE because its not interactive */
266 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
268 Options
*o
= options
;
273 d
= screen_last_desktop
;
276 d
= o
->u
.abs
.desktop
;
279 d
= screen_find_desktop(screen_desktop
,
280 o
->u
.rel
.dir
, o
->u
.rel
.wrap
, o
->u
.rel
.linear
);
283 g_assert_not_reached();
286 if (d
< screen_num_desktops
&& d
!= screen_desktop
) {
289 actions_client_move(data
, TRUE
);
290 if (o
->send
&& data
->client
&& client_normal(data
->client
)) {
291 client_set_desktop(data
->client
, d
, o
->follow
, FALSE
);
296 screen_set_desktop(d
, TRUE
);
298 client_bring_helper_windows(data
->client
);
301 actions_client_move(data
, FALSE
);
304 return o
->interactive
;
307 static gboolean
i_input_func(guint initial_state
,
315 mods
= obt_keyboard_only_modmasks(e
->xkey
.state
);
316 if (e
->type
== KeyRelease
) {
317 /* remove from the state the mask of the modifier key being
318 released, if it is a modifier key being released that is */
319 mods
&= ~obt_keyboard_keyevent_to_modmask(e
);
322 if (e
->type
== KeyPress
) {
323 KeySym sym
= obt_keyboard_keypress_to_keysym(e
);
325 /* Escape cancels no matter what */
326 if (sym
== XK_Escape
)
329 /* There were no modifiers and they pressed enter */
330 else if ((sym
== XK_Return
|| sym
== XK_KP_Enter
) && !initial_state
)
333 /* They released the modifiers */
334 else if (e
->type
== KeyRelease
&& initial_state
&& !(mods
& initial_state
))
342 static gboolean
i_pre_func(guint initial_state
, gpointer options
)
344 if (!initial_state
) {
345 Options
*o
= options
;
346 o
->interactive
= FALSE
;
350 screen_show_desktop_popup(screen_desktop
, TRUE
);
355 static void i_post_func(gpointer options
)
357 screen_hide_desktop_popup();
360 /* 3.4-compatilibity */
361 static gpointer
setup_follow(xmlNodePtr node
)
364 Options
*o
= g_slice_new0(Options
);
367 if ((n
= obt_xml_find_node(node
, "follow")))
368 o
->follow
= obt_xml_node_bool(n
);
372 static gpointer
setup_go_last_func(xmlNodePtr node
)
374 Options
*o
= g_slice_new0(Options
);
379 static gpointer
setup_send_last_func(xmlNodePtr node
)
381 Options
*o
= setup_follow(node
);
386 static gpointer
setup_go_abs_func(xmlNodePtr node
)
389 Options
*o
= g_slice_new0(Options
);
391 if ((n
= obt_xml_find_node(node
, "desktop")))
392 o
->u
.abs
.desktop
= obt_xml_node_int(n
) - 1;
394 o
->u
.abs
.desktop
= screen_desktop
;
398 static gpointer
setup_send_abs_func(xmlNodePtr node
)
401 Options
*o
= setup_follow(node
);
403 if ((n
= obt_xml_find_node(node
, "desktop")))
404 o
->u
.abs
.desktop
= obt_xml_node_int(n
) - 1;
406 o
->u
.abs
.desktop
= screen_desktop
;
410 static void setup_rel(Options
*o
, xmlNodePtr node
, gboolean lin
,
412 ObActionsIPreFunc
*pre
,
413 ObActionsIInputFunc
*input
,
414 ObActionsIPostFunc
*post
)
419 o
->u
.rel
.linear
= lin
;
421 o
->u
.rel
.wrap
= TRUE
;
423 if ((n
= obt_xml_find_node(node
, "wrap")))
424 o
->u
.rel
.wrap
= obt_xml_node_bool(n
);
427 o
->interactive
= TRUE
;
429 *input
= i_input_func
;
434 static gpointer
setup_go_next_func(xmlNodePtr node
,
435 ObActionsIPreFunc
*pre
,
436 ObActionsIInputFunc
*input
,
437 ObActionsICancelFunc
*cancel
,
438 ObActionsIPostFunc
*post
)
440 Options
*o
= g_slice_new0(Options
);
441 setup_rel(o
, node
, TRUE
, OB_DIRECTION_EAST
, pre
, input
, post
);
445 static gpointer
setup_send_next_func(xmlNodePtr node
,
446 ObActionsIPreFunc
*pre
,
447 ObActionsIInputFunc
*input
,
448 ObActionsICancelFunc
*cancel
,
449 ObActionsIPostFunc
*post
)
451 Options
*o
= setup_follow(node
);
452 setup_rel(o
, node
, TRUE
, OB_DIRECTION_EAST
,
453 pre
, (o
->follow
? input
: NULL
), post
);
457 static gpointer
setup_go_prev_func(xmlNodePtr node
,
458 ObActionsIPreFunc
*pre
,
459 ObActionsIInputFunc
*input
,
460 ObActionsICancelFunc
*cancel
,
461 ObActionsIPostFunc
*post
)
463 Options
*o
= g_slice_new0(Options
);
464 setup_rel(o
, node
, TRUE
, OB_DIRECTION_WEST
, pre
, input
, post
);
468 static gpointer
setup_send_prev_func(xmlNodePtr node
,
469 ObActionsIPreFunc
*pre
,
470 ObActionsIInputFunc
*input
,
471 ObActionsICancelFunc
*cancel
,
472 ObActionsIPostFunc
*post
)
474 Options
*o
= setup_follow(node
);
475 setup_rel(o
, node
, TRUE
, OB_DIRECTION_WEST
,
476 pre
, (o
->follow
? input
: NULL
), post
);
480 static gpointer
setup_go_left_func(xmlNodePtr node
,
481 ObActionsIPreFunc
*pre
,
482 ObActionsIInputFunc
*input
,
483 ObActionsICancelFunc
*cancel
,
484 ObActionsIPostFunc
*post
)
486 Options
*o
= g_slice_new0(Options
);
487 setup_rel(o
, node
, FALSE
, OB_DIRECTION_WEST
, pre
, input
, post
);
491 static gpointer
setup_send_left_func(xmlNodePtr node
,
492 ObActionsIPreFunc
*pre
,
493 ObActionsIInputFunc
*input
,
494 ObActionsICancelFunc
*cancel
,
495 ObActionsIPostFunc
*post
)
497 Options
*o
= setup_follow(node
);
498 setup_rel(o
, node
, FALSE
, OB_DIRECTION_WEST
,
499 pre
, (o
->follow
? input
: NULL
), post
);
503 static gpointer
setup_go_right_func(xmlNodePtr node
,
504 ObActionsIPreFunc
*pre
,
505 ObActionsIInputFunc
*input
,
506 ObActionsICancelFunc
*cancel
,
507 ObActionsIPostFunc
*post
)
509 Options
*o
= g_slice_new0(Options
);
510 setup_rel(o
, node
, FALSE
, OB_DIRECTION_EAST
, pre
, input
, post
);
514 static gpointer
setup_send_right_func(xmlNodePtr node
,
515 ObActionsIPreFunc
*pre
,
516 ObActionsIInputFunc
*input
,
517 ObActionsICancelFunc
*cancel
,
518 ObActionsIPostFunc
*post
)
520 Options
*o
= setup_follow(node
);
521 setup_rel(o
, node
, FALSE
, OB_DIRECTION_EAST
,
522 pre
, (o
->follow
? input
: NULL
), post
);
526 static gpointer
setup_go_up_func(xmlNodePtr node
,
527 ObActionsIPreFunc
*pre
,
528 ObActionsIInputFunc
*input
,
529 ObActionsICancelFunc
*cancel
,
530 ObActionsIPostFunc
*post
)
532 Options
*o
= g_slice_new0(Options
);
533 setup_rel(o
, node
, FALSE
, OB_DIRECTION_NORTH
, pre
, input
, post
);
537 static gpointer
setup_send_up_func(xmlNodePtr node
,
538 ObActionsIPreFunc
*pre
,
539 ObActionsIInputFunc
*input
,
540 ObActionsICancelFunc
*cancel
,
541 ObActionsIPostFunc
*post
)
543 Options
*o
= setup_follow(node
);
544 setup_rel(o
, node
, FALSE
, OB_DIRECTION_NORTH
,
545 pre
, (o
->follow
? input
: NULL
), post
);
549 static gpointer
setup_go_down_func(xmlNodePtr node
,
550 ObActionsIPreFunc
*pre
,
551 ObActionsIInputFunc
*input
,
552 ObActionsICancelFunc
*cancel
,
553 ObActionsIPostFunc
*post
)
555 Options
*o
= g_slice_new0(Options
);
556 setup_rel(o
, node
, FALSE
, OB_DIRECTION_SOUTH
, pre
, input
, post
);
560 static gpointer
setup_send_down_func(xmlNodePtr node
,
561 ObActionsIPreFunc
*pre
,
562 ObActionsIInputFunc
*input
,
563 ObActionsICancelFunc
*cancel
,
564 ObActionsIPostFunc
*post
)
566 Options
*o
= setup_follow(node
);
567 setup_rel(o
, node
, FALSE
, OB_DIRECTION_SOUTH
,
568 pre
, (o
->follow
? input
: NULL
), post
);
This page took 0.063616 seconds and 4 git commands to generate.