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