remove trailing whitespace
[dana/openbox.git] / openbox / frame.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    frame.c for the Openbox window manager
4    Copyright (c) 2006        Mikael Magnusson
5    Copyright (c) 2003-2007   Dana Jansens
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "frame.h"
21 #include "client.h"
22 #include "openbox.h"
23 #include "extensions.h"
24 #include "prop.h"
25 #include "config.h"
26 #include "framerender.h"
27 #include "mainloop.h"
28 #include "focus_cycle.h"
29 #include "focus_cycle_indicator.h"
30 #include "moveresize.h"
31 #include "screen.h"
32 #include "render/theme.h"
33
34 #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
35                          ButtonPressMask | ButtonReleaseMask | \
36                          SubstructureRedirectMask | FocusChangeMask)
37 #define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \
38                            ButtonMotionMask | PointerMotionMask | \
39                            EnterWindowMask | LeaveWindowMask)
40
41 #define FRAME_ANIMATE_ICONIFY_TIME 150000 /* .15 seconds */
42 #define FRAME_ANIMATE_ICONIFY_STEP_TIME (G_USEC_PER_SEC / 60) /* 60 Hz */
43
44 #define FRAME_HANDLE_Y(f) (f->size.top + f->client->area.height + f->cbwidth_b)
45
46 static void flash_done(gpointer data);
47 static gboolean flash_timeout(gpointer data);
48
49 static void layout_title(ObFrame *self);
50 static void set_theme_statics(ObFrame *self);
51 static void free_theme_statics(ObFrame *self);
52 static gboolean frame_animate_iconify(gpointer self);
53 static void frame_adjust_cursors(ObFrame *self);
54
55 static Window createWindow(Window parent, Visual *visual,
56                            gulong mask, XSetWindowAttributes *attrib)
57 {
58     return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
59                          (visual ? 32 : RrDepth(ob_rr_inst)), InputOutput,
60                          (visual ? visual : RrVisual(ob_rr_inst)),
61                          mask, attrib);
62
63 }
64
65 static Visual *check_32bit_client(ObClient *c)
66 {
67     XWindowAttributes wattrib;
68     Status ret;
69
70     /* we're already running at 32 bit depth, yay. we don't need to use their
71        visual */
72     if (RrDepth(ob_rr_inst) == 32)
73         return NULL;
74
75     ret = XGetWindowAttributes(ob_display, c->window, &wattrib);
76     g_assert(ret != BadDrawable);
77     g_assert(ret != BadWindow);
78
79     if (wattrib.depth == 32)
80         return wattrib.visual;
81     return NULL;
82 }
83
84 ObFrame *frame_new(ObClient *client)
85 {
86     XSetWindowAttributes attrib;
87     gulong mask;
88     ObFrame *self;
89     Visual *visual;
90
91     self = g_new0(ObFrame, 1);
92     self->client = client;
93
94     visual = check_32bit_client(client);
95
96     /* create the non-visible decor windows */
97
98     mask = 0;
99     if (visual) {
100         /* client has a 32-bit visual */
101         mask |= CWColormap | CWBackPixel | CWBorderPixel;
102         /* create a colormap with the visual */
103         self->colormap = attrib.colormap =
104             XCreateColormap(ob_display,
105                             RootWindow(ob_display, ob_screen),
106                             visual, AllocNone);
107         attrib.background_pixel = BlackPixel(ob_display, ob_screen);
108         attrib.border_pixel = BlackPixel(ob_display, ob_screen);
109     }
110     self->window = createWindow(RootWindow(ob_display, ob_screen), visual,
111                                 mask, &attrib);
112
113     /* create the visible decor windows */
114
115     mask = 0;
116     if (visual) {
117         /* client has a 32-bit visual */
118         mask |= CWColormap | CWBackPixel | CWBorderPixel;
119         attrib.colormap = RrColormap(ob_rr_inst);
120     }
121
122     self->backback = createWindow(self->window, NULL, mask, &attrib);
123     self->backfront = createWindow(self->backback, NULL, mask, &attrib);
124
125     mask |= CWEventMask;
126     attrib.event_mask = ELEMENT_EVENTMASK;
127     self->innerleft = createWindow(self->window, NULL, mask, &attrib);
128     self->innertop = createWindow(self->window, NULL, mask, &attrib);
129     self->innerright = createWindow(self->window, NULL, mask, &attrib);
130     self->innerbottom = createWindow(self->window, NULL, mask, &attrib);
131
132     self->title = createWindow(self->window, NULL, mask, &attrib);
133     self->titleleft = createWindow(self->window, NULL, mask, &attrib);
134     self->titletop = createWindow(self->window, NULL, mask, &attrib);
135     self->titletopleft = createWindow(self->window, NULL, mask, &attrib);
136     self->titletopright = createWindow(self->window, NULL, mask, &attrib);
137     self->titleright = createWindow(self->window, NULL, mask, &attrib);
138     self->titlebottom = createWindow(self->window, NULL, mask, &attrib);
139
140     self->topresize = createWindow(self->title, NULL, mask, &attrib);
141     self->tltresize = createWindow(self->title, NULL, mask, &attrib);
142     self->tllresize = createWindow(self->title, NULL, mask, &attrib);
143     self->trtresize = createWindow(self->title, NULL, mask, &attrib);
144     self->trrresize = createWindow(self->title, NULL, mask, &attrib);
145
146     self->left = createWindow(self->window, NULL, mask, &attrib);
147     self->right = createWindow(self->window, NULL, mask, &attrib);
148
149     self->label = createWindow(self->title, NULL, mask, &attrib);
150     self->max = createWindow(self->title, NULL, mask, &attrib);
151     self->close = createWindow(self->title, NULL, mask, &attrib);
152     self->desk = createWindow(self->title, NULL, mask, &attrib);
153     self->shade = createWindow(self->title, NULL, mask, &attrib);
154     self->icon = createWindow(self->title, NULL, mask, &attrib);
155     self->iconify = createWindow(self->title, NULL, mask, &attrib);
156
157     self->handle = createWindow(self->window, NULL, mask, &attrib);
158     self->lgrip = createWindow(self->handle, NULL, mask, &attrib);
159     self->rgrip = createWindow(self->handle, NULL, mask, &attrib);
160
161     self->handleleft = createWindow(self->handle, NULL, mask, &attrib);
162     self->handleright = createWindow(self->handle, NULL, mask, &attrib);
163
164     self->handletop = createWindow(self->window, NULL, mask, &attrib);
165     self->handlebottom = createWindow(self->window, NULL, mask, &attrib);
166     self->lgripleft = createWindow(self->window, NULL, mask, &attrib);
167     self->lgriptop = createWindow(self->window, NULL, mask, &attrib);
168     self->lgripbottom = createWindow(self->window, NULL, mask, &attrib);
169     self->rgripright = createWindow(self->window, NULL, mask, &attrib);
170     self->rgriptop = createWindow(self->window, NULL, mask, &attrib);
171     self->rgripbottom = createWindow(self->window, NULL, mask, &attrib);
172
173     self->focused = FALSE;
174
175     /* the other stuff is shown based on decor settings */
176     XMapWindow(ob_display, self->label);
177     XMapWindow(ob_display, self->backback);
178     XMapWindow(ob_display, self->backfront);
179
180     self->max_press = self->close_press = self->desk_press =
181         self->iconify_press = self->shade_press = FALSE;
182     self->max_hover = self->close_hover = self->desk_hover =
183         self->iconify_hover = self->shade_hover = FALSE;
184
185     set_theme_statics(self);
186
187     return (ObFrame*)self;
188 }
189
190 static void set_theme_statics(ObFrame *self)
191 {
192     /* set colors/appearance/sizes for stuff that doesn't change */
193     XResizeWindow(ob_display, self->max,
194                   ob_rr_theme->button_size, ob_rr_theme->button_size);
195     XResizeWindow(ob_display, self->iconify,
196                   ob_rr_theme->button_size, ob_rr_theme->button_size);
197     XResizeWindow(ob_display, self->icon,
198                   ob_rr_theme->button_size + 2, ob_rr_theme->button_size + 2);
199     XResizeWindow(ob_display, self->close,
200                   ob_rr_theme->button_size, ob_rr_theme->button_size);
201     XResizeWindow(ob_display, self->desk,
202                   ob_rr_theme->button_size, ob_rr_theme->button_size);
203     XResizeWindow(ob_display, self->shade,
204                   ob_rr_theme->button_size, ob_rr_theme->button_size);
205     XResizeWindow(ob_display, self->tltresize,
206                   ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
207     XResizeWindow(ob_display, self->trtresize,
208                   ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
209     XResizeWindow(ob_display, self->tllresize,
210                   ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
211     XResizeWindow(ob_display, self->trrresize,
212                   ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
213
214     /* set up the dynamic appearances */
215     self->a_unfocused_title = RrAppearanceCopy(ob_rr_theme->a_unfocused_title);
216     self->a_focused_title = RrAppearanceCopy(ob_rr_theme->a_focused_title);
217     self->a_unfocused_label = RrAppearanceCopy(ob_rr_theme->a_unfocused_label);
218     self->a_focused_label = RrAppearanceCopy(ob_rr_theme->a_focused_label);
219     self->a_unfocused_handle =
220         RrAppearanceCopy(ob_rr_theme->a_unfocused_handle);
221     self->a_focused_handle = RrAppearanceCopy(ob_rr_theme->a_focused_handle);
222     self->a_icon = RrAppearanceCopy(ob_rr_theme->a_icon);
223 }
224
225 static void free_theme_statics(ObFrame *self)
226 {
227     RrAppearanceFree(self->a_unfocused_title);
228     RrAppearanceFree(self->a_focused_title);
229     RrAppearanceFree(self->a_unfocused_label);
230     RrAppearanceFree(self->a_focused_label);
231     RrAppearanceFree(self->a_unfocused_handle);
232     RrAppearanceFree(self->a_focused_handle);
233     RrAppearanceFree(self->a_icon);
234 }
235
236 void frame_free(ObFrame *self)
237 {
238     free_theme_statics(self);
239
240     XDestroyWindow(ob_display, self->window);
241     if (self->colormap)
242         XFreeColormap(ob_display, self->colormap);
243
244     g_free(self);
245 }
246
247 void frame_show(ObFrame *self)
248 {
249     if (!self->visible) {
250         self->visible = TRUE;
251         framerender_frame(self);
252         XMapWindow(ob_display, self->client->window);
253         XMapWindow(ob_display, self->window);
254     }
255 }
256
257 void frame_hide(ObFrame *self)
258 {
259     if (self->visible) {
260         self->visible = FALSE;
261         if (!frame_iconify_animating(self))
262             XUnmapWindow(ob_display, self->window);
263         /* we unmap the client itself so that we can get MapRequest
264            events, and because the ICCCM tells us to! */
265         XUnmapWindow(ob_display, self->client->window);
266         self->client->ignore_unmaps += 1;
267     }
268 }
269
270 void frame_adjust_theme(ObFrame *self)
271 {
272     free_theme_statics(self);
273     set_theme_statics(self);
274 }
275
276 void frame_adjust_shape(ObFrame *self)
277 {
278 #ifdef SHAPE
279     gint num;
280     XRectangle xrect[2];
281
282     if (!self->client->shaped) {
283         /* clear the shape on the frame window */
284         XShapeCombineMask(ob_display, self->window, ShapeBounding,
285                           self->size.left,
286                           self->size.top,
287                           None, ShapeSet);
288     } else {
289         /* make the frame's shape match the clients */
290         XShapeCombineShape(ob_display, self->window, ShapeBounding,
291                            self->size.left,
292                            self->size.top,
293                            self->client->window,
294                            ShapeBounding, ShapeSet);
295
296         num = 0;
297         if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
298             xrect[0].x = 0;
299             xrect[0].y = 0;
300             xrect[0].width = self->area.width;
301             xrect[0].height = self->size.top;
302             ++num;
303         }
304
305         if (self->decorations & OB_FRAME_DECOR_HANDLE &&
306             ob_rr_theme->handle_height > 0)
307         {
308             xrect[1].x = 0;
309             xrect[1].y = FRAME_HANDLE_Y(self);
310             xrect[1].width = self->area.width;
311             xrect[1].height = ob_rr_theme->handle_height +
312                 self->bwidth * 2;
313             ++num;
314         }
315
316         XShapeCombineRectangles(ob_display, self->window,
317                                 ShapeBounding, 0, 0, xrect, num,
318                                 ShapeUnion, Unsorted);
319     }
320 #endif
321 }
322
323 void frame_adjust_area(ObFrame *self, gboolean moved,
324                        gboolean resized, gboolean fake)
325 {
326     Strut oldsize;
327
328     oldsize = self->size;
329
330     if (resized) {
331         /* do this before changing the frame's status like max_horz max_vert */
332         frame_adjust_cursors(self);
333
334         self->functions = self->client->functions;
335         self->decorations = self->client->decorations;
336         self->max_horz = self->client->max_horz;
337         self->max_vert = self->client->max_vert;
338         self->shaded = self->client->shaded;
339
340         if (self->decorations & OB_FRAME_DECOR_BORDER ||
341             (self->client->undecorated && config_theme_keepborder))
342             self->bwidth = ob_rr_theme->fbwidth;
343         else
344             self->bwidth = 0;
345
346         if (self->decorations & OB_FRAME_DECOR_BORDER) {
347             self->cbwidth_l = self->cbwidth_r = ob_rr_theme->cbwidthx;
348             self->cbwidth_t = self->cbwidth_b = ob_rr_theme->cbwidthy;
349         } else
350             self->cbwidth_l = self->cbwidth_t =
351                 self->cbwidth_r = self->cbwidth_b = 0;
352
353         if (self->max_horz) {
354             self->cbwidth_l = self->cbwidth_r = 0;
355             self->width = self->client->area.width;
356             if (self->max_vert)
357                 self->cbwidth_b = 0;
358         } else
359             self->width = self->client->area.width +
360                 self->cbwidth_l + self->cbwidth_r;
361
362         /* some elements are sized based of the width, so don't let them have
363            negative values */
364         self->width = MAX(self->width,
365                           (ob_rr_theme->grip_width + self->bwidth) * 2 + 1);
366
367         STRUT_SET(self->size,
368                   self->cbwidth_l + (!self->max_horz ? self->bwidth : 0),
369                   self->cbwidth_t + self->bwidth,
370                   self->cbwidth_r + (!self->max_horz ? self->bwidth : 0),
371                   self->cbwidth_b +
372                     (!self->max_horz || !self->max_vert ? self->bwidth : 0));
373
374         if (self->decorations & OB_FRAME_DECOR_TITLEBAR)
375             self->size.top += ob_rr_theme->title_height + self->bwidth;
376         if (self->decorations & OB_FRAME_DECOR_HANDLE &&
377             ob_rr_theme->handle_height > 0)
378         {
379             self->size.bottom += ob_rr_theme->handle_height + self->bwidth;
380         }
381
382         /* position/size and map/unmap all the windows */
383
384         if (!fake) {
385             if (self->cbwidth_l) {
386                 XMoveResizeWindow(ob_display, self->innerleft,
387                                   self->size.left - self->cbwidth_l,
388                                   self->size.top,
389                                   self->cbwidth_l, self->client->area.height);
390
391                 XMapWindow(ob_display, self->innerleft);
392             } else
393                 XUnmapWindow(ob_display, self->innerleft);
394
395             if (self->cbwidth_r) {
396                 XMoveResizeWindow(ob_display, self->innerright,
397                                   self->size.left + self->client->area.width,
398                                   self->size.top,
399                                   self->cbwidth_r, self->client->area.height);
400
401                 XMapWindow(ob_display, self->innerright);
402             } else
403                 XUnmapWindow(ob_display, self->innerright);
404
405             if (self->cbwidth_t) {
406                 XMoveResizeWindow(ob_display, self->innertop,
407                                   self->size.left - self->cbwidth_l,
408                                   self->size.top - self->cbwidth_t,
409                                   self->client->area.width +
410                                   self->cbwidth_l + self->cbwidth_r,
411                                   self->cbwidth_t);
412
413                 XMapWindow(ob_display, self->innertop);
414             } else
415                 XUnmapWindow(ob_display, self->innertop);
416
417             if (self->cbwidth_b) {
418                 XMoveResizeWindow(ob_display, self->innerbottom,
419                                   self->size.left - self->cbwidth_l,
420                                   self->size.top + self->client->area.height,
421                                   self->client->area.width +
422                                   self->cbwidth_l + self->cbwidth_r,
423                                   self->cbwidth_b);
424
425                 XMapWindow(ob_display, self->innerbottom);
426             } else
427                 XUnmapWindow(ob_display, self->innerbottom);
428
429             if (self->bwidth) {
430                 gint titlesides;
431
432                 /* height of titleleft and titleright */
433                 titlesides = (!self->max_horz ? ob_rr_theme->grip_width : 0);
434
435                 XMoveResizeWindow(ob_display, self->titletop,
436                                   ob_rr_theme->grip_width + self->bwidth, 0,
437                                   /* width + bwidth*2 - bwidth*2 - grips*2 */
438                                   self->width - ob_rr_theme->grip_width * 2,
439                                   self->bwidth);
440                 XMoveResizeWindow(ob_display, self->titletopleft,
441                                   0, 0,
442                                   ob_rr_theme->grip_width + self->bwidth,
443                                   self->bwidth);
444                 XMoveResizeWindow(ob_display, self->titletopright,
445                                   self->client->area.width +
446                                   self->size.left + self->size.right -
447                                   ob_rr_theme->grip_width - self->bwidth,
448                                   0,
449                                   ob_rr_theme->grip_width + self->bwidth,
450                                   self->bwidth);
451
452                 if (titlesides > 0) {
453                     XMoveResizeWindow(ob_display, self->titleleft,
454                                       0, self->bwidth,
455                                       self->bwidth,
456                                       titlesides);
457                     XMoveResizeWindow(ob_display, self->titleright,
458                                       self->client->area.width +
459                                       self->size.left + self->size.right -
460                                       self->bwidth,
461                                       self->bwidth,
462                                       self->bwidth,
463                                       titlesides);
464
465                     XMapWindow(ob_display, self->titleleft);
466                     XMapWindow(ob_display, self->titleright);
467                 } else {
468                     XUnmapWindow(ob_display, self->titleleft);
469                     XUnmapWindow(ob_display, self->titleright);
470                 }
471
472                 XMapWindow(ob_display, self->titletop);
473                 XMapWindow(ob_display, self->titletopleft);
474                 XMapWindow(ob_display, self->titletopright);
475
476                 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
477                     XMoveResizeWindow(ob_display, self->titlebottom,
478                                       (self->max_horz ? 0 : self->bwidth),
479                                       ob_rr_theme->title_height + self->bwidth,
480                                       self->width,
481                                       self->bwidth);
482
483                     XMapWindow(ob_display, self->titlebottom);
484                 } else
485                     XUnmapWindow(ob_display, self->titlebottom);
486             } else {
487                 XUnmapWindow(ob_display, self->titlebottom);
488
489                 XUnmapWindow(ob_display, self->titletop);
490                 XUnmapWindow(ob_display, self->titletopleft);
491                 XUnmapWindow(ob_display, self->titletopright);
492                 XUnmapWindow(ob_display, self->titleleft);
493                 XUnmapWindow(ob_display, self->titleright);
494             }
495
496             if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
497                 XMoveResizeWindow(ob_display, self->title,
498                                   (self->max_horz ? 0 : self->bwidth),
499                                   self->bwidth,
500                                   self->width, ob_rr_theme->title_height);
501
502                 XMapWindow(ob_display, self->title);
503
504                 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
505                     XMoveResizeWindow(ob_display, self->topresize,
506                                       ob_rr_theme->grip_width,
507                                       0,
508                                       self->width - ob_rr_theme->grip_width *2,
509                                       ob_rr_theme->paddingy + 1);
510
511                     XMoveWindow(ob_display, self->tltresize, 0, 0);
512                     XMoveWindow(ob_display, self->tllresize, 0, 0);
513                     XMoveWindow(ob_display, self->trtresize,
514                                 self->width - ob_rr_theme->grip_width, 0);
515                     XMoveWindow(ob_display, self->trrresize,
516                                 self->width - ob_rr_theme->paddingx - 1, 0);
517
518                     XMapWindow(ob_display, self->topresize);
519                     XMapWindow(ob_display, self->tltresize);
520                     XMapWindow(ob_display, self->tllresize);
521                     XMapWindow(ob_display, self->trtresize);
522                     XMapWindow(ob_display, self->trrresize);
523                 } else {
524                     XUnmapWindow(ob_display, self->topresize);
525                     XUnmapWindow(ob_display, self->tltresize);
526                     XUnmapWindow(ob_display, self->tllresize);
527                     XUnmapWindow(ob_display, self->trtresize);
528                     XUnmapWindow(ob_display, self->trrresize);
529                 }
530             } else
531                 XUnmapWindow(ob_display, self->title);
532         }
533
534         if ((self->decorations & OB_FRAME_DECOR_TITLEBAR))
535             /* layout the title bar elements */
536             layout_title(self);
537
538         if (!fake) {
539             gint sidebwidth = self->max_horz ? 0 : self->bwidth;
540
541             if (self->bwidth && self->size.bottom) {
542                 XMoveResizeWindow(ob_display, self->handlebottom,
543                                   ob_rr_theme->grip_width +
544                                   self->bwidth + sidebwidth,
545                                   self->size.top + self->client->area.height +
546                                   self->size.bottom - self->bwidth,
547                                   self->width - (ob_rr_theme->grip_width +
548                                                  sidebwidth) * 2,
549                                   self->bwidth);
550
551
552                 if (sidebwidth) {
553                     XMoveResizeWindow(ob_display, self->lgripleft,
554                                       0,
555                                       self->size.top +
556                                       self->client->area.height +
557                                       self->size.bottom -
558                                       (!self->max_horz ?
559                                        ob_rr_theme->grip_width :
560                                        self->size.bottom - self->cbwidth_b),
561                                       self->bwidth,
562                                       (!self->max_horz ?
563                                        ob_rr_theme->grip_width :
564                                        self->size.bottom - self->cbwidth_b));
565                     XMoveResizeWindow(ob_display, self->rgripright,
566                                   self->size.left +
567                                       self->client->area.width +
568                                       self->size.right - self->bwidth,
569                                       self->size.top +
570                                       self->client->area.height +
571                                       self->size.bottom -
572                                       (!self->max_horz ?
573                                        ob_rr_theme->grip_width :
574                                        self->size.bottom - self->cbwidth_b),
575                                       self->bwidth,
576                                       (!self->max_horz ?
577                                        ob_rr_theme->grip_width :
578                                        self->size.bottom - self->cbwidth_b));
579
580                     XMapWindow(ob_display, self->lgripleft);
581                     XMapWindow(ob_display, self->rgripright);
582                 } else {
583                     XUnmapWindow(ob_display, self->lgripleft);
584                     XUnmapWindow(ob_display, self->rgripright);
585                 }
586
587                 XMoveResizeWindow(ob_display, self->lgripbottom,
588                                   sidebwidth,
589                                   self->size.top + self->client->area.height +
590                                   self->size.bottom - self->bwidth,
591                                   ob_rr_theme->grip_width + self->bwidth,
592                                   self->bwidth);
593                 XMoveResizeWindow(ob_display, self->rgripbottom,
594                                   self->size.left + self->client->area.width +
595                                   self->size.right - self->bwidth - sidebwidth -
596                                   ob_rr_theme->grip_width,
597                                   self->size.top + self->client->area.height +
598                                   self->size.bottom - self->bwidth,
599                                   ob_rr_theme->grip_width + self->bwidth,
600                                   self->bwidth);
601
602                 XMapWindow(ob_display, self->handlebottom);
603                 XMapWindow(ob_display, self->lgripbottom);
604                 XMapWindow(ob_display, self->rgripbottom);
605
606                 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
607                     ob_rr_theme->handle_height > 0)
608                 {
609                     XMoveResizeWindow(ob_display, self->handletop,
610                                       ob_rr_theme->grip_width +
611                                       self->bwidth + sidebwidth,
612                                       FRAME_HANDLE_Y(self),
613                                       self->width - (ob_rr_theme->grip_width +
614                                                      sidebwidth) * 2,
615                                       self->bwidth);
616                     XMapWindow(ob_display, self->handletop);
617
618                     if (self->decorations & OB_FRAME_DECOR_GRIPS) {
619                         XMoveResizeWindow(ob_display, self->handleleft,
620                                           ob_rr_theme->grip_width,
621                                           0,
622                                           self->bwidth,
623                                           ob_rr_theme->handle_height);
624                         XMoveResizeWindow(ob_display, self->handleright,
625                                           self->width -
626                                           ob_rr_theme->grip_width -
627                                           self->bwidth,
628                                           0,
629                                           self->bwidth,
630                                           ob_rr_theme->handle_height);
631
632                         XMoveResizeWindow(ob_display, self->lgriptop,
633                                           sidebwidth,
634                                           FRAME_HANDLE_Y(self),
635                                           ob_rr_theme->grip_width +
636                                           self->bwidth,
637                                           self->bwidth);
638                         XMoveResizeWindow(ob_display, self->rgriptop,
639                                           self->size.left +
640                                           self->client->area.width +
641                                           self->size.right - self->bwidth -
642                                           sidebwidth - ob_rr_theme->grip_width,
643                                           FRAME_HANDLE_Y(self),
644                                           ob_rr_theme->grip_width +
645                                           self->bwidth,
646                                           self->bwidth);
647
648                         XMapWindow(ob_display, self->handleleft);
649                         XMapWindow(ob_display, self->handleright);
650                         XMapWindow(ob_display, self->lgriptop);
651                         XMapWindow(ob_display, self->rgriptop);
652                     } else {
653                         XUnmapWindow(ob_display, self->handleleft);
654                         XUnmapWindow(ob_display, self->handleright);
655                         XUnmapWindow(ob_display, self->lgriptop);
656                         XUnmapWindow(ob_display, self->rgriptop);
657                     }
658                 } else {
659                     XUnmapWindow(ob_display, self->handleleft);
660                     XUnmapWindow(ob_display, self->handleright);
661                     XUnmapWindow(ob_display, self->lgriptop);
662                     XUnmapWindow(ob_display, self->rgriptop);
663
664                     XUnmapWindow(ob_display, self->handletop);
665                 }
666             } else {
667                 XUnmapWindow(ob_display, self->handleleft);
668                 XUnmapWindow(ob_display, self->handleright);
669                 XUnmapWindow(ob_display, self->lgriptop);
670                 XUnmapWindow(ob_display, self->rgriptop);
671
672                 XUnmapWindow(ob_display, self->handletop);
673
674                 XUnmapWindow(ob_display, self->handlebottom);
675                 XUnmapWindow(ob_display, self->lgripleft);
676                 XUnmapWindow(ob_display, self->rgripright);
677                 XUnmapWindow(ob_display, self->lgripbottom);
678                 XUnmapWindow(ob_display, self->rgripbottom);
679             }
680
681             if (self->decorations & OB_FRAME_DECOR_HANDLE &&
682                 ob_rr_theme->handle_height > 0)
683             {
684                 XMoveResizeWindow(ob_display, self->handle,
685                                   sidebwidth,
686                                   FRAME_HANDLE_Y(self) + self->bwidth,
687                                   self->width, ob_rr_theme->handle_height);
688                 XMapWindow(ob_display, self->handle);
689
690                 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
691                     XMoveResizeWindow(ob_display, self->lgrip,
692                                       0, 0,
693                                       ob_rr_theme->grip_width,
694                                       ob_rr_theme->handle_height);
695                     XMoveResizeWindow(ob_display, self->rgrip,
696                                       self->width - ob_rr_theme->grip_width,
697                                       0,
698                                       ob_rr_theme->grip_width,
699                                       ob_rr_theme->handle_height);
700
701                     XMapWindow(ob_display, self->lgrip);
702                     XMapWindow(ob_display, self->rgrip);
703                 } else {
704                     XUnmapWindow(ob_display, self->lgrip);
705                     XUnmapWindow(ob_display, self->rgrip);
706                 }
707             } else {
708                 XUnmapWindow(ob_display, self->lgrip);
709                 XUnmapWindow(ob_display, self->rgrip);
710
711                 XUnmapWindow(ob_display, self->handle);
712             }
713
714             if (self->bwidth && !self->max_horz) {
715                 XMoveResizeWindow(ob_display, self->left,
716                                   0,
717                                   self->bwidth + ob_rr_theme->grip_width,
718                                   self->bwidth,
719                                   self->client->area.height +
720                                   self->size.top + self->size.bottom -
721                                   ob_rr_theme->grip_width * 2);
722
723                 XMapWindow(ob_display, self->left);
724             } else
725                 XUnmapWindow(ob_display, self->left);
726
727             if (self->bwidth && !self->max_horz) {
728                 XMoveResizeWindow(ob_display, self->right,
729                                   self->client->area.width + self->cbwidth_l +
730                                   self->cbwidth_r + self->bwidth,
731                                   self->bwidth + ob_rr_theme->grip_width,
732                                   self->bwidth,
733                                   self->client->area.height +
734                                   self->size.top + self->size.bottom -
735                                   ob_rr_theme->grip_width * 2);
736
737                 XMapWindow(ob_display, self->right);
738             } else
739                 XUnmapWindow(ob_display, self->right);
740
741             XMoveResizeWindow(ob_display, self->backback,
742                               self->size.left, self->size.top,
743                               self->client->area.width,
744                               self->client->area.height);
745         }
746     }
747
748     /* shading can change without being moved or resized */
749     RECT_SET_SIZE(self->area,
750                   self->client->area.width +
751                   self->size.left + self->size.right,
752                   (self->client->shaded ?
753                    ob_rr_theme->title_height + self->bwidth * 2:
754                    self->client->area.height +
755                    self->size.top + self->size.bottom));
756
757     if ((moved || resized) && !fake) {
758         /* find the new coordinates, done after setting the frame.size, for
759            frame_client_gravity. */
760         self->area.x = self->client->area.x;
761         self->area.y = self->client->area.y;
762         frame_client_gravity(self, &self->area.x, &self->area.y);
763     }
764
765     if (!fake) {
766         if (!frame_iconify_animating(self))
767             /* move and resize the top level frame.
768                shading can change without being moved or resized.
769
770                but don't do this during an iconify animation. it will be
771                reflected afterwards.
772             */
773             XMoveResizeWindow(ob_display, self->window,
774                               self->area.x,
775                               self->area.y,
776                               self->area.width,
777                               self->area.height);
778
779         /* when the client has StaticGravity, it likes to move around.
780            also this correctly positions the client when it maps.
781            this also needs to be run when the frame's decorations sizes change!
782         */
783         XMoveWindow(ob_display, self->client->window,
784                     self->size.left, self->size.top);
785
786         if (resized) {
787             self->need_render = TRUE;
788             framerender_frame(self);
789             frame_adjust_shape(self);
790         }
791
792         if (!STRUT_EQUAL(self->size, oldsize)) {
793             gulong vals[4];
794             vals[0] = self->size.left;
795             vals[1] = self->size.right;
796             vals[2] = self->size.top;
797             vals[3] = self->size.bottom;
798             PROP_SETA32(self->client->window, net_frame_extents,
799                         cardinal, vals, 4);
800             PROP_SETA32(self->client->window, kde_net_wm_frame_strut,
801                         cardinal, vals, 4);
802         }
803
804         /* if this occurs while we are focus cycling, the indicator needs to
805            match the changes */
806         if (focus_cycle_target == self->client)
807             focus_cycle_draw_indicator(self->client);
808     }
809     if (resized && (self->decorations & OB_FRAME_DECOR_TITLEBAR))
810         XResizeWindow(ob_display, self->label, self->label_width,
811                       ob_rr_theme->label_height);
812
813 }
814
815 static void frame_adjust_cursors(ObFrame *self)
816 {
817     if ((self->functions & OB_CLIENT_FUNC_RESIZE) !=
818         (self->client->functions & OB_CLIENT_FUNC_RESIZE) ||
819         self->max_horz != self->client->max_horz ||
820         self->max_vert != self->client->max_vert ||
821         self->shaded != self->client->shaded)
822     {
823         gboolean r = (self->client->functions & OB_CLIENT_FUNC_RESIZE) &&
824             !(self->client->max_horz && self->client->max_vert);
825         gboolean topbot = !self->client->max_vert;
826         gboolean sh = self->client->shaded;
827         XSetWindowAttributes a;
828
829         /* these ones turn off when max vert, and some when shaded */
830         a.cursor = ob_cursor(r && topbot && !sh ?
831                              OB_CURSOR_NORTH : OB_CURSOR_NONE);
832         XChangeWindowAttributes(ob_display, self->topresize, CWCursor, &a);
833         XChangeWindowAttributes(ob_display, self->titletop, CWCursor, &a);
834         a.cursor = ob_cursor(r && topbot ? OB_CURSOR_SOUTH : OB_CURSOR_NONE);
835         XChangeWindowAttributes(ob_display, self->handle, CWCursor, &a);
836         XChangeWindowAttributes(ob_display, self->handletop, CWCursor, &a);
837         XChangeWindowAttributes(ob_display, self->handlebottom, CWCursor, &a);
838         XChangeWindowAttributes(ob_display, self->innerbottom, CWCursor, &a);
839
840         /* these ones change when shaded */
841         a.cursor = ob_cursor(r ? (sh ? OB_CURSOR_WEST : OB_CURSOR_NORTHWEST) :
842                              OB_CURSOR_NONE);
843         XChangeWindowAttributes(ob_display, self->titleleft, CWCursor, &a);
844         XChangeWindowAttributes(ob_display, self->tltresize, CWCursor, &a);
845         XChangeWindowAttributes(ob_display, self->tllresize, CWCursor, &a);
846         XChangeWindowAttributes(ob_display, self->titletopleft, CWCursor, &a);
847         a.cursor = ob_cursor(r ? (sh ? OB_CURSOR_EAST : OB_CURSOR_NORTHEAST) :
848                              OB_CURSOR_NONE);
849         XChangeWindowAttributes(ob_display, self->titleright, CWCursor, &a);
850         XChangeWindowAttributes(ob_display, self->trtresize, CWCursor, &a);
851         XChangeWindowAttributes(ob_display, self->trrresize, CWCursor, &a);
852         XChangeWindowAttributes(ob_display, self->titletopright, CWCursor, &a);
853
854         /* these ones are pretty static */
855         a.cursor = ob_cursor(r ? OB_CURSOR_WEST : OB_CURSOR_NONE);
856         XChangeWindowAttributes(ob_display, self->left, CWCursor, &a);
857         XChangeWindowAttributes(ob_display, self->innerleft, CWCursor, &a);
858         a.cursor = ob_cursor(r ? OB_CURSOR_EAST : OB_CURSOR_NONE);
859         XChangeWindowAttributes(ob_display, self->right, CWCursor, &a);
860         XChangeWindowAttributes(ob_display, self->innerright, CWCursor, &a);
861         a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHWEST : OB_CURSOR_NONE);
862         XChangeWindowAttributes(ob_display, self->lgrip, CWCursor, &a);
863         XChangeWindowAttributes(ob_display, self->handleleft, CWCursor, &a);
864         XChangeWindowAttributes(ob_display, self->lgripleft, CWCursor, &a);
865         XChangeWindowAttributes(ob_display, self->lgriptop, CWCursor, &a);
866         XChangeWindowAttributes(ob_display, self->lgripbottom, CWCursor, &a);
867         a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHEAST : OB_CURSOR_NONE);
868         XChangeWindowAttributes(ob_display, self->rgrip, CWCursor, &a);
869         XChangeWindowAttributes(ob_display, self->handleright, CWCursor, &a);
870         XChangeWindowAttributes(ob_display, self->rgripright, CWCursor, &a);
871         XChangeWindowAttributes(ob_display, self->rgriptop, CWCursor, &a);
872         XChangeWindowAttributes(ob_display, self->rgripbottom, CWCursor, &a);
873     }
874 }
875
876 void frame_adjust_client_area(ObFrame *self)
877 {
878     /* adjust the window which is there to prevent flashing on unmap */
879     XMoveResizeWindow(ob_display, self->backfront, 0, 0,
880                       self->client->area.width,
881                       self->client->area.height);
882 }
883
884 void frame_adjust_state(ObFrame *self)
885 {
886     self->need_render = TRUE;
887     framerender_frame(self);
888 }
889
890 void frame_adjust_focus(ObFrame *self, gboolean hilite)
891 {
892     self->focused = hilite;
893     self->need_render = TRUE;
894     framerender_frame(self);
895     XFlush(ob_display);
896 }
897
898 void frame_adjust_title(ObFrame *self)
899 {
900     self->need_render = TRUE;
901     framerender_frame(self);
902 }
903
904 void frame_adjust_icon(ObFrame *self)
905 {
906     self->need_render = TRUE;
907     framerender_frame(self);
908 }
909
910 void frame_grab_client(ObFrame *self)
911 {
912     /* DO NOT map the client window here. we used to do that, but it is bogus.
913        we need to set up the client's dimensions and everything before we
914        send a mapnotify or we create race conditions.
915     */
916
917     /* reparent the client to the frame */
918     XReparentWindow(ob_display, self->client->window, self->window, 0, 0);
919
920     /*
921       When reparenting the client window, it is usually not mapped yet, since
922       this occurs from a MapRequest. However, in the case where Openbox is
923       starting up, the window is already mapped, so we'll see an unmap event
924       for it.
925     */
926     if (ob_state() == OB_STATE_STARTING)
927         ++self->client->ignore_unmaps;
928
929     /* select the event mask on the client's parent (to receive config/map
930        req's) the ButtonPress is to catch clicks on the client border */
931     XSelectInput(ob_display, self->window, FRAME_EVENTMASK);
932
933     /* set all the windows for the frame in the window_map */
934     g_hash_table_insert(window_map, &self->window, self->client);
935     g_hash_table_insert(window_map, &self->backback, self->client);
936     g_hash_table_insert(window_map, &self->backfront, self->client);
937     g_hash_table_insert(window_map, &self->innerleft, self->client);
938     g_hash_table_insert(window_map, &self->innertop, self->client);
939     g_hash_table_insert(window_map, &self->innerright, self->client);
940     g_hash_table_insert(window_map, &self->innerbottom, self->client);
941     g_hash_table_insert(window_map, &self->title, self->client);
942     g_hash_table_insert(window_map, &self->label, self->client);
943     g_hash_table_insert(window_map, &self->max, self->client);
944     g_hash_table_insert(window_map, &self->close, self->client);
945     g_hash_table_insert(window_map, &self->desk, self->client);
946     g_hash_table_insert(window_map, &self->shade, self->client);
947     g_hash_table_insert(window_map, &self->icon, self->client);
948     g_hash_table_insert(window_map, &self->iconify, self->client);
949     g_hash_table_insert(window_map, &self->handle, self->client);
950     g_hash_table_insert(window_map, &self->lgrip, self->client);
951     g_hash_table_insert(window_map, &self->rgrip, self->client);
952     g_hash_table_insert(window_map, &self->topresize, self->client);
953     g_hash_table_insert(window_map, &self->tltresize, self->client);
954     g_hash_table_insert(window_map, &self->tllresize, self->client);
955     g_hash_table_insert(window_map, &self->trtresize, self->client);
956     g_hash_table_insert(window_map, &self->trrresize, self->client);
957     g_hash_table_insert(window_map, &self->left, self->client);
958     g_hash_table_insert(window_map, &self->right, self->client);
959     g_hash_table_insert(window_map, &self->titleleft, self->client);
960     g_hash_table_insert(window_map, &self->titletop, self->client);
961     g_hash_table_insert(window_map, &self->titletopleft, self->client);
962     g_hash_table_insert(window_map, &self->titletopright, self->client);
963     g_hash_table_insert(window_map, &self->titleright, self->client);
964     g_hash_table_insert(window_map, &self->titlebottom, self->client);
965     g_hash_table_insert(window_map, &self->handleleft, self->client);
966     g_hash_table_insert(window_map, &self->handletop, self->client);
967     g_hash_table_insert(window_map, &self->handleright, self->client);
968     g_hash_table_insert(window_map, &self->handlebottom, self->client);
969     g_hash_table_insert(window_map, &self->lgripleft, self->client);
970     g_hash_table_insert(window_map, &self->lgriptop, self->client);
971     g_hash_table_insert(window_map, &self->lgripbottom, self->client);
972     g_hash_table_insert(window_map, &self->rgripright, self->client);
973     g_hash_table_insert(window_map, &self->rgriptop, self->client);
974     g_hash_table_insert(window_map, &self->rgripbottom, self->client);
975 }
976
977 void frame_release_client(ObFrame *self)
978 {
979     XEvent ev;
980     gboolean reparent = TRUE;
981
982     /* if there was any animation going on, kill it */
983     ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
984                                      self, FALSE);
985
986     /* check if the app has already reparented its window away */
987     while (XCheckTypedWindowEvent(ob_display, self->client->window,
988                                   ReparentNotify, &ev))
989     {
990         /* This check makes sure we don't catch our own reparent action to
991            our frame window. This doesn't count as the app reparenting itself
992            away of course.
993
994            Reparent events that are generated by us are just discarded here.
995            They are of no consequence to us anyhow.
996         */
997         if (ev.xreparent.parent != self->window) {
998             reparent = FALSE;
999             XPutBackEvent(ob_display, &ev);
1000             break;
1001         }
1002     }
1003
1004     if (reparent) {
1005         /* according to the ICCCM - if the client doesn't reparent itself,
1006            then we will reparent the window to root for them */
1007         XReparentWindow(ob_display, self->client->window,
1008                         RootWindow(ob_display, ob_screen),
1009                         self->client->area.x,
1010                         self->client->area.y);
1011     }
1012
1013     /* remove all the windows for the frame from the window_map */
1014     g_hash_table_remove(window_map, &self->window);
1015     g_hash_table_remove(window_map, &self->backback);
1016     g_hash_table_remove(window_map, &self->backfront);
1017     g_hash_table_remove(window_map, &self->innerleft);
1018     g_hash_table_remove(window_map, &self->innertop);
1019     g_hash_table_remove(window_map, &self->innerright);
1020     g_hash_table_remove(window_map, &self->innerbottom);
1021     g_hash_table_remove(window_map, &self->title);
1022     g_hash_table_remove(window_map, &self->label);
1023     g_hash_table_remove(window_map, &self->max);
1024     g_hash_table_remove(window_map, &self->close);
1025     g_hash_table_remove(window_map, &self->desk);
1026     g_hash_table_remove(window_map, &self->shade);
1027     g_hash_table_remove(window_map, &self->icon);
1028     g_hash_table_remove(window_map, &self->iconify);
1029     g_hash_table_remove(window_map, &self->handle);
1030     g_hash_table_remove(window_map, &self->lgrip);
1031     g_hash_table_remove(window_map, &self->rgrip);
1032     g_hash_table_remove(window_map, &self->topresize);
1033     g_hash_table_remove(window_map, &self->tltresize);
1034     g_hash_table_remove(window_map, &self->tllresize);
1035     g_hash_table_remove(window_map, &self->trtresize);
1036     g_hash_table_remove(window_map, &self->trrresize);
1037     g_hash_table_remove(window_map, &self->left);
1038     g_hash_table_remove(window_map, &self->right);
1039     g_hash_table_remove(window_map, &self->titleleft);
1040     g_hash_table_remove(window_map, &self->titletop);
1041     g_hash_table_remove(window_map, &self->titletopleft);
1042     g_hash_table_remove(window_map, &self->titletopright);
1043     g_hash_table_remove(window_map, &self->titleright);
1044     g_hash_table_remove(window_map, &self->titlebottom);
1045     g_hash_table_remove(window_map, &self->handleleft);
1046     g_hash_table_remove(window_map, &self->handletop);
1047     g_hash_table_remove(window_map, &self->handleright);
1048     g_hash_table_remove(window_map, &self->handlebottom);
1049     g_hash_table_remove(window_map, &self->lgripleft);
1050     g_hash_table_remove(window_map, &self->lgriptop);
1051     g_hash_table_remove(window_map, &self->lgripbottom);
1052     g_hash_table_remove(window_map, &self->rgripright);
1053     g_hash_table_remove(window_map, &self->rgriptop);
1054     g_hash_table_remove(window_map, &self->rgripbottom);
1055
1056     ob_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, self, TRUE);
1057 }
1058
1059 /* is there anything present between us and the label? */
1060 static gboolean is_button_present(ObFrame *self, const gchar *lc, gint dir) {
1061     for (; *lc != '\0' && lc >= config_title_layout; lc += dir) {
1062         if (*lc == ' ') continue; /* it was invalid */
1063         if (*lc == 'N' && self->decorations & OB_FRAME_DECOR_ICON)
1064             return TRUE;
1065         if (*lc == 'D' && self->decorations & OB_FRAME_DECOR_ALLDESKTOPS)
1066             return TRUE;
1067         if (*lc == 'S' && self->decorations & OB_FRAME_DECOR_SHADE)
1068             return TRUE;
1069         if (*lc == 'I' && self->decorations & OB_FRAME_DECOR_ICONIFY)
1070             return TRUE;
1071         if (*lc == 'M' && self->decorations & OB_FRAME_DECOR_MAXIMIZE)
1072             return TRUE;
1073         if (*lc == 'C' && self->decorations & OB_FRAME_DECOR_CLOSE)
1074             return TRUE;
1075         if (*lc == 'L') return FALSE;
1076     }
1077     return FALSE;
1078 }
1079
1080 static void layout_title(ObFrame *self)
1081 {
1082     gchar *lc;
1083     gint i;
1084
1085     const gint bwidth = ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
1086     /* position of the left most button */
1087     const gint left = ob_rr_theme->paddingx + 1;
1088     /* position of the right most button */
1089     const gint right = self->width;
1090
1091     /* turn them all off */
1092     self->icon_on = self->desk_on = self->shade_on = self->iconify_on =
1093         self->max_on = self->close_on = self->label_on = FALSE;
1094     self->label_width = self->width - (ob_rr_theme->paddingx + 1) * 2;
1095     self->leftmost = self->rightmost = OB_FRAME_CONTEXT_NONE;
1096
1097     /* figure out what's being show, find each element's position, and the
1098        width of the label
1099
1100        do the ones before the label, then after the label,
1101        i will be +1 the first time through when working to the left,
1102        and -1 the second time through when working to the right */
1103     for (i = 1; i >= -1; i-=2) {
1104         gint x;
1105         ObFrameContext *firstcon;
1106
1107         if (i > 0) {
1108             x = left;
1109             lc = config_title_layout;
1110             firstcon = &self->leftmost;
1111         } else {
1112             x = right;
1113             lc = config_title_layout + strlen(config_title_layout)-1;
1114             firstcon = &self->rightmost;
1115         }
1116
1117         /* stop at the end of the string (or the label, which calls break) */
1118         for (; *lc != '\0' && lc >= config_title_layout; lc+=i) {
1119             if (*lc == 'L') {
1120                 if (i > 0) {
1121                     self->label_on = TRUE;
1122                     self->label_x = x;
1123                 }
1124                 break; /* break the for loop, do other side of label */
1125             } else if (*lc == 'N') {
1126                 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICON;
1127                 if ((self->icon_on = is_button_present(self, lc, i))) {
1128                     /* icon is bigger than buttons */
1129                     self->label_width -= bwidth + 2;
1130                     if (i > 0) self->icon_x = x;
1131                     x += i * (bwidth + 2);
1132                     if (i < 0) self->icon_x = x;
1133                 }
1134             } else if (*lc == 'D') {
1135                 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ALLDESKTOPS;
1136                 if ((self->desk_on = is_button_present(self, lc, i))) {
1137                     self->label_width -= bwidth;
1138                     if (i > 0) self->desk_x = x;
1139                     x += i * bwidth;
1140                     if (i < 0) self->desk_x = x;
1141                 }
1142             } else if (*lc == 'S') {
1143                 if (firstcon) *firstcon = OB_FRAME_CONTEXT_SHADE;
1144                 if ((self->shade_on = is_button_present(self, lc, i))) {
1145                     self->label_width -= bwidth;
1146                     if (i > 0) self->shade_x = x;
1147                     x += i * bwidth;
1148                     if (i < 0) self->shade_x = x;
1149                 }
1150             } else if (*lc == 'I') {
1151                 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICONIFY;
1152                 if ((self->iconify_on = is_button_present(self, lc, i))) {
1153                     self->label_width -= bwidth;
1154                     if (i > 0) self->iconify_x = x;
1155                     x += i * bwidth;
1156                     if (i < 0) self->iconify_x = x;
1157                 }
1158             } else if (*lc == 'M') {
1159                 if (firstcon) *firstcon = OB_FRAME_CONTEXT_MAXIMIZE;
1160                 if ((self->max_on = is_button_present(self, lc, i))) {
1161                     self->label_width -= bwidth;
1162                     if (i > 0) self->max_x = x;
1163                     x += i * bwidth;
1164                     if (i < 0) self->max_x = x;
1165                 }
1166             } else if (*lc == 'C') {
1167                 if (firstcon) *firstcon = OB_FRAME_CONTEXT_CLOSE;
1168                 if ((self->close_on = is_button_present(self, lc, i))) {
1169                     self->label_width -= bwidth;
1170                     if (i > 0) self->close_x = x;
1171                     x += i * bwidth;
1172                     if (i < 0) self->close_x = x;
1173                 }
1174             } else
1175                 continue; /* don't set firstcon */
1176             firstcon = NULL;
1177         }
1178     }
1179
1180     /* position and map the elements */
1181     if (self->icon_on) {
1182         XMapWindow(ob_display, self->icon);
1183         XMoveWindow(ob_display, self->icon, self->icon_x,
1184                     ob_rr_theme->paddingy);
1185     } else
1186         XUnmapWindow(ob_display, self->icon);
1187
1188     if (self->desk_on) {
1189         XMapWindow(ob_display, self->desk);
1190         XMoveWindow(ob_display, self->desk, self->desk_x,
1191                     ob_rr_theme->paddingy + 1);
1192     } else
1193         XUnmapWindow(ob_display, self->desk);
1194
1195     if (self->shade_on) {
1196         XMapWindow(ob_display, self->shade);
1197         XMoveWindow(ob_display, self->shade, self->shade_x,
1198                     ob_rr_theme->paddingy + 1);
1199     } else
1200         XUnmapWindow(ob_display, self->shade);
1201
1202     if (self->iconify_on) {
1203         XMapWindow(ob_display, self->iconify);
1204         XMoveWindow(ob_display, self->iconify, self->iconify_x,
1205                     ob_rr_theme->paddingy + 1);
1206     } else
1207         XUnmapWindow(ob_display, self->iconify);
1208
1209     if (self->max_on) {
1210         XMapWindow(ob_display, self->max);
1211         XMoveWindow(ob_display, self->max, self->max_x,
1212                     ob_rr_theme->paddingy + 1);
1213     } else
1214         XUnmapWindow(ob_display, self->max);
1215
1216     if (self->close_on) {
1217         XMapWindow(ob_display, self->close);
1218         XMoveWindow(ob_display, self->close, self->close_x,
1219                     ob_rr_theme->paddingy + 1);
1220     } else
1221         XUnmapWindow(ob_display, self->close);
1222
1223     if (self->label_on) {
1224         self->label_width = MAX(1, self->label_width); /* no lower than 1 */
1225         XMapWindow(ob_display, self->label);
1226         XMoveWindow(ob_display, self->label, self->label_x,
1227                     ob_rr_theme->paddingy);
1228     } else
1229         XUnmapWindow(ob_display, self->label);
1230 }
1231
1232 ObFrameContext frame_context_from_string(const gchar *name)
1233 {
1234     if (!g_ascii_strcasecmp("Desktop", name))
1235         return OB_FRAME_CONTEXT_DESKTOP;
1236     else if (!g_ascii_strcasecmp("Root", name))
1237         return OB_FRAME_CONTEXT_ROOT;
1238     else if (!g_ascii_strcasecmp("Client", name))
1239         return OB_FRAME_CONTEXT_CLIENT;
1240     else if (!g_ascii_strcasecmp("Titlebar", name))
1241         return OB_FRAME_CONTEXT_TITLEBAR;
1242     else if (!g_ascii_strcasecmp("Frame", name))
1243         return OB_FRAME_CONTEXT_FRAME;
1244     else if (!g_ascii_strcasecmp("TLCorner", name))
1245         return OB_FRAME_CONTEXT_TLCORNER;
1246     else if (!g_ascii_strcasecmp("TRCorner", name))
1247         return OB_FRAME_CONTEXT_TRCORNER;
1248     else if (!g_ascii_strcasecmp("BLCorner", name))
1249         return OB_FRAME_CONTEXT_BLCORNER;
1250     else if (!g_ascii_strcasecmp("BRCorner", name))
1251         return OB_FRAME_CONTEXT_BRCORNER;
1252     else if (!g_ascii_strcasecmp("Top", name))
1253         return OB_FRAME_CONTEXT_TOP;
1254     else if (!g_ascii_strcasecmp("Bottom", name))
1255         return OB_FRAME_CONTEXT_BOTTOM;
1256     else if (!g_ascii_strcasecmp("Left", name))
1257         return OB_FRAME_CONTEXT_LEFT;
1258     else if (!g_ascii_strcasecmp("Right", name))
1259         return OB_FRAME_CONTEXT_RIGHT;
1260     else if (!g_ascii_strcasecmp("Maximize", name))
1261         return OB_FRAME_CONTEXT_MAXIMIZE;
1262     else if (!g_ascii_strcasecmp("AllDesktops", name))
1263         return OB_FRAME_CONTEXT_ALLDESKTOPS;
1264     else if (!g_ascii_strcasecmp("Shade", name))
1265         return OB_FRAME_CONTEXT_SHADE;
1266     else if (!g_ascii_strcasecmp("Iconify", name))
1267         return OB_FRAME_CONTEXT_ICONIFY;
1268     else if (!g_ascii_strcasecmp("Icon", name))
1269         return OB_FRAME_CONTEXT_ICON;
1270     else if (!g_ascii_strcasecmp("Close", name))
1271         return OB_FRAME_CONTEXT_CLOSE;
1272     else if (!g_ascii_strcasecmp("MoveResize", name))
1273         return OB_FRAME_CONTEXT_MOVE_RESIZE;
1274     return OB_FRAME_CONTEXT_NONE;
1275 }
1276
1277 ObFrameContext frame_context(ObClient *client, Window win, gint x, gint y)
1278 {
1279     ObFrame *self;
1280
1281     if (moveresize_in_progress)
1282         return OB_FRAME_CONTEXT_MOVE_RESIZE;
1283
1284     if (win == RootWindow(ob_display, ob_screen))
1285         return OB_FRAME_CONTEXT_ROOT ;
1286     if (client == NULL) return OB_FRAME_CONTEXT_NONE;
1287     if (win == client->window) {
1288         /* conceptually, this is the desktop, as far as users are
1289            concerned */
1290         if (client->type == OB_CLIENT_TYPE_DESKTOP)
1291             return OB_FRAME_CONTEXT_DESKTOP;
1292         return OB_FRAME_CONTEXT_CLIENT;
1293     }
1294
1295     self = client->frame;
1296
1297     /* when the user clicks in the corners of the titlebar and the client
1298        is fully maximized, then treat it like they clicked in the
1299        button that is there */
1300     if (self->max_horz && self->max_vert &&
1301         (win == self->title || win == self->titletop ||
1302          win == self->titleleft || win == self->titletopleft ||
1303          win == self->titleright || win == self->titletopright))
1304     {
1305         /* get the mouse coords in reference to the whole frame */
1306         gint fx = x;
1307         gint fy = y;
1308
1309         /* these windows are down a border width from the top of the frame */
1310         if (win == self->title ||
1311             win == self->titleleft || win == self->titleright)
1312             fy += self->bwidth;
1313
1314         /* title is a border width in from the edge */
1315         if (win == self->title)
1316             fx += self->bwidth;
1317         /* titletop is a bit to the right */
1318         else if (win == self->titletop)
1319             fx += ob_rr_theme->grip_width + self->bwidth;
1320         /* titletopright is way to the right edge */
1321         else if (win == self->titletopright)
1322             fx += self->area.width - (ob_rr_theme->grip_width + self->bwidth);
1323         /* titleright is even more way to the right edge */
1324         else if (win == self->titleright)
1325             fx += self->area.width - self->bwidth;
1326
1327         /* figure out if we're over the area that should be considered a
1328            button */
1329         if (fy < self->bwidth + ob_rr_theme->paddingy + 1 +
1330             ob_rr_theme->button_size)
1331         {
1332             if (fx < (self->bwidth + ob_rr_theme->paddingx + 1 +
1333                       ob_rr_theme->button_size))
1334             {
1335                 if (self->leftmost != OB_FRAME_CONTEXT_NONE)
1336                     return self->leftmost;
1337             }
1338             else if (fx >= (self->area.width -
1339                             (self->bwidth + ob_rr_theme->paddingx + 1 +
1340                              ob_rr_theme->button_size)))
1341             {
1342                 if (self->rightmost != OB_FRAME_CONTEXT_NONE)
1343                     return self->rightmost;
1344             }
1345         }
1346
1347         /* there is no resizing maximized windows so make them the titlebar
1348            context */
1349         return OB_FRAME_CONTEXT_TITLEBAR;
1350     }
1351     else if (self->max_vert &&
1352              (win == self->titletop || win == self->topresize))
1353         /* can't resize vertically when max vert */
1354         return OB_FRAME_CONTEXT_TITLEBAR;
1355     else if (self->shaded &&
1356              (win == self->titletop || win == self->topresize))
1357         /* can't resize vertically when shaded */
1358         return OB_FRAME_CONTEXT_TITLEBAR;
1359
1360     if (win == self->window)            return OB_FRAME_CONTEXT_FRAME;
1361     if (win == self->label)             return OB_FRAME_CONTEXT_TITLEBAR;
1362     if (win == self->handle)            return OB_FRAME_CONTEXT_BOTTOM;
1363     if (win == self->handletop)         return OB_FRAME_CONTEXT_BOTTOM;
1364     if (win == self->handlebottom)      return OB_FRAME_CONTEXT_BOTTOM;
1365     if (win == self->handleleft)        return OB_FRAME_CONTEXT_BLCORNER;
1366     if (win == self->lgrip)             return OB_FRAME_CONTEXT_BLCORNER;
1367     if (win == self->lgripleft)         return OB_FRAME_CONTEXT_BLCORNER;
1368     if (win == self->lgriptop)          return OB_FRAME_CONTEXT_BLCORNER;
1369     if (win == self->lgripbottom)       return OB_FRAME_CONTEXT_BLCORNER;
1370     if (win == self->handleright)       return OB_FRAME_CONTEXT_BRCORNER;
1371     if (win == self->rgrip)             return OB_FRAME_CONTEXT_BRCORNER;
1372     if (win == self->rgripright)        return OB_FRAME_CONTEXT_BLCORNER;
1373     if (win == self->rgriptop)          return OB_FRAME_CONTEXT_BLCORNER;
1374     if (win == self->rgripbottom)       return OB_FRAME_CONTEXT_BLCORNER;
1375     if (win == self->title)             return OB_FRAME_CONTEXT_TITLEBAR;
1376     if (win == self->titlebottom)       return OB_FRAME_CONTEXT_TITLEBAR;
1377     if (win == self->titleleft)         return OB_FRAME_CONTEXT_TLCORNER;
1378     if (win == self->titletopleft)      return OB_FRAME_CONTEXT_TLCORNER;
1379     if (win == self->titleright)        return OB_FRAME_CONTEXT_TRCORNER;
1380     if (win == self->titletopright)     return OB_FRAME_CONTEXT_TRCORNER;
1381     if (win == self->titletop)          return OB_FRAME_CONTEXT_TOP;
1382     if (win == self->topresize)         return OB_FRAME_CONTEXT_TOP;
1383     if (win == self->tltresize)         return OB_FRAME_CONTEXT_TLCORNER;
1384     if (win == self->tllresize)         return OB_FRAME_CONTEXT_TLCORNER;
1385     if (win == self->trtresize)         return OB_FRAME_CONTEXT_TRCORNER;
1386     if (win == self->trrresize)         return OB_FRAME_CONTEXT_TRCORNER;
1387     if (win == self->left)              return OB_FRAME_CONTEXT_LEFT;
1388     if (win == self->right)             return OB_FRAME_CONTEXT_RIGHT;
1389     if (win == self->innertop)          return OB_FRAME_CONTEXT_TITLEBAR;
1390     if (win == self->innerleft)         return OB_FRAME_CONTEXT_LEFT;
1391     if (win == self->innerbottom)       return OB_FRAME_CONTEXT_BOTTOM;
1392     if (win == self->innerright)        return OB_FRAME_CONTEXT_RIGHT;
1393     if (win == self->max)               return OB_FRAME_CONTEXT_MAXIMIZE;
1394     if (win == self->iconify)           return OB_FRAME_CONTEXT_ICONIFY;
1395     if (win == self->close)             return OB_FRAME_CONTEXT_CLOSE;
1396     if (win == self->icon)              return OB_FRAME_CONTEXT_ICON;
1397     if (win == self->desk)              return OB_FRAME_CONTEXT_ALLDESKTOPS;
1398     if (win == self->shade)             return OB_FRAME_CONTEXT_SHADE;
1399
1400     return OB_FRAME_CONTEXT_NONE;
1401 }
1402
1403 void frame_client_gravity(ObFrame *self, gint *x, gint *y)
1404 {
1405     /* horizontal */
1406     switch (self->client->gravity) {
1407     default:
1408     case NorthWestGravity:
1409     case SouthWestGravity:
1410     case WestGravity:
1411         break;
1412
1413     case NorthGravity:
1414     case SouthGravity:
1415     case CenterGravity:
1416         /* the middle of the client will be the middle of the frame */
1417         *x -= (self->size.right - self->size.left) / 2;
1418         break;
1419
1420     case NorthEastGravity:
1421     case SouthEastGravity:
1422     case EastGravity:
1423         /* the right side of the client will be the right side of the frame */
1424         *x -= self->size.right + self->size.left -
1425             self->client->border_width * 2;
1426         break;
1427
1428     case ForgetGravity:
1429     case StaticGravity:
1430         /* the client's position won't move */
1431         *x -= self->size.left - self->client->border_width;
1432         break;
1433     }
1434
1435     /* vertical */
1436     switch (self->client->gravity) {
1437     default:
1438     case NorthWestGravity:
1439     case NorthEastGravity:
1440     case NorthGravity:
1441         break;
1442
1443     case CenterGravity:
1444     case EastGravity:
1445     case WestGravity:
1446         /* the middle of the client will be the middle of the frame */
1447         *y -= (self->size.bottom - self->size.top) / 2;
1448         break;
1449
1450     case SouthWestGravity:
1451     case SouthEastGravity:
1452     case SouthGravity:
1453         /* the bottom of the client will be the bottom of the frame */
1454         *y -= self->size.bottom + self->size.top -
1455             self->client->border_width * 2;
1456         break;
1457
1458     case ForgetGravity:
1459     case StaticGravity:
1460         /* the client's position won't move */
1461         *y -= self->size.top - self->client->border_width;
1462         break;
1463     }
1464 }
1465
1466 void frame_frame_gravity(ObFrame *self, gint *x, gint *y)
1467 {
1468     /* horizontal */
1469     switch (self->client->gravity) {
1470     default:
1471     case NorthWestGravity:
1472     case WestGravity:
1473     case SouthWestGravity:
1474         break;
1475     case NorthGravity:
1476     case CenterGravity:
1477     case SouthGravity:
1478         /* the middle of the client will be the middle of the frame */
1479         *x += (self->size.right - self->size.left) / 2;
1480         break;
1481     case NorthEastGravity:
1482     case EastGravity:
1483     case SouthEastGravity:
1484         /* the right side of the client will be the right side of the frame */
1485         *x += self->size.right + self->size.left -
1486             self->client->border_width * 2;
1487         break;
1488     case StaticGravity:
1489     case ForgetGravity:
1490         /* the client's position won't move */
1491         *x += self->size.left - self->client->border_width;
1492         break;
1493     }
1494
1495     /* vertical */
1496     switch (self->client->gravity) {
1497     default:
1498     case NorthWestGravity:
1499     case NorthGravity:
1500     case NorthEastGravity:
1501         break;
1502     case WestGravity:
1503     case CenterGravity:
1504     case EastGravity:
1505         /* the middle of the client will be the middle of the frame */
1506         *y += (self->size.bottom - self->size.top) / 2;
1507         break;
1508     case SouthWestGravity:
1509     case SouthGravity:
1510     case SouthEastGravity:
1511         /* the bottom of the client will be the bottom of the frame */
1512         *y += self->size.bottom + self->size.top -
1513             self->client->border_width * 2;
1514         break;
1515     case StaticGravity:
1516     case ForgetGravity:
1517         /* the client's position won't move */
1518         *y += self->size.top - self->client->border_width;
1519         break;
1520     }
1521 }
1522
1523 void frame_rect_to_frame(ObFrame *self, Rect *r)
1524 {
1525     r->width += self->size.left + self->size.right;
1526     r->height += self->size.top + self->size.bottom;
1527     frame_client_gravity(self, &r->x, &r->y);
1528 }
1529
1530 static void flash_done(gpointer data)
1531 {
1532     ObFrame *self = data;
1533
1534     if (self->focused != self->flash_on)
1535         frame_adjust_focus(self, self->focused);
1536 }
1537
1538 static gboolean flash_timeout(gpointer data)
1539 {
1540     ObFrame *self = data;
1541     GTimeVal now;
1542
1543     g_get_current_time(&now);
1544     if (now.tv_sec > self->flash_end.tv_sec ||
1545         (now.tv_sec == self->flash_end.tv_sec &&
1546          now.tv_usec >= self->flash_end.tv_usec))
1547         self->flashing = FALSE;
1548
1549     if (!self->flashing)
1550         return FALSE; /* we are done */
1551
1552     self->flash_on = !self->flash_on;
1553     if (!self->focused) {
1554         frame_adjust_focus(self, self->flash_on);
1555         self->focused = FALSE;
1556     }
1557
1558     return TRUE; /* go again */
1559 }
1560
1561 void frame_flash_start(ObFrame *self)
1562 {
1563     self->flash_on = self->focused;
1564
1565     if (!self->flashing)
1566         ob_main_loop_timeout_add(ob_main_loop,
1567                                  G_USEC_PER_SEC * 0.6,
1568                                  flash_timeout,
1569                                  self,
1570                                  g_direct_equal,
1571                                  flash_done);
1572     g_get_current_time(&self->flash_end);
1573     g_time_val_add(&self->flash_end, G_USEC_PER_SEC * 5);
1574
1575     self->flashing = TRUE;
1576 }
1577
1578 void frame_flash_stop(ObFrame *self)
1579 {
1580     self->flashing = FALSE;
1581 }
1582
1583 static gulong frame_animate_iconify_time_left(ObFrame *self,
1584                                               const GTimeVal *now)
1585 {
1586     glong sec, usec;
1587     sec = self->iconify_animation_end.tv_sec - now->tv_sec;
1588     usec = self->iconify_animation_end.tv_usec - now->tv_usec;
1589     if (usec < 0) {
1590         usec += G_USEC_PER_SEC;
1591         sec--;
1592     }
1593     /* no negative values */
1594     return MAX(sec * G_USEC_PER_SEC + usec, 0);
1595 }
1596
1597 static gboolean frame_animate_iconify(gpointer p)
1598 {
1599     ObFrame *self = p;
1600     gint x, y, w, h;
1601     gint iconx, icony, iconw;
1602     GTimeVal now;
1603     gulong time;
1604     gboolean iconifying;
1605
1606     if (self->client->icon_geometry.width == 0) {
1607         /* there is no icon geometry set so just go straight down */
1608         Rect *a = screen_physical_area_monitor
1609             (screen_find_monitor(&self->area));
1610         iconx = self->area.x + self->area.width / 2 + 32;
1611         icony = a->y + a->width;
1612         iconw = 64;
1613         g_free(a);
1614     } else {
1615         iconx = self->client->icon_geometry.x;
1616         icony = self->client->icon_geometry.y;
1617         iconw = self->client->icon_geometry.width;
1618     }
1619
1620     iconifying = self->iconify_animation_going > 0;
1621
1622     /* how far do we have left to go ? */
1623     g_get_current_time(&now);
1624     time = frame_animate_iconify_time_left(self, &now);
1625
1626     if (time == 0 || iconifying) {
1627         /* start where the frame is supposed to be */
1628         x = self->area.x;
1629         y = self->area.y;
1630         w = self->area.width;
1631         h = self->area.height;
1632     } else {
1633         /* start at the icon */
1634         x = iconx;
1635         y = icony;
1636         w = iconw;
1637         h = self->size.top; /* just the titlebar */
1638     }
1639
1640     if (time > 0) {
1641         glong dx, dy, dw;
1642         glong elapsed;
1643
1644         dx = self->area.x - iconx;
1645         dy = self->area.y - icony;
1646         dw = self->area.width - self->bwidth * 2 - iconw;
1647          /* if restoring, we move in the opposite direction */
1648         if (!iconifying) { dx = -dx; dy = -dy; dw = -dw; }
1649
1650         elapsed = FRAME_ANIMATE_ICONIFY_TIME - time;
1651         x = x - (dx * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1652         y = y - (dy * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1653         w = w - (dw * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1654         h = self->size.top; /* just the titlebar */
1655     }
1656
1657     if (time == 0)
1658         frame_end_iconify_animation(self);
1659     else {
1660         XMoveResizeWindow(ob_display, self->window, x, y, w, h);
1661         XFlush(ob_display);
1662     }
1663
1664     return time > 0; /* repeat until we're out of time */
1665 }
1666
1667 void frame_end_iconify_animation(ObFrame *self)
1668 {
1669     /* see if there is an animation going */
1670     if (self->iconify_animation_going == 0) return;
1671
1672     if (!self->visible)
1673         XUnmapWindow(ob_display, self->window);
1674     else {
1675         /* Send a ConfigureNotify when the animation is done, this fixes
1676            KDE's pager showing the window in the wrong place.  since the
1677            window is mapped at a different location and is then moved, we
1678            need to send the synthetic configurenotify, since apps may have
1679            read the position when the client mapped, apparently. */
1680         client_reconfigure(self->client, TRUE);
1681     }
1682
1683     /* we're not animating any more ! */
1684     self->iconify_animation_going = 0;
1685
1686     XMoveResizeWindow(ob_display, self->window,
1687                       self->area.x, self->area.y,
1688                       self->area.width, self->area.height);
1689     /* we delay re-rendering until after we're done animating */
1690     framerender_frame(self);
1691     XFlush(ob_display);
1692 }
1693
1694 void frame_begin_iconify_animation(ObFrame *self, gboolean iconifying)
1695 {
1696     gulong time;
1697     gboolean new_anim = FALSE;
1698     gboolean set_end = TRUE;
1699     GTimeVal now;
1700
1701     /* if there is no titlebar, just don't animate for now
1702        XXX it would be nice tho.. */
1703     if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1704         return;
1705
1706     /* get the current time */
1707     g_get_current_time(&now);
1708
1709     /* get how long until the end */
1710     time = FRAME_ANIMATE_ICONIFY_TIME;
1711     if (self->iconify_animation_going) {
1712         if (!!iconifying != (self->iconify_animation_going > 0)) {
1713             /* animation was already going on in the opposite direction */
1714             time = time - frame_animate_iconify_time_left(self, &now);
1715         } else
1716             /* animation was already going in the same direction */
1717             set_end = FALSE;
1718     } else
1719         new_anim = TRUE;
1720     self->iconify_animation_going = iconifying ? 1 : -1;
1721
1722     /* set the ending time */
1723     if (set_end) {
1724         self->iconify_animation_end.tv_sec = now.tv_sec;
1725         self->iconify_animation_end.tv_usec = now.tv_usec;
1726         g_time_val_add(&self->iconify_animation_end, time);
1727     }
1728
1729     if (new_anim) {
1730         ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
1731                                          self, FALSE);
1732         ob_main_loop_timeout_add(ob_main_loop,
1733                                  FRAME_ANIMATE_ICONIFY_STEP_TIME,
1734                                  frame_animate_iconify, self,
1735                                  g_direct_equal, NULL);
1736
1737         /* do the first step */
1738         frame_animate_iconify(self);
1739
1740         /* show it during the animation even if it is not "visible" */
1741         if (!self->visible)
1742             XMapWindow(ob_display, self->window);
1743     }
1744 }