]> Dogcows Code - chaz/openbox/blob - openbox/action.c
d79bf7aec0b86bdda0a6df5495471a8624e3b2a9
[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 if (data->execute.path)
555 if (!g_spawn_command_line_async(data->execute.path, &e)) {
556 g_warning("failed to execute '%s': %s",
557 data->execute.path, e->message);
558 }
559 }
560
561 void action_focus(union ActionData *data)
562 {
563 if (data->client.c)
564 client_focus(data->client.c);
565 }
566
567 void action_unfocus (union ActionData *data)
568 {
569 if (data->client.c)
570 client_unfocus(data->client.c);
571 }
572
573 void action_iconify(union ActionData *data)
574 {
575 if (data->client.c)
576 client_iconify(data->client.c, TRUE, TRUE);
577 }
578
579 void action_focusraise(union ActionData *data)
580 {
581 if (data->client.c) {
582 client_focus(data->client.c);
583 stacking_raise(CLIENT_AS_WINDOW(data->client.c));
584 }
585 }
586
587 void action_raise(union ActionData *data)
588 {
589 if (data->client.c)
590 stacking_raise(CLIENT_AS_WINDOW(data->client.c));
591 }
592
593 void action_unshaderaise(union ActionData *data)
594 {
595 if (data->client.c) {
596 if (data->client.c->shaded)
597 client_shade(data->client.c, FALSE);
598 else
599 stacking_raise(CLIENT_AS_WINDOW(data->client.c));
600 }
601 }
602
603 void action_shadelower(union ActionData *data)
604 {
605 if (data->client.c) {
606 if (data->client.c->shaded)
607 stacking_lower(CLIENT_AS_WINDOW(data->client.c));
608 else
609 client_shade(data->client.c, TRUE);
610 }
611 }
612
613 void action_lower(union ActionData *data)
614 {
615 if (data->client.c)
616 stacking_lower(CLIENT_AS_WINDOW(data->client.c));
617 }
618
619 void action_close(union ActionData *data)
620 {
621 if (data->client.c)
622 client_close(data->client.c);
623 }
624
625 void action_kill(union ActionData *data)
626 {
627 if (data->client.c)
628 client_kill(data->client.c);
629 }
630
631 void action_shade(union ActionData *data)
632 {
633 if (data->client.c)
634 client_shade(data->client.c, TRUE);
635 }
636
637 void action_unshade(union ActionData *data)
638 {
639 if (data->client.c)
640 client_shade(data->client.c, FALSE);
641 }
642
643 void action_toggle_shade(union ActionData *data)
644 {
645 if (data->client.c)
646 client_shade(data->client.c, !data->client.c->shaded);
647 }
648
649 void action_toggle_omnipresent(union ActionData *data)
650 {
651 if (data->client.c)
652 client_set_desktop(data->client.c,
653 data->client.c->desktop == DESKTOP_ALL ?
654 screen_desktop : DESKTOP_ALL, FALSE);
655 }
656
657 void action_move_relative_horz(union ActionData *data)
658 {
659 Client *c = data->relative.c;
660 if (c)
661 client_configure(c, Corner_TopLeft,
662 c->area.x + data->relative.delta, c->area.y,
663 c->area.width, c->area.height, TRUE, TRUE);
664 }
665
666 void action_move_relative_vert(union ActionData *data)
667 {
668 Client *c = data->relative.c;
669 if (c)
670 client_configure(c, Corner_TopLeft,
671 c->area.x, c->area.y + data->relative.delta,
672 c->area.width, c->area.height, TRUE, TRUE);
673 }
674
675 void action_resize_relative_horz(union ActionData *data)
676 {
677 Client *c = data->relative.c;
678 if (c)
679 client_configure(c, Corner_TopLeft, c->area.x, c->area.y,
680 c->area.width +
681 data->relative.delta * c->size_inc.width,
682 c->area.height, TRUE, TRUE);
683 }
684
685 void action_resize_relative_vert(union ActionData *data)
686 {
687 Client *c = data->relative.c;
688 if (c && !c->shaded)
689 client_configure(c, Corner_TopLeft, c->area.x, c->area.y,
690 c->area.width, c->area.height +
691 data->relative.delta * c->size_inc.height,
692 TRUE, TRUE);
693 }
694
695 void action_maximize_full(union ActionData *data)
696 {
697 if (data->client.c)
698 client_maximize(data->client.c, TRUE, 0, TRUE);
699 }
700
701 void action_unmaximize_full(union ActionData *data)
702 {
703 if (data->client.c)
704 client_maximize(data->client.c, FALSE, 0, TRUE);
705 }
706
707 void action_toggle_maximize_full(union ActionData *data)
708 {
709 if (data->client.c)
710 client_maximize(data->client.c,
711 !(data->client.c->max_horz ||
712 data->client.c->max_vert),
713 0, TRUE);
714 }
715
716 void action_maximize_horz(union ActionData *data)
717 {
718 if (data->client.c)
719 client_maximize(data->client.c, TRUE, 1, TRUE);
720 }
721
722 void action_unmaximize_horz(union ActionData *data)
723 {
724 if (data->client.c)
725 client_maximize(data->client.c, FALSE, 1, TRUE);
726 }
727
728 void action_toggle_maximize_horz(union ActionData *data)
729 {
730 if (data->client.c)
731 client_maximize(data->client.c, !data->client.c->max_horz, 1, TRUE);
732 }
733
734 void action_maximize_vert(union ActionData *data)
735 {
736 if (data->client.c)
737 client_maximize(data->client.c, TRUE, 2, TRUE);
738 }
739
740 void action_unmaximize_vert(union ActionData *data)
741 {
742 if (data->client.c)
743 client_maximize(data->client.c, FALSE, 2, TRUE);
744 }
745
746 void action_toggle_maximize_vert(union ActionData *data)
747 {
748 if (data->client.c)
749 client_maximize(data->client.c, !data->client.c->max_vert, 2, TRUE);
750 }
751
752 void action_send_to_desktop(union ActionData *data)
753 {
754 if (data->sendto.c) {
755 if (data->sendto.desk < screen_num_desktops ||
756 data->sendto.desk == DESKTOP_ALL) {
757 client_set_desktop(data->desktop.c,
758 data->sendto.desk, data->sendto.follow);
759 if (data->sendto.follow) screen_set_desktop(data->sendto.desk);
760 }
761 }
762 }
763
764 void action_desktop(union ActionData *data)
765 {
766 if (data->desktop.desk < screen_num_desktops ||
767 data->desktop.desk == DESKTOP_ALL)
768 screen_set_desktop(data->desktop.desk);
769 }
770
771 static void cur_row_col(guint *r, guint *c)
772 {
773 switch (screen_desktop_layout.orientation) {
774 case Orientation_Horz:
775 switch (screen_desktop_layout.start_corner) {
776 case Corner_TopLeft:
777 *r = screen_desktop / screen_desktop_layout.columns;
778 *c = screen_desktop % screen_desktop_layout.columns;
779 break;
780 case Corner_BottomLeft:
781 *r = screen_desktop_layout.rows - 1 -
782 screen_desktop / screen_desktop_layout.columns;
783 *c = screen_desktop % screen_desktop_layout.columns;
784 break;
785 case Corner_TopRight:
786 *r = screen_desktop / screen_desktop_layout.columns;
787 *c = screen_desktop_layout.columns - 1 -
788 screen_desktop % screen_desktop_layout.columns;
789 break;
790 case Corner_BottomRight:
791 *r = screen_desktop_layout.rows - 1 -
792 screen_desktop / screen_desktop_layout.columns;
793 *c = screen_desktop_layout.columns - 1 -
794 screen_desktop % screen_desktop_layout.columns;
795 break;
796 }
797 break;
798 case Orientation_Vert:
799 switch (screen_desktop_layout.start_corner) {
800 case Corner_TopLeft:
801 *r = screen_desktop % screen_desktop_layout.rows;
802 *c = screen_desktop / screen_desktop_layout.rows;
803 break;
804 case Corner_BottomLeft:
805 *r = screen_desktop_layout.rows - 1 -
806 screen_desktop % screen_desktop_layout.rows;
807 *c = screen_desktop / screen_desktop_layout.rows;
808 break;
809 case Corner_TopRight:
810 *r = screen_desktop % screen_desktop_layout.rows;
811 *c = screen_desktop_layout.columns - 1 -
812 screen_desktop / screen_desktop_layout.rows;
813 break;
814 case Corner_BottomRight:
815 *r = screen_desktop_layout.rows - 1 -
816 screen_desktop % screen_desktop_layout.rows;
817 *c = screen_desktop_layout.columns - 1 -
818 screen_desktop / screen_desktop_layout.rows;
819 break;
820 }
821 break;
822 }
823 }
824
825 static guint translate_row_col(guint r, guint c)
826 {
827 switch (screen_desktop_layout.orientation) {
828 case Orientation_Horz:
829 switch (screen_desktop_layout.start_corner) {
830 case Corner_TopLeft:
831 return r % screen_desktop_layout.rows *
832 screen_desktop_layout.columns +
833 c % screen_desktop_layout.columns;
834 case Corner_BottomLeft:
835 return (screen_desktop_layout.rows - 1 -
836 r % screen_desktop_layout.rows) *
837 screen_desktop_layout.columns +
838 c % screen_desktop_layout.columns;
839 case Corner_TopRight:
840 return r % screen_desktop_layout.rows *
841 screen_desktop_layout.columns +
842 (screen_desktop_layout.columns - 1 -
843 c % screen_desktop_layout.columns);
844 case Corner_BottomRight:
845 return (screen_desktop_layout.rows - 1 -
846 r % screen_desktop_layout.rows) *
847 screen_desktop_layout.columns +
848 (screen_desktop_layout.columns - 1 -
849 c % screen_desktop_layout.columns);
850 }
851 case Orientation_Vert:
852 switch (screen_desktop_layout.start_corner) {
853 case Corner_TopLeft:
854 return c % screen_desktop_layout.columns *
855 screen_desktop_layout.rows +
856 r % screen_desktop_layout.rows;
857 case Corner_BottomLeft:
858 return c % screen_desktop_layout.columns *
859 screen_desktop_layout.rows +
860 (screen_desktop_layout.rows - 1 -
861 r % screen_desktop_layout.rows);
862 case Corner_TopRight:
863 return (screen_desktop_layout.columns - 1 -
864 c % screen_desktop_layout.columns) *
865 screen_desktop_layout.rows +
866 r % screen_desktop_layout.rows;
867 case Corner_BottomRight:
868 return (screen_desktop_layout.columns - 1 -
869 c % screen_desktop_layout.columns) *
870 screen_desktop_layout.rows +
871 (screen_desktop_layout.rows - 1 -
872 r % screen_desktop_layout.rows);
873 }
874 }
875 g_assert_not_reached();
876 return 0;
877 }
878
879 void action_desktop_right(union ActionData *data)
880 {
881 guint r, c, d;
882
883 cur_row_col(&r, &c);
884 ++c;
885 if (c >= screen_desktop_layout.columns) {
886 if (!data->desktopdir.wrap) return;
887 c = 0;
888 }
889 d = translate_row_col(r, c);
890 if (d >= screen_num_desktops) {
891 if (!data->desktopdir.wrap) return;
892 ++c;
893 }
894 d = translate_row_col(r, c);
895 if (d < screen_num_desktops)
896 screen_set_desktop(d);
897 }
898
899 void action_send_to_desktop_right(union ActionData *data)
900 {
901 guint r, c, d;
902
903 if (data->sendtodir.c) {
904 cur_row_col(&r, &c);
905 ++c;
906 if (c >= screen_desktop_layout.columns) {
907 if (!data->sendtodir.wrap) return;
908 c = 0;
909 }
910 d = translate_row_col(r, c);
911 if (d >= screen_num_desktops) {
912 if (!data->sendtodir.wrap) return;
913 ++c;
914 }
915 d = translate_row_col(r, c);
916 if (d < screen_num_desktops) {
917 client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
918 if (data->sendtodir.follow) screen_set_desktop(d);
919 }
920 }
921 }
922
923 void action_desktop_left(union ActionData *data)
924 {
925 guint r, c, d;
926
927 cur_row_col(&r, &c);
928 --c;
929 if (c >= screen_desktop_layout.columns) {
930 if (!data->desktopdir.wrap) return;
931 c = screen_desktop_layout.columns - 1;
932 }
933 d = translate_row_col(r, c);
934 if (d >= screen_num_desktops) {
935 if (!data->desktopdir.wrap) return;
936 --c;
937 }
938 d = translate_row_col(r, c);
939 if (d < screen_num_desktops)
940 screen_set_desktop(d);
941 }
942
943 void action_send_to_desktop_left(union ActionData *data)
944 {
945 guint r, c, d;
946
947 if (data->sendtodir.c) {
948 cur_row_col(&r, &c);
949 --c;
950 if (c >= screen_desktop_layout.columns) {
951 if (!data->sendtodir.wrap) return;
952 c = screen_desktop_layout.columns - 1;
953 }
954 d = translate_row_col(r, c);
955 if (d >= screen_num_desktops) {
956 if (!data->sendtodir.wrap) return;
957 --c;
958 }
959 d = translate_row_col(r, c);
960 if (d < screen_num_desktops) {
961 client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
962 if (data->sendtodir.follow) screen_set_desktop(d);
963 }
964 }
965 }
966
967 void action_desktop_down(union ActionData *data)
968 {
969 guint r, c, d;
970
971 cur_row_col(&r, &c);
972 ++r;
973 if (r >= screen_desktop_layout.rows) {
974 if (!data->desktopdir.wrap) return;
975 r = 0;
976 }
977 d = translate_row_col(r, c);
978 if (d >= screen_num_desktops) {
979 if (!data->desktopdir.wrap) return;
980 ++r;
981 }
982 d = translate_row_col(r, c);
983 if (d < screen_num_desktops)
984 screen_set_desktop(d);
985 }
986
987 void action_send_to_desktop_down(union ActionData *data)
988 {
989 guint r, c, d;
990
991 if (data->sendtodir.c) {
992 cur_row_col(&r, &c);
993 ++r;
994 if (r >= screen_desktop_layout.rows) {
995 if (!data->sendtodir.wrap) return;
996 r = 0;
997 }
998 d = translate_row_col(r, c);
999 if (d >= screen_num_desktops) {
1000 if (!data->sendtodir.wrap) return;
1001 ++r;
1002 }
1003 d = translate_row_col(r, c);
1004 if (d < screen_num_desktops) {
1005 client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
1006 if (data->sendtodir.follow) screen_set_desktop(d);
1007 }
1008 }
1009 }
1010
1011 void action_desktop_up(union ActionData *data)
1012 {
1013 guint r, c, d;
1014
1015 cur_row_col(&r, &c);
1016 --r;
1017 if (r >= screen_desktop_layout.rows) {
1018 if (!data->desktopdir.wrap) return;
1019 r = screen_desktop_layout.rows - 1;
1020 }
1021 d = translate_row_col(r, c);
1022 if (d >= screen_num_desktops) {
1023 if (!data->desktopdir.wrap) return;
1024 --r;
1025 }
1026 d = translate_row_col(r, c);
1027 if (d < screen_num_desktops)
1028 screen_set_desktop(d);
1029 }
1030
1031 void action_send_to_desktop_up(union ActionData *data)
1032 {
1033 guint r, c, d;
1034
1035 if (data->sendtodir.c) {
1036 cur_row_col(&r, &c);
1037 --r;
1038 if (r >= screen_desktop_layout.rows) {
1039 if (!data->sendtodir.wrap) return;
1040 r = screen_desktop_layout.rows - 1;
1041 }
1042 d = translate_row_col(r, c);
1043 if (d >= screen_num_desktops) {
1044 if (!data->sendtodir.wrap) return;
1045 --r;
1046 }
1047 d = translate_row_col(r, c);
1048 if (d < screen_num_desktops) {
1049 client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
1050 if (data->sendtodir.follow) screen_set_desktop(d);
1051 }
1052 }
1053 }
1054
1055 void action_toggle_decorations(union ActionData *data)
1056 {
1057 Client *c = data->client.c;;
1058
1059 if (!c) return;
1060
1061 c->disabled_decorations = c->disabled_decorations ? 0 : ~0;
1062 client_setup_decor_and_functions(c);
1063 }
1064
1065 void action_moveresize(union ActionData *data)
1066 {
1067 Client *c = data->moveresize.c;
1068
1069 if (!c || !client_normal(c)) return;
1070
1071 moveresize_start(c, data->moveresize.x, data->moveresize.y,
1072 data->moveresize.button, data->moveresize.corner);
1073 }
1074
1075 void action_restart(union ActionData *data)
1076 {
1077 ob_restart_path = data->execute.path;
1078 ob_shutdown = ob_restart = TRUE;
1079 }
1080
1081 void action_exit(union ActionData *data)
1082 {
1083 ob_shutdown = TRUE;
1084 }
1085
1086 void action_showmenu(union ActionData *data)
1087 {
1088 if (data->showmenu.name) {
1089 menu_show(data->showmenu.name, data->showmenu.x, data->showmenu.y,
1090 data->showmenu.c);
1091 }
1092 }
1093
1094 void action_cycle_windows(union ActionData *data)
1095 {
1096 Client *c;
1097
1098 c = focus_cycle(data->cycle.forward, data->cycle.linear, data->cycle.final,
1099 data->cycle.cancel);
1100 }
1101
1102 void action_directional_focus(union ActionData *data)
1103 {
1104 Client *nf;
1105
1106 if (!data->diraction.c)
1107 return;
1108 if ((nf = client_find_directional(data->diraction.c,
1109 data->diraction.direction)))
1110 client_activate(nf);
1111 }
1112
1113 void action_movetoedge(union ActionData *data)
1114 {
1115 int x, y, h, w;
1116 Client *c = data->diraction.c;
1117
1118 if (!c)
1119 return;
1120 x = c->frame->area.x;
1121 y = c->frame->area.y;
1122
1123 h = screen_area(c->desktop)->height;
1124 w = screen_area(c->desktop)->width;
1125 switch(data->diraction.direction) {
1126 case Direction_North:
1127 y = 0;
1128 break;
1129 case Direction_West:
1130 x = 0;
1131 break;
1132 case Direction_South:
1133 y = h - c->frame->area.height;
1134 break;
1135 case Direction_East:
1136 x = w - c->frame->area.width;
1137 break;
1138 }
1139 frame_frame_gravity(c->frame, &x, &y);
1140 client_configure(c, Corner_TopLeft,
1141 x, y, c->area.width, c->area.height, TRUE, TRUE);
1142
1143 }
1144
1145 void action_send_to_layer(union ActionData *data)
1146 {
1147 if (data->layer.c)
1148 client_set_layer(data->layer.c, data->layer.layer);
1149 }
1150
1151 void action_toggle_layer(union ActionData *data)
1152 {
1153 Client *c = data->layer.c;
1154
1155 if (c) {
1156 if (data->layer.layer < 0)
1157 client_set_layer(c, c->below ? 0 : -1);
1158 else if (data->layer.layer > 0)
1159 client_set_layer(c, c->above ? 0 : 1);
1160 }
1161 }
1162
1163 void action_toggle_show_desktop(union ActionData *data)
1164 {
1165 screen_show_desktop(!screen_showing_desktop);
1166 }
1167
1168 void action_show_desktop(union ActionData *data)
1169 {
1170 screen_show_desktop(TRUE);
1171 }
1172
1173 void action_unshow_desktop(union ActionData *data)
1174 {
1175 screen_show_desktop(FALSE);
1176 }
This page took 0.087951 seconds and 4 git commands to generate.