]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/action.c
add support for interactive/keyboard move/resize
[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.columns + c;
528         case Corner_BottomLeft:
529             return (screen_desktop_layout.rows - 1 - r) *
530                 screen_desktop_layout.columns + c;
531         case Corner_TopRight:
532             return r * screen_desktop_layout.columns +
533                 (screen_desktop_layout.columns - 1 - c);
534         case Corner_BottomRight:
535             return (screen_desktop_layout.rows - 1 - r) *
536                 screen_desktop_layout.columns +
537                 (screen_desktop_layout.columns - 1 - c);
538         }
539     case Orientation_Vert:
540         switch (screen_desktop_layout.start_corner) {
541         case Corner_TopLeft:
542             return c * screen_desktop_layout.rows + r;
543         case Corner_BottomLeft:
544             return c * screen_desktop_layout.rows +
545                 (screen_desktop_layout.rows - 1 - r);
546         case Corner_TopRight:
547             return (screen_desktop_layout.columns - 1 - c) *
548                 screen_desktop_layout.rows + r;
549         case Corner_BottomRight:
550             return (screen_desktop_layout.columns - 1 - c) *
551                 screen_desktop_layout.rows +
552                 (screen_desktop_layout.rows - 1 - r);
553         }
554     }
555     g_assert_not_reached();
556     return 0;
557 }
558
559 void action_next_desktop_column(union ActionData *data)
560 {
561     guint r, c, d;
562
563     cur_row_col(&r, &c);
564     ++c;
565     d = translate_row_col(r, c);
566     if (d >= screen_num_desktops) {
567         if (!data->nextprevdesktop.wrap) return;
568         c = 0;
569     }
570     if (d >= screen_num_desktops)
571         ++c;
572     d = translate_row_col(r, c);
573     if (d < screen_num_desktops)
574         screen_set_desktop(d);
575 }
576
577 void action_previous_desktop_column(union ActionData *data)
578 {
579     guint r, c, d;
580
581     cur_row_col(&r, &c);
582     --c;
583     d = translate_row_col(r, c);
584     if (d >= screen_num_desktops) {
585         if (!data->nextprevdesktop.wrap) return;
586         c = screen_desktop_layout.columns - 1;
587     }
588     if (d >= screen_num_desktops)
589         --c;
590     d = translate_row_col(r, c);
591     if (d < screen_num_desktops)
592         screen_set_desktop(d);
593 }
594
595 void action_next_desktop_row(union ActionData *data)
596 {
597     guint r, c, d;
598
599     cur_row_col(&r, &c);
600     ++r;
601     d = translate_row_col(r, c);
602     if (d >= screen_num_desktops) {
603         if (!data->nextprevdesktop.wrap) return;
604         r = 0;
605     }
606     if (d >= screen_num_desktops)
607         ++r;
608     d = translate_row_col(r, c);
609     if (d < screen_num_desktops)
610         screen_set_desktop(d);
611 }
612
613 void action_previous_desktop_row(union ActionData *data)
614 {
615     guint r, c, d;
616
617     cur_row_col(&r, &c);
618     --r;
619     d = translate_row_col(r, c);
620     if (d >= screen_num_desktops) {
621         if (!data->nextprevdesktop.wrap) return;
622         c = screen_desktop_layout.rows - 1;
623     }
624     if (d >= screen_num_desktops)
625         --r;
626     d = translate_row_col(r, c);
627     if (d < screen_num_desktops)
628         screen_set_desktop(d);
629 }
630
631 void action_toggle_decorations(union ActionData *data)
632 {
633     Client *c = data->client.c;;
634
635     if (!c) return;
636
637     c->disabled_decorations = c->disabled_decorations ? 0 : ~0;
638     client_setup_decor_and_functions(c);
639 }
640
641 void action_moveresize(union ActionData *data)
642 {
643     Client *c = data->moveresize.c;
644
645     if (!c || !client_normal(c)) return;
646
647     moveresize_start(c, data->moveresize.x, data->moveresize.y,
648                      data->moveresize.button, data->moveresize.corner);
649 }
650
651 void action_restart(union ActionData *data)
652 {
653     ob_restart_path = data->execute.path;
654     ob_shutdown = ob_restart = TRUE;
655 }
656
657 void action_exit(union ActionData *data)
658 {
659     ob_shutdown = TRUE;
660 }
661
662 void action_showmenu(union ActionData *data)
663 {
664     if (data->showmenu.name) {
665         menu_show(data->showmenu.name, data->showmenu.x, data->showmenu.y,
666                   data->showmenu.c);
667     }
668 }
669
670 static void popup_cycle(Client *c, gboolean hide)
671 {
672     XSetWindowAttributes attrib;
673     static Window coords = None;
674
675     if (coords == None) {
676         attrib.override_redirect = TRUE;
677         coords = XCreateWindow(ob_display, ob_root,
678                                0, 0, 1, 1, 0, render_depth, InputOutput,
679                                render_visual, CWOverrideRedirect, &attrib);
680         g_assert(coords != None);
681
682         grab_pointer(TRUE, None);
683
684         XMapWindow(ob_display, coords);
685     }
686
687     if (hide) {
688         XDestroyWindow(ob_display, coords);
689         coords = None;
690
691         grab_pointer(FALSE, None);
692     } else {
693         Rect *a;
694         Size s;
695
696         a = screen_area(c->desktop);
697
698         framerender_size_popup_label(c->title, &s);
699         XMoveResizeWindow(ob_display, coords,
700                           a->x + (a->width - s.width) / 2,
701                           a->y + (a->height - s.height) / 2,
702                           s.width, s.height);
703         framerender_popup_label(coords, &s, c->title);
704     }
705 }
706
707 void action_cycle_windows(union ActionData *data)
708 {
709     Client *c;
710     
711     c = focus_cycle(data->cycle.forward, data->cycle.linear, data->cycle.final,
712                     data->cycle.cancel);
713     popup_cycle(c, !c || data->cycle.final || data->cycle.cancel);
714 }
715