fix grip workspace cycling
[mikachu/openbox.git] / openbox / action.c
1 #include "client.h"
2 #include "grab.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 "framerender.h"
10 #include "screen.h"
11 #include "action.h"
12 #include "dispatch.h"
13 #include "openbox.h"
14
15 #include <glib.h>
16
17 Action *action_new(void (*func)(union ActionData *data))
18 {
19     Action *a = g_new0(Action, 1);
20     a->func = func;
21
22     return a;
23 }
24
25 void action_free(Action *a)
26 {
27     if (a == NULL) return;
28
29     /* deal with pointers */
30     if (a->func == action_execute || a->func == action_restart)
31         g_free(a->data.execute.path);
32     else if (a->func == action_showmenu)
33         g_free(a->data.showmenu.name);
34
35     g_free(a);
36 }
37
38 Action *action_from_string(char *name)
39 {
40     Action *a = NULL;
41     if (!g_ascii_strcasecmp(name, "execute")) {
42         a = action_new(action_execute);
43     } else if (!g_ascii_strcasecmp(name, "focus")) {
44         a = action_new(action_focus);
45     } else if (!g_ascii_strcasecmp(name, "unfocus")) {
46         a = action_new(action_unfocus);
47     } else if (!g_ascii_strcasecmp(name, "iconify")) {
48         a = action_new(action_iconify);
49     } else if (!g_ascii_strcasecmp(name, "raise")) {
50         a = action_new(action_raise);
51     } else if (!g_ascii_strcasecmp(name, "lower")) {
52         a = action_new(action_lower);
53     } else if (!g_ascii_strcasecmp(name, "focusraise")) {
54         a = action_new(action_focusraise);
55     } else if (!g_ascii_strcasecmp(name, "close")) {
56         a = action_new(action_close);
57     } else if (!g_ascii_strcasecmp(name, "kill")) {
58         a = action_new(action_kill);
59     } else if (!g_ascii_strcasecmp(name, "shadelower")) {
60         a = action_new(action_shadelower);
61     } else if (!g_ascii_strcasecmp(name, "unshaderaise")) {
62         a = action_new(action_unshaderaise);
63     } else if (!g_ascii_strcasecmp(name, "shade")) {
64         a = action_new(action_shade);
65     } else if (!g_ascii_strcasecmp(name, "unshade")) {
66         a = action_new(action_unshade);
67     } else if (!g_ascii_strcasecmp(name, "toggleshade")) {
68         a = action_new(action_toggle_shade);
69     } else if (!g_ascii_strcasecmp(name, "toggleomnipresent")) {
70         a = action_new(action_toggle_omnipresent);
71     } else if (!g_ascii_strcasecmp(name, "moverelativehorz")) {
72         a = action_new(action_move_relative_horz);
73     } else if (!g_ascii_strcasecmp(name, "moverelativevert")) {
74         a = action_new(action_move_relative_vert);
75     } else if (!g_ascii_strcasecmp(name, "resizerelativehorz")) {
76         a = action_new(action_resize_relative_horz);
77     } else if (!g_ascii_strcasecmp(name, "resizerelativevert")) {
78         a = action_new(action_resize_relative_vert);
79     } else if (!g_ascii_strcasecmp(name, "maximizefull")) {
80         a = action_new(action_maximize_full);
81     } else if (!g_ascii_strcasecmp(name, "unmaximizefull")) {
82         a = action_new(action_unmaximize_full);
83     } else if (!g_ascii_strcasecmp(name, "togglemaximizefull")) {
84         a = action_new(action_toggle_maximize_full);
85     } else if (!g_ascii_strcasecmp(name, "maximizehorz")) {
86         a = action_new(action_maximize_horz);
87     } else if (!g_ascii_strcasecmp(name, "unmaximizehorz")) {
88         a = action_new(action_unmaximize_horz);
89     } else if (!g_ascii_strcasecmp(name, "togglemaximizehorz")) {
90         a = action_new(action_toggle_maximize_horz);
91     } else if (!g_ascii_strcasecmp(name, "maximizevert")) {
92         a = action_new(action_maximize_vert);
93     } else if (!g_ascii_strcasecmp(name, "unmaximizevert")) {
94         a = action_new(action_unmaximize_vert);
95     } else if (!g_ascii_strcasecmp(name, "togglemaximizevert")) {
96         a = action_new(action_toggle_maximize_vert);
97     } else if (!g_ascii_strcasecmp(name, "sendtodesktop")) {
98         a = action_new(action_send_to_desktop);
99         a->data.sendto.follow = TRUE;
100     } else if (!g_ascii_strcasecmp(name, "sendtonextdesktop")) {
101         a = action_new(action_send_to_next_desktop);
102         a->data.sendtonextprev.wrap = FALSE;
103         a->data.sendtonextprev.follow = TRUE;
104     } else if (!g_ascii_strcasecmp(name, "sendtonextdesktopwrap")) {
105         a = action_new(action_send_to_next_desktop);
106         a->data.sendtonextprev.wrap = TRUE;
107         a->data.sendtonextprev.follow = TRUE;
108     } else if (!g_ascii_strcasecmp(name, "sendtopreviousdesktop")) {
109         a = action_new(action_send_to_previous_desktop);
110         a->data.sendtonextprev.wrap = FALSE;
111         a->data.sendtonextprev.follow = TRUE;
112     } else if (!g_ascii_strcasecmp(name, "sendtopreviousdesktopwrap")) {
113         a = action_new(action_send_to_previous_desktop);
114         a->data.sendtonextprev.wrap = TRUE;
115         a->data.sendtonextprev.follow = TRUE;
116     } else if (!g_ascii_strcasecmp(name, "desktop")) {
117         a = action_new(action_desktop);
118     } else if (!g_ascii_strcasecmp(name, "nextdesktop")) {
119         a = action_new(action_next_desktop);
120         a->data.nextprevdesktop.wrap = FALSE;
121     } else if (!g_ascii_strcasecmp(name, "nextdesktopwrap")) {
122         a = action_new(action_next_desktop);
123         a->data.nextprevdesktop.wrap = TRUE;
124     } else if (!g_ascii_strcasecmp(name, "previousdesktop")) {
125         a = action_new(action_previous_desktop);
126         a->data.nextprevdesktop.wrap = FALSE;
127     } else if (!g_ascii_strcasecmp(name, "previousdesktopwrap")) {
128         a = action_new(action_previous_desktop);
129         a->data.nextprevdesktop.wrap = TRUE;
130     } else if (!g_ascii_strcasecmp(name, "nextdesktopcolumn")) {
131         a = action_new(action_next_desktop_column);
132         a->data.nextprevdesktop.wrap = FALSE;
133     } else if (!g_ascii_strcasecmp(name, "nextdesktopcolumnwrap")) {
134         a = action_new(action_next_desktop_column);
135         a->data.nextprevdesktop.wrap = TRUE;
136     } else if (!g_ascii_strcasecmp(name, "previousdesktopcolumn")) {
137         a = action_new(action_previous_desktop_column);
138         a->data.nextprevdesktop.wrap = FALSE;
139     } else if (!g_ascii_strcasecmp(name, "previousdesktopcolumnwrap")) {
140         a = action_new(action_previous_desktop_column);
141         a->data.nextprevdesktop.wrap = TRUE;
142     } else if (!g_ascii_strcasecmp(name, "nextdesktoprow")) {
143         a = action_new(action_next_desktop_row);
144         a->data.nextprevdesktop.wrap = FALSE;
145     } else if (!g_ascii_strcasecmp(name, "nextdesktoprowwrap")) {
146         a = action_new(action_next_desktop_row);
147         a->data.nextprevdesktop.wrap = TRUE;
148     } else if (!g_ascii_strcasecmp(name, "previousdesktoprow")) {
149         a = action_new(action_previous_desktop_row);
150         a->data.nextprevdesktop.wrap = FALSE;
151     } else if (!g_ascii_strcasecmp(name, "previousdesktoprowwrap")) {
152         a = action_new(action_previous_desktop_row);
153         a->data.nextprevdesktop.wrap = TRUE;
154     } else if (!g_ascii_strcasecmp(name, "toggledecorations")) {
155         a = action_new(action_toggle_decorations);
156     } else if (!g_ascii_strcasecmp(name, "keyboardmove")) {
157         a = action_new(action_moveresize);
158         a->data.moveresize.corner = prop_atoms.net_wm_moveresize_move_keyboard;
159     } else if (!g_ascii_strcasecmp(name, "move")) {
160         a = action_new(action_moveresize);
161         a->data.moveresize.corner = prop_atoms.net_wm_moveresize_move;
162     } else if (!g_ascii_strcasecmp(name, "resize")) {
163         a = action_new(action_moveresize);
164         a->data.moveresize.corner = prop_atoms.net_wm_moveresize_size_topleft;
165     } else if (!g_ascii_strcasecmp(name, "keyboardresize")) {
166         a = action_new(action_moveresize);
167         a->data.moveresize.corner = prop_atoms.net_wm_moveresize_size_keyboard;
168     } else if (!g_ascii_strcasecmp(name, "restart")) {
169         a = action_new(action_restart);
170     } else if (!g_ascii_strcasecmp(name, "exit")) {
171         a = action_new(action_exit);
172     } else if (!g_ascii_strcasecmp(name, "showmenu")) {
173         a = action_new(action_showmenu);
174     } else if (!g_ascii_strcasecmp(name, "nextwindowlinear")) {
175         a = action_new(action_cycle_windows);
176         a->data.cycle.linear = TRUE;
177         a->data.cycle.forward = TRUE;
178     } else if (!g_ascii_strcasecmp(name, "previouswindowlinear")) {
179         a = action_new(action_cycle_windows);
180         a->data.cycle.linear = TRUE;
181         a->data.cycle.forward = FALSE;
182     } else if (!g_ascii_strcasecmp(name, "nextwindow")) {
183         a = action_new(action_cycle_windows);
184         a->data.cycle.linear = FALSE;
185         a->data.cycle.forward = TRUE;
186     } else if (!g_ascii_strcasecmp(name, "previouswindow")) {
187         a = action_new(action_cycle_windows);
188         a->data.cycle.linear = FALSE;
189         a->data.cycle.forward = FALSE;
190     }
191     
192     return a;
193 }
194
195 void action_execute(union ActionData *data)
196 {
197     GError *e = NULL;
198     if (data->execute.path)
199         if (!g_spawn_command_line_async(data->execute.path, &e)) {
200             g_warning("failed to execute '%s': %s",
201                       data->execute.path, e->message);
202         }
203 }
204
205 void action_focus(union ActionData *data)
206 {
207     if (data->client.c)
208         client_focus(data->client.c);
209 }
210
211 void action_unfocus (union ActionData *data)
212 {
213     if (data->client.c)
214         client_unfocus(data->client.c);
215 }
216
217 void action_iconify(union ActionData *data)
218 {
219     if (data->client.c)
220         client_iconify(data->client.c, TRUE, TRUE);
221 }
222
223 void action_focusraise(union ActionData *data)
224 {
225     if (data->client.c) {
226         client_focus(data->client.c);
227         stacking_raise(data->client.c);
228     }
229 }
230
231 void action_raise(union ActionData *data)
232 {
233     if (data->client.c)
234         stacking_raise(data->client.c);
235 }
236
237 void action_unshaderaise(union ActionData *data)
238 {
239     if (data->client.c) {
240         if (data->client.c->shaded)
241             client_shade(data->client.c, FALSE);
242         else
243             stacking_raise(data->client.c);
244     }
245 }
246
247 void action_shadelower(union ActionData *data)
248 {
249     if (data->client.c) {
250         if (data->client.c->shaded)
251             stacking_lower(data->client.c);
252         else
253             client_shade(data->client.c, TRUE);
254     }
255 }
256
257 void action_lower(union ActionData *data)
258 {
259     if (data->client.c)
260         stacking_lower(data->client.c);
261 }
262
263 void action_close(union ActionData *data)
264 {
265     if (data->client.c)
266         client_close(data->client.c);
267 }
268
269 void action_kill(union ActionData *data)
270 {
271     if (data->client.c)
272         client_kill(data->client.c);
273 }
274
275 void action_shade(union ActionData *data)
276 {
277     if (data->client.c)
278         client_shade(data->client.c, TRUE);
279 }
280
281 void action_unshade(union ActionData *data)
282 {
283     if (data->client.c)
284         client_shade(data->client.c, FALSE);
285 }
286
287 void action_toggle_shade(union ActionData *data)
288 {
289     if (data->client.c)
290         client_shade(data->client.c, !data->client.c->shaded);
291 }
292
293 void action_toggle_omnipresent(union ActionData *data)
294
295     if (data->client.c)
296         client_set_desktop(data->client.c,
297                            data->client.c->desktop == DESKTOP_ALL ?
298                            screen_desktop : DESKTOP_ALL, FALSE);
299 }
300
301 void action_move_relative_horz(union ActionData *data)
302 {
303     Client *c = data->relative.c;
304     if (c)
305         client_configure(c, Corner_TopLeft,
306                          c->area.x + data->relative.delta, c->area.y,
307                          c->area.width, c->area.height, TRUE, TRUE);
308 }
309
310 void action_move_relative_vert(union ActionData *data)
311 {
312     Client *c = data->relative.c;
313     if (c)
314         client_configure(c, Corner_TopLeft,
315                          c->area.x, c->area.y + data->relative.delta,
316                          c->area.width, c->area.height, TRUE, TRUE);
317 }
318
319 void action_resize_relative_horz(union ActionData *data)
320 {
321     Client *c = data->relative.c;
322     if (c)
323         client_configure(c, Corner_TopLeft, c->area.x, c->area.y,
324                          c->area.width + data->relative.delta,
325                          c->area.height, TRUE, TRUE);
326 }
327
328 void action_resize_relative_vert(union ActionData *data)
329 {
330     Client *c = data->relative.c;
331     if (c && !c->shaded)
332         client_configure(c, Corner_TopLeft, c->area.x, c->area.y,
333                          c->area.width, c->area.height + data->relative.delta,
334                          TRUE, TRUE);
335 }
336
337 void action_maximize_full(union ActionData *data)
338 {
339     if (data->client.c)
340         client_maximize(data->client.c, TRUE, 0, TRUE);
341 }
342
343 void action_unmaximize_full(union ActionData *data)
344 {
345     if (data->client.c)
346         client_maximize(data->client.c, FALSE, 0, TRUE);
347 }
348
349 void action_toggle_maximize_full(union ActionData *data)
350 {
351     if (data->client.c)
352         client_maximize(data->client.c,
353                         !(data->client.c->max_horz ||
354                           data->client.c->max_vert),
355                         0, TRUE);
356 }
357
358 void action_maximize_horz(union ActionData *data)
359 {
360     if (data->client.c)
361         client_maximize(data->client.c, TRUE, 1, TRUE);
362 }
363
364 void action_unmaximize_horz(union ActionData *data)
365 {
366     if (data->client.c)
367         client_maximize(data->client.c, FALSE, 1, TRUE);
368 }
369
370 void action_toggle_maximize_horz(union ActionData *data)
371 {
372     if (data->client.c)
373         client_maximize(data->client.c, !data->client.c->max_horz, 1, TRUE);
374 }
375
376 void action_maximize_vert(union ActionData *data)
377 {
378     if (data->client.c)
379         client_maximize(data->client.c, TRUE, 2, TRUE);
380 }
381
382 void action_unmaximize_vert(union ActionData *data)
383 {
384     if (data->client.c)
385         client_maximize(data->client.c, FALSE, 2, TRUE);
386 }
387
388 void action_toggle_maximize_vert(union ActionData *data)
389 {
390     if (data->client.c)
391         client_maximize(data->client.c, !data->client.c->max_vert, 2, TRUE);
392 }
393
394 void action_send_to_desktop(union ActionData *data)
395 {
396     if (data->sendto.c) {
397         if (data->sendto.desk < screen_num_desktops ||
398             data->sendto.desk == DESKTOP_ALL) {
399             client_set_desktop(data->desktop.c,
400                                data->sendto.desk, data->sendto.follow);
401             if (data->sendto.follow) screen_set_desktop(data->sendto.desk);
402         }
403     }
404 }
405
406 void action_send_to_next_desktop(union ActionData *data)
407 {
408     guint d;
409
410     if (!data->sendtonextprev.c) return;
411
412     d = screen_desktop + 1;
413     if (d >= screen_num_desktops) {
414         if (!data->sendtonextprev.wrap) return;
415         d = 0;
416     }
417     client_set_desktop(data->sendtonextprev.c, d, data->sendtonextprev.follow);
418     if (data->sendtonextprev.follow) screen_set_desktop(d);
419 }
420
421 void action_send_to_previous_desktop(union ActionData *data)
422 {
423     guint d;
424
425     if (!data->sendtonextprev.c) return;
426
427     d = screen_desktop - 1;
428     if (d >= screen_num_desktops) {
429         if (!data->sendtonextprev.wrap) return;
430         d = screen_num_desktops - 1;
431     }
432     client_set_desktop(data->sendtonextprev.c, d, data->sendtonextprev.follow);
433     if (data->sendtonextprev.follow) screen_set_desktop(d);
434 }
435
436 void action_desktop(union ActionData *data)
437 {
438     if (data->desktop.desk < screen_num_desktops ||
439         data->desktop.desk == DESKTOP_ALL)
440         screen_set_desktop(data->desktop.desk);
441 }
442
443 void action_next_desktop(union ActionData *data)
444 {
445     guint d;
446
447     d = screen_desktop + 1;
448     if (d >= screen_num_desktops) {
449         if (!data->nextprevdesktop.wrap) return;
450         d = 0;
451     }
452     screen_set_desktop(d);
453 }
454
455 void action_previous_desktop(union ActionData *data)
456 {
457     guint d;
458
459     d = screen_desktop - 1;
460     if (d >= screen_num_desktops) {
461         if (!data->nextprevdesktop.wrap) return;
462         d = screen_num_desktops - 1;
463     }
464     screen_set_desktop(d);
465 }
466
467 static void cur_row_col(guint *r, guint *c)
468 {
469     switch (screen_desktop_layout.orientation) {
470     case Orientation_Horz:
471         switch (screen_desktop_layout.start_corner) {
472         case Corner_TopLeft:
473             *r = screen_desktop / screen_desktop_layout.columns;
474             *c = screen_desktop % screen_desktop_layout.columns;
475             break;
476         case Corner_BottomLeft:
477             *r = screen_desktop_layout.rows - 1 -
478                 screen_desktop / screen_desktop_layout.columns;
479             *c = screen_desktop % screen_desktop_layout.columns;
480             break;
481         case Corner_TopRight:
482             *r = screen_desktop / screen_desktop_layout.columns;
483             *c = screen_desktop_layout.columns - 1 -
484                 screen_desktop % screen_desktop_layout.columns;
485             break;
486         case Corner_BottomRight:
487             *r = screen_desktop_layout.rows - 1 -
488                 screen_desktop / screen_desktop_layout.columns;
489             *c = screen_desktop_layout.columns - 1 -
490                 screen_desktop % screen_desktop_layout.columns;
491             break;
492         }
493         break;
494     case Orientation_Vert:
495         switch (screen_desktop_layout.start_corner) {
496         case Corner_TopLeft:
497             *r = screen_desktop % screen_desktop_layout.rows;
498             *c = screen_desktop / screen_desktop_layout.rows;
499             break;
500         case Corner_BottomLeft:
501             *r = screen_desktop_layout.rows - 1 -
502                 screen_desktop % screen_desktop_layout.rows;
503             *c = screen_desktop / screen_desktop_layout.rows;
504             break;
505         case Corner_TopRight:
506             *r = screen_desktop % screen_desktop_layout.rows;
507             *c = screen_desktop_layout.columns - 1 -
508                 screen_desktop / screen_desktop_layout.rows;
509             break;
510         case Corner_BottomRight:
511             *r = screen_desktop_layout.rows - 1 -
512                 screen_desktop % screen_desktop_layout.rows;
513             *c = screen_desktop_layout.columns - 1 -
514                 screen_desktop / screen_desktop_layout.rows;
515             break;
516         }
517         break;
518     }
519 }
520
521 static guint translate_row_col(guint r, guint c)
522 {
523     switch (screen_desktop_layout.orientation) {
524     case Orientation_Horz:
525         switch (screen_desktop_layout.start_corner) {
526         case Corner_TopLeft:
527             return r % screen_desktop_layout.rows *
528                 screen_desktop_layout.columns +
529                 c % screen_desktop_layout.columns;
530         case Corner_BottomLeft:
531             return (screen_desktop_layout.rows - 1 -
532                     r % screen_desktop_layout.rows) *
533                 screen_desktop_layout.columns +
534                 c % screen_desktop_layout.columns;
535         case Corner_TopRight:
536             return r % screen_desktop_layout.rows *
537                 screen_desktop_layout.columns +
538                 (screen_desktop_layout.columns - 1 -
539                  c % screen_desktop_layout.columns);
540         case Corner_BottomRight:
541             return (screen_desktop_layout.rows - 1 -
542                     r % screen_desktop_layout.rows) *
543                 screen_desktop_layout.columns +
544                 (screen_desktop_layout.columns - 1 -
545                  c % screen_desktop_layout.columns);
546         }
547     case Orientation_Vert:
548         switch (screen_desktop_layout.start_corner) {
549         case Corner_TopLeft:
550             return c % screen_desktop_layout.columns *
551                 screen_desktop_layout.rows +
552                 r % screen_desktop_layout.rows;
553         case Corner_BottomLeft:
554             return c % screen_desktop_layout.columns *
555                 screen_desktop_layout.rows +
556                 (screen_desktop_layout.rows - 1 -
557                  r % screen_desktop_layout.rows);
558         case Corner_TopRight:
559             return (screen_desktop_layout.columns - 1 -
560                     c % screen_desktop_layout.columns) *
561                 screen_desktop_layout.rows +
562                 r % screen_desktop_layout.rows;
563         case Corner_BottomRight:
564             return (screen_desktop_layout.columns - 1 -
565                     c % screen_desktop_layout.columns) *
566                 screen_desktop_layout.rows +
567                 (screen_desktop_layout.rows - 1 -
568                  r % screen_desktop_layout.rows);
569         }
570     }
571     g_assert_not_reached();
572     return 0;
573 }
574
575 void action_next_desktop_column(union ActionData *data)
576 {
577     guint r, c, d;
578
579     cur_row_col(&r, &c);
580     ++c;
581     d = translate_row_col(r, c);
582     if (d >= screen_num_desktops) {
583         if (!data->nextprevdesktop.wrap) return;
584         c = 0;
585     }
586     if (d >= screen_num_desktops)
587         ++c;
588     d = translate_row_col(r, c);
589     if (d < screen_num_desktops)
590         screen_set_desktop(d);
591 }
592
593 void action_previous_desktop_column(union ActionData *data)
594 {
595     guint r, c, d;
596
597     cur_row_col(&r, &c);
598     --c;
599     d = translate_row_col(r, c);
600     if (d >= screen_num_desktops) {
601         if (!data->nextprevdesktop.wrap) return;
602         c = screen_desktop_layout.columns - 1;
603     }
604     if (d >= screen_num_desktops)
605         --c;
606     d = translate_row_col(r, c);
607     if (d < screen_num_desktops)
608         screen_set_desktop(d);
609 }
610
611 void action_next_desktop_row(union ActionData *data)
612 {
613     guint r, c, d;
614
615     cur_row_col(&r, &c);
616     ++r;
617     d = translate_row_col(r, c);
618     if (d >= screen_num_desktops) {
619         if (!data->nextprevdesktop.wrap) return;
620         r = 0;
621     }
622     if (d >= screen_num_desktops)
623         ++r;
624     d = translate_row_col(r, c);
625     if (d < screen_num_desktops)
626         screen_set_desktop(d);
627 }
628
629 void action_previous_desktop_row(union ActionData *data)
630 {
631     guint r, c, d;
632
633     cur_row_col(&r, &c);
634     --r;
635     d = translate_row_col(r, c);
636     if (d >= screen_num_desktops) {
637         if (!data->nextprevdesktop.wrap) return;
638         c = screen_desktop_layout.rows - 1;
639     }
640     if (d >= screen_num_desktops)
641         --r;
642     d = translate_row_col(r, c);
643     if (d < screen_num_desktops)
644         screen_set_desktop(d);
645 }
646
647 void action_toggle_decorations(union ActionData *data)
648 {
649     Client *c = data->client.c;;
650
651     if (!c) return;
652
653     c->disabled_decorations = c->disabled_decorations ? 0 : ~0;
654     client_setup_decor_and_functions(c);
655 }
656
657 void action_moveresize(union ActionData *data)
658 {
659     Client *c = data->moveresize.c;
660
661     if (!c || !client_normal(c)) return;
662
663     moveresize_start(c, data->moveresize.x, data->moveresize.y,
664                      data->moveresize.button, data->moveresize.corner);
665 }
666
667 void action_restart(union ActionData *data)
668 {
669     ob_restart_path = data->execute.path;
670     ob_shutdown = ob_restart = TRUE;
671 }
672
673 void action_exit(union ActionData *data)
674 {
675     ob_shutdown = TRUE;
676 }
677
678 void action_showmenu(union ActionData *data)
679 {
680     if (data->showmenu.name) {
681         menu_show(data->showmenu.name, data->showmenu.x, data->showmenu.y,
682                   data->showmenu.c);
683     }
684 }
685
686 static void popup_cycle(Client *c, gboolean hide)
687 {
688     XSetWindowAttributes attrib;
689     static Window coords = None;
690
691     if (coords == None) {
692         attrib.override_redirect = TRUE;
693         coords = XCreateWindow(ob_display, ob_root,
694                                0, 0, 1, 1, 0, render_depth, InputOutput,
695                                render_visual, CWOverrideRedirect, &attrib);
696         g_assert(coords != None);
697
698         grab_pointer(TRUE, None);
699
700         XMapWindow(ob_display, coords);
701     }
702
703     if (hide) {
704         XDestroyWindow(ob_display, coords);
705         coords = None;
706
707         grab_pointer(FALSE, None);
708     } else {
709         Rect *a;
710         Size s;
711
712         a = screen_area(c->desktop);
713
714         framerender_size_popup_label(c->title, &s);
715         XMoveResizeWindow(ob_display, coords,
716                           a->x + (a->width - s.width) / 2,
717                           a->y + (a->height - s.height) / 2,
718                           s.width, s.height);
719         framerender_popup_label(coords, &s, c->title);
720     }
721 }
722
723 void action_cycle_windows(union ActionData *data)
724 {
725     Client *c;
726     
727     c = focus_cycle(data->cycle.forward, data->cycle.linear, data->cycle.final,
728                     data->cycle.cancel);
729     popup_cycle(c, !c || data->cycle.final || data->cycle.cancel);
730 }
731