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"
35 typedef struct ActionString {
37 void (*func)(union ActionData *);
38 void (*setup)(ObAction **, ObUserAction uact);
41 static ObAction *action_new(void (*func)(union ActionData *data),
44 ObAction *a = g_new0(ObAction, 1);
50 void action_free(ObAction *a)
52 if (a == NULL) return;
54 /* deal with pointers */
55 if (a->func == action_execute || a->func == action_restart)
56 g_free(a->data.execute.path);
57 else if (a->func == action_showmenu)
58 g_free(a->data.showmenu.name);
63 void setup_action_directional_focus_north(ObAction **a, ObUserAction uact)
65 (*a)->data.interdiraction.inter.any.interactive = TRUE;
66 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTH;
69 void setup_action_directional_focus_east(ObAction **a, ObUserAction uact)
71 (*a)->data.interdiraction.inter.any.interactive = TRUE;
72 (*a)->data.interdiraction.direction = OB_DIRECTION_EAST;
75 void setup_action_directional_focus_south(ObAction **a, ObUserAction uact)
77 (*a)->data.interdiraction.inter.any.interactive = TRUE;
78 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTH;
81 void setup_action_directional_focus_west(ObAction **a, ObUserAction uact)
83 (*a)->data.interdiraction.inter.any.interactive = TRUE;
84 (*a)->data.interdiraction.direction = OB_DIRECTION_WEST;
87 void setup_action_directional_focus_northeast(ObAction **a, ObUserAction uact)
89 (*a)->data.interdiraction.inter.any.interactive = TRUE;
90 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHEAST;
93 void setup_action_directional_focus_southeast(ObAction **a, ObUserAction uact)
95 (*a)->data.interdiraction.inter.any.interactive = TRUE;
96 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHEAST;
99 void setup_action_directional_focus_southwest(ObAction **a, ObUserAction uact)
101 (*a)->data.interdiraction.inter.any.interactive = TRUE;
102 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHWEST;
105 void setup_action_directional_focus_northwest(ObAction **a, ObUserAction uact)
107 (*a)->data.interdiraction.inter.any.interactive = TRUE;
108 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHWEST;
111 void setup_action_send_to_desktop(ObAction **a, ObUserAction uact)
113 (*a)->data.sendto.follow = TRUE;
116 void setup_action_send_to_desktop_prev(ObAction **a, ObUserAction uact)
118 (*a)->data.sendtodir.inter.any.interactive = TRUE;
119 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
120 (*a)->data.sendtodir.linear = TRUE;
121 (*a)->data.sendtodir.wrap = TRUE;
122 (*a)->data.sendtodir.follow = TRUE;
125 void setup_action_send_to_desktop_next(ObAction **a, ObUserAction uact)
127 (*a)->data.sendtodir.inter.any.interactive = TRUE;
128 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
129 (*a)->data.sendtodir.linear = TRUE;
130 (*a)->data.sendtodir.wrap = TRUE;
131 (*a)->data.sendtodir.follow = TRUE;
134 void setup_action_send_to_desktop_left(ObAction **a, ObUserAction uact)
136 (*a)->data.sendtodir.inter.any.interactive = TRUE;
137 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
138 (*a)->data.sendtodir.linear = FALSE;
139 (*a)->data.sendtodir.wrap = TRUE;
140 (*a)->data.sendtodir.follow = TRUE;
143 void setup_action_send_to_desktop_right(ObAction **a, ObUserAction uact)
145 (*a)->data.sendtodir.inter.any.interactive = TRUE;
146 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
147 (*a)->data.sendtodir.linear = FALSE;
148 (*a)->data.sendtodir.wrap = TRUE;
149 (*a)->data.sendtodir.follow = TRUE;
152 void setup_action_send_to_desktop_up(ObAction **a, ObUserAction uact)
154 (*a)->data.sendtodir.inter.any.interactive = TRUE;
155 (*a)->data.sendtodir.dir = OB_DIRECTION_NORTH;
156 (*a)->data.sendtodir.linear = FALSE;
157 (*a)->data.sendtodir.wrap = TRUE;
158 (*a)->data.sendtodir.follow = TRUE;
161 void setup_action_send_to_desktop_down(ObAction **a, ObUserAction uact)
163 (*a)->data.sendtodir.inter.any.interactive = TRUE;
164 (*a)->data.sendtodir.dir = OB_DIRECTION_SOUTH;
165 (*a)->data.sendtodir.linear = FALSE;
166 (*a)->data.sendtodir.wrap = TRUE;
167 (*a)->data.sendtodir.follow = TRUE;
170 void setup_action_desktop_prev(ObAction **a, ObUserAction uact)
172 (*a)->data.desktopdir.inter.any.interactive = TRUE;
173 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
174 (*a)->data.desktopdir.linear = TRUE;
175 (*a)->data.desktopdir.wrap = TRUE;
178 void setup_action_desktop_next(ObAction **a, ObUserAction uact)
180 (*a)->data.desktopdir.inter.any.interactive = TRUE;
181 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
182 (*a)->data.desktopdir.linear = TRUE;
183 (*a)->data.desktopdir.wrap = TRUE;
186 void setup_action_desktop_left(ObAction **a, ObUserAction uact)
188 (*a)->data.desktopdir.inter.any.interactive = TRUE;
189 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
190 (*a)->data.desktopdir.linear = FALSE;
191 (*a)->data.desktopdir.wrap = TRUE;
194 void setup_action_desktop_right(ObAction **a, ObUserAction uact)
196 (*a)->data.desktopdir.inter.any.interactive = TRUE;
197 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
198 (*a)->data.desktopdir.linear = FALSE;
199 (*a)->data.desktopdir.wrap = TRUE;
202 void setup_action_desktop_up(ObAction **a, ObUserAction uact)
204 (*a)->data.desktopdir.inter.any.interactive = TRUE;
205 (*a)->data.desktopdir.dir = OB_DIRECTION_NORTH;
206 (*a)->data.desktopdir.linear = FALSE;
207 (*a)->data.desktopdir.wrap = TRUE;
210 void setup_action_desktop_down(ObAction **a, ObUserAction uact)
212 (*a)->data.desktopdir.inter.any.interactive = TRUE;
213 (*a)->data.desktopdir.dir = OB_DIRECTION_SOUTH;
214 (*a)->data.desktopdir.linear = FALSE;
215 (*a)->data.desktopdir.wrap = TRUE;
218 void setup_action_cycle_windows_next(ObAction **a, ObUserAction uact)
220 (*a)->data.cycle.inter.any.interactive = TRUE;
221 (*a)->data.cycle.linear = FALSE;
222 (*a)->data.cycle.forward = TRUE;
225 void setup_action_cycle_windows_previous(ObAction **a, ObUserAction uact)
227 (*a)->data.cycle.inter.any.interactive = TRUE;
228 (*a)->data.cycle.linear = FALSE;
229 (*a)->data.cycle.forward = FALSE;
232 void setup_action_movetoedge_north(ObAction **a, ObUserAction uact)
234 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
237 void setup_action_movetoedge_south(ObAction **a, ObUserAction uact)
239 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
242 void setup_action_movetoedge_east(ObAction **a, ObUserAction uact)
244 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
247 void setup_action_movetoedge_west(ObAction **a, ObUserAction uact)
249 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
252 void setup_action_growtoedge_north(ObAction **a, ObUserAction uact)
254 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
257 void setup_action_growtoedge_south(ObAction **a, ObUserAction uact)
259 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
262 void setup_action_growtoedge_east(ObAction **a, ObUserAction uact)
264 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
267 void setup_action_growtoedge_west(ObAction **a, ObUserAction uact)
269 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
272 void setup_action_top_layer(ObAction **a, ObUserAction uact)
274 (*a)->data.layer.layer = 1;
277 void setup_action_normal_layer(ObAction **a, ObUserAction uact)
279 (*a)->data.layer.layer = 0;
282 void setup_action_bottom_layer(ObAction **a, ObUserAction uact)
284 (*a)->data.layer.layer = -1;
287 void setup_action_move(ObAction **a, ObUserAction uact)
289 (*a)->data.moveresize.move = TRUE;
290 (*a)->data.moveresize.keyboard =
291 (uact == OB_USER_ACTION_KEYBOARD_KEY ||
292 uact == OB_USER_ACTION_MENU_SELECTION);
295 void setup_action_resize(ObAction **a, ObUserAction uact)
297 (*a)->data.moveresize.move = FALSE;
298 (*a)->data.moveresize.keyboard =
299 (uact == OB_USER_ACTION_KEYBOARD_KEY ||
300 uact == OB_USER_ACTION_MENU_SELECTION);
303 void setup_action_showmenu(ObAction **a, ObUserAction uact)
305 /* you cannot call ShowMenu from inside a menu, cuz the menu code makes
306 assumptions that there is only one menu (and submenus) open at
308 if (uact == OB_USER_ACTION_MENU_SELECTION) {
314 ActionString actionstrings[] =
322 "directionalfocusnorth",
323 action_directional_focus,
324 setup_action_directional_focus_north
327 "directionalfocuseast",
328 action_directional_focus,
329 setup_action_directional_focus_east
332 "directionalfocussouth",
333 action_directional_focus,
334 setup_action_directional_focus_south
337 "directionalfocuswest",
338 action_directional_focus,
339 setup_action_directional_focus_west
342 "directionalfocusnortheast",
343 action_directional_focus,
344 setup_action_directional_focus_northeast
347 "directionalfocussoutheast",
348 action_directional_focus,
349 setup_action_directional_focus_southeast
352 "directionalfocussouthwest",
353 action_directional_focus,
354 setup_action_directional_focus_southwest
357 "directionalfocusnorthwest",
358 action_directional_focus,
359 setup_action_directional_focus_northwest
433 action_toggle_omnipresent,
438 action_move_relative_horz,
443 action_move_relative_vert,
447 "resizerelativehorz",
448 action_resize_relative_horz,
452 "resizerelativevert",
453 action_resize_relative_vert,
458 action_maximize_full,
463 action_unmaximize_full,
467 "togglemaximizefull",
468 action_toggle_maximize_full,
473 action_maximize_horz,
478 action_unmaximize_horz,
482 "togglemaximizehorz",
483 action_toggle_maximize_horz,
488 action_maximize_vert,
493 action_unmaximize_vert,
497 "togglemaximizevert",
498 action_toggle_maximize_vert,
503 action_send_to_desktop,
504 setup_action_send_to_desktop
508 action_send_to_desktop_dir,
509 setup_action_send_to_desktop_next
512 "sendtodesktopprevious",
513 action_send_to_desktop_dir,
514 setup_action_send_to_desktop_prev
517 "sendtodesktopright",
518 action_send_to_desktop_dir,
519 setup_action_send_to_desktop_right
523 action_send_to_desktop_dir,
524 setup_action_send_to_desktop_left
528 action_send_to_desktop_dir,
529 setup_action_send_to_desktop_up
533 action_send_to_desktop_dir,
534 setup_action_send_to_desktop_down
544 setup_action_desktop_next
549 setup_action_desktop_prev
554 setup_action_desktop_right
559 setup_action_desktop_left
564 setup_action_desktop_up
569 setup_action_desktop_down
573 action_toggle_decorations,
588 action_toggle_show_desktop,
598 action_unshow_desktop,
624 setup_action_showmenu
628 action_send_to_layer,
629 setup_action_top_layer
634 setup_action_top_layer
638 action_send_to_layer,
639 setup_action_normal_layer
643 action_send_to_layer,
644 setup_action_bottom_layer
647 "togglealwaysonbottom",
649 setup_action_bottom_layer
653 action_cycle_windows,
654 setup_action_cycle_windows_next
658 action_cycle_windows,
659 setup_action_cycle_windows_previous
664 setup_action_movetoedge_north
669 setup_action_movetoedge_south
674 setup_action_movetoedge_west
679 setup_action_movetoedge_east
684 setup_action_growtoedge_north
689 setup_action_growtoedge_south
694 setup_action_growtoedge_west
699 setup_action_growtoedge_east
708 ObAction *action_from_string(const gchar *name, ObUserAction uact)
711 gboolean exist = FALSE;
714 for (i = 0; actionstrings[i].name; i++)
715 if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
717 a = action_new(actionstrings[i].func, uact);
718 if (actionstrings[i].setup)
719 actionstrings[i].setup(&a, uact);
720 /* only key bindings can be interactive. thus saith the xor. */
721 if (uact != OB_USER_ACTION_KEYBOARD_KEY)
722 a->data.any.interactive = FALSE;
726 g_warning("Invalid action '%s' requested. No such action exists.",
729 g_warning("Invalid use of action '%s'. Action will be ignored.", name);
733 ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
737 ObAction *act = NULL;
740 if (parse_attr_string("name", node, &actname)) {
741 if ((act = action_from_string(actname, uact))) {
742 if (act->func == action_execute || act->func == action_restart) {
743 if ((n = parse_find_node("execute", node->xmlChildrenNode))) {
744 gchar *s = parse_string(doc, n);
745 act->data.execute.path = parse_expand_tilde(s);
748 } else if (act->func == action_showmenu) {
749 if ((n = parse_find_node("menu", node->xmlChildrenNode)))
750 act->data.showmenu.name = parse_string(doc, n);
751 } else if (act->func == action_move_relative_horz ||
752 act->func == action_move_relative_vert ||
753 act->func == action_resize_relative_horz ||
754 act->func == action_resize_relative_vert) {
755 if ((n = parse_find_node("delta", node->xmlChildrenNode)))
756 act->data.relative.delta = parse_int(doc, n);
757 } else if (act->func == action_desktop) {
758 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
759 act->data.desktop.desk = parse_int(doc, n);
760 if (act->data.desktop.desk > 0) act->data.desktop.desk--;
761 } else if (act->func == action_send_to_desktop) {
762 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
763 act->data.sendto.desk = parse_int(doc, n);
764 if (act->data.sendto.desk > 0) act->data.sendto.desk--;
765 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
766 act->data.sendto.follow = parse_bool(doc, n);
767 } else if (act->func == action_desktop_dir) {
768 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
769 act->data.desktopdir.wrap = parse_bool(doc, n);
770 } else if (act->func == action_send_to_desktop_dir) {
771 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
772 act->data.sendtodir.wrap = parse_bool(doc, n);
773 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
774 act->data.sendtodir.follow = parse_bool(doc, n);
775 } else if (act->func == action_activate) {
776 if ((n = parse_find_node("here", node->xmlChildrenNode)))
777 act->data.activate.here = parse_bool(doc, n);
778 } else if (act->func == action_cycle_windows) {
779 if ((n = parse_find_node("linear", node->xmlChildrenNode)))
780 act->data.cycle.linear = parse_bool(doc, n);
788 void action_run_list(GSList *acts, struct _ObClient *c,
789 guint state, guint button, gint x, gint y,
790 gboolean cancel, gboolean done)
794 gboolean inter = FALSE;
797 screen_pointer_pos(&x, &y);
799 for (it = acts; it; it = g_slist_next(it)) {
801 if (a->data.any.interactive) {
808 /* sometimes when we execute another app as an action,
809 it won't work right unless we XUngrabKeyboard first,
810 even though we grabbed the key/button Asychronously.
811 e.g. "gnome-panel-control --main-menu" */
812 XUngrabKeyboard(ob_display, event_lasttime);
815 for (it = acts; it; it = g_slist_next(it)) {
822 a->data.any.button = button;
824 if (a->data.any.interactive) {
825 a->data.inter.cancel = cancel;
826 a->data.inter.final = done;
827 if (!(cancel || done))
828 keyboard_interactive_grab(state, c, a);
835 void action_execute(union ActionData *data)
839 if (data->execute.path) {
840 cmd = g_filename_from_utf8(data->execute.path, -1, NULL, NULL, NULL);
842 if (!g_spawn_command_line_async(cmd, &e)) {
843 g_warning("failed to execute '%s': %s",
848 g_warning("failed to convert '%s' from utf8", data->execute.path);
853 void action_activate(union ActionData *data)
855 if (data->activate.any.c)
856 client_activate(data->activate.any.c, data->activate.here);
859 void action_focus(union ActionData *data)
861 if (data->client.any.c)
862 client_focus(data->client.any.c);
865 void action_unfocus (union ActionData *data)
867 if (data->client.any.c)
868 client_unfocus(data->client.any.c);
871 void action_iconify(union ActionData *data)
873 if (data->client.any.c)
874 client_iconify(data->client.any.c, TRUE, TRUE);
877 void action_raiselower(union ActionData *data)
879 ObClient *c = data->client.any.c;
881 gboolean raise = FALSE;
885 for (it = stacking_list; it; it = g_list_next(it)) {
886 ObClient *cit = it->data;
889 if (client_normal(cit) == client_normal(c) &&
890 cit->layer == c->layer &&
893 if (RECT_INTERSECTS_RECT(cit->frame->area, c->frame->area)) {
901 stacking_raise(CLIENT_AS_WINDOW(c));
903 stacking_lower(CLIENT_AS_WINDOW(c));
906 void action_raise(union ActionData *data)
908 if (data->client.any.c)
909 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
912 void action_unshaderaise(union ActionData *data)
914 if (data->client.any.c) {
915 if (data->client.any.c->shaded) {
916 grab_pointer(TRUE, OB_CURSOR_NONE);
917 client_shade(data->client.any.c, FALSE);
918 grab_pointer(FALSE, OB_CURSOR_NONE);
920 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
924 void action_shadelower(union ActionData *data)
926 if (data->client.any.c) {
927 if (data->client.any.c->shaded)
928 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
930 grab_pointer(TRUE, OB_CURSOR_NONE);
931 client_shade(data->client.any.c, TRUE);
932 grab_pointer(FALSE, OB_CURSOR_NONE);
937 void action_lower(union ActionData *data)
939 if (data->client.any.c)
940 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
943 void action_close(union ActionData *data)
945 if (data->client.any.c)
946 client_close(data->client.any.c);
949 void action_kill(union ActionData *data)
951 if (data->client.any.c)
952 client_kill(data->client.any.c);
955 void action_shade(union ActionData *data)
957 if (data->client.any.c) {
958 grab_pointer(TRUE, OB_CURSOR_NONE);
959 client_shade(data->client.any.c, TRUE);
960 grab_pointer(FALSE, OB_CURSOR_NONE);
964 void action_unshade(union ActionData *data)
966 if (data->client.any.c) {
967 grab_pointer(TRUE, OB_CURSOR_NONE);
968 client_shade(data->client.any.c, FALSE);
969 grab_pointer(FALSE, OB_CURSOR_NONE);
973 void action_toggle_shade(union ActionData *data)
975 if (data->client.any.c) {
976 grab_pointer(TRUE, OB_CURSOR_NONE);
977 client_shade(data->client.any.c, !data->client.any.c->shaded);
978 grab_pointer(FALSE, OB_CURSOR_NONE);
982 void action_toggle_omnipresent(union ActionData *data)
984 if (data->client.any.c)
985 client_set_desktop(data->client.any.c,
986 data->client.any.c->desktop == DESKTOP_ALL ?
987 screen_desktop : DESKTOP_ALL, FALSE);
990 void action_move_relative_horz(union ActionData *data)
992 ObClient *c = data->relative.any.c;
994 grab_pointer(TRUE, OB_CURSOR_NONE);
995 client_move(c, c->area.x + data->relative.delta, c->area.y);
996 grab_pointer(FALSE, OB_CURSOR_NONE);
1000 void action_move_relative_vert(union ActionData *data)
1002 ObClient *c = data->relative.any.c;
1004 grab_pointer(TRUE, OB_CURSOR_NONE);
1005 client_move(c, c->area.x, c->area.y + data->relative.delta);
1006 grab_pointer(FALSE, OB_CURSOR_NONE);
1010 void action_resize_relative_horz(union ActionData *data)
1012 ObClient *c = data->relative.any.c;
1014 grab_pointer(TRUE, OB_CURSOR_NONE);
1016 c->area.width + data->relative.delta * c->size_inc.width,
1018 grab_pointer(FALSE, OB_CURSOR_NONE);
1022 void action_resize_relative_vert(union ActionData *data)
1024 ObClient *c = data->relative.any.c;
1025 if (c && !c->shaded) {
1026 grab_pointer(TRUE, OB_CURSOR_NONE);
1027 client_resize(c, c->area.width, c->area.height +
1028 data->relative.delta * c->size_inc.height);
1029 grab_pointer(FALSE, OB_CURSOR_NONE);
1033 void action_maximize_full(union ActionData *data)
1035 if (data->client.any.c)
1036 client_maximize(data->client.any.c, TRUE, 0, TRUE);
1039 void action_unmaximize_full(union ActionData *data)
1041 if (data->client.any.c)
1042 client_maximize(data->client.any.c, FALSE, 0, TRUE);
1045 void action_toggle_maximize_full(union ActionData *data)
1047 if (data->client.any.c)
1048 client_maximize(data->client.any.c,
1049 !(data->client.any.c->max_horz ||
1050 data->client.any.c->max_vert),
1054 void action_maximize_horz(union ActionData *data)
1056 if (data->client.any.c)
1057 client_maximize(data->client.any.c, TRUE, 1, TRUE);
1060 void action_unmaximize_horz(union ActionData *data)
1062 if (data->client.any.c)
1063 client_maximize(data->client.any.c, FALSE, 1, TRUE);
1066 void action_toggle_maximize_horz(union ActionData *data)
1068 if (data->client.any.c)
1069 client_maximize(data->client.any.c,
1070 !data->client.any.c->max_horz, 1, TRUE);
1073 void action_maximize_vert(union ActionData *data)
1075 if (data->client.any.c)
1076 client_maximize(data->client.any.c, TRUE, 2, TRUE);
1079 void action_unmaximize_vert(union ActionData *data)
1081 if (data->client.any.c)
1082 client_maximize(data->client.any.c, FALSE, 2, TRUE);
1085 void action_toggle_maximize_vert(union ActionData *data)
1087 if (data->client.any.c)
1088 client_maximize(data->client.any.c, !data->client.any.c->max_vert, 2, TRUE);
1091 void action_send_to_desktop(union ActionData *data)
1093 ObClient *c = data->sendto.any.c;
1095 if (!c || !client_normal(c)) return;
1097 if (data->sendto.desk < screen_num_desktops ||
1098 data->sendto.desk == DESKTOP_ALL) {
1099 client_set_desktop(c, data->sendto.desk, data->sendto.follow);
1100 if (data->sendto.follow)
1101 screen_set_desktop(data->sendto.desk);
1105 void action_desktop(union ActionData *data)
1107 if (data->desktop.desk < screen_num_desktops ||
1108 data->desktop.desk == DESKTOP_ALL)
1109 screen_set_desktop(data->desktop.desk);
1112 void action_desktop_dir(union ActionData *data)
1116 d = screen_cycle_desktop(data->desktopdir.dir,
1117 data->desktopdir.wrap,
1118 data->sendtodir.linear,
1119 data->desktopdir.inter.any.interactive,
1120 data->desktopdir.inter.final,
1121 data->desktopdir.inter.cancel);
1122 screen_set_desktop(d);
1125 void action_send_to_desktop_dir(union ActionData *data)
1127 ObClient *c = data->sendtodir.inter.any.c;
1130 if (!c || !client_normal(c)) return;
1132 d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
1133 data->sendtodir.linear,
1134 data->sendtodir.inter.any.interactive,
1135 data->sendtodir.inter.final,
1136 data->sendtodir.inter.cancel);
1137 client_set_desktop(c, d, data->sendtodir.follow);
1138 if (data->sendtodir.follow)
1139 screen_set_desktop(d);
1142 void action_desktop_last(union ActionData *data)
1144 screen_set_desktop(screen_last_desktop);
1147 void action_toggle_decorations(union ActionData *data)
1149 ObClient *c = data->client.any.c;
1153 c->decorate = !c->decorate;
1154 client_setup_decor_and_functions(c);
1157 static guint32 pick_corner(int x, int y, int cx, int cy, int cw, int ch)
1159 if (x - cx > cw / 2) {
1160 if (y - cy > ch / 2)
1161 return prop_atoms.net_wm_moveresize_size_bottomright;
1163 return prop_atoms.net_wm_moveresize_size_topright;
1165 if (y - cy > ch / 2)
1166 return prop_atoms.net_wm_moveresize_size_bottomleft;
1168 return prop_atoms.net_wm_moveresize_size_topleft;
1172 void action_moveresize(union ActionData *data)
1174 ObClient *c = data->moveresize.any.c;
1177 if (!c || !client_normal(c)) return;
1179 if (data->moveresize.keyboard) {
1180 corner = (data->moveresize.move ?
1181 prop_atoms.net_wm_moveresize_move_keyboard :
1182 prop_atoms.net_wm_moveresize_size_keyboard);
1184 corner = (data->moveresize.move ?
1185 prop_atoms.net_wm_moveresize_move :
1186 pick_corner(data->any.x, data->any.y,
1187 c->frame->area.x, c->frame->area.y,
1188 /* use the client size because the frame
1189 can be differently sized (shaded
1190 windows) and we want this based on the
1192 c->area.width + c->frame->size.left +
1193 c->frame->size.right,
1194 c->area.height + c->frame->size.top +
1195 c->frame->size.bottom));
1198 moveresize_start(c, data->any.x, data->any.y, data->any.button, corner);
1201 void action_reconfigure(union ActionData *data)
1206 void action_restart(union ActionData *data)
1208 ob_restart_other(data->execute.path);
1211 void action_exit(union ActionData *data)
1216 void action_showmenu(union ActionData *data)
1218 if (data->showmenu.name) {
1219 menu_show(data->showmenu.name, data->any.x, data->any.y,
1220 data->showmenu.any.c);
1224 void action_cycle_windows(union ActionData *data)
1226 focus_cycle(data->cycle.forward, data->cycle.linear,
1227 data->cycle.inter.any.interactive,
1228 data->cycle.inter.final, data->cycle.inter.cancel);
1231 void action_directional_focus(union ActionData *data)
1233 focus_directional_cycle(data->interdiraction.direction,
1234 data->interdiraction.inter.any.interactive,
1235 data->interdiraction.inter.final,
1236 data->interdiraction.inter.cancel);
1239 void action_movetoedge(union ActionData *data)
1242 ObClient *c = data->diraction.any.c;
1246 x = c->frame->area.x;
1247 y = c->frame->area.y;
1249 switch(data->diraction.direction) {
1250 case OB_DIRECTION_NORTH:
1251 y = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1253 case OB_DIRECTION_WEST:
1254 x = client_directional_edge_search(c, OB_DIRECTION_WEST);
1256 case OB_DIRECTION_SOUTH:
1257 y = client_directional_edge_search(c, OB_DIRECTION_SOUTH) -
1258 c->frame->area.height;
1260 case OB_DIRECTION_EAST:
1261 x = client_directional_edge_search(c, OB_DIRECTION_EAST) -
1262 c->frame->area.width;
1265 g_assert_not_reached();
1267 frame_frame_gravity(c->frame, &x, &y);
1268 grab_pointer(TRUE, OB_CURSOR_NONE);
1269 client_move(c, x, y);
1270 grab_pointer(FALSE, OB_CURSOR_NONE);
1274 void action_growtoedge(union ActionData *data)
1276 int x, y, width, height, dest;
1277 ObClient *c = data->diraction.any.c;
1283 a = screen_area(c->desktop);
1284 x = c->frame->area.x;
1285 y = c->frame->area.y;
1286 width = c->frame->area.width;
1287 height = c->frame->area.height;
1289 switch(data->diraction.direction) {
1290 case OB_DIRECTION_NORTH:
1291 dest = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1293 height = c->frame->area.height / 2;
1295 height = c->frame->area.y + c->frame->area.height - dest;
1299 case OB_DIRECTION_WEST:
1300 dest = client_directional_edge_search(c, OB_DIRECTION_WEST);
1302 width = c->frame->area.width / 2;
1304 width = c->frame->area.x + c->frame->area.width - dest;
1308 case OB_DIRECTION_SOUTH:
1309 dest = client_directional_edge_search(c, OB_DIRECTION_SOUTH);
1310 if (a->y + a->height == y + c->frame->area.height) {
1311 height = c->frame->area.height / 2;
1312 y = a->y + a->height - height;
1314 height = dest - c->frame->area.y;
1315 y += (height - c->frame->area.height) % c->size_inc.height;
1316 height -= (height - c->frame->area.height) % c->size_inc.height;
1318 case OB_DIRECTION_EAST:
1319 dest = client_directional_edge_search(c, OB_DIRECTION_EAST);
1320 if (a->x + a->width == x + c->frame->area.width) {
1321 width = c->frame->area.width / 2;
1322 x = a->x + a->width - width;
1324 width = dest - c->frame->area.x;
1325 x += (width - c->frame->area.width) % c->size_inc.width;
1326 width -= (width - c->frame->area.width) % c->size_inc.width;
1329 g_assert_not_reached();
1331 frame_frame_gravity(c->frame, &x, &y);
1332 width -= c->frame->size.left + c->frame->size.right;
1333 height -= c->frame->size.top + c->frame->size.bottom;
1334 grab_pointer(TRUE, OB_CURSOR_NONE);
1335 client_move_resize(c, x, y, width, height);
1336 grab_pointer(FALSE, OB_CURSOR_NONE);
1339 void action_send_to_layer(union ActionData *data)
1341 if (data->layer.any.c)
1342 client_set_layer(data->layer.any.c, data->layer.layer);
1345 void action_toggle_layer(union ActionData *data)
1347 ObClient *c = data->layer.any.c;
1350 if (data->layer.layer < 0)
1351 client_set_layer(c, c->below ? 0 : -1);
1352 else if (data->layer.layer > 0)
1353 client_set_layer(c, c->above ? 0 : 1);
1357 void action_toggle_show_desktop(union ActionData *data)
1359 screen_show_desktop(!screen_showing_desktop);
1362 void action_show_desktop(union ActionData *data)
1364 screen_show_desktop(TRUE);
1367 void action_unshow_desktop(union ActionData *data)
1369 screen_show_desktop(FALSE);