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"
38 inline void client_action_start(union ActionData *data)
40 if (config_focus_follow)
41 if (data->any.context != OB_FRAME_CONTEXT_CLIENT && !data->any.button)
42 grab_pointer(TRUE, OB_CURSOR_NONE);
45 inline void client_action_end(union ActionData *data)
47 if (config_focus_follow)
48 if (data->any.context != OB_FRAME_CONTEXT_CLIENT) {
49 if (!data->any.button) {
50 grab_pointer(FALSE, OB_CURSOR_NONE);
54 /* usually this is sorta redundant, but with a press action
55 the enter event will come as a GrabNotify which is
56 ignored, so this will handle that case */
57 if ((c = client_under_pointer()))
58 event_enter_client(c);
66 void (*func)(union ActionData *);
67 void (*setup)(ObAction **, ObUserAction uact);
70 static ObAction *action_new(void (*func)(union ActionData *data))
72 ObAction *a = g_new0(ObAction, 1);
79 void action_ref(ObAction *a)
84 void action_unref(ObAction *a)
86 if (a == NULL) return;
88 if (--a->ref > 0) return;
90 /* deal with pointers */
91 if (a->func == action_execute || a->func == action_restart)
92 g_free(a->data.execute.path);
93 else if (a->func == action_showmenu)
94 g_free(a->data.showmenu.name);
99 ObAction* action_copy(const ObAction *src)
101 ObAction *a = action_new(src->func);
105 /* deal with pointers */
106 if (a->func == action_execute || a->func == action_restart)
107 a->data.execute.path = g_strdup(a->data.execute.path);
108 else if (a->func == action_showmenu)
109 a->data.showmenu.name = g_strdup(a->data.showmenu.name);
114 void setup_action_directional_focus_north(ObAction **a, ObUserAction uact)
116 (*a)->data.interdiraction.inter.any.interactive = TRUE;
117 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTH;
118 (*a)->data.interdiraction.dialog = TRUE;
121 void setup_action_directional_focus_east(ObAction **a, ObUserAction uact)
123 (*a)->data.interdiraction.inter.any.interactive = TRUE;
124 (*a)->data.interdiraction.direction = OB_DIRECTION_EAST;
125 (*a)->data.interdiraction.dialog = TRUE;
128 void setup_action_directional_focus_south(ObAction **a, ObUserAction uact)
130 (*a)->data.interdiraction.inter.any.interactive = TRUE;
131 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTH;
132 (*a)->data.interdiraction.dialog = TRUE;
135 void setup_action_directional_focus_west(ObAction **a, ObUserAction uact)
137 (*a)->data.interdiraction.inter.any.interactive = TRUE;
138 (*a)->data.interdiraction.direction = OB_DIRECTION_WEST;
139 (*a)->data.interdiraction.dialog = TRUE;
142 void setup_action_directional_focus_northeast(ObAction **a, ObUserAction uact)
144 (*a)->data.interdiraction.inter.any.interactive = TRUE;
145 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHEAST;
146 (*a)->data.interdiraction.dialog = TRUE;
149 void setup_action_directional_focus_southeast(ObAction **a, ObUserAction uact)
151 (*a)->data.interdiraction.inter.any.interactive = TRUE;
152 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHEAST;
153 (*a)->data.interdiraction.dialog = TRUE;
156 void setup_action_directional_focus_southwest(ObAction **a, ObUserAction uact)
158 (*a)->data.interdiraction.inter.any.interactive = TRUE;
159 (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHWEST;
160 (*a)->data.interdiraction.dialog = TRUE;
163 void setup_action_directional_focus_northwest(ObAction **a, ObUserAction uact)
165 (*a)->data.interdiraction.inter.any.interactive = TRUE;
166 (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHWEST;
167 (*a)->data.interdiraction.dialog = TRUE;
170 void setup_action_send_to_desktop(ObAction **a, ObUserAction uact)
172 (*a)->data.sendto.any.client_action = OB_CLIENT_ACTION_ALWAYS;
173 (*a)->data.sendto.follow = TRUE;
176 void setup_action_send_to_desktop_prev(ObAction **a, ObUserAction uact)
178 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
179 (*a)->data.sendtodir.inter.any.interactive = TRUE;
180 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
181 (*a)->data.sendtodir.linear = TRUE;
182 (*a)->data.sendtodir.wrap = TRUE;
183 (*a)->data.sendtodir.follow = TRUE;
186 void setup_action_send_to_desktop_next(ObAction **a, ObUserAction uact)
188 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
189 (*a)->data.sendtodir.inter.any.interactive = TRUE;
190 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
191 (*a)->data.sendtodir.linear = TRUE;
192 (*a)->data.sendtodir.wrap = TRUE;
193 (*a)->data.sendtodir.follow = TRUE;
196 void setup_action_send_to_desktop_left(ObAction **a, ObUserAction uact)
198 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
199 (*a)->data.sendtodir.inter.any.interactive = TRUE;
200 (*a)->data.sendtodir.dir = OB_DIRECTION_WEST;
201 (*a)->data.sendtodir.linear = FALSE;
202 (*a)->data.sendtodir.wrap = TRUE;
203 (*a)->data.sendtodir.follow = TRUE;
206 void setup_action_send_to_desktop_right(ObAction **a, ObUserAction uact)
208 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
209 (*a)->data.sendtodir.inter.any.interactive = TRUE;
210 (*a)->data.sendtodir.dir = OB_DIRECTION_EAST;
211 (*a)->data.sendtodir.linear = FALSE;
212 (*a)->data.sendtodir.wrap = TRUE;
213 (*a)->data.sendtodir.follow = TRUE;
216 void setup_action_send_to_desktop_up(ObAction **a, ObUserAction uact)
218 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
219 (*a)->data.sendtodir.inter.any.interactive = TRUE;
220 (*a)->data.sendtodir.dir = OB_DIRECTION_NORTH;
221 (*a)->data.sendtodir.linear = FALSE;
222 (*a)->data.sendtodir.wrap = TRUE;
223 (*a)->data.sendtodir.follow = TRUE;
226 void setup_action_send_to_desktop_down(ObAction **a, ObUserAction uact)
228 (*a)->data.sendtodir.inter.any.client_action = OB_CLIENT_ACTION_ALWAYS;
229 (*a)->data.sendtodir.inter.any.interactive = TRUE;
230 (*a)->data.sendtodir.dir = OB_DIRECTION_SOUTH;
231 (*a)->data.sendtodir.linear = FALSE;
232 (*a)->data.sendtodir.wrap = TRUE;
233 (*a)->data.sendtodir.follow = TRUE;
236 void setup_action_desktop(ObAction **a, ObUserAction uact)
238 (*a)->data.desktop.inter.any.interactive = FALSE;
241 void setup_action_desktop_prev(ObAction **a, ObUserAction uact)
243 (*a)->data.desktopdir.inter.any.interactive = TRUE;
244 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
245 (*a)->data.desktopdir.linear = TRUE;
246 (*a)->data.desktopdir.wrap = TRUE;
249 void setup_action_desktop_next(ObAction **a, ObUserAction uact)
251 (*a)->data.desktopdir.inter.any.interactive = TRUE;
252 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
253 (*a)->data.desktopdir.linear = TRUE;
254 (*a)->data.desktopdir.wrap = TRUE;
257 void setup_action_desktop_left(ObAction **a, ObUserAction uact)
259 (*a)->data.desktopdir.inter.any.interactive = TRUE;
260 (*a)->data.desktopdir.dir = OB_DIRECTION_WEST;
261 (*a)->data.desktopdir.linear = FALSE;
262 (*a)->data.desktopdir.wrap = TRUE;
265 void setup_action_desktop_right(ObAction **a, ObUserAction uact)
267 (*a)->data.desktopdir.inter.any.interactive = TRUE;
268 (*a)->data.desktopdir.dir = OB_DIRECTION_EAST;
269 (*a)->data.desktopdir.linear = FALSE;
270 (*a)->data.desktopdir.wrap = TRUE;
273 void setup_action_desktop_up(ObAction **a, ObUserAction uact)
275 (*a)->data.desktopdir.inter.any.interactive = TRUE;
276 (*a)->data.desktopdir.dir = OB_DIRECTION_NORTH;
277 (*a)->data.desktopdir.linear = FALSE;
278 (*a)->data.desktopdir.wrap = TRUE;
281 void setup_action_desktop_down(ObAction **a, ObUserAction uact)
283 (*a)->data.desktopdir.inter.any.interactive = TRUE;
284 (*a)->data.desktopdir.dir = OB_DIRECTION_SOUTH;
285 (*a)->data.desktopdir.linear = FALSE;
286 (*a)->data.desktopdir.wrap = TRUE;
289 void setup_action_cycle_windows_next(ObAction **a, ObUserAction uact)
291 (*a)->data.cycle.inter.any.interactive = TRUE;
292 (*a)->data.cycle.linear = FALSE;
293 (*a)->data.cycle.forward = TRUE;
294 (*a)->data.cycle.dialog = TRUE;
297 void setup_action_cycle_windows_previous(ObAction **a, ObUserAction uact)
299 (*a)->data.cycle.inter.any.interactive = TRUE;
300 (*a)->data.cycle.linear = FALSE;
301 (*a)->data.cycle.forward = FALSE;
302 (*a)->data.cycle.dialog = TRUE;
305 void setup_action_movetoedge_north(ObAction **a, ObUserAction uact)
307 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
308 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
311 void setup_action_movetoedge_south(ObAction **a, ObUserAction uact)
313 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
314 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
317 void setup_action_movetoedge_east(ObAction **a, ObUserAction uact)
319 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
320 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
323 void setup_action_movetoedge_west(ObAction **a, ObUserAction uact)
325 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
326 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
329 void setup_action_growtoedge_north(ObAction **a, ObUserAction uact)
331 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
332 (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
335 void setup_action_growtoedge_south(ObAction **a, ObUserAction uact)
337 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
338 (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
341 void setup_action_growtoedge_east(ObAction **a, ObUserAction uact)
343 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
344 (*a)->data.diraction.direction = OB_DIRECTION_EAST;
347 void setup_action_growtoedge_west(ObAction **a, ObUserAction uact)
349 (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
350 (*a)->data.diraction.direction = OB_DIRECTION_WEST;
353 void setup_action_top_layer(ObAction **a, ObUserAction uact)
355 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
356 (*a)->data.layer.layer = 1;
359 void setup_action_normal_layer(ObAction **a, ObUserAction uact)
361 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
362 (*a)->data.layer.layer = 0;
365 void setup_action_bottom_layer(ObAction **a, ObUserAction uact)
367 (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
368 (*a)->data.layer.layer = -1;
371 void setup_action_move(ObAction **a, ObUserAction uact)
373 (*a)->data.moveresize.any.client_action = OB_CLIENT_ACTION_ALWAYS;
374 (*a)->data.moveresize.move = TRUE;
375 (*a)->data.moveresize.keyboard =
376 (uact == OB_USER_ACTION_NONE ||
377 uact == OB_USER_ACTION_KEYBOARD_KEY ||
378 uact == OB_USER_ACTION_MENU_SELECTION);
381 void setup_action_resize(ObAction **a, ObUserAction uact)
383 (*a)->data.moveresize.any.client_action = OB_CLIENT_ACTION_ALWAYS;
384 (*a)->data.moveresize.move = FALSE;
385 (*a)->data.moveresize.keyboard =
386 (uact == OB_USER_ACTION_NONE ||
387 uact == OB_USER_ACTION_KEYBOARD_KEY ||
388 uact == OB_USER_ACTION_MENU_SELECTION);
391 void setup_action_showmenu(ObAction **a, ObUserAction uact)
393 (*a)->data.showmenu.any.client_action = OB_CLIENT_ACTION_OPTIONAL;
394 /* you cannot call ShowMenu from inside a menu, cuz the menu code makes
395 assumptions that there is only one menu (and submenus) open at
397 if (uact == OB_USER_ACTION_MENU_SELECTION) {
403 void setup_client_action(ObAction **a, ObUserAction uact)
405 (*a)->data.any.client_action = OB_CLIENT_ACTION_ALWAYS;
408 ActionString actionstrings[] =
416 "directionalfocusnorth",
417 action_directional_focus,
418 setup_action_directional_focus_north
421 "directionalfocuseast",
422 action_directional_focus,
423 setup_action_directional_focus_east
426 "directionalfocussouth",
427 action_directional_focus,
428 setup_action_directional_focus_south
431 "directionalfocuswest",
432 action_directional_focus,
433 setup_action_directional_focus_west
436 "directionalfocusnortheast",
437 action_directional_focus,
438 setup_action_directional_focus_northeast
441 "directionalfocussoutheast",
442 action_directional_focus,
443 setup_action_directional_focus_southeast
446 "directionalfocussouthwest",
447 action_directional_focus,
448 setup_action_directional_focus_southwest
451 "directionalfocusnorthwest",
452 action_directional_focus,
453 setup_action_directional_focus_northwest
477 action_focus_order_to_bottom,
532 action_toggle_omnipresent,
537 action_move_relative_horz,
542 action_move_relative_vert,
547 action_move_to_center,
551 "resizerelativehorz",
552 action_resize_relative_horz,
556 "resizerelativevert",
557 action_resize_relative_vert,
562 action_move_relative,
567 action_resize_relative,
572 action_maximize_full,
577 action_unmaximize_full,
581 "togglemaximizefull",
582 action_toggle_maximize_full,
587 action_maximize_horz,
592 action_unmaximize_horz,
596 "togglemaximizehorz",
597 action_toggle_maximize_horz,
602 action_maximize_vert,
607 action_unmaximize_vert,
611 "togglemaximizevert",
612 action_toggle_maximize_vert,
617 action_toggle_fullscreen,
622 action_send_to_desktop,
623 setup_action_send_to_desktop
627 action_send_to_desktop_dir,
628 setup_action_send_to_desktop_next
631 "sendtodesktopprevious",
632 action_send_to_desktop_dir,
633 setup_action_send_to_desktop_prev
636 "sendtodesktopright",
637 action_send_to_desktop_dir,
638 setup_action_send_to_desktop_right
642 action_send_to_desktop_dir,
643 setup_action_send_to_desktop_left
647 action_send_to_desktop_dir,
648 setup_action_send_to_desktop_up
652 action_send_to_desktop_dir,
653 setup_action_send_to_desktop_down
663 setup_action_desktop_next
668 setup_action_desktop_prev
673 setup_action_desktop_right
678 setup_action_desktop_left
683 setup_action_desktop_up
688 setup_action_desktop_down
692 action_toggle_decorations,
706 "toggledockautohide",
707 action_toggle_dockautohide,
712 action_toggle_show_desktop,
722 action_unshow_desktop,
748 setup_action_showmenu
752 action_send_to_layer,
753 setup_action_top_layer
758 setup_action_top_layer
762 action_send_to_layer,
763 setup_action_normal_layer
767 action_send_to_layer,
768 setup_action_bottom_layer
771 "togglealwaysonbottom",
773 setup_action_bottom_layer
777 action_cycle_windows,
778 setup_action_cycle_windows_next
782 action_cycle_windows,
783 setup_action_cycle_windows_previous
788 setup_action_movetoedge_north
793 setup_action_movetoedge_south
798 setup_action_movetoedge_west
803 setup_action_movetoedge_east
808 setup_action_growtoedge_north
813 setup_action_growtoedge_south
818 setup_action_growtoedge_west
823 setup_action_growtoedge_east
832 /* only key bindings can be interactive. thus saith the xor.
833 because of how the mouse is grabbed, mouse events dont even get
834 read during interactive events, so no dice! >:) */
835 #define INTERACTIVE_LIMIT(a, uact) \
836 if (uact != OB_USER_ACTION_KEYBOARD_KEY) \
837 a->data.any.interactive = FALSE;
839 ObAction *action_from_string(const gchar *name, ObUserAction uact)
842 gboolean exist = FALSE;
845 for (i = 0; actionstrings[i].name; i++)
846 if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
848 a = action_new(actionstrings[i].func);
849 if (actionstrings[i].setup)
850 actionstrings[i].setup(&a, uact);
852 INTERACTIVE_LIMIT(a, uact);
856 g_warning("Invalid action '%s' requested. No such action exists.",
859 g_warning("Invalid use of action '%s'. Action will be ignored.", name);
863 ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
867 ObAction *act = NULL;
870 if (parse_attr_string("name", node, &actname)) {
871 if ((act = action_from_string(actname, uact))) {
872 if (act->func == action_execute || act->func == action_restart) {
873 if ((n = parse_find_node("execute", node->xmlChildrenNode))) {
874 gchar *s = parse_string(doc, n);
875 act->data.execute.path = parse_expand_tilde(s);
878 } else if (act->func == action_showmenu) {
879 if ((n = parse_find_node("menu", node->xmlChildrenNode)))
880 act->data.showmenu.name = parse_string(doc, n);
881 } else if (act->func == action_move_relative_horz ||
882 act->func == action_move_relative_vert ||
883 act->func == action_resize_relative_horz ||
884 act->func == action_resize_relative_vert) {
885 if ((n = parse_find_node("delta", node->xmlChildrenNode)))
886 act->data.relative.deltax = parse_int(doc, n);
887 } else if (act->func == action_move_relative) {
888 if ((n = parse_find_node("x", node->xmlChildrenNode)))
889 act->data.relative.deltax = parse_int(doc, n);
890 if ((n = parse_find_node("y", node->xmlChildrenNode)))
891 act->data.relative.deltay = parse_int(doc, n);
892 } else if (act->func == action_resize_relative) {
893 if ((n = parse_find_node("left", node->xmlChildrenNode)))
894 act->data.relative.deltaxl = parse_int(doc, n);
895 if ((n = parse_find_node("up", node->xmlChildrenNode)))
896 act->data.relative.deltayu = parse_int(doc, n);
897 if ((n = parse_find_node("right", node->xmlChildrenNode)))
898 act->data.relative.deltax = parse_int(doc, n);
899 if ((n = parse_find_node("down", node->xmlChildrenNode)))
900 act->data.relative.deltay = parse_int(doc, n);
901 } else if (act->func == action_desktop) {
902 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
903 act->data.desktop.desk = parse_int(doc, n);
904 if (act->data.desktop.desk > 0) act->data.desktop.desk--;
905 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
906 act->data.desktop.inter.any.interactive =
908 } else if (act->func == action_send_to_desktop) {
909 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
910 act->data.sendto.desk = parse_int(doc, n);
911 if (act->data.sendto.desk > 0) act->data.sendto.desk--;
912 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
913 act->data.sendto.follow = parse_bool(doc, n);
914 } else if (act->func == action_desktop_dir) {
915 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
916 act->data.desktopdir.wrap = parse_bool(doc, n);
917 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
918 act->data.desktopdir.inter.any.interactive =
920 } else if (act->func == action_send_to_desktop_dir) {
921 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
922 act->data.sendtodir.wrap = parse_bool(doc, n);
923 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
924 act->data.sendtodir.follow = parse_bool(doc, n);
925 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
926 act->data.sendtodir.inter.any.interactive =
928 } else if (act->func == action_activate) {
929 if ((n = parse_find_node("here", node->xmlChildrenNode)))
930 act->data.activate.here = parse_bool(doc, n);
931 } else if (act->func == action_cycle_windows) {
932 if ((n = parse_find_node("linear", node->xmlChildrenNode)))
933 act->data.cycle.linear = parse_bool(doc, n);
934 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
935 act->data.cycle.dialog = parse_bool(doc, n);
936 } else if (act->func == action_directional_focus) {
937 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
938 act->data.cycle.dialog = parse_bool(doc, n);
939 } else if (act->func == action_raise ||
940 act->func == action_lower ||
941 act->func == action_raiselower ||
942 act->func == action_shadelower ||
943 act->func == action_unshaderaise) {
944 if ((n = parse_find_node("group", node->xmlChildrenNode)))
945 act->data.stacking.group = parse_bool(doc, n);
947 INTERACTIVE_LIMIT(act, uact);
954 void action_run_list(GSList *acts, ObClient *c, ObFrameContext context,
955 guint state, guint button, gint x, gint y,
956 gboolean cancel, gboolean done)
960 gboolean inter = FALSE;
966 screen_pointer_pos(&x, &y);
968 if (grab_on_keyboard())
971 for (it = acts; it; it = g_slist_next(it)) {
973 if (a->data.any.interactive) {
980 /* sometimes when we execute another app as an action,
981 it won't work right unless we XUngrabKeyboard first,
982 even though we grabbed the key/button Asychronously.
983 e.g. "gnome-panel-control --main-menu" */
984 XUngrabKeyboard(ob_display, event_lasttime);
987 for (it = acts; it; it = g_slist_next(it)) {
990 if (!(a->data.any.client_action == OB_CLIENT_ACTION_ALWAYS && !c)) {
991 a->data.any.c = a->data.any.client_action ? c : NULL;
992 a->data.any.context = context;
996 a->data.any.button = button;
998 if (a->data.any.interactive) {
999 a->data.inter.cancel = cancel;
1000 a->data.inter.final = done;
1001 if (!(cancel || done))
1002 if (!keyboard_interactive_grab(state, a->data.any.c, a))
1006 /* XXX UGLY HACK race with motion event starting a move and the
1007 button release gettnig processed first. answer: don't queue
1008 moveresize starts. UGLY HACK XXX */
1009 if (a->data.any.interactive || a->func == action_moveresize) {
1010 /* interactive actions are not queued */
1013 ob_main_loop_queue_action(ob_main_loop, a);
1018 void action_run_string(const gchar *name, struct _ObClient *c)
1023 a = action_from_string(name, OB_USER_ACTION_NONE);
1026 l = g_slist_append(NULL, a);
1028 action_run(l, c, 0);
1031 void action_execute(union ActionData *data)
1034 gchar *cmd, **argv = 0;
1035 if (data->execute.path) {
1036 cmd = g_filename_from_utf8(data->execute.path, -1, NULL, NULL, NULL);
1038 if (!g_shell_parse_argv (cmd, NULL, &argv, &e)) {
1039 g_warning("failed to execute '%s': %s",
1043 if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH |
1044 G_SPAWN_DO_NOT_REAP_CHILD,
1045 NULL, NULL, NULL, &e)) {
1046 g_warning("failed to execute '%s': %s",
1054 g_warning("failed to convert '%s' from utf8", data->execute.path);
1059 void action_activate(union ActionData *data)
1061 client_activate(data->activate.any.c, data->activate.here);
1064 void action_focus(union ActionData *data)
1066 /* if using focus_delay, stop the timer now so that focus doesn't go moving
1068 event_halt_focus_delay();
1070 client_focus(data->client.any.c);
1073 void action_unfocus (union ActionData *data)
1075 if (data->client.any.c == focus_client);
1076 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
1079 void action_iconify(union ActionData *data)
1081 client_action_start(data);
1082 client_iconify(data->client.any.c, TRUE, TRUE);
1083 client_action_end(data);
1086 void action_focus_order_to_bottom(union ActionData *data)
1088 focus_order_to_bottom(data->client.any.c);
1091 void action_raiselower(union ActionData *data)
1093 ObClient *c = data->client.any.c;
1095 gboolean raise = FALSE;
1097 for (it = stacking_list; it; it = g_list_next(it)) {
1098 ObClient *cit = it->data;
1100 if (cit == c) break;
1101 if (client_normal(cit) == client_normal(c) &&
1102 cit->layer == c->layer &&
1103 cit->frame->visible &&
1104 !client_search_transient(c, cit))
1106 if (RECT_INTERSECTS_RECT(cit->frame->area, c->frame->area)) {
1119 void action_raise(union ActionData *data)
1121 client_action_start(data);
1122 stacking_raise(CLIENT_AS_WINDOW(data->client.any.c), data->stacking.group);
1123 client_action_end(data);
1126 void action_unshaderaise(union ActionData *data)
1128 if (data->client.any.c->shaded)
1129 action_unshade(data);
1134 void action_shadelower(union ActionData *data)
1136 if (data->client.any.c->shaded)
1142 void action_lower(union ActionData *data)
1144 client_action_start(data);
1145 stacking_lower(CLIENT_AS_WINDOW(data->client.any.c), data->stacking.group);
1146 client_action_end(data);
1149 void action_close(union ActionData *data)
1151 client_close(data->client.any.c);
1154 void action_kill(union ActionData *data)
1156 client_kill(data->client.any.c);
1159 void action_shade(union ActionData *data)
1161 client_action_start(data);
1162 client_shade(data->client.any.c, TRUE);
1163 client_action_end(data);
1166 void action_unshade(union ActionData *data)
1168 client_action_start(data);
1169 client_shade(data->client.any.c, FALSE);
1170 client_action_end(data);
1173 void action_toggle_shade(union ActionData *data)
1175 client_action_start(data);
1176 client_shade(data->client.any.c, !data->client.any.c->shaded);
1177 client_action_end(data);
1180 void action_toggle_omnipresent(union ActionData *data)
1182 client_set_desktop(data->client.any.c,
1183 data->client.any.c->desktop == DESKTOP_ALL ?
1184 screen_desktop : DESKTOP_ALL, FALSE);
1187 void action_move_relative_horz(union ActionData *data)
1189 ObClient *c = data->relative.any.c;
1190 client_action_start(data);
1191 client_move(c, c->area.x + data->relative.deltax, c->area.y);
1192 client_action_end(data);
1195 void action_move_relative_vert(union ActionData *data)
1197 ObClient *c = data->relative.any.c;
1198 client_action_start(data);
1199 client_move(c, c->area.x, c->area.y + data->relative.deltax);
1200 client_action_end(data);
1203 void action_move_to_center(union ActionData *data)
1205 ObClient *c = data->client.any.c;
1207 area = screen_area_monitor(c->desktop, 0);
1208 client_action_start(data);
1209 client_move(c, area->width / 2 - c->area.width / 2,
1210 area->height / 2 - c->area.height / 2);
1211 client_action_end(data);
1214 void action_resize_relative_horz(union ActionData *data)
1216 ObClient *c = data->relative.any.c;
1217 client_action_start(data);
1219 c->area.width + data->relative.deltax * c->size_inc.width,
1221 client_action_end(data);
1224 void action_resize_relative_vert(union ActionData *data)
1226 ObClient *c = data->relative.any.c;
1228 client_action_start(data);
1229 client_resize(c, c->area.width, c->area.height +
1230 data->relative.deltax * c->size_inc.height);
1231 client_action_end(data);
1235 void action_move_relative(union ActionData *data)
1237 ObClient *c = data->relative.any.c;
1238 client_action_start(data);
1239 client_move(c, c->area.x + data->relative.deltax, c->area.y +
1240 data->relative.deltay);
1241 client_action_end(data);
1244 void action_resize_relative(union ActionData *data)
1246 ObClient *c = data->relative.any.c;
1247 client_action_start(data);
1248 client_move_resize(c,
1249 c->area.x - data->relative.deltaxl * c->size_inc.width,
1250 c->area.y - data->relative.deltayu * c->size_inc.height,
1251 c->area.width + data->relative.deltax * c->size_inc.width
1252 + data->relative.deltaxl * c->size_inc.width,
1253 c->area.height + data->relative.deltay * c->size_inc.height
1254 + data->relative.deltayu * c->size_inc.height);
1255 client_action_end(data);
1258 void action_maximize_full(union ActionData *data)
1260 client_action_start(data);
1261 client_maximize(data->client.any.c, TRUE, 0, TRUE);
1262 client_action_end(data);
1265 void action_unmaximize_full(union ActionData *data)
1267 client_action_start(data);
1268 client_maximize(data->client.any.c, FALSE, 0, TRUE);
1269 client_action_end(data);
1272 void action_toggle_maximize_full(union ActionData *data)
1274 client_action_start(data);
1275 client_maximize(data->client.any.c,
1276 !(data->client.any.c->max_horz ||
1277 data->client.any.c->max_vert),
1279 client_action_end(data);
1282 void action_maximize_horz(union ActionData *data)
1284 client_action_start(data);
1285 client_maximize(data->client.any.c, TRUE, 1, TRUE);
1286 client_action_end(data);
1289 void action_unmaximize_horz(union ActionData *data)
1291 client_action_start(data);
1292 client_maximize(data->client.any.c, FALSE, 1, TRUE);
1293 client_action_end(data);
1296 void action_toggle_maximize_horz(union ActionData *data)
1298 client_action_start(data);
1299 client_maximize(data->client.any.c,
1300 !data->client.any.c->max_horz, 1, TRUE);
1301 client_action_end(data);
1304 void action_maximize_vert(union ActionData *data)
1306 client_action_start(data);
1307 client_maximize(data->client.any.c, TRUE, 2, TRUE);
1308 client_action_end(data);
1311 void action_unmaximize_vert(union ActionData *data)
1313 client_action_start(data);
1314 client_maximize(data->client.any.c, FALSE, 2, TRUE);
1315 client_action_end(data);
1318 void action_toggle_maximize_vert(union ActionData *data)
1320 client_action_start(data);
1321 client_maximize(data->client.any.c,
1322 !data->client.any.c->max_vert, 2, TRUE);
1323 client_action_end(data);
1326 void action_toggle_fullscreen(union ActionData *data)
1328 client_action_start(data);
1329 client_fullscreen(data->client.any.c,
1330 !(data->client.any.c->fullscreen), TRUE);
1331 client_action_end(data);
1334 void action_send_to_desktop(union ActionData *data)
1336 ObClient *c = data->sendto.any.c;
1338 if (!client_normal(c)) return;
1340 if (data->sendto.desk < screen_num_desktops ||
1341 data->sendto.desk == DESKTOP_ALL) {
1342 client_set_desktop(c, data->sendto.desk, data->sendto.follow);
1343 if (data->sendto.follow)
1344 screen_set_desktop(data->sendto.desk);
1348 void action_desktop(union ActionData *data)
1350 static guint first = (unsigned) -1;
1352 if (data->inter.any.interactive && first == (unsigned) -1)
1353 first = screen_desktop;
1355 if (!data->inter.any.interactive ||
1356 (!data->inter.cancel && !data->inter.final))
1358 if (data->desktop.desk < screen_num_desktops ||
1359 data->desktop.desk == DESKTOP_ALL)
1361 screen_set_desktop(data->desktop.desk);
1362 if (data->inter.any.interactive)
1363 screen_desktop_popup(data->desktop.desk, TRUE);
1365 } else if (data->inter.cancel) {
1366 screen_set_desktop(first);
1369 if (!data->inter.any.interactive || data->inter.final) {
1370 screen_desktop_popup(0, FALSE);
1371 first = (unsigned) -1;
1375 void action_desktop_dir(union ActionData *data)
1379 d = screen_cycle_desktop(data->desktopdir.dir,
1380 data->desktopdir.wrap,
1381 data->desktopdir.linear,
1382 data->desktopdir.inter.any.interactive,
1383 data->desktopdir.inter.final,
1384 data->desktopdir.inter.cancel);
1385 if (!data->sendtodir.inter.any.interactive ||
1386 !data->sendtodir.inter.final ||
1387 data->sendtodir.inter.cancel)
1389 screen_set_desktop(d);
1393 void action_send_to_desktop_dir(union ActionData *data)
1395 ObClient *c = data->sendtodir.inter.any.c;
1398 if (!client_normal(c)) return;
1400 d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
1401 data->sendtodir.linear,
1402 data->sendtodir.inter.any.interactive,
1403 data->sendtodir.inter.final,
1404 data->sendtodir.inter.cancel);
1405 if (!data->sendtodir.inter.any.interactive ||
1406 !data->sendtodir.inter.final ||
1407 data->sendtodir.inter.cancel)
1409 client_set_desktop(c, d, data->sendtodir.follow);
1410 if (data->sendtodir.follow)
1411 screen_set_desktop(d);
1415 void action_desktop_last(union ActionData *data)
1417 screen_set_desktop(screen_last_desktop);
1420 void action_toggle_decorations(union ActionData *data)
1422 ObClient *c = data->client.any.c;
1424 client_action_start(data);
1425 client_set_undecorated(c, !c->undecorated);
1426 client_action_end(data);
1429 static guint32 pick_corner(gint x, gint y, gint cx, gint cy, gint cw, gint ch)
1431 if (config_resize_four_corners) {
1432 if (x - cx > cw / 2) {
1433 if (y - cy > ch / 2)
1434 return prop_atoms.net_wm_moveresize_size_bottomright;
1436 return prop_atoms.net_wm_moveresize_size_topright;
1438 if (y - cy > ch / 2)
1439 return prop_atoms.net_wm_moveresize_size_bottomleft;
1441 return prop_atoms.net_wm_moveresize_size_topleft;
1444 if (x - cx > cw * 2 / 3) {
1445 if (y - cy > ch * 2 / 3)
1446 return prop_atoms.net_wm_moveresize_size_bottomright;
1447 else if (y - cy < ch / 3)
1448 return prop_atoms.net_wm_moveresize_size_topright;
1450 return prop_atoms.net_wm_moveresize_size_right;
1451 } else if (x - cx < cw / 3) {
1452 if (y - cy > ch * 2 / 3)
1453 return prop_atoms.net_wm_moveresize_size_bottomleft;
1454 else if (y - cy < ch / 3)
1455 return prop_atoms.net_wm_moveresize_size_topleft;
1457 return prop_atoms.net_wm_moveresize_size_left;
1459 if (y - cy > ch * 2 / 3)
1460 return prop_atoms.net_wm_moveresize_size_bottom;
1461 else if (y - cy < ch / 3)
1462 return prop_atoms.net_wm_moveresize_size_top;
1464 return prop_atoms.net_wm_moveresize_move;
1468 void action_moveresize(union ActionData *data)
1470 ObClient *c = data->moveresize.any.c;
1473 if (!client_normal(c)) return;
1475 if (data->moveresize.keyboard) {
1476 corner = (data->moveresize.move ?
1477 prop_atoms.net_wm_moveresize_move_keyboard :
1478 prop_atoms.net_wm_moveresize_size_keyboard);
1480 corner = (data->moveresize.move ?
1481 prop_atoms.net_wm_moveresize_move :
1482 pick_corner(data->any.x, data->any.y,
1483 c->frame->area.x, c->frame->area.y,
1484 /* use the client size because the frame
1485 can be differently sized (shaded
1486 windows) and we want this based on the
1488 c->area.width + c->frame->size.left +
1489 c->frame->size.right,
1490 c->area.height + c->frame->size.top +
1491 c->frame->size.bottom));
1494 moveresize_start(c, data->any.x, data->any.y, data->any.button, corner);
1497 void action_reconfigure(union ActionData *data)
1502 void action_restart(union ActionData *data)
1504 ob_restart_other(data->execute.path);
1507 void action_exit(union ActionData *data)
1512 void action_showmenu(union ActionData *data)
1514 if (data->showmenu.name) {
1515 menu_show(data->showmenu.name, data->any.x, data->any.y,
1516 data->showmenu.any.c);
1520 void action_cycle_windows(union ActionData *data)
1522 /* if using focus_delay, stop the timer now so that focus doesn't go moving
1524 event_halt_focus_delay();
1526 focus_cycle(data->cycle.forward, data->cycle.linear, data->any.interactive,
1528 data->cycle.inter.final, data->cycle.inter.cancel);
1531 void action_directional_focus(union ActionData *data)
1533 /* if using focus_delay, stop the timer now so that focus doesn't go moving
1535 event_halt_focus_delay();
1537 focus_directional_cycle(data->interdiraction.direction,
1538 data->any.interactive,
1539 data->interdiraction.dialog,
1540 data->interdiraction.inter.final,
1541 data->interdiraction.inter.cancel);
1544 void action_movetoedge(union ActionData *data)
1547 ObClient *c = data->diraction.any.c;
1549 x = c->frame->area.x;
1550 y = c->frame->area.y;
1552 switch(data->diraction.direction) {
1553 case OB_DIRECTION_NORTH:
1554 y = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1556 case OB_DIRECTION_WEST:
1557 x = client_directional_edge_search(c, OB_DIRECTION_WEST);
1559 case OB_DIRECTION_SOUTH:
1560 y = client_directional_edge_search(c, OB_DIRECTION_SOUTH) -
1561 c->frame->area.height;
1563 case OB_DIRECTION_EAST:
1564 x = client_directional_edge_search(c, OB_DIRECTION_EAST) -
1565 c->frame->area.width;
1568 g_assert_not_reached();
1570 frame_frame_gravity(c->frame, &x, &y);
1571 client_action_start(data);
1572 client_move(c, x, y);
1573 client_action_end(data);
1576 void action_growtoedge(union ActionData *data)
1578 gint x, y, width, height, dest;
1579 ObClient *c = data->diraction.any.c;
1582 //FIXME growtoedge resizes shaded windows to 0 height
1586 a = screen_area(c->desktop);
1587 x = c->frame->area.x;
1588 y = c->frame->area.y;
1589 width = c->frame->area.width;
1590 height = c->frame->area.height;
1592 switch(data->diraction.direction) {
1593 case OB_DIRECTION_NORTH:
1594 dest = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1596 height = c->frame->area.height / 2;
1598 height = c->frame->area.y + c->frame->area.height - dest;
1602 case OB_DIRECTION_WEST:
1603 dest = client_directional_edge_search(c, OB_DIRECTION_WEST);
1605 width = c->frame->area.width / 2;
1607 width = c->frame->area.x + c->frame->area.width - dest;
1611 case OB_DIRECTION_SOUTH:
1612 dest = client_directional_edge_search(c, OB_DIRECTION_SOUTH);
1613 if (a->y + a->height == y + c->frame->area.height) {
1614 height = c->frame->area.height / 2;
1615 y = a->y + a->height - height;
1617 height = dest - c->frame->area.y;
1618 y += (height - c->frame->area.height) % c->size_inc.height;
1619 height -= (height - c->frame->area.height) % c->size_inc.height;
1621 case OB_DIRECTION_EAST:
1622 dest = client_directional_edge_search(c, OB_DIRECTION_EAST);
1623 if (a->x + a->width == x + c->frame->area.width) {
1624 width = c->frame->area.width / 2;
1625 x = a->x + a->width - width;
1627 width = dest - c->frame->area.x;
1628 x += (width - c->frame->area.width) % c->size_inc.width;
1629 width -= (width - c->frame->area.width) % c->size_inc.width;
1632 g_assert_not_reached();
1634 frame_frame_gravity(c->frame, &x, &y);
1635 width -= c->frame->size.left + c->frame->size.right;
1636 height -= c->frame->size.top + c->frame->size.bottom;
1637 client_action_start(data);
1638 client_move_resize(c, x, y, width, height);
1639 client_action_end(data);
1642 void action_send_to_layer(union ActionData *data)
1644 client_set_layer(data->layer.any.c, data->layer.layer);
1647 void action_toggle_layer(union ActionData *data)
1649 ObClient *c = data->layer.any.c;
1651 client_action_start(data);
1652 if (data->layer.layer < 0)
1653 client_set_layer(c, c->below ? 0 : -1);
1654 else if (data->layer.layer > 0)
1655 client_set_layer(c, c->above ? 0 : 1);
1656 client_action_end(data);
1659 void action_toggle_dockautohide(union ActionData *data)
1661 config_dock_hide = !config_dock_hide;
1665 void action_toggle_show_desktop(union ActionData *data)
1667 screen_show_desktop(!screen_showing_desktop);
1670 void action_show_desktop(union ActionData *data)
1672 screen_show_desktop(TRUE);
1675 void action_unshow_desktop(union ActionData *data)
1677 screen_show_desktop(FALSE);