]> icculus.org git repositories - dana/openbox.git/blob - openbox/action.c
really fix focus_last?
[dana/openbox.git] / openbox / action.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    action.c for the Openbox window manager
4    Copyright (c) 2003        Ben Jansens
5
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.
10
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.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "debug.h"
20 #include "client.h"
21 #include "focus.h"
22 #include "moveresize.h"
23 #include "menu.h"
24 #include "prop.h"
25 #include "stacking.h"
26 #include "screen.h"
27 #include "action.h"
28 #include "openbox.h"
29 #include "grab.h"
30 #include "keyboard.h"
31 #include "event.h"
32 #include "config.h"
33 #include "mainloop.h"
34
35 #include <glib.h>
36
37 inline void client_action_start(union ActionData *data)
38 {
39     if (config_focus_follow)
40         if (data->any.context != OB_FRAME_CONTEXT_CLIENT && !data->any.button)
41             grab_pointer(TRUE, OB_CURSOR_NONE);
42 }
43
44 inline void client_action_end(union ActionData *data)
45 {
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);
50             } else {
51                 ObClient *c;
52
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);
58             }
59         }
60 }
61
62 typedef struct
63 {
64     const gchar *name;
65     void (*func)(union ActionData *);
66     void (*setup)(ObAction **, ObUserAction uact);
67 } ActionString;
68
69 static ObAction *action_new(void (*func)(union ActionData *data))
70 {
71     ObAction *a = g_new0(ObAction, 1);
72     a->ref = 1;
73     a->func = func;
74
75     return a;
76 }
77
78 void action_ref(ObAction *a)
79 {
80     ++a->ref;
81 }
82
83 void action_unref(ObAction *a)
84 {
85     if (a == NULL) return;
86
87     if (--a->ref > 0) return;
88
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);
94
95     g_free(a);
96 }
97
98 ObAction* action_copy(const ObAction *src)
99 {
100     ObAction *a = action_new(src->func);
101
102     a->data = src->data;
103
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);
109
110     return a;
111 }
112
113 void setup_action_directional_focus_north(ObAction **a, ObUserAction uact)
114 {
115     (*a)->data.interdiraction.inter.any.interactive = TRUE;
116     (*a)->data.interdiraction.direction = OB_DIRECTION_NORTH;
117     (*a)->data.interdiraction.dialog = TRUE;
118 }
119
120 void setup_action_directional_focus_east(ObAction **a, ObUserAction uact)
121 {
122     (*a)->data.interdiraction.inter.any.interactive = TRUE;
123     (*a)->data.interdiraction.direction = OB_DIRECTION_EAST;
124     (*a)->data.interdiraction.dialog = TRUE;
125 }
126
127 void setup_action_directional_focus_south(ObAction **a, ObUserAction uact)
128 {
129     (*a)->data.interdiraction.inter.any.interactive = TRUE;
130     (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTH;
131     (*a)->data.interdiraction.dialog = TRUE;
132 }
133
134 void setup_action_directional_focus_west(ObAction **a, ObUserAction uact)
135 {
136     (*a)->data.interdiraction.inter.any.interactive = TRUE;
137     (*a)->data.interdiraction.direction = OB_DIRECTION_WEST;
138     (*a)->data.interdiraction.dialog = TRUE;
139 }
140
141 void setup_action_directional_focus_northeast(ObAction **a, ObUserAction uact)
142 {
143     (*a)->data.interdiraction.inter.any.interactive = TRUE;
144     (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHEAST;
145     (*a)->data.interdiraction.dialog = TRUE;
146 }
147
148 void setup_action_directional_focus_southeast(ObAction **a, ObUserAction uact)
149 {
150     (*a)->data.interdiraction.inter.any.interactive = TRUE;
151     (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHEAST;
152     (*a)->data.interdiraction.dialog = TRUE;
153 }
154
155 void setup_action_directional_focus_southwest(ObAction **a, ObUserAction uact)
156 {
157     (*a)->data.interdiraction.inter.any.interactive = TRUE;
158     (*a)->data.interdiraction.direction = OB_DIRECTION_SOUTHWEST;
159     (*a)->data.interdiraction.dialog = TRUE;
160 }
161
162 void setup_action_directional_focus_northwest(ObAction **a, ObUserAction uact)
163 {
164     (*a)->data.interdiraction.inter.any.interactive = TRUE;
165     (*a)->data.interdiraction.direction = OB_DIRECTION_NORTHWEST;
166     (*a)->data.interdiraction.dialog = TRUE;
167 }
168
169 void setup_action_send_to_desktop(ObAction **a, ObUserAction uact)
170 {
171     (*a)->data.sendto.any.client_action = OB_CLIENT_ACTION_ALWAYS;
172     (*a)->data.sendto.follow = TRUE;
173 }
174
175 void setup_action_send_to_desktop_prev(ObAction **a, ObUserAction uact)
176 {
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;
183 }
184
185 void setup_action_send_to_desktop_next(ObAction **a, ObUserAction uact)
186 {
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;
193 }
194
195 void setup_action_send_to_desktop_left(ObAction **a, ObUserAction uact)
196 {
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;
203 }
204
205 void setup_action_send_to_desktop_right(ObAction **a, ObUserAction uact)
206 {
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;
213 }
214
215 void setup_action_send_to_desktop_up(ObAction **a, ObUserAction uact)
216 {
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;
223 }
224
225 void setup_action_send_to_desktop_down(ObAction **a, ObUserAction uact)
226 {
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;
233 }
234
235 void setup_action_desktop(ObAction **a, ObUserAction uact)
236 {
237     (*a)->data.desktop.inter.any.interactive = FALSE;
238 }
239
240 void setup_action_desktop_prev(ObAction **a, ObUserAction uact)
241 {
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;
246 }
247
248 void setup_action_desktop_next(ObAction **a, ObUserAction uact)
249 {
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;
254 }
255
256 void setup_action_desktop_left(ObAction **a, ObUserAction uact)
257 {
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;
262 }
263
264 void setup_action_desktop_right(ObAction **a, ObUserAction uact)
265 {
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;
270 }
271
272 void setup_action_desktop_up(ObAction **a, ObUserAction uact)
273 {
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;
278 }
279
280 void setup_action_desktop_down(ObAction **a, ObUserAction uact)
281 {
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;
286 }
287
288 void setup_action_cycle_windows_next(ObAction **a, ObUserAction uact)
289 {
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;
294 }
295
296 void setup_action_cycle_windows_previous(ObAction **a, ObUserAction uact)
297 {
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;
302 }
303
304 void setup_action_movetoedge_north(ObAction **a, ObUserAction uact)
305 {
306     (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
307     (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
308 }
309
310 void setup_action_movetoedge_south(ObAction **a, ObUserAction uact)
311 {
312     (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
313     (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
314 }
315
316 void setup_action_movetoedge_east(ObAction **a, ObUserAction uact)
317 {
318     (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
319     (*a)->data.diraction.direction = OB_DIRECTION_EAST;
320 }
321
322 void setup_action_movetoedge_west(ObAction **a, ObUserAction uact)
323 {
324     (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
325     (*a)->data.diraction.direction = OB_DIRECTION_WEST;
326 }
327
328 void setup_action_growtoedge_north(ObAction **a, ObUserAction uact)
329 {
330     (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
331     (*a)->data.diraction.direction = OB_DIRECTION_NORTH;
332 }
333
334 void setup_action_growtoedge_south(ObAction **a, ObUserAction uact)
335 {
336     (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
337     (*a)->data.diraction.direction = OB_DIRECTION_SOUTH;
338 }
339
340 void setup_action_growtoedge_east(ObAction **a, ObUserAction uact)
341 {
342     (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
343     (*a)->data.diraction.direction = OB_DIRECTION_EAST;
344 }
345
346 void setup_action_growtoedge_west(ObAction **a, ObUserAction uact)
347 {
348     (*a)->data.diraction.any.client_action = OB_CLIENT_ACTION_ALWAYS;
349     (*a)->data.diraction.direction = OB_DIRECTION_WEST;
350 }
351
352 void setup_action_top_layer(ObAction **a, ObUserAction uact)
353 {
354     (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
355     (*a)->data.layer.layer = 1;
356 }
357
358 void setup_action_normal_layer(ObAction **a, ObUserAction uact)
359 {
360     (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
361     (*a)->data.layer.layer = 0;
362 }
363
364 void setup_action_bottom_layer(ObAction **a, ObUserAction uact)
365 {
366     (*a)->data.layer.any.client_action = OB_CLIENT_ACTION_ALWAYS;
367     (*a)->data.layer.layer = -1;
368 }
369
370 void setup_action_move(ObAction **a, ObUserAction uact)
371 {
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);
378 }
379
380 void setup_action_resize(ObAction **a, ObUserAction uact)
381 {
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);
388 }
389
390 void setup_action_showmenu(ObAction **a, ObUserAction uact)
391 {
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
395        a time! */
396     if (uact == OB_USER_ACTION_MENU_SELECTION) {
397         action_unref(*a);
398         *a = NULL;
399     }
400 }
401
402 void setup_client_action(ObAction **a, ObUserAction uact)
403 {
404     (*a)->data.any.client_action = OB_CLIENT_ACTION_ALWAYS;
405 }
406
407 ActionString actionstrings[] =
408 {
409     {
410         "execute", 
411         action_execute, 
412         NULL
413     },
414     {
415         "directionalfocusnorth", 
416         action_directional_focus, 
417         setup_action_directional_focus_north
418     },
419     {
420         "directionalfocuseast", 
421         action_directional_focus, 
422         setup_action_directional_focus_east
423     },
424     {
425         "directionalfocussouth", 
426         action_directional_focus, 
427         setup_action_directional_focus_south
428     },
429     {
430         "directionalfocuswest",
431         action_directional_focus,
432         setup_action_directional_focus_west
433     },
434     {
435         "directionalfocusnortheast",
436         action_directional_focus,
437         setup_action_directional_focus_northeast
438     },
439     {
440         "directionalfocussoutheast",
441         action_directional_focus,
442         setup_action_directional_focus_southeast
443     },
444     {
445         "directionalfocussouthwest",
446         action_directional_focus,
447         setup_action_directional_focus_southwest
448     },
449     {
450         "directionalfocusnorthwest",
451         action_directional_focus,
452         setup_action_directional_focus_northwest
453     },
454     {
455         "activate",
456         action_activate,
457         setup_client_action
458     },
459     {
460         "focus",
461         action_focus,
462         setup_client_action
463     },
464     {
465         "unfocus",
466         action_unfocus,
467         setup_client_action
468     },
469     {
470         "iconify",
471         action_iconify,
472         setup_client_action
473     },
474     {
475         "focustobottom",
476         action_focus_order_to_bottom,
477         setup_client_action
478     },
479     {
480         "raiselower",
481         action_raiselower,
482         setup_client_action
483     },
484     {
485         "raise",
486         action_raise,
487         setup_client_action
488     },
489     {
490         "lower",
491         action_lower,
492         setup_client_action
493     },
494     {
495         "close",
496         action_close,
497         setup_client_action
498     },
499     {
500         "kill",
501         action_kill,
502         setup_client_action
503     },
504     {
505         "shadelower",
506         action_shadelower,
507         setup_client_action
508     },
509     {
510         "unshaderaise",
511         action_unshaderaise,
512         setup_client_action
513     },
514     {
515         "shade",
516         action_shade,
517         setup_client_action
518     },
519     {
520         "unshade",
521         action_unshade,
522         setup_client_action
523     },
524     {
525         "toggleshade",
526         action_toggle_shade,
527         setup_client_action
528     },
529     {
530         "toggleomnipresent",
531         action_toggle_omnipresent,
532         setup_client_action
533     },
534     {
535         "moverelativehorz",
536         action_move_relative_horz,
537         setup_client_action
538     },
539     {
540         "moverelativevert",
541         action_move_relative_vert,
542         setup_client_action
543     },
544     {
545         "movetocenter",
546         action_move_to_center,
547         setup_client_action
548     },
549     {
550         "resizerelativehorz",
551         action_resize_relative_horz,
552         setup_client_action
553     },
554     {
555         "resizerelativevert",
556         action_resize_relative_vert,
557         setup_client_action
558     },
559     {
560         "moverelative",
561         action_move_relative,
562         setup_client_action
563     },
564     {
565         "resizerelative",
566         action_resize_relative,
567         setup_client_action
568     },
569     {
570         "maximizefull",
571         action_maximize_full,
572         setup_client_action
573     },
574     {
575         "unmaximizefull",
576         action_unmaximize_full,
577         setup_client_action
578     },
579     {
580         "togglemaximizefull",
581         action_toggle_maximize_full,
582         setup_client_action
583     },
584     {
585         "maximizehorz",
586         action_maximize_horz,
587         setup_client_action
588     },
589     {
590         "unmaximizehorz",
591         action_unmaximize_horz,
592         setup_client_action
593     },
594     {
595         "togglemaximizehorz",
596         action_toggle_maximize_horz,
597         setup_client_action
598     },
599     {
600         "maximizevert",
601         action_maximize_vert,
602         setup_client_action
603     },
604     {
605         "unmaximizevert",
606         action_unmaximize_vert,
607         setup_client_action
608     },
609     {
610         "togglemaximizevert",
611         action_toggle_maximize_vert,
612         setup_client_action
613     },
614     {
615         "togglefullscreen",
616         action_toggle_fullscreen,
617         setup_client_action
618     },
619     {
620         "sendtodesktop",
621         action_send_to_desktop,
622         setup_action_send_to_desktop
623     },
624     {
625         "sendtodesktopnext",
626         action_send_to_desktop_dir,
627         setup_action_send_to_desktop_next
628     },
629     {
630         "sendtodesktopprevious",
631         action_send_to_desktop_dir,
632         setup_action_send_to_desktop_prev
633     },
634     {
635         "sendtodesktopright",
636         action_send_to_desktop_dir,
637         setup_action_send_to_desktop_right
638     },
639     {
640         "sendtodesktopleft",
641         action_send_to_desktop_dir,
642         setup_action_send_to_desktop_left
643     },
644     {
645         "sendtodesktopup",
646         action_send_to_desktop_dir,
647         setup_action_send_to_desktop_up
648     },
649     {
650         "sendtodesktopdown",
651         action_send_to_desktop_dir,
652         setup_action_send_to_desktop_down
653     },
654     {
655         "desktop",
656         action_desktop,
657         setup_action_desktop
658     },
659     {
660         "desktopnext",
661         action_desktop_dir,
662         setup_action_desktop_next
663     },
664     {
665         "desktopprevious",
666         action_desktop_dir,
667         setup_action_desktop_prev
668     },
669     {
670         "desktopright",
671         action_desktop_dir,
672         setup_action_desktop_right
673     },
674     {
675         "desktopleft",
676         action_desktop_dir,
677         setup_action_desktop_left
678     },
679     {
680         "desktopup",
681         action_desktop_dir,
682         setup_action_desktop_up
683     },
684     {
685         "desktopdown",
686         action_desktop_dir,
687         setup_action_desktop_down
688     },
689     {
690         "toggledecorations",
691         action_toggle_decorations,
692         setup_client_action
693     },
694     {
695         "move",
696         action_moveresize,
697         setup_action_move
698     },
699     {
700         "resize",
701         action_moveresize,
702         setup_action_resize
703     },
704     {
705         "toggledockautohide",
706         action_toggle_dockautohide,
707         NULL
708     },
709     {
710         "toggleshowdesktop",
711         action_toggle_show_desktop,
712         NULL
713     },
714     {
715         "showdesktop",
716         action_show_desktop,
717         NULL
718     },
719     {
720         "unshowdesktop",
721         action_unshow_desktop,
722         NULL
723     },
724     {
725         "desktoplast",
726         action_desktop_last,
727         NULL
728     },
729     {
730         "reconfigure",
731         action_reconfigure,
732         NULL
733     },
734     {
735         "restart",
736         action_restart,
737         NULL
738     },
739     {
740         "exit",
741         action_exit,
742         NULL
743     },
744     {
745         "showmenu",
746         action_showmenu,
747         setup_action_showmenu
748     },
749     {
750         "sendtotoplayer",
751         action_send_to_layer,
752         setup_action_top_layer
753     },
754     {
755         "togglealwaysontop",
756         action_toggle_layer,
757         setup_action_top_layer
758     },
759     {
760         "sendtonormallayer",
761         action_send_to_layer,
762         setup_action_normal_layer
763     },
764     {
765         "sendtobottomlayer",
766         action_send_to_layer,
767         setup_action_bottom_layer
768     },
769     {
770         "togglealwaysonbottom",
771         action_toggle_layer,
772         setup_action_bottom_layer
773     },
774     {
775         "nextwindow",
776         action_cycle_windows,
777         setup_action_cycle_windows_next
778     },
779     {
780         "previouswindow",
781         action_cycle_windows,
782         setup_action_cycle_windows_previous
783     },
784     {
785         "movetoedgenorth",
786         action_movetoedge,
787         setup_action_movetoedge_north
788     },
789     {
790         "movetoedgesouth",
791         action_movetoedge,
792         setup_action_movetoedge_south
793     },
794     {
795         "movetoedgewest",
796         action_movetoedge,
797         setup_action_movetoedge_west
798     },
799     {
800         "movetoedgeeast",
801         action_movetoedge,
802         setup_action_movetoedge_east
803     },
804     {
805         "growtoedgenorth",
806         action_growtoedge,
807         setup_action_growtoedge_north
808     },
809     {
810         "growtoedgesouth",
811         action_growtoedge,
812         setup_action_growtoedge_south
813     },
814     {
815         "growtoedgewest",
816         action_growtoedge,
817         setup_action_growtoedge_west
818     },
819     {
820         "growtoedgeeast",
821         action_growtoedge,
822         setup_action_growtoedge_east
823     },
824     {
825         NULL,
826         NULL,
827         NULL
828     }
829 };
830
831 /* only key bindings can be interactive. thus saith the xor.
832    because of how the mouse is grabbed, mouse events dont even get
833    read during interactive events, so no dice! >:) */
834 #define INTERACTIVE_LIMIT(a, uact) \
835     if (uact != OB_USER_ACTION_KEYBOARD_KEY) \
836         a->data.any.interactive = FALSE;
837
838 ObAction *action_from_string(const gchar *name, ObUserAction uact)
839 {
840     ObAction *a = NULL;
841     gboolean exist = FALSE;
842     gint i;
843
844     for (i = 0; actionstrings[i].name; i++)
845         if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
846             exist = TRUE;
847             a = action_new(actionstrings[i].func);
848             if (actionstrings[i].setup)
849                 actionstrings[i].setup(&a, uact);
850             if (a)
851                 INTERACTIVE_LIMIT(a, uact);
852             break;
853         }
854     if (!exist)
855         g_warning("Invalid action '%s' requested. No such action exists.",
856                   name);
857     if (!a)
858         g_warning("Invalid use of action '%s'. Action will be ignored.", name);
859     return a;
860 }
861
862 ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
863                        ObUserAction uact)
864 {
865     gchar *actname;
866     ObAction *act = NULL;
867     xmlNodePtr n;
868
869     if (parse_attr_string("name", node, &actname)) {
870         if ((act = action_from_string(actname, uact))) {
871             if (act->func == action_execute || act->func == action_restart) {
872                 if ((n = parse_find_node("execute", node->xmlChildrenNode))) {
873                     gchar *s = parse_string(doc, n);
874                     act->data.execute.path = parse_expand_tilde(s);
875                     g_free(s);
876                 }
877             } else if (act->func == action_showmenu) {
878                 if ((n = parse_find_node("menu", node->xmlChildrenNode)))
879                     act->data.showmenu.name = parse_string(doc, n);
880             } else if (act->func == action_move_relative_horz ||
881                        act->func == action_move_relative_vert ||
882                        act->func == action_resize_relative_horz ||
883                        act->func == action_resize_relative_vert) {
884                 if ((n = parse_find_node("delta", node->xmlChildrenNode)))
885                     act->data.relative.deltax = parse_int(doc, n);
886             } else if (act->func == action_move_relative) {
887                 if ((n = parse_find_node("x", node->xmlChildrenNode)))
888                     act->data.relative.deltax = parse_int(doc, n);
889                 if ((n = parse_find_node("y", node->xmlChildrenNode)))
890                     act->data.relative.deltay = parse_int(doc, n);
891             } else if (act->func == action_resize_relative) {
892                 if ((n = parse_find_node("left", node->xmlChildrenNode)))
893                     act->data.relative.deltaxl = parse_int(doc, n);
894                 if ((n = parse_find_node("up", node->xmlChildrenNode)))
895                     act->data.relative.deltayu = parse_int(doc, n);
896                 if ((n = parse_find_node("right", node->xmlChildrenNode)))
897                     act->data.relative.deltax = parse_int(doc, n);
898                 if ((n = parse_find_node("down", node->xmlChildrenNode)))
899                     act->data.relative.deltay = parse_int(doc, n);
900             } else if (act->func == action_desktop) {
901                 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
902                     act->data.desktop.desk = parse_int(doc, n);
903                 if (act->data.desktop.desk > 0) act->data.desktop.desk--;
904                 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
905                     act->data.desktop.inter.any.interactive =
906                         parse_bool(doc, n);
907            } else if (act->func == action_send_to_desktop) {
908                 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
909                     act->data.sendto.desk = parse_int(doc, n);
910                 if (act->data.sendto.desk > 0) act->data.sendto.desk--;
911                 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
912                     act->data.sendto.follow = parse_bool(doc, n);
913             } else if (act->func == action_desktop_dir) {
914                 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
915                     act->data.desktopdir.wrap = parse_bool(doc, n); 
916                 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
917                     act->data.desktopdir.inter.any.interactive =
918                         parse_bool(doc, n);
919             } else if (act->func == action_send_to_desktop_dir) {
920                 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
921                     act->data.sendtodir.wrap = parse_bool(doc, n);
922                 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
923                     act->data.sendtodir.follow = parse_bool(doc, n);
924                 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
925                     act->data.sendtodir.inter.any.interactive =
926                         parse_bool(doc, n);
927             } else if (act->func == action_activate) {
928                 if ((n = parse_find_node("here", node->xmlChildrenNode)))
929                     act->data.activate.here = parse_bool(doc, n);
930             } else if (act->func == action_cycle_windows) {
931                 if ((n = parse_find_node("linear", node->xmlChildrenNode)))
932                     act->data.cycle.linear = parse_bool(doc, n);
933                 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
934                     act->data.cycle.dialog = parse_bool(doc, n);
935             } else if (act->func == action_directional_focus) {
936                 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
937                     act->data.cycle.dialog = parse_bool(doc, n);
938             } else if (act->func == action_raise ||
939                        act->func == action_lower ||
940                        act->func == action_raiselower ||
941                        act->func == action_shadelower ||
942                        act->func == action_unshaderaise) {
943                 if ((n = parse_find_node("group", node->xmlChildrenNode)))
944                     act->data.stacking.group = parse_bool(doc, n);
945             }
946             INTERACTIVE_LIMIT(act, uact);
947         }
948         g_free(actname);
949     }
950     return act;
951 }
952
953 void action_run_list(GSList *acts, ObClient *c, ObFrameContext context,
954                      guint state, guint button, gint x, gint y,
955                      gboolean cancel, gboolean done)
956 {
957     GSList *it;
958     ObAction *a;
959     gboolean inter = FALSE;
960
961     if (!acts)
962         return;
963
964     if (x < 0 && y < 0)
965         screen_pointer_pos(&x, &y);
966
967     if (grab_on_keyboard())
968         inter = TRUE;
969     else
970         for (it = acts; it; it = g_slist_next(it)) {
971             a = it->data;
972             if (a->data.any.interactive) {
973                 inter = TRUE;
974                 break;
975             }
976         }
977
978     if (!inter) {
979         /* sometimes when we execute another app as an action,
980            it won't work right unless we XUngrabKeyboard first,
981            even though we grabbed the key/button Asychronously.
982            e.g. "gnome-panel-control --main-menu" */
983         XUngrabKeyboard(ob_display, event_lasttime);
984     }
985
986     for (it = acts; it; it = g_slist_next(it)) {
987         a = it->data;
988
989         if (!(a->data.any.client_action == OB_CLIENT_ACTION_ALWAYS && !c)) {
990             a->data.any.c = a->data.any.client_action ? c : NULL;
991             a->data.any.context = context;
992             a->data.any.x = x;
993             a->data.any.y = y;
994
995             a->data.any.button = button;
996
997             if (a->data.any.interactive) {
998                 a->data.inter.cancel = cancel;
999                 a->data.inter.final = done;
1000                 if (!(cancel || done))
1001                     if (!keyboard_interactive_grab(state, a->data.any.c, a))
1002                         continue;
1003             }
1004
1005             /* XXX UGLY HACK race with motion event starting a move and the
1006                button release gettnig processed first. answer: don't queue
1007                moveresize starts. UGLY HACK XXX */
1008             if (a->data.any.interactive || a->func == action_moveresize) {
1009                 /* interactive actions are not queued */
1010                 a->func(&a->data);
1011             } else
1012                 ob_main_loop_queue_action(ob_main_loop, a);
1013         }
1014     }
1015 }
1016
1017 void action_run_string(const gchar *name, struct _ObClient *c)
1018 {
1019     ObAction *a;
1020     GSList *l;
1021
1022     a = action_from_string(name, OB_USER_ACTION_NONE);
1023     g_assert(a);
1024
1025     l = g_slist_append(NULL, a);
1026
1027     action_run(l, c, 0);
1028 }
1029
1030 void action_execute(union ActionData *data)
1031 {
1032     GError *e = NULL;
1033     gchar *cmd, **argv = 0;
1034     if (data->execute.path) {
1035         cmd = g_filename_from_utf8(data->execute.path, -1, NULL, NULL, NULL);
1036         if (cmd) {
1037             if (!g_shell_parse_argv (cmd, NULL, &argv, &e)) {
1038                 g_warning("failed to execute '%s': %s",
1039                           cmd, e->message);
1040                 g_error_free(e);
1041             } else {
1042                 if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH |
1043                                    G_SPAWN_DO_NOT_REAP_CHILD,
1044                                    NULL, NULL, NULL, &e)) {
1045                     g_warning("failed to execute '%s': %s",
1046                               cmd, e->message);
1047                     g_error_free(e);
1048                 }
1049                 g_strfreev(argv);
1050             }
1051             g_free(cmd);
1052         } else {
1053             g_warning("failed to convert '%s' from utf8", data->execute.path);
1054         }
1055     }
1056 }
1057
1058 void action_activate(union ActionData *data)
1059 {
1060     client_activate(data->activate.any.c, data->activate.here);
1061 }
1062
1063 void action_focus(union ActionData *data)
1064 {
1065     /* if using focus_delay, stop the timer now so that focus doesn't go moving
1066        on us */
1067     event_halt_focus_delay();
1068
1069     client_focus(data->client.any.c);
1070 }
1071
1072 void action_unfocus (union ActionData *data)
1073 {
1074     if (data->client.any.c == focus_client);
1075         focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
1076 }
1077
1078 void action_iconify(union ActionData *data)
1079 {
1080     client_action_start(data);
1081     client_iconify(data->client.any.c, TRUE, TRUE);
1082     client_action_end(data);
1083 }
1084
1085 void action_focus_order_to_bottom(union ActionData *data)
1086 {
1087     focus_order_to_bottom(data->client.any.c);
1088 }
1089
1090 void action_raiselower(union ActionData *data)
1091 {
1092     ObClient *c = data->client.any.c;
1093     GList *it;
1094     gboolean raise = FALSE;
1095
1096     for (it = stacking_list; it; it = g_list_next(it)) {
1097         ObClient *cit = it->data;
1098
1099         if (cit == c) break;
1100         if (client_normal(cit) == client_normal(c) &&
1101             cit->layer == c->layer &&
1102             cit->frame->visible &&
1103             !client_search_transient(c, cit))
1104         {
1105             if (RECT_INTERSECTS_RECT(cit->frame->area, c->frame->area)) {
1106                 raise = TRUE;
1107                 break;
1108             }
1109         }
1110     }
1111
1112     if (raise)
1113         action_raise(data);
1114     else
1115         action_lower(data);
1116 }
1117
1118 void action_raise(union ActionData *data)
1119 {
1120     client_action_start(data);
1121     stacking_raise(CLIENT_AS_WINDOW(data->client.any.c), data->stacking.group);
1122     client_action_end(data);
1123 }
1124
1125 void action_unshaderaise(union ActionData *data)
1126 {
1127     if (data->client.any.c->shaded)
1128         action_unshade(data);
1129     else
1130         action_raise(data);
1131 }
1132
1133 void action_shadelower(union ActionData *data)
1134 {
1135     if (data->client.any.c->shaded)
1136         action_lower(data);
1137     else
1138         action_shade(data);
1139 }
1140
1141 void action_lower(union ActionData *data)
1142 {
1143     client_action_start(data);
1144     stacking_lower(CLIENT_AS_WINDOW(data->client.any.c), data->stacking.group);
1145     client_action_end(data);
1146 }
1147
1148 void action_close(union ActionData *data)
1149 {
1150     client_close(data->client.any.c);
1151 }
1152
1153 void action_kill(union ActionData *data)
1154 {
1155     client_kill(data->client.any.c);
1156 }
1157
1158 void action_shade(union ActionData *data)
1159 {
1160     client_action_start(data);
1161     client_shade(data->client.any.c, TRUE);
1162     client_action_end(data);
1163 }
1164
1165 void action_unshade(union ActionData *data)
1166 {
1167     client_action_start(data);
1168     client_shade(data->client.any.c, FALSE);
1169     client_action_end(data);
1170 }
1171
1172 void action_toggle_shade(union ActionData *data)
1173 {
1174     client_action_start(data);
1175     client_shade(data->client.any.c, !data->client.any.c->shaded);
1176     client_action_end(data);
1177 }
1178
1179 void action_toggle_omnipresent(union ActionData *data)
1180
1181     client_set_desktop(data->client.any.c,
1182                        data->client.any.c->desktop == DESKTOP_ALL ?
1183                        screen_desktop : DESKTOP_ALL, FALSE);
1184 }
1185
1186 void action_move_relative_horz(union ActionData *data)
1187 {
1188     ObClient *c = data->relative.any.c;
1189     client_action_start(data);
1190     client_move(c, c->area.x + data->relative.deltax, c->area.y);
1191     client_action_end(data);
1192 }
1193
1194 void action_move_relative_vert(union ActionData *data)
1195 {
1196     ObClient *c = data->relative.any.c;
1197     client_action_start(data);
1198     client_move(c, c->area.x, c->area.y + data->relative.deltax);
1199     client_action_end(data);
1200 }
1201
1202 void action_move_to_center(union ActionData *data)
1203 {
1204     ObClient *c = data->client.any.c;
1205     Rect *area;
1206     area = screen_area_monitor(c->desktop, 0);
1207     client_action_start(data);
1208     client_move(c, area->width / 2 - c->area.width / 2,
1209                 area->height / 2 - c->area.height / 2);
1210     client_action_end(data);
1211 }
1212
1213 void action_resize_relative_horz(union ActionData *data)
1214 {
1215     ObClient *c = data->relative.any.c;
1216     client_action_start(data);
1217     client_resize(c,
1218                   c->area.width + data->relative.deltax * c->size_inc.width,
1219                   c->area.height);
1220     client_action_end(data);
1221 }
1222
1223 void action_resize_relative_vert(union ActionData *data)
1224 {
1225     ObClient *c = data->relative.any.c;
1226     if (!c->shaded) {
1227         client_action_start(data);
1228         client_resize(c, c->area.width, c->area.height +
1229                       data->relative.deltax * c->size_inc.height);
1230         client_action_end(data);
1231     }
1232 }
1233
1234 void action_move_relative(union ActionData *data)
1235 {
1236     ObClient *c = data->relative.any.c;
1237     client_action_start(data);
1238     client_move(c, c->area.x + data->relative.deltax, c->area.y +
1239                 data->relative.deltay);
1240     client_action_end(data);
1241 }
1242
1243 void action_resize_relative(union ActionData *data)
1244 {
1245     ObClient *c = data->relative.any.c;
1246     client_action_start(data);
1247     client_move_resize(c,
1248                   c->area.x - data->relative.deltaxl * c->size_inc.width,
1249                   c->area.y - data->relative.deltayu * c->size_inc.height,
1250                   c->area.width + data->relative.deltax  * c->size_inc.width
1251                                 + data->relative.deltaxl * c->size_inc.width,
1252                   c->area.height + data->relative.deltay  * c->size_inc.height
1253                                  + data->relative.deltayu * c->size_inc.height);
1254     client_action_end(data);
1255 }
1256
1257 void action_maximize_full(union ActionData *data)
1258 {
1259     client_action_start(data);
1260     client_maximize(data->client.any.c, TRUE, 0, TRUE);
1261     client_action_end(data);
1262 }
1263
1264 void action_unmaximize_full(union ActionData *data)
1265 {
1266     client_action_start(data);
1267     client_maximize(data->client.any.c, FALSE, 0, TRUE);
1268     client_action_end(data);
1269 }
1270
1271 void action_toggle_maximize_full(union ActionData *data)
1272 {
1273     client_action_start(data);
1274     client_maximize(data->client.any.c,
1275                     !(data->client.any.c->max_horz ||
1276                       data->client.any.c->max_vert),
1277                     0, TRUE);
1278     client_action_end(data);
1279 }
1280
1281 void action_maximize_horz(union ActionData *data)
1282 {
1283     client_action_start(data);
1284     client_maximize(data->client.any.c, TRUE, 1, TRUE);
1285     client_action_end(data);
1286 }
1287
1288 void action_unmaximize_horz(union ActionData *data)
1289 {
1290     client_action_start(data);
1291     client_maximize(data->client.any.c, FALSE, 1, TRUE);
1292     client_action_end(data);
1293 }
1294
1295 void action_toggle_maximize_horz(union ActionData *data)
1296 {
1297     client_action_start(data);
1298     client_maximize(data->client.any.c,
1299                     !data->client.any.c->max_horz, 1, TRUE);
1300     client_action_end(data);
1301 }
1302
1303 void action_maximize_vert(union ActionData *data)
1304 {
1305     client_action_start(data);
1306     client_maximize(data->client.any.c, TRUE, 2, TRUE);
1307     client_action_end(data);
1308 }
1309
1310 void action_unmaximize_vert(union ActionData *data)
1311 {
1312     client_action_start(data);
1313     client_maximize(data->client.any.c, FALSE, 2, TRUE);
1314     client_action_end(data);
1315 }
1316
1317 void action_toggle_maximize_vert(union ActionData *data)
1318 {
1319     client_action_start(data);
1320     client_maximize(data->client.any.c,
1321                     !data->client.any.c->max_vert, 2, TRUE);
1322     client_action_end(data);
1323 }
1324
1325 void action_toggle_fullscreen(union ActionData *data)
1326 {
1327     client_action_start(data);
1328     client_fullscreen(data->client.any.c,
1329                       !(data->client.any.c->fullscreen), TRUE);
1330     client_action_end(data);
1331 }
1332
1333 void action_send_to_desktop(union ActionData *data)
1334 {
1335     ObClient *c = data->sendto.any.c;
1336
1337     if (!client_normal(c)) return;
1338
1339     if (data->sendto.desk < screen_num_desktops ||
1340         data->sendto.desk == DESKTOP_ALL) {
1341         client_set_desktop(c, data->sendto.desk, data->sendto.follow);
1342         if (data->sendto.follow)
1343             screen_set_desktop(data->sendto.desk);
1344     }
1345 }
1346
1347 void action_desktop(union ActionData *data)
1348 {
1349     static guint first = (unsigned) -1;
1350
1351     if (data->inter.any.interactive && first == (unsigned) -1)
1352         first = screen_desktop;
1353
1354     if (!data->inter.any.interactive ||
1355         (!data->inter.cancel && !data->inter.final))
1356     {
1357         if (data->desktop.desk < screen_num_desktops ||
1358             data->desktop.desk == DESKTOP_ALL)
1359         {
1360             screen_set_desktop(data->desktop.desk);
1361             if (data->inter.any.interactive)
1362                 screen_desktop_popup(data->desktop.desk, TRUE);
1363         }
1364     } else if (data->inter.cancel) {
1365         screen_set_desktop(first);
1366     }
1367
1368     if (!data->inter.any.interactive || data->inter.final) {
1369         screen_desktop_popup(0, FALSE);
1370         first = (unsigned) -1;
1371     }
1372 }
1373
1374 void action_desktop_dir(union ActionData *data)
1375 {
1376     guint d;
1377
1378     d = screen_cycle_desktop(data->desktopdir.dir,
1379                              data->desktopdir.wrap,
1380                              data->desktopdir.linear,
1381                              data->desktopdir.inter.any.interactive,
1382                              data->desktopdir.inter.final,
1383                              data->desktopdir.inter.cancel);
1384     if (!data->sendtodir.inter.any.interactive ||
1385         !data->sendtodir.inter.final ||
1386         data->sendtodir.inter.cancel)
1387     {
1388         screen_set_desktop(d);
1389     }
1390 }
1391
1392 void action_send_to_desktop_dir(union ActionData *data)
1393 {
1394     ObClient *c = data->sendtodir.inter.any.c;
1395     guint d;
1396
1397     if (!client_normal(c)) return;
1398
1399     d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
1400                              data->sendtodir.linear,
1401                              data->sendtodir.inter.any.interactive,
1402                              data->sendtodir.inter.final,
1403                              data->sendtodir.inter.cancel);
1404     if (!data->sendtodir.inter.any.interactive ||
1405         !data->sendtodir.inter.final ||
1406         data->sendtodir.inter.cancel)
1407     {
1408         client_set_desktop(c, d, data->sendtodir.follow);
1409         if (data->sendtodir.follow)
1410             screen_set_desktop(d);
1411     }
1412 }
1413
1414 void action_desktop_last(union ActionData *data)
1415 {
1416     screen_set_desktop(screen_last_desktop);
1417 }
1418
1419 void action_toggle_decorations(union ActionData *data)
1420 {
1421     ObClient *c = data->client.any.c;
1422
1423     client_action_start(data);
1424     client_set_undecorated(c, !c->undecorated);
1425     client_action_end(data);
1426 }
1427
1428 static guint32 pick_corner(gint x, gint y, gint cx, gint cy, gint cw, gint ch)
1429 {
1430     if (config_resize_four_corners) {
1431         if (x - cx > cw / 2) {
1432             if (y - cy > ch / 2)
1433                 return prop_atoms.net_wm_moveresize_size_bottomright;
1434             else
1435                 return prop_atoms.net_wm_moveresize_size_topright;
1436         } else {
1437             if (y - cy > ch / 2)
1438                 return prop_atoms.net_wm_moveresize_size_bottomleft;
1439             else
1440                 return prop_atoms.net_wm_moveresize_size_topleft;
1441         }
1442     } else {
1443         if (x - cx > cw * 2 / 3) {
1444             if (y - cy > ch * 2 / 3)
1445                 return prop_atoms.net_wm_moveresize_size_bottomright;
1446             else if (y - cy < ch / 3)
1447                 return prop_atoms.net_wm_moveresize_size_topright;
1448             else
1449                 return prop_atoms.net_wm_moveresize_size_right;
1450         } else if (x - cx < cw / 3) {
1451             if (y - cy > ch * 2 / 3)
1452                 return prop_atoms.net_wm_moveresize_size_bottomleft;
1453             else if (y - cy < ch / 3)
1454                 return prop_atoms.net_wm_moveresize_size_topleft;
1455             else
1456                 return prop_atoms.net_wm_moveresize_size_left;
1457         } else
1458             if (y - cy > ch * 2 / 3)
1459                 return prop_atoms.net_wm_moveresize_size_bottom;
1460             else if (y - cy < ch / 3)
1461                 return prop_atoms.net_wm_moveresize_size_top;
1462             else
1463                 return prop_atoms.net_wm_moveresize_move;
1464     }
1465 }
1466
1467 void action_moveresize(union ActionData *data)
1468 {
1469     ObClient *c = data->moveresize.any.c;
1470     guint32 corner;
1471
1472     if (!client_normal(c)) return;
1473
1474     if (data->moveresize.keyboard) {
1475         corner = (data->moveresize.move ?
1476                   prop_atoms.net_wm_moveresize_move_keyboard :
1477                   prop_atoms.net_wm_moveresize_size_keyboard);
1478     } else {
1479         corner = (data->moveresize.move ?
1480                   prop_atoms.net_wm_moveresize_move :
1481                   pick_corner(data->any.x, data->any.y,
1482                               c->frame->area.x, c->frame->area.y,
1483                               /* use the client size because the frame
1484                                  can be differently sized (shaded
1485                                  windows) and we want this based on the
1486                                  clients size */
1487                               c->area.width + c->frame->size.left +
1488                               c->frame->size.right,
1489                               c->area.height + c->frame->size.top +
1490                               c->frame->size.bottom));
1491     }
1492
1493     moveresize_start(c, data->any.x, data->any.y, data->any.button, corner);
1494 }
1495
1496 void action_reconfigure(union ActionData *data)
1497 {
1498     ob_reconfigure();
1499 }
1500
1501 void action_restart(union ActionData *data)
1502 {
1503     ob_restart_other(data->execute.path);
1504 }
1505
1506 void action_exit(union ActionData *data)
1507 {
1508     ob_exit(0);
1509 }
1510
1511 void action_showmenu(union ActionData *data)
1512 {
1513     if (data->showmenu.name) {
1514         menu_show(data->showmenu.name, data->any.x, data->any.y,
1515                   data->showmenu.any.c);
1516     }
1517 }
1518
1519 void action_cycle_windows(union ActionData *data)
1520 {
1521     /* if using focus_delay, stop the timer now so that focus doesn't go moving
1522        on us */
1523     event_halt_focus_delay();
1524
1525     focus_cycle(data->cycle.forward, data->cycle.linear, data->any.interactive,
1526                 data->cycle.dialog,
1527                 data->cycle.inter.final, data->cycle.inter.cancel);
1528 }
1529
1530 void action_directional_focus(union ActionData *data)
1531 {
1532     /* if using focus_delay, stop the timer now so that focus doesn't go moving
1533        on us */
1534     event_halt_focus_delay();
1535
1536     focus_directional_cycle(data->interdiraction.direction,
1537                             data->any.interactive,
1538                             data->interdiraction.dialog,
1539                             data->interdiraction.inter.final,
1540                             data->interdiraction.inter.cancel);
1541 }
1542
1543 void action_movetoedge(union ActionData *data)
1544 {
1545     gint x, y;
1546     ObClient *c = data->diraction.any.c;
1547
1548     x = c->frame->area.x;
1549     y = c->frame->area.y;
1550     
1551     switch(data->diraction.direction) {
1552     case OB_DIRECTION_NORTH:
1553         y = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1554         break;
1555     case OB_DIRECTION_WEST:
1556         x = client_directional_edge_search(c, OB_DIRECTION_WEST);
1557         break;
1558     case OB_DIRECTION_SOUTH:
1559         y = client_directional_edge_search(c, OB_DIRECTION_SOUTH) -
1560             c->frame->area.height;
1561         break;
1562     case OB_DIRECTION_EAST:
1563         x = client_directional_edge_search(c, OB_DIRECTION_EAST) -
1564             c->frame->area.width;
1565         break;
1566     default:
1567         g_assert_not_reached();
1568     }
1569     frame_frame_gravity(c->frame, &x, &y);
1570     client_action_start(data);
1571     client_move(c, x, y);
1572     client_action_end(data);
1573 }
1574
1575 void action_growtoedge(union ActionData *data)
1576 {
1577     gint x, y, width, height, dest;
1578     ObClient *c = data->diraction.any.c;
1579     Rect *a;
1580
1581     //FIXME growtoedge resizes shaded windows to 0 height
1582     if (c->shaded)
1583         return;
1584
1585     a = screen_area(c->desktop);
1586     x = c->frame->area.x;
1587     y = c->frame->area.y;
1588     width = c->frame->area.width;
1589     height = c->frame->area.height;
1590
1591     switch(data->diraction.direction) {
1592     case OB_DIRECTION_NORTH:
1593         dest = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1594         if (a->y == y)
1595             height = c->frame->area.height / 2;
1596         else {
1597             height = c->frame->area.y + c->frame->area.height - dest;
1598             y = dest;
1599         }
1600         break;
1601     case OB_DIRECTION_WEST:
1602         dest = client_directional_edge_search(c, OB_DIRECTION_WEST);
1603         if (a->x == x)
1604             width = c->frame->area.width / 2;
1605         else {
1606             width = c->frame->area.x + c->frame->area.width - dest;
1607             x = dest;
1608         }
1609         break;
1610     case OB_DIRECTION_SOUTH:
1611         dest = client_directional_edge_search(c, OB_DIRECTION_SOUTH);
1612         if (a->y + a->height == y + c->frame->area.height) {
1613             height = c->frame->area.height / 2;
1614             y = a->y + a->height - height;
1615         } else
1616             height = dest - c->frame->area.y;
1617         y += (height - c->frame->area.height) % c->size_inc.height;
1618         height -= (height - c->frame->area.height) % c->size_inc.height;
1619         break;
1620     case OB_DIRECTION_EAST:
1621         dest = client_directional_edge_search(c, OB_DIRECTION_EAST);
1622         if (a->x + a->width == x + c->frame->area.width) {
1623             width = c->frame->area.width / 2;
1624             x = a->x + a->width - width;
1625         } else
1626             width = dest - c->frame->area.x;
1627         x += (width - c->frame->area.width) % c->size_inc.width;
1628         width -= (width - c->frame->area.width) % c->size_inc.width;
1629         break;
1630     default:
1631         g_assert_not_reached();
1632     }
1633     frame_frame_gravity(c->frame, &x, &y);
1634     width -= c->frame->size.left + c->frame->size.right;
1635     height -= c->frame->size.top + c->frame->size.bottom;
1636     client_action_start(data);
1637     client_move_resize(c, x, y, width, height);
1638     client_action_end(data);
1639 }
1640
1641 void action_send_to_layer(union ActionData *data)
1642 {
1643     client_set_layer(data->layer.any.c, data->layer.layer);
1644 }
1645
1646 void action_toggle_layer(union ActionData *data)
1647 {
1648     ObClient *c = data->layer.any.c;
1649
1650     client_action_start(data);
1651     if (data->layer.layer < 0)
1652         client_set_layer(c, c->below ? 0 : -1);
1653     else if (data->layer.layer > 0)
1654         client_set_layer(c, c->above ? 0 : 1);
1655     client_action_end(data);
1656 }
1657
1658 void action_toggle_dockautohide(union ActionData *data)
1659 {
1660     config_dock_hide = !config_dock_hide;
1661     dock_configure();
1662 }
1663
1664 void action_toggle_show_desktop(union ActionData *data)
1665 {
1666     screen_show_desktop(!screen_showing_desktop);
1667 }
1668
1669 void action_show_desktop(union ActionData *data)
1670 {
1671     screen_show_desktop(TRUE);
1672 }
1673
1674 void action_unshow_desktop(union ActionData *data)
1675 {
1676     screen_show_desktop(FALSE);
1677 }