1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 frame.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
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.
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.
17 See the COPYING file for a copy of the GNU General Public License.
23 #include "extensions.h"
26 #include "framerender.h"
28 #include "focus_cycle.h"
29 #include "focus_cycle_indicator.h"
30 #include "moveresize.h"
32 #include "render/theme.h"
34 #define PLATE_EVENTMASK (SubstructureRedirectMask | FocusChangeMask)
35 #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
36 ButtonPressMask | ButtonReleaseMask)
37 #define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \
38 ButtonMotionMask | PointerMotionMask | \
39 EnterWindowMask | LeaveWindowMask)
40 /* The inner window does not need enter/leave events.
41 If it does get them, then it needs its own context for enter events
42 because sloppy focus will focus the window when you enter the inner window
44 #define INNER_EVENTMASK (ButtonPressMask)
46 #define FRAME_ANIMATE_ICONIFY_TIME 150000 /* .15 seconds */
47 #define FRAME_ANIMATE_ICONIFY_STEP_TIME (G_USEC_PER_SEC / 60) /* 60 Hz */
49 #define FRAME_HANDLE_Y(f) (f->size.top + f->client->area.height + f->cbwidth_y)
51 static void flash_done(gpointer data);
52 static gboolean flash_timeout(gpointer data);
54 static void layout_title(ObFrame *self);
55 static void set_theme_statics(ObFrame *self);
56 static void free_theme_statics(ObFrame *self);
57 static gboolean frame_animate_iconify(gpointer self);
59 static Window createWindow(Window parent, Visual *visual,
60 gulong mask, XSetWindowAttributes *attrib)
62 return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
63 (visual ? 32 : RrDepth(ob_rr_inst)), InputOutput,
64 (visual ? visual : RrVisual(ob_rr_inst)),
69 static Visual *check_32bit_client(ObClient *c)
71 XWindowAttributes wattrib;
74 /* we're already running at 32 bit depth, yay. we don't need to use their
76 if (RrDepth(ob_rr_inst) == 32)
79 ret = XGetWindowAttributes(ob_display, c->window, &wattrib);
80 g_assert(ret != BadDrawable);
81 g_assert(ret != BadWindow);
83 if (wattrib.depth == 32)
84 return wattrib.visual;
88 ObFrame *frame_new(ObClient *client)
90 XSetWindowAttributes attrib;
95 self = g_new0(ObFrame, 1);
96 self->client = client;
98 visual = check_32bit_client(client);
100 /* create the non-visible decor windows */
104 /* client has a 32-bit visual */
105 mask |= CWColormap | CWBackPixel | CWBorderPixel;
106 /* create a colormap with the visual */
107 self->colormap = attrib.colormap =
108 XCreateColormap(ob_display,
109 RootWindow(ob_display, ob_screen),
111 attrib.background_pixel = BlackPixel(ob_display, ob_screen);
112 attrib.border_pixel = BlackPixel(ob_display, ob_screen);
114 attrib.event_mask = FRAME_EVENTMASK;
115 self->window = createWindow(RootWindow(ob_display, ob_screen), visual,
118 attrib.event_mask = INNER_EVENTMASK;
119 self->inner = createWindow(self->window, visual, mask, &attrib);
121 mask &= ~CWEventMask;
122 self->plate = createWindow(self->inner, visual, mask, &attrib);
124 /* create the visible decor windows */
128 /* client has a 32-bit visual */
129 mask |= CWColormap | CWBackPixel | CWBorderPixel;
130 attrib.colormap = RrColormap(ob_rr_inst);
132 attrib.event_mask = ELEMENT_EVENTMASK;
133 self->title = createWindow(self->window, NULL, mask, &attrib);
134 self->titleleft = createWindow(self->window, NULL, mask, &attrib);
135 self->titletop = createWindow(self->window, NULL, mask, &attrib);
136 self->titletopleft = createWindow(self->window, NULL, mask, &attrib);
137 self->titletopright = createWindow(self->window, NULL, mask, &attrib);
138 self->titleright = createWindow(self->window, NULL, mask, &attrib);
139 self->titlebottom = createWindow(self->window, NULL, mask, &attrib);
141 self->topresize = createWindow(self->title, NULL, mask, &attrib);
142 self->tltresize = createWindow(self->title, NULL, mask, &attrib);
143 self->tllresize = createWindow(self->title, NULL, mask, &attrib);
144 self->trtresize = createWindow(self->title, NULL, mask, &attrib);
145 self->trrresize = createWindow(self->title, NULL, mask, &attrib);
147 self->left = createWindow(self->window, NULL, mask, &attrib);
148 self->right = createWindow(self->window, NULL, mask, &attrib);
150 self->label = createWindow(self->title, NULL, mask, &attrib);
151 self->max = createWindow(self->title, NULL, mask, &attrib);
152 self->close = createWindow(self->title, NULL, mask, &attrib);
153 self->desk = createWindow(self->title, NULL, mask, &attrib);
154 self->shade = createWindow(self->title, NULL, mask, &attrib);
155 self->icon = createWindow(self->title, NULL, mask, &attrib);
156 self->iconify = createWindow(self->title, NULL, mask, &attrib);
158 self->handle = createWindow(self->window, NULL, mask, &attrib);
159 self->lgrip = createWindow(self->handle, NULL, mask, &attrib);
160 self->rgrip = createWindow(self->handle, NULL, mask, &attrib);
162 self->handleleft = createWindow(self->handle, NULL, mask, &attrib);
163 self->handleright = createWindow(self->handle, NULL, mask, &attrib);
165 self->handletop = createWindow(self->window, NULL, mask, &attrib);
166 self->handlebottom = createWindow(self->window, NULL, mask, &attrib);
167 self->lgripleft = createWindow(self->window, NULL, mask, &attrib);
168 self->lgriptop = createWindow(self->window, NULL, mask, &attrib);
169 self->lgripbottom = createWindow(self->window, NULL, mask, &attrib);
170 self->rgripright = createWindow(self->window, NULL, mask, &attrib);
171 self->rgriptop = createWindow(self->window, NULL, mask, &attrib);
172 self->rgripbottom = createWindow(self->window, NULL, mask, &attrib);
174 self->focused = FALSE;
176 /* the other stuff is shown based on decor settings */
177 XMapWindow(ob_display, self->plate);
178 XMapWindow(ob_display, self->inner);
179 XMapWindow(ob_display, self->label);
181 self->max_press = self->close_press = self->desk_press =
182 self->iconify_press = self->shade_press = FALSE;
183 self->max_hover = self->close_hover = self->desk_hover =
184 self->iconify_hover = self->shade_hover = FALSE;
186 set_theme_statics(self);
188 return (ObFrame*)self;
191 static void set_theme_statics(ObFrame *self)
193 /* set colors/appearance/sizes for stuff that doesn't change */
194 XResizeWindow(ob_display, self->max,
195 ob_rr_theme->button_size, ob_rr_theme->button_size);
196 XResizeWindow(ob_display, self->iconify,
197 ob_rr_theme->button_size, ob_rr_theme->button_size);
198 XResizeWindow(ob_display, self->icon,
199 ob_rr_theme->button_size + 2, ob_rr_theme->button_size + 2);
200 XResizeWindow(ob_display, self->close,
201 ob_rr_theme->button_size, ob_rr_theme->button_size);
202 XResizeWindow(ob_display, self->desk,
203 ob_rr_theme->button_size, ob_rr_theme->button_size);
204 XResizeWindow(ob_display, self->shade,
205 ob_rr_theme->button_size, ob_rr_theme->button_size);
206 XResizeWindow(ob_display, self->tltresize,
207 ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
208 XResizeWindow(ob_display, self->trtresize,
209 ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
210 XResizeWindow(ob_display, self->tllresize,
211 ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
212 XResizeWindow(ob_display, self->trrresize,
213 ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
215 /* set up the dynamic appearances */
216 self->a_unfocused_title = RrAppearanceCopy(ob_rr_theme->a_unfocused_title);
217 self->a_focused_title = RrAppearanceCopy(ob_rr_theme->a_focused_title);
218 self->a_unfocused_label = RrAppearanceCopy(ob_rr_theme->a_unfocused_label);
219 self->a_focused_label = RrAppearanceCopy(ob_rr_theme->a_focused_label);
220 self->a_unfocused_handle =
221 RrAppearanceCopy(ob_rr_theme->a_unfocused_handle);
222 self->a_focused_handle = RrAppearanceCopy(ob_rr_theme->a_focused_handle);
223 self->a_icon = RrAppearanceCopy(ob_rr_theme->a_icon);
226 static void free_theme_statics(ObFrame *self)
228 RrAppearanceFree(self->a_unfocused_title);
229 RrAppearanceFree(self->a_focused_title);
230 RrAppearanceFree(self->a_unfocused_label);
231 RrAppearanceFree(self->a_focused_label);
232 RrAppearanceFree(self->a_unfocused_handle);
233 RrAppearanceFree(self->a_focused_handle);
234 RrAppearanceFree(self->a_icon);
237 void frame_free(ObFrame *self)
239 free_theme_statics(self);
241 XDestroyWindow(ob_display, self->window);
243 XFreeColormap(ob_display, self->colormap);
248 void frame_show(ObFrame *self)
250 if (!self->visible) {
251 self->visible = TRUE;
252 XMapWindow(ob_display, self->client->window);
253 XMapWindow(ob_display, self->window);
257 void frame_hide(ObFrame *self)
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;
270 void frame_adjust_theme(ObFrame *self)
272 free_theme_statics(self);
273 set_theme_statics(self);
276 void frame_adjust_shape(ObFrame *self)
282 if (!self->client->shaped) {
283 /* clear the shape on the frame window */
284 XShapeCombineMask(ob_display, self->window, ShapeBounding,
289 /* make the frame's shape match the clients */
290 XShapeCombineShape(ob_display, self->window, ShapeBounding,
293 self->client->window,
294 ShapeBounding, ShapeSet);
297 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
300 xrect[0].width = self->area.width;
301 xrect[0].height = ob_rr_theme->title_height +
302 self->bwidth + self->rbwidth;
306 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
307 ob_rr_theme->handle_height > 0)
310 xrect[1].y = FRAME_HANDLE_Y(self);
311 xrect[1].width = self->area.width;
312 xrect[1].height = ob_rr_theme->handle_height +
317 XShapeCombineRectangles(ob_display, self->window,
318 ShapeBounding, 0, 0, xrect, num,
319 ShapeUnion, Unsorted);
324 void frame_adjust_area(ObFrame *self, gboolean moved,
325 gboolean resized, gboolean fake)
329 oldsize = self->size;
332 self->decorations = self->client->decorations;
333 self->max_horz = self->client->max_horz;
335 if (self->decorations & OB_FRAME_DECOR_BORDER) {
336 self->bwidth = ob_rr_theme->fbwidth;
337 self->cbwidth_x = ob_rr_theme->cbwidthx;
338 self->cbwidth_y = ob_rr_theme->cbwidthy;
340 self->bwidth = self->cbwidth_x = self->cbwidth_y = 0;
342 self->rbwidth = self->bwidth;
343 self->leftb = self->rightb = TRUE;
345 if (self->max_horz) {
346 self->leftb = self->rightb = FALSE;
350 self->width = self->client->area.width + self->cbwidth_x * 2;
351 self->width = MAX(self->width, 1); /* no lower than 1 */
353 STRUT_SET(self->size,
354 self->cbwidth_x + (self->leftb ? self->bwidth : 0),
355 self->cbwidth_y + self->bwidth,
356 self->cbwidth_x + (self->rightb ? self->bwidth : 0),
357 self->cbwidth_y + self->bwidth);
359 if (self->decorations & OB_FRAME_DECOR_TITLEBAR)
360 self->size.top += ob_rr_theme->title_height + self->rbwidth;
361 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
362 ob_rr_theme->handle_height > 0)
364 self->size.bottom += ob_rr_theme->handle_height + self->bwidth;
367 /* position/size and map/unmap all the windows */
371 XMoveResizeWindow(ob_display, self->titletop,
372 ob_rr_theme->grip_width + self->bwidth, 0,
373 self->client->area.width +
374 self->cbwidth_x * 2 + self->bwidth * 2 -
375 (ob_rr_theme->grip_width + self->bwidth) * 2,
377 XMoveResizeWindow(ob_display, self->titletopleft,
379 ob_rr_theme->grip_width + self->bwidth,
381 XMoveResizeWindow(ob_display, self->titletopright,
382 self->client->area.width +
383 self->cbwidth_x * 2 + self->bwidth * 2 -
384 ob_rr_theme->grip_width - self->bwidth,
386 ob_rr_theme->grip_width + self->bwidth,
389 XMoveResizeWindow(ob_display, self->titleleft,
393 ob_rr_theme->grip_width :
394 self->size.top - self->bwidth));
395 XMoveResizeWindow(ob_display, self->titleright,
396 self->client->area.width +
397 self->cbwidth_x * 2 + self->bwidth,
401 ob_rr_theme->grip_width :
402 self->size.top - self->bwidth));
404 XMapWindow(ob_display, self->titletop);
405 XMapWindow(ob_display, self->titletopleft);
406 XMapWindow(ob_display, self->titletopright);
407 XMapWindow(ob_display, self->titleleft);
408 XMapWindow(ob_display, self->titleright);
410 if (self->decorations & OB_FRAME_DECOR_TITLEBAR &&
413 XMoveResizeWindow(ob_display, self->titlebottom,
415 ob_rr_theme->title_height + self->bwidth,
416 self->client->area.width +
420 XMapWindow(ob_display, self->titlebottom);
422 XUnmapWindow(ob_display, self->titlebottom);
424 XUnmapWindow(ob_display, self->titlebottom);
426 XUnmapWindow(ob_display, self->titletop);
427 XUnmapWindow(ob_display, self->titletopleft);
428 XUnmapWindow(ob_display, self->titletopright);
429 XUnmapWindow(ob_display, self->titleleft);
430 XUnmapWindow(ob_display, self->titleright);
433 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
434 XMoveResizeWindow(ob_display, self->title,
435 self->bwidth, self->bwidth,
436 self->width, ob_rr_theme->title_height);
438 XMapWindow(ob_display, self->title);
440 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
441 XMoveResizeWindow(ob_display, self->topresize,
442 ob_rr_theme->grip_width + self->bwidth,
444 self->width - (ob_rr_theme->grip_width +
446 ob_rr_theme->paddingy + 1);
448 XMoveWindow(ob_display, self->tltresize, 0, 0);
449 XMoveWindow(ob_display, self->tllresize, 0, 0);
450 XMoveWindow(ob_display, self->trtresize,
451 self->width - ob_rr_theme->grip_width, 0);
452 XMoveWindow(ob_display, self->trrresize,
453 self->width - ob_rr_theme->paddingx - 1, 0);
455 XMapWindow(ob_display, self->topresize);
456 XMapWindow(ob_display, self->tltresize);
457 XMapWindow(ob_display, self->tllresize);
458 XMapWindow(ob_display, self->trtresize);
459 XMapWindow(ob_display, self->trrresize);
461 XUnmapWindow(ob_display, self->topresize);
462 XUnmapWindow(ob_display, self->tltresize);
463 XUnmapWindow(ob_display, self->tllresize);
464 XUnmapWindow(ob_display, self->trtresize);
465 XUnmapWindow(ob_display, self->trrresize);
468 XUnmapWindow(ob_display, self->title);
471 if ((self->decorations & OB_FRAME_DECOR_TITLEBAR))
472 /* layout the title bar elements */
477 XMoveResizeWindow(ob_display, self->handlebottom,
478 ob_rr_theme->grip_width +
480 self->size.top + self->client->area.height +
481 self->size.bottom - self->bwidth,
482 self->width - (ob_rr_theme->grip_width +
486 XMoveResizeWindow(ob_display, self->lgripleft,
488 self->size.top + self->client->area.height +
491 ob_rr_theme->grip_width :
495 ob_rr_theme->grip_width :
497 XMoveResizeWindow(ob_display, self->rgripright,
498 self->size.left + self->client->area.width +
499 self->size.right - self->bwidth,
500 self->size.top + self->client->area.height +
503 ob_rr_theme->grip_width :
507 ob_rr_theme->grip_width :
510 XMoveResizeWindow(ob_display, self->lgripbottom,
512 self->size.top + self->client->area.height +
513 self->size.bottom - self->bwidth,
514 ob_rr_theme->grip_width + self->bwidth,
516 XMoveResizeWindow(ob_display, self->rgripbottom,
517 self->size.left + self->client->area.width +
518 self->size.right - self->bwidth * 2 -
519 ob_rr_theme->grip_width,
520 self->size.top + self->client->area.height +
521 self->size.bottom - self->bwidth,
522 ob_rr_theme->grip_width + self->bwidth,
525 XMapWindow(ob_display, self->handlebottom);
526 XMapWindow(ob_display, self->lgripleft);
527 XMapWindow(ob_display, self->rgripright);
528 XMapWindow(ob_display, self->lgripbottom);
529 XMapWindow(ob_display, self->rgripbottom);
531 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
532 ob_rr_theme->handle_height > 0)
534 XMoveResizeWindow(ob_display, self->handletop,
535 ob_rr_theme->grip_width +
537 FRAME_HANDLE_Y(self),
538 self->width - (ob_rr_theme->grip_width +
541 XMapWindow(ob_display, self->handletop);
543 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
544 XMoveResizeWindow(ob_display, self->handleleft,
545 ob_rr_theme->grip_width,
548 ob_rr_theme->handle_height);
549 XMoveResizeWindow(ob_display, self->handleright,
551 ob_rr_theme->grip_width -
555 ob_rr_theme->handle_height);
557 XMoveResizeWindow(ob_display, self->lgriptop,
559 FRAME_HANDLE_Y(self),
560 ob_rr_theme->grip_width +
563 XMoveResizeWindow(ob_display, self->rgriptop,
565 self->client->area.width +
566 self->size.right - self->bwidth * 2 -
567 ob_rr_theme->grip_width,
568 FRAME_HANDLE_Y(self),
569 ob_rr_theme->grip_width +
573 XMapWindow(ob_display, self->handleleft);
574 XMapWindow(ob_display, self->handleright);
575 XMapWindow(ob_display, self->lgriptop);
576 XMapWindow(ob_display, self->rgriptop);
578 XUnmapWindow(ob_display, self->handleleft);
579 XUnmapWindow(ob_display, self->handleright);
580 XUnmapWindow(ob_display, self->lgriptop);
581 XUnmapWindow(ob_display, self->rgriptop);
584 XUnmapWindow(ob_display, self->handletop);
586 XUnmapWindow(ob_display, self->handletop);
588 XUnmapWindow(ob_display, self->handlebottom);
589 XUnmapWindow(ob_display, self->lgripleft);
590 XUnmapWindow(ob_display, self->rgripright);
591 XUnmapWindow(ob_display, self->lgripbottom);
592 XUnmapWindow(ob_display, self->rgripbottom);
595 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
596 ob_rr_theme->handle_height > 0)
598 XMoveResizeWindow(ob_display, self->handle,
600 FRAME_HANDLE_Y(self) + self->bwidth,
601 self->width, ob_rr_theme->handle_height);
602 XMapWindow(ob_display, self->handle);
604 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
605 XMoveResizeWindow(ob_display, self->lgrip,
607 ob_rr_theme->grip_width,
608 ob_rr_theme->handle_height);
609 XMoveResizeWindow(ob_display, self->rgrip,
610 self->width - ob_rr_theme->grip_width,
612 ob_rr_theme->grip_width,
613 ob_rr_theme->handle_height);
615 XMapWindow(ob_display, self->lgrip);
616 XMapWindow(ob_display, self->rgrip);
618 XUnmapWindow(ob_display, self->lgrip);
619 XUnmapWindow(ob_display, self->rgrip);
622 XUnmapWindow(ob_display, self->handle);
624 if (self->bwidth && !self->max_horz) {
625 XMoveResizeWindow(ob_display, self->left,
627 self->bwidth + ob_rr_theme->grip_width,
629 self->client->area.height +
630 self->size.top + self->size.bottom -
631 ob_rr_theme->grip_width * 2);
632 XMoveResizeWindow(ob_display, self->right,
633 self->client->area.width +
634 self->cbwidth_x * 2 + self->bwidth,
635 self->bwidth + ob_rr_theme->grip_width,
637 self->client->area.height +
638 self->size.top + self->size.bottom -
639 ob_rr_theme->grip_width * 2);
641 XMapWindow(ob_display, self->left);
642 XMapWindow(ob_display, self->right);
644 XUnmapWindow(ob_display, self->left);
645 XUnmapWindow(ob_display, self->right);
648 /* move and resize the inner border window which contains the plate
650 XMoveResizeWindow(ob_display, self->inner,
652 self->size.top - self->cbwidth_y,
653 self->client->area.width +
654 self->cbwidth_x * 2 +
655 (self->leftb ? self->bwidth : 0) +
656 (self->rightb ? self->bwidth : 0),
657 self->client->area.height +
658 self->cbwidth_y * 2);
661 XMoveWindow(ob_display, self->plate,
662 (self->leftb ? self->bwidth : 0) + self->cbwidth_x,
665 /* when the client has StaticGravity, it likes to move around. */
666 XMoveWindow(ob_display, self->client->window, 0, 0);
670 /* shading can change without being moved or resized */
671 RECT_SET_SIZE(self->area,
672 self->client->area.width +
673 self->size.left + self->size.right,
674 (self->client->shaded ?
675 ob_rr_theme->title_height + self->bwidth * 2:
676 self->client->area.height +
677 self->size.top + self->size.bottom));
679 if (moved || resized) {
680 /* find the new coordinates, done after setting the frame.size, for
681 frame_client_gravity. */
682 self->area.x = self->client->area.x;
683 self->area.y = self->client->area.y;
684 frame_client_gravity(self, &self->area.x, &self->area.y,
685 self->client->area.width,
686 self->client->area.height);
690 if (!frame_iconify_animating(self))
691 /* move and resize the top level frame.
692 shading can change without being moved or resized.
694 but don't do this during an iconify animation. it will be
695 reflected afterwards.
697 XMoveResizeWindow(ob_display, self->window,
704 framerender_frame(self);
705 frame_adjust_shape(self);
708 if (!STRUT_EQUAL(self->size, oldsize)) {
710 vals[0] = self->size.left;
711 vals[1] = self->size.right;
712 vals[2] = self->size.top;
713 vals[3] = self->size.bottom;
714 PROP_SETA32(self->client->window, net_frame_extents,
716 PROP_SETA32(self->client->window, kde_net_wm_frame_strut,
720 /* if this occurs while we are focus cycling, the indicator needs to
722 if (focus_cycle_target == self->client)
723 focus_cycle_draw_indicator(self->client);
725 if (resized && (self->decorations & OB_FRAME_DECOR_TITLEBAR))
726 XResizeWindow(ob_display, self->label, self->label_width,
727 ob_rr_theme->label_height);
731 (self->functions & OB_CLIENT_FUNC_RESIZE) !=
732 (self->client->functions & OB_CLIENT_FUNC_RESIZE))
734 gboolean r = self->client->functions & OB_CLIENT_FUNC_RESIZE;
735 XSetWindowAttributes a;
737 a.cursor = ob_cursor(r ? OB_CURSOR_NORTH : OB_CURSOR_NONE);
738 XChangeWindowAttributes(ob_display, self->topresize, CWCursor, &a);
739 XChangeWindowAttributes(ob_display, self->titletop, CWCursor, &a);
740 a.cursor = ob_cursor(r ? OB_CURSOR_NORTHWEST : OB_CURSOR_NONE);
741 XChangeWindowAttributes(ob_display, self->tltresize, CWCursor, &a);
742 XChangeWindowAttributes(ob_display, self->tllresize, CWCursor, &a);
743 XChangeWindowAttributes(ob_display, self->titletopleft, CWCursor, &a);
744 XChangeWindowAttributes(ob_display, self->titleleft, CWCursor, &a);
745 a.cursor = ob_cursor(r ? OB_CURSOR_NORTHEAST : OB_CURSOR_NONE);
746 XChangeWindowAttributes(ob_display, self->trtresize, CWCursor, &a);
747 XChangeWindowAttributes(ob_display, self->trrresize, CWCursor, &a);
748 XChangeWindowAttributes(ob_display, self->titletopright, CWCursor, &a);
749 XChangeWindowAttributes(ob_display, self->titleright, CWCursor, &a);
750 a.cursor = ob_cursor(r ? OB_CURSOR_WEST : OB_CURSOR_NONE);
751 XChangeWindowAttributes(ob_display, self->left, CWCursor, &a);
752 a.cursor = ob_cursor(r ? OB_CURSOR_EAST : OB_CURSOR_NONE);
753 XChangeWindowAttributes(ob_display, self->right, CWCursor, &a);
754 a.cursor = ob_cursor(r ? OB_CURSOR_SOUTH : OB_CURSOR_NONE);
755 XChangeWindowAttributes(ob_display, self->handle, CWCursor, &a);
756 XChangeWindowAttributes(ob_display, self->handletop, CWCursor, &a);
757 XChangeWindowAttributes(ob_display, self->handlebottom, CWCursor, &a);
758 a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHWEST : OB_CURSOR_NONE);
759 XChangeWindowAttributes(ob_display, self->lgrip, CWCursor, &a);
760 XChangeWindowAttributes(ob_display, self->handleleft, CWCursor, &a);
761 XChangeWindowAttributes(ob_display, self->lgripleft, CWCursor, &a);
762 XChangeWindowAttributes(ob_display, self->lgriptop, CWCursor, &a);
763 XChangeWindowAttributes(ob_display, self->lgripbottom, CWCursor, &a);
764 a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHEAST : OB_CURSOR_NONE);
765 XChangeWindowAttributes(ob_display, self->rgrip, CWCursor, &a);
766 XChangeWindowAttributes(ob_display, self->handleright, CWCursor, &a);
767 XChangeWindowAttributes(ob_display, self->rgripright, CWCursor, &a);
768 XChangeWindowAttributes(ob_display, self->rgriptop, CWCursor, &a);
769 XChangeWindowAttributes(ob_display, self->rgripbottom, CWCursor, &a);
771 self->functions = self->client->functions;
775 void frame_adjust_client_area(ObFrame *self)
777 /* resize the plate */
778 XResizeWindow(ob_display, self->plate,
779 self->client->area.width, self->client->area.height);
782 void frame_adjust_state(ObFrame *self)
784 framerender_frame(self);
787 void frame_adjust_focus(ObFrame *self, gboolean hilite)
789 self->focused = hilite;
790 framerender_frame(self);
794 void frame_adjust_title(ObFrame *self)
796 framerender_frame(self);
799 void frame_adjust_icon(ObFrame *self)
801 framerender_frame(self);
804 void frame_grab_client(ObFrame *self)
806 /* reparent the client to the frame */
807 XReparentWindow(ob_display, self->client->window, self->plate, 0, 0);
810 When reparenting the client window, it is usually not mapped yet, since
811 this occurs from a MapRequest. However, in the case where Openbox is
812 starting up, the window is already mapped, so we'll see unmap events for
813 it. There are 2 unmap events generated that we see, one with the 'event'
814 member set the root window, and one set to the client, but both get
815 handled and need to be ignored.
817 if (ob_state() == OB_STATE_STARTING)
818 self->client->ignore_unmaps += 2;
820 /* select the event mask on the client's parent (to receive config/map
821 req's) the ButtonPress is to catch clicks on the client border */
822 XSelectInput(ob_display, self->plate, PLATE_EVENTMASK);
824 /* map the client so it maps when the frame does */
825 XMapWindow(ob_display, self->client->window);
827 /* set all the windows for the frame in the window_map */
828 g_hash_table_insert(window_map, &self->window, self->client);
829 g_hash_table_insert(window_map, &self->plate, self->client);
830 g_hash_table_insert(window_map, &self->inner, self->client);
831 g_hash_table_insert(window_map, &self->title, self->client);
832 g_hash_table_insert(window_map, &self->label, self->client);
833 g_hash_table_insert(window_map, &self->max, self->client);
834 g_hash_table_insert(window_map, &self->close, self->client);
835 g_hash_table_insert(window_map, &self->desk, self->client);
836 g_hash_table_insert(window_map, &self->shade, self->client);
837 g_hash_table_insert(window_map, &self->icon, self->client);
838 g_hash_table_insert(window_map, &self->iconify, self->client);
839 g_hash_table_insert(window_map, &self->handle, self->client);
840 g_hash_table_insert(window_map, &self->lgrip, self->client);
841 g_hash_table_insert(window_map, &self->rgrip, self->client);
842 g_hash_table_insert(window_map, &self->topresize, self->client);
843 g_hash_table_insert(window_map, &self->tltresize, self->client);
844 g_hash_table_insert(window_map, &self->tllresize, self->client);
845 g_hash_table_insert(window_map, &self->trtresize, self->client);
846 g_hash_table_insert(window_map, &self->trrresize, self->client);
847 g_hash_table_insert(window_map, &self->left, self->client);
848 g_hash_table_insert(window_map, &self->right, self->client);
849 g_hash_table_insert(window_map, &self->titleleft, self->client);
850 g_hash_table_insert(window_map, &self->titletop, self->client);
851 g_hash_table_insert(window_map, &self->titletopleft, self->client);
852 g_hash_table_insert(window_map, &self->titletopright, self->client);
853 g_hash_table_insert(window_map, &self->titleright, self->client);
854 g_hash_table_insert(window_map, &self->titlebottom, self->client);
855 g_hash_table_insert(window_map, &self->handleleft, self->client);
856 g_hash_table_insert(window_map, &self->handletop, self->client);
857 g_hash_table_insert(window_map, &self->handleright, self->client);
858 g_hash_table_insert(window_map, &self->handlebottom, self->client);
859 g_hash_table_insert(window_map, &self->lgripleft, self->client);
860 g_hash_table_insert(window_map, &self->lgriptop, self->client);
861 g_hash_table_insert(window_map, &self->lgripbottom, self->client);
862 g_hash_table_insert(window_map, &self->rgripright, self->client);
863 g_hash_table_insert(window_map, &self->rgriptop, self->client);
864 g_hash_table_insert(window_map, &self->rgripbottom, self->client);
867 void frame_release_client(ObFrame *self)
870 gboolean reparent = TRUE;
872 /* if there was any animation going on, kill it */
873 ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
876 /* check if the app has already reparented its window away */
877 while (XCheckTypedWindowEvent(ob_display, self->client->window,
878 ReparentNotify, &ev))
880 /* This check makes sure we don't catch our own reparent action to
881 our frame window. This doesn't count as the app reparenting itself
884 Reparent events that are generated by us are just discarded here.
885 They are of no consequence to us anyhow.
887 if (ev.xreparent.parent != self->plate) {
889 XPutBackEvent(ob_display, &ev);
895 /* according to the ICCCM - if the client doesn't reparent itself,
896 then we will reparent the window to root for them */
897 XReparentWindow(ob_display, self->client->window,
898 RootWindow(ob_display, ob_screen),
899 self->client->area.x,
900 self->client->area.y);
903 /* remove all the windows for the frame from the window_map */
904 g_hash_table_remove(window_map, &self->window);
905 g_hash_table_remove(window_map, &self->plate);
906 g_hash_table_remove(window_map, &self->inner);
907 g_hash_table_remove(window_map, &self->title);
908 g_hash_table_remove(window_map, &self->label);
909 g_hash_table_remove(window_map, &self->max);
910 g_hash_table_remove(window_map, &self->close);
911 g_hash_table_remove(window_map, &self->desk);
912 g_hash_table_remove(window_map, &self->shade);
913 g_hash_table_remove(window_map, &self->icon);
914 g_hash_table_remove(window_map, &self->iconify);
915 g_hash_table_remove(window_map, &self->handle);
916 g_hash_table_remove(window_map, &self->lgrip);
917 g_hash_table_remove(window_map, &self->rgrip);
918 g_hash_table_remove(window_map, &self->topresize);
919 g_hash_table_remove(window_map, &self->tltresize);
920 g_hash_table_remove(window_map, &self->tllresize);
921 g_hash_table_remove(window_map, &self->trtresize);
922 g_hash_table_remove(window_map, &self->trrresize);
923 g_hash_table_remove(window_map, &self->left);
924 g_hash_table_remove(window_map, &self->right);
925 g_hash_table_remove(window_map, &self->titleleft);
926 g_hash_table_remove(window_map, &self->titletop);
927 g_hash_table_remove(window_map, &self->titletopleft);
928 g_hash_table_remove(window_map, &self->titletopright);
929 g_hash_table_remove(window_map, &self->titleright);
930 g_hash_table_remove(window_map, &self->titlebottom);
931 g_hash_table_remove(window_map, &self->handleleft);
932 g_hash_table_remove(window_map, &self->handletop);
933 g_hash_table_remove(window_map, &self->handleright);
934 g_hash_table_remove(window_map, &self->handlebottom);
935 g_hash_table_remove(window_map, &self->lgripleft);
936 g_hash_table_remove(window_map, &self->lgriptop);
937 g_hash_table_remove(window_map, &self->lgripbottom);
938 g_hash_table_remove(window_map, &self->rgripright);
939 g_hash_table_remove(window_map, &self->rgriptop);
940 g_hash_table_remove(window_map, &self->rgripbottom);
942 ob_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, self, TRUE);
945 /* is there anything present between us and the label? */
946 static gboolean is_button_present(ObFrame *self, const gchar *lc, gint dir) {
947 for (; *lc != '\0' && lc >= config_title_layout; lc += dir) {
948 if (*lc == ' ') continue; /* it was invalid */
949 if (*lc == 'N' && self->decorations & OB_FRAME_DECOR_ICON)
951 if (*lc == 'D' && self->decorations & OB_FRAME_DECOR_ALLDESKTOPS)
953 if (*lc == 'S' && self->decorations & OB_FRAME_DECOR_SHADE)
955 if (*lc == 'I' && self->decorations & OB_FRAME_DECOR_ICONIFY)
957 if (*lc == 'M' && self->decorations & OB_FRAME_DECOR_MAXIMIZE)
959 if (*lc == 'C' && self->decorations & OB_FRAME_DECOR_CLOSE)
961 if (*lc == 'L') return FALSE;
966 static void layout_title(ObFrame *self)
971 const gint bwidth = ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
972 /* position of the left most button */
973 const gint left = ob_rr_theme->paddingx + 1;
974 /* position of the right most button */
975 const gint right = self->width - bwidth;
977 /* turn them all off */
978 self->icon_on = self->desk_on = self->shade_on = self->iconify_on =
979 self->max_on = self->close_on = self->label_on = FALSE;
980 self->label_width = self->width - (ob_rr_theme->paddingx + 1) * 2;
981 self->leftmost = self->rightmost = OB_FRAME_CONTEXT_NONE;
983 /* figure out what's being show, find each element's position, and the
986 do the ones before the label, then after the label,
987 i will be +1 the first time through when working to the left,
988 and -1 the second time through when working to the right */
989 for (i = 1; i >= -1; i-=2) {
991 ObFrameContext *firstcon;
995 lc = config_title_layout;
996 firstcon = &self->leftmost;
999 lc = config_title_layout + strlen(config_title_layout)-1;
1000 firstcon = &self->rightmost;
1003 /* stop at the end of the string (or the label, which calls break) */
1004 for (; *lc != '\0' && lc >= config_title_layout; lc+=i) {
1007 self->label_on = TRUE;
1010 break; /* break the for loop, do other side of label */
1011 } else if (*lc == 'N') {
1012 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICON;
1013 if ((self->icon_on = is_button_present(self, lc, i))) {
1014 /* icon is bigger than buttons */
1015 self->label_width -= bwidth + 2;
1017 x += i * (bwidth + 2);
1019 } else if (*lc == 'D') {
1020 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ALLDESKTOPS;
1021 if ((self->desk_on = is_button_present(self, lc, i))) {
1022 self->label_width -= bwidth;
1026 } else if (*lc == 'S') {
1027 if (firstcon) *firstcon = OB_FRAME_CONTEXT_SHADE;
1028 if ((self->shade_on = is_button_present(self, lc, i))) {
1029 self->label_width -= bwidth;
1033 } else if (*lc == 'I') {
1034 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICONIFY;
1035 if ((self->iconify_on = is_button_present(self, lc, i))) {
1036 self->label_width -= bwidth;
1037 self->iconify_x = x;
1040 } else if (*lc == 'M') {
1041 if (firstcon) *firstcon = OB_FRAME_CONTEXT_MAXIMIZE;
1042 if ((self->max_on = is_button_present(self, lc, i))) {
1043 self->label_width -= bwidth;
1047 } else if (*lc == 'C') {
1048 if (firstcon) *firstcon = OB_FRAME_CONTEXT_CLOSE;
1049 if ((self->close_on = is_button_present(self, lc, i))) {
1050 self->label_width -= bwidth;
1055 continue; /* don't set firstcon */
1060 /* position and map the elements */
1061 if (self->icon_on) {
1062 XMapWindow(ob_display, self->icon);
1063 XMoveWindow(ob_display, self->icon, self->icon_x,
1064 ob_rr_theme->paddingy);
1066 XUnmapWindow(ob_display, self->icon);
1068 if (self->desk_on) {
1069 XMapWindow(ob_display, self->desk);
1070 XMoveWindow(ob_display, self->desk, self->desk_x,
1071 ob_rr_theme->paddingy + 1);
1073 XUnmapWindow(ob_display, self->desk);
1075 if (self->shade_on) {
1076 XMapWindow(ob_display, self->shade);
1077 XMoveWindow(ob_display, self->shade, self->shade_x,
1078 ob_rr_theme->paddingy + 1);
1080 XUnmapWindow(ob_display, self->shade);
1082 if (self->iconify_on) {
1083 XMapWindow(ob_display, self->iconify);
1084 XMoveWindow(ob_display, self->iconify, self->iconify_x,
1085 ob_rr_theme->paddingy + 1);
1087 XUnmapWindow(ob_display, self->iconify);
1090 XMapWindow(ob_display, self->max);
1091 XMoveWindow(ob_display, self->max, self->max_x,
1092 ob_rr_theme->paddingy + 1);
1094 XUnmapWindow(ob_display, self->max);
1096 if (self->close_on) {
1097 XMapWindow(ob_display, self->close);
1098 XMoveWindow(ob_display, self->close, self->close_x,
1099 ob_rr_theme->paddingy + 1);
1101 XUnmapWindow(ob_display, self->close);
1103 if (self->label_on) {
1104 self->label_width = MAX(1, self->label_width); /* no lower than 1 */
1105 XMapWindow(ob_display, self->label);
1106 XMoveWindow(ob_display, self->label, self->label_x,
1107 ob_rr_theme->paddingy);
1109 XUnmapWindow(ob_display, self->label);
1112 ObFrameContext frame_context_from_string(const gchar *name)
1114 if (!g_ascii_strcasecmp("Desktop", name))
1115 return OB_FRAME_CONTEXT_DESKTOP;
1116 else if (!g_ascii_strcasecmp("Root", name))
1117 return OB_FRAME_CONTEXT_ROOT;
1118 else if (!g_ascii_strcasecmp("Client", name))
1119 return OB_FRAME_CONTEXT_CLIENT;
1120 else if (!g_ascii_strcasecmp("Titlebar", name))
1121 return OB_FRAME_CONTEXT_TITLEBAR;
1122 else if (!g_ascii_strcasecmp("Frame", name))
1123 return OB_FRAME_CONTEXT_FRAME;
1124 else if (!g_ascii_strcasecmp("TLCorner", name))
1125 return OB_FRAME_CONTEXT_TLCORNER;
1126 else if (!g_ascii_strcasecmp("TRCorner", name))
1127 return OB_FRAME_CONTEXT_TRCORNER;
1128 else if (!g_ascii_strcasecmp("BLCorner", name))
1129 return OB_FRAME_CONTEXT_BLCORNER;
1130 else if (!g_ascii_strcasecmp("BRCorner", name))
1131 return OB_FRAME_CONTEXT_BRCORNER;
1132 else if (!g_ascii_strcasecmp("Top", name))
1133 return OB_FRAME_CONTEXT_TOP;
1134 else if (!g_ascii_strcasecmp("Bottom", name))
1135 return OB_FRAME_CONTEXT_BOTTOM;
1136 else if (!g_ascii_strcasecmp("Left", name))
1137 return OB_FRAME_CONTEXT_LEFT;
1138 else if (!g_ascii_strcasecmp("Right", name))
1139 return OB_FRAME_CONTEXT_RIGHT;
1140 else if (!g_ascii_strcasecmp("Maximize", name))
1141 return OB_FRAME_CONTEXT_MAXIMIZE;
1142 else if (!g_ascii_strcasecmp("AllDesktops", name))
1143 return OB_FRAME_CONTEXT_ALLDESKTOPS;
1144 else if (!g_ascii_strcasecmp("Shade", name))
1145 return OB_FRAME_CONTEXT_SHADE;
1146 else if (!g_ascii_strcasecmp("Iconify", name))
1147 return OB_FRAME_CONTEXT_ICONIFY;
1148 else if (!g_ascii_strcasecmp("Icon", name))
1149 return OB_FRAME_CONTEXT_ICON;
1150 else if (!g_ascii_strcasecmp("Close", name))
1151 return OB_FRAME_CONTEXT_CLOSE;
1152 else if (!g_ascii_strcasecmp("MoveResize", name))
1153 return OB_FRAME_CONTEXT_MOVE_RESIZE;
1154 return OB_FRAME_CONTEXT_NONE;
1157 ObFrameContext frame_context(ObClient *client, Window win, gint x, gint y)
1161 if (moveresize_in_progress)
1162 return OB_FRAME_CONTEXT_MOVE_RESIZE;
1164 if (win == RootWindow(ob_display, ob_screen))
1165 return OB_FRAME_CONTEXT_ROOT ;
1166 if (client == NULL) return OB_FRAME_CONTEXT_NONE;
1167 if (win == client->window) {
1168 /* conceptually, this is the desktop, as far as users are
1170 if (client->type == OB_CLIENT_TYPE_DESKTOP)
1171 return OB_FRAME_CONTEXT_DESKTOP;
1172 return OB_FRAME_CONTEXT_CLIENT;
1175 self = client->frame;
1176 if (win == self->inner || win == self->plate) {
1177 /* conceptually, this is the desktop, as far as users are
1179 if (client->type == OB_CLIENT_TYPE_DESKTOP)
1180 return OB_FRAME_CONTEXT_DESKTOP;
1181 return OB_FRAME_CONTEXT_CLIENT;
1184 if (win == self->title) {
1185 /* when the user clicks in the corners of the titlebar and the client
1186 is fully maximized, then treat it like they clicked in the
1187 button that is there */
1188 if (self->client->max_horz && self->client->max_vert &&
1189 y < ob_rr_theme->paddingy + 1 + ob_rr_theme->button_size)
1191 if (x < ((ob_rr_theme->paddingx + 1) * 2 +
1192 ob_rr_theme->button_size)) {
1193 if (self->leftmost != OB_FRAME_CONTEXT_NONE)
1194 return self->leftmost;
1196 else if (x > (self->width -
1197 (ob_rr_theme->paddingx + 1 +
1198 ob_rr_theme->button_size)))
1200 if (self->rightmost != OB_FRAME_CONTEXT_NONE)
1201 return self->rightmost;
1204 return OB_FRAME_CONTEXT_TITLEBAR;
1207 if (win == self->window) return OB_FRAME_CONTEXT_FRAME;
1208 if (win == self->label) return OB_FRAME_CONTEXT_TITLEBAR;
1209 if (win == self->handle) return OB_FRAME_CONTEXT_BOTTOM;
1210 if (win == self->handletop) return OB_FRAME_CONTEXT_BOTTOM;
1211 if (win == self->handlebottom) return OB_FRAME_CONTEXT_BOTTOM;
1212 if (win == self->handleleft) return OB_FRAME_CONTEXT_BLCORNER;
1213 if (win == self->lgrip) return OB_FRAME_CONTEXT_BLCORNER;
1214 if (win == self->lgripleft) return OB_FRAME_CONTEXT_BLCORNER;
1215 if (win == self->lgriptop) return OB_FRAME_CONTEXT_BLCORNER;
1216 if (win == self->lgripbottom) return OB_FRAME_CONTEXT_BLCORNER;
1217 if (win == self->handleright) return OB_FRAME_CONTEXT_BRCORNER;
1218 if (win == self->rgrip) return OB_FRAME_CONTEXT_BRCORNER;
1219 if (win == self->rgripright) return OB_FRAME_CONTEXT_BLCORNER;
1220 if (win == self->rgriptop) return OB_FRAME_CONTEXT_BLCORNER;
1221 if (win == self->rgripbottom) return OB_FRAME_CONTEXT_BLCORNER;
1222 if (win == self->titletop) return OB_FRAME_CONTEXT_TOP;
1223 if (win == self->topresize) return OB_FRAME_CONTEXT_TOP;
1224 if (win == self->tltresize) return OB_FRAME_CONTEXT_TLCORNER;
1225 if (win == self->tllresize) return OB_FRAME_CONTEXT_TLCORNER;
1226 if (win == self->titleleft) return OB_FRAME_CONTEXT_TLCORNER;
1227 if (win == self->titletopleft) return OB_FRAME_CONTEXT_TLCORNER;
1228 if (win == self->trtresize) return OB_FRAME_CONTEXT_TRCORNER;
1229 if (win == self->trrresize) return OB_FRAME_CONTEXT_TRCORNER;
1230 if (win == self->titleright) return OB_FRAME_CONTEXT_TRCORNER;
1231 if (win == self->titletopright) return OB_FRAME_CONTEXT_TRCORNER;
1232 if (win == self->left) return OB_FRAME_CONTEXT_LEFT;
1233 if (win == self->right) return OB_FRAME_CONTEXT_RIGHT;
1234 if (win == self->max) return OB_FRAME_CONTEXT_MAXIMIZE;
1235 if (win == self->iconify) return OB_FRAME_CONTEXT_ICONIFY;
1236 if (win == self->close) return OB_FRAME_CONTEXT_CLOSE;
1237 if (win == self->icon) return OB_FRAME_CONTEXT_ICON;
1238 if (win == self->desk) return OB_FRAME_CONTEXT_ALLDESKTOPS;
1239 if (win == self->shade) return OB_FRAME_CONTEXT_SHADE;
1241 return OB_FRAME_CONTEXT_NONE;
1244 void frame_client_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h)
1247 switch (self->client->gravity) {
1249 case NorthWestGravity:
1250 case SouthWestGravity:
1257 *x -= (self->size.left + w) / 2;
1260 case NorthEastGravity:
1261 case SouthEastGravity:
1263 *x -= (self->size.left + self->size.right + w) - 1;
1268 *x -= self->size.left;
1273 switch (self->client->gravity) {
1275 case NorthWestGravity:
1276 case NorthEastGravity:
1283 *y -= (self->size.top + h) / 2;
1286 case SouthWestGravity:
1287 case SouthEastGravity:
1289 *y -= (self->size.top + self->size.bottom + h) - 1;
1294 *y -= self->size.top;
1299 void frame_frame_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h)
1302 switch (self->client->gravity) {
1304 case NorthWestGravity:
1306 case SouthWestGravity:
1311 *x += (self->size.left + w) / 2;
1313 case NorthEastGravity:
1315 case SouthEastGravity:
1316 *x += (self->size.left + self->size.right + w) - 1;
1320 *x += self->size.left;
1325 switch (self->client->gravity) {
1327 case NorthWestGravity:
1329 case NorthEastGravity:
1334 *y += (self->size.top + h) / 2;
1336 case SouthWestGravity:
1338 case SouthEastGravity:
1339 *y += (self->size.top + self->size.bottom + h) - 1;
1343 *y += self->size.top;
1348 static void flash_done(gpointer data)
1350 ObFrame *self = data;
1352 if (self->focused != self->flash_on)
1353 frame_adjust_focus(self, self->focused);
1356 static gboolean flash_timeout(gpointer data)
1358 ObFrame *self = data;
1361 g_get_current_time(&now);
1362 if (now.tv_sec > self->flash_end.tv_sec ||
1363 (now.tv_sec == self->flash_end.tv_sec &&
1364 now.tv_usec >= self->flash_end.tv_usec))
1365 self->flashing = FALSE;
1367 if (!self->flashing)
1368 return FALSE; /* we are done */
1370 self->flash_on = !self->flash_on;
1371 if (!self->focused) {
1372 frame_adjust_focus(self, self->flash_on);
1373 self->focused = FALSE;
1376 return TRUE; /* go again */
1379 void frame_flash_start(ObFrame *self)
1381 self->flash_on = self->focused;
1383 if (!self->flashing)
1384 ob_main_loop_timeout_add(ob_main_loop,
1385 G_USEC_PER_SEC * 0.6,
1390 g_get_current_time(&self->flash_end);
1391 g_time_val_add(&self->flash_end, G_USEC_PER_SEC * 5);
1393 self->flashing = TRUE;
1396 void frame_flash_stop(ObFrame *self)
1398 self->flashing = FALSE;
1401 static gulong frame_animate_iconify_time_left(ObFrame *self,
1402 const GTimeVal *now)
1405 sec = self->iconify_animation_end.tv_sec - now->tv_sec;
1406 usec = self->iconify_animation_end.tv_usec - now->tv_usec;
1408 usec += G_USEC_PER_SEC;
1411 /* no negative values */
1412 return MAX(sec * G_USEC_PER_SEC + usec, 0);
1415 static gboolean frame_animate_iconify(gpointer p)
1419 gint iconx, icony, iconw;
1422 gboolean iconifying;
1424 if (self->client->icon_geometry.width == 0) {
1425 /* there is no icon geometry set so just go straight down */
1426 Rect *a = screen_physical_area();
1427 iconx = self->area.x + self->area.width / 2 + 32;
1428 icony = a->y + a->width;
1431 iconx = self->client->icon_geometry.x;
1432 icony = self->client->icon_geometry.y;
1433 iconw = self->client->icon_geometry.width;
1436 iconifying = self->iconify_animation_going > 0;
1438 /* how far do we have left to go ? */
1439 g_get_current_time(&now);
1440 time = frame_animate_iconify_time_left(self, &now);
1442 if (time == 0 || iconifying) {
1443 /* start where the frame is supposed to be */
1446 w = self->area.width - self->bwidth * 2;
1447 h = self->area.height - self->bwidth * 2;
1449 /* start at the icon */
1453 h = self->size.top; /* just the titlebar */
1460 dx = self->area.x - iconx;
1461 dy = self->area.y - icony;
1462 dw = self->area.width - self->bwidth * 2 - iconw;
1463 /* if restoring, we move in the opposite direction */
1464 if (!iconifying) { dx = -dx; dy = -dy; dw = -dw; }
1466 elapsed = FRAME_ANIMATE_ICONIFY_TIME - time;
1467 x = x - (dx * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1468 y = y - (dy * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1469 w = w - (dw * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1470 h = self->size.top; /* just the titlebar */
1474 frame_end_iconify_animation(self);
1476 XMoveResizeWindow(ob_display, self->window, x, y, w, h);
1480 return time > 0; /* repeat until we're out of time */
1483 void frame_end_iconify_animation(ObFrame *self)
1485 /* see if there is an animation going */
1486 if (self->iconify_animation_going == 0) return;
1489 XUnmapWindow(ob_display, self->window);
1491 /* Send a ConfigureNotify when the animation is done, this fixes
1492 KDE's pager showing the window in the wrong place. */
1493 client_reconfigure(self->client);
1495 /* we're not animating any more ! */
1496 self->iconify_animation_going = 0;
1498 XMoveResizeWindow(ob_display, self->window,
1499 self->area.x, self->area.y,
1500 self->area.width - self->bwidth * 2,
1501 self->area.height - self->bwidth * 2);
1505 void frame_begin_iconify_animation(ObFrame *self, gboolean iconifying)
1508 gboolean new_anim = FALSE;
1509 gboolean set_end = TRUE;
1512 /* if there is no titlebar, just don't animate for now
1513 XXX it would be nice tho.. */
1514 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1517 /* get the current time */
1518 g_get_current_time(&now);
1520 /* get how long until the end */
1521 time = FRAME_ANIMATE_ICONIFY_TIME;
1522 if (self->iconify_animation_going) {
1523 if (!!iconifying != (self->iconify_animation_going > 0)) {
1524 /* animation was already going on in the opposite direction */
1525 time = time - frame_animate_iconify_time_left(self, &now);
1527 /* animation was already going in the same direction */
1531 self->iconify_animation_going = iconifying ? 1 : -1;
1533 /* set the ending time */
1535 self->iconify_animation_end.tv_sec = now.tv_sec;
1536 self->iconify_animation_end.tv_usec = now.tv_usec;
1537 g_time_val_add(&self->iconify_animation_end, time);
1541 ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
1543 ob_main_loop_timeout_add(ob_main_loop,
1544 FRAME_ANIMATE_ICONIFY_STEP_TIME,
1545 frame_animate_iconify, self,
1546 g_direct_equal, NULL);
1548 /* do the first step */
1549 frame_animate_iconify(self);
1551 /* show it during the animation even if it is not "visible" */
1553 XMapWindow(ob_display, self->window);