]> Dogcows Code - chaz/openbox/blob - openbox/action.c
move expand_tilde to ob_expand_tilde in openbox.c to make it global.
[chaz/openbox] / openbox / action.c
1 #include "debug.h"
2 #include "client.h"
3 #include "focus.h"
4 #include "moveresize.h"
5 #include "menu.h"
6 #include "prop.h"
7 #include "stacking.h"
8 #include "frame.h"
9 #include "screen.h"
10 #include "action.h"
11 #include "openbox.h"
12
13 #include <glib.h>
14
15 typedef struct ActionString {
16 char *name;
17 void (*func)(union ActionData *);
18 void (*setup)(ObAction *);
19 } ActionString;
20
21 ObAction *action_new(void (*func)(union ActionData *data))
22 {
23 ObAction *a = g_new0(ObAction, 1);
24 a->func = func;
25
26 return a;
27 }
28
29 void action_free(ObAction *a)
30 {
31 if (a == NULL) return;
32
33 /* deal with pointers */
34 if (a->func == action_execute || a->func == action_restart)
35 g_free(a->data.execute.path);
36 else if (a->func == action_showmenu)
37 g_free(a->data.showmenu.name);
38
39 g_free(a);
40 }
41
42 void setup_action_directional_focus_north(ObAction *a)
43 {
44 a->data.interdiraction.inter.any.interactive = TRUE;
45 a->data.interdiraction.direction = OB_DIRECTION_NORTH;
46 }
47
48 void setup_action_directional_focus_east(ObAction *a)
49 {
50 a->data.interdiraction.inter.any.interactive = TRUE;
51 a->data.interdiraction.direction = OB_DIRECTION_EAST;
52 }
53
54 void setup_action_directional_focus_south(ObAction *a)
55 {
56 a->data.interdiraction.inter.any.interactive = TRUE;
57 a->data.interdiraction.direction = OB_DIRECTION_SOUTH;
58 }
59
60 void setup_action_directional_focus_west(ObAction *a)
61 {
62 a->data.interdiraction.inter.any.interactive = TRUE;
63 a->data.interdiraction.direction = OB_DIRECTION_WEST;
64 }
65
66 void setup_action_directional_focus_northeast(ObAction *a)
67 {
68 a->data.interdiraction.inter.any.interactive = TRUE;
69 a->data.interdiraction.direction = OB_DIRECTION_NORTHEAST;
70 }
71
72 void setup_action_directional_focus_southeast(ObAction *a)
73 {
74 a->data.interdiraction.inter.any.interactive = TRUE;
75 a->data.interdiraction.direction = OB_DIRECTION_SOUTHEAST;
76 }
77
78 void setup_action_directional_focus_southwest(ObAction *a)
79 {
80 a->data.interdiraction.inter.any.interactive = TRUE;
81 a->data.interdiraction.direction = OB_DIRECTION_SOUTHWEST;
82 }
83
84 void setup_action_directional_focus_northwest(ObAction *a)
85 {
86 a->data.interdiraction.inter.any.interactive = TRUE;
87 a->data.interdiraction.direction = OB_DIRECTION_NORTHWEST;
88 }
89
90 void setup_action_send_to_desktop(ObAction *a)
91 {
92 a->data.sendto.follow = TRUE;
93 }
94
95 void setup_action_send_to_desktop_prev(ObAction *a)
96 {
97 a->data.sendtodir.inter.any.interactive = TRUE;
98 a->data.sendtodir.dir = OB_DIRECTION_WEST;
99 a->data.sendtodir.linear = TRUE;
100 a->data.sendtodir.wrap = TRUE;
101 a->data.sendtodir.follow = TRUE;
102 }
103
104 void setup_action_send_to_desktop_next(ObAction *a)
105 {
106 a->data.sendtodir.inter.any.interactive = TRUE;
107 a->data.sendtodir.dir = OB_DIRECTION_EAST;
108 a->data.sendtodir.linear = TRUE;
109 a->data.sendtodir.wrap = TRUE;
110 a->data.sendtodir.follow = TRUE;
111 }
112
113 void setup_action_send_to_desktop_left(ObAction *a)
114 {
115 a->data.sendtodir.inter.any.interactive = TRUE;
116 a->data.sendtodir.dir = OB_DIRECTION_WEST;
117 a->data.sendtodir.linear = FALSE;
118 a->data.sendtodir.wrap = TRUE;
119 a->data.sendtodir.follow = TRUE;
120 }
121
122 void setup_action_send_to_desktop_right(ObAction *a)
123 {
124 a->data.sendtodir.inter.any.interactive = TRUE;
125 a->data.sendtodir.dir = OB_DIRECTION_EAST;
126 a->data.sendtodir.linear = FALSE;
127 a->data.sendtodir.wrap = TRUE;
128 a->data.sendtodir.follow = TRUE;
129 }
130
131 void setup_action_send_to_desktop_up(ObAction *a)
132 {
133 a->data.sendtodir.inter.any.interactive = TRUE;
134 a->data.sendtodir.dir = OB_DIRECTION_NORTH;
135 a->data.sendtodir.linear = FALSE;
136 a->data.sendtodir.wrap = TRUE;
137 a->data.sendtodir.follow = TRUE;
138 }
139
140 void setup_action_send_to_desktop_down(ObAction *a)
141 {
142 a->data.sendtodir.inter.any.interactive = TRUE;
143 a->data.sendtodir.dir = OB_DIRECTION_SOUTH;
144 a->data.sendtodir.linear = FALSE;
145 a->data.sendtodir.wrap = TRUE;
146 a->data.sendtodir.follow = TRUE;
147 }
148
149 void setup_action_desktop_prev(ObAction *a)
150 {
151 a->data.desktopdir.inter.any.interactive = TRUE;
152 a->data.desktopdir.dir = OB_DIRECTION_WEST;
153 a->data.desktopdir.linear = TRUE;
154 a->data.desktopdir.wrap = TRUE;
155 }
156
157 void setup_action_desktop_next(ObAction *a)
158 {
159 a->data.desktopdir.inter.any.interactive = TRUE;
160 a->data.desktopdir.dir = OB_DIRECTION_EAST;
161 a->data.desktopdir.linear = TRUE;
162 a->data.desktopdir.wrap = TRUE;
163 }
164
165 void setup_action_desktop_left(ObAction *a)
166 {
167 a->data.desktopdir.inter.any.interactive = TRUE;
168 a->data.desktopdir.dir = OB_DIRECTION_WEST;
169 a->data.desktopdir.linear = FALSE;
170 a->data.desktopdir.wrap = TRUE;
171 }
172
173 void setup_action_desktop_right(ObAction *a)
174 {
175 a->data.desktopdir.inter.any.interactive = TRUE;
176 a->data.desktopdir.dir = OB_DIRECTION_EAST;
177 a->data.desktopdir.linear = FALSE;
178 a->data.desktopdir.wrap = TRUE;
179 }
180
181 void setup_action_desktop_up(ObAction *a)
182 {
183 a->data.desktopdir.inter.any.interactive = TRUE;
184 a->data.desktopdir.dir = OB_DIRECTION_NORTH;
185 a->data.desktopdir.linear = FALSE;
186 a->data.desktopdir.wrap = TRUE;
187 }
188
189 void setup_action_desktop_down(ObAction *a)
190 {
191 a->data.desktopdir.inter.any.interactive = TRUE;
192 a->data.desktopdir.dir = OB_DIRECTION_SOUTH;
193 a->data.desktopdir.linear = FALSE;
194 a->data.desktopdir.wrap = TRUE;
195 }
196
197 void setup_action_move_keyboard(ObAction *a)
198 {
199 a->data.moveresize.corner = prop_atoms.net_wm_moveresize_move_keyboard;
200 }
201
202 void setup_action_move(ObAction *a)
203 {
204 a->data.moveresize.corner = prop_atoms.net_wm_moveresize_move;
205 }
206
207 void setup_action_resize(ObAction *a)
208 {
209 a->data.moveresize.corner = prop_atoms.net_wm_moveresize_size_topleft;
210 }
211
212 void setup_action_resize_keyboard(ObAction *a)
213 {
214 a->data.moveresize.corner = prop_atoms.net_wm_moveresize_size_keyboard;
215 }
216
217 void setup_action_cycle_windows_linear_next(ObAction *a)
218 {
219 a->data.cycle.inter.any.interactive = TRUE;
220 a->data.cycle.linear = TRUE;
221 a->data.cycle.forward = TRUE;
222 }
223
224 void setup_action_cycle_windows_linear_previous(ObAction *a)
225 {
226 a->data.cycle.inter.any.interactive = TRUE;
227 a->data.cycle.linear = TRUE;
228 a->data.cycle.forward = FALSE;
229 }
230
231 void setup_action_cycle_windows_next(ObAction *a)
232 {
233 a->data.cycle.inter.any.interactive = TRUE;
234 a->data.cycle.linear = FALSE;
235 a->data.cycle.forward = TRUE;
236 }
237
238 void setup_action_cycle_windows_previous(ObAction *a)
239 {
240 a->data.cycle.inter.any.interactive = TRUE;
241 a->data.cycle.linear = FALSE;
242 a->data.cycle.forward = FALSE;
243 }
244
245 void setup_action_movetoedge_north(ObAction *a)
246 {
247 a->data.diraction.direction = OB_DIRECTION_NORTH;
248 }
249
250 void setup_action_movetoedge_south(ObAction *a)
251 {
252 a->data.diraction.direction = OB_DIRECTION_SOUTH;
253 }
254
255 void setup_action_movetoedge_east(ObAction *a)
256 {
257 a->data.diraction.direction = OB_DIRECTION_EAST;
258 }
259
260 void setup_action_movetoedge_west(ObAction *a)
261 {
262 a->data.diraction.direction = OB_DIRECTION_WEST;
263 }
264
265 void setup_action_growtoedge_north(ObAction *a)
266 {
267 a->data.diraction.direction = OB_DIRECTION_NORTH;
268 }
269
270 void setup_action_growtoedge_south(ObAction *a)
271 {
272 a->data.diraction.direction = OB_DIRECTION_SOUTH;
273 }
274
275 void setup_action_growtoedge_east(ObAction *a)
276 {
277 a->data.diraction.direction = OB_DIRECTION_EAST;
278 }
279
280 void setup_action_growtoedge_west(ObAction *a)
281 {
282 a->data.diraction.direction = OB_DIRECTION_WEST;
283 }
284
285 void setup_action_top_layer(ObAction *a)
286 {
287 a->data.layer.layer = 1;
288 }
289
290 void setup_action_normal_layer(ObAction *a)
291 {
292 a->data.layer.layer = 0;
293 }
294
295 void setup_action_bottom_layer(ObAction *a)
296 {
297 a->data.layer.layer = -1;
298 }
299
300 ActionString actionstrings[] =
301 {
302 {
303 "execute",
304 action_execute,
305 NULL
306 },
307 {
308 "directionalfocusnorth",
309 action_directional_focus,
310 setup_action_directional_focus_north
311 },
312 {
313 "directionalfocuseast",
314 action_directional_focus,
315 setup_action_directional_focus_east
316 },
317 {
318 "directionalfocussouth",
319 action_directional_focus,
320 setup_action_directional_focus_south
321 },
322 {
323 "directionalfocuswest",
324 action_directional_focus,
325 setup_action_directional_focus_west
326 },
327 {
328 "directionalfocusnortheast",
329 action_directional_focus,
330 setup_action_directional_focus_northeast
331 },
332 {
333 "directionalfocussoutheast",
334 action_directional_focus,
335 setup_action_directional_focus_southeast
336 },
337 {
338 "directionalfocussouthwest",
339 action_directional_focus,
340 setup_action_directional_focus_southwest
341 },
342 {
343 "directionalfocusnorthwest",
344 action_directional_focus,
345 setup_action_directional_focus_northwest
346 },
347 {
348 "activate",
349 action_activate,
350 NULL,
351 },
352 {
353 "focus",
354 action_focus,
355 NULL,
356 },
357 {
358 "unfocus",
359 action_unfocus,
360 NULL
361 },
362 {
363 "iconify",
364 action_iconify,
365 NULL
366 },
367 {
368 "raiselower",
369 action_raiselower,
370 NULL
371 },
372 {
373 "raise",
374 action_raise,
375 NULL
376 },
377 {
378 "lower",
379 action_lower,
380 NULL
381 },
382 {
383 "close",
384 action_close,
385 NULL
386 },
387 {
388 "kill",
389 action_kill,
390 NULL
391 },
392 {
393 "shadelower",
394 action_shadelower,
395 NULL
396 },
397 {
398 "unshaderaise",
399 action_unshaderaise,
400 NULL
401 },
402 {
403 "shade",
404 action_shade,
405 NULL
406 },
407 {
408 "unshade",
409 action_unshade,
410 NULL
411 },
412 {
413 "toggleshade",
414 action_toggle_shade,
415 NULL
416 },
417 {
418 "toggleomnipresent",
419 action_toggle_omnipresent,
420 NULL
421 },
422 {
423 "moverelativehorz",
424 action_move_relative_horz,
425 NULL
426 },
427 {
428 "moverelativevert",
429 action_move_relative_vert,
430 NULL
431 },
432 {
433 "resizerelativehorz",
434 action_resize_relative_horz,
435 NULL
436 },
437 {
438 "resizerelativevert",
439 action_resize_relative_vert,
440 NULL
441 },
442 {
443 "maximizefull",
444 action_maximize_full,
445 NULL
446 },
447 {
448 "unmaximizefull",
449 action_unmaximize_full,
450 NULL
451 },
452 {
453 "togglemaximizefull",
454 action_toggle_maximize_full,
455 NULL
456 },
457 {
458 "maximizehorz",
459 action_maximize_horz,
460 NULL
461 },
462 {
463 "unmaximizehorz",
464 action_unmaximize_horz,
465 NULL
466 },
467 {
468 "togglemaximizehorz",
469 action_toggle_maximize_horz,
470 NULL
471 },
472 {
473 "maximizevert",
474 action_maximize_vert,
475 NULL
476 },
477 {
478 "unmaximizevert",
479 action_unmaximize_vert,
480 NULL
481 },
482 {
483 "togglemaximizevert",
484 action_toggle_maximize_vert,
485 NULL
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 NULL
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 NULL
561 },
562 {
563 "keyboardmove",
564 action_moveresize,
565 setup_action_move_keyboard
566 },
567 {
568 "move",
569 action_moveresize,
570 setup_action_move
571 },
572 {
573 "resize",
574 action_moveresize,
575 setup_action_resize
576 },
577 {
578 "keyboardresize",
579 action_moveresize,
580 setup_action_resize_keyboard
581 },
582 {
583 "toggleshowdesktop",
584 action_toggle_show_desktop,
585 NULL
586 },
587 {
588 "showdesktop",
589 action_show_desktop,
590 NULL
591 },
592 {
593 "unshowdesktop",
594 action_unshow_desktop,
595 NULL
596 },
597 {
598 "desktoplast",
599 action_desktop_last,
600 NULL
601 },
602 {
603 "restart",
604 action_restart,
605 NULL
606 },
607 {
608 "exit",
609 action_exit,
610 NULL
611 },
612 {
613 "showmenu",
614 action_showmenu,
615 NULL
616 },
617 {
618 "sendtotoplayer",
619 action_send_to_layer,
620 setup_action_top_layer
621 },
622 {
623 "togglealwaysontop",
624 action_toggle_layer,
625 setup_action_top_layer
626 },
627 {
628 "sendtonormallayer",
629 action_send_to_layer,
630 setup_action_normal_layer
631 },
632 {
633 "sendtobottomlayer",
634 action_send_to_layer,
635 setup_action_bottom_layer
636 },
637 {
638 "togglealwaysonbottom",
639 action_toggle_layer,
640 setup_action_bottom_layer
641 },
642 {
643 "nextwindowlinear",
644 action_cycle_windows,
645 setup_action_cycle_windows_linear_next
646 },
647 {
648 "previouswindowlinear",
649 action_cycle_windows,
650 setup_action_cycle_windows_linear_previous
651 },
652 {
653 "nextwindow",
654 action_cycle_windows,
655 setup_action_cycle_windows_next
656 },
657 {
658 "previouswindow",
659 action_cycle_windows,
660 setup_action_cycle_windows_previous
661 },
662 {
663 "movetoedgenorth",
664 action_movetoedge,
665 setup_action_movetoedge_north
666 },
667 {
668 "movetoedgesouth",
669 action_movetoedge,
670 setup_action_movetoedge_south
671 },
672 {
673 "movetoedgewest",
674 action_movetoedge,
675 setup_action_movetoedge_west
676 },
677 {
678 "movetoedgeeast",
679 action_movetoedge,
680 setup_action_movetoedge_east
681 },
682 {
683 "growtoedgenorth",
684 action_growtoedge,
685 setup_action_growtoedge_north
686 },
687 {
688 "growtoedgesouth",
689 action_growtoedge,
690 setup_action_growtoedge_south
691 },
692 {
693 "growtoedgewest",
694 action_growtoedge,
695 setup_action_growtoedge_west
696 },
697 {
698 "growtoedgeeast",
699 action_growtoedge,
700 setup_action_growtoedge_east
701 },
702 {
703 NULL,
704 NULL,
705 NULL
706 }
707 };
708
709 ObAction *action_from_string(char *name)
710 {
711 ObAction *a = NULL;
712 int i;
713
714 for (i = 0; actionstrings[i].name; i++)
715 if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
716 a = action_new(actionstrings[i].func);
717 if (actionstrings[i].setup)
718 actionstrings[i].setup(a);
719 break;
720 }
721 return a;
722 }
723
724 ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
725 {
726 char *actname;
727 ObAction *act = NULL;
728 xmlNodePtr n;
729
730 if (parse_attr_string("name", node, &actname)) {
731 if ((act = action_from_string(actname))) {
732 if (act->func == action_execute || act->func == action_restart) {
733 if ((n = parse_find_node("execute", node->xmlChildrenNode))) {
734 gchar *s = parse_string(doc, n);
735 act->data.execute.path = expand_tilde(s);
736 g_free(s);
737 }
738 } else if (act->func == action_showmenu) {
739 if ((n = parse_find_node("menu", node->xmlChildrenNode)))
740 act->data.showmenu.name = parse_string(doc, n);
741 } else if (act->func == action_desktop) {
742 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
743 act->data.desktop.desk = parse_int(doc, n);
744 if (act->data.desktop.desk > 0) act->data.desktop.desk--;
745 } else if (act->func == action_send_to_desktop) {
746 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
747 act->data.sendto.desk = parse_int(doc, n);
748 if (act->data.sendto.desk > 0) act->data.sendto.desk--;
749 } else if (act->func == action_move_relative_horz ||
750 act->func == action_move_relative_vert ||
751 act->func == action_resize_relative_horz ||
752 act->func == action_resize_relative_vert) {
753 if ((n = parse_find_node("delta", node->xmlChildrenNode)))
754 act->data.relative.delta = parse_int(doc, n);
755 } else if (act->func == action_desktop_dir) {
756 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
757 act->data.desktopdir.wrap = parse_bool(doc, n);
758 } else if (act->func == action_send_to_desktop) {
759 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
760 act->data.sendto.follow = parse_bool(doc, n);
761 } else if (act->func == action_send_to_desktop_dir) {
762 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
763 act->data.sendtodir.wrap = parse_bool(doc, n);
764 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
765 act->data.sendtodir.follow = parse_bool(doc, n);
766 } else if (act->func == action_activate) {
767 if ((n = parse_find_node("here", node->xmlChildrenNode)))
768 act->data.activate.here = parse_bool(doc, n);
769 }
770 }
771 g_free(actname);
772 }
773 return act;
774 }
775
776 void action_execute(union ActionData *data)
777 {
778 GError *e = NULL;
779 char *cmd;
780 if (data->execute.path) {
781 cmd = g_filename_from_utf8(data->execute.path, -1, NULL, NULL, NULL);
782 if (cmd) {
783 if (!g_spawn_command_line_async(cmd, &e)) {
784 g_warning("failed to execute '%s': %s",
785 cmd, e->message);
786 }
787 } else {
788 g_warning("failed to convert '%s' from utf8", data->execute.path);
789 }
790 }
791 }
792
793 void action_activate(union ActionData *data)
794 {
795 if (data->activate.any.c)
796 client_activate(data->activate.any.c, data->activate.here);
797 }
798
799 void action_focus(union ActionData *data)
800 {
801 if (data->client.any.c)
802 client_focus(data->client.any.c);
803 }
804
805 void action_unfocus (union ActionData *data)
806 {
807 if (data->client.any.c)
808 client_unfocus(data->client.any.c);
809 }
810
811 void action_iconify(union ActionData *data)
812 {
813 if (data->client.any.c)
814 client_iconify(data->client.any.c, TRUE, TRUE);
815 }
816
817 void action_raiselower(union ActionData *data)
818 {
819 ObClient *c = data->client.any.c;
820 GList *it;
821 gboolean raise = FALSE;
822
823 if (!c) return;
824
825 for (it = stacking_list; it; it = g_list_next(it)) {
826 ObClient *cit = it->data;
827
828 if (cit == c) break;
829 if (client_normal(cit) == client_normal(c) &&
830 cit->layer == c->layer &&
831 cit->frame->visible)
832 {
833 if (RECT_INTERSECTS_RECT(cit->frame->area, c->frame->area)) {
834 raise = TRUE;
835 break;
836 }
837 }
838 }
839
840 if (raise)
841 stacking_raise(CLIENT_AS_WINDOW(c));
842 else
843 stacking_lower(CLIENT_AS_WINDOW(c));
844 }
845
846 void action_raise(union ActionData *data)
847 {
848 if (data->client.any.c)
849 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
850 }
851
852 void action_unshaderaise(union ActionData *data)
853 {
854 if (data->client.any.c) {
855 if (data->client.any.c->shaded)
856 client_shade(data->client.any.c, FALSE);
857 else
858 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
859 }
860 }
861
862 void action_shadelower(union ActionData *data)
863 {
864 if (data->client.any.c) {
865 if (data->client.any.c->shaded)
866 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
867 else
868 client_shade(data->client.any.c, TRUE);
869 }
870 }
871
872 void action_lower(union ActionData *data)
873 {
874 if (data->client.any.c)
875 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
876 }
877
878 void action_close(union ActionData *data)
879 {
880 if (data->client.any.c)
881 client_close(data->client.any.c);
882 }
883
884 void action_kill(union ActionData *data)
885 {
886 if (data->client.any.c)
887 client_kill(data->client.any.c);
888 }
889
890 void action_shade(union ActionData *data)
891 {
892 if (data->client.any.c)
893 client_shade(data->client.any.c, TRUE);
894 }
895
896 void action_unshade(union ActionData *data)
897 {
898 if (data->client.any.c)
899 client_shade(data->client.any.c, FALSE);
900 }
901
902 void action_toggle_shade(union ActionData *data)
903 {
904 if (data->client.any.c)
905 client_shade(data->client.any.c, !data->client.any.c->shaded);
906 }
907
908 void action_toggle_omnipresent(union ActionData *data)
909 {
910 if (data->client.any.c)
911 client_set_desktop(data->client.any.c,
912 data->client.any.c->desktop == DESKTOP_ALL ?
913 screen_desktop : DESKTOP_ALL, FALSE);
914 }
915
916 void action_move_relative_horz(union ActionData *data)
917 {
918 ObClient *c = data->relative.any.c;
919 if (c)
920 client_configure(c, OB_CORNER_TOPLEFT,
921 c->area.x + data->relative.delta, c->area.y,
922 c->area.width, c->area.height, TRUE, TRUE);
923 }
924
925 void action_move_relative_vert(union ActionData *data)
926 {
927 ObClient *c = data->relative.any.c;
928 if (c)
929 client_configure(c, OB_CORNER_TOPLEFT,
930 c->area.x, c->area.y + data->relative.delta,
931 c->area.width, c->area.height, TRUE, TRUE);
932 }
933
934 void action_resize_relative_horz(union ActionData *data)
935 {
936 ObClient *c = data->relative.any.c;
937 if (c)
938 client_configure(c, OB_CORNER_TOPLEFT, c->area.x, c->area.y,
939 c->area.width +
940 data->relative.delta * c->size_inc.width,
941 c->area.height, TRUE, TRUE);
942 }
943
944 void action_resize_relative_vert(union ActionData *data)
945 {
946 ObClient *c = data->relative.any.c;
947 if (c && !c->shaded)
948 client_configure(c, OB_CORNER_TOPLEFT, c->area.x, c->area.y,
949 c->area.width, c->area.height +
950 data->relative.delta * c->size_inc.height,
951 TRUE, TRUE);
952 }
953
954 void action_maximize_full(union ActionData *data)
955 {
956 if (data->client.any.c)
957 client_maximize(data->client.any.c, TRUE, 0, TRUE);
958 }
959
960 void action_unmaximize_full(union ActionData *data)
961 {
962 if (data->client.any.c)
963 client_maximize(data->client.any.c, FALSE, 0, TRUE);
964 }
965
966 void action_toggle_maximize_full(union ActionData *data)
967 {
968 if (data->client.any.c)
969 client_maximize(data->client.any.c,
970 !(data->client.any.c->max_horz ||
971 data->client.any.c->max_vert),
972 0, TRUE);
973 }
974
975 void action_maximize_horz(union ActionData *data)
976 {
977 if (data->client.any.c)
978 client_maximize(data->client.any.c, TRUE, 1, TRUE);
979 }
980
981 void action_unmaximize_horz(union ActionData *data)
982 {
983 if (data->client.any.c)
984 client_maximize(data->client.any.c, FALSE, 1, TRUE);
985 }
986
987 void action_toggle_maximize_horz(union ActionData *data)
988 {
989 if (data->client.any.c)
990 client_maximize(data->client.any.c,
991 !data->client.any.c->max_horz, 1, TRUE);
992 }
993
994 void action_maximize_vert(union ActionData *data)
995 {
996 if (data->client.any.c)
997 client_maximize(data->client.any.c, TRUE, 2, TRUE);
998 }
999
1000 void action_unmaximize_vert(union ActionData *data)
1001 {
1002 if (data->client.any.c)
1003 client_maximize(data->client.any.c, FALSE, 2, TRUE);
1004 }
1005
1006 void action_toggle_maximize_vert(union ActionData *data)
1007 {
1008 if (data->client.any.c)
1009 client_maximize(data->client.any.c, !data->client.any.c->max_vert, 2, TRUE);
1010 }
1011
1012 void action_send_to_desktop(union ActionData *data)
1013 {
1014 ObClient *c = data->sendto.any.c;
1015
1016 if (!c || !client_normal(c)) return;
1017
1018 if (data->sendto.desk < screen_num_desktops ||
1019 data->sendto.desk == DESKTOP_ALL) {
1020 client_set_desktop(c, data->sendto.desk, data->sendto.follow);
1021 if (data->sendto.follow)
1022 screen_set_desktop(data->sendto.desk);
1023 }
1024 }
1025
1026 void action_desktop(union ActionData *data)
1027 {
1028 if (data->desktop.desk < screen_num_desktops ||
1029 data->desktop.desk == DESKTOP_ALL)
1030 screen_set_desktop(data->desktop.desk);
1031 }
1032
1033 void action_desktop_dir(union ActionData *data)
1034 {
1035 guint d;
1036
1037 d = screen_cycle_desktop(data->desktopdir.dir,
1038 data->desktopdir.wrap,
1039 data->sendtodir.linear,
1040 data->desktopdir.inter.any.interactive,
1041 data->desktopdir.inter.final,
1042 data->desktopdir.inter.cancel);
1043 screen_set_desktop(d);
1044 }
1045
1046 void action_send_to_desktop_dir(union ActionData *data)
1047 {
1048 ObClient *c = data->sendtodir.inter.any.c;
1049 guint d;
1050
1051 if (!c || !client_normal(c)) return;
1052
1053 d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
1054 data->sendtodir.linear,
1055 data->sendtodir.inter.any.interactive,
1056 data->sendtodir.inter.final,
1057 data->sendtodir.inter.cancel);
1058 client_set_desktop(c, d, data->sendtodir.follow);
1059 if (data->sendtodir.follow)
1060 screen_set_desktop(d);
1061 }
1062
1063 void action_desktop_last(union ActionData *data)
1064 {
1065 screen_set_desktop(screen_last_desktop);
1066 }
1067
1068 void action_toggle_decorations(union ActionData *data)
1069 {
1070 ObClient *c = data->client.any.c;
1071
1072 if (!c) return;
1073
1074 c->decorate = !c->decorate;
1075 client_setup_decor_and_functions(c);
1076 }
1077
1078 void action_moveresize(union ActionData *data)
1079 {
1080 ObClient *c = data->moveresize.any.c;
1081
1082 if (!c || !client_normal(c)) return;
1083
1084 moveresize_start(c, data->moveresize.x, data->moveresize.y,
1085 data->moveresize.button, data->moveresize.corner);
1086 }
1087
1088 void action_restart(union ActionData *data)
1089 {
1090 ob_restart_other(data->execute.path);
1091 }
1092
1093 void action_exit(union ActionData *data)
1094 {
1095 ob_exit();
1096 }
1097
1098 void action_showmenu(union ActionData *data)
1099 {
1100 if (data->showmenu.name) {
1101 menu_show(data->showmenu.name, data->showmenu.x, data->showmenu.y,
1102 data->showmenu.any.c);
1103 }
1104 }
1105
1106 void action_cycle_windows(union ActionData *data)
1107 {
1108 focus_cycle(data->cycle.forward, data->cycle.linear,
1109 data->cycle.inter.any.interactive,
1110 data->cycle.inter.final, data->cycle.inter.cancel);
1111 }
1112
1113 void action_directional_focus(union ActionData *data)
1114 {
1115 focus_directional_cycle(data->interdiraction.direction,
1116 data->interdiraction.inter.any.interactive,
1117 data->interdiraction.inter.final,
1118 data->interdiraction.inter.cancel);
1119 }
1120
1121 void action_movetoedge(union ActionData *data)
1122 {
1123 int x, y;
1124 ObClient *c = data->diraction.any.c;
1125
1126 if (!c)
1127 return;
1128 x = c->frame->area.x;
1129 y = c->frame->area.y;
1130
1131 switch(data->diraction.direction) {
1132 case OB_DIRECTION_NORTH:
1133 y = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1134 break;
1135 case OB_DIRECTION_WEST:
1136 x = client_directional_edge_search(c, OB_DIRECTION_WEST);
1137 break;
1138 case OB_DIRECTION_SOUTH:
1139 y = client_directional_edge_search(c, OB_DIRECTION_SOUTH) -
1140 c->frame->area.height;
1141 break;
1142 case OB_DIRECTION_EAST:
1143 x = client_directional_edge_search(c, OB_DIRECTION_EAST) -
1144 c->frame->area.width;
1145 break;
1146 default:
1147 g_assert_not_reached();
1148 }
1149 frame_frame_gravity(c->frame, &x, &y);
1150 client_configure(c, OB_CORNER_TOPLEFT,
1151 x, y, c->area.width, c->area.height, TRUE, TRUE);
1152
1153 }
1154
1155 void action_growtoedge(union ActionData *data)
1156 {
1157 int x, y, width, height, dest;
1158 ObClient *c = data->diraction.any.c;
1159 Rect *a = screen_area(c->desktop);
1160
1161 if (!c)
1162 return;
1163
1164 x = c->frame->area.x;
1165 y = c->frame->area.y;
1166 width = c->frame->area.width;
1167 height = c->frame->area.height;
1168
1169 switch(data->diraction.direction) {
1170 case OB_DIRECTION_NORTH:
1171 dest = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1172 if (a->y == y)
1173 height = c->frame->area.height / 2;
1174 else {
1175 height = c->frame->area.y + c->frame->area.height - dest;
1176 y = dest;
1177 }
1178 break;
1179 case OB_DIRECTION_WEST:
1180 dest = client_directional_edge_search(c, OB_DIRECTION_WEST);
1181 if (a->x == x)
1182 width = c->frame->area.width / 2;
1183 else {
1184 width = c->frame->area.x + c->frame->area.width - dest;
1185 x = dest;
1186 }
1187 break;
1188 case OB_DIRECTION_SOUTH:
1189 dest = client_directional_edge_search(c, OB_DIRECTION_SOUTH);
1190 if (a->y + a->height == y + c->frame->area.height) {
1191 height = c->frame->area.height / 2;
1192 y = a->y + a->height - height;
1193 } else
1194 height = dest - c->frame->area.y;
1195 y += (height - c->frame->area.height) % c->size_inc.height;
1196 height -= (height - c->frame->area.height) % c->size_inc.height;
1197 break;
1198 case OB_DIRECTION_EAST:
1199 dest = client_directional_edge_search(c, OB_DIRECTION_EAST);
1200 if (a->x + a->width == x + c->frame->area.width) {
1201 width = c->frame->area.width / 2;
1202 x = a->x + a->width - width;
1203 } else
1204 width = dest - c->frame->area.x;
1205 x += (width - c->frame->area.width) % c->size_inc.width;
1206 width -= (width - c->frame->area.width) % c->size_inc.width;
1207 break;
1208 default:
1209 g_assert_not_reached();
1210 }
1211 frame_frame_gravity(c->frame, &x, &y);
1212 width -= c->frame->size.left + c->frame->size.right;
1213 height -= c->frame->size.top + c->frame->size.bottom;
1214 client_configure(c, OB_CORNER_TOPLEFT, x, y, width, height, TRUE, TRUE);
1215 }
1216
1217 void action_send_to_layer(union ActionData *data)
1218 {
1219 if (data->layer.any.c)
1220 client_set_layer(data->layer.any.c, data->layer.layer);
1221 }
1222
1223 void action_toggle_layer(union ActionData *data)
1224 {
1225 ObClient *c = data->layer.any.c;
1226
1227 if (c) {
1228 if (data->layer.layer < 0)
1229 client_set_layer(c, c->below ? 0 : -1);
1230 else if (data->layer.layer > 0)
1231 client_set_layer(c, c->above ? 0 : 1);
1232 }
1233 }
1234
1235 void action_toggle_show_desktop(union ActionData *data)
1236 {
1237 screen_show_desktop(!screen_showing_desktop);
1238 }
1239
1240 void action_show_desktop(union ActionData *data)
1241 {
1242 screen_show_desktop(TRUE);
1243 }
1244
1245 void action_unshow_desktop(union ActionData *data)
1246 {
1247 screen_show_desktop(FALSE);
1248 }
This page took 0.084612 seconds and 5 git commands to generate.