]> icculus.org git repositories - manmower/openbox.git/blob - openbox/action.c
make the raiselower action smarter
[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         "raiselower",
339         action_raiselower,
340         NULL
341     },
342     {
343         "raise",
344         action_raise,
345         NULL
346     },
347     {
348         "lower",
349         action_lower,
350         NULL
351     },
352     {
353         "close",
354         action_close,
355         NULL
356     },
357     {
358         "kill",
359         action_kill,
360         NULL
361     },
362     {
363         "shadelower",
364         action_shadelower,
365         NULL
366     },
367     {
368         "unshaderaise",
369         action_unshaderaise,
370         NULL
371     },
372     {
373         "shade",
374         action_shade,
375         NULL
376     },
377     {
378         "unshade",
379         action_unshade,
380         NULL
381     },
382     {
383         "toggleshade",
384         action_toggle_shade,
385         NULL
386     },
387     {
388         "toggleomnipresent",
389         action_toggle_omnipresent,
390         NULL
391     },
392     {
393         "moverelativehorz",
394         action_move_relative_horz,
395         NULL
396     },
397     {
398         "moverelativevert",
399         action_move_relative_vert,
400         NULL
401     },
402     {
403         "resizerelativehorz",
404         action_resize_relative_horz,
405         NULL
406     },
407     {
408         "resizerelativevert",
409         action_resize_relative_vert,
410         NULL
411     },
412     {
413         "maximizefull",
414         action_maximize_full,
415         NULL
416     },
417     {
418         "unmaximizefull",
419         action_unmaximize_full,
420         NULL
421     },
422     {
423         "togglemaximizefull",
424         action_toggle_maximize_full,
425         NULL
426     },
427     {
428         "maximizehorz",
429         action_maximize_horz,
430         NULL
431     },
432     {
433         "unmaximizehorz",
434         action_unmaximize_horz,
435         NULL
436     },
437     {
438         "togglemaximizehorz",
439         action_toggle_maximize_horz,
440         NULL
441     },
442     {
443         "maximizevert",
444         action_maximize_vert,
445         NULL
446     },
447     {
448         "unmaximizevert",
449         action_unmaximize_vert,
450         NULL
451     },
452     {
453         "togglemaximizevert",
454         action_toggle_maximize_vert,
455         NULL
456     },
457     {
458         "sendtodesktop",
459         action_send_to_desktop,
460         setup_action_send_to_desktop
461     },
462     {
463         "sendtodesktopnext",
464         action_send_to_desktop_dir,
465         setup_action_send_to_desktop_next
466     },
467     {
468         "sendtodesktopprevious",
469         action_send_to_desktop_dir,
470         setup_action_send_to_desktop_prev
471     },
472     {
473         "sendtodesktopright",
474         action_send_to_desktop_dir,
475         setup_action_send_to_desktop_right
476     },
477     {
478         "sendtodesktopleft",
479         action_send_to_desktop_dir,
480         setup_action_send_to_desktop_left
481     },
482     {
483         "sendtodesktopup",
484         action_send_to_desktop_dir,
485         setup_action_send_to_desktop_up
486     },
487     {
488         "sendtodesktopdown",
489         action_send_to_desktop_dir,
490         setup_action_send_to_desktop_down
491     },
492     {
493         "desktop",
494         action_desktop,
495         NULL
496     },
497     {
498         "desktopnext",
499         action_desktop_dir,
500         setup_action_desktop_next
501     },
502     {
503         "desktopprevious",
504         action_desktop_dir,
505         setup_action_desktop_prev
506     },
507     {
508         "desktopright",
509         action_desktop_dir,
510         setup_action_desktop_right
511     },
512     {
513         "desktopleft",
514         action_desktop_dir,
515         setup_action_desktop_left
516     },
517     {
518         "desktopup",
519         action_desktop_dir,
520         setup_action_desktop_up
521     },
522     {
523         "desktopdown",
524         action_desktop_dir,
525         setup_action_desktop_down
526     },
527     {
528         "toggledecorations",
529         action_toggle_decorations,
530         NULL
531     },
532     {
533         "keyboardmove", 
534         action_moveresize,
535         setup_action_move_keyboard
536     },
537     {
538         "move",
539         action_moveresize,
540         setup_action_move
541     },
542     {
543         "resize",
544         action_moveresize,
545         setup_action_resize
546     },
547     {
548         "keyboardresize",
549         action_moveresize,
550         setup_action_resize_keyboard
551     },
552     {
553         "toggleshowdesktop",
554         action_toggle_show_desktop,
555         NULL
556     },
557     {
558         "showdesktop",
559         action_show_desktop,
560         NULL
561     },
562     {
563         "unshowdesktop",
564         action_unshow_desktop,
565         NULL
566     },
567     {
568         "restart",
569         action_restart,
570         NULL
571     },
572     {
573         "exit",
574         action_exit,
575         NULL
576     },
577     {
578         "showmenu",
579         action_showmenu,
580         NULL
581     },
582     {
583         "sendtotoplayer",
584         action_send_to_layer,
585         setup_action_top_layer
586     },
587     {
588         "togglealwaysontop",
589         action_toggle_layer,
590         setup_action_top_layer
591     },
592     {
593         "sendtonormallayer",
594         action_send_to_layer,
595         setup_action_normal_layer
596     },
597     {
598         "sendtobottomlayer",
599         action_send_to_layer,
600         setup_action_bottom_layer
601     },
602     {
603         "togglealwaysonbottom",
604         action_toggle_layer,
605         setup_action_bottom_layer
606     },
607     {
608         "nextwindowlinear",
609         action_cycle_windows,
610         setup_action_cycle_windows_linear_next
611     },
612     {
613         "previouswindowlinear",
614         action_cycle_windows,
615         setup_action_cycle_windows_linear_previous
616     },
617     {
618         "nextwindow",
619         action_cycle_windows,
620         setup_action_cycle_windows_next
621     },
622     {
623         "previouswindow",
624         action_cycle_windows,
625         setup_action_cycle_windows_previous
626     },
627     {
628         "movetoedgenorth",
629         action_movetoedge,
630         setup_action_movetoedge_north
631     },
632     {
633         "movetoedgesouth",
634         action_movetoedge,
635         setup_action_movetoedge_south
636     },
637     {
638         "movetoedgewest",
639         action_movetoedge,
640         setup_action_movetoedge_west
641     },
642     {
643         "movetoedgeeast",
644         action_movetoedge,
645         setup_action_movetoedge_east
646     },
647     {
648         "growtoedgenorth",
649         action_growtoedge,
650         setup_action_growtoedge_north
651     },
652     {
653         "growtoedgesouth",
654         action_growtoedge,
655         setup_action_growtoedge_south
656     },
657     {
658         "growtoedgewest",
659         action_growtoedge,
660         setup_action_growtoedge_west
661     },
662     {
663         "growtoedgeeast",
664         action_growtoedge,
665         setup_action_growtoedge_east
666     },
667     {
668         NULL,
669         NULL,
670         NULL
671     }
672 };
673
674 ObAction *action_from_string(char *name)
675 {
676     ObAction *a = NULL;
677     int i;
678
679     for (i = 0; actionstrings[i].name; i++)
680         if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
681             a = action_new(actionstrings[i].func);
682             if (actionstrings[i].setup)
683                 actionstrings[i].setup(a);
684             break;
685         }
686     return a;
687 }
688
689 ObAction *action_parse(xmlDocPtr doc, xmlNodePtr node)
690 {
691     char *actname;
692     ObAction *act = NULL;
693     xmlNodePtr n;
694
695     if (parse_attr_string("name", node, &actname)) {
696         if ((act = action_from_string(actname))) {
697             if (act->func == action_execute || act->func == action_restart) {
698                 if ((n = parse_find_node("execute", node->xmlChildrenNode)))
699                     act->data.execute.path = parse_string(doc, n);
700             } else if (act->func == action_showmenu) {
701                 if ((n = parse_find_node("menu", node->xmlChildrenNode)))
702                     act->data.showmenu.name = parse_string(doc, n);
703             } else if (act->func == action_desktop) {
704                 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
705                     act->data.desktop.desk = parse_int(doc, n);
706                 if (act->data.desktop.desk > 0) act->data.desktop.desk--;
707             } else if (act->func == action_send_to_desktop) {
708                 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
709                     act->data.sendto.desk = parse_int(doc, n);
710                 if (act->data.sendto.desk > 0) act->data.sendto.desk--;
711             } else if (act->func == action_move_relative_horz ||
712                        act->func == action_move_relative_vert ||
713                        act->func == action_resize_relative_horz ||
714                        act->func == action_resize_relative_vert) {
715                 if ((n = parse_find_node("delta", node->xmlChildrenNode)))
716                     act->data.relative.delta = parse_int(doc, n);
717             } else if (act->func == action_desktop_dir) {
718                 if ((n = parse_find_node("wrap", node->xmlChildrenNode))) {
719                     act->data.desktopdir.wrap = parse_bool(doc, n);
720                 }
721             } else if (act->func == action_send_to_desktop_dir) {
722                 if ((n = parse_find_node("wrap", node->xmlChildrenNode)))
723                     act->data.sendtodir.wrap = parse_bool(doc, n);
724             } else if (act->func == action_activate) {
725                 if ((n = parse_find_node("here", node->xmlChildrenNode)))
726                     act->data.activate.here = parse_bool(doc, n);
727             }
728         }
729         g_free(actname);
730     }
731     return act;
732 }
733
734 void action_execute(union ActionData *data)
735 {
736     GError *e = NULL;
737     char *cmd;
738     if (data->execute.path) {
739         cmd = g_filename_from_utf8(data->execute.path, -1, NULL, NULL, NULL);
740         if (cmd) {
741             if (!g_spawn_command_line_async(cmd, &e)) {
742                 g_warning("failed to execute '%s': %s",
743                           cmd, e->message);
744             }
745         } else {
746             g_warning("failed to convert '%s' from utf8", data->execute.path);
747         }
748     }
749 }
750
751 void action_activate(union ActionData *data)
752 {
753     if (data->activate.c)
754         client_activate(data->activate.c, data->activate.here);
755 }
756
757 void action_focus(union ActionData *data)
758 {
759     if (data->client.c)
760         client_focus(data->client.c);
761 }
762
763 void action_unfocus (union ActionData *data)
764 {
765     if (data->client.c)
766         client_unfocus(data->client.c);
767 }
768
769 void action_iconify(union ActionData *data)
770 {
771     if (data->client.c)
772         client_iconify(data->client.c, TRUE, TRUE);
773 }
774
775 void action_raiselower(union ActionData *data)
776 {
777     ObClient *c = data->client.c;
778     GList *it;
779     gboolean raise = FALSE;
780
781     if (!c) return;
782
783     for (it = stacking_list; it; it = g_list_next(it)) {
784         ObClient *cit = it->data;
785
786         if (cit == c) break;
787         if (client_normal(cit) && cit->layer == c->layer) {
788             if (RECT_INTERSECTS_RECT(cit->frame->area, c->frame->area)) {
789                 raise = TRUE;
790                 break;
791             }
792         }
793     }
794
795     if (raise)
796         stacking_raise(CLIENT_AS_WINDOW(c));
797     else
798         stacking_lower(CLIENT_AS_WINDOW(c));
799 }
800
801 void action_raise(union ActionData *data)
802 {
803     if (data->client.c)
804         stacking_raise(CLIENT_AS_WINDOW(data->client.c));
805 }
806
807 void action_unshaderaise(union ActionData *data)
808 {
809     if (data->client.c) {
810         if (data->client.c->shaded)
811             client_shade(data->client.c, FALSE);
812         else
813             stacking_raise(CLIENT_AS_WINDOW(data->client.c));
814     }
815 }
816
817 void action_shadelower(union ActionData *data)
818 {
819     if (data->client.c) {
820         if (data->client.c->shaded)
821             stacking_lower(CLIENT_AS_WINDOW(data->client.c));
822         else
823             client_shade(data->client.c, TRUE);
824     }
825 }
826
827 void action_lower(union ActionData *data)
828 {
829     if (data->client.c)
830         stacking_lower(CLIENT_AS_WINDOW(data->client.c));
831 }
832
833 void action_close(union ActionData *data)
834 {
835     if (data->client.c)
836         client_close(data->client.c);
837 }
838
839 void action_kill(union ActionData *data)
840 {
841     if (data->client.c)
842         client_kill(data->client.c);
843 }
844
845 void action_shade(union ActionData *data)
846 {
847     if (data->client.c)
848         client_shade(data->client.c, TRUE);
849 }
850
851 void action_unshade(union ActionData *data)
852 {
853     if (data->client.c)
854         client_shade(data->client.c, FALSE);
855 }
856
857 void action_toggle_shade(union ActionData *data)
858 {
859     if (data->client.c)
860         client_shade(data->client.c, !data->client.c->shaded);
861 }
862
863 void action_toggle_omnipresent(union ActionData *data)
864
865     if (data->client.c)
866         client_set_desktop(data->client.c,
867                            data->client.c->desktop == DESKTOP_ALL ?
868                            screen_desktop : DESKTOP_ALL, FALSE);
869 }
870
871 void action_move_relative_horz(union ActionData *data)
872 {
873     ObClient *c = data->relative.c;
874     if (c)
875         client_configure(c, OB_CORNER_TOPLEFT,
876                          c->area.x + data->relative.delta, c->area.y,
877                          c->area.width, c->area.height, TRUE, TRUE);
878 }
879
880 void action_move_relative_vert(union ActionData *data)
881 {
882     ObClient *c = data->relative.c;
883     if (c)
884         client_configure(c, OB_CORNER_TOPLEFT,
885                          c->area.x, c->area.y + data->relative.delta,
886                          c->area.width, c->area.height, TRUE, TRUE);
887 }
888
889 void action_resize_relative_horz(union ActionData *data)
890 {
891     ObClient *c = data->relative.c;
892     if (c)
893         client_configure(c, OB_CORNER_TOPLEFT, c->area.x, c->area.y,
894                          c->area.width +
895                          data->relative.delta * c->size_inc.width,
896                          c->area.height, TRUE, TRUE);
897 }
898
899 void action_resize_relative_vert(union ActionData *data)
900 {
901     ObClient *c = data->relative.c;
902     if (c && !c->shaded)
903         client_configure(c, OB_CORNER_TOPLEFT, c->area.x, c->area.y,
904                          c->area.width, c->area.height +
905                          data->relative.delta * c->size_inc.height,
906                          TRUE, TRUE);
907 }
908
909 void action_maximize_full(union ActionData *data)
910 {
911     if (data->client.c)
912         client_maximize(data->client.c, TRUE, 0, TRUE);
913 }
914
915 void action_unmaximize_full(union ActionData *data)
916 {
917     if (data->client.c)
918         client_maximize(data->client.c, FALSE, 0, TRUE);
919 }
920
921 void action_toggle_maximize_full(union ActionData *data)
922 {
923     if (data->client.c)
924         client_maximize(data->client.c,
925                         !(data->client.c->max_horz ||
926                           data->client.c->max_vert),
927                         0, TRUE);
928 }
929
930 void action_maximize_horz(union ActionData *data)
931 {
932     if (data->client.c)
933         client_maximize(data->client.c, TRUE, 1, TRUE);
934 }
935
936 void action_unmaximize_horz(union ActionData *data)
937 {
938     if (data->client.c)
939         client_maximize(data->client.c, FALSE, 1, TRUE);
940 }
941
942 void action_toggle_maximize_horz(union ActionData *data)
943 {
944     if (data->client.c)
945         client_maximize(data->client.c, !data->client.c->max_horz, 1, TRUE);
946 }
947
948 void action_maximize_vert(union ActionData *data)
949 {
950     if (data->client.c)
951         client_maximize(data->client.c, TRUE, 2, TRUE);
952 }
953
954 void action_unmaximize_vert(union ActionData *data)
955 {
956     if (data->client.c)
957         client_maximize(data->client.c, FALSE, 2, TRUE);
958 }
959
960 void action_toggle_maximize_vert(union ActionData *data)
961 {
962     if (data->client.c)
963         client_maximize(data->client.c, !data->client.c->max_vert, 2, TRUE);
964 }
965
966 void action_send_to_desktop(union ActionData *data)
967 {
968     ObClient *c = data->sendto.c;
969
970     if (!c || !client_normal(c)) return;
971
972     if (data->sendto.desk < screen_num_desktops ||
973         data->sendto.desk == DESKTOP_ALL) {
974         client_set_desktop(c, data->sendto.desk, TRUE);
975         screen_set_desktop(data->sendto.desk);
976     }
977 }
978
979 void action_desktop(union ActionData *data)
980 {
981     if (data->desktop.desk < screen_num_desktops ||
982         data->desktop.desk == DESKTOP_ALL)
983         screen_set_desktop(data->desktop.desk);
984 }
985
986 void action_desktop_dir(union ActionData *data)
987 {
988     guint d;
989
990     d = screen_cycle_desktop(data->desktopdir.dir, data->desktopdir.wrap,
991                              data->sendtodir.linear,
992                              data->desktopdir.final, data->desktopdir.cancel);
993     screen_set_desktop(d);
994 }
995
996 void action_send_to_desktop_dir(union ActionData *data)
997 {
998     ObClient *c = data->sendtodir.c;
999     guint d;
1000
1001     if (!c || !client_normal(c)) return;
1002
1003     d = screen_cycle_desktop(data->sendtodir.dir, data->sendtodir.wrap,
1004                              data->sendtodir.linear,
1005                              data->sendtodir.final, data->sendtodir.cancel);
1006     client_set_desktop(c, d, TRUE);
1007     screen_set_desktop(d);
1008 }
1009
1010 #if 0
1011 void action_desktop_right(union ActionData *data)
1012 {
1013     guint r, c, d;
1014
1015     cur_row_col(&r, &c);
1016     ++c;
1017     if (c >= screen_desktop_layout.columns) {
1018         if (!data->desktopdir.wrap) return;
1019         c = 0;
1020     }
1021     d = translate_row_col(r, c);
1022     if (d >= screen_num_desktops) {
1023         if (!data->desktopdir.wrap) return;
1024         ++c;
1025     }
1026     d = translate_row_col(r, c);
1027     if (d < screen_num_desktops)
1028         screen_cycle_desktop(d, data->desktopdir.final,
1029                              data->desktopdir.cancel);
1030 }
1031
1032 void action_send_to_desktop_right(union ActionData *data)
1033 {
1034     ObClient *cl = data->sendto.c;
1035     guint r, c, d;
1036
1037     if (!cl || !client_normal(cl)) return;
1038
1039     cur_row_col(&r, &c);
1040     ++c;
1041     if (c >= screen_desktop_layout.columns) {
1042         if (!data->sendtodir.wrap) return;
1043         c = 0;
1044     }
1045     d = translate_row_col(r, c);
1046     if (d >= screen_num_desktops) {
1047         if (!data->sendtodir.wrap) return;
1048         ++c;
1049     }
1050     d = translate_row_col(r, c);
1051     if (d < screen_num_desktops) {
1052         client_set_desktop(cl, d, data->sendtodir.follow);
1053         if (data->sendtodir.follow)
1054             screen_cycle_desktop(d, data->desktopdir.final,
1055                                  data->desktopdir.cancel);
1056     }
1057 }
1058
1059 void action_desktop_left(union ActionData *data)
1060 {
1061     guint r, c, d;
1062
1063     cur_row_col(&r, &c);
1064     --c;
1065     if (c >= screen_desktop_layout.columns) {
1066         if (!data->desktopdir.wrap) return;
1067         c = screen_desktop_layout.columns - 1;
1068     }
1069     d = translate_row_col(r, c);
1070     if (d >= screen_num_desktops) {
1071         if (!data->desktopdir.wrap) return;
1072         --c;
1073     }
1074     d = translate_row_col(r, c);
1075     if (d < screen_num_desktops)
1076         screen_cycle_desktop(d, data->desktopdir.final,
1077                              data->desktopdir.cancel);
1078 }
1079
1080 void action_send_to_desktop_left(union ActionData *data)
1081 {
1082     ObClient *cl = data->sendto.c;
1083     guint r, c, d;
1084
1085     if (!cl || !client_normal(cl)) return;
1086
1087     cur_row_col(&r, &c);
1088     --c;
1089     if (c >= screen_desktop_layout.columns) {
1090         if (!data->sendtodir.wrap) return;
1091         c = screen_desktop_layout.columns - 1;
1092     }
1093     d = translate_row_col(r, c);
1094     if (d >= screen_num_desktops) {
1095         if (!data->sendtodir.wrap) return;
1096         --c;
1097     }
1098     d = translate_row_col(r, c);
1099     if (d < screen_num_desktops) {
1100         client_set_desktop(cl, d, data->sendtodir.follow);
1101         if (data->sendtodir.follow)
1102             screen_cycle_desktop(d, data->desktopdir.final,
1103                                  data->desktopdir.cancel);
1104     }
1105 }
1106
1107 void action_desktop_down(union ActionData *data)
1108 {
1109     guint r, c, d;
1110
1111     cur_row_col(&r, &c);
1112     ++r;
1113     if (r >= screen_desktop_layout.rows) {
1114         if (!data->desktopdir.wrap) return;
1115         r = 0;
1116     }
1117     d = translate_row_col(r, c);
1118     if (d >= screen_num_desktops) {
1119         if (!data->desktopdir.wrap) return;
1120         ++r;
1121     }
1122     d = translate_row_col(r, c);
1123     if (d < screen_num_desktops)
1124         screen_cycle_desktop(d, data->desktopdir.final,
1125                              data->desktopdir.cancel);
1126 }
1127
1128 void action_send_to_desktop_down(union ActionData *data)
1129 {
1130     guint r, c, d;
1131
1132     if (data->sendtodir.c) {
1133         cur_row_col(&r, &c);
1134         ++r;
1135         if (r >= screen_desktop_layout.rows) {
1136             if (!data->sendtodir.wrap) return;
1137             r = 0;
1138         }
1139         d = translate_row_col(r, c);
1140         if (d >= screen_num_desktops) {
1141             if (!data->sendtodir.wrap) return;
1142             ++r;
1143         }
1144         d = translate_row_col(r, c);
1145         if (d < screen_num_desktops) {
1146             client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
1147             if (data->sendtodir.follow)
1148                 screen_cycle_desktop(d, data->desktopdir.final,
1149                                      data->desktopdir.cancel);
1150         }
1151     }
1152 }
1153
1154 void action_desktop_up(union ActionData *data)
1155 {
1156     guint r, c, d;
1157
1158     cur_row_col(&r, &c);
1159     --r;
1160     if (r >= screen_desktop_layout.rows) {
1161         if (!data->desktopdir.wrap) return;
1162         r = screen_desktop_layout.rows - 1;
1163     }
1164     d = translate_row_col(r, c);
1165     if (d >= screen_num_desktops) {
1166         if (!data->desktopdir.wrap) return;
1167         --r;
1168     }
1169     d = translate_row_col(r, c);
1170     if (d < screen_num_desktops)
1171         screen_cycle_desktop(d, data->desktopdir.final,
1172                              data->desktopdir.cancel);
1173 }
1174
1175 void action_send_to_desktop_up(union ActionData *data)
1176 {
1177     guint r, c, d;
1178
1179     if (data->sendtodir.c) {
1180         cur_row_col(&r, &c);
1181         --r;
1182         if (r >= screen_desktop_layout.rows) {
1183             if (!data->sendtodir.wrap) return;
1184             r = screen_desktop_layout.rows - 1;
1185         }
1186         d = translate_row_col(r, c);
1187         if (d >= screen_num_desktops) {
1188             if (!data->sendtodir.wrap) return;
1189             --r;
1190         }
1191         d = translate_row_col(r, c);
1192         if (d < screen_num_desktops) {
1193             client_set_desktop(data->sendtodir.c, d, data->sendtodir.follow);
1194             if (data->sendtodir.follow)
1195                 screen_cycle_desktop(d, data->desktopdir.final,
1196                                      data->desktopdir.cancel);
1197         }
1198     }
1199 }
1200 #endif
1201
1202 void action_toggle_decorations(union ActionData *data)
1203 {
1204     ObClient *c = data->client.c;;
1205
1206     if (!c) return;
1207
1208     c->decorate = !c->decorate;
1209     client_setup_decor_and_functions(c);
1210 }
1211
1212 void action_moveresize(union ActionData *data)
1213 {
1214     ObClient *c = data->moveresize.c;
1215
1216     if (!c || !client_normal(c)) return;
1217
1218     moveresize_start(c, data->moveresize.x, data->moveresize.y,
1219                      data->moveresize.button, data->moveresize.corner);
1220 }
1221
1222 void action_restart(union ActionData *data)
1223 {
1224     ob_restart_other(data->execute.path);
1225 }
1226
1227 void action_exit(union ActionData *data)
1228 {
1229     ob_exit();
1230 }
1231
1232 void action_showmenu(union ActionData *data)
1233 {
1234     if (data->showmenu.name) {
1235         menu_show(data->showmenu.name, data->showmenu.x, data->showmenu.y,
1236                   data->showmenu.c);
1237     }
1238 }
1239
1240 void action_cycle_windows(union ActionData *data)
1241 {
1242     ObClient *c;
1243     
1244     c = focus_cycle(data->cycle.forward, data->cycle.linear, data->cycle.final,
1245                     data->cycle.cancel);
1246 }
1247
1248 void action_directional_focus(union ActionData *data)
1249 {
1250     ObClient *nf;
1251
1252     if (!data->diraction.c)
1253         return;
1254     if ((nf = client_find_directional(data->diraction.c,
1255                                       data->diraction.direction)))
1256         client_activate(nf, FALSE);
1257 }
1258
1259 void action_movetoedge(union ActionData *data)
1260 {
1261     int x, y;
1262     ObClient *c = data->diraction.c;
1263
1264     if (!c)
1265         return;
1266     x = c->frame->area.x;
1267     y = c->frame->area.y;
1268     
1269     switch(data->diraction.direction) {
1270     case OB_DIRECTION_NORTH:
1271         y = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1272         break;
1273     case OB_DIRECTION_WEST:
1274         x = client_directional_edge_search(c, OB_DIRECTION_WEST);
1275         break;
1276     case OB_DIRECTION_SOUTH:
1277         y = client_directional_edge_search(c, OB_DIRECTION_SOUTH) -
1278             c->frame->area.height;
1279         break;
1280     case OB_DIRECTION_EAST:
1281         x = client_directional_edge_search(c, OB_DIRECTION_EAST) -
1282             c->frame->area.width;
1283         break;
1284     default:
1285         g_assert_not_reached();
1286     }
1287     frame_frame_gravity(c->frame, &x, &y);
1288     client_configure(c, OB_CORNER_TOPLEFT,
1289                      x, y, c->area.width, c->area.height, TRUE, TRUE);
1290
1291 }
1292
1293 void action_growtoedge(union ActionData *data)
1294 {
1295     int x, y, width, height, dest;
1296     ObClient *c = data->diraction.c;
1297     Rect *a = screen_area(c->desktop);
1298
1299     if (!c)
1300         return;
1301     
1302     x = c->frame->area.x;
1303     y = c->frame->area.y;
1304     width = c->frame->area.width;
1305     height = c->frame->area.height;
1306
1307     switch(data->diraction.direction) {
1308     case OB_DIRECTION_NORTH:
1309         dest = client_directional_edge_search(c, OB_DIRECTION_NORTH);
1310         if (a->y == y)
1311             height = c->frame->area.height / 2;
1312         else {
1313             height = c->frame->area.y + c->frame->area.height - dest;
1314             y = dest;
1315         }
1316         break;
1317     case OB_DIRECTION_WEST:
1318         dest = client_directional_edge_search(c, OB_DIRECTION_WEST);
1319         if (a->x == x)
1320             width = c->frame->area.width / 2;
1321         else {
1322             width = c->frame->area.x + c->frame->area.width - dest;
1323             x = dest;
1324         }
1325         break;
1326     case OB_DIRECTION_SOUTH:
1327         dest = client_directional_edge_search(c, OB_DIRECTION_SOUTH);
1328         if (a->y + a->height == y + c->frame->area.height) {
1329             height = c->frame->area.height / 2;
1330             y = a->y + a->height - height;
1331         } else
1332             height = dest - c->frame->area.y;
1333         y += (height - c->frame->area.height) % c->size_inc.height;
1334         height -= (height - c->frame->area.height) % c->size_inc.height;
1335         break;
1336     case OB_DIRECTION_EAST:
1337         dest = client_directional_edge_search(c, OB_DIRECTION_EAST);
1338         if (a->x + a->width == x + c->frame->area.width) {
1339             width = c->frame->area.width / 2;
1340             x = a->x + a->width - width;
1341         } else
1342             width = dest - c->frame->area.x;
1343         x += (width - c->frame->area.width) % c->size_inc.width;
1344         width -= (width - c->frame->area.width) % c->size_inc.width;
1345         break;
1346     default:
1347         g_assert_not_reached();
1348     }
1349     frame_frame_gravity(c->frame, &x, &y);
1350     width -= c->frame->size.left + c->frame->size.right;
1351     height -= c->frame->size.top + c->frame->size.bottom;
1352     client_configure(c, OB_CORNER_TOPLEFT, x, y, width, height, TRUE, TRUE);
1353 }
1354
1355 void action_send_to_layer(union ActionData *data)
1356 {
1357     if (data->layer.c)
1358         client_set_layer(data->layer.c, data->layer.layer);
1359 }
1360
1361 void action_toggle_layer(union ActionData *data)
1362 {
1363     ObClient *c = data->layer.c;
1364
1365     if (c) {
1366         if (data->layer.layer < 0)
1367             client_set_layer(c, c->below ? 0 : -1);
1368         else if (data->layer.layer > 0)
1369             client_set_layer(c, c->above ? 0 : 1);
1370     }
1371 }
1372
1373 void action_toggle_show_desktop(union ActionData *data)
1374 {
1375     screen_show_desktop(!screen_showing_desktop);
1376 }
1377
1378 void action_show_desktop(union ActionData *data)
1379 {
1380     screen_show_desktop(TRUE);
1381 }
1382
1383 void action_unshow_desktop(union ActionData *data)
1384 {
1385     screen_show_desktop(FALSE);
1386 }