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