11 Action
*action_new(void (*func
)(union ActionData
*data
))
13 Action
*a
= g_new0(Action
, 1);
16 /* deal with pointers */
17 if (func
== action_execute
)
18 a
->data
.execute
.path
= NULL
;
23 void action_free(Action
*a
)
25 if (a
== NULL
) return;
27 /* deal with pointers */
28 if (a
->func
== action_execute
|| a
->func
== action_restart
)
29 g_free(a
->data
.execute
.path
);
34 Action
*action_from_string(char *name
)
37 if (!g_ascii_strcasecmp(name
, "execute")) {
38 a
= action_new(action_execute
);
39 } else if (!g_ascii_strcasecmp(name
, "focus")) {
40 a
= action_new(action_focus
);
41 } else if (!g_ascii_strcasecmp(name
, "unfocus")) {
42 a
= action_new(action_unfocus
);
43 } else if (!g_ascii_strcasecmp(name
, "iconify")) {
44 a
= action_new(action_iconify
);
45 } else if (!g_ascii_strcasecmp(name
, "raise")) {
46 a
= action_new(action_raise
);
47 } else if (!g_ascii_strcasecmp(name
, "lower")) {
48 a
= action_new(action_lower
);
49 } else if (!g_ascii_strcasecmp(name
, "focusraise")) {
50 a
= action_new(action_focusraise
);
51 } else if (!g_ascii_strcasecmp(name
, "close")) {
52 a
= action_new(action_close
);
53 } else if (!g_ascii_strcasecmp(name
, "kill")) {
54 a
= action_new(action_kill
);
55 } else if (!g_ascii_strcasecmp(name
, "shadelower")) {
56 a
= action_new(action_shadelower
);
57 } else if (!g_ascii_strcasecmp(name
, "unshaderaise")) {
58 a
= action_new(action_unshaderaise
);
59 } else if (!g_ascii_strcasecmp(name
, "shade")) {
60 a
= action_new(action_shade
);
61 } else if (!g_ascii_strcasecmp(name
, "unshade")) {
62 a
= action_new(action_unshade
);
63 } else if (!g_ascii_strcasecmp(name
, "toggleshade")) {
64 a
= action_new(action_toggle_shade
);
65 } else if (!g_ascii_strcasecmp(name
, "toggleomnipresent")) {
66 a
= action_new(action_toggle_omnipresent
);
67 } else if (!g_ascii_strcasecmp(name
, "moverelativehorz")) {
68 a
= action_new(action_move_relative_horz
);
69 } else if (!g_ascii_strcasecmp(name
, "moverelativevert")) {
70 a
= action_new(action_move_relative_vert
);
71 } else if (!g_ascii_strcasecmp(name
, "resizerelativehorz")) {
72 a
= action_new(action_resize_relative_horz
);
73 } else if (!g_ascii_strcasecmp(name
, "resizerelativevert")) {
74 a
= action_new(action_resize_relative_vert
);
75 } else if (!g_ascii_strcasecmp(name
, "maximizefull")) {
76 a
= action_new(action_maximize_full
);
77 } else if (!g_ascii_strcasecmp(name
, "unmaximizefull")) {
78 a
= action_new(action_unmaximize_full
);
79 } else if (!g_ascii_strcasecmp(name
, "togglemaximizefull")) {
80 a
= action_new(action_toggle_maximize_full
);
81 } else if (!g_ascii_strcasecmp(name
, "maximizehorz")) {
82 a
= action_new(action_maximize_horz
);
83 } else if (!g_ascii_strcasecmp(name
, "unmaximizehorz")) {
84 a
= action_new(action_unmaximize_horz
);
85 } else if (!g_ascii_strcasecmp(name
, "togglemaximizehorz")) {
86 a
= action_new(action_toggle_maximize_horz
);
87 } else if (!g_ascii_strcasecmp(name
, "maximizevert")) {
88 a
= action_new(action_maximize_vert
);
89 } else if (!g_ascii_strcasecmp(name
, "unmaximizevert")) {
90 a
= action_new(action_unmaximize_vert
);
91 } else if (!g_ascii_strcasecmp(name
, "togglemaximizevert")) {
92 a
= action_new(action_toggle_maximize_vert
);
93 } else if (!g_ascii_strcasecmp(name
, "sendtonextdesktop")) {
94 a
= action_new(action_send_to_next_desktop
);
95 a
->data
.sendtonextprev
.wrap
= FALSE
;
96 a
->data
.sendtonextprev
.follow
= TRUE
;
97 } else if (!g_ascii_strcasecmp(name
, "sendtonextdesktopwrap")) {
98 a
= action_new(action_send_to_next_desktop
);
99 a
->data
.sendtonextprev
.wrap
= TRUE
;
100 a
->data
.sendtonextprev
.follow
= TRUE
;
101 } else if (!g_ascii_strcasecmp(name
, "sendtopreviousdesktop")) {
102 a
= action_new(action_send_to_previous_desktop
);
103 a
->data
.sendtonextprev
.wrap
= FALSE
;
104 a
->data
.sendtonextprev
.follow
= TRUE
;
105 } else if (!g_ascii_strcasecmp(name
, "sendtopreviousdesktopwrap")) {
106 a
= action_new(action_send_to_previous_desktop
);
107 a
->data
.sendtonextprev
.wrap
= TRUE
;
108 a
->data
.sendtonextprev
.follow
= TRUE
;
109 } else if (!g_ascii_strcasecmp(name
, "desktop")) {
110 a
= action_new(action_desktop
);
111 } else if (!g_ascii_strcasecmp(name
, "nextdesktop")) {
112 a
= action_new(action_next_desktop
);
113 a
->data
.nextprevdesktop
.wrap
= FALSE
;
114 } else if (!g_ascii_strcasecmp(name
, "nextdesktopwrap")) {
115 a
= action_new(action_next_desktop
);
116 a
->data
.nextprevdesktop
.wrap
= TRUE
;
117 } else if (!g_ascii_strcasecmp(name
, "previousdesktop")) {
118 a
= action_new(action_previous_desktop
);
119 a
->data
.nextprevdesktop
.wrap
= FALSE
;
120 } else if (!g_ascii_strcasecmp(name
, "previousdesktopwrap")) {
121 a
= action_new(action_previous_desktop
);
122 a
->data
.nextprevdesktop
.wrap
= TRUE
;
123 } else if (!g_ascii_strcasecmp(name
, "nextdesktopcolumn")) {
124 a
= action_new(action_next_desktop_column
);
125 a
->data
.nextprevdesktop
.wrap
= FALSE
;
126 } else if (!g_ascii_strcasecmp(name
, "nextdesktopcolumnwrap")) {
127 a
= action_new(action_next_desktop_column
);
128 a
->data
.nextprevdesktop
.wrap
= TRUE
;
129 } else if (!g_ascii_strcasecmp(name
, "previousdesktopcolumn")) {
130 a
= action_new(action_previous_desktop_column
);
131 a
->data
.nextprevdesktop
.wrap
= FALSE
;
132 } else if (!g_ascii_strcasecmp(name
, "previousdesktopcolumnwrap")) {
133 a
= action_new(action_previous_desktop_column
);
134 a
->data
.nextprevdesktop
.wrap
= TRUE
;
135 } else if (!g_ascii_strcasecmp(name
, "nextdesktoprow")) {
136 a
= action_new(action_next_desktop_row
);
137 a
->data
.nextprevdesktop
.wrap
= FALSE
;
138 } else if (!g_ascii_strcasecmp(name
, "nextdesktoprowwrap")) {
139 a
= action_new(action_next_desktop_row
);
140 a
->data
.nextprevdesktop
.wrap
= TRUE
;
141 } else if (!g_ascii_strcasecmp(name
, "previousdesktoprow")) {
142 a
= action_new(action_previous_desktop_row
);
143 a
->data
.nextprevdesktop
.wrap
= FALSE
;
144 } else if (!g_ascii_strcasecmp(name
, "previousdesktoprowwrap")) {
145 a
= action_new(action_previous_desktop_row
);
146 a
->data
.nextprevdesktop
.wrap
= TRUE
;
147 } else if (!g_ascii_strcasecmp(name
, "toggledecorations")) {
148 a
= action_new(action_toggle_decorations
);
149 } else if (!g_ascii_strcasecmp(name
, "move")) {
150 a
= action_new(action_move
);
151 } else if (!g_ascii_strcasecmp(name
, "resize")) {
152 a
= action_new(action_resize
);
153 } else if (!g_ascii_strcasecmp(name
, "restart")) {
154 a
= action_new(action_restart
);
155 } else if (!g_ascii_strcasecmp(name
, "exit")) {
156 a
= action_new(action_exit
);
161 void action_execute(union ActionData
*data
)
164 if (data
->execute
.path
)
165 if (!g_spawn_command_line_async(data
->execute
.path
, &e
)) {
166 g_warning("failed to execute '%s': %s",
167 data
->execute
.path
, e
->message
);
171 void action_focus(union ActionData
*data
)
174 client_focus(data
->client
.c
);
177 void action_unfocus (union ActionData
*data
)
180 client_unfocus(data
->client
.c
);
183 void action_iconify(union ActionData
*data
)
186 client_iconify(data
->client
.c
, TRUE
, TRUE
);
189 void action_focusraise(union ActionData
*data
)
191 if (data
->client
.c
) {
192 client_focus(data
->client
.c
);
193 stacking_raise(data
->client
.c
);
197 void action_raise(union ActionData
*data
)
200 stacking_raise(data
->client
.c
);
203 void action_unshaderaise(union ActionData
*data
)
205 if (data
->client
.c
) {
206 if (data
->client
.c
->shaded
)
207 client_shade(data
->client
.c
, FALSE
);
209 stacking_raise(data
->client
.c
);
213 void action_shadelower(union ActionData
*data
)
215 if (data
->client
.c
) {
216 if (data
->client
.c
->shaded
)
217 stacking_lower(data
->client
.c
);
219 client_shade(data
->client
.c
, TRUE
);
223 void action_lower(union ActionData
*data
)
226 stacking_lower(data
->client
.c
);
229 void action_close(union ActionData
*data
)
232 client_close(data
->client
.c
);
235 void action_kill(union ActionData
*data
)
238 client_kill(data
->client
.c
);
241 void action_shade(union ActionData
*data
)
244 client_shade(data
->client
.c
, TRUE
);
247 void action_unshade(union ActionData
*data
)
250 client_shade(data
->client
.c
, FALSE
);
253 void action_toggle_shade(union ActionData
*data
)
256 client_shade(data
->client
.c
, !data
->client
.c
->shaded
);
259 void action_toggle_omnipresent(union ActionData
*data
)
262 client_set_desktop(data
->client
.c
,
263 data
->client
.c
->desktop
== DESKTOP_ALL
?
264 screen_desktop
: DESKTOP_ALL
, FALSE
);
267 void action_move_relative_horz(union ActionData
*data
)
269 Client
*c
= data
->relative
.c
;
271 client_configure(c
, Corner_TopLeft
,
272 c
->area
.x
+ data
->relative
.delta
, c
->area
.y
,
273 c
->area
.width
, c
->area
.height
, TRUE
, TRUE
);
276 void action_move_relative_vert(union ActionData
*data
)
278 Client
*c
= data
->relative
.c
;
280 client_configure(c
, Corner_TopLeft
,
281 c
->area
.x
, c
->area
.y
+ data
->relative
.delta
,
282 c
->area
.width
, c
->area
.height
, TRUE
, TRUE
);
285 void action_resize_relative_horz(union ActionData
*data
)
287 Client
*c
= data
->relative
.c
;
289 client_configure(c
, Corner_TopLeft
, c
->area
.x
, c
->area
.y
,
290 c
->area
.width
+ data
->relative
.delta
,
291 c
->area
.height
, TRUE
, TRUE
);
294 void action_resize_relative_vert(union ActionData
*data
)
296 Client
*c
= data
->relative
.c
;
298 client_configure(c
, Corner_TopLeft
, c
->area
.x
, c
->area
.y
,
299 c
->area
.width
, c
->area
.height
+ data
->relative
.delta
,
303 void action_maximize_full(union ActionData
*data
)
306 client_maximize(data
->client
.c
, TRUE
, 0, TRUE
);
309 void action_unmaximize_full(union ActionData
*data
)
312 client_maximize(data
->client
.c
, FALSE
, 0, TRUE
);
315 void action_toggle_maximize_full(union ActionData
*data
)
318 client_maximize(data
->client
.c
,
319 !(data
->client
.c
->max_horz
||
320 data
->client
.c
->max_vert
),
324 void action_maximize_horz(union ActionData
*data
)
327 client_maximize(data
->client
.c
, TRUE
, 1, TRUE
);
330 void action_unmaximize_horz(union ActionData
*data
)
333 client_maximize(data
->client
.c
, FALSE
, 1, TRUE
);
336 void action_toggle_maximize_horz(union ActionData
*data
)
339 client_maximize(data
->client
.c
, !data
->client
.c
->max_horz
, 1, TRUE
);
342 void action_maximize_vert(union ActionData
*data
)
345 client_maximize(data
->client
.c
, TRUE
, 2, TRUE
);
348 void action_unmaximize_vert(union ActionData
*data
)
351 client_maximize(data
->client
.c
, FALSE
, 2, TRUE
);
354 void action_toggle_maximize_vert(union ActionData
*data
)
357 client_maximize(data
->client
.c
, !data
->client
.c
->max_vert
, 2, TRUE
);
360 void action_send_to_desktop(union ActionData
*data
)
363 if (data
->sendto
.desktop
< screen_num_desktops
||
364 data
->sendto
.desktop
== DESKTOP_ALL
)
365 client_set_desktop(data
->sendto
.c
, data
->sendto
.desktop
, TRUE
);
368 void action_send_to_next_desktop(union ActionData
*data
)
372 if (!data
->sendto
.c
) return;
374 d
= screen_desktop
+ 1;
375 if (d
>= screen_num_desktops
) {
376 if (!data
->sendtonextprev
.wrap
) return;
379 client_set_desktop(data
->sendtonextprev
.c
, d
, data
->sendtonextprev
.follow
);
380 if (data
->sendtonextprev
.follow
) screen_set_desktop(d
);
383 void action_send_to_previous_desktop(union ActionData
*data
)
387 if (!data
->sendto
.c
) return;
389 d
= screen_desktop
- 1;
390 if (d
>= screen_num_desktops
) {
391 if (!data
->sendtonextprev
.wrap
) return;
392 d
= screen_num_desktops
- 1;
394 client_set_desktop(data
->sendtonextprev
.c
, d
, data
->sendtonextprev
.follow
);
395 if (data
->sendtonextprev
.follow
) screen_set_desktop(d
);
398 void action_desktop(union ActionData
*data
)
400 if (data
->desktop
.desk
< screen_num_desktops
||
401 data
->desktop
.desk
== DESKTOP_ALL
)
402 screen_set_desktop(data
->desktop
.desk
);
405 void action_next_desktop(union ActionData
*data
)
409 d
= screen_desktop
+ 1;
410 if (d
>= screen_num_desktops
) {
411 if (!data
->nextprevdesktop
.wrap
) return;
414 screen_set_desktop(d
);
417 void action_previous_desktop(union ActionData
*data
)
421 d
= screen_desktop
- 1;
422 if (d
>= screen_num_desktops
) {
423 if (!data
->nextprevdesktop
.wrap
) return;
424 d
= screen_num_desktops
- 1;
426 screen_set_desktop(d
);
429 static void cur_row_col(guint
*r
, guint
*c
)
431 switch (screen_desktop_layout
.orientation
) {
432 case Orientation_Horz
:
433 switch (screen_desktop_layout
.start_corner
) {
435 *r
= screen_desktop
/ screen_desktop_layout
.columns
;
436 *c
= screen_desktop
% screen_desktop_layout
.columns
;
438 case Corner_BottomLeft
:
439 *r
= screen_desktop_layout
.rows
- 1 -
440 screen_desktop
/ screen_desktop_layout
.columns
;
441 *c
= screen_desktop
% screen_desktop_layout
.columns
;
444 case Corner_TopRight
:
445 *r
= screen_desktop
/ screen_desktop_layout
.columns
;
446 *c
= screen_desktop_layout
.columns
- 1 -
447 screen_desktop
% screen_desktop_layout
.columns
;
449 case Corner_BottomRight
:
450 *r
= screen_desktop_layout
.rows
- 1 -
451 screen_desktop
/ screen_desktop_layout
.columns
;
452 *c
= screen_desktop_layout
.columns
- 1 -
453 screen_desktop
% screen_desktop_layout
.columns
;
457 case Orientation_Vert
:
458 switch (screen_desktop_layout
.start_corner
) {
460 *r
= screen_desktop
% screen_desktop_layout
.rows
;
461 *c
= screen_desktop
/ screen_desktop_layout
.rows
;
463 case Corner_BottomLeft
:
464 *r
= screen_desktop_layout
.rows
- 1 -
465 screen_desktop
% screen_desktop_layout
.rows
;
466 *c
= screen_desktop
/ screen_desktop_layout
.rows
;
469 case Corner_TopRight
:
470 *r
= screen_desktop
% screen_desktop_layout
.rows
;
471 *c
= screen_desktop_layout
.columns
- 1 -
472 screen_desktop
/ screen_desktop_layout
.rows
;
474 case Corner_BottomRight
:
475 *r
= screen_desktop_layout
.rows
- 1 -
476 screen_desktop
% screen_desktop_layout
.rows
;
477 *c
= screen_desktop_layout
.columns
- 1 -
478 screen_desktop
/ screen_desktop_layout
.rows
;
486 static guint
translate_row_col(guint r
, guint c
)
488 switch (screen_desktop_layout
.orientation
) {
489 case Orientation_Horz
:
490 switch (screen_desktop_layout
.start_corner
) {
492 return r
* screen_desktop_layout
.columns
+ c
;
493 case Corner_BottomLeft
:
494 return (screen_desktop_layout
.rows
- 1 - r
) *
495 screen_desktop_layout
.columns
+ c
;
496 case Corner_TopRight
:
497 return r
* screen_desktop_layout
.columns
+
498 (screen_desktop_layout
.columns
- 1 - c
);
499 case Corner_BottomRight
:
500 return (screen_desktop_layout
.rows
- 1 - r
) *
501 screen_desktop_layout
.columns
+
502 (screen_desktop_layout
.columns
- 1 - c
);
504 case Orientation_Vert
:
505 switch (screen_desktop_layout
.start_corner
) {
507 return c
* screen_desktop_layout
.rows
+ r
;
508 case Corner_BottomLeft
:
509 return c
* screen_desktop_layout
.rows
+
510 (screen_desktop_layout
.rows
- 1 - r
);
511 case Corner_TopRight
:
512 return (screen_desktop_layout
.columns
- 1 - c
) *
513 screen_desktop_layout
.rows
+ r
;
514 case Corner_BottomRight
:
515 return (screen_desktop_layout
.columns
- 1 - c
) *
516 screen_desktop_layout
.rows
+
517 (screen_desktop_layout
.rows
- 1 - r
);
520 g_assert_not_reached();
524 void action_next_desktop_column(union ActionData
*data
)
530 d
= translate_row_col(r
, c
);
531 if (d
>= screen_num_desktops
) {
532 if (!data
->nextprevdesktop
.wrap
) return;
535 if (d
>= screen_num_desktops
)
537 d
= translate_row_col(r
, c
);
538 if (d
< screen_num_desktops
)
539 screen_set_desktop(d
);
542 void action_previous_desktop_column(union ActionData
*data
)
548 d
= translate_row_col(r
, c
);
549 if (d
>= screen_num_desktops
) {
550 if (!data
->nextprevdesktop
.wrap
) return;
551 c
= screen_desktop_layout
.columns
- 1;
553 if (d
>= screen_num_desktops
)
555 d
= translate_row_col(r
, c
);
556 if (d
< screen_num_desktops
)
557 screen_set_desktop(d
);
560 void action_next_desktop_row(union ActionData
*data
)
566 d
= translate_row_col(r
, c
);
567 if (d
>= screen_num_desktops
) {
568 if (!data
->nextprevdesktop
.wrap
) return;
571 if (d
>= screen_num_desktops
)
573 d
= translate_row_col(r
, c
);
574 if (d
< screen_num_desktops
)
575 screen_set_desktop(d
);
578 void action_previous_desktop_row(union ActionData
*data
)
584 d
= translate_row_col(r
, c
);
585 if (d
>= screen_num_desktops
) {
586 if (!data
->nextprevdesktop
.wrap
) return;
587 c
= screen_desktop_layout
.rows
- 1;
589 if (d
>= screen_num_desktops
)
591 d
= translate_row_col(r
, c
);
592 if (d
< screen_num_desktops
)
593 screen_set_desktop(d
);
596 void action_toggle_decorations(union ActionData
*data
)
598 Client
*c
= data
->client
.c
;
599 c
->disabled_decorations
= c
->disabled_decorations
? 0 : ~0;
600 client_setup_decor_and_functions(c
);
603 void action_move(union ActionData
*data
)
605 Client
*c
= data
->move
.c
;
606 int x
= data
->move
.x
;
607 int y
= data
->move
.y
;
609 if (!c
|| !client_normal(c
)) return;
611 dispatch_move(c
, &x
, &y
);
613 frame_frame_gravity(c
->frame
, &x
, &y
); /* get where the client should be */
614 client_configure(c
, Corner_TopLeft
, x
, y
, c
->area
.width
, c
->area
.height
,
615 TRUE
, data
->move
.final
);
618 void action_resize(union ActionData
*data
)
620 Client
*c
= data
->resize
.c
;
621 int w
= data
->resize
.x
;
622 int h
= data
->resize
.y
;
624 if (!c
|| !client_normal(c
)) return;
626 dispatch_resize(c
, &w
, &h
, data
->resize
.corner
);
628 w
-= c
->frame
->size
.left
+ c
->frame
->size
.right
;
629 h
-= c
->frame
->size
.top
+ c
->frame
->size
.bottom
;
630 client_configure(c
, data
->resize
.corner
, c
->area
.x
, c
->area
.y
, w
, h
,
631 TRUE
, data
->resize
.final
);
634 void action_restart(union ActionData
*data
)
636 ob_restart_path
= data
->execute
.path
;
637 ob_shutdown
= ob_restart
= TRUE
;
640 void action_exit(union ActionData
*data
)