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