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, ObClient *c,
789 guint state, guint button, gint x, gint y,
790 gboolean cancel, gboolean done)
794 gboolean inter = FALSE;
800 screen_pointer_pos(&x, &y);
802 if (grab_on_keyboard())
805 for (it = acts; it; it = g_slist_next(it)) {
807 if (a->data.any.interactive) {
814 /* sometimes when we execute another app as an action,
815 it won't work right unless we XUngrabKeyboard first,
816 even though we grabbed the key/button Asychronously.
817 e.g. "gnome-panel-control --main-menu" */
818 XUngrabKeyboard(ob_display, event_lasttime);
821 for (it = acts; it; it = g_slist_next(it)) {
828 a->data.any.button = button;
830 if (a->data.any.interactive) {
831 a->data.inter.cancel = cancel;
832 a->data.inter.final = done;
833 if (!(cancel || done))
834 keyboard_interactive_grab(state, c, a);
841 void action_execute(union ActionData *data)
845 if (data->execute.path) {
846 cmd = g_filename_from_utf8(data->execute.path, -1, NULL, NULL, NULL);
848 if (!g_spawn_command_line_async(cmd, &e)) {
849 g_warning("failed to execute '%s': %s",
854 g_warning("failed to convert '%s' from utf8", data->execute.path);
859 void action_activate(union ActionData *data)
861 if (data->activate.any.c)
862 client_activate(data->activate.any.c, data->activate.here);
865 void action_focus(union ActionData *data)
867 if (data->client.any.c)
868 client_focus(data->client.any.c);
871 void action_unfocus (union ActionData *data)
873 if (data->client.any.c)
874 client_unfocus(data->client.any.c);
877 void action_iconify(union ActionData *data)
879 if (data->client.any.c)
880 client_iconify(data->client.any.c, TRUE, TRUE);
883 void action_raiselower(union ActionData *data)
885 ObClient *c = data->client.any.c;
887 gboolean raise = FALSE;
891 for (it = stacking_list; it; it = g_list_next(it)) {
892 ObClient *cit = it->data;
895 if (client_normal(cit) == client_normal(c) &&
896 cit->layer == c->layer &&
899 if (RECT_INTERSECTS_RECT(cit->frame->area, c->frame->area)) {
907 stacking_raise(CLIENT_AS_WINDOW(c));
909 stacking_lower(CLIENT_AS_WINDOW(c));
912 void action_raise(union ActionData *data)
914 if (data->client.any.c)
915 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
918 void action_unshaderaise(union ActionData *data)
920 if (data->client.any.c) {
921 if (data->client.any.c->shaded) {
922 grab_pointer(TRUE, OB_CURSOR_NONE);
923 client_shade(data->client.any.c, FALSE);
924 grab_pointer(FALSE, OB_CURSOR_NONE);
926 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
930 void action_shadelower(union ActionData *data)
932 if (data->client.any.c) {
933 if (data->client.any.c->shaded)
934 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
936 grab_pointer(TRUE, OB_CURSOR_NONE);
937 client_shade(data->client.any.c, TRUE);
938 grab_pointer(FALSE, OB_CURSOR_NONE);
943 void action_lower(union ActionData *data)
945 if (data->client.any.c)
946 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
949 void action_close(union ActionData *data)
951 if (data->client.any.c)
952 client_close(data->client.any.c);
955 void action_kill(union ActionData *data)
957 if (data->client.any.c)
958 client_kill(data->client.any.c);
961 void action_shade(union ActionData *data)
963 if (data->client.any.c) {
964 grab_pointer(TRUE, OB_CURSOR_NONE);
965 client_shade(data->client.any.c, TRUE);
966 grab_pointer(FALSE, OB_CURSOR_NONE);
970 void action_unshade(union ActionData *data)
972 if (data->client.any.c) {
973 grab_pointer(TRUE, OB_CURSOR_NONE);
974 client_shade(data->client.any.c, FALSE);
975 grab_pointer(FALSE, OB_CURSOR_NONE);
979 void action_toggle_shade(union ActionData *data)
981 if (data->client.any.c) {
982 grab_pointer(TRUE, OB_CURSOR_NONE);
983 client_shade(data->client.any.c, !data->client.any.c->shaded);
984 grab_pointer(FALSE, OB_CURSOR_NONE);
988 void action_toggle_omnipresent(union ActionData *data)
990 if (data->client.any.c)
991 client_set_desktop(data->client.any.c,
992 data->client.any.c->desktop == DESKTOP_ALL ?
993 screen_desktop : DESKTOP_ALL, FALSE);
996 void action_move_relative_horz(union ActionData *data)
998 ObClient *c = data->relative.any.c;
1000 grab_pointer(TRUE, OB_CURSOR_NONE);
1001 client_move(c, c->area.x + data->relative.delta, c->area.y);
1002 grab_pointer(FALSE, OB_CURSOR_NONE);
1006 void action_move_relative_vert(union ActionData *data)
1008 ObClient *c = data->relative.any.c;
1010 grab_pointer(TRUE, OB_CURSOR_NONE);
1011 client_move(c, c->area.x, c->area.y + data->relative.delta);
1012 grab_pointer(FALSE, OB_CURSOR_NONE);
1016 void action_resize_relative_horz(union ActionData *data)
1018 ObClient *c = data->relative.any.c;
1020 grab_pointer(TRUE, OB_CURSOR_NONE);
1022 c->area.width + data->relative.delta * c->size_inc.width,
1024 grab_pointer(FALSE, OB_CURSOR_NONE);
1028 void action_resize_relative_vert(union ActionData *data)
1030 ObClient *c = data->relative.any.c;
1031 if (c && !c->shaded) {
1032 grab_pointer(TRUE, OB_CURSOR_NONE);
1033 client_resize(c, c->area.width, c->area.height +
1034 data->relative.delta * c->size_inc.height);
1035 grab_pointer(FALSE, OB_CURSOR_NONE);
1039 void action_maximize_full(union ActionData *data)
1041 if (data->client.any.c)
1042 client_maximize(data->client.any.c, TRUE, 0, TRUE);
1045 void action_unmaximize_full(union ActionData *data)
1047 if (data->client.any.c)
1048 client_maximize(data->client.any.c, FALSE, 0, TRUE);
1051 void action_toggle_maximize_full(union ActionData *data)
1053 if (data->client.any.c)
1054 client_maximize(data->client.any.c,
1055 !(data->client.any.c->max_horz ||
1056 data->client.any.c->max_vert),
1060 void action_maximize_horz(union ActionData *data)
1062 if (data->client.any.c)
1063 client_maximize(data->client.any.c, TRUE, 1, TRUE);
1066 void action_unmaximize_horz(union ActionData *data)
1068 if (data->client.any.c)
1069 client_maximize(data->client.any.c, FALSE, 1, TRUE);
1072 void action_toggle_maximize_horz(union ActionData *data)
1074 if (data->client.any.c)
1075 client_maximize(data->client.any.c,
1076 !data->client.any.c->max_horz, 1, TRUE);
1079 void action_maximize_vert(union ActionData *data)
1081 if (data->client.any.c)
1082 client_maximize(data->client.any.c, TRUE, 2, TRUE);
1085 void action_unmaximize_vert(union ActionData *data)
1087 if (data->client.any.c)
1088 client_maximize(data->client.any.c, FALSE, 2, TRUE);
1091 void action_toggle_maximize_vert(union ActionData *data)
1093 if (data->client.any.c)
1094 client_maximize(data->client.any.c, !data->client.any.c->max_vert, 2, TRUE);
1097 void action_send_to_desktop(union ActionData *data)
1099 ObClient *c = data->sendto.any.c;
1101 if (!c || !client_normal(c)) return;
1103 if (data->sendto.desk < screen_num_desktops ||
1104 data->sendto.desk == DESKTOP_ALL) {
1105 client_set_desktop(c, data->sendto.desk, data->sendto.follow);
1106 if (data->sendto.follow)
1107 screen_set_desktop(data->sendto.desk);
1111 void action_desktop(union ActionData *data)
1113 if (data->desktop.desk < screen_num_desktops ||
1114 data->desktop.desk == DESKTOP_ALL)
1115 screen_set_desktop(data->desktop.desk);
1118 void action_desktop_dir(union ActionData *data)
1122 d = screen_cycle_desktop(data->desktopdir.dir,
1123 data->desktopdir.wrap,
1124 data->sendtodir.linear,
1125 data->desktopdir.inter.any.interactive,
1126 data->desktopdir.inter.final,
1127 data->desktopdir.inter.cancel);
1128 screen_set_desktop(d);
1131 void action_send_to_desktop_dir(union ActionData *data)
1133 ObClient *c = data->sendtodir.inter.any.c;
1136 if (!c || !client_normal(c)) return;
1138 d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
1139 data->sendtodir.linear,
1140 data->sendtodir.inter.any.interactive,
1141 data->sendtodir.inter.final,
1142 data->sendtodir.inter.cancel);
1143 client_set_desktop(c, d, data->sendtodir.follow);
1144 if (data->sendtodir.follow)
1145 screen_set_desktop(d);
1148 void action_desktop_last(union ActionData *data)
1150 screen_set_desktop(screen_last_desktop);
1153 void action_toggle_decorations(union ActionData *data)
1155 ObClient *c = data->client.any.c;
1159 c->decorate = !c->decorate;
1160 client_setup_decor_and_functions(c);
1163 static guint32 pick_corner(int x, int y, int cx, int cy, int cw, int ch)
1165 if (x - cx > cw / 2) {
1166 if (y - cy > ch / 2)
1167 return prop_atoms.net_wm_moveresize_size_bottomright;
1169 return prop_atoms.net_wm_moveresize_size_topright;
1171 if (y - cy > ch / 2)
1172 return prop_atoms.net_wm_moveresize_size_bottomleft;
1174 return prop_atoms.net_wm_moveresize_size_topleft;
1178 void action_moveresize(union ActionData *data)
1180 ObClient *c = data->moveresize.any.c;
1183 if (!c || !client_normal(c)) return;
1185 if (data->moveresize.keyboard) {
1186 corner = (data->moveresize.move ?
1187 prop_atoms.net_wm_moveresize_move_keyboard :
1188 prop_atoms.net_wm_moveresize_size_keyboard);
1190 corner = (data->moveresize.move ?
1191 prop_atoms.net_wm_moveresize_move :
1192 pick_corner(data->any.x, data->any.y,
1193 c->frame->area.x, c->frame->area.y,
1194 /* use the client size because the frame
1195 can be differently sized (shaded
1196 windows) and we want this based on the
1198 c->area.width + c->frame->size.left +
1199 c->frame->size.right,
1200 c->area.height + c->frame->size.top +
1201 c->frame->size.bottom));
1204 moveresize_start(c, data->any.x, data->any.y, data->any.button, corner);
1207 void action_reconfigure(union ActionData *data)
1212 void action_restart(union ActionData *data)
1214 ob_restart_other(data->execute.path);
1217 void action_exit(union ActionData *data)
1222 void action_showmenu(union ActionData *data)
1224 if (data->showmenu.name) {
1225 menu_show(data->showmenu.name, data->any.x, data->any.y,
1226 data->showmenu.any.c);
1230 void action_cycle_windows(union ActionData *data)
1232 focus_cycle(data->cycle.forward, data->cycle.linear,
1233 data->cycle.inter.any.interactive,
1234 data->cycle.inter.final, data->cycle.inter.cancel);
1237 void action_directional_focus(union ActionData *data)
1239 focus_directional_cycle(data->interdiraction.direction,
1240 data->interdiraction.inter.any.interactive,
1241 data->interdiraction.inter.final,
1242 data->interdiraction.inter.cancel);
1245 void action_movetoedge(union ActionData *data)
1248 ObClient *c = data->diraction.any.c;
1252 x = c->frame->area.x;
1253 y = c->frame->area.y;
1255 switch(data->diraction.direction) {
1256 case OB_DIRECTION_NORTH:
1257 y = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1259 case OB_DIRECTION_WEST:
1260 x = client_directional_edge_search(c, OB_DIRECTION_WEST);
1262 case OB_DIRECTION_SOUTH:
1263 y = client_directional_edge_search(c, OB_DIRECTION_SOUTH) -
1264 c->frame->area.height;
1266 case OB_DIRECTION_EAST:
1267 x = client_directional_edge_search(c, OB_DIRECTION_EAST) -
1268 c->frame->area.width;
1271 g_assert_not_reached();
1273 frame_frame_gravity(c->frame, &x, &y);
1274 grab_pointer(TRUE, OB_CURSOR_NONE);
1275 client_move(c, x, y);
1276 grab_pointer(FALSE, OB_CURSOR_NONE);
1280 void action_growtoedge(union ActionData *data)
1282 int x, y, width, height, dest;
1283 ObClient *c = data->diraction.any.c;
1289 a = screen_area(c->desktop);
1290 x = c->frame->area.x;
1291 y = c->frame->area.y;
1292 width = c->frame->area.width;
1293 height = c->frame->area.height;
1295 switch(data->diraction.direction) {
1296 case OB_DIRECTION_NORTH:
1297 dest = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1299 height = c->frame->area.height / 2;
1301 height = c->frame->area.y + c->frame->area.height - dest;
1305 case OB_DIRECTION_WEST:
1306 dest = client_directional_edge_search(c, OB_DIRECTION_WEST);
1308 width = c->frame->area.width / 2;
1310 width = c->frame->area.x + c->frame->area.width - dest;
1314 case OB_DIRECTION_SOUTH:
1315 dest = client_directional_edge_search(c, OB_DIRECTION_SOUTH);
1316 if (a->y + a->height == y + c->frame->area.height) {
1317 height = c->frame->area.height / 2;
1318 y = a->y + a->height - height;
1320 height = dest - c->frame->area.y;
1321 y += (height - c->frame->area.height) % c->size_inc.height;
1322 height -= (height - c->frame->area.height) % c->size_inc.height;
1324 case OB_DIRECTION_EAST:
1325 dest = client_directional_edge_search(c, OB_DIRECTION_EAST);
1326 if (a->x + a->width == x + c->frame->area.width) {
1327 width = c->frame->area.width / 2;
1328 x = a->x + a->width - width;
1330 width = dest - c->frame->area.x;
1331 x += (width - c->frame->area.width) % c->size_inc.width;
1332 width -= (width - c->frame->area.width) % c->size_inc.width;
1335 g_assert_not_reached();
1337 frame_frame_gravity(c->frame, &x, &y);
1338 width -= c->frame->size.left + c->frame->size.right;
1339 height -= c->frame->size.top + c->frame->size.bottom;
1340 grab_pointer(TRUE, OB_CURSOR_NONE);
1341 client_move_resize(c, x, y, width, height);
1342 grab_pointer(FALSE, OB_CURSOR_NONE);
1345 void action_send_to_layer(union ActionData *data)
1347 if (data->layer.any.c)
1348 client_set_layer(data->layer.any.c, data->layer.layer);
1351 void action_toggle_layer(union ActionData *data)
1353 ObClient *c = data->layer.any.c;
1356 if (data->layer.layer < 0)
1357 client_set_layer(c, c->below ? 0 : -1);
1358 else if (data->layer.layer > 0)
1359 client_set_layer(c, c->above ? 0 : 1);
1363 void action_toggle_show_desktop(union ActionData *data)
1365 screen_show_desktop(!screen_showing_desktop);
1368 void action_show_desktop(union ActionData *data)
1370 screen_show_desktop(TRUE);
1373 void action_unshow_desktop(union ActionData *data)
1375 screen_show_desktop(FALSE);