]> Dogcows Code - chaz/openbox/blob - openbox/action.c
add max horz/vert actions. add toggle/on/off ability to all the maximize actions.
[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
43
44 typedef struct
45 {
46 const gchar *name;
47 void (*func)(union ActionData *);
48 void (*setup)(ObAction **, ObUserAction uact);
49 } ActionString;
50
51 static ObAction *action_new(void (*func)(union ActionData *data))
52 {
53 ObAction *a = g_new0(ObAction, 1);
54 a->ref = 1;
55 a->func = func;
56
57 return a;
58 }
59
60 void action_ref(ObAction *a)
61 {
62 ++a->ref;
63 }
64
65 void action_unref(ObAction *a)
66 {
67 if (a == NULL) return;
68
69 if (--a->ref > 0) return;
70
71 /* deal with pointers */
72 if (a->func == action_execute || a->func == action_restart)
73 g_free(a->data.execute.path);
74 else if (a->func == action_debug)
75 g_free(a->data.debug.string);
76 else if (a->func == action_showmenu)
77 g_free(a->data.showmenu.name);
78
79 g_free(a);
80 }
81
82 ObAction* action_copy(const ObAction *src)
83 {
84 ObAction *a = action_new(src->func);
85
86 a->data = src->data;
87
88 /* deal with pointers */
89 if (a->func == action_execute || a->func == action_restart)
90 a->data.execute.path = g_strdup(a->data.execute.path);
91 else if (a->func == action_debug)
92 a->data.debug.string = g_strdup(a->data.debug.string);
93 else if (a->func == action_showmenu)
94 a->data.showmenu.name = g_strdup(a->data.showmenu.name);
95
96 return a;
97 }
98
99 void setup_action_directional_focus_north(ObAction **a, ObUserAction uact)
100 {
101 (*a)->data.interdiraction.inter.any.interactive = TRUE;
102 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTH;
103 (*a)->data.interdiraction.dialog = TRUE;
104 (*a)->data.interdiraction.dock_windows = FALSE;
105 (*a)->data.interdiraction.desktop_windows = FALSE;
106 }
107
108 void setup_action_directional_focus_east(ObAction **a, ObUserAction uact)
109 {
110 (*a)->data.interdiraction.inter.any.interactive = TRUE;
111 (*a)->data.interdiraction.direction = OB_DIRECTION_EAST;
112 (*a)->data.interdiraction.dialog = TRUE;
113 (*a)->data.interdiraction.dock_windows = FALSE;
114 (*a)->data.interdiraction.desktop_windows = FALSE;
115 }
116
117 void setup_action_directional_focus_south(ObAction **a, ObUserAction uact)
118 {
119 (*a)->data.interdiraction.inter.any.interactive = TRUE;
120 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTH;
121 (*a)->data.interdiraction.dialog = TRUE;
122 (*a)->data.interdiraction.dock_windows = FALSE;
123 (*a)->data.interdiraction.desktop_windows = FALSE;
124 }
125
126 void setup_action_directional_focus_west(ObAction **a, ObUserAction uact)
127 {
128 (*a)->data.interdiraction.inter.any.interactive = TRUE;
129 (*a)->data.interdiraction.direction = OB_DIRECTION_WEST;
130 (*a)->data.interdiraction.dialog = TRUE;
131 (*a)->data.interdiraction.dock_windows = FALSE;
132 (*a)->data.interdiraction.desktop_windows = FALSE;
133 }
134
135 void setup_action_directional_focus_northeast(ObAction **a, ObUserAction uact)
136 {
137 (*a)->data.interdiraction.inter.any.interactive = TRUE;
138 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHEAST;
139 (*a)->data.interdiraction.dialog = TRUE;
140 (*a)->data.interdiraction.dock_windows = FALSE;
141 (*a)->data.interdiraction.desktop_windows = FALSE;
142 }
143
144 void setup_action_directional_focus_southeast(ObAction **a, ObUserAction uact)
145 {
146 (*a)->data.interdiraction.inter.any.interactive = TRUE;
147 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHEAST;
148 (*a)->data.interdiraction.dialog = TRUE;
149 (*a)->data.interdiraction.dock_windows = FALSE;
150 (*a)->data.interdiraction.desktop_windows = FALSE;
151 }
152
153 void setup_action_directional_focus_southwest(ObAction **a, ObUserAction uact)
154 {
155 (*a)->data.interdiraction.inter.any.interactive = TRUE;
156 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHWEST;
157 (*a)->data.interdiraction.dialog = TRUE;
158 (*a)->data.interdiraction.dock_windows = FALSE;
159 (*a)->data.interdiraction.desktop_windows = FALSE;
160 }
161
162 void setup_action_directional_focus_northwest(ObAction **a, ObUserAction uact)
163 {
164 (*a)->data.interdiraction.inter.any.interactive = TRUE;
165 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHWEST;
166 (*a)->data.interdiraction.dialog = TRUE;
167 (*a)->data.interdiraction.dock_windows = FALSE;
168 (*a)->data.interdiraction.desktop_windows = FALSE;
169 }
170
171 void setup_action_send_to_desktop(ObAction **a, ObUserAction uact)
172 {
173 (*a)->data.sendto.any.client_action = OB_CLIENT_ACTION_ALWAYS;
174 (*a)->data.sendto.follow = TRUE;
175 }
176
177 void setup_action_send_to_desktop_prev(ObAction **a, ObUserAction uact)
178 {
179 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
180 (*a)->data.sendtodir.inter.any.interactive = TRUE;
181 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
182 (*a)->data.sendtodir.linear = TRUE;
183 (*a)->data.sendtodir.wrap = TRUE;
184 (*a)->data.sendtodir.follow = TRUE;
185 }
186
187 void setup_action_send_to_desktop_next(ObAction **a, ObUserAction uact)
188 {
189 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
190 (*a)->data.sendtodir.inter.any.interactive = TRUE;
191 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
192 (*a)->data.sendtodir.linear = TRUE;
193 (*a)->data.sendtodir.wrap = TRUE;
194 (*a)->data.sendtodir.follow = TRUE;
195 }
196
197 void setup_action_send_to_desktop_left(ObAction **a, ObUserAction uact)
198 {
199 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
200 (*a)->data.sendtodir.inter.any.interactive = TRUE;
201 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
202 (*a)->data.sendtodir.linear = FALSE;
203 (*a)->data.sendtodir.wrap = TRUE;
204 (*a)->data.sendtodir.follow = TRUE;
205 }
206
207 void setup_action_send_to_desktop_right(ObAction **a, ObUserAction uact)
208 {
209 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
210 (*a)->data.sendtodir.inter.any.interactive = TRUE;
211 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
212 (*a)->data.sendtodir.linear = FALSE;
213 (*a)->data.sendtodir.wrap = TRUE;
214 (*a)->data.sendtodir.follow = TRUE;
215 }
216
217 void setup_action_send_to_desktop_up(ObAction **a, ObUserAction uact)
218 {
219 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
220 (*a)->data.sendtodir.inter.any.interactive = TRUE;
221 (*a)->data.sendtodir.dir = OB_DIRECTION_NORTH;
222 (*a)->data.sendtodir.linear = FALSE;
223 (*a)->data.sendtodir.wrap = TRUE;
224 (*a)->data.sendtodir.follow = TRUE;
225 }
226
227 void setup_action_send_to_desktop_down(ObAction **a, ObUserAction uact)
228 {
229 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
230 (*a)->data.sendtodir.inter.any.interactive = TRUE;
231 (*a)->data.sendtodir.dir = OB_DIRECTION_SOUTH;
232 (*a)->data.sendtodir.linear = FALSE;
233 (*a)->data.sendtodir.wrap = TRUE;
234 (*a)->data.sendtodir.follow = TRUE;
235 }
236
237 void setup_action_desktop(ObAction **a, ObUserAction uact)
238 {
239 /*
240 (*a)->data.desktop.inter.any.interactive = FALSE;
241 */
242 }
243
244 void setup_action_desktop_prev(ObAction **a, ObUserAction uact)
245 {
246 (*a)->data.desktopdir.inter.any.interactive = TRUE;
247 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
248 (*a)->data.desktopdir.linear = TRUE;
249 (*a)->data.desktopdir.wrap = TRUE;
250 }
251
252 void setup_action_desktop_next(ObAction **a, ObUserAction uact)
253 {
254 (*a)->data.desktopdir.inter.any.interactive = TRUE;
255 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
256 (*a)->data.desktopdir.linear = TRUE;
257 (*a)->data.desktopdir.wrap = TRUE;
258 }
259
260 void setup_action_desktop_left(ObAction **a, ObUserAction uact)
261 {
262 (*a)->data.desktopdir.inter.any.interactive = TRUE;
263 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
264 (*a)->data.desktopdir.linear = FALSE;
265 (*a)->data.desktopdir.wrap = TRUE;
266 }
267
268 void setup_action_desktop_right(ObAction **a, ObUserAction uact)
269 {
270 (*a)->data.desktopdir.inter.any.interactive = TRUE;
271 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
272 (*a)->data.desktopdir.linear = FALSE;
273 (*a)->data.desktopdir.wrap = TRUE;
274 }
275
276 void setup_action_desktop_up(ObAction **a, ObUserAction uact)
277 {
278 (*a)->data.desktopdir.inter.any.interactive = TRUE;
279 (*a)->data.desktopdir.dir = OB_DIRECTION_NORTH;
280 (*a)->data.desktopdir.linear = FALSE;
281 (*a)->data.desktopdir.wrap = TRUE;
282 }
283
284 void setup_action_desktop_down(ObAction **a, ObUserAction uact)
285 {
286 (*a)->data.desktopdir.inter.any.interactive = TRUE;
287 (*a)->data.desktopdir.dir = OB_DIRECTION_SOUTH;
288 (*a)->data.desktopdir.linear = FALSE;
289 (*a)->data.desktopdir.wrap = TRUE;
290 }
291
292 void setup_action_movefromedge_north(ObAction **a, ObUserAction uact)
293 {
294 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
295 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
296 (*a)->data.diraction.hang = TRUE;
297 }
298
299 void setup_action_movefromedge_south(ObAction **a, ObUserAction uact)
300 {
301 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
302 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
303 (*a)->data.diraction.hang = TRUE;
304 }
305
306 void setup_action_movefromedge_east(ObAction **a, ObUserAction uact)
307 {
308 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
309 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
310 (*a)->data.diraction.hang = TRUE;
311 }
312
313 void setup_action_movefromedge_west(ObAction **a, ObUserAction uact)
314 {
315 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
316 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
317 (*a)->data.diraction.hang = TRUE;
318 }
319
320 void setup_action_movetoedge_north(ObAction **a, ObUserAction uact)
321 {
322 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
323 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
324 (*a)->data.diraction.hang = FALSE;
325 }
326
327 void setup_action_movetoedge_south(ObAction **a, ObUserAction uact)
328 {
329 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
330 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
331 (*a)->data.diraction.hang = FALSE;
332 }
333
334 void setup_action_movetoedge_east(ObAction **a, ObUserAction uact)
335 {
336 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
337 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
338 (*a)->data.diraction.hang = FALSE;
339 }
340
341 void setup_action_movetoedge_west(ObAction **a, ObUserAction uact)
342 {
343 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
344 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
345 (*a)->data.diraction.hang = FALSE;
346 }
347
348 void setup_action_growtoedge_north(ObAction **a, ObUserAction uact)
349 {
350 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
351 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
352 }
353
354 void setup_action_growtoedge_south(ObAction **a, ObUserAction uact)
355 {
356 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
357 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
358 }
359
360 void setup_action_growtoedge_east(ObAction **a, ObUserAction uact)
361 {
362 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
363 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
364 }
365
366 void setup_action_growtoedge_west(ObAction **a, ObUserAction uact)
367 {
368 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
369 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
370 }
371
372 void setup_action_top_layer(ObAction **a, ObUserAction uact)
373 {
374 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
375 (*a)->data.layer.layer = 1;
376 }
377
378 void setup_action_normal_layer(ObAction **a, ObUserAction uact)
379 {
380 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
381 (*a)->data.layer.layer = 0;
382 }
383
384 void setup_action_bottom_layer(ObAction **a, ObUserAction uact)
385 {
386 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
387 (*a)->data.layer.layer = -1;
388 }
389
390 void setup_action_resize(ObAction **a, ObUserAction uact)
391 {
392 (*a)->data.moveresize.any.client_action = OB_CLIENT_ACTION_ALWAYS;
393 (*a)->data.moveresize.keyboard =
394 (uact == OB_USER_ACTION_NONE ||
395 uact == OB_USER_ACTION_KEYBOARD_KEY ||
396 uact == OB_USER_ACTION_MENU_SELECTION);
397 (*a)->data.moveresize.corner = 0;
398 }
399
400 void setup_action_addremove_desktop_current(ObAction **a, ObUserAction uact)
401 {
402 (*a)->data.addremovedesktop.current = TRUE;
403 }
404
405 void setup_action_addremove_desktop_last(ObAction **a, ObUserAction uact)
406 {
407 (*a)->data.addremovedesktop.current = FALSE;
408 }
409
410 void setup_client_action(ObAction **a, ObUserAction uact)
411 {
412 (*a)->data.any.client_action = OB_CLIENT_ACTION_ALWAYS;
413 }
414
415 ActionString actionstrings[] =
416 {
417 {
418 "directionalfocusnorth",
419 action_directional_focus,
420 setup_action_directional_focus_north
421 },
422 {
423 "directionalfocuseast",
424 action_directional_focus,
425 setup_action_directional_focus_east
426 },
427 {
428 "directionalfocussouth",
429 action_directional_focus,
430 setup_action_directional_focus_south
431 },
432 {
433 "directionalfocuswest",
434 action_directional_focus,
435 setup_action_directional_focus_west
436 },
437 {
438 "directionalfocusnortheast",
439 action_directional_focus,
440 setup_action_directional_focus_northeast
441 },
442 {
443 "directionalfocussoutheast",
444 action_directional_focus,
445 setup_action_directional_focus_southeast
446 },
447 {
448 "directionalfocussouthwest",
449 action_directional_focus,
450 setup_action_directional_focus_southwest
451 },
452 {
453 "directionalfocusnorthwest",
454 action_directional_focus,
455 setup_action_directional_focus_northwest
456 },
457 {
458 "kill",
459 action_kill,
460 setup_client_action
461 },
462 {
463 "shadelower",
464 action_shadelower,
465 setup_client_action
466 },
467 {
468 "unshaderaise",
469 action_unshaderaise,
470 setup_client_action
471 },
472 {
473 "toggleomnipresent",
474 action_toggle_omnipresent,
475 setup_client_action
476 },
477 {
478 "resizerelativevert",
479 action_resize_relative_vert,
480 setup_client_action
481 },
482 {
483 "resizerelative",
484 action_resize_relative,
485 setup_client_action
486 },
487 {
488 "sendtodesktop",
489 action_send_to_desktop,
490 setup_action_send_to_desktop
491 },
492 {
493 "sendtodesktopnext",
494 action_send_to_desktop_dir,
495 setup_action_send_to_desktop_next
496 },
497 {
498 "sendtodesktopprevious",
499 action_send_to_desktop_dir,
500 setup_action_send_to_desktop_prev
501 },
502 {
503 "sendtodesktopright",
504 action_send_to_desktop_dir,
505 setup_action_send_to_desktop_right
506 },
507 {
508 "sendtodesktopleft",
509 action_send_to_desktop_dir,
510 setup_action_send_to_desktop_left
511 },
512 {
513 "sendtodesktopup",
514 action_send_to_desktop_dir,
515 setup_action_send_to_desktop_up
516 },
517 {
518 "sendtodesktopdown",
519 action_send_to_desktop_dir,
520 setup_action_send_to_desktop_down
521 },
522 {
523 "desktop",
524 action_desktop,
525 setup_action_desktop
526 },
527 {
528 "desktopnext",
529 action_desktop_dir,
530 setup_action_desktop_next
531 },
532 {
533 "desktopprevious",
534 action_desktop_dir,
535 setup_action_desktop_prev
536 },
537 {
538 "desktopright",
539 action_desktop_dir,
540 setup_action_desktop_right
541 },
542 {
543 "desktopleft",
544 action_desktop_dir,
545 setup_action_desktop_left
546 },
547 {
548 "desktopup",
549 action_desktop_dir,
550 setup_action_desktop_up
551 },
552 {
553 "desktopdown",
554 action_desktop_dir,
555 setup_action_desktop_down
556 },
557 {
558 "toggledecorations",
559 action_toggle_decorations,
560 setup_client_action
561 },
562 {
563 "resize",
564 action_resize,
565 setup_action_resize
566 },
567 {
568 "toggledockautohide",
569 action_toggle_dockautohide,
570 NULL
571 },
572 {
573 "desktoplast",
574 action_desktop_last,
575 NULL
576 },
577 {
578 "sendtotoplayer",
579 action_send_to_layer,
580 setup_action_top_layer
581 },
582 {
583 "togglealwaysontop",
584 action_toggle_layer,
585 setup_action_top_layer
586 },
587 {
588 "sendtonormallayer",
589 action_send_to_layer,
590 setup_action_normal_layer
591 },
592 {
593 "sendtobottomlayer",
594 action_send_to_layer,
595 setup_action_bottom_layer
596 },
597 {
598 "togglealwaysonbottom",
599 action_toggle_layer,
600 setup_action_bottom_layer
601 },
602 {
603 "movefromedgenorth",
604 action_movetoedge,
605 setup_action_movefromedge_north
606 },
607 {
608 "movefromedgesouth",
609 action_movetoedge,
610 setup_action_movefromedge_south
611 },
612 {
613 "movefromedgewest",
614 action_movetoedge,
615 setup_action_movefromedge_west
616 },
617 {
618 "movefromedgeeast",
619 action_movetoedge,
620 setup_action_movefromedge_east
621 },
622 {
623 "movetoedgenorth",
624 action_movetoedge,
625 setup_action_movetoedge_north
626 },
627 {
628 "movetoedgesouth",
629 action_movetoedge,
630 setup_action_movetoedge_south
631 },
632 {
633 "movetoedgewest",
634 action_movetoedge,
635 setup_action_movetoedge_west
636 },
637 {
638 "movetoedgeeast",
639 action_movetoedge,
640 setup_action_movetoedge_east
641 },
642 {
643 "growtoedgenorth",
644 action_growtoedge,
645 setup_action_growtoedge_north
646 },
647 {
648 "growtoedgesouth",
649 action_growtoedge,
650 setup_action_growtoedge_south
651 },
652 {
653 "growtoedgewest",
654 action_growtoedge,
655 setup_action_growtoedge_west
656 },
657 {
658 "growtoedgeeast",
659 action_growtoedge,
660 setup_action_growtoedge_east
661 },
662 {
663 "adddesktoplast",
664 action_add_desktop,
665 setup_action_addremove_desktop_last
666 },
667 {
668 "removedesktoplast",
669 action_remove_desktop,
670 setup_action_addremove_desktop_last
671 },
672 {
673 "adddesktopcurrent",
674 action_add_desktop,
675 setup_action_addremove_desktop_current
676 },
677 {
678 "removedesktopcurrent",
679 action_remove_desktop,
680 setup_action_addremove_desktop_current
681 },
682 {
683 NULL,
684 NULL,
685 NULL
686 }
687 };
688
689 /* only key bindings can be interactive. thus saith the xor.
690 because of how the mouse is grabbed, mouse events dont even get
691 read during interactive events, so no dice! >:) */
692 #define INTERACTIVE_LIMIT(a, uact) \
693 if (uact != OB_USER_ACTION_KEYBOARD_KEY) \
694 a->data.any.interactive = FALSE;
695
696 ObAction *action_from_string(const gchar *name, ObUserAction uact)
697 {
698 ObAction *a = NULL;
699 gboolean exist = FALSE;
700 gint i;
701
702 for (i = 0; actionstrings[i].name; i++)
703 if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
704 exist = TRUE;
705 a = action_new(actionstrings[i].func);
706 if (actionstrings[i].setup)
707 actionstrings[i].setup(&a, uact);
708 if (a)
709 INTERACTIVE_LIMIT(a, uact);
710 break;
711 }
712 if (!exist)
713 g_message(_("Invalid action '%s' requested. No such action exists."),
714 name);
715 if (!a)
716 g_message(_("Invalid use of action '%s'. Action will be ignored."),
717 name);
718 return a;
719 }
720
721 ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
722 ObUserAction uact)
723 {
724 gchar *actname;
725 ObAction *act = NULL;
726 xmlNodePtr n;
727
728 if (parse_attr_string("name", node, &actname)) {
729 if ((act = action_from_string(actname, uact))) {
730 } else if (act->func == action_resize_relative) {
731 if ((n = parse_find_node("left", node->xmlChildrenNode)))
732 act->data.relative.deltaxl = parse_int(doc, n);
733 if ((n = parse_find_node("up", node->xmlChildrenNode)))
734 act->data.relative.deltayu = parse_int(doc, n);
735 if ((n = parse_find_node("right", node->xmlChildrenNode)))
736 act->data.relative.deltax = parse_int(doc, n);
737 if ((n = parse_find_node("down", node->xmlChildrenNode)))
738 act->data.relative.deltay = parse_int(doc, n);
739 } else if (act->func == action_desktop) {
740 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
741 act->data.desktop.desk = parse_int(doc, n);
742 if (act->data.desktop.desk > 0) act->data.desktop.desk--;
743 /*
744 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
745 act->data.desktop.inter.any.interactive =
746 parse_bool(doc, n);
747 */
748 } else if (act->func == action_send_to_desktop) {
749 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
750 act->data.sendto.desk = parse_int(doc, n);
751 if (act->data.sendto.desk > 0) act->data.sendto.desk--;
752 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
753 act->data.sendto.follow = parse_bool(doc, n);
754 } else if (act->func == action_desktop_dir) {
755 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
756 act->data.desktopdir.wrap = parse_bool(doc, n);
757 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
758 act->data.desktopdir.inter.any.interactive =
759 parse_bool(doc, n);
760 } else if (act->func == action_send_to_desktop_dir) {
761 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
762 act->data.sendtodir.wrap = parse_bool(doc, n);
763 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
764 act->data.sendtodir.follow = parse_bool(doc, n);
765 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
766 act->data.sendtodir.inter.any.interactive =
767 parse_bool(doc, n);
768 } else if (act->func == action_directional_focus) {
769 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
770 act->data.interdiraction.dialog = parse_bool(doc, n);
771 if ((n = parse_find_node("panels", node->xmlChildrenNode)))
772 act->data.interdiraction.dock_windows = parse_bool(doc, n);
773 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
774 act->data.interdiraction.desktop_windows =
775 parse_bool(doc, n);
776 } else if (act->func == action_resize) {
777 if ((n = parse_find_node("edge", node->xmlChildrenNode))) {
778 gchar *s = parse_string(doc, n);
779 if (!g_ascii_strcasecmp(s, "top"))
780 act->data.moveresize.corner =
781 prop_atoms.net_wm_moveresize_size_top;
782 else if (!g_ascii_strcasecmp(s, "bottom"))
783 act->data.moveresize.corner =
784 prop_atoms.net_wm_moveresize_size_bottom;
785 else if (!g_ascii_strcasecmp(s, "left"))
786 act->data.moveresize.corner =
787 prop_atoms.net_wm_moveresize_size_left;
788 else if (!g_ascii_strcasecmp(s, "right"))
789 act->data.moveresize.corner =
790 prop_atoms.net_wm_moveresize_size_right;
791 else if (!g_ascii_strcasecmp(s, "topleft"))
792 act->data.moveresize.corner =
793 prop_atoms.net_wm_moveresize_size_topleft;
794 else if (!g_ascii_strcasecmp(s, "topright"))
795 act->data.moveresize.corner =
796 prop_atoms.net_wm_moveresize_size_topright;
797 else if (!g_ascii_strcasecmp(s, "bottomleft"))
798 act->data.moveresize.corner =
799 prop_atoms.net_wm_moveresize_size_bottomleft;
800 else if (!g_ascii_strcasecmp(s, "bottomright"))
801 act->data.moveresize.corner =
802 prop_atoms.net_wm_moveresize_size_bottomright;
803 g_free(s);
804 }
805 INTERACTIVE_LIMIT(act, uact);
806 }
807 g_free(actname);
808 }
809 return act;
810 }
811
812 void action_run_list(GSList *acts, ObClient *c, ObFrameContext context,
813 guint state, guint button, gint x, gint y, Time time,
814 gboolean cancel, gboolean done)
815 {
816 GSList *it;
817 ObAction *a;
818
819 if (!acts)
820 return;
821
822 if (x < 0 && y < 0)
823 screen_pointer_pos(&x, &y);
824
825 for (it = acts; it; it = g_slist_next(it)) {
826 a = it->data;
827
828 if (!(a->data.any.client_action == OB_CLIENT_ACTION_ALWAYS && !c)) {
829 a->data.any.c = a->data.any.client_action ? c : NULL;
830 a->data.any.context = context;
831 a->data.any.x = x;
832 a->data.any.y = y;
833
834 a->data.any.button = button;
835
836 a->data.any.time = time;
837
838 if (a->data.any.interactive) {
839 a->data.inter.cancel = cancel;
840 a->data.inter.final = done;
841 if (!(cancel || done))
842 if (!keyboard_interactive_grab(state, a->data.any.c, a))
843 continue;
844 }
845
846 /* XXX UGLY HACK race with motion event starting a move and the
847 button release gettnig processed first. answer: don't queue
848 moveresize starts. UGLY HACK XXX
849
850 XXX ALSO don't queue showmenu events, because on button press
851 events we need to know if a mouse grab is going to take place,
852 and set the button to 0, so that later motion events don't think
853 that a drag is going on. since showmenu grabs the pointer..
854 */
855 if (a->data.any.interactive || a->func == action_move ||
856 a->func == action_resize || a->func == action_showmenu)
857 {
858 /* interactive actions are not queued */
859 a->func(&a->data);
860 } else if (a->func == action_focus ||
861 a->func == action_activate ||
862 a->func == action_showmenu)
863 {
864 /* XXX MORE UGLY HACK
865 actions from clicks on client windows are NOT queued.
866 this solves the mysterious click-and-drag-doesnt-work
867 problem. it was because the window gets focused and stuff
868 after the button event has already been passed through. i
869 dont really know why it should care but it does and it makes
870 a difference.
871
872 however this very bogus ! !
873 we want to send the button press to the window BEFORE
874 we do the action because the action might move the windows
875 (eg change desktops) and then the button press ends up on
876 the completely wrong window !
877 so, this is just for that bug, and it will only NOT queue it
878 if it is a focusing action that can be used with the mouse
879 pointer. ugh.
880
881 also with the menus, there is a race going on. if the
882 desktop wants to pop up a menu, and we do too, we send them
883 the button before we pop up the menu, so they pop up their
884 menu first. but not always. if we pop up our menu before
885 sending them the button press, then the result is
886 deterministic. yay.
887
888 XXX further more. focus actions are not queued at all,
889 because if you bind focus->showmenu, the menu will get
890 hidden to do the focusing
891 */
892 a->func(&a->data);
893 } else
894 ob_main_loop_queue_action(ob_main_loop, a);
895 }
896 }
897 }
898
899 void action_run_string(const gchar *name, struct _ObClient *c, Time time)
900 {
901 ObAction *a;
902 GSList *l;
903
904 a = action_from_string(name, OB_USER_ACTION_NONE);
905 g_assert(a);
906
907 l = g_slist_append(NULL, a);
908
909 action_run(l, c, 0, time);
910 }
911
912 void action_unshaderaise(union ActionData *data)
913 {
914 if (data->client.any.c->shaded)
915 action_unshade(data);
916 else
917 action_raise(data);
918 }
919
920 void action_shadelower(union ActionData *data)
921 {
922 if (data->client.any.c->shaded)
923 action_lower(data);
924 else
925 action_shade(data);
926 }
927
928 void action_kill(union ActionData *data)
929 {
930 client_kill(data->client.any.c);
931 }
932
933 void action_toggle_omnipresent(union ActionData *data)
934 {
935 client_set_desktop(data->client.any.c,
936 data->client.any.c->desktop == DESKTOP_ALL ?
937 screen_desktop : DESKTOP_ALL, FALSE, TRUE);
938 }
939
940 void action_resize_relative_horz(union ActionData *data)
941 {
942 ObClient *c = data->relative.any.c;
943 client_action_start(data);
944 client_resize(c,
945 c->area.width + data->relative.deltax * c->size_inc.width,
946 c->area.height);
947 client_action_end(data, FALSE);
948 }
949
950 void action_resize_relative_vert(union ActionData *data)
951 {
952 ObClient *c = data->relative.any.c;
953 if (!c->shaded) {
954 client_action_start(data);
955 client_resize(c, c->area.width, c->area.height +
956 data->relative.deltax * c->size_inc.height);
957 client_action_end(data, FALSE);
958 }
959 }
960
961 void action_resize_relative(union ActionData *data)
962 {
963 ObClient *c = data->relative.any.c;
964 gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
965
966 client_action_start(data);
967
968 x = c->area.x;
969 y = c->area.y;
970 ow = c->area.width;
971 xoff = -data->relative.deltaxl * c->size_inc.width;
972 nw = ow + data->relative.deltax * c->size_inc.width
973 + data->relative.deltaxl * c->size_inc.width;
974 oh = c->area.height;
975 yoff = -data->relative.deltayu * c->size_inc.height;
976 nh = oh + data->relative.deltay * c->size_inc.height
977 + data->relative.deltayu * c->size_inc.height;
978
979 g_print("deltax %d %d x %d ow %d xoff %d nw %d\n",
980 data->relative.deltax,
981 data->relative.deltaxl,
982 x, ow, xoff, nw);
983
984 client_try_configure(c, &x, &y, &nw, &nh, &lw, &lh, TRUE);
985 xoff = xoff == 0 ? 0 : (xoff < 0 ? MAX(xoff, ow-nw) : MIN(xoff, ow-nw));
986 yoff = yoff == 0 ? 0 : (yoff < 0 ? MAX(yoff, oh-nh) : MIN(yoff, oh-nh));
987 client_move_resize(c, x + xoff, y + yoff, nw, nh);
988 client_action_end(data, FALSE);
989 }
990
991 void action_send_to_desktop(union ActionData *data)
992 {
993 ObClient *c = data->sendto.any.c;
994
995 if (!client_normal(c)) return;
996
997 if (data->sendto.desk < screen_num_desktops ||
998 data->sendto.desk == DESKTOP_ALL) {
999 client_set_desktop(c, data->sendto.desk, data->sendto.follow, FALSE);
1000 if (data->sendto.follow && data->sendto.desk != screen_desktop)
1001 screen_set_desktop(data->sendto.desk, TRUE);
1002 }
1003 }
1004
1005 void action_desktop(union ActionData *data)
1006 {
1007 /* XXX add the interactive/dialog option back again once the dialog
1008 has been made to not use grabs */
1009 if (data->desktop.desk < screen_num_desktops ||
1010 data->desktop.desk == DESKTOP_ALL)
1011 {
1012 screen_set_desktop(data->desktop.desk, TRUE);
1013 if (data->inter.any.interactive)
1014 screen_desktop_popup(data->desktop.desk, TRUE);
1015 }
1016 }
1017
1018 void action_desktop_dir(union ActionData *data)
1019 {
1020 guint d;
1021
1022 d = screen_cycle_desktop(data->desktopdir.dir,
1023 data->desktopdir.wrap,
1024 data->desktopdir.linear,
1025 data->desktopdir.inter.any.interactive,
1026 data->desktopdir.inter.final,
1027 data->desktopdir.inter.cancel);
1028 /* only move the desktop when the action is complete. if we switch
1029 desktops during the interactive action, focus will move but with
1030 NotifyWhileGrabbed and applications don't like that. */
1031 if (!data->sendtodir.inter.any.interactive ||
1032 (data->sendtodir.inter.final && !data->sendtodir.inter.cancel))
1033 {
1034 if (d != screen_desktop)
1035 screen_set_desktop(d, TRUE);
1036 }
1037 }
1038
1039 void action_send_to_desktop_dir(union ActionData *data)
1040 {
1041 ObClient *c = data->sendtodir.inter.any.c;
1042 guint d;
1043
1044 if (!client_normal(c)) return;
1045
1046 d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
1047 data->sendtodir.linear,
1048 data->sendtodir.inter.any.interactive,
1049 data->sendtodir.inter.final,
1050 data->sendtodir.inter.cancel);
1051 /* only move the desktop when the action is complete. if we switch
1052 desktops during the interactive action, focus will move but with
1053 NotifyWhileGrabbed and applications don't like that. */
1054 if (!data->sendtodir.inter.any.interactive ||
1055 (data->sendtodir.inter.final && !data->sendtodir.inter.cancel))
1056 {
1057 client_set_desktop(c, d, data->sendtodir.follow, FALSE);
1058 if (data->sendtodir.follow && d != screen_desktop)
1059 screen_set_desktop(d, TRUE);
1060 }
1061 }
1062
1063 void action_desktop_last(union ActionData *data)
1064 {
1065 if (screen_last_desktop < screen_num_desktops)
1066 screen_set_desktop(screen_last_desktop, TRUE);
1067 }
1068
1069 void action_toggle_decorations(union ActionData *data)
1070 {
1071 ObClient *c = data->client.any.c;
1072
1073 client_action_start(data);
1074 client_set_undecorated(c, !c->undecorated);
1075 client_action_end(data, FALSE);
1076 }
1077
1078 static guint32 pick_corner(gint x, gint y, gint cx, gint cy, gint cw, gint ch,
1079 gboolean shaded)
1080 {
1081 /* let's make x and y client relative instead of screen relative */
1082 x = x - cx;
1083 y = ch - (y - cy); /* y is inverted, 0 is at the bottom of the window */
1084
1085 #define X x*ch/cw
1086 #define A -4*X + 7*ch/3
1087 #define B 4*X -15*ch/9
1088 #define C -X/4 + 2*ch/3
1089 #define D X/4 + 5*ch/12
1090 #define E X/4 + ch/3
1091 #define F -X/4 + 7*ch/12
1092 #define G 4*X - 4*ch/3
1093 #define H -4*X + 8*ch/3
1094 #define a (y > 5*ch/9)
1095 #define b (x < 4*cw/9)
1096 #define c (x > 5*cw/9)
1097 #define d (y < 4*ch/9)
1098
1099 /*
1100 Each of these defines (except X which is just there for fun), represents
1101 the equation of a line. The lines they represent are shown in the diagram
1102 below. Checking y against these lines, we are able to choose a region
1103 of the window as shown.
1104
1105 +---------------------A-------|-------|-------B---------------------+
1106 | |A B| |
1107 | |A | | B| |
1108 | | A B | |
1109 | | A | | B | |
1110 | | A B | |
1111 | | A | | B | |
1112 | northwest | A north B | northeast |
1113 | | A | | B | |
1114 | | A B | |
1115 C---------------------+----A--+-------+--B----+---------------------D
1116 |CCCCCCC | A B | DDDDDDD|
1117 | CCCCCCCC | A | | B | DDDDDDDD |
1118 | CCCCCCC A B DDDDDDD |
1119 - - - - - - - - - - - +CCCCCCC+aaaaaaa+DDDDDDD+ - - - - - - - - - - - -
1120 | | b c | | sh
1121 | west | b move c | east | ad
1122 | | b c | | ed
1123 - - - - - - - - - - - +EEEEEEE+ddddddd+FFFFFFF+- - - - - - - - - - - -
1124 | EEEEEEE G H FFFFFFF |
1125 | EEEEEEEE | G | | H | FFFFFFFF |
1126 |EEEEEEE | G H | FFFFFFF|
1127 E---------------------+----G--+-------+--H----+---------------------F
1128 | | G H | |
1129 | | G | | H | |
1130 | southwest | G south H | southeast |
1131 | | G | | H | |
1132 | | G H | |
1133 | | G | | H | |
1134 | | G H | |
1135 | |G | | H| |
1136 | |G H| |
1137 +---------------------G-------|-------|-------H---------------------+
1138 */
1139
1140 if (shaded) {
1141 /* for shaded windows, you can only resize west/east and move */
1142 if (b)
1143 return prop_atoms.net_wm_moveresize_size_left;
1144 if (c)
1145 return prop_atoms.net_wm_moveresize_size_right;
1146 return prop_atoms.net_wm_moveresize_move;
1147 }
1148
1149 if (y < A && y >= C)
1150 return prop_atoms.net_wm_moveresize_size_topleft;
1151 else if (y >= A && y >= B && a)
1152 return prop_atoms.net_wm_moveresize_size_top;
1153 else if (y < B && y >= D)
1154 return prop_atoms.net_wm_moveresize_size_topright;
1155 else if (y < C && y >= E && b)
1156 return prop_atoms.net_wm_moveresize_size_left;
1157 else if (y < D && y >= F && c)
1158 return prop_atoms.net_wm_moveresize_size_right;
1159 else if (y < E && y >= G)
1160 return prop_atoms.net_wm_moveresize_size_bottomleft;
1161 else if (y < G && y < H && d)
1162 return prop_atoms.net_wm_moveresize_size_bottom;
1163 else if (y >= H && y < F)
1164 return prop_atoms.net_wm_moveresize_size_bottomright;
1165 else
1166 return prop_atoms.net_wm_moveresize_move;
1167
1168 #undef X
1169 #undef A
1170 #undef B
1171 #undef C
1172 #undef D
1173 #undef E
1174 #undef F
1175 #undef G
1176 #undef H
1177 #undef a
1178 #undef b
1179 #undef c
1180 #undef d
1181 }
1182
1183 void action_resize(union ActionData *data)
1184 {
1185 ObClient *c = data->moveresize.any.c;
1186 guint32 corner;
1187
1188 if (data->moveresize.keyboard)
1189 corner = prop_atoms.net_wm_moveresize_size_keyboard;
1190 else if (data->moveresize.corner)
1191 corner = data->moveresize.corner; /* it was specified in the binding */
1192 else
1193 corner = pick_corner(data->any.x, data->any.y,
1194 c->frame->area.x, c->frame->area.y,
1195 /* use the client size because the frame
1196 can be differently sized (shaded
1197 windows) and we want this based on the
1198 clients size */
1199 c->area.width + c->frame->size.left +
1200 c->frame->size.right,
1201 c->area.height + c->frame->size.top +
1202 c->frame->size.bottom, c->shaded);
1203
1204 moveresize_start(c, data->any.x, data->any.y, data->any.button, corner);
1205 }
1206
1207 void action_directional_focus(union ActionData *data)
1208 {
1209 /* if using focus_delay, stop the timer now so that focus doesn't go moving
1210 on us */
1211 event_halt_focus_delay();
1212
1213 focus_directional_cycle(data->interdiraction.direction,
1214 data->interdiraction.dock_windows,
1215 data->interdiraction.desktop_windows,
1216 data->any.interactive,
1217 data->interdiraction.dialog,
1218 data->interdiraction.inter.final,
1219 data->interdiraction.inter.cancel);
1220 }
1221
1222 void action_movetoedge(union ActionData *data)
1223 {
1224 gint x, y;
1225 ObClient *c = data->diraction.any.c;
1226
1227 x = c->frame->area.x;
1228 y = c->frame->area.y;
1229
1230 switch(data->diraction.direction) {
1231 case OB_DIRECTION_NORTH:
1232 y = client_directional_edge_search(c, OB_DIRECTION_NORTH,
1233 data->diraction.hang)
1234 - (data->diraction.hang ? c->frame->area.height : 0);
1235 break;
1236 case OB_DIRECTION_WEST:
1237 x = client_directional_edge_search(c, OB_DIRECTION_WEST,
1238 data->diraction.hang)
1239 - (data->diraction.hang ? c->frame->area.width : 0);
1240 break;
1241 case OB_DIRECTION_SOUTH:
1242 y = client_directional_edge_search(c, OB_DIRECTION_SOUTH,
1243 data->diraction.hang)
1244 - (data->diraction.hang ? 0 : c->frame->area.height);
1245 break;
1246 case OB_DIRECTION_EAST:
1247 x = client_directional_edge_search(c, OB_DIRECTION_EAST,
1248 data->diraction.hang)
1249 - (data->diraction.hang ? 0 : c->frame->area.width);
1250 break;
1251 default:
1252 g_assert_not_reached();
1253 }
1254 frame_frame_gravity(c->frame, &x, &y, c->area.width, c->area.height);
1255 client_action_start(data);
1256 client_move(c, x, y);
1257 client_action_end(data, FALSE);
1258 }
1259
1260 void action_growtoedge(union ActionData *data)
1261 {
1262 gint x, y, width, height, dest;
1263 ObClient *c = data->diraction.any.c;
1264 Rect *a;
1265
1266 a = screen_area(c->desktop, SCREEN_AREA_ALL_MONITORS, &c->frame->area);
1267 x = c->frame->area.x;
1268 y = c->frame->area.y;
1269 /* get the unshaded frame's dimensions..if it is shaded */
1270 width = c->area.width + c->frame->size.left + c->frame->size.right;
1271 height = c->area.height + c->frame->size.top + c->frame->size.bottom;
1272
1273 switch(data->diraction.direction) {
1274 case OB_DIRECTION_NORTH:
1275 if (c->shaded) break; /* don't allow vertical resize if shaded */
1276
1277 dest = client_directional_edge_search(c, OB_DIRECTION_NORTH, FALSE);
1278 if (a->y == y)
1279 height = height / 2;
1280 else {
1281 height = c->frame->area.y + height - dest;
1282 y = dest;
1283 }
1284 break;
1285 case OB_DIRECTION_WEST:
1286 dest = client_directional_edge_search(c, OB_DIRECTION_WEST, FALSE);
1287 if (a->x == x)
1288 width = width / 2;
1289 else {
1290 width = c->frame->area.x + width - dest;
1291 x = dest;
1292 }
1293 break;
1294 case OB_DIRECTION_SOUTH:
1295 if (c->shaded) break; /* don't allow vertical resize if shaded */
1296
1297 dest = client_directional_edge_search(c, OB_DIRECTION_SOUTH, FALSE);
1298 if (a->y + a->height == y + c->frame->area.height) {
1299 height = c->frame->area.height / 2;
1300 y = a->y + a->height - height;
1301 } else
1302 height = dest - c->frame->area.y;
1303 y += (height - c->frame->area.height) % c->size_inc.height;
1304 height -= (height - c->frame->area.height) % c->size_inc.height;
1305 break;
1306 case OB_DIRECTION_EAST:
1307 dest = client_directional_edge_search(c, OB_DIRECTION_EAST, FALSE);
1308 if (a->x + a->width == x + c->frame->area.width) {
1309 width = c->frame->area.width / 2;
1310 x = a->x + a->width - width;
1311 } else
1312 width = dest - c->frame->area.x;
1313 x += (width - c->frame->area.width) % c->size_inc.width;
1314 width -= (width - c->frame->area.width) % c->size_inc.width;
1315 break;
1316 default:
1317 g_assert_not_reached();
1318 }
1319 width -= c->frame->size.left + c->frame->size.right;
1320 height -= c->frame->size.top + c->frame->size.bottom;
1321 frame_frame_gravity(c->frame, &x, &y, width, height);
1322 client_action_start(data);
1323 client_move_resize(c, x, y, width, height);
1324 client_action_end(data, FALSE);
1325 g_free(a);
1326 }
1327
1328 void action_send_to_layer(union ActionData *data)
1329 {
1330 client_set_layer(data->layer.any.c, data->layer.layer);
1331 }
1332
1333 void action_toggle_layer(union ActionData *data)
1334 {
1335 ObClient *c = data->layer.any.c;
1336
1337 client_action_start(data);
1338 if (data->layer.layer < 0)
1339 client_set_layer(c, c->below ? 0 : -1);
1340 else if (data->layer.layer > 0)
1341 client_set_layer(c, c->above ? 0 : 1);
1342 client_action_end(data, config_focus_under_mouse);
1343 }
1344
1345 void action_toggle_dockautohide(union ActionData *data)
1346 {
1347 config_dock_hide = !config_dock_hide;
1348 dock_configure();
1349 }
1350
1351 void action_add_desktop(union ActionData *data)
1352 {
1353 client_action_start(data);
1354 screen_set_num_desktops(screen_num_desktops+1);
1355
1356 /* move all the clients over */
1357 if (data->addremovedesktop.current) {
1358 GList *it;
1359
1360 for (it = client_list; it; it = g_list_next(it)) {
1361 ObClient *c = it->data;
1362 if (c->desktop != DESKTOP_ALL && c->desktop >= screen_desktop)
1363 client_set_desktop(c, c->desktop+1, FALSE, TRUE);
1364 }
1365 }
1366
1367 client_action_end(data, config_focus_under_mouse);
1368 }
1369
1370 void action_remove_desktop(union ActionData *data)
1371 {
1372 guint rmdesktop, movedesktop;
1373 GList *it, *stacking_copy;
1374
1375 if (screen_num_desktops < 2) return;
1376
1377 client_action_start(data);
1378
1379 /* what desktop are we removing and moving to? */
1380 if (data->addremovedesktop.current)
1381 rmdesktop = screen_desktop;
1382 else
1383 rmdesktop = screen_num_desktops - 1;
1384 if (rmdesktop < screen_num_desktops - 1)
1385 movedesktop = rmdesktop + 1;
1386 else
1387 movedesktop = rmdesktop;
1388
1389 /* make a copy of the list cuz we're changing it */
1390 stacking_copy = g_list_copy(stacking_list);
1391 for (it = g_list_last(stacking_copy); it; it = g_list_previous(it)) {
1392 if (WINDOW_IS_CLIENT(it->data)) {
1393 ObClient *c = it->data;
1394 guint d = c->desktop;
1395 if (d != DESKTOP_ALL && d >= movedesktop) {
1396 client_set_desktop(c, c->desktop - 1, TRUE, TRUE);
1397 ob_debug("moving window %s\n", c->title);
1398 }
1399 /* raise all the windows that are on the current desktop which
1400 is being merged */
1401 if ((screen_desktop == rmdesktop - 1 ||
1402 screen_desktop == rmdesktop) &&
1403 (d == DESKTOP_ALL || d == screen_desktop))
1404 {
1405 stacking_raise(CLIENT_AS_WINDOW(c));
1406 ob_debug("raising window %s\n", c->title);
1407 }
1408 }
1409 }
1410
1411 /* act like we're changing desktops */
1412 if (screen_desktop < screen_num_desktops - 1) {
1413 gint d = screen_desktop;
1414 screen_desktop = screen_last_desktop;
1415 screen_set_desktop(d, TRUE);
1416 ob_debug("fake desktop change\n");
1417 }
1418
1419 screen_set_num_desktops(screen_num_desktops-1);
1420
1421 client_action_end(data, config_focus_under_mouse);
1422 }
This page took 0.096229 seconds and 4 git commands to generate.