]> icculus.org git repositories - manmower/openbox.git/blob - openbox/action.c
use the NONE cursor when not specifying a cursor
[manmower/openbox.git] / openbox / action.c
1 #include "debug.h"
2 #include "client.h"
3 #include "focus.h"
4 #include "moveresize.h"
5 #include "menu.h"
6 #include "prop.h"
7 #include "stacking.h"
8 #include "frame.h"
9 #include "screen.h"
10 #include "action.h"
11 #include "openbox.h"
12 #include "grab.h"
13
14 #include <glib.h>
15
16 typedef struct ActionString {
17     char *name;
18     void (*func)(union ActionData *);
19     void (*setup)(ObAction *);
20 } ActionString;
21
22 ObAction *action_new(void (*func)(union ActionData *data))
23 {
24     ObAction *a = g_new0(ObAction, 1);
25     a->func = func;
26
27     return a;
28 }
29
30 void action_free(ObAction *a)
31 {
32     if (a == NULL) return;
33
34     /* deal with pointers */
35     if (a->func == action_execute || a->func == action_restart)
36         g_free(a->data.execute.path);
37     else if (a->func == action_showmenu)
38         g_free(a->data.showmenu.name);
39
40     g_free(a);
41 }
42
43 void setup_action_directional_focus_north(ObAction *a)
44
45     a->data.interdiraction.inter.any.interactive = TRUE;
46     a->data.interdiraction.direction = OB_DIRECTION_NORTH;
47 }
48
49 void setup_action_directional_focus_east(ObAction *a)
50 {
51     a->data.interdiraction.inter.any.interactive = TRUE;
52     a->data.interdiraction.direction = OB_DIRECTION_EAST;
53 }
54
55 void setup_action_directional_focus_south(ObAction *a)
56 {
57     a->data.interdiraction.inter.any.interactive = TRUE;
58     a->data.interdiraction.direction = OB_DIRECTION_SOUTH;
59 }
60
61 void setup_action_directional_focus_west(ObAction *a)
62 {
63     a->data.interdiraction.inter.any.interactive = TRUE;
64     a->data.interdiraction.direction = OB_DIRECTION_WEST;
65 }
66
67 void setup_action_directional_focus_northeast(ObAction *a)
68 {
69     a->data.interdiraction.inter.any.interactive = TRUE;
70     a->data.interdiraction.direction = OB_DIRECTION_NORTHEAST;
71 }
72
73 void setup_action_directional_focus_southeast(ObAction *a)
74 {
75     a->data.interdiraction.inter.any.interactive = TRUE;
76     a->data.interdiraction.direction = OB_DIRECTION_SOUTHEAST;
77 }
78
79 void setup_action_directional_focus_southwest(ObAction *a)
80 {
81     a->data.interdiraction.inter.any.interactive = TRUE;
82     a->data.interdiraction.direction = OB_DIRECTION_SOUTHWEST;
83 }
84
85 void setup_action_directional_focus_northwest(ObAction *a)
86 {
87     a->data.interdiraction.inter.any.interactive = TRUE;
88     a->data.interdiraction.direction = OB_DIRECTION_NORTHWEST;
89 }
90
91 void setup_action_send_to_desktop(ObAction *a)
92 {
93     a->data.sendto.follow = TRUE;
94 }
95
96 void setup_action_send_to_desktop_prev(ObAction *a)
97 {
98     a->data.sendtodir.inter.any.interactive = TRUE;
99     a->data.sendtodir.dir = OB_DIRECTION_WEST;
100     a->data.sendtodir.linear = TRUE;
101     a->data.sendtodir.wrap = TRUE;
102     a->data.sendtodir.follow = TRUE;
103 }
104
105 void setup_action_send_to_desktop_next(ObAction *a)
106 {
107     a->data.sendtodir.inter.any.interactive = TRUE;
108     a->data.sendtodir.dir = OB_DIRECTION_EAST;
109     a->data.sendtodir.linear = TRUE;
110     a->data.sendtodir.wrap = TRUE;
111     a->data.sendtodir.follow = TRUE;
112 }
113
114 void setup_action_send_to_desktop_left(ObAction *a)
115 {
116     a->data.sendtodir.inter.any.interactive = TRUE;
117     a->data.sendtodir.dir = OB_DIRECTION_WEST;
118     a->data.sendtodir.linear = FALSE;
119     a->data.sendtodir.wrap = TRUE;
120     a->data.sendtodir.follow = TRUE;
121 }
122
123 void setup_action_send_to_desktop_right(ObAction *a)
124 {
125     a->data.sendtodir.inter.any.interactive = TRUE;
126     a->data.sendtodir.dir = OB_DIRECTION_EAST;
127     a->data.sendtodir.linear = FALSE;
128     a->data.sendtodir.wrap = TRUE;
129     a->data.sendtodir.follow = TRUE;
130 }
131
132 void setup_action_send_to_desktop_up(ObAction *a)
133 {
134     a->data.sendtodir.inter.any.interactive = TRUE;
135     a->data.sendtodir.dir = OB_DIRECTION_NORTH;
136     a->data.sendtodir.linear = FALSE;
137     a->data.sendtodir.wrap = TRUE;
138     a->data.sendtodir.follow = TRUE;
139 }
140
141 void setup_action_send_to_desktop_down(ObAction *a)
142 {
143     a->data.sendtodir.inter.any.interactive = TRUE;
144     a->data.sendtodir.dir = OB_DIRECTION_SOUTH;
145     a->data.sendtodir.linear = FALSE;
146     a->data.sendtodir.wrap = TRUE;
147     a->data.sendtodir.follow = TRUE;
148 }
149
150 void setup_action_desktop_prev(ObAction *a)
151 {
152     a->data.desktopdir.inter.any.interactive = TRUE;
153     a->data.desktopdir.dir = OB_DIRECTION_WEST;
154     a->data.desktopdir.linear = TRUE;
155     a->data.desktopdir.wrap = TRUE;
156 }
157
158 void setup_action_desktop_next(ObAction *a)
159 {
160     a->data.desktopdir.inter.any.interactive = TRUE;
161     a->data.desktopdir.dir = OB_DIRECTION_EAST;
162     a->data.desktopdir.linear = TRUE;
163     a->data.desktopdir.wrap = TRUE;
164 }
165
166 void setup_action_desktop_left(ObAction *a)
167 {
168     a->data.desktopdir.inter.any.interactive = TRUE;
169     a->data.desktopdir.dir = OB_DIRECTION_WEST;
170     a->data.desktopdir.linear = FALSE;
171     a->data.desktopdir.wrap = TRUE;
172 }
173
174 void setup_action_desktop_right(ObAction *a)
175 {
176     a->data.desktopdir.inter.any.interactive = TRUE;
177     a->data.desktopdir.dir = OB_DIRECTION_EAST;
178     a->data.desktopdir.linear = FALSE;
179     a->data.desktopdir.wrap = TRUE;
180 }
181
182 void setup_action_desktop_up(ObAction *a)
183 {
184     a->data.desktopdir.inter.any.interactive = TRUE;
185     a->data.desktopdir.dir = OB_DIRECTION_NORTH;
186     a->data.desktopdir.linear = FALSE;
187     a->data.desktopdir.wrap = TRUE;
188 }
189
190 void setup_action_desktop_down(ObAction *a)
191 {
192     a->data.desktopdir.inter.any.interactive = TRUE;
193     a->data.desktopdir.dir = OB_DIRECTION_SOUTH;
194     a->data.desktopdir.linear = FALSE;
195     a->data.desktopdir.wrap = TRUE;
196 }
197
198 void setup_action_move_keyboard(ObAction *a)
199 {
200     a->data.moveresize.corner = prop_atoms.net_wm_moveresize_move_keyboard;
201 }
202
203 void setup_action_move(ObAction *a)
204 {
205     a->data.moveresize.corner = prop_atoms.net_wm_moveresize_move;
206 }
207
208 void setup_action_resize(ObAction *a)
209 {
210     a->data.moveresize.corner = prop_atoms.net_wm_moveresize_size_topleft;
211 }
212
213 void setup_action_resize_keyboard(ObAction *a)
214 {
215     a->data.moveresize.corner = prop_atoms.net_wm_moveresize_size_keyboard;
216 }
217
218 void setup_action_cycle_windows_linear_next(ObAction *a)
219 {
220     a->data.cycle.inter.any.interactive = TRUE;
221     a->data.cycle.linear = TRUE;
222     a->data.cycle.forward = TRUE;
223 }
224
225 void setup_action_cycle_windows_linear_previous(ObAction *a)
226 {
227     a->data.cycle.inter.any.interactive = TRUE;
228     a->data.cycle.linear = TRUE;
229     a->data.cycle.forward = FALSE;
230 }
231
232 void setup_action_cycle_windows_next(ObAction *a)
233 {
234     a->data.cycle.inter.any.interactive = TRUE;
235     a->data.cycle.linear = FALSE;
236     a->data.cycle.forward = TRUE;
237 }
238
239 void setup_action_cycle_windows_previous(ObAction *a)
240 {
241     a->data.cycle.inter.any.interactive = TRUE;
242     a->data.cycle.linear = FALSE;
243     a->data.cycle.forward = FALSE;
244 }
245
246 void setup_action_movetoedge_north(ObAction *a)
247 {
248     a->data.diraction.direction = OB_DIRECTION_NORTH;
249 }
250
251 void setup_action_movetoedge_south(ObAction *a)
252 {
253     a->data.diraction.direction = OB_DIRECTION_SOUTH;
254 }
255
256 void setup_action_movetoedge_east(ObAction *a)
257 {
258     a->data.diraction.direction = OB_DIRECTION_EAST;
259 }
260
261 void setup_action_movetoedge_west(ObAction *a)
262 {
263     a->data.diraction.direction = OB_DIRECTION_WEST;
264 }
265
266 void setup_action_growtoedge_north(ObAction *a)
267 {
268     a->data.diraction.direction = OB_DIRECTION_NORTH;
269 }
270
271 void setup_action_growtoedge_south(ObAction *a)
272 {
273     a->data.diraction.direction = OB_DIRECTION_SOUTH;
274 }
275
276 void setup_action_growtoedge_east(ObAction *a)
277 {
278     a->data.diraction.direction = OB_DIRECTION_EAST;
279 }
280
281 void setup_action_growtoedge_west(ObAction *a)
282 {
283     a->data.diraction.direction = OB_DIRECTION_WEST;
284 }
285
286 void setup_action_top_layer(ObAction *a)
287 {
288     a->data.layer.layer = 1;
289 }
290
291 void setup_action_normal_layer(ObAction *a)
292 {
293     a->data.layer.layer = 0;
294 }
295
296 void setup_action_bottom_layer(ObAction *a)
297 {
298     a->data.layer.layer = -1;
299 }
300
301 ActionString actionstrings[] =
302 {
303     {
304         "execute", 
305         action_execute, 
306         NULL
307     },
308     {
309         "directionalfocusnorth", 
310         action_directional_focus, 
311         setup_action_directional_focus_north
312     },
313     {
314         "directionalfocuseast", 
315         action_directional_focus, 
316         setup_action_directional_focus_east
317     },
318     {
319         "directionalfocussouth", 
320         action_directional_focus, 
321         setup_action_directional_focus_south
322     },
323     {
324         "directionalfocuswest",
325         action_directional_focus,
326         setup_action_directional_focus_west
327     },
328     {
329         "directionalfocusnortheast",
330         action_directional_focus,
331         setup_action_directional_focus_northeast
332     },
333     {
334         "directionalfocussoutheast",
335         action_directional_focus,
336         setup_action_directional_focus_southeast
337     },
338     {
339         "directionalfocussouthwest",
340         action_directional_focus,
341         setup_action_directional_focus_southwest
342     },
343     {
344         "directionalfocusnorthwest",
345         action_directional_focus,
346         setup_action_directional_focus_northwest
347     },
348     {
349         "activate",
350         action_activate,
351         NULL,
352     },
353     {
354         "focus",
355         action_focus,
356         NULL,
357     },
358     {
359         "unfocus",
360         action_unfocus,
361         NULL
362     },
363     {
364         "iconify",
365         action_iconify,
366         NULL
367     },
368     {
369         "raiselower",
370         action_raiselower,
371         NULL
372     },
373     {
374         "raise",
375         action_raise,
376         NULL
377     },
378     {
379         "lower",
380         action_lower,
381         NULL
382     },
383     {
384         "close",
385         action_close,
386         NULL
387     },
388     {
389         "kill",
390         action_kill,
391         NULL
392     },
393     {
394         "shadelower",
395         action_shadelower,
396         NULL
397     },
398     {
399         "unshaderaise",
400         action_unshaderaise,
401         NULL
402     },
403     {
404         "shade",
405         action_shade,
406         NULL
407     },
408     {
409         "unshade",
410         action_unshade,
411         NULL
412     },
413     {
414         "toggleshade",
415         action_toggle_shade,
416         NULL
417     },
418     {
419         "toggleomnipresent",
420         action_toggle_omnipresent,
421         NULL
422     },
423     {
424         "moverelativehorz",
425         action_move_relative_horz,
426         NULL
427     },
428     {
429         "moverelativevert",
430         action_move_relative_vert,
431         NULL
432     },
433     {
434         "resizerelativehorz",
435         action_resize_relative_horz,
436         NULL
437     },
438     {
439         "resizerelativevert",
440         action_resize_relative_vert,
441         NULL
442     },
443     {
444         "maximizefull",
445         action_maximize_full,
446         NULL
447     },
448     {
449         "unmaximizefull",
450         action_unmaximize_full,
451         NULL
452     },
453     {
454         "togglemaximizefull",
455         action_toggle_maximize_full,
456         NULL
457     },
458     {
459         "maximizehorz",
460         action_maximize_horz,
461         NULL
462     },
463     {
464         "unmaximizehorz",
465         action_unmaximize_horz,
466         NULL
467     },
468     {
469         "togglemaximizehorz",
470         action_toggle_maximize_horz,
471         NULL
472     },
473     {
474         "maximizevert",
475         action_maximize_vert,
476         NULL
477     },
478     {
479         "unmaximizevert",
480         action_unmaximize_vert,
481         NULL
482     },
483     {
484         "togglemaximizevert",
485         action_toggle_maximize_vert,
486         NULL
487     },
488     {
489         "sendtodesktop",
490         action_send_to_desktop,
491         setup_action_send_to_desktop
492     },
493     {
494         "sendtodesktopnext",
495         action_send_to_desktop_dir,
496         setup_action_send_to_desktop_next
497     },
498     {
499         "sendtodesktopprevious",
500         action_send_to_desktop_dir,
501         setup_action_send_to_desktop_prev
502     },
503     {
504         "sendtodesktopright",
505         action_send_to_desktop_dir,
506         setup_action_send_to_desktop_right
507     },
508     {
509         "sendtodesktopleft",
510         action_send_to_desktop_dir,
511         setup_action_send_to_desktop_left
512     },
513     {
514         "sendtodesktopup",
515         action_send_to_desktop_dir,
516         setup_action_send_to_desktop_up
517     },
518     {
519         "sendtodesktopdown",
520         action_send_to_desktop_dir,
521         setup_action_send_to_desktop_down
522     },
523     {
524         "desktop",
525         action_desktop,
526         NULL
527     },
528     {
529         "desktopnext",
530         action_desktop_dir,
531         setup_action_desktop_next
532     },
533     {
534         "desktopprevious",
535         action_desktop_dir,
536         setup_action_desktop_prev
537     },
538     {
539         "desktopright",
540         action_desktop_dir,
541         setup_action_desktop_right
542     },
543     {
544         "desktopleft",
545         action_desktop_dir,
546         setup_action_desktop_left
547     },
548     {
549         "desktopup",
550         action_desktop_dir,
551         setup_action_desktop_up
552     },
553     {
554         "desktopdown",
555         action_desktop_dir,
556         setup_action_desktop_down
557     },
558     {
559         "toggledecorations",
560         action_toggle_decorations,
561         NULL
562     },
563     {
564         "keyboardmove", 
565         action_moveresize,
566         setup_action_move_keyboard
567     },
568     {
569         "move",
570         action_moveresize,
571         setup_action_move
572     },
573     {
574         "resize",
575         action_moveresize,
576         setup_action_resize
577     },
578     {
579         "keyboardresize",
580         action_moveresize,
581         setup_action_resize_keyboard
582     },
583     {
584         "toggleshowdesktop",
585         action_toggle_show_desktop,
586         NULL
587     },
588     {
589         "showdesktop",
590         action_show_desktop,
591         NULL
592     },
593     {
594         "unshowdesktop",
595         action_unshow_desktop,
596         NULL
597     },
598     {
599         "desktoplast",
600         action_desktop_last,
601         NULL
602     },
603     {
604         "reconfigure",
605         action_reconfigure,
606         NULL
607     },
608     {
609         "restart",
610         action_restart,
611         NULL
612     },
613     {
614         "exit",
615         action_exit,
616         NULL
617     },
618     {
619         "showmenu",
620         action_showmenu,
621         NULL
622     },
623     {
624         "sendtotoplayer",
625         action_send_to_layer,
626         setup_action_top_layer
627     },
628     {
629         "togglealwaysontop",
630         action_toggle_layer,
631         setup_action_top_layer
632     },
633     {
634         "sendtonormallayer",
635         action_send_to_layer,
636         setup_action_normal_layer
637     },
638     {
639         "sendtobottomlayer",
640         action_send_to_layer,
641         setup_action_bottom_layer
642     },
643     {
644         "togglealwaysonbottom",
645         action_toggle_layer,
646         setup_action_bottom_layer
647     },
648     {
649         "nextwindowlinear",
650         action_cycle_windows,
651         setup_action_cycle_windows_linear_next
652     },
653     {
654         "previouswindowlinear",
655         action_cycle_windows,
656         setup_action_cycle_windows_linear_previous
657     },
658     {
659         "nextwindow",
660         action_cycle_windows,
661         setup_action_cycle_windows_next
662     },
663     {
664         "previouswindow",
665         action_cycle_windows,
666         setup_action_cycle_windows_previous
667     },
668     {
669         "movetoedgenorth",
670         action_movetoedge,
671         setup_action_movetoedge_north
672     },
673     {
674         "movetoedgesouth",
675         action_movetoedge,
676         setup_action_movetoedge_south
677     },
678     {
679         "movetoedgewest",
680         action_movetoedge,
681         setup_action_movetoedge_west
682     },
683     {
684         "movetoedgeeast",
685         action_movetoedge,
686         setup_action_movetoedge_east
687     },
688     {
689         "growtoedgenorth",
690         action_growtoedge,
691         setup_action_growtoedge_north
692     },
693     {
694         "growtoedgesouth",
695         action_growtoedge,
696         setup_action_growtoedge_south
697     },
698     {
699         "growtoedgewest",
700         action_growtoedge,
701         setup_action_growtoedge_west
702     },
703     {
704         "growtoedgeeast",
705         action_growtoedge,
706         setup_action_growtoedge_east
707     },
708     {
709         NULL,
710         NULL,
711         NULL
712     }
713 };
714
715 ObAction *action_from_string(char *name)
716 {
717     ObAction *a = NULL;
718     int i;
719
720     for (i = 0; actionstrings[i].name; i++)
721         if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
722             a = action_new(actionstrings[i].func);
723             if (actionstrings[i].setup)
724                 actionstrings[i].setup(a);
725             break;
726         }
727     if (!a)
728         g_warning("Invalid action '%s' requested. No such action exists.",
729                   name);
730     return a;
731 }
732
733 ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
734 {
735     char *actname;
736     ObAction *act = NULL;
737     xmlNodePtr n;
738
739     if (parse_attr_string("name", node, &actname)) {
740         if ((act = action_from_string(actname))) {
741             if (act->func == action_execute || act->func == action_restart) {
742                 if ((n = parse_find_node("execute", node->xmlChildrenNode))) {
743                     gchar *s = parse_string(doc, n);
744                     act->data.execute.path = ob_expand_tilde(s);
745                     g_free(s);
746                 }
747             } else if (act->func == action_showmenu) {
748                 if ((n = parse_find_node("menu", node->xmlChildrenNode)))
749                     act->data.showmenu.name = parse_string(doc, n);
750             } else if (act->func == action_desktop) {
751                 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
752                     act->data.desktop.desk = parse_int(doc, n);
753                 if (act->data.desktop.desk > 0) act->data.desktop.desk--;
754             } else if (act->func == action_send_to_desktop) {
755                 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
756                     act->data.sendto.desk = parse_int(doc, n);
757                 if (act->data.sendto.desk > 0) act->data.sendto.desk--;
758             } else if (act->func == action_move_relative_horz ||
759                        act->func == action_move_relative_vert ||
760                        act->func == action_resize_relative_horz ||
761                        act->func == action_resize_relative_vert) {
762                 if ((n = parse_find_node("delta", node->xmlChildrenNode)))
763                     act->data.relative.delta = parse_int(doc, n);
764             } else if (act->func == action_desktop_dir) {
765                 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
766                     act->data.desktopdir.wrap = parse_bool(doc, n);
767             } else if (act->func == action_send_to_desktop) {
768                 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
769                     act->data.sendto.follow = parse_bool(doc, n);
770             } else if (act->func == action_send_to_desktop_dir) {
771                 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
772                     act->data.sendtodir.wrap = parse_bool(doc, n);
773                 if ((n = parse_find_node("follow", node->xmlChildrenNode)))
774                     act->data.sendtodir.follow = parse_bool(doc, n);
775             } else if (act->func == action_activate) {
776                 if ((n = parse_find_node("here", node->xmlChildrenNode)))
777                     act->data.activate.here = parse_bool(doc, n);
778             }
779         }
780         g_free(actname);
781     }
782     return act;
783 }
784
785 void action_execute(union ActionData *data)
786 {
787     GError *e = NULL;
788     char *cmd;
789     if (data->execute.path) {
790         cmd = g_filename_from_utf8(data->execute.path, -1, NULL, NULL, NULL);
791         if (cmd) {
792             if (!g_spawn_command_line_async(cmd, &e)) {
793                 g_warning("failed to execute '%s': %s",
794                           cmd, e->message);
795             }
796         } else {
797             g_warning("failed to convert '%s' from utf8", data->execute.path);
798         }
799     }
800 }
801
802 void action_activate(union ActionData *data)
803 {
804     if (data->activate.any.c)
805         client_activate(data->activate.any.c, data->activate.here);
806 }
807
808 void action_focus(union ActionData *data)
809 {
810     if (data->client.any.c)
811         client_focus(data->client.any.c);
812 }
813
814 void action_unfocus (union ActionData *data)
815 {
816     if (data->client.any.c)
817         client_unfocus(data->client.any.c);
818 }
819
820 void action_iconify(union ActionData *data)
821 {
822     if (data->client.any.c)
823         client_iconify(data->client.any.c, TRUE, TRUE);
824 }
825
826 void action_raiselower(union ActionData *data)
827 {
828     ObClient *c = data->client.any.c;
829     GList *it;
830     gboolean raise = FALSE;
831
832     if (!c) return;
833
834     for (it = stacking_list; it; it = g_list_next(it)) {
835         ObClient *cit = it->data;
836
837         if (cit == c) break;
838         if (client_normal(cit) == client_normal(c) &&
839             cit->layer == c->layer &&
840             cit->frame->visible)
841         {
842             if (RECT_INTERSECTS_RECT(cit->frame->area, c->frame->area)) {
843                 raise = TRUE;
844                 break;
845             }
846         }
847     }
848
849     if (raise)
850         stacking_raise(CLIENT_AS_WINDOW(c));
851     else
852         stacking_lower(CLIENT_AS_WINDOW(c));
853 }
854
855 void action_raise(union ActionData *data)
856 {
857     if (data->client.any.c)
858         stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
859 }
860
861 void action_unshaderaise(union ActionData *data)
862 {
863     if (data->client.any.c) {
864         if (data->client.any.c->shaded)
865             client_shade(data->client.any.c, FALSE);
866         else
867             stacking_raise(CLIENT_AS_WINDOW(data->client.any.c));
868     }
869 }
870
871 void action_shadelower(union ActionData *data)
872 {
873     if (data->client.any.c) {
874         if (data->client.any.c->shaded)
875             stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
876         else
877             client_shade(data->client.any.c, TRUE);
878     }
879 }
880
881 void action_lower(union ActionData *data)
882 {
883     if (data->client.any.c)
884         stacking_lower(CLIENT_AS_WINDOW(data->client.any.c));
885 }
886
887 void action_close(union ActionData *data)
888 {
889     if (data->client.any.c)
890         client_close(data->client.any.c);
891 }
892
893 void action_kill(union ActionData *data)
894 {
895     if (data->client.any.c)
896         client_kill(data->client.any.c);
897 }
898
899 void action_shade(union ActionData *data)
900 {
901     if (data->client.any.c)
902         client_shade(data->client.any.c, TRUE);
903 }
904
905 void action_unshade(union ActionData *data)
906 {
907     if (data->client.any.c)
908         client_shade(data->client.any.c, FALSE);
909 }
910
911 void action_toggle_shade(union ActionData *data)
912 {
913     if (data->client.any.c)
914         client_shade(data->client.any.c, !data->client.any.c->shaded);
915 }
916
917 void action_toggle_omnipresent(union ActionData *data)
918
919     if (data->client.any.c)
920         client_set_desktop(data->client.any.c,
921                            data->client.any.c->desktop == DESKTOP_ALL ?
922                            screen_desktop : DESKTOP_ALL, FALSE);
923 }
924
925 void action_move_relative_horz(union ActionData *data)
926 {
927     ObClient *c = data->relative.any.c;
928     if (c) {
929         grab_pointer(TRUE, OB_CURSOR_NONE);
930         client_move(c, c->area.x + data->relative.delta, c->area.y);
931         grab_pointer(FALSE, OB_CURSOR_NONE);
932     }
933 }
934
935 void action_move_relative_vert(union ActionData *data)
936 {
937     ObClient *c = data->relative.any.c;
938     if (c) {
939         grab_pointer(TRUE, OB_CURSOR_NONE);
940         client_move(c, c->area.x, c->area.y + data->relative.delta);
941         grab_pointer(FALSE, OB_CURSOR_NONE);
942     }
943 }
944
945 void action_resize_relative_horz(union ActionData *data)
946 {
947     ObClient *c = data->relative.any.c;
948     if (c) {
949         grab_pointer(TRUE, OB_CURSOR_NONE);
950         client_resize(c,
951                       c->area.width + data->relative.delta * c->size_inc.width,
952                       c->area.height);
953         grab_pointer(FALSE, OB_CURSOR_NONE);
954     }
955 }
956
957 void action_resize_relative_vert(union ActionData *data)
958 {
959     ObClient *c = data->relative.any.c;
960     if (c && !c->shaded) {
961         grab_pointer(TRUE, OB_CURSOR_NONE);
962         client_resize(c, c->area.width, c->area.height +
963                       data->relative.delta * c->size_inc.height);
964         grab_pointer(FALSE, OB_CURSOR_NONE);
965     }
966 }
967
968 void action_maximize_full(union ActionData *data)
969 {
970     if (data->client.any.c)
971         client_maximize(data->client.any.c, TRUE, 0, TRUE);
972 }
973
974 void action_unmaximize_full(union ActionData *data)
975 {
976     if (data->client.any.c)
977         client_maximize(data->client.any.c, FALSE, 0, TRUE);
978 }
979
980 void action_toggle_maximize_full(union ActionData *data)
981 {
982     if (data->client.any.c)
983         client_maximize(data->client.any.c,
984                         !(data->client.any.c->max_horz ||
985                           data->client.any.c->max_vert),
986                         0, TRUE);
987 }
988
989 void action_maximize_horz(union ActionData *data)
990 {
991     if (data->client.any.c)
992         client_maximize(data->client.any.c, TRUE, 1, TRUE);
993 }
994
995 void action_unmaximize_horz(union ActionData *data)
996 {
997     if (data->client.any.c)
998         client_maximize(data->client.any.c, FALSE, 1, TRUE);
999 }
1000
1001 void action_toggle_maximize_horz(union ActionData *data)
1002 {
1003     if (data->client.any.c)
1004         client_maximize(data->client.any.c,
1005                         !data->client.any.c->max_horz, 1, TRUE);
1006 }
1007
1008 void action_maximize_vert(union ActionData *data)
1009 {
1010     if (data->client.any.c)
1011         client_maximize(data->client.any.c, TRUE, 2, TRUE);
1012 }
1013
1014 void action_unmaximize_vert(union ActionData *data)
1015 {
1016     if (data->client.any.c)
1017         client_maximize(data->client.any.c, FALSE, 2, TRUE);
1018 }
1019
1020 void action_toggle_maximize_vert(union ActionData *data)
1021 {
1022     if (data->client.any.c)
1023         client_maximize(data->client.any.c, !data->client.any.c->max_vert, 2, TRUE);
1024 }
1025
1026 void action_send_to_desktop(union ActionData *data)
1027 {
1028     ObClient *c = data->sendto.any.c;
1029
1030     if (!c || !client_normal(c)) return;
1031
1032     if (data->sendto.desk < screen_num_desktops ||
1033         data->sendto.desk == DESKTOP_ALL) {
1034         client_set_desktop(c, data->sendto.desk, data->sendto.follow);
1035         if (data->sendto.follow)
1036             screen_set_desktop(data->sendto.desk);
1037     }
1038 }
1039
1040 void action_desktop(union ActionData *data)
1041 {
1042     if (data->desktop.desk < screen_num_desktops ||
1043         data->desktop.desk == DESKTOP_ALL)
1044         screen_set_desktop(data->desktop.desk);
1045 }
1046
1047 void action_desktop_dir(union ActionData *data)
1048 {
1049     guint d;
1050
1051     d = screen_cycle_desktop(data->desktopdir.dir,
1052                              data->desktopdir.wrap,
1053                              data->sendtodir.linear,
1054                              data->desktopdir.inter.any.interactive,
1055                              data->desktopdir.inter.final,
1056                              data->desktopdir.inter.cancel);
1057     screen_set_desktop(d);
1058 }
1059
1060 void action_send_to_desktop_dir(union ActionData *data)
1061 {
1062     ObClient *c = data->sendtodir.inter.any.c;
1063     guint d;
1064
1065     if (!c || !client_normal(c)) return;
1066
1067     d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
1068                              data->sendtodir.linear,
1069                              data->sendtodir.inter.any.interactive,
1070                              data->sendtodir.inter.final,
1071                              data->sendtodir.inter.cancel);
1072     client_set_desktop(c, d, data->sendtodir.follow);
1073     if (data->sendtodir.follow)
1074         screen_set_desktop(d);
1075 }
1076
1077 void action_desktop_last(union ActionData *data)
1078 {
1079     screen_set_desktop(screen_last_desktop);
1080 }
1081
1082 void action_toggle_decorations(union ActionData *data)
1083 {
1084     ObClient *c = data->client.any.c;
1085
1086     if (!c) return;
1087
1088     c->decorate = !c->decorate;
1089     client_setup_decor_and_functions(c);
1090 }
1091
1092 void action_moveresize(union ActionData *data)
1093 {
1094     ObClient *c = data->moveresize.any.c;
1095
1096     if (!c || !client_normal(c)) return;
1097
1098     moveresize_start(c, data->moveresize.x, data->moveresize.y,
1099                      data->moveresize.button, data->moveresize.corner);
1100 }
1101
1102 void action_reconfigure(union ActionData *data)
1103 {
1104     ob_reconfigure();
1105 }
1106
1107 void action_restart(union ActionData *data)
1108 {
1109     ob_restart_other(data->execute.path);
1110 }
1111
1112 void action_exit(union ActionData *data)
1113 {
1114     ob_exit();
1115 }
1116
1117 void action_showmenu(union ActionData *data)
1118 {
1119     if (data->showmenu.name) {
1120         menu_show(data->showmenu.name, data->showmenu.x, data->showmenu.y,
1121                   data->showmenu.any.c);
1122     }
1123 }
1124
1125 void action_cycle_windows(union ActionData *data)
1126 {
1127     focus_cycle(data->cycle.forward, data->cycle.linear,
1128                 data->cycle.inter.any.interactive,
1129                 data->cycle.inter.final, data->cycle.inter.cancel);
1130 }
1131
1132 void action_directional_focus(union ActionData *data)
1133 {
1134     focus_directional_cycle(data->interdiraction.direction,
1135                             data->interdiraction.inter.any.interactive,
1136                             data->interdiraction.inter.final,
1137                             data->interdiraction.inter.cancel);
1138 }
1139
1140 void action_movetoedge(union ActionData *data)
1141 {
1142     int x, y;
1143     ObClient *c = data->diraction.any.c;
1144
1145     if (!c)
1146         return;
1147     x = c->frame->area.x;
1148     y = c->frame->area.y;
1149     
1150     switch(data->diraction.direction) {
1151     case OB_DIRECTION_NORTH:
1152         y = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1153         break;
1154     case OB_DIRECTION_WEST:
1155         x = client_directional_edge_search(c, OB_DIRECTION_WEST);
1156         break;
1157     case OB_DIRECTION_SOUTH:
1158         y = client_directional_edge_search(c, OB_DIRECTION_SOUTH) -
1159             c->frame->area.height;
1160         break;
1161     case OB_DIRECTION_EAST:
1162         x = client_directional_edge_search(c, OB_DIRECTION_EAST) -
1163             c->frame->area.width;
1164         break;
1165     default:
1166         g_assert_not_reached();
1167     }
1168     frame_frame_gravity(c->frame, &x, &y);
1169     grab_pointer(TRUE, OB_CURSOR_NONE);
1170     client_move(c, x, y);
1171     grab_pointer(FALSE, OB_CURSOR_NONE);
1172
1173 }
1174
1175 void action_growtoedge(union ActionData *data)
1176 {
1177     int x, y, width, height, dest;
1178     ObClient *c = data->diraction.any.c;
1179     Rect *a = screen_area(c->desktop);
1180
1181     if (!c)
1182         return;
1183     
1184     x = c->frame->area.x;
1185     y = c->frame->area.y;
1186     width = c->frame->area.width;
1187     height = c->frame->area.height;
1188
1189     switch(data->diraction.direction) {
1190     case OB_DIRECTION_NORTH:
1191         dest = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1192         if (a->y == y)
1193             height = c->frame->area.height / 2;
1194         else {
1195             height = c->frame->area.y + c->frame->area.height - dest;
1196             y = dest;
1197         }
1198         break;
1199     case OB_DIRECTION_WEST:
1200         dest = client_directional_edge_search(c, OB_DIRECTION_WEST);
1201         if (a->x == x)
1202             width = c->frame->area.width / 2;
1203         else {
1204             width = c->frame->area.x + c->frame->area.width - dest;
1205             x = dest;
1206         }
1207         break;
1208     case OB_DIRECTION_SOUTH:
1209         dest = client_directional_edge_search(c, OB_DIRECTION_SOUTH);
1210         if (a->y + a->height == y + c->frame->area.height) {
1211             height = c->frame->area.height / 2;
1212             y = a->y + a->height - height;
1213         } else
1214             height = dest - c->frame->area.y;
1215         y += (height - c->frame->area.height) % c->size_inc.height;
1216         height -= (height - c->frame->area.height) % c->size_inc.height;
1217         break;
1218     case OB_DIRECTION_EAST:
1219         dest = client_directional_edge_search(c, OB_DIRECTION_EAST);
1220         if (a->x + a->width == x + c->frame->area.width) {
1221             width = c->frame->area.width / 2;
1222             x = a->x + a->width - width;
1223         } else
1224             width = dest - c->frame->area.x;
1225         x += (width - c->frame->area.width) % c->size_inc.width;
1226         width -= (width - c->frame->area.width) % c->size_inc.width;
1227         break;
1228     default:
1229         g_assert_not_reached();
1230     }
1231     frame_frame_gravity(c->frame, &x, &y);
1232     width -= c->frame->size.left + c->frame->size.right;
1233     height -= c->frame->size.top + c->frame->size.bottom;
1234     grab_pointer(TRUE, OB_CURSOR_NONE);
1235     client_move_resize(c, x, y, width, height);
1236     grab_pointer(FALSE, OB_CURSOR_NONE);
1237 }
1238
1239 void action_send_to_layer(union ActionData *data)
1240 {
1241     if (data->layer.any.c)
1242         client_set_layer(data->layer.any.c, data->layer.layer);
1243 }
1244
1245 void action_toggle_layer(union ActionData *data)
1246 {
1247     ObClient *c = data->layer.any.c;
1248
1249     if (c) {
1250         if (data->layer.layer < 0)
1251             client_set_layer(c, c->below ? 0 : -1);
1252         else if (data->layer.layer > 0)
1253             client_set_layer(c, c->above ? 0 : 1);
1254     }
1255 }
1256
1257 void action_toggle_show_desktop(union ActionData *data)
1258 {
1259     screen_show_desktop(!screen_showing_desktop);
1260 }
1261
1262 void action_show_desktop(union ActionData *data)
1263 {
1264     screen_show_desktop(TRUE);
1265 }
1266
1267 void action_unshow_desktop(union ActionData *data)
1268 {
1269     screen_show_desktop(FALSE);
1270 }