]>
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
,
322 guint mods
, initial_mods
;
324 initial_mods
= obt_keyboard_only_modmasks(initial_state
);
325 mods
= obt_keyboard_only_modmasks(e
->xkey
.state
);
326 if (e
->type
== KeyRelease
) {
327 /* remove from the state the mask of the modifier key being
328 released, if it is a modifier key being released that is */
329 mods
&= ~obt_keyboard_keyevent_to_modmask(e
);
332 if (e
->type
== KeyPress
) {
333 KeySym sym
= obt_keyboard_keypress_to_keysym(e
);
335 /* Escape cancels no matter what */
336 if (sym
== XK_Escape
)
339 /* There were no modifiers and they pressed enter */
340 else if ((sym
== XK_Return
|| sym
== XK_KP_Enter
) && !initial_mods
)
343 /* They released the modifiers */
344 else if (e
->type
== KeyRelease
&& initial_mods
&& !(mods
& initial_mods
))
352 static gboolean
i_pre_func(guint initial_state
, gpointer options
)
354 guint initial_mods
= obt_keyboard_only_modmasks(initial_state
);
356 Options
*o
= options
;
357 o
->interactive
= FALSE
;
361 screen_show_desktop_popup(screen_desktop
, TRUE
);
366 static void i_post_func(gpointer options
)
368 screen_hide_desktop_popup();
371 /* 3.4-compatilibity */
372 static gpointer
setup_follow(xmlNodePtr node
)
375 Options
*o
= g_slice_new0(Options
);
378 if ((n
= obt_xml_find_node(node
, "follow")))
379 o
->follow
= obt_xml_node_bool(n
);
383 static gpointer
setup_go_last_func(xmlNodePtr node
)
385 Options
*o
= g_slice_new0(Options
);
390 static gpointer
setup_send_last_func(xmlNodePtr node
)
392 Options
*o
= setup_follow(node
);
397 static gpointer
setup_go_abs_func(xmlNodePtr node
)
400 Options
*o
= g_slice_new0(Options
);
402 if ((n
= obt_xml_find_node(node
, "desktop")))
403 o
->u
.abs
.desktop
= obt_xml_node_int(n
) - 1;
405 o
->u
.abs
.desktop
= screen_desktop
;
409 static void setup_rel(Options
*o
, xmlNodePtr node
, gboolean lin
,
411 ObActionsIPreFunc
*pre
,
412 ObActionsIInputFunc
*input
,
413 ObActionsIPostFunc
*post
)
418 o
->u
.rel
.linear
= lin
;
420 o
->u
.rel
.wrap
= TRUE
;
422 if ((n
= obt_xml_find_node(node
, "wrap")))
423 o
->u
.rel
.wrap
= obt_xml_node_bool(n
);
426 o
->interactive
= TRUE
;
428 *input
= i_input_func
;
433 static gpointer
setup_go_next_func(xmlNodePtr node
,
434 ObActionsIPreFunc
*pre
,
435 ObActionsIInputFunc
*input
,
436 ObActionsICancelFunc
*cancel
,
437 ObActionsIPostFunc
*post
)
439 Options
*o
= g_slice_new0(Options
);
440 setup_rel(o
, node
, TRUE
, OB_DIRECTION_EAST
, pre
, input
, post
);
444 static gpointer
setup_send_next_func(xmlNodePtr node
,
445 ObActionsIPreFunc
*pre
,
446 ObActionsIInputFunc
*input
,
447 ObActionsICancelFunc
*cancel
,
448 ObActionsIPostFunc
*post
)
450 Options
*o
= setup_follow(node
);
451 setup_rel(o
, node
, TRUE
, OB_DIRECTION_EAST
,
452 pre
, (o
->follow
? input
: NULL
), post
);
456 static gpointer
setup_go_prev_func(xmlNodePtr node
,
457 ObActionsIPreFunc
*pre
,
458 ObActionsIInputFunc
*input
,
459 ObActionsICancelFunc
*cancel
,
460 ObActionsIPostFunc
*post
)
462 Options
*o
= g_slice_new0(Options
);
463 setup_rel(o
, node
, TRUE
, OB_DIRECTION_WEST
, pre
, input
, post
);
467 static gpointer
setup_send_prev_func(xmlNodePtr node
,
468 ObActionsIPreFunc
*pre
,
469 ObActionsIInputFunc
*input
,
470 ObActionsICancelFunc
*cancel
,
471 ObActionsIPostFunc
*post
)
473 Options
*o
= setup_follow(node
);
474 setup_rel(o
, node
, TRUE
, OB_DIRECTION_WEST
,
475 pre
, (o
->follow
? input
: NULL
), post
);
479 static gpointer
setup_go_left_func(xmlNodePtr node
,
480 ObActionsIPreFunc
*pre
,
481 ObActionsIInputFunc
*input
,
482 ObActionsICancelFunc
*cancel
,
483 ObActionsIPostFunc
*post
)
485 Options
*o
= g_slice_new0(Options
);
486 setup_rel(o
, node
, FALSE
, OB_DIRECTION_WEST
, pre
, input
, post
);
490 static gpointer
setup_send_left_func(xmlNodePtr node
,
491 ObActionsIPreFunc
*pre
,
492 ObActionsIInputFunc
*input
,
493 ObActionsICancelFunc
*cancel
,
494 ObActionsIPostFunc
*post
)
496 Options
*o
= setup_follow(node
);
497 setup_rel(o
, node
, FALSE
, OB_DIRECTION_WEST
,
498 pre
, (o
->follow
? input
: NULL
), post
);
502 static gpointer
setup_go_right_func(xmlNodePtr node
,
503 ObActionsIPreFunc
*pre
,
504 ObActionsIInputFunc
*input
,
505 ObActionsICancelFunc
*cancel
,
506 ObActionsIPostFunc
*post
)
508 Options
*o
= g_slice_new0(Options
);
509 setup_rel(o
, node
, FALSE
, OB_DIRECTION_EAST
, pre
, input
, post
);
513 static gpointer
setup_send_right_func(xmlNodePtr node
,
514 ObActionsIPreFunc
*pre
,
515 ObActionsIInputFunc
*input
,
516 ObActionsICancelFunc
*cancel
,
517 ObActionsIPostFunc
*post
)
519 Options
*o
= setup_follow(node
);
520 setup_rel(o
, node
, FALSE
, OB_DIRECTION_EAST
,
521 pre
, (o
->follow
? input
: NULL
), post
);
525 static gpointer
setup_go_up_func(xmlNodePtr node
,
526 ObActionsIPreFunc
*pre
,
527 ObActionsIInputFunc
*input
,
528 ObActionsICancelFunc
*cancel
,
529 ObActionsIPostFunc
*post
)
531 Options
*o
= g_slice_new0(Options
);
532 setup_rel(o
, node
, FALSE
, OB_DIRECTION_NORTH
, pre
, input
, post
);
536 static gpointer
setup_send_up_func(xmlNodePtr node
,
537 ObActionsIPreFunc
*pre
,
538 ObActionsIInputFunc
*input
,
539 ObActionsICancelFunc
*cancel
,
540 ObActionsIPostFunc
*post
)
542 Options
*o
= setup_follow(node
);
543 setup_rel(o
, node
, FALSE
, OB_DIRECTION_NORTH
,
544 pre
, (o
->follow
? input
: NULL
), post
);
548 static gpointer
setup_go_down_func(xmlNodePtr node
,
549 ObActionsIPreFunc
*pre
,
550 ObActionsIInputFunc
*input
,
551 ObActionsICancelFunc
*cancel
,
552 ObActionsIPostFunc
*post
)
554 Options
*o
= g_slice_new0(Options
);
555 setup_rel(o
, node
, FALSE
, OB_DIRECTION_SOUTH
, pre
, input
, post
);
559 static gpointer
setup_send_down_func(xmlNodePtr node
,
560 ObActionsIPreFunc
*pre
,
561 ObActionsIInputFunc
*input
,
562 ObActionsICancelFunc
*cancel
,
563 ObActionsIPostFunc
*post
)
565 Options
*o
= setup_follow(node
);
566 setup_rel(o
, node
, FALSE
, OB_DIRECTION_SOUTH
,
567 pre
, (o
->follow
? input
: NULL
), post
);
This page took 0.056308 seconds and 4 git commands to generate.