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
;
117 (*a
)->data
.interdiraction
.dialog
= TRUE
;
120 void setup_action_directional_focus_east(ObAction
**a
, ObUserAction uact
)
122 (*a
)->data
.interdiraction
.inter
.any
.interactive
= TRUE
;
123 (*a
)->data
.interdiraction
.direction
= OB_DIRECTION_EAST
;
124 (*a
)->data
.interdiraction
.dialog
= TRUE
;
127 void setup_action_directional_focus_south(ObAction
**a
, ObUserAction uact
)
129 (*a
)->data
.interdiraction
.inter
.any
.interactive
= TRUE
;
130 (*a
)->data
.interdiraction
.direction
= OB_DIRECTION_SOUTH
;
131 (*a
)->data
.interdiraction
.dialog
= TRUE
;
134 void setup_action_directional_focus_west(ObAction
**a
, ObUserAction uact
)
136 (*a
)->data
.interdiraction
.inter
.any
.interactive
= TRUE
;
137 (*a
)->data
.interdiraction
.direction
= OB_DIRECTION_WEST
;
138 (*a
)->data
.interdiraction
.dialog
= TRUE
;
141 void setup_action_directional_focus_northeast(ObAction
**a
, ObUserAction uact
)
143 (*a
)->data
.interdiraction
.inter
.any
.interactive
= TRUE
;
144 (*a
)->data
.interdiraction
.direction
= OB_DIRECTION_NORTHEAST
;
145 (*a
)->data
.interdiraction
.dialog
= TRUE
;
148 void setup_action_directional_focus_southeast(ObAction
**a
, ObUserAction uact
)
150 (*a
)->data
.interdiraction
.inter
.any
.interactive
= TRUE
;
151 (*a
)->data
.interdiraction
.direction
= OB_DIRECTION_SOUTHEAST
;
152 (*a
)->data
.interdiraction
.dialog
= TRUE
;
155 void setup_action_directional_focus_southwest(ObAction
**a
, ObUserAction uact
)
157 (*a
)->data
.interdiraction
.inter
.any
.interactive
= TRUE
;
158 (*a
)->data
.interdiraction
.direction
= OB_DIRECTION_SOUTHWEST
;
159 (*a
)->data
.interdiraction
.dialog
= TRUE
;
162 void setup_action_directional_focus_northwest(ObAction
**a
, ObUserAction uact
)
164 (*a
)->data
.interdiraction
.inter
.any
.interactive
= TRUE
;
165 (*a
)->data
.interdiraction
.direction
= OB_DIRECTION_NORTHWEST
;
166 (*a
)->data
.interdiraction
.dialog
= TRUE
;
169 void setup_action_send_to_desktop(ObAction
**a
, ObUserAction uact
)
171 (*a
)->data
.sendto
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
172 (*a
)->data
.sendto
.follow
= TRUE
;
175 void setup_action_send_to_desktop_prev(ObAction
**a
, ObUserAction uact
)
177 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
178 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
179 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_WEST
;
180 (*a
)->data
.sendtodir
.linear
= TRUE
;
181 (*a
)->data
.sendtodir
.wrap
= TRUE
;
182 (*a
)->data
.sendtodir
.follow
= TRUE
;
185 void setup_action_send_to_desktop_next(ObAction
**a
, ObUserAction uact
)
187 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
188 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
189 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_EAST
;
190 (*a
)->data
.sendtodir
.linear
= TRUE
;
191 (*a
)->data
.sendtodir
.wrap
= TRUE
;
192 (*a
)->data
.sendtodir
.follow
= TRUE
;
195 void setup_action_send_to_desktop_left(ObAction
**a
, ObUserAction uact
)
197 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
198 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
199 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_WEST
;
200 (*a
)->data
.sendtodir
.linear
= FALSE
;
201 (*a
)->data
.sendtodir
.wrap
= TRUE
;
202 (*a
)->data
.sendtodir
.follow
= TRUE
;
205 void setup_action_send_to_desktop_right(ObAction
**a
, ObUserAction uact
)
207 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
208 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
209 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_EAST
;
210 (*a
)->data
.sendtodir
.linear
= FALSE
;
211 (*a
)->data
.sendtodir
.wrap
= TRUE
;
212 (*a
)->data
.sendtodir
.follow
= TRUE
;
215 void setup_action_send_to_desktop_up(ObAction
**a
, ObUserAction uact
)
217 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
218 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
219 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_NORTH
;
220 (*a
)->data
.sendtodir
.linear
= FALSE
;
221 (*a
)->data
.sendtodir
.wrap
= TRUE
;
222 (*a
)->data
.sendtodir
.follow
= TRUE
;
225 void setup_action_send_to_desktop_down(ObAction
**a
, ObUserAction uact
)
227 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
228 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
229 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_SOUTH
;
230 (*a
)->data
.sendtodir
.linear
= FALSE
;
231 (*a
)->data
.sendtodir
.wrap
= TRUE
;
232 (*a
)->data
.sendtodir
.follow
= TRUE
;
235 void setup_action_desktop(ObAction
**a
, ObUserAction uact
)
237 (*a
)->data
.desktop
.inter
.any
.interactive
= FALSE
;
240 void setup_action_desktop_prev(ObAction
**a
, ObUserAction uact
)
242 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
243 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_WEST
;
244 (*a
)->data
.desktopdir
.linear
= TRUE
;
245 (*a
)->data
.desktopdir
.wrap
= TRUE
;
248 void setup_action_desktop_next(ObAction
**a
, ObUserAction uact
)
250 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
251 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_EAST
;
252 (*a
)->data
.desktopdir
.linear
= TRUE
;
253 (*a
)->data
.desktopdir
.wrap
= TRUE
;
256 void setup_action_desktop_left(ObAction
**a
, ObUserAction uact
)
258 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
259 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_WEST
;
260 (*a
)->data
.desktopdir
.linear
= FALSE
;
261 (*a
)->data
.desktopdir
.wrap
= TRUE
;
264 void setup_action_desktop_right(ObAction
**a
, ObUserAction uact
)
266 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
267 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_EAST
;
268 (*a
)->data
.desktopdir
.linear
= FALSE
;
269 (*a
)->data
.desktopdir
.wrap
= TRUE
;
272 void setup_action_desktop_up(ObAction
**a
, ObUserAction uact
)
274 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
275 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_NORTH
;
276 (*a
)->data
.desktopdir
.linear
= FALSE
;
277 (*a
)->data
.desktopdir
.wrap
= TRUE
;
280 void setup_action_desktop_down(ObAction
**a
, ObUserAction uact
)
282 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
283 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_SOUTH
;
284 (*a
)->data
.desktopdir
.linear
= FALSE
;
285 (*a
)->data
.desktopdir
.wrap
= TRUE
;
288 void setup_action_cycle_windows_next(ObAction
**a
, ObUserAction uact
)
290 (*a
)->data
.cycle
.inter
.any
.interactive
= TRUE
;
291 (*a
)->data
.cycle
.linear
= FALSE
;
292 (*a
)->data
.cycle
.forward
= TRUE
;
293 (*a
)->data
.cycle
.dialog
= TRUE
;
296 void setup_action_cycle_windows_previous(ObAction
**a
, ObUserAction uact
)
298 (*a
)->data
.cycle
.inter
.any
.interactive
= TRUE
;
299 (*a
)->data
.cycle
.linear
= FALSE
;
300 (*a
)->data
.cycle
.forward
= FALSE
;
301 (*a
)->data
.cycle
.dialog
= TRUE
;
304 void setup_action_movetoedge_north(ObAction
**a
, ObUserAction uact
)
306 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
307 (*a
)->data
.diraction
.direction
= OB_DIRECTION_NORTH
;
310 void setup_action_movetoedge_south(ObAction
**a
, ObUserAction uact
)
312 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
313 (*a
)->data
.diraction
.direction
= OB_DIRECTION_SOUTH
;
316 void setup_action_movetoedge_east(ObAction
**a
, ObUserAction uact
)
318 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
319 (*a
)->data
.diraction
.direction
= OB_DIRECTION_EAST
;
322 void setup_action_movetoedge_west(ObAction
**a
, ObUserAction uact
)
324 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
325 (*a
)->data
.diraction
.direction
= OB_DIRECTION_WEST
;
328 void setup_action_growtoedge_north(ObAction
**a
, ObUserAction uact
)
330 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
331 (*a
)->data
.diraction
.direction
= OB_DIRECTION_NORTH
;
334 void setup_action_growtoedge_south(ObAction
**a
, ObUserAction uact
)
336 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
337 (*a
)->data
.diraction
.direction
= OB_DIRECTION_SOUTH
;
340 void setup_action_growtoedge_east(ObAction
**a
, ObUserAction uact
)
342 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
343 (*a
)->data
.diraction
.direction
= OB_DIRECTION_EAST
;
346 void setup_action_growtoedge_west(ObAction
**a
, ObUserAction uact
)
348 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
349 (*a
)->data
.diraction
.direction
= OB_DIRECTION_WEST
;
352 void setup_action_top_layer(ObAction
**a
, ObUserAction uact
)
354 (*a
)->data
.layer
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
355 (*a
)->data
.layer
.layer
= 1;
358 void setup_action_normal_layer(ObAction
**a
, ObUserAction uact
)
360 (*a
)->data
.layer
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
361 (*a
)->data
.layer
.layer
= 0;
364 void setup_action_bottom_layer(ObAction
**a
, ObUserAction uact
)
366 (*a
)->data
.layer
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
367 (*a
)->data
.layer
.layer
= -1;
370 void setup_action_move(ObAction
**a
, ObUserAction uact
)
372 (*a
)->data
.moveresize
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
373 (*a
)->data
.moveresize
.move
= TRUE
;
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_resize(ObAction
**a
, ObUserAction uact
)
382 (*a
)->data
.moveresize
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
383 (*a
)->data
.moveresize
.move
= FALSE
;
384 (*a
)->data
.moveresize
.keyboard
=
385 (uact
== OB_USER_ACTION_NONE
||
386 uact
== OB_USER_ACTION_KEYBOARD_KEY
||
387 uact
== OB_USER_ACTION_MENU_SELECTION
);
390 void setup_action_showmenu(ObAction
**a
, ObUserAction uact
)
392 (*a
)->data
.showmenu
.any
.client_action
= OB_CLIENT_ACTION_OPTIONAL
;
393 /* you cannot call ShowMenu from inside a menu, cuz the menu code makes
394 assumptions that there is only one menu (and submenus) open at
396 if (uact
== OB_USER_ACTION_MENU_SELECTION
) {
402 void setup_client_action(ObAction
**a
, ObUserAction uact
)
404 (*a
)->data
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
407 ActionString actionstrings
[] =
415 "directionalfocusnorth",
416 action_directional_focus
,
417 setup_action_directional_focus_north
420 "directionalfocuseast",
421 action_directional_focus
,
422 setup_action_directional_focus_east
425 "directionalfocussouth",
426 action_directional_focus
,
427 setup_action_directional_focus_south
430 "directionalfocuswest",
431 action_directional_focus
,
432 setup_action_directional_focus_west
435 "directionalfocusnortheast",
436 action_directional_focus
,
437 setup_action_directional_focus_northeast
440 "directionalfocussoutheast",
441 action_directional_focus
,
442 setup_action_directional_focus_southeast
445 "directionalfocussouthwest",
446 action_directional_focus
,
447 setup_action_directional_focus_southwest
450 "directionalfocusnorthwest",
451 action_directional_focus
,
452 setup_action_directional_focus_northwest
526 action_toggle_omnipresent
,
531 action_move_relative_horz
,
536 action_move_relative_vert
,
540 "resizerelativehorz",
541 action_resize_relative_horz
,
545 "resizerelativevert",
546 action_resize_relative_vert
,
551 action_maximize_full
,
556 action_unmaximize_full
,
560 "togglemaximizefull",
561 action_toggle_maximize_full
,
566 action_maximize_horz
,
571 action_unmaximize_horz
,
575 "togglemaximizehorz",
576 action_toggle_maximize_horz
,
581 action_maximize_vert
,
586 action_unmaximize_vert
,
590 "togglemaximizevert",
591 action_toggle_maximize_vert
,
596 action_toggle_fullscreen
,
601 action_send_to_desktop
,
602 setup_action_send_to_desktop
606 action_send_to_desktop_dir
,
607 setup_action_send_to_desktop_next
610 "sendtodesktopprevious",
611 action_send_to_desktop_dir
,
612 setup_action_send_to_desktop_prev
615 "sendtodesktopright",
616 action_send_to_desktop_dir
,
617 setup_action_send_to_desktop_right
621 action_send_to_desktop_dir
,
622 setup_action_send_to_desktop_left
626 action_send_to_desktop_dir
,
627 setup_action_send_to_desktop_up
631 action_send_to_desktop_dir
,
632 setup_action_send_to_desktop_down
642 setup_action_desktop_next
647 setup_action_desktop_prev
652 setup_action_desktop_right
657 setup_action_desktop_left
662 setup_action_desktop_up
667 setup_action_desktop_down
671 action_toggle_decorations
,
685 "toggledockautohide",
686 action_toggle_dockautohide
,
691 action_toggle_show_desktop
,
701 action_unshow_desktop
,
727 setup_action_showmenu
731 action_send_to_layer
,
732 setup_action_top_layer
737 setup_action_top_layer
741 action_send_to_layer
,
742 setup_action_normal_layer
746 action_send_to_layer
,
747 setup_action_bottom_layer
750 "togglealwaysonbottom",
752 setup_action_bottom_layer
756 action_cycle_windows
,
757 setup_action_cycle_windows_next
761 action_cycle_windows
,
762 setup_action_cycle_windows_previous
767 setup_action_movetoedge_north
772 setup_action_movetoedge_south
777 setup_action_movetoedge_west
782 setup_action_movetoedge_east
787 setup_action_growtoedge_north
792 setup_action_growtoedge_south
797 setup_action_growtoedge_west
802 setup_action_growtoedge_east
811 /* only key bindings can be interactive. thus saith the xor.
812 because of how the mouse is grabbed, mouse events dont even get
813 read during interactive events, so no dice! >:) */
814 #define INTERACTIVE_LIMIT(a, uact) \
815 if (uact != OB_USER_ACTION_KEYBOARD_KEY) \
816 a->data.any.interactive = FALSE;
818 ObAction
*action_from_string(const gchar
*name
, ObUserAction uact
)
821 gboolean exist
= FALSE
;
824 for (i
= 0; actionstrings
[i
].name
; i
++)
825 if (!g_ascii_strcasecmp(name
, actionstrings
[i
].name
)) {
827 a
= action_new(actionstrings
[i
].func
);
828 if (actionstrings
[i
].setup
)
829 actionstrings
[i
].setup(&a
, uact
);
831 INTERACTIVE_LIMIT(a
, uact
);
835 g_warning("Invalid action '%s' requested. No such action exists.",
838 g_warning("Invalid use of action '%s'. Action will be ignored.", name
);
842 ObAction
*action_parse(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
846 ObAction
*act
= NULL
;
849 if (parse_attr_string("name", node
, &actname
)) {
850 if ((act
= action_from_string(actname
, uact
))) {
851 if (act
->func
== action_execute
|| act
->func
== action_restart
) {
852 if ((n
= parse_find_node("execute", node
->xmlChildrenNode
))) {
853 gchar
*s
= parse_string(doc
, n
);
854 act
->data
.execute
.path
= parse_expand_tilde(s
);
857 } else if (act
->func
== action_showmenu
) {
858 if ((n
= parse_find_node("menu", node
->xmlChildrenNode
)))
859 act
->data
.showmenu
.name
= parse_string(doc
, n
);
860 } else if (act
->func
== action_move_relative_horz
||
861 act
->func
== action_move_relative_vert
||
862 act
->func
== action_resize_relative_horz
||
863 act
->func
== action_resize_relative_vert
) {
864 if ((n
= parse_find_node("delta", node
->xmlChildrenNode
)))
865 act
->data
.relative
.delta
= parse_int(doc
, n
);
866 } else if (act
->func
== action_desktop
) {
867 if ((n
= parse_find_node("desktop", node
->xmlChildrenNode
)))
868 act
->data
.desktop
.desk
= parse_int(doc
, n
);
869 if (act
->data
.desktop
.desk
> 0) act
->data
.desktop
.desk
--;
870 if ((n
= parse_find_node("dialog", node
->xmlChildrenNode
)))
871 act
->data
.desktop
.inter
.any
.interactive
=
873 } else if (act
->func
== action_send_to_desktop
) {
874 if ((n
= parse_find_node("desktop", node
->xmlChildrenNode
)))
875 act
->data
.sendto
.desk
= parse_int(doc
, n
);
876 if (act
->data
.sendto
.desk
> 0) act
->data
.sendto
.desk
--;
877 if ((n
= parse_find_node("follow", node
->xmlChildrenNode
)))
878 act
->data
.sendto
.follow
= parse_bool(doc
, n
);
879 } else if (act
->func
== action_desktop_dir
) {
880 if ((n
= parse_find_node("wrap", node
->xmlChildrenNode
)))
881 act
->data
.desktopdir
.wrap
= parse_bool(doc
, n
);
882 if ((n
= parse_find_node("dialog", node
->xmlChildrenNode
)))
883 act
->data
.desktopdir
.inter
.any
.interactive
=
885 } else if (act
->func
== action_send_to_desktop_dir
) {
886 if ((n
= parse_find_node("wrap", node
->xmlChildrenNode
)))
887 act
->data
.sendtodir
.wrap
= parse_bool(doc
, n
);
888 if ((n
= parse_find_node("follow", node
->xmlChildrenNode
)))
889 act
->data
.sendtodir
.follow
= parse_bool(doc
, n
);
890 if ((n
= parse_find_node("dialog", node
->xmlChildrenNode
)))
891 act
->data
.sendtodir
.inter
.any
.interactive
=
893 } else if (act
->func
== action_activate
) {
894 if ((n
= parse_find_node("here", node
->xmlChildrenNode
)))
895 act
->data
.activate
.here
= parse_bool(doc
, n
);
896 } else if (act
->func
== action_cycle_windows
) {
897 if ((n
= parse_find_node("linear", node
->xmlChildrenNode
)))
898 act
->data
.cycle
.linear
= parse_bool(doc
, n
);
899 if ((n
= parse_find_node("dialog", node
->xmlChildrenNode
)))
900 act
->data
.cycle
.dialog
= parse_bool(doc
, n
);
901 } else if (act
->func
== action_directional_focus
) {
902 if ((n
= parse_find_node("dialog", node
->xmlChildrenNode
)))
903 act
->data
.cycle
.dialog
= parse_bool(doc
, n
);
905 INTERACTIVE_LIMIT(act
, uact
);
912 void action_run_list(GSList
*acts
, ObClient
*c
, ObFrameContext context
,
913 guint state
, guint button
, gint x
, gint y
,
914 gboolean cancel
, gboolean done
)
918 gboolean inter
= FALSE
;
924 screen_pointer_pos(&x
, &y
);
926 if (grab_on_keyboard())
929 for (it
= acts
; it
; it
= g_slist_next(it
)) {
931 if (a
->data
.any
.interactive
) {
938 /* sometimes when we execute another app as an action,
939 it won't work right unless we XUngrabKeyboard first,
940 even though we grabbed the key/button Asychronously.
941 e.g. "gnome-panel-control --main-menu" */
942 XUngrabKeyboard(ob_display
, event_lasttime
);
945 for (it
= acts
; it
; it
= g_slist_next(it
)) {
948 if (!(a
->data
.any
.client_action
== OB_CLIENT_ACTION_ALWAYS
&& !c
)) {
949 a
->data
.any
.c
= a
->data
.any
.client_action
? c
: NULL
;
950 a
->data
.any
.context
= context
;
954 a
->data
.any
.button
= button
;
956 if (a
->data
.any
.interactive
) {
957 a
->data
.inter
.cancel
= cancel
;
958 a
->data
.inter
.final
= done
;
959 if (!(cancel
|| done
))
960 if (!keyboard_interactive_grab(state
, a
->data
.any
.c
, a
))
964 /* XXX UGLY HACK race with motion event starting a move and the
965 button release gettnig processed first. answer: don't queue
966 moveresize starts. UGLY HACK XXX */
967 if (a
->data
.any
.interactive
|| a
->func
== action_moveresize
) {
968 /* interactive actions are not queued */
971 ob_main_loop_queue_action(ob_main_loop
, a
);
976 void action_run_string(const gchar
*name
, struct _ObClient
*c
)
981 a
= action_from_string(name
, OB_USER_ACTION_NONE
);
984 l
= g_slist_append(NULL
, a
);
989 void action_execute(union ActionData
*data
)
992 gchar
*cmd
, **argv
= 0;
993 if (data
->execute
.path
) {
994 cmd
= g_filename_from_utf8(data
->execute
.path
, -1, NULL
, NULL
, NULL
);
996 if (!g_shell_parse_argv (cmd
, NULL
, &argv
, &e
)) {
997 g_warning("failed to execute '%s': %s",
1001 if (!g_spawn_async(NULL
, argv
, NULL
, G_SPAWN_SEARCH_PATH
|
1002 G_SPAWN_DO_NOT_REAP_CHILD
,
1003 NULL
, NULL
, NULL
, &e
)) {
1004 g_warning("failed to execute '%s': %s",
1012 g_warning("failed to convert '%s' from utf8", data
->execute
.path
);
1017 void action_activate(union ActionData
*data
)
1019 client_activate(data
->activate
.any
.c
, data
->activate
.here
);
1022 void action_focus(union ActionData
*data
)
1024 /* if using focus_delay, stop the timer now so that focus doesn't go moving
1026 event_halt_focus_delay();
1028 client_focus(data
->client
.any
.c
);
1031 void action_unfocus (union ActionData
*data
)
1033 client_unfocus(data
->client
.any
.c
);
1036 void action_iconify(union ActionData
*data
)
1038 client_iconify(data
->client
.any
.c
, TRUE
, TRUE
);
1041 void action_raiselower(union ActionData
*data
)
1043 ObClient
*c
= data
->client
.any
.c
;
1045 gboolean raise
= FALSE
;
1047 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
1048 ObClient
*cit
= it
->data
;
1050 if (cit
== c
) break;
1051 if (client_normal(cit
) == client_normal(c
) &&
1052 cit
->layer
== c
->layer
&&
1053 cit
->frame
->visible
&&
1054 !client_search_transient(c
, cit
))
1056 if (RECT_INTERSECTS_RECT(cit
->frame
->area
, c
->frame
->area
)) {
1069 void action_raise(union ActionData
*data
)
1071 client_action_start(data
);
1072 stacking_raise(CLIENT_AS_WINDOW(data
->client
.any
.c
));
1073 client_action_end(data
);
1076 void action_unshaderaise(union ActionData
*data
)
1078 if (data
->client
.any
.c
->shaded
)
1079 action_unshade(data
);
1084 void action_shadelower(union ActionData
*data
)
1086 if (data
->client
.any
.c
->shaded
)
1092 void action_lower(union ActionData
*data
)
1094 client_action_start(data
);
1095 stacking_lower(CLIENT_AS_WINDOW(data
->client
.any
.c
));
1096 client_action_end(data
);
1099 void action_close(union ActionData
*data
)
1101 client_close(data
->client
.any
.c
);
1104 void action_kill(union ActionData
*data
)
1106 client_kill(data
->client
.any
.c
);
1109 void action_shade(union ActionData
*data
)
1111 client_action_start(data
);
1112 client_shade(data
->client
.any
.c
, TRUE
);
1113 client_action_end(data
);
1116 void action_unshade(union ActionData
*data
)
1118 client_action_start(data
);
1119 client_shade(data
->client
.any
.c
, FALSE
);
1120 client_action_end(data
);
1123 void action_toggle_shade(union ActionData
*data
)
1125 client_action_start(data
);
1126 client_shade(data
->client
.any
.c
, !data
->client
.any
.c
->shaded
);
1127 client_action_end(data
);
1130 void action_toggle_omnipresent(union ActionData
*data
)
1132 client_set_desktop(data
->client
.any
.c
,
1133 data
->client
.any
.c
->desktop
== DESKTOP_ALL
?
1134 screen_desktop
: DESKTOP_ALL
, FALSE
);
1137 void action_move_relative_horz(union ActionData
*data
)
1139 ObClient
*c
= data
->relative
.any
.c
;
1140 client_action_start(data
);
1141 client_move(c
, c
->area
.x
+ data
->relative
.delta
, c
->area
.y
);
1142 client_action_end(data
);
1145 void action_move_relative_vert(union ActionData
*data
)
1147 ObClient
*c
= data
->relative
.any
.c
;
1148 client_action_start(data
);
1149 client_move(c
, c
->area
.x
, c
->area
.y
+ data
->relative
.delta
);
1150 client_action_end(data
);
1153 void action_resize_relative_horz(union ActionData
*data
)
1155 ObClient
*c
= data
->relative
.any
.c
;
1156 client_action_start(data
);
1158 c
->area
.width
+ data
->relative
.delta
* c
->size_inc
.width
,
1160 client_action_end(data
);
1163 void action_resize_relative_vert(union ActionData
*data
)
1165 ObClient
*c
= data
->relative
.any
.c
;
1167 client_action_start(data
);
1168 client_resize(c
, c
->area
.width
, c
->area
.height
+
1169 data
->relative
.delta
* c
->size_inc
.height
);
1170 client_action_end(data
);
1174 void action_maximize_full(union ActionData
*data
)
1176 client_action_start(data
);
1177 client_maximize(data
->client
.any
.c
, TRUE
, 0, TRUE
);
1178 client_action_end(data
);
1181 void action_unmaximize_full(union ActionData
*data
)
1183 client_action_start(data
);
1184 client_maximize(data
->client
.any
.c
, FALSE
, 0, TRUE
);
1185 client_action_end(data
);
1188 void action_toggle_maximize_full(union ActionData
*data
)
1190 client_action_start(data
);
1191 client_maximize(data
->client
.any
.c
,
1192 !(data
->client
.any
.c
->max_horz
||
1193 data
->client
.any
.c
->max_vert
),
1195 client_action_end(data
);
1198 void action_maximize_horz(union ActionData
*data
)
1200 client_action_start(data
);
1201 client_maximize(data
->client
.any
.c
, TRUE
, 1, TRUE
);
1202 client_action_end(data
);
1205 void action_unmaximize_horz(union ActionData
*data
)
1207 client_action_start(data
);
1208 client_maximize(data
->client
.any
.c
, FALSE
, 1, TRUE
);
1209 client_action_end(data
);
1212 void action_toggle_maximize_horz(union ActionData
*data
)
1214 client_action_start(data
);
1215 client_maximize(data
->client
.any
.c
,
1216 !data
->client
.any
.c
->max_horz
, 1, TRUE
);
1217 client_action_end(data
);
1220 void action_maximize_vert(union ActionData
*data
)
1222 client_action_start(data
);
1223 client_maximize(data
->client
.any
.c
, TRUE
, 2, TRUE
);
1224 client_action_end(data
);
1227 void action_unmaximize_vert(union ActionData
*data
)
1229 client_action_start(data
);
1230 client_maximize(data
->client
.any
.c
, FALSE
, 2, TRUE
);
1231 client_action_end(data
);
1234 void action_toggle_maximize_vert(union ActionData
*data
)
1236 client_action_start(data
);
1237 client_maximize(data
->client
.any
.c
,
1238 !data
->client
.any
.c
->max_vert
, 2, TRUE
);
1239 client_action_end(data
);
1242 void action_toggle_fullscreen(union ActionData
*data
)
1244 client_action_start(data
);
1245 client_fullscreen(data
->client
.any
.c
,
1246 !(data
->client
.any
.c
->fullscreen
), TRUE
);
1247 client_action_end(data
);
1250 void action_send_to_desktop(union ActionData
*data
)
1252 ObClient
*c
= data
->sendto
.any
.c
;
1254 if (!client_normal(c
)) return;
1256 if (data
->sendto
.desk
< screen_num_desktops
||
1257 data
->sendto
.desk
== DESKTOP_ALL
) {
1258 client_set_desktop(c
, data
->sendto
.desk
, data
->sendto
.follow
);
1259 if (data
->sendto
.follow
)
1260 screen_set_desktop(data
->sendto
.desk
);
1264 void action_desktop(union ActionData
*data
)
1266 static guint first
= (unsigned) -1;
1268 if (data
->inter
.any
.interactive
&& first
== (unsigned) -1)
1269 first
= screen_desktop
;
1271 if (!data
->inter
.any
.interactive
||
1272 (!data
->inter
.cancel
&& !data
->inter
.final
))
1274 if (data
->desktop
.desk
< screen_num_desktops
||
1275 data
->desktop
.desk
== DESKTOP_ALL
)
1277 screen_set_desktop(data
->desktop
.desk
);
1278 if (data
->inter
.any
.interactive
)
1279 screen_desktop_popup(data
->desktop
.desk
, TRUE
);
1281 } else if (data
->inter
.cancel
) {
1282 screen_set_desktop(first
);
1285 if (!data
->inter
.any
.interactive
|| data
->inter
.final
) {
1286 screen_desktop_popup(0, FALSE
);
1287 first
= (unsigned) -1;
1291 void action_desktop_dir(union ActionData
*data
)
1295 d
= screen_cycle_desktop(data
->desktopdir
.dir
,
1296 data
->desktopdir
.wrap
,
1297 data
->desktopdir
.linear
,
1298 data
->desktopdir
.inter
.any
.interactive
,
1299 data
->desktopdir
.inter
.final
,
1300 data
->desktopdir
.inter
.cancel
);
1301 if (!data
->sendtodir
.inter
.any
.interactive
||
1302 !data
->sendtodir
.inter
.final
||
1303 data
->sendtodir
.inter
.cancel
)
1305 screen_set_desktop(d
);
1309 void action_send_to_desktop_dir(union ActionData
*data
)
1311 ObClient
*c
= data
->sendtodir
.inter
.any
.c
;
1314 if (!client_normal(c
)) return;
1316 d
= screen_cycle_desktop(data
->sendtodir
.dir
, data
->sendtodir
.wrap
,
1317 data
->sendtodir
.linear
,
1318 data
->sendtodir
.inter
.any
.interactive
,
1319 data
->sendtodir
.inter
.final
,
1320 data
->sendtodir
.inter
.cancel
);
1321 if (!data
->sendtodir
.inter
.any
.interactive
||
1322 !data
->sendtodir
.inter
.final
||
1323 data
->sendtodir
.inter
.cancel
)
1325 client_set_desktop(c
, d
, data
->sendtodir
.follow
);
1326 if (data
->sendtodir
.follow
)
1327 screen_set_desktop(d
);
1331 void action_desktop_last(union ActionData
*data
)
1333 screen_set_desktop(screen_last_desktop
);
1336 void action_toggle_decorations(union ActionData
*data
)
1338 ObClient
*c
= data
->client
.any
.c
;
1340 client_action_start(data
);
1341 client_set_undecorated(c
, !c
->undecorated
);
1342 client_action_end(data
);
1345 static guint32
pick_corner(gint x
, gint y
, gint cx
, gint cy
, gint cw
, gint ch
)
1347 if (config_resize_four_corners
) {
1348 if (x
- cx
> cw
/ 2) {
1349 if (y
- cy
> ch
/ 2)
1350 return prop_atoms
.net_wm_moveresize_size_bottomright
;
1352 return prop_atoms
.net_wm_moveresize_size_topright
;
1354 if (y
- cy
> ch
/ 2)
1355 return prop_atoms
.net_wm_moveresize_size_bottomleft
;
1357 return prop_atoms
.net_wm_moveresize_size_topleft
;
1360 if (x
- cx
> cw
* 2 / 3) {
1361 if (y
- cy
> ch
* 2 / 3)
1362 return prop_atoms
.net_wm_moveresize_size_bottomright
;
1363 else if (y
- cy
< ch
/ 3)
1364 return prop_atoms
.net_wm_moveresize_size_topright
;
1366 return prop_atoms
.net_wm_moveresize_size_right
;
1367 } else if (x
- cx
< cw
/ 3) {
1368 if (y
- cy
> ch
* 2 / 3)
1369 return prop_atoms
.net_wm_moveresize_size_bottomleft
;
1370 else if (y
- cy
< ch
/ 3)
1371 return prop_atoms
.net_wm_moveresize_size_topleft
;
1373 return prop_atoms
.net_wm_moveresize_size_left
;
1375 if (y
- cy
> ch
* 2 / 3)
1376 return prop_atoms
.net_wm_moveresize_size_bottom
;
1377 else if (y
- cy
< ch
/ 3)
1378 return prop_atoms
.net_wm_moveresize_size_top
;
1380 return prop_atoms
.net_wm_moveresize_move
;
1384 void action_moveresize(union ActionData
*data
)
1386 ObClient
*c
= data
->moveresize
.any
.c
;
1389 if (!client_normal(c
)) return;
1391 if (data
->moveresize
.keyboard
) {
1392 corner
= (data
->moveresize
.move
?
1393 prop_atoms
.net_wm_moveresize_move_keyboard
:
1394 prop_atoms
.net_wm_moveresize_size_keyboard
);
1396 corner
= (data
->moveresize
.move
?
1397 prop_atoms
.net_wm_moveresize_move
:
1398 pick_corner(data
->any
.x
, data
->any
.y
,
1399 c
->frame
->area
.x
, c
->frame
->area
.y
,
1400 /* use the client size because the frame
1401 can be differently sized (shaded
1402 windows) and we want this based on the
1404 c
->area
.width
+ c
->frame
->size
.left
+
1405 c
->frame
->size
.right
,
1406 c
->area
.height
+ c
->frame
->size
.top
+
1407 c
->frame
->size
.bottom
));
1410 moveresize_start(c
, data
->any
.x
, data
->any
.y
, data
->any
.button
, corner
);
1413 void action_reconfigure(union ActionData
*data
)
1418 void action_restart(union ActionData
*data
)
1420 ob_restart_other(data
->execute
.path
);
1423 void action_exit(union ActionData
*data
)
1428 void action_showmenu(union ActionData
*data
)
1430 if (data
->showmenu
.name
) {
1431 menu_show(data
->showmenu
.name
, data
->any
.x
, data
->any
.y
,
1432 data
->showmenu
.any
.c
);
1436 void action_cycle_windows(union ActionData
*data
)
1438 /* if using focus_delay, stop the timer now so that focus doesn't go moving
1440 event_halt_focus_delay();
1442 focus_cycle(data
->cycle
.forward
, data
->cycle
.linear
, data
->any
.interactive
,
1444 data
->cycle
.inter
.final
, data
->cycle
.inter
.cancel
);
1447 void action_directional_focus(union ActionData
*data
)
1449 /* if using focus_delay, stop the timer now so that focus doesn't go moving
1451 event_halt_focus_delay();
1453 focus_directional_cycle(data
->interdiraction
.direction
,
1454 data
->any
.interactive
,
1455 data
->interdiraction
.dialog
,
1456 data
->interdiraction
.inter
.final
,
1457 data
->interdiraction
.inter
.cancel
);
1460 void action_movetoedge(union ActionData
*data
)
1463 ObClient
*c
= data
->diraction
.any
.c
;
1465 x
= c
->frame
->area
.x
;
1466 y
= c
->frame
->area
.y
;
1468 switch(data
->diraction
.direction
) {
1469 case OB_DIRECTION_NORTH
:
1470 y
= client_directional_edge_search(c
, OB_DIRECTION_NORTH
);
1472 case OB_DIRECTION_WEST
:
1473 x
= client_directional_edge_search(c
, OB_DIRECTION_WEST
);
1475 case OB_DIRECTION_SOUTH
:
1476 y
= client_directional_edge_search(c
, OB_DIRECTION_SOUTH
) -
1477 c
->frame
->area
.height
;
1479 case OB_DIRECTION_EAST
:
1480 x
= client_directional_edge_search(c
, OB_DIRECTION_EAST
) -
1481 c
->frame
->area
.width
;
1484 g_assert_not_reached();
1486 frame_frame_gravity(c
->frame
, &x
, &y
);
1487 client_action_start(data
);
1488 client_move(c
, x
, y
);
1489 client_action_end(data
);
1492 void action_growtoedge(union ActionData
*data
)
1494 gint x
, y
, width
, height
, dest
;
1495 ObClient
*c
= data
->diraction
.any
.c
;
1498 //FIXME growtoedge resizes shaded windows to 0 height
1502 a
= screen_area(c
->desktop
);
1503 x
= c
->frame
->area
.x
;
1504 y
= c
->frame
->area
.y
;
1505 width
= c
->frame
->area
.width
;
1506 height
= c
->frame
->area
.height
;
1508 switch(data
->diraction
.direction
) {
1509 case OB_DIRECTION_NORTH
:
1510 dest
= client_directional_edge_search(c
, OB_DIRECTION_NORTH
);
1512 height
= c
->frame
->area
.height
/ 2;
1514 height
= c
->frame
->area
.y
+ c
->frame
->area
.height
- dest
;
1518 case OB_DIRECTION_WEST
:
1519 dest
= client_directional_edge_search(c
, OB_DIRECTION_WEST
);
1521 width
= c
->frame
->area
.width
/ 2;
1523 width
= c
->frame
->area
.x
+ c
->frame
->area
.width
- dest
;
1527 case OB_DIRECTION_SOUTH
:
1528 dest
= client_directional_edge_search(c
, OB_DIRECTION_SOUTH
);
1529 if (a
->y
+ a
->height
== y
+ c
->frame
->area
.height
) {
1530 height
= c
->frame
->area
.height
/ 2;
1531 y
= a
->y
+ a
->height
- height
;
1533 height
= dest
- c
->frame
->area
.y
;
1534 y
+= (height
- c
->frame
->area
.height
) % c
->size_inc
.height
;
1535 height
-= (height
- c
->frame
->area
.height
) % c
->size_inc
.height
;
1537 case OB_DIRECTION_EAST
:
1538 dest
= client_directional_edge_search(c
, OB_DIRECTION_EAST
);
1539 if (a
->x
+ a
->width
== x
+ c
->frame
->area
.width
) {
1540 width
= c
->frame
->area
.width
/ 2;
1541 x
= a
->x
+ a
->width
- width
;
1543 width
= dest
- c
->frame
->area
.x
;
1544 x
+= (width
- c
->frame
->area
.width
) % c
->size_inc
.width
;
1545 width
-= (width
- c
->frame
->area
.width
) % c
->size_inc
.width
;
1548 g_assert_not_reached();
1550 frame_frame_gravity(c
->frame
, &x
, &y
);
1551 width
-= c
->frame
->size
.left
+ c
->frame
->size
.right
;
1552 height
-= c
->frame
->size
.top
+ c
->frame
->size
.bottom
;
1553 client_action_start(data
);
1554 client_move_resize(c
, x
, y
, width
, height
);
1555 client_action_end(data
);
1558 void action_send_to_layer(union ActionData
*data
)
1560 client_set_layer(data
->layer
.any
.c
, data
->layer
.layer
);
1563 void action_toggle_layer(union ActionData
*data
)
1565 ObClient
*c
= data
->layer
.any
.c
;
1567 client_action_start(data
);
1568 if (data
->layer
.layer
< 0)
1569 client_set_layer(c
, c
->below
? 0 : -1);
1570 else if (data
->layer
.layer
> 0)
1571 client_set_layer(c
, c
->above
? 0 : 1);
1572 client_action_end(data
);
1575 void action_toggle_dockautohide(union ActionData
*data
)
1577 config_dock_hide
= !config_dock_hide
;
1581 void action_toggle_show_desktop(union ActionData
*data
)
1583 screen_show_desktop(!screen_showing_desktop
);
1586 void action_show_desktop(union ActionData
*data
)
1588 screen_show_desktop(TRUE
);
1591 void action_unshow_desktop(union ActionData
*data
)
1593 screen_show_desktop(FALSE
);