]> Dogcows Code - chaz/openbox/blob - openbox/action.c
2288dcb9886762ffcbbb3436093e0b98ada7ec62
[chaz/openbox] / openbox / action.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 action.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "debug.h"
21 #include "client.h"
22 #include "focus.h"
23 #include "focus_cycle.h"
24 #include "moveresize.h"
25 #include "menu.h"
26 #include "prop.h"
27 #include "stacking.h"
28 #include "screen.h"
29 #include "action.h"
30 #include "openbox.h"
31 #include "grab.h"
32 #include "keyboard.h"
33 #include "event.h"
34 #include "dock.h"
35 #include "config.h"
36 #include "mainloop.h"
37 #include "startupnotify.h"
38 #include "gettext.h"
39
40 #include <glib.h>
41
42 static gulong ignore_start = 0;
43
44 static void client_action_start(union ActionData *data)
45 {
46 ignore_start = event_start_ignore_all_enters();
47 }
48
49 static void client_action_end(union ActionData *data, gboolean allow_enters)
50 {
51 if (config_focus_follow)
52 if (data->any.context != OB_FRAME_CONTEXT_CLIENT) {
53 if (!data->any.button && data->any.c && !allow_enters) {
54 event_end_ignore_all_enters(ignore_start);
55 } else {
56 ObClient *c;
57
58 /* usually this is sorta redundant, but with a press action
59 that moves windows our from under the cursor, the enter
60 event will come as a GrabNotify which is ignored, so this
61 makes a fake enter event
62 */
63 if ((c = client_under_pointer()) && c != data->any.c) {
64 ob_debug_type(OB_DEBUG_FOCUS,
65 "Generating fake enter because we did a "
66 "mouse-event action");
67 event_enter_client(c);
68 }
69 }
70 }
71 }
72
73 typedef struct
74 {
75 const gchar *name;
76 void (*func)(union ActionData *);
77 void (*setup)(ObAction **, ObUserAction uact);
78 } ActionString;
79
80 static ObAction *action_new(void (*func)(union ActionData *data))
81 {
82 ObAction *a = g_new0(ObAction, 1);
83 a->ref = 1;
84 a->func = func;
85
86 return a;
87 }
88
89 void action_ref(ObAction *a)
90 {
91 ++a->ref;
92 }
93
94 void action_unref(ObAction *a)
95 {
96 if (a == NULL) return;
97
98 if (--a->ref > 0) return;
99
100 /* deal with pointers */
101 if (a->func == action_execute || a->func == action_restart)
102 g_free(a->data.execute.path);
103 else if (a->func == action_debug)
104 g_free(a->data.debug.string);
105 else if (a->func == action_showmenu)
106 g_free(a->data.showmenu.name);
107
108 g_free(a);
109 }
110
111 ObAction* action_copy(const ObAction *src)
112 {
113 ObAction *a = action_new(src->func);
114
115 a->data = src->data;
116
117 /* deal with pointers */
118 if (a->func == action_execute || a->func == action_restart)
119 a->data.execute.path = g_strdup(a->data.execute.path);
120 else if (a->func == action_debug)
121 a->data.debug.string = g_strdup(a->data.debug.string);
122 else if (a->func == action_showmenu)
123 a->data.showmenu.name = g_strdup(a->data.showmenu.name);
124
125 return a;
126 }
127
128 void setup_action_directional_focus_north(ObAction **a, ObUserAction uact)
129 {
130 (*a)->data.interdiraction.inter.any.interactive = TRUE;
131 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTH;
132 (*a)->data.interdiraction.dialog = TRUE;
133 (*a)->data.interdiraction.dock_windows = FALSE;
134 (*a)->data.interdiraction.desktop_windows = FALSE;
135 }
136
137 void setup_action_directional_focus_east(ObAction **a, ObUserAction uact)
138 {
139 (*a)->data.interdiraction.inter.any.interactive = TRUE;
140 (*a)->data.interdiraction.direction = OB_DIRECTION_EAST;
141 (*a)->data.interdiraction.dialog = TRUE;
142 (*a)->data.interdiraction.dock_windows = FALSE;
143 (*a)->data.interdiraction.desktop_windows = FALSE;
144 }
145
146 void setup_action_directional_focus_south(ObAction **a, ObUserAction uact)
147 {
148 (*a)->data.interdiraction.inter.any.interactive = TRUE;
149 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTH;
150 (*a)->data.interdiraction.dialog = TRUE;
151 (*a)->data.interdiraction.dock_windows = FALSE;
152 (*a)->data.interdiraction.desktop_windows = FALSE;
153 }
154
155 void setup_action_directional_focus_west(ObAction **a, ObUserAction uact)
156 {
157 (*a)->data.interdiraction.inter.any.interactive = TRUE;
158 (*a)->data.interdiraction.direction = OB_DIRECTION_WEST;
159 (*a)->data.interdiraction.dialog = TRUE;
160 (*a)->data.interdiraction.dock_windows = FALSE;
161 (*a)->data.interdiraction.desktop_windows = FALSE;
162 }
163
164 void setup_action_directional_focus_northeast(ObAction **a, ObUserAction uact)
165 {
166 (*a)->data.interdiraction.inter.any.interactive = TRUE;
167 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHEAST;
168 (*a)->data.interdiraction.dialog = TRUE;
169 (*a)->data.interdiraction.dock_windows = FALSE;
170 (*a)->data.interdiraction.desktop_windows = FALSE;
171 }
172
173 void setup_action_directional_focus_southeast(ObAction **a, ObUserAction uact)
174 {
175 (*a)->data.interdiraction.inter.any.interactive = TRUE;
176 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHEAST;
177 (*a)->data.interdiraction.dialog = TRUE;
178 (*a)->data.interdiraction.dock_windows = FALSE;
179 (*a)->data.interdiraction.desktop_windows = FALSE;
180 }
181
182 void setup_action_directional_focus_southwest(ObAction **a, ObUserAction uact)
183 {
184 (*a)->data.interdiraction.inter.any.interactive = TRUE;
185 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHWEST;
186 (*a)->data.interdiraction.dialog = TRUE;
187 (*a)->data.interdiraction.dock_windows = FALSE;
188 (*a)->data.interdiraction.desktop_windows = FALSE;
189 }
190
191 void setup_action_directional_focus_northwest(ObAction **a, ObUserAction uact)
192 {
193 (*a)->data.interdiraction.inter.any.interactive = TRUE;
194 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHWEST;
195 (*a)->data.interdiraction.dialog = TRUE;
196 (*a)->data.interdiraction.dock_windows = FALSE;
197 (*a)->data.interdiraction.desktop_windows = FALSE;
198 }
199
200 void setup_action_send_to_desktop(ObAction **a, ObUserAction uact)
201 {
202 (*a)->data.sendto.any.client_action = OB_CLIENT_ACTION_ALWAYS;
203 (*a)->data.sendto.follow = TRUE;
204 }
205
206 void setup_action_send_to_desktop_prev(ObAction **a, ObUserAction uact)
207 {
208 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
209 (*a)->data.sendtodir.inter.any.interactive = TRUE;
210 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
211 (*a)->data.sendtodir.linear = TRUE;
212 (*a)->data.sendtodir.wrap = TRUE;
213 (*a)->data.sendtodir.follow = TRUE;
214 }
215
216 void setup_action_send_to_desktop_next(ObAction **a, ObUserAction uact)
217 {
218 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
219 (*a)->data.sendtodir.inter.any.interactive = TRUE;
220 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
221 (*a)->data.sendtodir.linear = TRUE;
222 (*a)->data.sendtodir.wrap = TRUE;
223 (*a)->data.sendtodir.follow = TRUE;
224 }
225
226 void setup_action_send_to_desktop_left(ObAction **a, ObUserAction uact)
227 {
228 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
229 (*a)->data.sendtodir.inter.any.interactive = TRUE;
230 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
231 (*a)->data.sendtodir.linear = FALSE;
232 (*a)->data.sendtodir.wrap = TRUE;
233 (*a)->data.sendtodir.follow = TRUE;
234 }
235
236 void setup_action_send_to_desktop_right(ObAction **a, ObUserAction uact)
237 {
238 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
239 (*a)->data.sendtodir.inter.any.interactive = TRUE;
240 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
241 (*a)->data.sendtodir.linear = FALSE;
242 (*a)->data.sendtodir.wrap = TRUE;
243 (*a)->data.sendtodir.follow = TRUE;
244 }
245
246 void setup_action_send_to_desktop_up(ObAction **a, ObUserAction uact)
247 {
248 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
249 (*a)->data.sendtodir.inter.any.interactive = TRUE;
250 (*a)->data.sendtodir.dir = OB_DIRECTION_NORTH;
251 (*a)->data.sendtodir.linear = FALSE;
252 (*a)->data.sendtodir.wrap = TRUE;
253 (*a)->data.sendtodir.follow = TRUE;
254 }
255
256 void setup_action_send_to_desktop_down(ObAction **a, ObUserAction uact)
257 {
258 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
259 (*a)->data.sendtodir.inter.any.interactive = TRUE;
260 (*a)->data.sendtodir.dir = OB_DIRECTION_SOUTH;
261 (*a)->data.sendtodir.linear = FALSE;
262 (*a)->data.sendtodir.wrap = TRUE;
263 (*a)->data.sendtodir.follow = TRUE;
264 }
265
266 void setup_action_desktop(ObAction **a, ObUserAction uact)
267 {
268 /*
269 (*a)->data.desktop.inter.any.interactive = FALSE;
270 */
271 }
272
273 void setup_action_desktop_prev(ObAction **a, ObUserAction uact)
274 {
275 (*a)->data.desktopdir.inter.any.interactive = TRUE;
276 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
277 (*a)->data.desktopdir.linear = TRUE;
278 (*a)->data.desktopdir.wrap = TRUE;
279 }
280
281 void setup_action_desktop_next(ObAction **a, ObUserAction uact)
282 {
283 (*a)->data.desktopdir.inter.any.interactive = TRUE;
284 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
285 (*a)->data.desktopdir.linear = TRUE;
286 (*a)->data.desktopdir.wrap = TRUE;
287 }
288
289 void setup_action_desktop_left(ObAction **a, ObUserAction uact)
290 {
291 (*a)->data.desktopdir.inter.any.interactive = TRUE;
292 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
293 (*a)->data.desktopdir.linear = FALSE;
294 (*a)->data.desktopdir.wrap = TRUE;
295 }
296
297 void setup_action_desktop_right(ObAction **a, ObUserAction uact)
298 {
299 (*a)->data.desktopdir.inter.any.interactive = TRUE;
300 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
301 (*a)->data.desktopdir.linear = FALSE;
302 (*a)->data.desktopdir.wrap = TRUE;
303 }
304
305 void setup_action_desktop_up(ObAction **a, ObUserAction uact)
306 {
307 (*a)->data.desktopdir.inter.any.interactive = TRUE;
308 (*a)->data.desktopdir.dir = OB_DIRECTION_NORTH;
309 (*a)->data.desktopdir.linear = FALSE;
310 (*a)->data.desktopdir.wrap = TRUE;
311 }
312
313 void setup_action_desktop_down(ObAction **a, ObUserAction uact)
314 {
315 (*a)->data.desktopdir.inter.any.interactive = TRUE;
316 (*a)->data.desktopdir.dir = OB_DIRECTION_SOUTH;
317 (*a)->data.desktopdir.linear = FALSE;
318 (*a)->data.desktopdir.wrap = TRUE;
319 }
320
321 void setup_action_movefromedge_north(ObAction **a, ObUserAction uact)
322 {
323 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
324 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
325 (*a)->data.diraction.hang = TRUE;
326 }
327
328 void setup_action_movefromedge_south(ObAction **a, ObUserAction uact)
329 {
330 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
331 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
332 (*a)->data.diraction.hang = TRUE;
333 }
334
335 void setup_action_movefromedge_east(ObAction **a, ObUserAction uact)
336 {
337 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
338 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
339 (*a)->data.diraction.hang = TRUE;
340 }
341
342 void setup_action_movefromedge_west(ObAction **a, ObUserAction uact)
343 {
344 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
345 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
346 (*a)->data.diraction.hang = TRUE;
347 }
348
349 void setup_action_movetoedge_north(ObAction **a, ObUserAction uact)
350 {
351 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
352 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
353 (*a)->data.diraction.hang = FALSE;
354 }
355
356 void setup_action_movetoedge_south(ObAction **a, ObUserAction uact)
357 {
358 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
359 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
360 (*a)->data.diraction.hang = FALSE;
361 }
362
363 void setup_action_movetoedge_east(ObAction **a, ObUserAction uact)
364 {
365 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
366 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
367 (*a)->data.diraction.hang = FALSE;
368 }
369
370 void setup_action_movetoedge_west(ObAction **a, ObUserAction uact)
371 {
372 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
373 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
374 (*a)->data.diraction.hang = FALSE;
375 }
376
377 void setup_action_growtoedge_north(ObAction **a, ObUserAction uact)
378 {
379 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
380 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
381 }
382
383 void setup_action_growtoedge_south(ObAction **a, ObUserAction uact)
384 {
385 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
386 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
387 }
388
389 void setup_action_growtoedge_east(ObAction **a, ObUserAction uact)
390 {
391 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
392 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
393 }
394
395 void setup_action_growtoedge_west(ObAction **a, ObUserAction uact)
396 {
397 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
398 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
399 }
400
401 void setup_action_top_layer(ObAction **a, ObUserAction uact)
402 {
403 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
404 (*a)->data.layer.layer = 1;
405 }
406
407 void setup_action_normal_layer(ObAction **a, ObUserAction uact)
408 {
409 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
410 (*a)->data.layer.layer = 0;
411 }
412
413 void setup_action_bottom_layer(ObAction **a, ObUserAction uact)
414 {
415 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
416 (*a)->data.layer.layer = -1;
417 }
418
419 void setup_action_move(ObAction **a, ObUserAction uact)
420 {
421 (*a)->data.moveresize.any.client_action = OB_CLIENT_ACTION_ALWAYS;
422 (*a)->data.moveresize.keyboard =
423 (uact == OB_USER_ACTION_NONE ||
424 uact == OB_USER_ACTION_KEYBOARD_KEY ||
425 uact == OB_USER_ACTION_MENU_SELECTION);
426 (*a)->data.moveresize.corner = 0;
427 }
428
429 void setup_action_resize(ObAction **a, ObUserAction uact)
430 {
431 (*a)->data.moveresize.any.client_action = OB_CLIENT_ACTION_ALWAYS;
432 (*a)->data.moveresize.keyboard =
433 (uact == OB_USER_ACTION_NONE ||
434 uact == OB_USER_ACTION_KEYBOARD_KEY ||
435 uact == OB_USER_ACTION_MENU_SELECTION);
436 (*a)->data.moveresize.corner = 0;
437 }
438
439 void setup_action_addremove_desktop_current(ObAction **a, ObUserAction uact)
440 {
441 (*a)->data.addremovedesktop.current = TRUE;
442 }
443
444 void setup_action_addremove_desktop_last(ObAction **a, ObUserAction uact)
445 {
446 (*a)->data.addremovedesktop.current = FALSE;
447 }
448
449 void setup_client_action(ObAction **a, ObUserAction uact)
450 {
451 (*a)->data.any.client_action = OB_CLIENT_ACTION_ALWAYS;
452 }
453
454 ActionString actionstrings[] =
455 {
456 {
457 "directionalfocusnorth",
458 action_directional_focus,
459 setup_action_directional_focus_north
460 },
461 {
462 "directionalfocuseast",
463 action_directional_focus,
464 setup_action_directional_focus_east
465 },
466 {
467 "directionalfocussouth",
468 action_directional_focus,
469 setup_action_directional_focus_south
470 },
471 {
472 "directionalfocuswest",
473 action_directional_focus,
474 setup_action_directional_focus_west
475 },
476 {
477 "directionalfocusnortheast",
478 action_directional_focus,
479 setup_action_directional_focus_northeast
480 },
481 {
482 "directionalfocussoutheast",
483 action_directional_focus,
484 setup_action_directional_focus_southeast
485 },
486 {
487 "directionalfocussouthwest",
488 action_directional_focus,
489 setup_action_directional_focus_southwest
490 },
491 {
492 "directionalfocusnorthwest",
493 action_directional_focus,
494 setup_action_directional_focus_northwest
495 },
496 {
497 "unfocus",
498 action_unfocus,
499 setup_client_action
500 },
501 {
502 "iconify",
503 action_iconify,
504 setup_client_action
505 },
506 {
507 "focustobottom",
508 action_focus_order_to_bottom,
509 setup_client_action
510 },
511 {
512 "raiselower",
513 action_raiselower,
514 setup_client_action
515 },
516 {
517 "raise",
518 action_raise,
519 setup_client_action
520 },
521 {
522 "lower",
523 action_lower,
524 setup_client_action
525 },
526 {
527 "close",
528 action_close,
529 setup_client_action
530 },
531 {
532 "kill",
533 action_kill,
534 setup_client_action
535 },
536 {
537 "shadelower",
538 action_shadelower,
539 setup_client_action
540 },
541 {
542 "unshaderaise",
543 action_unshaderaise,
544 setup_client_action
545 },
546 {
547 "shade",
548 action_shade,
549 setup_client_action
550 },
551 {
552 "unshade",
553 action_unshade,
554 setup_client_action
555 },
556 {
557 "toggleshade",
558 action_toggle_shade,
559 setup_client_action
560 },
561 {
562 "toggleomnipresent",
563 action_toggle_omnipresent,
564 setup_client_action
565 },
566 {
567 "moverelativehorz",
568 action_move_relative_horz,
569 setup_client_action
570 },
571 {
572 "moverelativevert",
573 action_move_relative_vert,
574 setup_client_action
575 },
576 {
577 "movetocenter",
578 action_move_to_center,
579 setup_client_action
580 },
581 {
582 "resizerelativehorz",
583 action_resize_relative_horz,
584 setup_client_action
585 },
586 {
587 "resizerelativevert",
588 action_resize_relative_vert,
589 setup_client_action
590 },
591 {
592 "moverelative",
593 action_move_relative,
594 setup_client_action
595 },
596 {
597 "resizerelative",
598 action_resize_relative,
599 setup_client_action
600 },
601 {
602 "maximizefull",
603 action_maximize_full,
604 setup_client_action
605 },
606 {
607 "unmaximizefull",
608 action_unmaximize_full,
609 setup_client_action
610 },
611 {
612 "togglemaximizefull",
613 action_toggle_maximize_full,
614 setup_client_action
615 },
616 {
617 "maximizehorz",
618 action_maximize_horz,
619 setup_client_action
620 },
621 {
622 "unmaximizehorz",
623 action_unmaximize_horz,
624 setup_client_action
625 },
626 {
627 "togglemaximizehorz",
628 action_toggle_maximize_horz,
629 setup_client_action
630 },
631 {
632 "maximizevert",
633 action_maximize_vert,
634 setup_client_action
635 },
636 {
637 "unmaximizevert",
638 action_unmaximize_vert,
639 setup_client_action
640 },
641 {
642 "togglemaximizevert",
643 action_toggle_maximize_vert,
644 setup_client_action
645 },
646 {
647 "togglefullscreen",
648 action_toggle_fullscreen,
649 setup_client_action
650 },
651 {
652 "sendtodesktop",
653 action_send_to_desktop,
654 setup_action_send_to_desktop
655 },
656 {
657 "sendtodesktopnext",
658 action_send_to_desktop_dir,
659 setup_action_send_to_desktop_next
660 },
661 {
662 "sendtodesktopprevious",
663 action_send_to_desktop_dir,
664 setup_action_send_to_desktop_prev
665 },
666 {
667 "sendtodesktopright",
668 action_send_to_desktop_dir,
669 setup_action_send_to_desktop_right
670 },
671 {
672 "sendtodesktopleft",
673 action_send_to_desktop_dir,
674 setup_action_send_to_desktop_left
675 },
676 {
677 "sendtodesktopup",
678 action_send_to_desktop_dir,
679 setup_action_send_to_desktop_up
680 },
681 {
682 "sendtodesktopdown",
683 action_send_to_desktop_dir,
684 setup_action_send_to_desktop_down
685 },
686 {
687 "desktop",
688 action_desktop,
689 setup_action_desktop
690 },
691 {
692 "desktopnext",
693 action_desktop_dir,
694 setup_action_desktop_next
695 },
696 {
697 "desktopprevious",
698 action_desktop_dir,
699 setup_action_desktop_prev
700 },
701 {
702 "desktopright",
703 action_desktop_dir,
704 setup_action_desktop_right
705 },
706 {
707 "desktopleft",
708 action_desktop_dir,
709 setup_action_desktop_left
710 },
711 {
712 "desktopup",
713 action_desktop_dir,
714 setup_action_desktop_up
715 },
716 {
717 "desktopdown",
718 action_desktop_dir,
719 setup_action_desktop_down
720 },
721 {
722 "toggledecorations",
723 action_toggle_decorations,
724 setup_client_action
725 },
726 {
727 "move",
728 action_move,
729 setup_action_move
730 },
731 {
732 "resize",
733 action_resize,
734 setup_action_resize
735 },
736 {
737 "toggledockautohide",
738 action_toggle_dockautohide,
739 NULL
740 },
741 {
742 "desktoplast",
743 action_desktop_last,
744 NULL
745 },
746 {
747 "sendtotoplayer",
748 action_send_to_layer,
749 setup_action_top_layer
750 },
751 {
752 "togglealwaysontop",
753 action_toggle_layer,
754 setup_action_top_layer
755 },
756 {
757 "sendtonormallayer",
758 action_send_to_layer,
759 setup_action_normal_layer
760 },
761 {
762 "sendtobottomlayer",
763 action_send_to_layer,
764 setup_action_bottom_layer
765 },
766 {
767 "togglealwaysonbottom",
768 action_toggle_layer,
769 setup_action_bottom_layer
770 },
771 {
772 "movefromedgenorth",
773 action_movetoedge,
774 setup_action_movefromedge_north
775 },
776 {
777 "movefromedgesouth",
778 action_movetoedge,
779 setup_action_movefromedge_south
780 },
781 {
782 "movefromedgewest",
783 action_movetoedge,
784 setup_action_movefromedge_west
785 },
786 {
787 "movefromedgeeast",
788 action_movetoedge,
789 setup_action_movefromedge_east
790 },
791 {
792 "movetoedgenorth",
793 action_movetoedge,
794 setup_action_movetoedge_north
795 },
796 {
797 "movetoedgesouth",
798 action_movetoedge,
799 setup_action_movetoedge_south
800 },
801 {
802 "movetoedgewest",
803 action_movetoedge,
804 setup_action_movetoedge_west
805 },
806 {
807 "movetoedgeeast",
808 action_movetoedge,
809 setup_action_movetoedge_east
810 },
811 {
812 "growtoedgenorth",
813 action_growtoedge,
814 setup_action_growtoedge_north
815 },
816 {
817 "growtoedgesouth",
818 action_growtoedge,
819 setup_action_growtoedge_south
820 },
821 {
822 "growtoedgewest",
823 action_growtoedge,
824 setup_action_growtoedge_west
825 },
826 {
827 "growtoedgeeast",
828 action_growtoedge,
829 setup_action_growtoedge_east
830 },
831 {
832 "adddesktoplast",
833 action_add_desktop,
834 setup_action_addremove_desktop_last
835 },
836 {
837 "removedesktoplast",
838 action_remove_desktop,
839 setup_action_addremove_desktop_last
840 },
841 {
842 "adddesktopcurrent",
843 action_add_desktop,
844 setup_action_addremove_desktop_current
845 },
846 {
847 "removedesktopcurrent",
848 action_remove_desktop,
849 setup_action_addremove_desktop_current
850 },
851 {
852 NULL,
853 NULL,
854 NULL
855 }
856 };
857
858 /* only key bindings can be interactive. thus saith the xor.
859 because of how the mouse is grabbed, mouse events dont even get
860 read during interactive events, so no dice! >:) */
861 #define INTERACTIVE_LIMIT(a, uact) \
862 if (uact != OB_USER_ACTION_KEYBOARD_KEY) \
863 a->data.any.interactive = FALSE;
864
865 ObAction *action_from_string(const gchar *name, ObUserAction uact)
866 {
867 ObAction *a = NULL;
868 gboolean exist = FALSE;
869 gint i;
870
871 for (i = 0; actionstrings[i].name; i++)
872 if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
873 exist = TRUE;
874 a = action_new(actionstrings[i].func);
875 if (actionstrings[i].setup)
876 actionstrings[i].setup(&a, uact);
877 if (a)
878 INTERACTIVE_LIMIT(a, uact);
879 break;
880 }
881 if (!exist)
882 g_message(_("Invalid action '%s' requested. No such action exists."),
883 name);
884 if (!a)
885 g_message(_("Invalid use of action '%s'. Action will be ignored."),
886 name);
887 return a;
888 }
889
890 ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
891 ObUserAction uact)
892 {
893 gchar *actname;
894 ObAction *act = NULL;
895 xmlNodePtr n;
896
897 if (parse_attr_string("name", node, &actname)) {
898 if ((act = action_from_string(actname, uact))) {
899 } else if (act->func == action_move_relative_horz ||
900 act->func == action_move_relative_vert ||
901 act->func == action_resize_relative_horz ||
902 act->func == action_resize_relative_vert) {
903 if ((n = parse_find_node("delta", node->xmlChildrenNode)))
904 act->data.relative.deltax = parse_int(doc, n);
905 } else if (act->func == action_move_relative) {
906 if ((n = parse_find_node("x", node->xmlChildrenNode)))
907 act->data.relative.deltax = parse_int(doc, n);
908 if ((n = parse_find_node("y", node->xmlChildrenNode)))
909 act->data.relative.deltay = parse_int(doc, n);
910 } else if (act->func == action_resize_relative) {
911 if ((n = parse_find_node("left", node->xmlChildrenNode)))
912 act->data.relative.deltaxl = parse_int(doc, n);
913 if ((n = parse_find_node("up", node->xmlChildrenNode)))
914 act->data.relative.deltayu = parse_int(doc, n);
915 if ((n = parse_find_node("right", node->xmlChildrenNode)))
916 act->data.relative.deltax = parse_int(doc, n);
917 if ((n = parse_find_node("down", node->xmlChildrenNode)))
918 act->data.relative.deltay = parse_int(doc, n);
919 } else if (act->func == action_desktop) {
920 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
921 act->data.desktop.desk = parse_int(doc, n);
922 if (act->data.desktop.desk > 0) act->data.desktop.desk--;
923 /*
924 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
925 act->data.desktop.inter.any.interactive =
926 parse_bool(doc, n);
927 */
928 } else if (act->func == action_send_to_desktop) {
929 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
930 act->data.sendto.desk = parse_int(doc, n);
931 if (act->data.sendto.desk > 0) act->data.sendto.desk--;
932 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
933 act->data.sendto.follow = parse_bool(doc, n);
934 } else if (act->func == action_desktop_dir) {
935 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
936 act->data.desktopdir.wrap = parse_bool(doc, n);
937 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
938 act->data.desktopdir.inter.any.interactive =
939 parse_bool(doc, n);
940 } else if (act->func == action_send_to_desktop_dir) {
941 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
942 act->data.sendtodir.wrap = parse_bool(doc, n);
943 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
944 act->data.sendtodir.follow = parse_bool(doc, n);
945 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
946 act->data.sendtodir.inter.any.interactive =
947 parse_bool(doc, n);
948 } else if (act->func == action_directional_focus) {
949 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
950 act->data.interdiraction.dialog = parse_bool(doc, n);
951 if ((n = parse_find_node("panels", node->xmlChildrenNode)))
952 act->data.interdiraction.dock_windows = parse_bool(doc, n);
953 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
954 act->data.interdiraction.desktop_windows =
955 parse_bool(doc, n);
956 } else if (act->func == action_resize) {
957 if ((n = parse_find_node("edge", node->xmlChildrenNode))) {
958 gchar *s = parse_string(doc, n);
959 if (!g_ascii_strcasecmp(s, "top"))
960 act->data.moveresize.corner =
961 prop_atoms.net_wm_moveresize_size_top;
962 else if (!g_ascii_strcasecmp(s, "bottom"))
963 act->data.moveresize.corner =
964 prop_atoms.net_wm_moveresize_size_bottom;
965 else if (!g_ascii_strcasecmp(s, "left"))
966 act->data.moveresize.corner =
967 prop_atoms.net_wm_moveresize_size_left;
968 else if (!g_ascii_strcasecmp(s, "right"))
969 act->data.moveresize.corner =
970 prop_atoms.net_wm_moveresize_size_right;
971 else if (!g_ascii_strcasecmp(s, "topleft"))
972 act->data.moveresize.corner =
973 prop_atoms.net_wm_moveresize_size_topleft;
974 else if (!g_ascii_strcasecmp(s, "topright"))
975 act->data.moveresize.corner =
976 prop_atoms.net_wm_moveresize_size_topright;
977 else if (!g_ascii_strcasecmp(s, "bottomleft"))
978 act->data.moveresize.corner =
979 prop_atoms.net_wm_moveresize_size_bottomleft;
980 else if (!g_ascii_strcasecmp(s, "bottomright"))
981 act->data.moveresize.corner =
982 prop_atoms.net_wm_moveresize_size_bottomright;
983 g_free(s);
984 }
985 } else if (act->func == action_raise ||
986 act->func == action_lower ||
987 act->func == action_raiselower ||
988 act->func == action_shadelower ||
989 act->func == action_unshaderaise) {
990 }
991 INTERACTIVE_LIMIT(act, uact);
992 }
993 g_free(actname);
994 }
995 return act;
996 }
997
998 void action_run_list(GSList *acts, ObClient *c, ObFrameContext context,
999 guint state, guint button, gint x, gint y, Time time,
1000 gboolean cancel, gboolean done)
1001 {
1002 GSList *it;
1003 ObAction *a;
1004
1005 if (!acts)
1006 return;
1007
1008 if (x < 0 && y < 0)
1009 screen_pointer_pos(&x, &y);
1010
1011 for (it = acts; it; it = g_slist_next(it)) {
1012 a = it->data;
1013
1014 if (!(a->data.any.client_action == OB_CLIENT_ACTION_ALWAYS && !c)) {
1015 a->data.any.c = a->data.any.client_action ? c : NULL;
1016 a->data.any.context = context;
1017 a->data.any.x = x;
1018 a->data.any.y = y;
1019
1020 a->data.any.button = button;
1021
1022 a->data.any.time = time;
1023
1024 if (a->data.any.interactive) {
1025 a->data.inter.cancel = cancel;
1026 a->data.inter.final = done;
1027 if (!(cancel || done))
1028 if (!keyboard_interactive_grab(state, a->data.any.c, a))
1029 continue;
1030 }
1031
1032 /* XXX UGLY HACK race with motion event starting a move and the
1033 button release gettnig processed first. answer: don't queue
1034 moveresize starts. UGLY HACK XXX
1035
1036 XXX ALSO don't queue showmenu events, because on button press
1037 events we need to know if a mouse grab is going to take place,
1038 and set the button to 0, so that later motion events don't think
1039 that a drag is going on. since showmenu grabs the pointer..
1040 */
1041 if (a->data.any.interactive || a->func == action_move ||
1042 a->func == action_resize || a->func == action_showmenu)
1043 {
1044 /* interactive actions are not queued */
1045 a->func(&a->data);
1046 } else if (a->func == action_focus ||
1047 a->func == action_activate ||
1048 a->func == action_showmenu)
1049 {
1050 /* XXX MORE UGLY HACK
1051 actions from clicks on client windows are NOT queued.
1052 this solves the mysterious click-and-drag-doesnt-work
1053 problem. it was because the window gets focused and stuff
1054 after the button event has already been passed through. i
1055 dont really know why it should care but it does and it makes
1056 a difference.
1057
1058 however this very bogus ! !
1059 we want to send the button press to the window BEFORE
1060 we do the action because the action might move the windows
1061 (eg change desktops) and then the button press ends up on
1062 the completely wrong window !
1063 so, this is just for that bug, and it will only NOT queue it
1064 if it is a focusing action that can be used with the mouse
1065 pointer. ugh.
1066
1067 also with the menus, there is a race going on. if the
1068 desktop wants to pop up a menu, and we do too, we send them
1069 the button before we pop up the menu, so they pop up their
1070 menu first. but not always. if we pop up our menu before
1071 sending them the button press, then the result is
1072 deterministic. yay.
1073
1074 XXX further more. focus actions are not queued at all,
1075 because if you bind focus->showmenu, the menu will get
1076 hidden to do the focusing
1077 */
1078 a->func(&a->data);
1079 } else
1080 ob_main_loop_queue_action(ob_main_loop, a);
1081 }
1082 }
1083 }
1084
1085 void action_run_string(const gchar *name, struct _ObClient *c, Time time)
1086 {
1087 ObAction *a;
1088 GSList *l;
1089
1090 a = action_from_string(name, OB_USER_ACTION_NONE);
1091 g_assert(a);
1092
1093 l = g_slist_append(NULL, a);
1094
1095 action_run(l, c, 0, time);
1096 }
1097
1098 void action_unfocus (union ActionData *data)
1099 {
1100 if (data->client.any.c == focus_client)
1101 focus_fallback(FALSE, FALSE, TRUE);
1102 }
1103
1104 void action_iconify(union ActionData *data)
1105 {
1106 client_action_start(data);
1107 client_iconify(data->client.any.c, TRUE, TRUE, FALSE);
1108 client_action_end(data, config_focus_under_mouse);
1109 }
1110
1111 void action_focus_order_to_bottom(union ActionData *data)
1112 {
1113 focus_order_to_bottom(data->client.any.c);
1114 }
1115
1116 void action_raiselower(union ActionData *data)
1117 {
1118 ObClient *c = data->client.any.c;
1119
1120 client_action_start(data);
1121 stacking_restack_request(c, NULL, Opposite);
1122 client_action_end(data, config_focus_under_mouse);
1123 }
1124
1125 void action_raise(union ActionData *data)
1126 {
1127 client_action_start(data);
1128 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
1129 client_action_end(data, config_focus_under_mouse);
1130 }
1131
1132 void action_unshaderaise(union ActionData *data)
1133 {
1134 if (data->client.any.c->shaded)
1135 action_unshade(data);
1136 else
1137 action_raise(data);
1138 }
1139
1140 void action_shadelower(union ActionData *data)
1141 {
1142 if (data->client.any.c->shaded)
1143 action_lower(data);
1144 else
1145 action_shade(data);
1146 }
1147
1148 void action_lower(union ActionData *data)
1149 {
1150 client_action_start(data);
1151 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
1152 client_action_end(data, config_focus_under_mouse);
1153 }
1154
1155 void action_close(union ActionData *data)
1156 {
1157 client_close(data->client.any.c);
1158 }
1159
1160 void action_kill(union ActionData *data)
1161 {
1162 client_kill(data->client.any.c);
1163 }
1164
1165 void action_shade(union ActionData *data)
1166 {
1167 client_action_start(data);
1168 client_shade(data->client.any.c, TRUE);
1169 client_action_end(data, config_focus_under_mouse);
1170 }
1171
1172 void action_unshade(union ActionData *data)
1173 {
1174 client_action_start(data);
1175 client_shade(data->client.any.c, FALSE);
1176 client_action_end(data, config_focus_under_mouse);
1177 }
1178
1179 void action_toggle_shade(union ActionData *data)
1180 {
1181 client_action_start(data);
1182 client_shade(data->client.any.c, !data->client.any.c->shaded);
1183 client_action_end(data, config_focus_under_mouse);
1184 }
1185
1186 void action_toggle_omnipresent(union ActionData *data)
1187 {
1188 client_set_desktop(data->client.any.c,
1189 data->client.any.c->desktop == DESKTOP_ALL ?
1190 screen_desktop : DESKTOP_ALL, FALSE, TRUE);
1191 }
1192
1193 void action_move_relative_horz(union ActionData *data)
1194 {
1195 ObClient *c = data->relative.any.c;
1196 client_action_start(data);
1197 client_move(c, c->area.x + data->relative.deltax, c->area.y);
1198 client_action_end(data, FALSE);
1199 }
1200
1201 void action_move_relative_vert(union ActionData *data)
1202 {
1203 ObClient *c = data->relative.any.c;
1204 client_action_start(data);
1205 client_move(c, c->area.x, c->area.y + data->relative.deltax);
1206 client_action_end(data, FALSE);
1207 }
1208
1209 void action_move_to_center(union ActionData *data)
1210 {
1211 ObClient *c = data->client.any.c;
1212 Rect *area;
1213 area = screen_area(c->desktop, client_monitor(c), NULL);
1214 client_action_start(data);
1215 client_move(c, area->x + area->width / 2 - c->area.width / 2,
1216 area->y + area->height / 2 - c->area.height / 2);
1217 client_action_end(data, FALSE);
1218 g_free(area);
1219 }
1220
1221 void action_resize_relative_horz(union ActionData *data)
1222 {
1223 ObClient *c = data->relative.any.c;
1224 client_action_start(data);
1225 client_resize(c,
1226 c->area.width + data->relative.deltax * c->size_inc.width,
1227 c->area.height);
1228 client_action_end(data, FALSE);
1229 }
1230
1231 void action_resize_relative_vert(union ActionData *data)
1232 {
1233 ObClient *c = data->relative.any.c;
1234 if (!c->shaded) {
1235 client_action_start(data);
1236 client_resize(c, c->area.width, c->area.height +
1237 data->relative.deltax * c->size_inc.height);
1238 client_action_end(data, FALSE);
1239 }
1240 }
1241
1242 void action_move_relative(union ActionData *data)
1243 {
1244 ObClient *c = data->relative.any.c;
1245 client_action_start(data);
1246 client_move(c, c->area.x + data->relative.deltax, c->area.y +
1247 data->relative.deltay);
1248 client_action_end(data, FALSE);
1249 }
1250
1251 void action_resize_relative(union ActionData *data)
1252 {
1253 ObClient *c = data->relative.any.c;
1254 gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
1255
1256 client_action_start(data);
1257
1258 x = c->area.x;
1259 y = c->area.y;
1260 ow = c->area.width;
1261 xoff = -data->relative.deltaxl * c->size_inc.width;
1262 nw = ow + data->relative.deltax * c->size_inc.width
1263 + data->relative.deltaxl * c->size_inc.width;
1264 oh = c->area.height;
1265 yoff = -data->relative.deltayu * c->size_inc.height;
1266 nh = oh + data->relative.deltay * c->size_inc.height
1267 + data->relative.deltayu * c->size_inc.height;
1268
1269 g_print("deltax %d %d x %d ow %d xoff %d nw %d\n",
1270 data->relative.deltax,
1271 data->relative.deltaxl,
1272 x, ow, xoff, nw);
1273
1274 client_try_configure(c, &x, &y, &nw, &nh, &lw, &lh, TRUE);
1275 xoff = xoff == 0 ? 0 : (xoff < 0 ? MAX(xoff, ow-nw) : MIN(xoff, ow-nw));
1276 yoff = yoff == 0 ? 0 : (yoff < 0 ? MAX(yoff, oh-nh) : MIN(yoff, oh-nh));
1277 client_move_resize(c, x + xoff, y + yoff, nw, nh);
1278 client_action_end(data, FALSE);
1279 }
1280
1281 void action_maximize_full(union ActionData *data)
1282 {
1283 client_action_start(data);
1284 client_maximize(data->client.any.c, TRUE, 0);
1285 client_action_end(data, config_focus_under_mouse);
1286 }
1287
1288 void action_unmaximize_full(union ActionData *data)
1289 {
1290 client_action_start(data);
1291 client_maximize(data->client.any.c, FALSE, 0);
1292 client_action_end(data, config_focus_under_mouse);
1293 }
1294
1295 void action_toggle_maximize_full(union ActionData *data)
1296 {
1297 client_action_start(data);
1298 client_maximize(data->client.any.c,
1299 !(data->client.any.c->max_horz ||
1300 data->client.any.c->max_vert),
1301 0);
1302 client_action_end(data, config_focus_under_mouse);
1303 }
1304
1305 void action_maximize_horz(union ActionData *data)
1306 {
1307 client_action_start(data);
1308 client_maximize(data->client.any.c, TRUE, 1);
1309 client_action_end(data, config_focus_under_mouse);
1310 }
1311
1312 void action_unmaximize_horz(union ActionData *data)
1313 {
1314 client_action_start(data);
1315 client_maximize(data->client.any.c, FALSE, 1);
1316 client_action_end(data, config_focus_under_mouse);
1317 }
1318
1319 void action_toggle_maximize_horz(union ActionData *data)
1320 {
1321 client_action_start(data);
1322 client_maximize(data->client.any.c,
1323 !data->client.any.c->max_horz, 1);
1324 client_action_end(data, config_focus_under_mouse);
1325 }
1326
1327 void action_maximize_vert(union ActionData *data)
1328 {
1329 client_action_start(data);
1330 client_maximize(data->client.any.c, TRUE, 2);
1331 client_action_end(data, config_focus_under_mouse);
1332 }
1333
1334 void action_unmaximize_vert(union ActionData *data)
1335 {
1336 client_action_start(data);
1337 client_maximize(data->client.any.c, FALSE, 2);
1338 client_action_end(data, config_focus_under_mouse);
1339 }
1340
1341 void action_toggle_maximize_vert(union ActionData *data)
1342 {
1343 client_action_start(data);
1344 client_maximize(data->client.any.c,
1345 !data->client.any.c->max_vert, 2);
1346 client_action_end(data, config_focus_under_mouse);
1347 }
1348
1349 void action_toggle_fullscreen(union ActionData *data)
1350 {
1351 client_action_start(data);
1352 client_fullscreen(data->client.any.c, !(data->client.any.c->fullscreen));
1353 client_action_end(data, config_focus_under_mouse);
1354 }
1355
1356 void action_send_to_desktop(union ActionData *data)
1357 {
1358 ObClient *c = data->sendto.any.c;
1359
1360 if (!client_normal(c)) return;
1361
1362 if (data->sendto.desk < screen_num_desktops ||
1363 data->sendto.desk == DESKTOP_ALL) {
1364 client_set_desktop(c, data->sendto.desk, data->sendto.follow, FALSE);
1365 if (data->sendto.follow && data->sendto.desk != screen_desktop)
1366 screen_set_desktop(data->sendto.desk, TRUE);
1367 }
1368 }
1369
1370 void action_desktop(union ActionData *data)
1371 {
1372 /* XXX add the interactive/dialog option back again once the dialog
1373 has been made to not use grabs */
1374 if (data->desktop.desk < screen_num_desktops ||
1375 data->desktop.desk == DESKTOP_ALL)
1376 {
1377 screen_set_desktop(data->desktop.desk, TRUE);
1378 if (data->inter.any.interactive)
1379 screen_desktop_popup(data->desktop.desk, TRUE);
1380 }
1381 }
1382
1383 void action_desktop_dir(union ActionData *data)
1384 {
1385 guint d;
1386
1387 d = screen_cycle_desktop(data->desktopdir.dir,
1388 data->desktopdir.wrap,
1389 data->desktopdir.linear,
1390 data->desktopdir.inter.any.interactive,
1391 data->desktopdir.inter.final,
1392 data->desktopdir.inter.cancel);
1393 /* only move the desktop when the action is complete. if we switch
1394 desktops during the interactive action, focus will move but with
1395 NotifyWhileGrabbed and applications don't like that. */
1396 if (!data->sendtodir.inter.any.interactive ||
1397 (data->sendtodir.inter.final && !data->sendtodir.inter.cancel))
1398 {
1399 if (d != screen_desktop)
1400 screen_set_desktop(d, TRUE);
1401 }
1402 }
1403
1404 void action_send_to_desktop_dir(union ActionData *data)
1405 {
1406 ObClient *c = data->sendtodir.inter.any.c;
1407 guint d;
1408
1409 if (!client_normal(c)) return;
1410
1411 d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
1412 data->sendtodir.linear,
1413 data->sendtodir.inter.any.interactive,
1414 data->sendtodir.inter.final,
1415 data->sendtodir.inter.cancel);
1416 /* only move the desktop when the action is complete. if we switch
1417 desktops during the interactive action, focus will move but with
1418 NotifyWhileGrabbed and applications don't like that. */
1419 if (!data->sendtodir.inter.any.interactive ||
1420 (data->sendtodir.inter.final && !data->sendtodir.inter.cancel))
1421 {
1422 client_set_desktop(c, d, data->sendtodir.follow, FALSE);
1423 if (data->sendtodir.follow && d != screen_desktop)
1424 screen_set_desktop(d, TRUE);
1425 }
1426 }
1427
1428 void action_desktop_last(union ActionData *data)
1429 {
1430 if (screen_last_desktop < screen_num_desktops)
1431 screen_set_desktop(screen_last_desktop, TRUE);
1432 }
1433
1434 void action_toggle_decorations(union ActionData *data)
1435 {
1436 ObClient *c = data->client.any.c;
1437
1438 client_action_start(data);
1439 client_set_undecorated(c, !c->undecorated);
1440 client_action_end(data, FALSE);
1441 }
1442
1443 static guint32 pick_corner(gint x, gint y, gint cx, gint cy, gint cw, gint ch,
1444 gboolean shaded)
1445 {
1446 /* let's make x and y client relative instead of screen relative */
1447 x = x - cx;
1448 y = ch - (y - cy); /* y is inverted, 0 is at the bottom of the window */
1449
1450 #define X x*ch/cw
1451 #define A -4*X + 7*ch/3
1452 #define B 4*X -15*ch/9
1453 #define C -X/4 + 2*ch/3
1454 #define D X/4 + 5*ch/12
1455 #define E X/4 + ch/3
1456 #define F -X/4 + 7*ch/12
1457 #define G 4*X - 4*ch/3
1458 #define H -4*X + 8*ch/3
1459 #define a (y > 5*ch/9)
1460 #define b (x < 4*cw/9)
1461 #define c (x > 5*cw/9)
1462 #define d (y < 4*ch/9)
1463
1464 /*
1465 Each of these defines (except X which is just there for fun), represents
1466 the equation of a line. The lines they represent are shown in the diagram
1467 below. Checking y against these lines, we are able to choose a region
1468 of the window as shown.
1469
1470 +---------------------A-------|-------|-------B---------------------+
1471 | |A B| |
1472 | |A | | B| |
1473 | | A B | |
1474 | | A | | B | |
1475 | | A B | |
1476 | | A | | B | |
1477 | northwest | A north B | northeast |
1478 | | A | | B | |
1479 | | A B | |
1480 C---------------------+----A--+-------+--B----+---------------------D
1481 |CCCCCCC | A B | DDDDDDD|
1482 | CCCCCCCC | A | | B | DDDDDDDD |
1483 | CCCCCCC A B DDDDDDD |
1484 - - - - - - - - - - - +CCCCCCC+aaaaaaa+DDDDDDD+ - - - - - - - - - - - -
1485 | | b c | | sh
1486 | west | b move c | east | ad
1487 | | b c | | ed
1488 - - - - - - - - - - - +EEEEEEE+ddddddd+FFFFFFF+- - - - - - - - - - - -
1489 | EEEEEEE G H FFFFFFF |
1490 | EEEEEEEE | G | | H | FFFFFFFF |
1491 |EEEEEEE | G H | FFFFFFF|
1492 E---------------------+----G--+-------+--H----+---------------------F
1493 | | G H | |
1494 | | G | | H | |
1495 | southwest | G south H | southeast |
1496 | | G | | H | |
1497 | | G H | |
1498 | | G | | H | |
1499 | | G H | |
1500 | |G | | H| |
1501 | |G H| |
1502 +---------------------G-------|-------|-------H---------------------+
1503 */
1504
1505 if (shaded) {
1506 /* for shaded windows, you can only resize west/east and move */
1507 if (b)
1508 return prop_atoms.net_wm_moveresize_size_left;
1509 if (c)
1510 return prop_atoms.net_wm_moveresize_size_right;
1511 return prop_atoms.net_wm_moveresize_move;
1512 }
1513
1514 if (y < A && y >= C)
1515 return prop_atoms.net_wm_moveresize_size_topleft;
1516 else if (y >= A && y >= B && a)
1517 return prop_atoms.net_wm_moveresize_size_top;
1518 else if (y < B && y >= D)
1519 return prop_atoms.net_wm_moveresize_size_topright;
1520 else if (y < C && y >= E && b)
1521 return prop_atoms.net_wm_moveresize_size_left;
1522 else if (y < D && y >= F && c)
1523 return prop_atoms.net_wm_moveresize_size_right;
1524 else if (y < E && y >= G)
1525 return prop_atoms.net_wm_moveresize_size_bottomleft;
1526 else if (y < G && y < H && d)
1527 return prop_atoms.net_wm_moveresize_size_bottom;
1528 else if (y >= H && y < F)
1529 return prop_atoms.net_wm_moveresize_size_bottomright;
1530 else
1531 return prop_atoms.net_wm_moveresize_move;
1532
1533 #undef X
1534 #undef A
1535 #undef B
1536 #undef C
1537 #undef D
1538 #undef E
1539 #undef F
1540 #undef G
1541 #undef H
1542 #undef a
1543 #undef b
1544 #undef c
1545 #undef d
1546 }
1547
1548 void action_move(union ActionData *data)
1549 {
1550 ObClient *c = data->moveresize.any.c;
1551 guint32 corner;
1552
1553 if (data->moveresize.keyboard)
1554 corner = prop_atoms.net_wm_moveresize_move_keyboard;
1555 else
1556 corner = prop_atoms.net_wm_moveresize_move;
1557
1558 moveresize_start(c, data->any.x, data->any.y, data->any.button, corner);
1559 }
1560
1561 void action_resize(union ActionData *data)
1562 {
1563 ObClient *c = data->moveresize.any.c;
1564 guint32 corner;
1565
1566 if (data->moveresize.keyboard)
1567 corner = prop_atoms.net_wm_moveresize_size_keyboard;
1568 else if (data->moveresize.corner)
1569 corner = data->moveresize.corner; /* it was specified in the binding */
1570 else
1571 corner = pick_corner(data->any.x, data->any.y,
1572 c->frame->area.x, c->frame->area.y,
1573 /* use the client size because the frame
1574 can be differently sized (shaded
1575 windows) and we want this based on the
1576 clients size */
1577 c->area.width + c->frame->size.left +
1578 c->frame->size.right,
1579 c->area.height + c->frame->size.top +
1580 c->frame->size.bottom, c->shaded);
1581
1582 moveresize_start(c, data->any.x, data->any.y, data->any.button, corner);
1583 }
1584
1585 void action_directional_focus(union ActionData *data)
1586 {
1587 /* if using focus_delay, stop the timer now so that focus doesn't go moving
1588 on us */
1589 event_halt_focus_delay();
1590
1591 focus_directional_cycle(data->interdiraction.direction,
1592 data->interdiraction.dock_windows,
1593 data->interdiraction.desktop_windows,
1594 data->any.interactive,
1595 data->interdiraction.dialog,
1596 data->interdiraction.inter.final,
1597 data->interdiraction.inter.cancel);
1598 }
1599
1600 void action_movetoedge(union ActionData *data)
1601 {
1602 gint x, y;
1603 ObClient *c = data->diraction.any.c;
1604
1605 x = c->frame->area.x;
1606 y = c->frame->area.y;
1607
1608 switch(data->diraction.direction) {
1609 case OB_DIRECTION_NORTH:
1610 y = client_directional_edge_search(c, OB_DIRECTION_NORTH,
1611 data->diraction.hang)
1612 - (data->diraction.hang ? c->frame->area.height : 0);
1613 break;
1614 case OB_DIRECTION_WEST:
1615 x = client_directional_edge_search(c, OB_DIRECTION_WEST,
1616 data->diraction.hang)
1617 - (data->diraction.hang ? c->frame->area.width : 0);
1618 break;
1619 case OB_DIRECTION_SOUTH:
1620 y = client_directional_edge_search(c, OB_DIRECTION_SOUTH,
1621 data->diraction.hang)
1622 - (data->diraction.hang ? 0 : c->frame->area.height);
1623 break;
1624 case OB_DIRECTION_EAST:
1625 x = client_directional_edge_search(c, OB_DIRECTION_EAST,
1626 data->diraction.hang)
1627 - (data->diraction.hang ? 0 : c->frame->area.width);
1628 break;
1629 default:
1630 g_assert_not_reached();
1631 }
1632 frame_frame_gravity(c->frame, &x, &y, c->area.width, c->area.height);
1633 client_action_start(data);
1634 client_move(c, x, y);
1635 client_action_end(data, FALSE);
1636 }
1637
1638 void action_growtoedge(union ActionData *data)
1639 {
1640 gint x, y, width, height, dest;
1641 ObClient *c = data->diraction.any.c;
1642 Rect *a;
1643
1644 a = screen_area(c->desktop, SCREEN_AREA_ALL_MONITORS, &c->frame->area);
1645 x = c->frame->area.x;
1646 y = c->frame->area.y;
1647 /* get the unshaded frame's dimensions..if it is shaded */
1648 width = c->area.width + c->frame->size.left + c->frame->size.right;
1649 height = c->area.height + c->frame->size.top + c->frame->size.bottom;
1650
1651 switch(data->diraction.direction) {
1652 case OB_DIRECTION_NORTH:
1653 if (c->shaded) break; /* don't allow vertical resize if shaded */
1654
1655 dest = client_directional_edge_search(c, OB_DIRECTION_NORTH, FALSE);
1656 if (a->y == y)
1657 height = height / 2;
1658 else {
1659 height = c->frame->area.y + height - dest;
1660 y = dest;
1661 }
1662 break;
1663 case OB_DIRECTION_WEST:
1664 dest = client_directional_edge_search(c, OB_DIRECTION_WEST, FALSE);
1665 if (a->x == x)
1666 width = width / 2;
1667 else {
1668 width = c->frame->area.x + width - dest;
1669 x = dest;
1670 }
1671 break;
1672 case OB_DIRECTION_SOUTH:
1673 if (c->shaded) break; /* don't allow vertical resize if shaded */
1674
1675 dest = client_directional_edge_search(c, OB_DIRECTION_SOUTH, FALSE);
1676 if (a->y + a->height == y + c->frame->area.height) {
1677 height = c->frame->area.height / 2;
1678 y = a->y + a->height - height;
1679 } else
1680 height = dest - c->frame->area.y;
1681 y += (height - c->frame->area.height) % c->size_inc.height;
1682 height -= (height - c->frame->area.height) % c->size_inc.height;
1683 break;
1684 case OB_DIRECTION_EAST:
1685 dest = client_directional_edge_search(c, OB_DIRECTION_EAST, FALSE);
1686 if (a->x + a->width == x + c->frame->area.width) {
1687 width = c->frame->area.width / 2;
1688 x = a->x + a->width - width;
1689 } else
1690 width = dest - c->frame->area.x;
1691 x += (width - c->frame->area.width) % c->size_inc.width;
1692 width -= (width - c->frame->area.width) % c->size_inc.width;
1693 break;
1694 default:
1695 g_assert_not_reached();
1696 }
1697 width -= c->frame->size.left + c->frame->size.right;
1698 height -= c->frame->size.top + c->frame->size.bottom;
1699 frame_frame_gravity(c->frame, &x, &y, width, height);
1700 client_action_start(data);
1701 client_move_resize(c, x, y, width, height);
1702 client_action_end(data, FALSE);
1703 g_free(a);
1704 }
1705
1706 void action_send_to_layer(union ActionData *data)
1707 {
1708 client_set_layer(data->layer.any.c, data->layer.layer);
1709 }
1710
1711 void action_toggle_layer(union ActionData *data)
1712 {
1713 ObClient *c = data->layer.any.c;
1714
1715 client_action_start(data);
1716 if (data->layer.layer < 0)
1717 client_set_layer(c, c->below ? 0 : -1);
1718 else if (data->layer.layer > 0)
1719 client_set_layer(c, c->above ? 0 : 1);
1720 client_action_end(data, config_focus_under_mouse);
1721 }
1722
1723 void action_toggle_dockautohide(union ActionData *data)
1724 {
1725 config_dock_hide = !config_dock_hide;
1726 dock_configure();
1727 }
1728
1729 void action_add_desktop(union ActionData *data)
1730 {
1731 client_action_start(data);
1732 screen_set_num_desktops(screen_num_desktops+1);
1733
1734 /* move all the clients over */
1735 if (data->addremovedesktop.current) {
1736 GList *it;
1737
1738 for (it = client_list; it; it = g_list_next(it)) {
1739 ObClient *c = it->data;
1740 if (c->desktop != DESKTOP_ALL && c->desktop >= screen_desktop)
1741 client_set_desktop(c, c->desktop+1, FALSE, TRUE);
1742 }
1743 }
1744
1745 client_action_end(data, config_focus_under_mouse);
1746 }
1747
1748 void action_remove_desktop(union ActionData *data)
1749 {
1750 guint rmdesktop, movedesktop;
1751 GList *it, *stacking_copy;
1752
1753 if (screen_num_desktops < 2) return;
1754
1755 client_action_start(data);
1756
1757 /* what desktop are we removing and moving to? */
1758 if (data->addremovedesktop.current)
1759 rmdesktop = screen_desktop;
1760 else
1761 rmdesktop = screen_num_desktops - 1;
1762 if (rmdesktop < screen_num_desktops - 1)
1763 movedesktop = rmdesktop + 1;
1764 else
1765 movedesktop = rmdesktop;
1766
1767 /* make a copy of the list cuz we're changing it */
1768 stacking_copy = g_list_copy(stacking_list);
1769 for (it = g_list_last(stacking_copy); it; it = g_list_previous(it)) {
1770 if (WINDOW_IS_CLIENT(it->data)) {
1771 ObClient *c = it->data;
1772 guint d = c->desktop;
1773 if (d != DESKTOP_ALL && d >= movedesktop) {
1774 client_set_desktop(c, c->desktop - 1, TRUE, TRUE);
1775 ob_debug("moving window %s\n", c->title);
1776 }
1777 /* raise all the windows that are on the current desktop which
1778 is being merged */
1779 if ((screen_desktop == rmdesktop - 1 ||
1780 screen_desktop == rmdesktop) &&
1781 (d == DESKTOP_ALL || d == screen_desktop))
1782 {
1783 stacking_raise(CLIENT_AS_WINDOW(c));
1784 ob_debug("raising window %s\n", c->title);
1785 }
1786 }
1787 }
1788
1789 /* act like we're changing desktops */
1790 if (screen_desktop < screen_num_desktops - 1) {
1791 gint d = screen_desktop;
1792 screen_desktop = screen_last_desktop;
1793 screen_set_desktop(d, TRUE);
1794 ob_debug("fake desktop change\n");
1795 }
1796
1797 screen_set_num_desktops(screen_num_desktops-1);
1798
1799 client_action_end(data, config_focus_under_mouse);
1800 }
This page took 0.126112 seconds and 4 git commands to generate.