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"
37 inline void client_action_start(union ActionData *data)
39 if (config_focus_follow)
40 if (data->any.context != OB_FRAME_CONTEXT_CLIENT && !data->any.button)
41 grab_pointer(TRUE, OB_CURSOR_NONE);
44 inline void client_action_end(union ActionData *data)
46 if (config_focus_follow)
47 if (data->any.context != OB_FRAME_CONTEXT_CLIENT) {
48 if (!data->any.button) {
49 grab_pointer(FALSE, OB_CURSOR_NONE);
53 /* usually this is sorta redundant, but with a press action
54 the enter event will come as a GrabNotify which is
55 ignored, so this will handle that case */
56 if ((c = client_under_pointer()))
57 event_enter_client(c);
65 void (*func)(union ActionData *);
66 void (*setup)(ObAction **, ObUserAction uact);
69 static ObAction *action_new(void (*func)(union ActionData *data))
71 ObAction *a = g_new0(ObAction, 1);
78 void action_ref(ObAction *a)
83 void action_unref(ObAction *a)
85 if (a == NULL) return;
87 if (--a->ref > 0) return;
89 /* deal with pointers */
90 if (a->func == action_execute || a->func == action_restart)
91 g_free(a->data.execute.path);
92 else if (a->func == action_showmenu)
93 g_free(a->data.showmenu.name);
98 ObAction* action_copy(const ObAction *src)
100 ObAction *a = action_new(src->func);
104 /* deal with pointers */
105 if (a->func == action_execute || a->func == action_restart)
106 a->data.execute.path = g_strdup(a->data.execute.path);
107 else if (a->func == action_showmenu)
108 a->data.showmenu.name = g_strdup(a->data.showmenu.name);
113 void setup_action_directional_focus_north(ObAction **a, ObUserAction uact)
115 (*a)->data.interdiraction.inter.any.interactive = TRUE;
116 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTH;
119 void setup_action_directional_focus_east(ObAction **a, ObUserAction uact)
121 (*a)->data.interdiraction.inter.any.interactive = TRUE;
122 (*a)->data.interdiraction.direction = OB_DIRECTION_EAST;
125 void setup_action_directional_focus_south(ObAction **a, ObUserAction uact)
127 (*a)->data.interdiraction.inter.any.interactive = TRUE;
128 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTH;
131 void setup_action_directional_focus_west(ObAction **a, ObUserAction uact)
133 (*a)->data.interdiraction.inter.any.interactive = TRUE;
134 (*a)->data.interdiraction.direction = OB_DIRECTION_WEST;
137 void setup_action_directional_focus_northeast(ObAction **a, ObUserAction uact)
139 (*a)->data.interdiraction.inter.any.interactive = TRUE;
140 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHEAST;
143 void setup_action_directional_focus_southeast(ObAction **a, ObUserAction uact)
145 (*a)->data.interdiraction.inter.any.interactive = TRUE;
146 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHEAST;
149 void setup_action_directional_focus_southwest(ObAction **a, ObUserAction uact)
151 (*a)->data.interdiraction.inter.any.interactive = TRUE;
152 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHWEST;
155 void setup_action_directional_focus_northwest(ObAction **a, ObUserAction uact)
157 (*a)->data.interdiraction.inter.any.interactive = TRUE;
158 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHWEST;
161 void setup_action_send_to_desktop(ObAction **a, ObUserAction uact)
163 (*a)->data.sendto.any.client_action = OB_CLIENT_ACTION_ALWAYS;
164 (*a)->data.sendto.follow = TRUE;
167 void setup_action_send_to_desktop_prev(ObAction **a, ObUserAction uact)
169 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
170 (*a)->data.sendtodir.inter.any.interactive = TRUE;
171 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
172 (*a)->data.sendtodir.linear = TRUE;
173 (*a)->data.sendtodir.wrap = TRUE;
174 (*a)->data.sendtodir.follow = TRUE;
177 void setup_action_send_to_desktop_next(ObAction **a, ObUserAction uact)
179 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
180 (*a)->data.sendtodir.inter.any.interactive = TRUE;
181 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
182 (*a)->data.sendtodir.linear = TRUE;
183 (*a)->data.sendtodir.wrap = TRUE;
184 (*a)->data.sendtodir.follow = TRUE;
187 void setup_action_send_to_desktop_left(ObAction **a, ObUserAction uact)
189 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
190 (*a)->data.sendtodir.inter.any.interactive = TRUE;
191 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
192 (*a)->data.sendtodir.linear = FALSE;
193 (*a)->data.sendtodir.wrap = TRUE;
194 (*a)->data.sendtodir.follow = TRUE;
197 void setup_action_send_to_desktop_right(ObAction **a, ObUserAction uact)
199 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
200 (*a)->data.sendtodir.inter.any.interactive = TRUE;
201 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
202 (*a)->data.sendtodir.linear = FALSE;
203 (*a)->data.sendtodir.wrap = TRUE;
204 (*a)->data.sendtodir.follow = TRUE;
207 void setup_action_send_to_desktop_up(ObAction **a, ObUserAction uact)
209 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
210 (*a)->data.sendtodir.inter.any.interactive = TRUE;
211 (*a)->data.sendtodir.dir = OB_DIRECTION_NORTH;
212 (*a)->data.sendtodir.linear = FALSE;
213 (*a)->data.sendtodir.wrap = TRUE;
214 (*a)->data.sendtodir.follow = TRUE;
217 void setup_action_send_to_desktop_down(ObAction **a, ObUserAction uact)
219 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
220 (*a)->data.sendtodir.inter.any.interactive = TRUE;
221 (*a)->data.sendtodir.dir = OB_DIRECTION_SOUTH;
222 (*a)->data.sendtodir.linear = FALSE;
223 (*a)->data.sendtodir.wrap = TRUE;
224 (*a)->data.sendtodir.follow = TRUE;
227 void setup_action_desktop(ObAction **a, ObUserAction uact)
229 (*a)->data.desktop.inter.any.interactive = TRUE;
232 void setup_action_desktop_prev(ObAction **a, ObUserAction uact)
234 (*a)->data.desktopdir.inter.any.interactive = TRUE;
235 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
236 (*a)->data.desktopdir.linear = TRUE;
237 (*a)->data.desktopdir.wrap = TRUE;
240 void setup_action_desktop_next(ObAction **a, ObUserAction uact)
242 (*a)->data.desktopdir.inter.any.interactive = TRUE;
243 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
244 (*a)->data.desktopdir.linear = TRUE;
245 (*a)->data.desktopdir.wrap = TRUE;
248 void setup_action_desktop_left(ObAction **a, ObUserAction uact)
250 (*a)->data.desktopdir.inter.any.interactive = TRUE;
251 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
252 (*a)->data.desktopdir.linear = FALSE;
253 (*a)->data.desktopdir.wrap = TRUE;
256 void setup_action_desktop_right(ObAction **a, ObUserAction uact)
258 (*a)->data.desktopdir.inter.any.interactive = TRUE;
259 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
260 (*a)->data.desktopdir.linear = FALSE;
261 (*a)->data.desktopdir.wrap = TRUE;
264 void setup_action_desktop_up(ObAction **a, ObUserAction uact)
266 (*a)->data.desktopdir.inter.any.interactive = TRUE;
267 (*a)->data.desktopdir.dir = OB_DIRECTION_NORTH;
268 (*a)->data.desktopdir.linear = FALSE;
269 (*a)->data.desktopdir.wrap = TRUE;
272 void setup_action_desktop_down(ObAction **a, ObUserAction uact)
274 (*a)->data.desktopdir.inter.any.interactive = TRUE;
275 (*a)->data.desktopdir.dir = OB_DIRECTION_SOUTH;
276 (*a)->data.desktopdir.linear = FALSE;
277 (*a)->data.desktopdir.wrap = TRUE;
280 void setup_action_cycle_windows_next(ObAction **a, ObUserAction uact)
282 (*a)->data.cycle.inter.any.interactive = TRUE;
283 (*a)->data.cycle.linear = FALSE;
284 (*a)->data.cycle.forward = TRUE;
287 void setup_action_cycle_windows_previous(ObAction **a, ObUserAction uact)
289 (*a)->data.cycle.inter.any.interactive = TRUE;
290 (*a)->data.cycle.linear = FALSE;
291 (*a)->data.cycle.forward = FALSE;
294 void setup_action_movetoedge_north(ObAction **a, ObUserAction uact)
296 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
297 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
300 void setup_action_movetoedge_south(ObAction **a, ObUserAction uact)
302 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
303 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
306 void setup_action_movetoedge_east(ObAction **a, ObUserAction uact)
308 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
309 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
312 void setup_action_movetoedge_west(ObAction **a, ObUserAction uact)
314 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
315 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
318 void setup_action_growtoedge_north(ObAction **a, ObUserAction uact)
320 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
321 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
324 void setup_action_growtoedge_south(ObAction **a, ObUserAction uact)
326 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
327 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
330 void setup_action_growtoedge_east(ObAction **a, ObUserAction uact)
332 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
333 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
336 void setup_action_growtoedge_west(ObAction **a, ObUserAction uact)
338 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
339 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
342 void setup_action_top_layer(ObAction **a, ObUserAction uact)
344 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
345 (*a)->data.layer.layer = 1;
348 void setup_action_normal_layer(ObAction **a, ObUserAction uact)
350 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
351 (*a)->data.layer.layer = 0;
354 void setup_action_bottom_layer(ObAction **a, ObUserAction uact)
356 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
357 (*a)->data.layer.layer = -1;
360 void setup_action_move(ObAction **a, ObUserAction uact)
362 (*a)->data.moveresize.any.client_action = OB_CLIENT_ACTION_ALWAYS;
363 (*a)->data.moveresize.move = TRUE;
364 (*a)->data.moveresize.keyboard =
365 (uact == OB_USER_ACTION_NONE ||
366 uact == OB_USER_ACTION_KEYBOARD_KEY ||
367 uact == OB_USER_ACTION_MENU_SELECTION);
370 void setup_action_resize(ObAction **a, ObUserAction uact)
372 (*a)->data.moveresize.any.client_action = OB_CLIENT_ACTION_ALWAYS;
373 (*a)->data.moveresize.move = FALSE;
374 (*a)->data.moveresize.keyboard =
375 (uact == OB_USER_ACTION_NONE ||
376 uact == OB_USER_ACTION_KEYBOARD_KEY ||
377 uact == OB_USER_ACTION_MENU_SELECTION);
380 void setup_action_showmenu(ObAction **a, ObUserAction uact)
382 (*a)->data.showmenu.any.client_action = OB_CLIENT_ACTION_OPTIONAL;
383 /* you cannot call ShowMenu from inside a menu, cuz the menu code makes
384 assumptions that there is only one menu (and submenus) open at
386 if (uact == OB_USER_ACTION_MENU_SELECTION) {
392 void setup_client_action(ObAction **a, ObUserAction uact)
394 (*a)->data.any.client_action = OB_CLIENT_ACTION_ALWAYS;
397 ActionString actionstrings[] =
405 "directionalfocusnorth",
406 action_directional_focus,
407 setup_action_directional_focus_north
410 "directionalfocuseast",
411 action_directional_focus,
412 setup_action_directional_focus_east
415 "directionalfocussouth",
416 action_directional_focus,
417 setup_action_directional_focus_south
420 "directionalfocuswest",
421 action_directional_focus,
422 setup_action_directional_focus_west
425 "directionalfocusnortheast",
426 action_directional_focus,
427 setup_action_directional_focus_northeast
430 "directionalfocussoutheast",
431 action_directional_focus,
432 setup_action_directional_focus_southeast
435 "directionalfocussouthwest",
436 action_directional_focus,
437 setup_action_directional_focus_southwest
440 "directionalfocusnorthwest",
441 action_directional_focus,
442 setup_action_directional_focus_northwest
516 action_toggle_omnipresent,
521 action_move_relative_horz,
526 action_move_relative_vert,
530 "resizerelativehorz",
531 action_resize_relative_horz,
535 "resizerelativevert",
536 action_resize_relative_vert,
541 action_maximize_full,
546 action_unmaximize_full,
550 "togglemaximizefull",
551 action_toggle_maximize_full,
556 action_maximize_horz,
561 action_unmaximize_horz,
565 "togglemaximizehorz",
566 action_toggle_maximize_horz,
571 action_maximize_vert,
576 action_unmaximize_vert,
580 "togglemaximizevert",
581 action_toggle_maximize_vert,
586 action_send_to_desktop,
587 setup_action_send_to_desktop
591 action_send_to_desktop_dir,
592 setup_action_send_to_desktop_next
595 "sendtodesktopprevious",
596 action_send_to_desktop_dir,
597 setup_action_send_to_desktop_prev
600 "sendtodesktopright",
601 action_send_to_desktop_dir,
602 setup_action_send_to_desktop_right
606 action_send_to_desktop_dir,
607 setup_action_send_to_desktop_left
611 action_send_to_desktop_dir,
612 setup_action_send_to_desktop_up
616 action_send_to_desktop_dir,
617 setup_action_send_to_desktop_down
627 setup_action_desktop_next
632 setup_action_desktop_prev
637 setup_action_desktop_right
642 setup_action_desktop_left
647 setup_action_desktop_up
652 setup_action_desktop_down
656 action_toggle_decorations,
671 action_toggle_show_desktop,
681 action_unshow_desktop,
707 setup_action_showmenu
711 action_send_to_layer,
712 setup_action_top_layer
717 setup_action_top_layer
721 action_send_to_layer,
722 setup_action_normal_layer
726 action_send_to_layer,
727 setup_action_bottom_layer
730 "togglealwaysonbottom",
732 setup_action_bottom_layer
736 action_cycle_windows,
737 setup_action_cycle_windows_next
741 action_cycle_windows,
742 setup_action_cycle_windows_previous
747 setup_action_movetoedge_north
752 setup_action_movetoedge_south
757 setup_action_movetoedge_west
762 setup_action_movetoedge_east
767 setup_action_growtoedge_north
772 setup_action_growtoedge_south
777 setup_action_growtoedge_west
782 setup_action_growtoedge_east
791 ObAction *action_from_string(const gchar *name, ObUserAction uact)
794 gboolean exist = FALSE;
797 for (i = 0; actionstrings[i].name; i++)
798 if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
800 a = action_new(actionstrings[i].func);
801 if (actionstrings[i].setup)
802 actionstrings[i].setup(&a, uact);
803 /* only key bindings can be interactive. thus saith the xor.
804 because of how the mouse is grabbed, mouse events dont even get
805 read during interactive events, so no dice! >:) */
806 if (uact != OB_USER_ACTION_KEYBOARD_KEY)
807 a->data.any.interactive = FALSE;
811 g_warning("Invalid action '%s' requested. No such action exists.",
814 g_warning("Invalid use of action '%s'. Action will be ignored.", name);
818 ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
822 ObAction *act = NULL;
825 if (parse_attr_string("name", node, &actname)) {
826 if ((act = action_from_string(actname, uact))) {
827 if (act->func == action_execute || act->func == action_restart) {
828 if ((n = parse_find_node("execute", node->xmlChildrenNode))) {
829 gchar *s = parse_string(doc, n);
830 act->data.execute.path = parse_expand_tilde(s);
833 } else if (act->func == action_showmenu) {
834 if ((n = parse_find_node("menu", node->xmlChildrenNode)))
835 act->data.showmenu.name = parse_string(doc, n);
836 } else if (act->func == action_move_relative_horz ||
837 act->func == action_move_relative_vert ||
838 act->func == action_resize_relative_horz ||
839 act->func == action_resize_relative_vert) {
840 if ((n = parse_find_node("delta", node->xmlChildrenNode)))
841 act->data.relative.delta = parse_int(doc, n);
842 } else if (act->func == action_desktop) {
843 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
844 act->data.desktop.desk = parse_int(doc, n);
845 if (act->data.desktop.desk > 0) act->data.desktop.desk--;
846 } else if (act->func == action_send_to_desktop) {
847 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
848 act->data.sendto.desk = parse_int(doc, n);
849 if (act->data.sendto.desk > 0) act->data.sendto.desk--;
850 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
851 act->data.sendto.follow = parse_bool(doc, n);
852 } else if (act->func == action_desktop_dir) {
853 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
854 act->data.desktopdir.wrap = parse_bool(doc, n);
855 } else if (act->func == action_send_to_desktop_dir) {
856 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
857 act->data.sendtodir.wrap = parse_bool(doc, n);
858 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
859 act->data.sendtodir.follow = parse_bool(doc, n);
860 } else if (act->func == action_activate) {
861 if ((n = parse_find_node("here", node->xmlChildrenNode)))
862 act->data.activate.here = parse_bool(doc, n);
863 } else if (act->func == action_cycle_windows) {
864 if ((n = parse_find_node("linear", node->xmlChildrenNode)))
865 act->data.cycle.linear = parse_bool(doc, n);
873 void action_run_list(GSList *acts, ObClient *c, ObFrameContext context,
874 guint state, guint button, gint x, gint y,
875 gboolean cancel, gboolean done)
879 gboolean inter = FALSE;
885 screen_pointer_pos(&x, &y);
887 if (grab_on_keyboard())
890 for (it = acts; it; it = g_slist_next(it)) {
892 if (a->data.any.interactive) {
899 /* sometimes when we execute another app as an action,
900 it won't work right unless we XUngrabKeyboard first,
901 even though we grabbed the key/button Asychronously.
902 e.g. "gnome-panel-control --main-menu" */
903 XUngrabKeyboard(ob_display, event_lasttime);
906 for (it = acts; it; it = g_slist_next(it)) {
909 if (!(a->data.any.client_action == OB_CLIENT_ACTION_ALWAYS && !c)) {
910 a->data.any.c = a->data.any.client_action ? c : NULL;
911 a->data.any.context = context;
915 a->data.any.button = button;
917 if (a->data.any.interactive) {
918 a->data.inter.cancel = cancel;
919 a->data.inter.final = done;
920 if (!(cancel || done))
921 keyboard_interactive_grab(state, a->data.any.c, a);
924 ob_main_loop_queue_action(ob_main_loop, a);
929 void action_run_string(const gchar *name, struct _ObClient *c)
934 a = action_from_string(name, OB_USER_ACTION_NONE);
937 l = g_slist_append(NULL, a);
942 void action_execute(union ActionData *data)
946 if (data->execute.path) {
947 cmd = g_filename_from_utf8(data->execute.path, -1, NULL, NULL, NULL);
949 if (!g_spawn_command_line_async(cmd, &e)) {
950 g_warning("failed to execute '%s': %s",
955 g_warning("failed to convert '%s' from utf8", data->execute.path);
960 void action_activate(union ActionData *data)
962 client_activate(data->activate.any.c, data->activate.here);
965 void action_focus(union ActionData *data)
967 client_focus(data->client.any.c);
970 void action_unfocus (union ActionData *data)
972 client_unfocus(data->client.any.c);
975 void action_iconify(union ActionData *data)
977 client_iconify(data->client.any.c, TRUE, TRUE);
980 void action_raiselower(union ActionData *data)
982 ObClient *c = data->client.any.c;
984 gboolean raise = FALSE;
986 for (it = stacking_list; it; it = g_list_next(it)) {
987 ObClient *cit = it->data;
990 if (client_normal(cit) == client_normal(c) &&
991 cit->layer == c->layer &&
992 cit->frame->visible &&
993 !client_search_transient(c, cit))
995 if (RECT_INTERSECTS_RECT(cit->frame->area, c->frame->area)) {
1003 client_action_start(data);
1004 stacking_raise(CLIENT_AS_WINDOW(c));
1005 client_action_end(data);
1007 client_action_start(data);
1008 stacking_lower(CLIENT_AS_WINDOW(c));
1009 client_action_end(data);
1013 void action_raise(union ActionData *data)
1015 client_action_start(data);
1016 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
1017 client_action_end(data);
1020 void action_unshaderaise(union ActionData *data)
1022 if (data->client.any.c->shaded) {
1023 client_action_start(data);
1024 client_shade(data->client.any.c, FALSE);
1025 client_action_end(data);
1027 client_action_start(data);
1028 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
1029 client_action_end(data);
1033 void action_shadelower(union ActionData *data)
1035 if (data->client.any.c->shaded)
1036 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
1038 client_action_start(data);
1039 client_shade(data->client.any.c, TRUE);
1040 client_action_end(data);
1044 void action_lower(union ActionData *data)
1046 client_action_start(data);
1047 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
1048 client_action_end(data);
1051 void action_close(union ActionData *data)
1053 client_close(data->client.any.c);
1056 void action_kill(union ActionData *data)
1058 client_kill(data->client.any.c);
1061 void action_shade(union ActionData *data)
1063 client_action_start(data);
1064 client_shade(data->client.any.c, TRUE);
1065 client_action_end(data);
1068 void action_unshade(union ActionData *data)
1070 client_action_start(data);
1071 client_shade(data->client.any.c, FALSE);
1072 client_action_end(data);
1075 void action_toggle_shade(union ActionData *data)
1077 client_action_start(data);
1078 client_shade(data->client.any.c, !data->client.any.c->shaded);
1079 client_action_end(data);
1082 void action_toggle_omnipresent(union ActionData *data)
1084 client_set_desktop(data->client.any.c,
1085 data->client.any.c->desktop == DESKTOP_ALL ?
1086 screen_desktop : DESKTOP_ALL, FALSE);
1089 void action_move_relative_horz(union ActionData *data)
1091 ObClient *c = data->relative.any.c;
1092 client_action_start(data);
1093 client_move(c, c->area.x + data->relative.delta, c->area.y);
1094 client_action_end(data);
1097 void action_move_relative_vert(union ActionData *data)
1099 ObClient *c = data->relative.any.c;
1100 client_action_start(data);
1101 client_move(c, c->area.x, c->area.y + data->relative.delta);
1102 client_action_end(data);
1105 void action_resize_relative_horz(union ActionData *data)
1107 ObClient *c = data->relative.any.c;
1108 client_action_start(data);
1110 c->area.width + data->relative.delta * c->size_inc.width,
1112 client_action_end(data);
1115 void action_resize_relative_vert(union ActionData *data)
1117 ObClient *c = data->relative.any.c;
1119 client_action_start(data);
1120 client_resize(c, c->area.width, c->area.height +
1121 data->relative.delta * c->size_inc.height);
1122 client_action_end(data);
1126 void action_maximize_full(union ActionData *data)
1128 client_action_start(data);
1129 client_maximize(data->client.any.c, TRUE, 0, TRUE);
1130 client_action_end(data);
1133 void action_unmaximize_full(union ActionData *data)
1135 client_action_start(data);
1136 client_maximize(data->client.any.c, FALSE, 0, TRUE);
1137 client_action_end(data);
1140 void action_toggle_maximize_full(union ActionData *data)
1142 client_action_start(data);
1143 client_maximize(data->client.any.c,
1144 !(data->client.any.c->max_horz ||
1145 data->client.any.c->max_vert),
1147 client_action_end(data);
1150 void action_maximize_horz(union ActionData *data)
1152 client_action_start(data);
1153 client_maximize(data->client.any.c, TRUE, 1, TRUE);
1154 client_action_end(data);
1157 void action_unmaximize_horz(union ActionData *data)
1159 client_action_start(data);
1160 client_maximize(data->client.any.c, FALSE, 1, TRUE);
1161 client_action_end(data);
1164 void action_toggle_maximize_horz(union ActionData *data)
1166 client_action_start(data);
1167 client_maximize(data->client.any.c,
1168 !data->client.any.c->max_horz, 1, TRUE);
1169 client_action_end(data);
1172 void action_maximize_vert(union ActionData *data)
1174 client_action_start(data);
1175 client_maximize(data->client.any.c, TRUE, 2, TRUE);
1176 client_action_end(data);
1179 void action_unmaximize_vert(union ActionData *data)
1181 client_action_start(data);
1182 client_maximize(data->client.any.c, FALSE, 2, TRUE);
1183 client_action_end(data);
1186 void action_toggle_maximize_vert(union ActionData *data)
1188 client_action_start(data);
1189 client_maximize(data->client.any.c,
1190 !data->client.any.c->max_vert, 2, TRUE);
1191 client_action_end(data);
1194 void action_send_to_desktop(union ActionData *data)
1196 ObClient *c = data->sendto.any.c;
1198 if (!client_normal(c)) return;
1200 if (data->sendto.desk < screen_num_desktops ||
1201 data->sendto.desk == DESKTOP_ALL) {
1202 client_set_desktop(c, data->sendto.desk, data->sendto.follow);
1203 if (data->sendto.follow)
1204 screen_set_desktop(data->sendto.desk);
1208 void action_desktop(union ActionData *data)
1210 static guint first = (unsigned) -1;
1212 if (data->inter.any.interactive && first == (unsigned) -1)
1213 first = screen_desktop;
1215 if (!data->inter.any.interactive ||
1216 (!data->inter.cancel && !data->inter.final))
1218 if (data->desktop.desk < screen_num_desktops ||
1219 data->desktop.desk == DESKTOP_ALL)
1221 screen_set_desktop(data->desktop.desk);
1222 if (data->inter.any.interactive)
1223 screen_desktop_popup(data->desktop.desk, TRUE);
1225 } else if (data->inter.cancel) {
1226 screen_set_desktop(first);
1229 if (data->inter.any.interactive && data->inter.final) {
1230 screen_desktop_popup(0, FALSE);
1231 first = (unsigned) -1;
1235 void action_desktop_dir(union ActionData *data)
1239 d = screen_cycle_desktop(data->desktopdir.dir,
1240 data->desktopdir.wrap,
1241 data->sendtodir.linear,
1242 data->desktopdir.inter.any.interactive,
1243 data->desktopdir.inter.final,
1244 data->desktopdir.inter.cancel);
1245 if (!data->sendtodir.inter.any.interactive ||
1246 !data->sendtodir.inter.final)
1248 screen_set_desktop(d);
1252 void action_send_to_desktop_dir(union ActionData *data)
1254 ObClient *c = data->sendtodir.inter.any.c;
1257 if (!client_normal(c)) return;
1259 d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
1260 data->sendtodir.linear,
1261 data->sendtodir.inter.any.interactive,
1262 data->sendtodir.inter.final,
1263 data->sendtodir.inter.cancel);
1264 if (!data->sendtodir.inter.any.interactive ||
1265 !data->sendtodir.inter.final)
1267 client_set_desktop(c, d, data->sendtodir.follow);
1268 if (data->sendtodir.follow)
1269 screen_set_desktop(d);
1273 void action_desktop_last(union ActionData *data)
1275 screen_set_desktop(screen_last_desktop);
1278 void action_toggle_decorations(union ActionData *data)
1280 ObClient *c = data->client.any.c;
1282 client_action_start(data);
1283 client_set_undecorated(c, !c->undecorated);
1284 client_action_end(data);
1287 static guint32 pick_corner(int x, int y, int cx, int cy, int cw, int ch)
1289 if (x - cx > cw / 2) {
1290 if (y - cy > ch / 2)
1291 return prop_atoms.net_wm_moveresize_size_bottomright;
1293 return prop_atoms.net_wm_moveresize_size_topright;
1295 if (y - cy > ch / 2)
1296 return prop_atoms.net_wm_moveresize_size_bottomleft;
1298 return prop_atoms.net_wm_moveresize_size_topleft;
1302 void action_moveresize(union ActionData *data)
1304 ObClient *c = data->moveresize.any.c;
1307 if (!client_normal(c)) return;
1309 if (data->moveresize.keyboard) {
1310 corner = (data->moveresize.move ?
1311 prop_atoms.net_wm_moveresize_move_keyboard :
1312 prop_atoms.net_wm_moveresize_size_keyboard);
1314 corner = (data->moveresize.move ?
1315 prop_atoms.net_wm_moveresize_move :
1316 pick_corner(data->any.x, data->any.y,
1317 c->frame->area.x, c->frame->area.y,
1318 /* use the client size because the frame
1319 can be differently sized (shaded
1320 windows) and we want this based on the
1322 c->area.width + c->frame->size.left +
1323 c->frame->size.right,
1324 c->area.height + c->frame->size.top +
1325 c->frame->size.bottom));
1328 moveresize_start(c, data->any.x, data->any.y, data->any.button, corner);
1331 void action_reconfigure(union ActionData *data)
1336 void action_restart(union ActionData *data)
1338 ob_restart_other(data->execute.path);
1341 void action_exit(union ActionData *data)
1346 void action_showmenu(union ActionData *data)
1348 if (data->showmenu.name) {
1349 menu_show(data->showmenu.name, data->any.x, data->any.y,
1350 data->showmenu.any.c);
1354 void action_cycle_windows(union ActionData *data)
1356 focus_cycle(data->cycle.forward, data->cycle.linear,
1357 data->cycle.inter.any.interactive,
1358 data->cycle.inter.final, data->cycle.inter.cancel);
1361 void action_directional_focus(union ActionData *data)
1363 focus_directional_cycle(data->interdiraction.direction,
1364 data->interdiraction.inter.any.interactive,
1365 data->interdiraction.inter.final,
1366 data->interdiraction.inter.cancel);
1369 void action_movetoedge(union ActionData *data)
1372 ObClient *c = data->diraction.any.c;
1374 x = c->frame->area.x;
1375 y = c->frame->area.y;
1377 switch(data->diraction.direction) {
1378 case OB_DIRECTION_NORTH:
1379 y = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1381 case OB_DIRECTION_WEST:
1382 x = client_directional_edge_search(c, OB_DIRECTION_WEST);
1384 case OB_DIRECTION_SOUTH:
1385 y = client_directional_edge_search(c, OB_DIRECTION_SOUTH) -
1386 c->frame->area.height;
1388 case OB_DIRECTION_EAST:
1389 x = client_directional_edge_search(c, OB_DIRECTION_EAST) -
1390 c->frame->area.width;
1393 g_assert_not_reached();
1395 frame_frame_gravity(c->frame, &x, &y);
1396 client_action_start(data);
1397 client_move(c, x, y);
1398 client_action_end(data);
1401 void action_growtoedge(union ActionData *data)
1403 int x, y, width, height, dest;
1404 ObClient *c = data->diraction.any.c;
1407 a = screen_area(c->desktop);
1408 x = c->frame->area.x;
1409 y = c->frame->area.y;
1410 width = c->frame->area.width;
1411 height = c->frame->area.height;
1413 switch(data->diraction.direction) {
1414 case OB_DIRECTION_NORTH:
1415 dest = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1417 height = c->frame->area.height / 2;
1419 height = c->frame->area.y + c->frame->area.height - dest;
1423 case OB_DIRECTION_WEST:
1424 dest = client_directional_edge_search(c, OB_DIRECTION_WEST);
1426 width = c->frame->area.width / 2;
1428 width = c->frame->area.x + c->frame->area.width - dest;
1432 case OB_DIRECTION_SOUTH:
1433 dest = client_directional_edge_search(c, OB_DIRECTION_SOUTH);
1434 if (a->y + a->height == y + c->frame->area.height) {
1435 height = c->frame->area.height / 2;
1436 y = a->y + a->height - height;
1438 height = dest - c->frame->area.y;
1439 y += (height - c->frame->area.height) % c->size_inc.height;
1440 height -= (height - c->frame->area.height) % c->size_inc.height;
1442 case OB_DIRECTION_EAST:
1443 dest = client_directional_edge_search(c, OB_DIRECTION_EAST);
1444 if (a->x + a->width == x + c->frame->area.width) {
1445 width = c->frame->area.width / 2;
1446 x = a->x + a->width - width;
1448 width = dest - c->frame->area.x;
1449 x += (width - c->frame->area.width) % c->size_inc.width;
1450 width -= (width - c->frame->area.width) % c->size_inc.width;
1453 g_assert_not_reached();
1455 frame_frame_gravity(c->frame, &x, &y);
1456 width -= c->frame->size.left + c->frame->size.right;
1457 height -= c->frame->size.top + c->frame->size.bottom;
1458 client_action_start(data);
1459 client_move_resize(c, x, y, width, height);
1460 client_action_end(data);
1463 void action_send_to_layer(union ActionData *data)
1465 client_set_layer(data->layer.any.c, data->layer.layer);
1468 void action_toggle_layer(union ActionData *data)
1470 ObClient *c = data->layer.any.c;
1472 client_action_start(data);
1473 if (data->layer.layer < 0)
1474 client_set_layer(c, c->below ? 0 : -1);
1475 else if (data->layer.layer > 0)
1476 client_set_layer(c, c->above ? 0 : 1);
1477 client_action_end(data);
1480 void action_toggle_show_desktop(union ActionData *data)
1482 screen_show_desktop(!screen_showing_desktop);
1485 void action_show_desktop(union ActionData *data)
1487 screen_show_desktop(TRUE);
1490 void action_unshow_desktop(union ActionData *data)
1492 screen_show_desktop(FALSE);