3 #include "moveresize.h"
15 typedef struct ActionString {
17 void (*func)(union ActionData *);
18 void (*setup)(Action *);
21 Action *action_new(void (*func)(union ActionData *data))
23 Action *a = g_new0(Action, 1);
29 void action_free(Action *a)
31 if (a == NULL) return;
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);
42 void setup_action_directional_focus_north(Action *a)
44 a->data.diraction.direction = Direction_North;
47 void setup_action_directional_focus_east(Action *a)
49 a->data.diraction.direction = Direction_East;
52 void setup_action_directional_focus_south(Action *a)
54 a->data.diraction.direction = Direction_South;
57 void setup_action_directional_focus_west(Action *a)
59 a->data.diraction.direction = Direction_West;
62 void setup_action_directional_focus_northeast(Action *a)
64 a->data.diraction.direction = Direction_NorthEast;
67 void setup_action_directional_focus_southeast(Action *a)
69 a->data.diraction.direction = Direction_SouthEast;
72 void setup_action_directional_focus_southwest(Action *a)
74 a->data.diraction.direction = Direction_SouthWest;
77 void setup_action_directional_focus_northwest(Action *a)
79 a->data.diraction.direction = Direction_NorthWest;
82 void setup_action_send_to_desktop(Action *a)
84 a->data.sendto.follow = TRUE;
87 void setup_action_send_to_desktop_direction(Action *a)
89 a->data.sendtodir.wrap = TRUE;
90 a->data.sendtodir.follow = TRUE;
93 void setup_action_desktop_direction(Action *a)
95 a->data.desktopdir.wrap = TRUE;
98 void setup_action_move_keyboard(Action *a)
100 a->data.moveresize.corner = prop_atoms.net_wm_moveresize_move_keyboard;
103 void setup_action_move(Action *a)
105 a->data.moveresize.corner = prop_atoms.net_wm_moveresize_move;
108 void setup_action_resize(Action *a)
110 a->data.moveresize.corner = prop_atoms.net_wm_moveresize_size_topleft;
113 void setup_action_resize_keyboard(Action *a)
115 a->data.moveresize.corner = prop_atoms.net_wm_moveresize_size_keyboard;
118 void setup_action_cycle_windows_linear_next(Action *a)
120 a->data.cycle.linear = TRUE;
121 a->data.cycle.forward = TRUE;
124 void setup_action_cycle_windows_linear_previous(Action *a)
126 a->data.cycle.linear = TRUE;
127 a->data.cycle.forward = FALSE;
130 void setup_action_cycle_windows_next(Action *a)
132 a->data.cycle.linear = FALSE;
133 a->data.cycle.forward = TRUE;
136 void setup_action_cycle_windows_previous(Action *a)
138 a->data.cycle.linear = FALSE;
139 a->data.cycle.forward = FALSE;
142 void setup_action_movetoedge_north(Action *a)
144 a->data.diraction.direction = Direction_North;
147 void setup_action_movetoedge_south(Action *a)
149 a->data.diraction.direction = Direction_South;
152 void setup_action_movetoedge_east(Action *a)
154 a->data.diraction.direction = Direction_East;
157 void setup_action_movetoedge_west(Action *a)
159 a->data.diraction.direction = Direction_West;
162 void setup_action_top_layer(Action *a)
164 a->data.layer.layer = 1;
167 void setup_action_normal_layer(Action *a)
169 a->data.layer.layer = 0;
172 void setup_action_bottom_layer(Action *a)
174 a->data.layer.layer = -1;
177 ActionString actionstrings[] =
185 "directionalfocusnorth",
186 action_directional_focus,
187 setup_action_directional_focus_north
190 "directionalfocuseast",
191 action_directional_focus,
192 setup_action_directional_focus_east
195 "directionalfocussouth",
196 action_directional_focus,
197 setup_action_directional_focus_south
200 "directionalfocuswest",
201 action_directional_focus,
202 setup_action_directional_focus_west
205 "directionalfocusnortheast",
206 action_directional_focus,
207 setup_action_directional_focus_northeast
210 "directionalfocussoutheast",
211 action_directional_focus,
212 setup_action_directional_focus_southeast
215 "directionalfocussouthwest",
216 action_directional_focus,
217 setup_action_directional_focus_southwest
220 "directionalfocusnorthwest",
221 action_directional_focus,
222 setup_action_directional_focus_northwest
291 action_toggle_omnipresent,
296 action_move_relative_horz,
301 action_move_relative_vert,
305 "resizerelativehorz",
306 action_resize_relative_horz,
310 "resizerelativevert",
311 action_resize_relative_vert,
316 action_maximize_full,
321 action_unmaximize_full,
325 "togglemaximizefull",
326 action_toggle_maximize_full,
331 action_maximize_horz,
336 action_unmaximize_horz,
340 "togglemaximizehorz",
341 action_toggle_maximize_horz,
346 action_maximize_vert,
351 action_unmaximize_vert,
355 "togglemaximizevert",
356 action_toggle_maximize_vert,
361 action_send_to_desktop,
362 setup_action_send_to_desktop
365 "sendtodesktopright",
366 action_send_to_desktop_right,
367 setup_action_send_to_desktop_direction
371 action_send_to_desktop_left,
372 setup_action_send_to_desktop_direction
376 action_send_to_desktop_up,
377 setup_action_send_to_desktop_direction
381 action_send_to_desktop_down,
382 setup_action_send_to_desktop_direction
391 action_desktop_right,
392 setup_action_desktop_direction
397 setup_action_desktop_direction
402 setup_action_desktop_direction
407 setup_action_desktop_direction
411 action_toggle_decorations,
417 setup_action_move_keyboard
432 setup_action_resize_keyboard
451 action_send_to_layer,
452 setup_action_top_layer
457 setup_action_top_layer
461 action_send_to_layer,
462 setup_action_normal_layer
466 action_send_to_layer,
467 setup_action_bottom_layer
470 "togglealwaysonbottom",
472 setup_action_bottom_layer
476 action_cycle_windows,
477 setup_action_cycle_windows_linear_next
480 "previouswindowlinear",
481 action_cycle_windows,
482 setup_action_cycle_windows_linear_previous
486 action_cycle_windows,
487 setup_action_cycle_windows_next
491 action_cycle_windows,
492 setup_action_cycle_windows_previous
497 setup_action_movetoedge_north
502 setup_action_movetoedge_south
507 setup_action_movetoedge_west
512 setup_action_movetoedge_east
521 Action *action_from_string(char *name)
526 for (i = 0; actionstrings[i].name; i++)
527 if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
528 a = action_new(actionstrings[i].func);
529 if (actionstrings[i].setup)
530 actionstrings[i].setup(a);
536 void action_execute(union ActionData *data)
539 if (data->execute.path)
540 if (!g_spawn_command_line_async(data->execute.path, &e)) {
541 g_warning("failed to execute '%s': %s",
542 data->execute.path, e->message);
546 void action_focus(union ActionData *data)
549 client_focus(data->client.c);
552 void action_unfocus (union ActionData *data)
555 client_unfocus(data->client.c);
558 void action_iconify(union ActionData *data)
561 client_iconify(data->client.c, TRUE, TRUE);
564 void action_focusraise(union ActionData *data)
566 if (data->client.c) {
567 client_focus(data->client.c);
568 stacking_raise(CLIENT_AS_WINDOW(data->client.c));
572 void action_raise(union ActionData *data)
575 stacking_raise(CLIENT_AS_WINDOW(data->client.c));
578 void action_unshaderaise(union ActionData *data)
580 if (data->client.c) {
581 if (data->client.c->shaded)
582 client_shade(data->client.c, FALSE);
584 stacking_raise(CLIENT_AS_WINDOW(data->client.c));
588 void action_shadelower(union ActionData *data)
590 if (data->client.c) {
591 if (data->client.c->shaded)
592 stacking_lower(CLIENT_AS_WINDOW(data->client.c));
594 client_shade(data->client.c, TRUE);
598 void action_lower(union ActionData *data)
601 stacking_lower(CLIENT_AS_WINDOW(data->client.c));
604 void action_close(union ActionData *data)
607 client_close(data->client.c);
610 void action_kill(union ActionData *data)
613 client_kill(data->client.c);
616 void action_shade(union ActionData *data)
619 client_shade(data->client.c, TRUE);
622 void action_unshade(union ActionData *data)
625 client_shade(data->client.c, FALSE);
628 void action_toggle_shade(union ActionData *data)
631 client_shade(data->client.c, !data->client.c->shaded);
634 void action_toggle_omnipresent(union ActionData *data)
637 client_set_desktop(data->client.c,
638 data->client.c->desktop == DESKTOP_ALL ?
639 screen_desktop : DESKTOP_ALL, FALSE);
642 void action_move_relative_horz(union ActionData *data)
644 Client *c = data->relative.c;
646 client_configure(c, Corner_TopLeft,
647 c->area.x + data->relative.delta, c->area.y,
648 c->area.width, c->area.height, TRUE, TRUE);
651 void action_move_relative_vert(union ActionData *data)
653 Client *c = data->relative.c;
655 client_configure(c, Corner_TopLeft,
656 c->area.x, c->area.y + data->relative.delta,
657 c->area.width, c->area.height, TRUE, TRUE);
660 void action_resize_relative_horz(union ActionData *data)
662 Client *c = data->relative.c;
664 client_configure(c, Corner_TopLeft, c->area.x, c->area.y,
666 data->relative.delta * c->size_inc.width,
667 c->area.height, TRUE, TRUE);
670 void action_resize_relative_vert(union ActionData *data)
672 Client *c = data->relative.c;
674 client_configure(c, Corner_TopLeft, c->area.x, c->area.y,
675 c->area.width, c->area.height +
676 data->relative.delta * c->size_inc.height,
680 void action_maximize_full(union ActionData *data)
683 client_maximize(data->client.c, TRUE, 0, TRUE);
686 void action_unmaximize_full(union ActionData *data)
689 client_maximize(data->client.c, FALSE, 0, TRUE);
692 void action_toggle_maximize_full(union ActionData *data)
695 client_maximize(data->client.c,
696 !(data->client.c->max_horz ||
697 data->client.c->max_vert),
701 void action_maximize_horz(union ActionData *data)
704 client_maximize(data->client.c, TRUE, 1, TRUE);
707 void action_unmaximize_horz(union ActionData *data)
710 client_maximize(data->client.c, FALSE, 1, TRUE);
713 void action_toggle_maximize_horz(union ActionData *data)
716 client_maximize(data->client.c, !data->client.c->max_horz, 1, TRUE);
719 void action_maximize_vert(union ActionData *data)
722 client_maximize(data->client.c, TRUE, 2, TRUE);
725 void action_unmaximize_vert(union ActionData *data)
728 client_maximize(data->client.c, FALSE, 2, TRUE);
731 void action_toggle_maximize_vert(union ActionData *data)
734 client_maximize(data->client.c, !data->client.c->max_vert, 2, TRUE);
737 void action_send_to_desktop(union ActionData *data)
739 if (data->sendto.c) {
740 if (data->sendto.desk < screen_num_desktops ||
741 data->sendto.desk == DESKTOP_ALL) {
742 client_set_desktop(data->desktop.c,
743 data->sendto.desk, data->sendto.follow);
744 if (data->sendto.follow) screen_set_desktop(data->sendto.desk);
749 void action_desktop(union ActionData *data)
751 if (data->desktop.desk < screen_num_desktops ||
752 data->desktop.desk == DESKTOP_ALL)
753 screen_set_desktop(data->desktop.desk);
756 static void cur_row_col(guint *r, guint *c)
758 switch (screen_desktop_layout.orientation) {
759 case Orientation_Horz:
760 switch (screen_desktop_layout.start_corner) {
762 *r = screen_desktop / screen_desktop_layout.columns;
763 *c = screen_desktop % screen_desktop_layout.columns;
765 case Corner_BottomLeft:
766 *r = screen_desktop_layout.rows - 1 -
767 screen_desktop / screen_desktop_layout.columns;
768 *c = screen_desktop % screen_desktop_layout.columns;
770 case Corner_TopRight:
771 *r = screen_desktop / screen_desktop_layout.columns;
772 *c = screen_desktop_layout.columns - 1 -
773 screen_desktop % screen_desktop_layout.columns;
775 case Corner_BottomRight:
776 *r = screen_desktop_layout.rows - 1 -
777 screen_desktop / screen_desktop_layout.columns;
778 *c = screen_desktop_layout.columns - 1 -
779 screen_desktop % screen_desktop_layout.columns;
783 case Orientation_Vert:
784 switch (screen_desktop_layout.start_corner) {
786 *r = screen_desktop % screen_desktop_layout.rows;
787 *c = screen_desktop / screen_desktop_layout.rows;
789 case Corner_BottomLeft:
790 *r = screen_desktop_layout.rows - 1 -
791 screen_desktop % screen_desktop_layout.rows;
792 *c = screen_desktop / screen_desktop_layout.rows;
794 case Corner_TopRight:
795 *r = screen_desktop % screen_desktop_layout.rows;
796 *c = screen_desktop_layout.columns - 1 -
797 screen_desktop / screen_desktop_layout.rows;
799 case Corner_BottomRight:
800 *r = screen_desktop_layout.rows - 1 -
801 screen_desktop % screen_desktop_layout.rows;
802 *c = screen_desktop_layout.columns - 1 -
803 screen_desktop / screen_desktop_layout.rows;
810 static guint translate_row_col(guint r, guint c)
812 switch (screen_desktop_layout.orientation) {
813 case Orientation_Horz:
814 switch (screen_desktop_layout.start_corner) {
816 return r % screen_desktop_layout.rows *
817 screen_desktop_layout.columns +
818 c % screen_desktop_layout.columns;
819 case Corner_BottomLeft:
820 return (screen_desktop_layout.rows - 1 -
821 r % screen_desktop_layout.rows) *
822 screen_desktop_layout.columns +
823 c % screen_desktop_layout.columns;
824 case Corner_TopRight:
825 return r % screen_desktop_layout.rows *
826 screen_desktop_layout.columns +
827 (screen_desktop_layout.columns - 1 -
828 c % screen_desktop_layout.columns);
829 case Corner_BottomRight:
830 return (screen_desktop_layout.rows - 1 -
831 r % screen_desktop_layout.rows) *
832 screen_desktop_layout.columns +
833 (screen_desktop_layout.columns - 1 -
834 c % screen_desktop_layout.columns);
836 case Orientation_Vert:
837 switch (screen_desktop_layout.start_corner) {
839 return c % screen_desktop_layout.columns *
840 screen_desktop_layout.rows +
841 r % screen_desktop_layout.rows;
842 case Corner_BottomLeft:
843 return c % screen_desktop_layout.columns *
844 screen_desktop_layout.rows +
845 (screen_desktop_layout.rows - 1 -
846 r % screen_desktop_layout.rows);
847 case Corner_TopRight:
848 return (screen_desktop_layout.columns - 1 -
849 c % screen_desktop_layout.columns) *
850 screen_desktop_layout.rows +
851 r % screen_desktop_layout.rows;
852 case Corner_BottomRight:
853 return (screen_desktop_layout.columns - 1 -
854 c % screen_desktop_layout.columns) *
855 screen_desktop_layout.rows +
856 (screen_desktop_layout.rows - 1 -
857 r % screen_desktop_layout.rows);
860 g_assert_not_reached();
864 void action_desktop_right(union ActionData *data)
870 if (c >= screen_desktop_layout.columns) {
871 if (!data->desktopdir.wrap) return;
874 d = translate_row_col(r, c);
875 if (d >= screen_num_desktops) {
876 if (!data->desktopdir.wrap) return;
879 d = translate_row_col(r, c);
880 if (d < screen_num_desktops)
881 screen_set_desktop(d);
884 void action_send_to_desktop_right(union ActionData *data)
888 if (data->sendtodir.c) {
891 if (c >= screen_desktop_layout.columns) {
892 if (!data->sendtodir.wrap) return;
895 d = translate_row_col(r, c);
896 if (d >= screen_num_desktops) {
897 if (!data->sendtodir.wrap) return;
900 d = translate_row_col(r, c);
901 if (d < screen_num_desktops) {
902 client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
903 if (data->sendtodir.follow) screen_set_desktop(d);
908 void action_desktop_left(union ActionData *data)
914 if (c >= screen_desktop_layout.columns) {
915 if (!data->desktopdir.wrap) return;
916 c = screen_desktop_layout.columns - 1;
918 d = translate_row_col(r, c);
919 if (d >= screen_num_desktops) {
920 if (!data->desktopdir.wrap) return;
923 d = translate_row_col(r, c);
924 if (d < screen_num_desktops)
925 screen_set_desktop(d);
928 void action_send_to_desktop_left(union ActionData *data)
932 if (data->sendtodir.c) {
935 if (c >= screen_desktop_layout.columns) {
936 if (!data->sendtodir.wrap) return;
937 c = screen_desktop_layout.columns - 1;
939 d = translate_row_col(r, c);
940 if (d >= screen_num_desktops) {
941 if (!data->sendtodir.wrap) return;
944 d = translate_row_col(r, c);
945 if (d < screen_num_desktops) {
946 client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
947 if (data->sendtodir.follow) screen_set_desktop(d);
952 void action_desktop_down(union ActionData *data)
958 if (r >= screen_desktop_layout.rows) {
959 if (!data->desktopdir.wrap) return;
962 d = translate_row_col(r, c);
963 if (d >= screen_num_desktops) {
964 if (!data->desktopdir.wrap) return;
967 d = translate_row_col(r, c);
968 if (d < screen_num_desktops)
969 screen_set_desktop(d);
972 void action_send_to_desktop_down(union ActionData *data)
976 if (data->sendtodir.c) {
979 if (r >= screen_desktop_layout.rows) {
980 if (!data->sendtodir.wrap) return;
983 d = translate_row_col(r, c);
984 if (d >= screen_num_desktops) {
985 if (!data->sendtodir.wrap) return;
988 d = translate_row_col(r, c);
989 if (d < screen_num_desktops) {
990 client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
991 if (data->sendtodir.follow) screen_set_desktop(d);
996 void action_desktop_up(union ActionData *data)
1000 cur_row_col(&r, &c);
1002 if (r >= screen_desktop_layout.rows) {
1003 if (!data->desktopdir.wrap) return;
1004 r = screen_desktop_layout.rows - 1;
1006 d = translate_row_col(r, c);
1007 if (d >= screen_num_desktops) {
1008 if (!data->desktopdir.wrap) return;
1011 d = translate_row_col(r, c);
1012 if (d < screen_num_desktops)
1013 screen_set_desktop(d);
1016 void action_send_to_desktop_up(union ActionData *data)
1020 if (data->sendtodir.c) {
1021 cur_row_col(&r, &c);
1023 if (r >= screen_desktop_layout.rows) {
1024 if (!data->sendtodir.wrap) return;
1025 r = screen_desktop_layout.rows - 1;
1027 d = translate_row_col(r, c);
1028 if (d >= screen_num_desktops) {
1029 if (!data->sendtodir.wrap) return;
1032 d = translate_row_col(r, c);
1033 if (d < screen_num_desktops) {
1034 client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
1035 if (data->sendtodir.follow) screen_set_desktop(d);
1040 void action_toggle_decorations(union ActionData *data)
1042 Client *c = data->client.c;;
1046 c->disabled_decorations = c->disabled_decorations ? 0 : ~0;
1047 client_setup_decor_and_functions(c);
1050 void action_moveresize(union ActionData *data)
1052 Client *c = data->moveresize.c;
1054 if (!c || !client_normal(c)) return;
1056 moveresize_start(c, data->moveresize.x, data->moveresize.y,
1057 data->moveresize.button, data->moveresize.corner);
1060 void action_restart(union ActionData *data)
1062 ob_restart_path = data->execute.path;
1063 ob_shutdown = ob_restart = TRUE;
1066 void action_exit(union ActionData *data)
1071 void action_showmenu(union ActionData *data)
1073 if (data->showmenu.name) {
1074 menu_show(data->showmenu.name, data->showmenu.x, data->showmenu.y,
1079 void action_cycle_windows(union ActionData *data)
1083 c = focus_cycle(data->cycle.forward, data->cycle.linear, data->cycle.final,
1084 data->cycle.cancel);
1087 void action_directional_focus(union ActionData *data)
1091 if (!data->diraction.c)
1093 if ((nf = client_find_directional(data->diraction.c,
1094 data->diraction.direction)))
1095 client_activate(nf);
1098 void action_movetoedge(union ActionData *data)
1101 Client *c = data->diraction.c;
1105 x = c->frame->area.x;
1106 y = c->frame->area.y;
1108 h = screen_area(c->desktop)->height;
1109 w = screen_area(c->desktop)->width;
1110 switch(data->diraction.direction) {
1111 case Direction_North:
1114 case Direction_West:
1117 case Direction_South:
1118 y = h - c->frame->area.height;
1120 case Direction_East:
1121 x = w - c->frame->area.width;
1124 frame_frame_gravity(c->frame, &x, &y);
1125 client_configure(c, Corner_TopLeft,
1126 x, y, c->area.width, c->area.height, TRUE, TRUE);
1130 void action_send_to_layer(union ActionData *data)
1133 client_set_layer(data->layer.c, data->layer.layer);
1136 void action_toggle_layer(union ActionData *data)
1138 Client *c = data->layer.c;
1141 if (data->layer.layer < 0)
1142 client_set_layer(c, c->below ? 0 : -1);
1143 else if (data->layer.layer > 0)
1144 client_set_layer(c, c->above ? 0 : 1);