1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 action.c for the Openbox window manager
4 Copyright (c) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
22 #include "moveresize.h"
34 typedef struct ActionString {
36 void (*func)(union ActionData *);
37 void (*setup)(ObAction **, ObUserAction uact);
40 static ObAction *action_new(void (*func)(union ActionData *data),
43 ObAction *a = g_new0(ObAction, 1);
49 void action_free(ObAction *a)
51 if (a == NULL) return;
53 /* deal with pointers */
54 if (a->func == action_execute || a->func == action_restart)
55 g_free(a->data.execute.path);
56 else if (a->func == action_showmenu)
57 g_free(a->data.showmenu.name);
62 void setup_action_directional_focus_north(ObAction **a, ObUserAction uact)
64 (*a)->data.interdiraction.inter.any.interactive = TRUE;
65 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTH;
68 void setup_action_directional_focus_east(ObAction **a, ObUserAction uact)
70 (*a)->data.interdiraction.inter.any.interactive = TRUE;
71 (*a)->data.interdiraction.direction = OB_DIRECTION_EAST;
74 void setup_action_directional_focus_south(ObAction **a, ObUserAction uact)
76 (*a)->data.interdiraction.inter.any.interactive = TRUE;
77 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTH;
80 void setup_action_directional_focus_west(ObAction **a, ObUserAction uact)
82 (*a)->data.interdiraction.inter.any.interactive = TRUE;
83 (*a)->data.interdiraction.direction = OB_DIRECTION_WEST;
86 void setup_action_directional_focus_northeast(ObAction **a, ObUserAction uact)
88 (*a)->data.interdiraction.inter.any.interactive = TRUE;
89 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHEAST;
92 void setup_action_directional_focus_southeast(ObAction **a, ObUserAction uact)
94 (*a)->data.interdiraction.inter.any.interactive = TRUE;
95 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHEAST;
98 void setup_action_directional_focus_southwest(ObAction **a, ObUserAction uact)
100 (*a)->data.interdiraction.inter.any.interactive = TRUE;
101 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHWEST;
104 void setup_action_directional_focus_northwest(ObAction **a, ObUserAction uact)
106 (*a)->data.interdiraction.inter.any.interactive = TRUE;
107 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHWEST;
110 void setup_action_send_to_desktop(ObAction **a, ObUserAction uact)
112 (*a)->data.sendto.follow = TRUE;
115 void setup_action_send_to_desktop_prev(ObAction **a, ObUserAction uact)
117 (*a)->data.sendtodir.inter.any.interactive = TRUE;
118 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
119 (*a)->data.sendtodir.linear = TRUE;
120 (*a)->data.sendtodir.wrap = TRUE;
121 (*a)->data.sendtodir.follow = TRUE;
124 void setup_action_send_to_desktop_next(ObAction **a, ObUserAction uact)
126 (*a)->data.sendtodir.inter.any.interactive = TRUE;
127 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
128 (*a)->data.sendtodir.linear = TRUE;
129 (*a)->data.sendtodir.wrap = TRUE;
130 (*a)->data.sendtodir.follow = TRUE;
133 void setup_action_send_to_desktop_left(ObAction **a, ObUserAction uact)
135 (*a)->data.sendtodir.inter.any.interactive = TRUE;
136 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
137 (*a)->data.sendtodir.linear = FALSE;
138 (*a)->data.sendtodir.wrap = TRUE;
139 (*a)->data.sendtodir.follow = TRUE;
142 void setup_action_send_to_desktop_right(ObAction **a, ObUserAction uact)
144 (*a)->data.sendtodir.inter.any.interactive = TRUE;
145 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
146 (*a)->data.sendtodir.linear = FALSE;
147 (*a)->data.sendtodir.wrap = TRUE;
148 (*a)->data.sendtodir.follow = TRUE;
151 void setup_action_send_to_desktop_up(ObAction **a, ObUserAction uact)
153 (*a)->data.sendtodir.inter.any.interactive = TRUE;
154 (*a)->data.sendtodir.dir = OB_DIRECTION_NORTH;
155 (*a)->data.sendtodir.linear = FALSE;
156 (*a)->data.sendtodir.wrap = TRUE;
157 (*a)->data.sendtodir.follow = TRUE;
160 void setup_action_send_to_desktop_down(ObAction **a, ObUserAction uact)
162 (*a)->data.sendtodir.inter.any.interactive = TRUE;
163 (*a)->data.sendtodir.dir = OB_DIRECTION_SOUTH;
164 (*a)->data.sendtodir.linear = FALSE;
165 (*a)->data.sendtodir.wrap = TRUE;
166 (*a)->data.sendtodir.follow = TRUE;
169 void setup_action_desktop_prev(ObAction **a, ObUserAction uact)
171 (*a)->data.desktopdir.inter.any.interactive = TRUE;
172 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
173 (*a)->data.desktopdir.linear = TRUE;
174 (*a)->data.desktopdir.wrap = TRUE;
177 void setup_action_desktop_next(ObAction **a, ObUserAction uact)
179 (*a)->data.desktopdir.inter.any.interactive = TRUE;
180 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
181 (*a)->data.desktopdir.linear = TRUE;
182 (*a)->data.desktopdir.wrap = TRUE;
185 void setup_action_desktop_left(ObAction **a, ObUserAction uact)
187 (*a)->data.desktopdir.inter.any.interactive = TRUE;
188 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
189 (*a)->data.desktopdir.linear = FALSE;
190 (*a)->data.desktopdir.wrap = TRUE;
193 void setup_action_desktop_right(ObAction **a, ObUserAction uact)
195 (*a)->data.desktopdir.inter.any.interactive = TRUE;
196 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
197 (*a)->data.desktopdir.linear = FALSE;
198 (*a)->data.desktopdir.wrap = TRUE;
201 void setup_action_desktop_up(ObAction **a, ObUserAction uact)
203 (*a)->data.desktopdir.inter.any.interactive = TRUE;
204 (*a)->data.desktopdir.dir = OB_DIRECTION_NORTH;
205 (*a)->data.desktopdir.linear = FALSE;
206 (*a)->data.desktopdir.wrap = TRUE;
209 void setup_action_desktop_down(ObAction **a, ObUserAction uact)
211 (*a)->data.desktopdir.inter.any.interactive = TRUE;
212 (*a)->data.desktopdir.dir = OB_DIRECTION_SOUTH;
213 (*a)->data.desktopdir.linear = FALSE;
214 (*a)->data.desktopdir.wrap = TRUE;
217 void setup_action_cycle_windows_next(ObAction **a, ObUserAction uact)
219 (*a)->data.cycle.inter.any.interactive = TRUE;
220 (*a)->data.cycle.linear = FALSE;
221 (*a)->data.cycle.forward = TRUE;
224 void setup_action_cycle_windows_previous(ObAction **a, ObUserAction uact)
226 (*a)->data.cycle.inter.any.interactive = TRUE;
227 (*a)->data.cycle.linear = FALSE;
228 (*a)->data.cycle.forward = FALSE;
231 void setup_action_movetoedge_north(ObAction **a, ObUserAction uact)
233 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
236 void setup_action_movetoedge_south(ObAction **a, ObUserAction uact)
238 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
241 void setup_action_movetoedge_east(ObAction **a, ObUserAction uact)
243 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
246 void setup_action_movetoedge_west(ObAction **a, ObUserAction uact)
248 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
251 void setup_action_growtoedge_north(ObAction **a, ObUserAction uact)
253 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
256 void setup_action_growtoedge_south(ObAction **a, ObUserAction uact)
258 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
261 void setup_action_growtoedge_east(ObAction **a, ObUserAction uact)
263 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
266 void setup_action_growtoedge_west(ObAction **a, ObUserAction uact)
268 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
271 void setup_action_top_layer(ObAction **a, ObUserAction uact)
273 (*a)->data.layer.layer = 1;
276 void setup_action_normal_layer(ObAction **a, ObUserAction uact)
278 (*a)->data.layer.layer = 0;
281 void setup_action_bottom_layer(ObAction **a, ObUserAction uact)
283 (*a)->data.layer.layer = -1;
286 void setup_action_move(ObAction **a, ObUserAction uact)
288 (*a)->data.moveresize.move = TRUE;
289 (*a)->data.moveresize.keyboard =
290 (uact == OB_USER_ACTION_KEYBOARD_KEY ||
291 uact == OB_USER_ACTION_MENU_SELECTION);
294 void setup_action_resize(ObAction **a, ObUserAction uact)
296 (*a)->data.moveresize.move = FALSE;
297 (*a)->data.moveresize.keyboard =
298 (uact == OB_USER_ACTION_KEYBOARD_KEY ||
299 uact == OB_USER_ACTION_MENU_SELECTION);
302 void setup_action_showmenu(ObAction **a, ObUserAction uact)
304 /* you cannot call ShowMenu from inside a menu, cuz the menu code makes
305 assumptions that there is only one menu (and submenus) open at
307 if (uact == OB_USER_ACTION_MENU_SELECTION) {
313 ActionString actionstrings[] =
321 "directionalfocusnorth",
322 action_directional_focus,
323 setup_action_directional_focus_north
326 "directionalfocuseast",
327 action_directional_focus,
328 setup_action_directional_focus_east
331 "directionalfocussouth",
332 action_directional_focus,
333 setup_action_directional_focus_south
336 "directionalfocuswest",
337 action_directional_focus,
338 setup_action_directional_focus_west
341 "directionalfocusnortheast",
342 action_directional_focus,
343 setup_action_directional_focus_northeast
346 "directionalfocussoutheast",
347 action_directional_focus,
348 setup_action_directional_focus_southeast
351 "directionalfocussouthwest",
352 action_directional_focus,
353 setup_action_directional_focus_southwest
356 "directionalfocusnorthwest",
357 action_directional_focus,
358 setup_action_directional_focus_northwest
432 action_toggle_omnipresent,
437 action_move_relative_horz,
442 action_move_relative_vert,
446 "resizerelativehorz",
447 action_resize_relative_horz,
451 "resizerelativevert",
452 action_resize_relative_vert,
457 action_maximize_full,
462 action_unmaximize_full,
466 "togglemaximizefull",
467 action_toggle_maximize_full,
472 action_maximize_horz,
477 action_unmaximize_horz,
481 "togglemaximizehorz",
482 action_toggle_maximize_horz,
487 action_maximize_vert,
492 action_unmaximize_vert,
496 "togglemaximizevert",
497 action_toggle_maximize_vert,
502 action_send_to_desktop,
503 setup_action_send_to_desktop
507 action_send_to_desktop_dir,
508 setup_action_send_to_desktop_next
511 "sendtodesktopprevious",
512 action_send_to_desktop_dir,
513 setup_action_send_to_desktop_prev
516 "sendtodesktopright",
517 action_send_to_desktop_dir,
518 setup_action_send_to_desktop_right
522 action_send_to_desktop_dir,
523 setup_action_send_to_desktop_left
527 action_send_to_desktop_dir,
528 setup_action_send_to_desktop_up
532 action_send_to_desktop_dir,
533 setup_action_send_to_desktop_down
543 setup_action_desktop_next
548 setup_action_desktop_prev
553 setup_action_desktop_right
558 setup_action_desktop_left
563 setup_action_desktop_up
568 setup_action_desktop_down
572 action_toggle_decorations,
587 action_toggle_show_desktop,
597 action_unshow_desktop,
623 setup_action_showmenu
627 action_send_to_layer,
628 setup_action_top_layer
633 setup_action_top_layer
637 action_send_to_layer,
638 setup_action_normal_layer
642 action_send_to_layer,
643 setup_action_bottom_layer
646 "togglealwaysonbottom",
648 setup_action_bottom_layer
652 action_cycle_windows,
653 setup_action_cycle_windows_next
657 action_cycle_windows,
658 setup_action_cycle_windows_previous
663 setup_action_movetoedge_north
668 setup_action_movetoedge_south
673 setup_action_movetoedge_west
678 setup_action_movetoedge_east
683 setup_action_growtoedge_north
688 setup_action_growtoedge_south
693 setup_action_growtoedge_west
698 setup_action_growtoedge_east
707 ObAction *action_from_string(const gchar *name, ObUserAction uact)
710 gboolean exist = FALSE;
713 for (i = 0; actionstrings[i].name; i++)
714 if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
716 a = action_new(actionstrings[i].func, uact);
717 if (actionstrings[i].setup)
718 actionstrings[i].setup(&a, uact);
719 /* only key bindings can be interactive. thus saith the xor. */
720 if (uact != OB_USER_ACTION_KEYBOARD_KEY)
721 a->data.any.interactive = FALSE;
725 g_warning("Invalid action '%s' requested. No such action exists.",
728 g_warning("Invalid use of action '%s'. Action will be ignored.", name);
732 ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
736 ObAction *act = NULL;
739 if (parse_attr_string("name", node, &actname)) {
740 if ((act = action_from_string(actname, uact))) {
741 if (act->func == action_execute || act->func == action_restart) {
742 if ((n = parse_find_node("execute", node->xmlChildrenNode))) {
743 gchar *s = parse_string(doc, n);
744 act->data.execute.path = parse_expand_tilde(s);
747 } else if (act->func == action_showmenu) {
748 if ((n = parse_find_node("menu", node->xmlChildrenNode)))
749 act->data.showmenu.name = parse_string(doc, n);
750 } else if (act->func == action_move_relative_horz ||
751 act->func == action_move_relative_vert ||
752 act->func == action_resize_relative_horz ||
753 act->func == action_resize_relative_vert) {
754 if ((n = parse_find_node("delta", node->xmlChildrenNode)))
755 act->data.relative.delta = parse_int(doc, n);
756 } else if (act->func == action_desktop) {
757 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
758 act->data.desktop.desk = parse_int(doc, n);
759 if (act->data.desktop.desk > 0) act->data.desktop.desk--;
760 } else if (act->func == action_send_to_desktop) {
761 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
762 act->data.sendto.desk = parse_int(doc, n);
763 if (act->data.sendto.desk > 0) act->data.sendto.desk--;
764 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
765 act->data.sendto.follow = parse_bool(doc, n);
766 } else if (act->func == action_desktop_dir) {
767 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
768 act->data.desktopdir.wrap = parse_bool(doc, n);
769 } else if (act->func == action_send_to_desktop_dir) {
770 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
771 act->data.sendtodir.wrap = parse_bool(doc, n);
772 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
773 act->data.sendtodir.follow = parse_bool(doc, n);
774 } else if (act->func == action_activate) {
775 if ((n = parse_find_node("here", node->xmlChildrenNode)))
776 act->data.activate.here = parse_bool(doc, n);
777 } else if (act->func == action_cycle_windows) {
778 if ((n = parse_find_node("linear", node->xmlChildrenNode)))
779 act->data.cycle.linear = parse_bool(doc, n);
787 void action_run_full(ObAction *a, struct _ObClient *c,
788 guint state, guint button, gint x, gint y,
789 gboolean cancel, gboolean done)
792 screen_pointer_pos(&x, &y);
798 a->data.any.button = button;
800 if (a->data.any.interactive) {
801 a->data.inter.cancel = cancel;
802 a->data.inter.final = done;
803 if (!(cancel || done))
804 keyboard_interactive_grab(state, c, a);
810 void action_execute(union ActionData *data)
814 if (data->execute.path) {
815 cmd = g_filename_from_utf8(data->execute.path, -1, NULL, NULL, NULL);
817 if (!g_spawn_command_line_async(cmd, &e)) {
818 g_warning("failed to execute '%s': %s",
823 g_warning("failed to convert '%s' from utf8", data->execute.path);
828 void action_activate(union ActionData *data)
830 if (data->activate.any.c)
831 client_activate(data->activate.any.c, data->activate.here);
834 void action_focus(union ActionData *data)
836 if (data->client.any.c)
837 client_focus(data->client.any.c);
840 void action_unfocus (union ActionData *data)
842 if (data->client.any.c)
843 client_unfocus(data->client.any.c);
846 void action_iconify(union ActionData *data)
848 if (data->client.any.c)
849 client_iconify(data->client.any.c, TRUE, TRUE);
852 void action_raiselower(union ActionData *data)
854 ObClient *c = data->client.any.c;
856 gboolean raise = FALSE;
860 for (it = stacking_list; it; it = g_list_next(it)) {
861 ObClient *cit = it->data;
864 if (client_normal(cit) == client_normal(c) &&
865 cit->layer == c->layer &&
868 if (RECT_INTERSECTS_RECT(cit->frame->area, c->frame->area)) {
876 stacking_raise(CLIENT_AS_WINDOW(c));
878 stacking_lower(CLIENT_AS_WINDOW(c));
881 void action_raise(union ActionData *data)
883 if (data->client.any.c)
884 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
887 void action_unshaderaise(union ActionData *data)
889 if (data->client.any.c) {
890 if (data->client.any.c->shaded) {
891 grab_pointer(TRUE, OB_CURSOR_NONE);
892 client_shade(data->client.any.c, FALSE);
893 grab_pointer(FALSE, OB_CURSOR_NONE);
895 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
899 void action_shadelower(union ActionData *data)
901 if (data->client.any.c) {
902 if (data->client.any.c->shaded)
903 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
905 grab_pointer(TRUE, OB_CURSOR_NONE);
906 client_shade(data->client.any.c, TRUE);
907 grab_pointer(FALSE, OB_CURSOR_NONE);
912 void action_lower(union ActionData *data)
914 if (data->client.any.c)
915 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
918 void action_close(union ActionData *data)
920 if (data->client.any.c)
921 client_close(data->client.any.c);
924 void action_kill(union ActionData *data)
926 if (data->client.any.c)
927 client_kill(data->client.any.c);
930 void action_shade(union ActionData *data)
932 if (data->client.any.c) {
933 grab_pointer(TRUE, OB_CURSOR_NONE);
934 client_shade(data->client.any.c, TRUE);
935 grab_pointer(FALSE, OB_CURSOR_NONE);
939 void action_unshade(union ActionData *data)
941 if (data->client.any.c) {
942 grab_pointer(TRUE, OB_CURSOR_NONE);
943 client_shade(data->client.any.c, FALSE);
944 grab_pointer(FALSE, OB_CURSOR_NONE);
948 void action_toggle_shade(union ActionData *data)
950 if (data->client.any.c) {
951 grab_pointer(TRUE, OB_CURSOR_NONE);
952 client_shade(data->client.any.c, !data->client.any.c->shaded);
953 grab_pointer(FALSE, OB_CURSOR_NONE);
957 void action_toggle_omnipresent(union ActionData *data)
959 if (data->client.any.c)
960 client_set_desktop(data->client.any.c,
961 data->client.any.c->desktop == DESKTOP_ALL ?
962 screen_desktop : DESKTOP_ALL, FALSE);
965 void action_move_relative_horz(union ActionData *data)
967 ObClient *c = data->relative.any.c;
969 grab_pointer(TRUE, OB_CURSOR_NONE);
970 client_move(c, c->area.x + data->relative.delta, c->area.y);
971 grab_pointer(FALSE, OB_CURSOR_NONE);
975 void action_move_relative_vert(union ActionData *data)
977 ObClient *c = data->relative.any.c;
979 grab_pointer(TRUE, OB_CURSOR_NONE);
980 client_move(c, c->area.x, c->area.y + data->relative.delta);
981 grab_pointer(FALSE, OB_CURSOR_NONE);
985 void action_resize_relative_horz(union ActionData *data)
987 ObClient *c = data->relative.any.c;
989 grab_pointer(TRUE, OB_CURSOR_NONE);
991 c->area.width + data->relative.delta * c->size_inc.width,
993 grab_pointer(FALSE, OB_CURSOR_NONE);
997 void action_resize_relative_vert(union ActionData *data)
999 ObClient *c = data->relative.any.c;
1000 if (c && !c->shaded) {
1001 grab_pointer(TRUE, OB_CURSOR_NONE);
1002 client_resize(c, c->area.width, c->area.height +
1003 data->relative.delta * c->size_inc.height);
1004 grab_pointer(FALSE, OB_CURSOR_NONE);
1008 void action_maximize_full(union ActionData *data)
1010 if (data->client.any.c)
1011 client_maximize(data->client.any.c, TRUE, 0, TRUE);
1014 void action_unmaximize_full(union ActionData *data)
1016 if (data->client.any.c)
1017 client_maximize(data->client.any.c, FALSE, 0, TRUE);
1020 void action_toggle_maximize_full(union ActionData *data)
1022 if (data->client.any.c)
1023 client_maximize(data->client.any.c,
1024 !(data->client.any.c->max_horz ||
1025 data->client.any.c->max_vert),
1029 void action_maximize_horz(union ActionData *data)
1031 if (data->client.any.c)
1032 client_maximize(data->client.any.c, TRUE, 1, TRUE);
1035 void action_unmaximize_horz(union ActionData *data)
1037 if (data->client.any.c)
1038 client_maximize(data->client.any.c, FALSE, 1, TRUE);
1041 void action_toggle_maximize_horz(union ActionData *data)
1043 if (data->client.any.c)
1044 client_maximize(data->client.any.c,
1045 !data->client.any.c->max_horz, 1, TRUE);
1048 void action_maximize_vert(union ActionData *data)
1050 if (data->client.any.c)
1051 client_maximize(data->client.any.c, TRUE, 2, TRUE);
1054 void action_unmaximize_vert(union ActionData *data)
1056 if (data->client.any.c)
1057 client_maximize(data->client.any.c, FALSE, 2, TRUE);
1060 void action_toggle_maximize_vert(union ActionData *data)
1062 if (data->client.any.c)
1063 client_maximize(data->client.any.c, !data->client.any.c->max_vert, 2, TRUE);
1066 void action_send_to_desktop(union ActionData *data)
1068 ObClient *c = data->sendto.any.c;
1070 if (!c || !client_normal(c)) return;
1072 if (data->sendto.desk < screen_num_desktops ||
1073 data->sendto.desk == DESKTOP_ALL) {
1074 client_set_desktop(c, data->sendto.desk, data->sendto.follow);
1075 if (data->sendto.follow)
1076 screen_set_desktop(data->sendto.desk);
1080 void action_desktop(union ActionData *data)
1082 if (data->desktop.desk < screen_num_desktops ||
1083 data->desktop.desk == DESKTOP_ALL)
1084 screen_set_desktop(data->desktop.desk);
1087 void action_desktop_dir(union ActionData *data)
1091 d = screen_cycle_desktop(data->desktopdir.dir,
1092 data->desktopdir.wrap,
1093 data->sendtodir.linear,
1094 data->desktopdir.inter.any.interactive,
1095 data->desktopdir.inter.final,
1096 data->desktopdir.inter.cancel);
1097 screen_set_desktop(d);
1100 void action_send_to_desktop_dir(union ActionData *data)
1102 ObClient *c = data->sendtodir.inter.any.c;
1105 if (!c || !client_normal(c)) return;
1107 d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
1108 data->sendtodir.linear,
1109 data->sendtodir.inter.any.interactive,
1110 data->sendtodir.inter.final,
1111 data->sendtodir.inter.cancel);
1112 client_set_desktop(c, d, data->sendtodir.follow);
1113 if (data->sendtodir.follow)
1114 screen_set_desktop(d);
1117 void action_desktop_last(union ActionData *data)
1119 screen_set_desktop(screen_last_desktop);
1122 void action_toggle_decorations(union ActionData *data)
1124 ObClient *c = data->client.any.c;
1128 c->decorate = !c->decorate;
1129 client_setup_decor_and_functions(c);
1132 static guint32 pick_corner(int x, int y, int cx, int cy, int cw, int ch)
1134 if (x - cx > cw / 2) {
1135 if (y - cy > ch / 2)
1136 return prop_atoms.net_wm_moveresize_size_bottomright;
1138 return prop_atoms.net_wm_moveresize_size_topright;
1140 if (y - cy > ch / 2)
1141 return prop_atoms.net_wm_moveresize_size_bottomleft;
1143 return prop_atoms.net_wm_moveresize_size_topleft;
1147 void action_moveresize(union ActionData *data)
1149 ObClient *c = data->moveresize.any.c;
1152 if (!c || !client_normal(c)) return;
1154 if (data->moveresize.keyboard) {
1155 corner = (data->moveresize.move ?
1156 prop_atoms.net_wm_moveresize_move_keyboard :
1157 prop_atoms.net_wm_moveresize_size_keyboard);
1159 corner = (data->moveresize.move ?
1160 prop_atoms.net_wm_moveresize_move :
1161 pick_corner(data->any.x, data->any.y,
1162 c->frame->area.x, c->frame->area.y,
1163 /* use the client size because the frame
1164 can be differently sized (shaded
1165 windows) and we want this based on the
1167 c->area.width + c->frame->size.left +
1168 c->frame->size.right,
1169 c->area.height + c->frame->size.top +
1170 c->frame->size.bottom));
1173 moveresize_start(c, data->any.x, data->any.y, data->any.button, corner);
1176 void action_reconfigure(union ActionData *data)
1181 void action_restart(union ActionData *data)
1183 ob_restart_other(data->execute.path);
1186 void action_exit(union ActionData *data)
1191 void action_showmenu(union ActionData *data)
1193 if (data->showmenu.name) {
1194 menu_show(data->showmenu.name, data->any.x, data->any.y,
1195 data->showmenu.any.c);
1199 void action_cycle_windows(union ActionData *data)
1201 focus_cycle(data->cycle.forward, data->cycle.linear,
1202 data->cycle.inter.any.interactive,
1203 data->cycle.inter.final, data->cycle.inter.cancel);
1206 void action_directional_focus(union ActionData *data)
1208 focus_directional_cycle(data->interdiraction.direction,
1209 data->interdiraction.inter.any.interactive,
1210 data->interdiraction.inter.final,
1211 data->interdiraction.inter.cancel);
1214 void action_movetoedge(union ActionData *data)
1217 ObClient *c = data->diraction.any.c;
1221 x = c->frame->area.x;
1222 y = c->frame->area.y;
1224 switch(data->diraction.direction) {
1225 case OB_DIRECTION_NORTH:
1226 y = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1228 case OB_DIRECTION_WEST:
1229 x = client_directional_edge_search(c, OB_DIRECTION_WEST);
1231 case OB_DIRECTION_SOUTH:
1232 y = client_directional_edge_search(c, OB_DIRECTION_SOUTH) -
1233 c->frame->area.height;
1235 case OB_DIRECTION_EAST:
1236 x = client_directional_edge_search(c, OB_DIRECTION_EAST) -
1237 c->frame->area.width;
1240 g_assert_not_reached();
1242 frame_frame_gravity(c->frame, &x, &y);
1243 grab_pointer(TRUE, OB_CURSOR_NONE);
1244 client_move(c, x, y);
1245 grab_pointer(FALSE, OB_CURSOR_NONE);
1249 void action_growtoedge(union ActionData *data)
1251 int x, y, width, height, dest;
1252 ObClient *c = data->diraction.any.c;
1258 a = screen_area(c->desktop);
1259 x = c->frame->area.x;
1260 y = c->frame->area.y;
1261 width = c->frame->area.width;
1262 height = c->frame->area.height;
1264 switch(data->diraction.direction) {
1265 case OB_DIRECTION_NORTH:
1266 dest = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1268 height = c->frame->area.height / 2;
1270 height = c->frame->area.y + c->frame->area.height - dest;
1274 case OB_DIRECTION_WEST:
1275 dest = client_directional_edge_search(c, OB_DIRECTION_WEST);
1277 width = c->frame->area.width / 2;
1279 width = c->frame->area.x + c->frame->area.width - dest;
1283 case OB_DIRECTION_SOUTH:
1284 dest = client_directional_edge_search(c, OB_DIRECTION_SOUTH);
1285 if (a->y + a->height == y + c->frame->area.height) {
1286 height = c->frame->area.height / 2;
1287 y = a->y + a->height - height;
1289 height = dest - c->frame->area.y;
1290 y += (height - c->frame->area.height) % c->size_inc.height;
1291 height -= (height - c->frame->area.height) % c->size_inc.height;
1293 case OB_DIRECTION_EAST:
1294 dest = client_directional_edge_search(c, OB_DIRECTION_EAST);
1295 if (a->x + a->width == x + c->frame->area.width) {
1296 width = c->frame->area.width / 2;
1297 x = a->x + a->width - width;
1299 width = dest - c->frame->area.x;
1300 x += (width - c->frame->area.width) % c->size_inc.width;
1301 width -= (width - c->frame->area.width) % c->size_inc.width;
1304 g_assert_not_reached();
1306 frame_frame_gravity(c->frame, &x, &y);
1307 width -= c->frame->size.left + c->frame->size.right;
1308 height -= c->frame->size.top + c->frame->size.bottom;
1309 grab_pointer(TRUE, OB_CURSOR_NONE);
1310 client_move_resize(c, x, y, width, height);
1311 grab_pointer(FALSE, OB_CURSOR_NONE);
1314 void action_send_to_layer(union ActionData *data)
1316 if (data->layer.any.c)
1317 client_set_layer(data->layer.any.c, data->layer.layer);
1320 void action_toggle_layer(union ActionData *data)
1322 ObClient *c = data->layer.any.c;
1325 if (data->layer.layer < 0)
1326 client_set_layer(c, c->below ? 0 : -1);
1327 else if (data->layer.layer > 0)
1328 client_set_layer(c, c->above ? 0 : 1);
1332 void action_toggle_show_desktop(union ActionData *data)
1334 screen_show_desktop(!screen_showing_desktop);
1337 void action_show_desktop(union ActionData *data)
1339 screen_show_desktop(TRUE);
1342 void action_unshow_desktop(union ActionData *data)
1344 screen_show_desktop(FALSE);