]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/action.c
move the keyboard and mouse plugins into the kernel for mucho sexiness.
[mikachu/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_top_layer(ObAction *a)
236 {
237     a->data.layer.layer = 1;
238 }
239
240 void setup_action_normal_layer(ObAction *a)
241 {
242     a->data.layer.layer = 0;
243 }
244
245 void setup_action_bottom_layer(ObAction *a)
246 {
247     a->data.layer.layer = -1;
248 }
249
250 ActionString actionstrings[] =
251 {
252     {
253         "execute", 
254         action_execute, 
255         NULL
256     },
257     {
258         "directionalfocusnorth", 
259         action_directional_focus, 
260         setup_action_directional_focus_north
261     },
262     {
263         "directionalfocuseast", 
264         action_directional_focus, 
265         setup_action_directional_focus_east
266     },
267     {
268         "directionalfocussouth", 
269         action_directional_focus, 
270         setup_action_directional_focus_south
271     },
272     {
273         "directionalfocuswest",
274         action_directional_focus,
275         setup_action_directional_focus_west
276     },
277     {
278         "directionalfocusnortheast",
279         action_directional_focus,
280         setup_action_directional_focus_northeast
281     },
282     {
283         "directionalfocussoutheast",
284         action_directional_focus,
285         setup_action_directional_focus_southeast
286     },
287     {
288         "directionalfocussouthwest",
289         action_directional_focus,
290         setup_action_directional_focus_southwest
291     },
292     {
293         "directionalfocusnorthwest",
294         action_directional_focus,
295         setup_action_directional_focus_northwest
296     },
297     {
298         "focus",
299         action_focus,
300         NULL,
301     },
302     {
303         "unfocus",
304         action_unfocus,
305         NULL
306     },
307     {
308         "iconify",
309         action_iconify,
310         NULL
311     },
312     {
313         "raise",
314         action_raise,
315         NULL
316     },
317     {
318         "lower",
319         action_lower,
320         NULL
321     },
322     {
323         "close",
324         action_close,
325         NULL
326     },
327     {
328         "kill",
329         action_kill,
330         NULL
331     },
332     {
333         "shadelower",
334         action_shadelower,
335         NULL
336     },
337     {
338         "unshaderaise",
339         action_unshaderaise,
340         NULL
341     },
342     {
343         "shade",
344         action_shade,
345         NULL
346     },
347     {
348         "unshade",
349         action_unshade,
350         NULL
351     },
352     {
353         "toggleshade",
354         action_toggle_shade,
355         NULL
356     },
357     {
358         "toggleomnipresent",
359         action_toggle_omnipresent,
360         NULL
361     },
362     {
363         "moverelativehorz",
364         action_move_relative_horz,
365         NULL
366     },
367     {
368         "moverelativevert",
369         action_move_relative_vert,
370         NULL
371     },
372     {
373         "resizerelativehorz",
374         action_resize_relative_horz,
375         NULL
376     },
377     {
378         "resizerelativevert",
379         action_resize_relative_vert,
380         NULL
381     },
382     {
383         "maximizefull",
384         action_maximize_full,
385         NULL
386     },
387     {
388         "unmaximizefull",
389         action_unmaximize_full,
390         NULL
391     },
392     {
393         "togglemaximizefull",
394         action_toggle_maximize_full,
395         NULL
396     },
397     {
398         "maximizehorz",
399         action_maximize_horz,
400         NULL
401     },
402     {
403         "unmaximizehorz",
404         action_unmaximize_horz,
405         NULL
406     },
407     {
408         "togglemaximizehorz",
409         action_toggle_maximize_horz,
410         NULL
411     },
412     {
413         "maximizevert",
414         action_maximize_vert,
415         NULL
416     },
417     {
418         "unmaximizevert",
419         action_unmaximize_vert,
420         NULL
421     },
422     {
423         "togglemaximizevert",
424         action_toggle_maximize_vert,
425         NULL
426     },
427     {
428         "sendtodesktop",
429         action_send_to_desktop,
430         setup_action_send_to_desktop
431     },
432     {
433         "sendtodesktopnext",
434         action_send_to_desktop_dir,
435         setup_action_send_to_desktop_next
436     },
437     {
438         "sendtodesktopprevious",
439         action_send_to_desktop_dir,
440         setup_action_send_to_desktop_prev
441     },
442     {
443         "sendtodesktopright",
444         action_send_to_desktop_dir,
445         setup_action_send_to_desktop_right
446     },
447     {
448         "sendtodesktopleft",
449         action_send_to_desktop_dir,
450         setup_action_send_to_desktop_left
451     },
452     {
453         "sendtodesktopup",
454         action_send_to_desktop_dir,
455         setup_action_send_to_desktop_up
456     },
457     {
458         "sendtodesktopdown",
459         action_send_to_desktop_dir,
460         setup_action_send_to_desktop_down
461     },
462     {
463         "desktop",
464         action_desktop,
465         NULL
466     },
467     {
468         "desktopnext",
469         action_desktop_dir,
470         setup_action_desktop_next
471     },
472     {
473         "desktopprevious",
474         action_desktop_dir,
475         setup_action_desktop_prev
476     },
477     {
478         "desktopright",
479         action_desktop_dir,
480         setup_action_desktop_right
481     },
482     {
483         "desktopleft",
484         action_desktop_dir,
485         setup_action_desktop_left
486     },
487     {
488         "desktopup",
489         action_desktop_dir,
490         setup_action_desktop_up
491     },
492     {
493         "desktopdown",
494         action_desktop_dir,
495         setup_action_desktop_down
496     },
497     {
498         "toggledecorations",
499         action_toggle_decorations,
500         NULL
501     },
502     {
503         "keyboardmove", 
504         action_moveresize,
505         setup_action_move_keyboard
506     },
507     {
508         "move",
509         action_moveresize,
510         setup_action_move
511     },
512     {
513         "resize",
514         action_moveresize,
515         setup_action_resize
516     },
517     {
518         "keyboardresize",
519         action_moveresize,
520         setup_action_resize_keyboard
521     },
522     {
523         "toggleshowdesktop",
524         action_toggle_show_desktop,
525         NULL
526     },
527     {
528         "showdesktop",
529         action_show_desktop,
530         NULL
531     },
532     {
533         "unshowdesktop",
534         action_unshow_desktop,
535         NULL
536     },
537     {
538         "restart",
539         action_restart,
540         NULL
541     },
542     {
543         "exit",
544         action_exit,
545         NULL
546     },
547     {
548         "showmenu",
549         action_showmenu,
550         NULL
551     },
552     {
553         "sendtotoplayer",
554         action_send_to_layer,
555         setup_action_top_layer
556     },
557     {
558         "togglealwaysontop",
559         action_toggle_layer,
560         setup_action_top_layer
561     },
562     {
563         "sendtonormallayer",
564         action_send_to_layer,
565         setup_action_normal_layer
566     },
567     {
568         "sendtobottomlayer",
569         action_send_to_layer,
570         setup_action_bottom_layer
571     },
572     {
573         "togglealwaysonbottom",
574         action_toggle_layer,
575         setup_action_bottom_layer
576     },
577     {
578         "nextwindowlinear",
579         action_cycle_windows,
580         setup_action_cycle_windows_linear_next
581     },
582     {
583         "previouswindowlinear",
584         action_cycle_windows,
585         setup_action_cycle_windows_linear_previous
586     },
587     {
588         "nextwindow",
589         action_cycle_windows,
590         setup_action_cycle_windows_next
591     },
592     {
593         "previouswindow",
594         action_cycle_windows,
595         setup_action_cycle_windows_previous
596     },
597     {
598         "movetoedgenorth",
599         action_movetoedge,
600         setup_action_movetoedge_north
601     },
602     {
603         "movetoedgesouth",
604         action_movetoedge,
605         setup_action_movetoedge_south
606     },
607     {
608         "movetoedgewest",
609         action_movetoedge,
610         setup_action_movetoedge_west
611     },
612     {
613         "movetoedgeeast",
614         action_movetoedge,
615         setup_action_movetoedge_east
616     },
617     {
618         NULL,
619         NULL,
620         NULL
621     }
622 };
623
624 ObAction *action_from_string(char *name)
625 {
626     ObAction *a = NULL;
627     int i;
628
629     for (i = 0; actionstrings[i].name; i++)
630         if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
631             a = action_new(actionstrings[i].func);
632             if (actionstrings[i].setup)
633                 actionstrings[i].setup(a);
634             break;
635         }
636     return a;
637 }
638
639 ObAction *action_parse(xmlDocPtr doc, xmlNodePtr node)
640 {
641     char *actname;
642     ObAction *act = NULL;
643     xmlNodePtr n;
644
645     if (parse_attr_string("name", node, &actname)) {
646         if ((act = action_from_string(actname))) {
647             if (act->func == action_execute || act->func == action_restart) {
648                 if ((n = parse_find_node("execute", node->xmlChildrenNode)))
649                     act->data.execute.path = parse_string(doc, n);
650             } else if (act->func == action_showmenu) {
651                 if ((n = parse_find_node("menu", node->xmlChildrenNode)))
652                     act->data.showmenu.name = parse_string(doc, n);
653             } else if (act->func == action_desktop) {
654                 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
655                     act->data.desktop.desk = parse_int(doc, n);
656                 if (act->data.desktop.desk > 0) act->data.desktop.desk--;
657             } else if (act->func == action_send_to_desktop) {
658                 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
659                     act->data.sendto.desk = parse_int(doc, n);
660                 if (act->data.sendto.desk > 0) act->data.sendto.desk--;
661             } else if (act->func == action_move_relative_horz ||
662                        act->func == action_move_relative_vert ||
663                        act->func == action_resize_relative_horz ||
664                        act->func == action_resize_relative_vert) {
665                 if ((n = parse_find_node("delta", node->xmlChildrenNode)))
666                     act->data.relative.delta = parse_int(doc, n);
667             } else if (act->func == action_desktop_dir) {
668                 if ((n = parse_find_node("wrap", node->xmlChildrenNode))) {
669                     act->data.desktopdir.wrap = parse_bool(doc, n);
670                 }
671             } else if (act->func == action_send_to_desktop_dir) {
672                 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
673                     act->data.sendtodir.wrap = parse_bool(doc, n);
674             }
675         }
676         g_free(actname);
677     }
678     return act;
679 }
680
681 void action_execute(union ActionData *data)
682 {
683     GError *e = NULL;
684     char *cmd;
685     if (data->execute.path) {
686         cmd = g_filename_from_utf8(data->execute.path, -1, NULL, NULL, NULL);
687         if (cmd) {
688             if (!g_spawn_command_line_async(cmd, &e)) {
689                 g_warning("failed to execute '%s': %s",
690                           cmd, e->message);
691             }
692         } else {
693             g_warning("failed to convert '%s' from utf8", data->execute.path);
694         }
695     }
696 }
697
698 void action_focus(union ActionData *data)
699 {
700     if (data->client.c)
701         client_focus(data->client.c);
702 }
703
704 void action_unfocus (union ActionData *data)
705 {
706     if (data->client.c)
707         client_unfocus(data->client.c);
708 }
709
710 void action_iconify(union ActionData *data)
711 {
712     if (data->client.c)
713         client_iconify(data->client.c, TRUE, TRUE);
714 }
715
716 void action_raise(union ActionData *data)
717 {
718     if (data->client.c)
719         stacking_raise(CLIENT_AS_WINDOW(data->client.c));
720 }
721
722 void action_unshaderaise(union ActionData *data)
723 {
724     if (data->client.c) {
725         if (data->client.c->shaded)
726             client_shade(data->client.c, FALSE);
727         else
728             stacking_raise(CLIENT_AS_WINDOW(data->client.c));
729     }
730 }
731
732 void action_shadelower(union ActionData *data)
733 {
734     if (data->client.c) {
735         if (data->client.c->shaded)
736             stacking_lower(CLIENT_AS_WINDOW(data->client.c));
737         else
738             client_shade(data->client.c, TRUE);
739     }
740 }
741
742 void action_lower(union ActionData *data)
743 {
744     if (data->client.c)
745         stacking_lower(CLIENT_AS_WINDOW(data->client.c));
746 }
747
748 void action_close(union ActionData *data)
749 {
750     if (data->client.c)
751         client_close(data->client.c);
752 }
753
754 void action_kill(union ActionData *data)
755 {
756     if (data->client.c)
757         client_kill(data->client.c);
758 }
759
760 void action_shade(union ActionData *data)
761 {
762     if (data->client.c)
763         client_shade(data->client.c, TRUE);
764 }
765
766 void action_unshade(union ActionData *data)
767 {
768     if (data->client.c)
769         client_shade(data->client.c, FALSE);
770 }
771
772 void action_toggle_shade(union ActionData *data)
773 {
774     if (data->client.c)
775         client_shade(data->client.c, !data->client.c->shaded);
776 }
777
778 void action_toggle_omnipresent(union ActionData *data)
779
780     if (data->client.c)
781         client_set_desktop(data->client.c,
782                            data->client.c->desktop == DESKTOP_ALL ?
783                            screen_desktop : DESKTOP_ALL, FALSE);
784 }
785
786 void action_move_relative_horz(union ActionData *data)
787 {
788     ObClient *c = data->relative.c;
789     if (c)
790         client_configure(c, OB_CORNER_TOPLEFT,
791                          c->area.x + data->relative.delta, c->area.y,
792                          c->area.width, c->area.height, TRUE, TRUE);
793 }
794
795 void action_move_relative_vert(union ActionData *data)
796 {
797     ObClient *c = data->relative.c;
798     if (c)
799         client_configure(c, OB_CORNER_TOPLEFT,
800                          c->area.x, c->area.y + data->relative.delta,
801                          c->area.width, c->area.height, TRUE, TRUE);
802 }
803
804 void action_resize_relative_horz(union ActionData *data)
805 {
806     ObClient *c = data->relative.c;
807     if (c)
808         client_configure(c, OB_CORNER_TOPLEFT, c->area.x, c->area.y,
809                          c->area.width +
810                          data->relative.delta * c->size_inc.width,
811                          c->area.height, TRUE, TRUE);
812 }
813
814 void action_resize_relative_vert(union ActionData *data)
815 {
816     ObClient *c = data->relative.c;
817     if (c && !c->shaded)
818         client_configure(c, OB_CORNER_TOPLEFT, c->area.x, c->area.y,
819                          c->area.width, c->area.height +
820                          data->relative.delta * c->size_inc.height,
821                          TRUE, TRUE);
822 }
823
824 void action_maximize_full(union ActionData *data)
825 {
826     if (data->client.c)
827         client_maximize(data->client.c, TRUE, 0, TRUE);
828 }
829
830 void action_unmaximize_full(union ActionData *data)
831 {
832     if (data->client.c)
833         client_maximize(data->client.c, FALSE, 0, TRUE);
834 }
835
836 void action_toggle_maximize_full(union ActionData *data)
837 {
838     if (data->client.c)
839         client_maximize(data->client.c,
840                         !(data->client.c->max_horz ||
841                           data->client.c->max_vert),
842                         0, TRUE);
843 }
844
845 void action_maximize_horz(union ActionData *data)
846 {
847     if (data->client.c)
848         client_maximize(data->client.c, TRUE, 1, TRUE);
849 }
850
851 void action_unmaximize_horz(union ActionData *data)
852 {
853     if (data->client.c)
854         client_maximize(data->client.c, FALSE, 1, TRUE);
855 }
856
857 void action_toggle_maximize_horz(union ActionData *data)
858 {
859     if (data->client.c)
860         client_maximize(data->client.c, !data->client.c->max_horz, 1, TRUE);
861 }
862
863 void action_maximize_vert(union ActionData *data)
864 {
865     if (data->client.c)
866         client_maximize(data->client.c, TRUE, 2, TRUE);
867 }
868
869 void action_unmaximize_vert(union ActionData *data)
870 {
871     if (data->client.c)
872         client_maximize(data->client.c, FALSE, 2, TRUE);
873 }
874
875 void action_toggle_maximize_vert(union ActionData *data)
876 {
877     if (data->client.c)
878         client_maximize(data->client.c, !data->client.c->max_vert, 2, TRUE);
879 }
880
881 void action_send_to_desktop(union ActionData *data)
882 {
883     ObClient *c = data->sendto.c;
884
885     if (!c || !client_normal(c)) return;
886
887     if (data->sendto.desk < screen_num_desktops ||
888         data->sendto.desk == DESKTOP_ALL) {
889         client_set_desktop(c, data->sendto.desk, TRUE);
890         screen_set_desktop(data->sendto.desk);
891     }
892 }
893
894 void action_desktop(union ActionData *data)
895 {
896     if (data->desktop.desk < screen_num_desktops ||
897         data->desktop.desk == DESKTOP_ALL)
898         screen_set_desktop(data->desktop.desk);
899 }
900
901 void action_desktop_dir(union ActionData *data)
902 {
903     guint d;
904
905     d = screen_cycle_desktop(data->desktopdir.dir, data->desktopdir.wrap,
906                              data->sendtodir.linear,
907                              data->desktopdir.final, data->desktopdir.cancel);
908     screen_set_desktop(d);
909 }
910
911 void action_send_to_desktop_dir(union ActionData *data)
912 {
913     ObClient *c = data->sendtodir.c;
914     guint d;
915
916     if (!c || !client_normal(c)) return;
917
918     d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
919                              data->sendtodir.linear,
920                              data->sendtodir.final, data->sendtodir.cancel);
921
922     g_message("sendto %d", d);
923
924     client_set_desktop(c, d, TRUE);
925     screen_set_desktop(d);
926 }
927
928 #if 0
929 void action_desktop_right(union ActionData *data)
930 {
931     guint r, c, d;
932
933     cur_row_col(&r, &c);
934     ++c;
935     if (c >= screen_desktop_layout.columns) {
936         if (!data->desktopdir.wrap) return;
937         c = 0;
938     }
939     d = translate_row_col(r, c);
940     if (d >= screen_num_desktops) {
941         if (!data->desktopdir.wrap) return;
942         ++c;
943     }
944     d = translate_row_col(r, c);
945     if (d < screen_num_desktops)
946         screen_cycle_desktop(d, data->desktopdir.final,
947                              data->desktopdir.cancel);
948 }
949
950 void action_send_to_desktop_right(union ActionData *data)
951 {
952     ObClient *cl = data->sendto.c;
953     guint r, c, d;
954
955     if (!cl || !client_normal(cl)) return;
956
957     cur_row_col(&r, &c);
958     ++c;
959     if (c >= screen_desktop_layout.columns) {
960         if (!data->sendtodir.wrap) return;
961         c = 0;
962     }
963     d = translate_row_col(r, c);
964     if (d >= screen_num_desktops) {
965         if (!data->sendtodir.wrap) return;
966         ++c;
967     }
968     d = translate_row_col(r, c);
969     if (d < screen_num_desktops) {
970         client_set_desktop(cl, d, data->sendtodir.follow);
971         if (data->sendtodir.follow)
972             screen_cycle_desktop(d, data->desktopdir.final,
973                                  data->desktopdir.cancel);
974     }
975 }
976
977 void action_desktop_left(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 = screen_desktop_layout.columns - 1;
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_left(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 = screen_desktop_layout.columns - 1;
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_down(union ActionData *data)
1026 {
1027     guint r, c, d;
1028
1029     cur_row_col(&r, &c);
1030     ++r;
1031     if (r >= screen_desktop_layout.rows) {
1032         if (!data->desktopdir.wrap) return;
1033         r = 0;
1034     }
1035     d = translate_row_col(r, c);
1036     if (d >= screen_num_desktops) {
1037         if (!data->desktopdir.wrap) return;
1038         ++r;
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_down(union ActionData *data)
1047 {
1048     guint r, c, d;
1049
1050     if (data->sendtodir.c) {
1051         cur_row_col(&r, &c);
1052         ++r;
1053         if (r >= screen_desktop_layout.rows) {
1054             if (!data->sendtodir.wrap) return;
1055             r = 0;
1056         }
1057         d = translate_row_col(r, c);
1058         if (d >= screen_num_desktops) {
1059             if (!data->sendtodir.wrap) return;
1060             ++r;
1061         }
1062         d = translate_row_col(r, c);
1063         if (d < screen_num_desktops) {
1064             client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
1065             if (data->sendtodir.follow)
1066                 screen_cycle_desktop(d, data->desktopdir.final,
1067                                      data->desktopdir.cancel);
1068         }
1069     }
1070 }
1071
1072 void action_desktop_up(union ActionData *data)
1073 {
1074     guint r, c, d;
1075
1076     cur_row_col(&r, &c);
1077     --r;
1078     if (r >= screen_desktop_layout.rows) {
1079         if (!data->desktopdir.wrap) return;
1080         r = screen_desktop_layout.rows - 1;
1081     }
1082     d = translate_row_col(r, c);
1083     if (d >= screen_num_desktops) {
1084         if (!data->desktopdir.wrap) return;
1085         --r;
1086     }
1087     d = translate_row_col(r, c);
1088     if (d < screen_num_desktops)
1089         screen_cycle_desktop(d, data->desktopdir.final,
1090                              data->desktopdir.cancel);
1091 }
1092
1093 void action_send_to_desktop_up(union ActionData *data)
1094 {
1095     guint r, c, d;
1096
1097     if (data->sendtodir.c) {
1098         cur_row_col(&r, &c);
1099         --r;
1100         if (r >= screen_desktop_layout.rows) {
1101             if (!data->sendtodir.wrap) return;
1102             r = screen_desktop_layout.rows - 1;
1103         }
1104         d = translate_row_col(r, c);
1105         if (d >= screen_num_desktops) {
1106             if (!data->sendtodir.wrap) return;
1107             --r;
1108         }
1109         d = translate_row_col(r, c);
1110         if (d < screen_num_desktops) {
1111             client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
1112             if (data->sendtodir.follow)
1113                 screen_cycle_desktop(d, data->desktopdir.final,
1114                                      data->desktopdir.cancel);
1115         }
1116     }
1117 }
1118 #endif
1119
1120 void action_toggle_decorations(union ActionData *data)
1121 {
1122     ObClient *c = data->client.c;;
1123
1124     if (!c) return;
1125
1126     c->decorate = !c->decorate;
1127     client_setup_decor_and_functions(c);
1128 }
1129
1130 void action_moveresize(union ActionData *data)
1131 {
1132     ObClient *c = data->moveresize.c;
1133
1134     if (!c || !client_normal(c)) return;
1135
1136     moveresize_start(c, data->moveresize.x, data->moveresize.y,
1137                      data->moveresize.button, data->moveresize.corner);
1138 }
1139
1140 void action_restart(union ActionData *data)
1141 {
1142     ob_restart_other(data->execute.path);
1143 }
1144
1145 void action_exit(union ActionData *data)
1146 {
1147     ob_exit();
1148 }
1149
1150 void action_showmenu(union ActionData *data)
1151 {
1152     if (data->showmenu.name) {
1153         menu_show(data->showmenu.name, data->showmenu.x, data->showmenu.y,
1154                   data->showmenu.c);
1155     }
1156 }
1157
1158 void action_cycle_windows(union ActionData *data)
1159 {
1160     ObClient *c;
1161     
1162     c = focus_cycle(data->cycle.forward, data->cycle.linear, data->cycle.final,
1163                     data->cycle.cancel);
1164 }
1165
1166 void action_directional_focus(union ActionData *data)
1167 {
1168     ObClient *nf;
1169
1170     if (!data->diraction.c)
1171         return;
1172     if ((nf = client_find_directional(data->diraction.c,
1173                                       data->diraction.direction)))
1174         client_activate(nf);
1175 }
1176
1177 void action_movetoedge(union ActionData *data)
1178 {
1179     int x, y, h, w;
1180     ObClient *c = data->diraction.c;
1181
1182     if (!c)
1183         return;
1184     x = c->frame->area.x;
1185     y = c->frame->area.y;
1186     
1187     h = screen_area(c->desktop)->height;
1188     w = screen_area(c->desktop)->width;
1189     switch(data->diraction.direction) {
1190     case OB_DIRECTION_NORTH:
1191         y = 0;
1192         break;
1193     case OB_DIRECTION_WEST:
1194         x = 0;
1195         break;
1196     case OB_DIRECTION_SOUTH:
1197         y = h - c->frame->area.height;
1198         break;
1199     case OB_DIRECTION_EAST:
1200         x = w - c->frame->area.width;
1201         break;
1202     default:
1203         g_assert_not_reached();
1204     }
1205     frame_frame_gravity(c->frame, &x, &y);
1206     client_configure(c, OB_CORNER_TOPLEFT,
1207                      x, y, c->area.width, c->area.height, TRUE, TRUE);
1208
1209 }
1210
1211 void action_send_to_layer(union ActionData *data)
1212 {
1213     if (data->layer.c)
1214         client_set_layer(data->layer.c, data->layer.layer);
1215 }
1216
1217 void action_toggle_layer(union ActionData *data)
1218 {
1219     ObClient *c = data->layer.c;
1220
1221     if (c) {
1222         if (data->layer.layer < 0)
1223             client_set_layer(c, c->below ? 0 : -1);
1224         else if (data->layer.layer > 0)
1225             client_set_layer(c, c->above ? 0 : 1);
1226     }
1227 }
1228
1229 void action_toggle_show_desktop(union ActionData *data)
1230 {
1231     screen_show_desktop(!screen_showing_desktop);
1232 }
1233
1234 void action_show_desktop(union ActionData *data)
1235 {
1236     screen_show_desktop(TRUE);
1237 }
1238
1239 void action_unshow_desktop(union ActionData *data)
1240 {
1241     screen_show_desktop(FALSE);
1242 }