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.
26 #include "framerender.h"
27 #include "focus_cycle.h"
28 #include "focus_cycle_indicator.h"
29 #include "moveresize.h"
31 #include "obrender/theme.h"
32 #include "obt/display.h"
33 #include "obt/xqueue.h"
36 #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
37 ButtonPressMask | ButtonReleaseMask | \
38 SubstructureRedirectMask | FocusChangeMask)
39 #define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \
40 ButtonMotionMask | PointerMotionMask | \
41 EnterWindowMask | LeaveWindowMask)
43 #define FRAME_ANIMATE_ICONIFY_TIME 150000 /* .15 seconds */
44 #define FRAME_ANIMATE_ICONIFY_STEP_TIME (G_USEC_PER_SEC / 60) /* 60 Hz */
46 #define FRAME_HANDLE_Y(f) (f->size.top + f->client->area.height + f->cbwidth_b)
48 static void flash_done(gpointer data);
49 static gboolean flash_timeout(gpointer data);
51 static void layout_title(ObFrame *self);
52 static void set_theme_statics(ObFrame *self);
53 static void free_theme_statics(ObFrame *self);
54 static gboolean frame_animate_iconify(gpointer self);
55 static void frame_adjust_cursors(ObFrame *self);
57 static Window createWindow(Window parent, Visual *visual,
58 gulong mask, XSetWindowAttributes *attrib)
60 return XCreateWindow(obt_display, parent, 0, 0, 1, 1, 0,
61 (visual ? 32 : RrDepth(ob_rr_inst)), InputOutput,
62 (visual ? visual : RrVisual(ob_rr_inst)),
67 static Visual *check_32bit_client(ObClient *c)
69 XWindowAttributes wattrib;
72 /* we're already running at 32 bit depth, yay. we don't need to use their
74 if (RrDepth(ob_rr_inst) == 32)
77 ret = XGetWindowAttributes(obt_display, c->window, &wattrib);
78 g_assert(ret != BadDrawable);
79 g_assert(ret != BadWindow);
81 if (wattrib.depth == 32)
82 return wattrib.visual;
86 ObFrame *frame_new(ObClient *client)
88 XSetWindowAttributes attrib;
93 self = g_slice_new0(ObFrame);
94 self->client = client;
96 visual = check_32bit_client(client);
98 /* create the non-visible decor windows */
102 /* client has a 32-bit visual */
103 mask = CWColormap | CWBackPixel | CWBorderPixel;
104 /* create a colormap with the visual */
105 self->colormap = attrib.colormap =
106 XCreateColormap(obt_display, obt_root(ob_screen),
108 attrib.background_pixel = BlackPixel(obt_display, ob_screen);
109 attrib.border_pixel = BlackPixel(obt_display, ob_screen);
111 self->window = createWindow(obt_root(ob_screen), visual,
114 /* create the visible decor windows */
118 /* client has a 32-bit visual */
119 mask = CWColormap | CWBackPixel | CWBorderPixel;
120 attrib.colormap = RrColormap(ob_rr_inst);
123 self->backback = createWindow(self->window, NULL, mask, &attrib);
124 self->backfront = createWindow(self->backback, NULL, mask, &attrib);
127 attrib.event_mask = ELEMENT_EVENTMASK;
128 self->innerleft = createWindow(self->window, NULL, mask, &attrib);
129 self->innertop = createWindow(self->window, NULL, mask, &attrib);
130 self->innerright = createWindow(self->window, NULL, mask, &attrib);
131 self->innerbottom = createWindow(self->window, NULL, mask, &attrib);
133 self->innerblb = createWindow(self->innerbottom, NULL, mask, &attrib);
134 self->innerbrb = createWindow(self->innerbottom, NULL, mask, &attrib);
135 self->innerbll = createWindow(self->innerleft, NULL, mask, &attrib);
136 self->innerbrr = createWindow(self->innerright, NULL, mask, &attrib);
138 self->title = createWindow(self->window, NULL, mask, &attrib);
139 self->titleleft = createWindow(self->window, NULL, mask, &attrib);
140 self->titletop = createWindow(self->window, NULL, mask, &attrib);
141 self->titletopleft = createWindow(self->window, NULL, mask, &attrib);
142 self->titletopright = createWindow(self->window, NULL, mask, &attrib);
143 self->titleright = createWindow(self->window, NULL, mask, &attrib);
144 self->titlebottom = createWindow(self->window, NULL, mask, &attrib);
146 self->topresize = createWindow(self->title, NULL, mask, &attrib);
147 self->tltresize = createWindow(self->title, NULL, mask, &attrib);
148 self->tllresize = createWindow(self->title, NULL, mask, &attrib);
149 self->trtresize = createWindow(self->title, NULL, mask, &attrib);
150 self->trrresize = createWindow(self->title, NULL, mask, &attrib);
152 self->left = createWindow(self->window, NULL, mask, &attrib);
153 self->right = createWindow(self->window, NULL, mask, &attrib);
155 self->label = createWindow(self->title, NULL, mask, &attrib);
156 self->max = createWindow(self->title, NULL, mask, &attrib);
157 self->close = createWindow(self->title, NULL, mask, &attrib);
158 self->desk = createWindow(self->title, NULL, mask, &attrib);
159 self->shade = createWindow(self->title, NULL, mask, &attrib);
160 self->icon = createWindow(self->title, NULL, mask, &attrib);
161 self->iconify = createWindow(self->title, NULL, mask, &attrib);
163 self->handle = createWindow(self->window, NULL, mask, &attrib);
164 self->lgrip = createWindow(self->handle, NULL, mask, &attrib);
165 self->rgrip = createWindow(self->handle, NULL, mask, &attrib);
167 self->handleleft = createWindow(self->handle, NULL, mask, &attrib);
168 self->handleright = createWindow(self->handle, NULL, mask, &attrib);
170 self->handletop = createWindow(self->window, NULL, mask, &attrib);
171 self->handlebottom = createWindow(self->window, NULL, mask, &attrib);
172 self->lgripleft = createWindow(self->window, NULL, mask, &attrib);
173 self->lgriptop = createWindow(self->window, NULL, mask, &attrib);
174 self->lgripbottom = createWindow(self->window, NULL, mask, &attrib);
175 self->rgripright = createWindow(self->window, NULL, mask, &attrib);
176 self->rgriptop = createWindow(self->window, NULL, mask, &attrib);
177 self->rgripbottom = createWindow(self->window, NULL, mask, &attrib);
179 self->focused = FALSE;
181 /* the other stuff is shown based on decor settings */
182 XMapWindow(obt_display, self->label);
183 XMapWindow(obt_display, self->backback);
184 XMapWindow(obt_display, self->backfront);
186 self->max_press = self->close_press = self->desk_press =
187 self->iconify_press = self->shade_press = FALSE;
188 self->max_hover = self->close_hover = self->desk_hover =
189 self->iconify_hover = self->shade_hover = FALSE;
191 /* make sure the size will be different the first time, so the extent hints
193 STRUT_SET(self->size, -1, -1, -1, -1);
195 set_theme_statics(self);
200 static void set_theme_statics(ObFrame *self)
202 /* set colors/appearance/sizes for stuff that doesn't change */
203 XResizeWindow(obt_display, self->max,
204 ob_rr_theme->button_size, ob_rr_theme->button_size);
205 XResizeWindow(obt_display, self->iconify,
206 ob_rr_theme->button_size, ob_rr_theme->button_size);
207 XResizeWindow(obt_display, self->icon,
208 ob_rr_theme->button_size + 2, ob_rr_theme->button_size + 2);
209 XResizeWindow(obt_display, self->close,
210 ob_rr_theme->button_size, ob_rr_theme->button_size);
211 XResizeWindow(obt_display, self->desk,
212 ob_rr_theme->button_size, ob_rr_theme->button_size);
213 XResizeWindow(obt_display, self->shade,
214 ob_rr_theme->button_size, ob_rr_theme->button_size);
215 XResizeWindow(obt_display, self->tltresize,
216 ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
217 XResizeWindow(obt_display, self->trtresize,
218 ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
219 XResizeWindow(obt_display, self->tllresize,
220 ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
221 XResizeWindow(obt_display, self->trrresize,
222 ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
225 static void free_theme_statics(ObFrame *self)
229 void frame_free(ObFrame *self)
231 free_theme_statics(self);
233 XDestroyWindow(obt_display, self->window);
235 XFreeColormap(obt_display, self->colormap);
237 g_slice_free(ObFrame, self);
240 void frame_show(ObFrame *self)
242 if (!self->visible) {
243 self->visible = TRUE;
244 framerender_frame(self);
245 /* Grab the server to make sure that the frame window is mapped before
246 the client gets its MapNotify, i.e. to make sure the client is
247 _visible_ when it gets MapNotify. */
249 XMapWindow(obt_display, self->client->window);
250 XMapWindow(obt_display, self->window);
255 void frame_hide(ObFrame *self)
258 self->visible = FALSE;
259 if (!frame_iconify_animating(self))
260 XUnmapWindow(obt_display, self->window);
261 /* we unmap the client itself so that we can get MapRequest
262 events, and because the ICCCM tells us to! */
263 XUnmapWindow(obt_display, self->client->window);
264 self->client->ignore_unmaps += 1;
268 void frame_adjust_theme(ObFrame *self)
270 free_theme_statics(self);
271 set_theme_statics(self);
275 void frame_adjust_shape_kind(ObFrame *self, int kind)
280 if (!((kind == ShapeBounding && self->client->shaped) ||
281 (kind == ShapeInput && self->client->shaped_input))) {
282 /* clear the shape on the frame window */
283 XShapeCombineMask(obt_display, self->window, kind,
288 /* make the frame's shape match the clients */
289 XShapeCombineShape(obt_display, self->window, kind,
292 self->client->window,
296 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
299 xrect[0].width = self->area.width;
300 xrect[0].height = self->size.top;
304 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
305 ob_rr_theme->handle_height > 0)
308 xrect[1].y = FRAME_HANDLE_Y(self);
309 xrect[1].width = self->area.width;
310 xrect[1].height = ob_rr_theme->handle_height +
315 XShapeCombineRectangles(obt_display, self->window,
316 ShapeBounding, 0, 0, xrect, num,
317 ShapeUnion, Unsorted);
322 void frame_adjust_shape(ObFrame *self)
325 frame_adjust_shape_kind(self, ShapeBounding);
326 frame_adjust_shape_kind(self, ShapeInput);
330 void frame_adjust_area(ObFrame *self, gboolean moved,
331 gboolean resized, gboolean fake)
335 oldsize = self->size;
338 /* do this before changing the frame's status like max_horz max_vert */
339 frame_adjust_cursors(self);
341 self->functions = self->client->functions;
342 self->decorations = self->client->decorations;
343 self->max_horz = self->client->max_horz;
344 self->max_vert = self->client->max_vert;
345 self->shaded = self->client->shaded;
347 if (self->decorations & OB_FRAME_DECOR_BORDER)
348 self->bwidth = ob_rr_theme->fbwidth;
352 if (self->decorations & OB_FRAME_DECOR_BORDER &&
353 !self->client->undecorated)
355 self->cbwidth_l = self->cbwidth_r = ob_rr_theme->cbwidthx;
356 self->cbwidth_t = self->cbwidth_b = ob_rr_theme->cbwidthy;
358 self->cbwidth_l = self->cbwidth_t =
359 self->cbwidth_r = self->cbwidth_b = 0;
361 if (self->max_horz) {
362 self->cbwidth_l = self->cbwidth_r = 0;
363 self->width = self->client->area.width;
367 self->width = self->client->area.width +
368 self->cbwidth_l + self->cbwidth_r;
370 /* some elements are sized based of the width, so don't let them have
372 self->width = MAX(self->width,
373 (ob_rr_theme->grip_width + self->bwidth) * 2 + 1);
375 STRUT_SET(self->size,
376 self->cbwidth_l + (!self->max_horz ? self->bwidth : 0),
377 self->cbwidth_t + self->bwidth,
378 self->cbwidth_r + (!self->max_horz ? self->bwidth : 0),
380 (!self->max_horz || !self->max_vert ? self->bwidth : 0));
382 if (self->decorations & OB_FRAME_DECOR_TITLEBAR)
383 self->size.top += ob_rr_theme->title_height + self->bwidth;
384 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
385 ob_rr_theme->handle_height > 0)
387 self->size.bottom += ob_rr_theme->handle_height + self->bwidth;
390 /* position/size and map/unmap all the windows */
393 gint innercornerheight =
394 ob_rr_theme->grip_width - self->size.bottom;
396 if (self->cbwidth_l) {
397 XMoveResizeWindow(obt_display, self->innerleft,
398 self->size.left - self->cbwidth_l,
400 self->cbwidth_l, self->client->area.height);
402 XMapWindow(obt_display, self->innerleft);
404 XUnmapWindow(obt_display, self->innerleft);
406 if (self->cbwidth_l && innercornerheight > 0) {
407 XMoveResizeWindow(obt_display, self->innerbll,
409 self->client->area.height -
410 (ob_rr_theme->grip_width -
413 ob_rr_theme->grip_width - self->size.bottom);
415 XMapWindow(obt_display, self->innerbll);
417 XUnmapWindow(obt_display, self->innerbll);
419 if (self->cbwidth_r) {
420 XMoveResizeWindow(obt_display, self->innerright,
421 self->size.left + self->client->area.width,
423 self->cbwidth_r, self->client->area.height);
425 XMapWindow(obt_display, self->innerright);
427 XUnmapWindow(obt_display, self->innerright);
429 if (self->cbwidth_r && innercornerheight > 0) {
430 XMoveResizeWindow(obt_display, self->innerbrr,
432 self->client->area.height -
433 (ob_rr_theme->grip_width -
436 ob_rr_theme->grip_width - self->size.bottom);
438 XMapWindow(obt_display, self->innerbrr);
440 XUnmapWindow(obt_display, self->innerbrr);
442 if (self->cbwidth_t) {
443 XMoveResizeWindow(obt_display, self->innertop,
444 self->size.left - self->cbwidth_l,
445 self->size.top - self->cbwidth_t,
446 self->client->area.width +
447 self->cbwidth_l + self->cbwidth_r,
450 XMapWindow(obt_display, self->innertop);
452 XUnmapWindow(obt_display, self->innertop);
454 if (self->cbwidth_b) {
455 XMoveResizeWindow(obt_display, self->innerbottom,
456 self->size.left - self->cbwidth_l,
457 self->size.top + self->client->area.height,
458 self->client->area.width +
459 self->cbwidth_l + self->cbwidth_r,
462 XMoveResizeWindow(obt_display, self->innerblb,
464 ob_rr_theme->grip_width + self->bwidth,
466 XMoveResizeWindow(obt_display, self->innerbrb,
467 self->client->area.width +
468 self->cbwidth_l + self->cbwidth_r -
469 (ob_rr_theme->grip_width + self->bwidth),
471 ob_rr_theme->grip_width + self->bwidth,
474 XMapWindow(obt_display, self->innerbottom);
475 XMapWindow(obt_display, self->innerblb);
476 XMapWindow(obt_display, self->innerbrb);
478 XUnmapWindow(obt_display, self->innerbottom);
479 XUnmapWindow(obt_display, self->innerblb);
480 XUnmapWindow(obt_display, self->innerbrb);
486 /* height of titleleft and titleright */
487 titlesides = (!self->max_horz ? ob_rr_theme->grip_width : 0);
489 XMoveResizeWindow(obt_display, self->titletop,
490 ob_rr_theme->grip_width + self->bwidth, 0,
491 /* width + bwidth*2 - bwidth*2 - grips*2 */
492 self->width - ob_rr_theme->grip_width * 2,
494 XMoveResizeWindow(obt_display, self->titletopleft,
496 ob_rr_theme->grip_width + self->bwidth,
498 XMoveResizeWindow(obt_display, self->titletopright,
499 self->client->area.width +
500 self->size.left + self->size.right -
501 ob_rr_theme->grip_width - self->bwidth,
503 ob_rr_theme->grip_width + self->bwidth,
506 if (titlesides > 0) {
507 XMoveResizeWindow(obt_display, self->titleleft,
511 XMoveResizeWindow(obt_display, self->titleright,
512 self->client->area.width +
513 self->size.left + self->size.right -
519 XMapWindow(obt_display, self->titleleft);
520 XMapWindow(obt_display, self->titleright);
522 XUnmapWindow(obt_display, self->titleleft);
523 XUnmapWindow(obt_display, self->titleright);
526 XMapWindow(obt_display, self->titletop);
527 XMapWindow(obt_display, self->titletopleft);
528 XMapWindow(obt_display, self->titletopright);
530 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
531 XMoveResizeWindow(obt_display, self->titlebottom,
532 (self->max_horz ? 0 : self->bwidth),
533 ob_rr_theme->title_height + self->bwidth,
537 XMapWindow(obt_display, self->titlebottom);
539 XUnmapWindow(obt_display, self->titlebottom);
541 XUnmapWindow(obt_display, self->titlebottom);
543 XUnmapWindow(obt_display, self->titletop);
544 XUnmapWindow(obt_display, self->titletopleft);
545 XUnmapWindow(obt_display, self->titletopright);
546 XUnmapWindow(obt_display, self->titleleft);
547 XUnmapWindow(obt_display, self->titleright);
550 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
551 XMoveResizeWindow(obt_display, self->title,
552 (self->max_horz ? 0 : self->bwidth),
554 self->width, ob_rr_theme->title_height);
556 XMapWindow(obt_display, self->title);
558 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
559 XMoveResizeWindow(obt_display, self->topresize,
560 ob_rr_theme->grip_width,
562 self->width - ob_rr_theme->grip_width *2,
563 ob_rr_theme->paddingy + 1);
565 XMoveWindow(obt_display, self->tltresize, 0, 0);
566 XMoveWindow(obt_display, self->tllresize, 0, 0);
567 XMoveWindow(obt_display, self->trtresize,
568 self->width - ob_rr_theme->grip_width, 0);
569 XMoveWindow(obt_display, self->trrresize,
570 self->width - ob_rr_theme->paddingx - 1, 0);
572 XMapWindow(obt_display, self->topresize);
573 XMapWindow(obt_display, self->tltresize);
574 XMapWindow(obt_display, self->tllresize);
575 XMapWindow(obt_display, self->trtresize);
576 XMapWindow(obt_display, self->trrresize);
578 XUnmapWindow(obt_display, self->topresize);
579 XUnmapWindow(obt_display, self->tltresize);
580 XUnmapWindow(obt_display, self->tllresize);
581 XUnmapWindow(obt_display, self->trtresize);
582 XUnmapWindow(obt_display, self->trrresize);
585 XUnmapWindow(obt_display, self->title);
588 if ((self->decorations & OB_FRAME_DECOR_TITLEBAR))
589 /* layout the title bar elements */
593 gint sidebwidth = self->max_horz ? 0 : self->bwidth;
595 if (self->bwidth && self->size.bottom) {
596 XMoveResizeWindow(obt_display, self->handlebottom,
597 ob_rr_theme->grip_width +
598 self->bwidth + sidebwidth,
599 self->size.top + self->client->area.height +
600 self->size.bottom - self->bwidth,
601 self->width - (ob_rr_theme->grip_width +
607 XMoveResizeWindow(obt_display, self->lgripleft,
610 self->client->area.height +
613 ob_rr_theme->grip_width :
614 self->size.bottom - self->cbwidth_b),
617 ob_rr_theme->grip_width :
618 self->size.bottom - self->cbwidth_b));
619 XMoveResizeWindow(obt_display, self->rgripright,
621 self->client->area.width +
622 self->size.right - self->bwidth,
624 self->client->area.height +
627 ob_rr_theme->grip_width :
628 self->size.bottom - self->cbwidth_b),
631 ob_rr_theme->grip_width :
632 self->size.bottom - self->cbwidth_b));
634 XMapWindow(obt_display, self->lgripleft);
635 XMapWindow(obt_display, self->rgripright);
637 XUnmapWindow(obt_display, self->lgripleft);
638 XUnmapWindow(obt_display, self->rgripright);
641 XMoveResizeWindow(obt_display, self->lgripbottom,
643 self->size.top + self->client->area.height +
644 self->size.bottom - self->bwidth,
645 ob_rr_theme->grip_width + self->bwidth,
647 XMoveResizeWindow(obt_display, self->rgripbottom,
648 self->size.left + self->client->area.width +
649 self->size.right - self->bwidth - sidebwidth-
650 ob_rr_theme->grip_width,
651 self->size.top + self->client->area.height +
652 self->size.bottom - self->bwidth,
653 ob_rr_theme->grip_width + self->bwidth,
656 XMapWindow(obt_display, self->handlebottom);
657 XMapWindow(obt_display, self->lgripbottom);
658 XMapWindow(obt_display, self->rgripbottom);
660 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
661 ob_rr_theme->handle_height > 0)
663 XMoveResizeWindow(obt_display, self->handletop,
664 ob_rr_theme->grip_width +
665 self->bwidth + sidebwidth,
666 FRAME_HANDLE_Y(self),
667 self->width - (ob_rr_theme->grip_width +
670 XMapWindow(obt_display, self->handletop);
672 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
673 XMoveResizeWindow(obt_display, self->handleleft,
674 ob_rr_theme->grip_width,
677 ob_rr_theme->handle_height);
678 XMoveResizeWindow(obt_display, self->handleright,
680 ob_rr_theme->grip_width -
684 ob_rr_theme->handle_height);
686 XMoveResizeWindow(obt_display, self->lgriptop,
688 FRAME_HANDLE_Y(self),
689 ob_rr_theme->grip_width +
692 XMoveResizeWindow(obt_display, self->rgriptop,
694 self->client->area.width +
695 self->size.right - self->bwidth -
696 sidebwidth - ob_rr_theme->grip_width,
697 FRAME_HANDLE_Y(self),
698 ob_rr_theme->grip_width +
702 XMapWindow(obt_display, self->handleleft);
703 XMapWindow(obt_display, self->handleright);
704 XMapWindow(obt_display, self->lgriptop);
705 XMapWindow(obt_display, self->rgriptop);
707 XUnmapWindow(obt_display, self->handleleft);
708 XUnmapWindow(obt_display, self->handleright);
709 XUnmapWindow(obt_display, self->lgriptop);
710 XUnmapWindow(obt_display, self->rgriptop);
713 XUnmapWindow(obt_display, self->handleleft);
714 XUnmapWindow(obt_display, self->handleright);
715 XUnmapWindow(obt_display, self->lgriptop);
716 XUnmapWindow(obt_display, self->rgriptop);
718 XUnmapWindow(obt_display, self->handletop);
721 XUnmapWindow(obt_display, self->handleleft);
722 XUnmapWindow(obt_display, self->handleright);
723 XUnmapWindow(obt_display, self->lgriptop);
724 XUnmapWindow(obt_display, self->rgriptop);
726 XUnmapWindow(obt_display, self->handletop);
728 XUnmapWindow(obt_display, self->handlebottom);
729 XUnmapWindow(obt_display, self->lgripleft);
730 XUnmapWindow(obt_display, self->rgripright);
731 XUnmapWindow(obt_display, self->lgripbottom);
732 XUnmapWindow(obt_display, self->rgripbottom);
735 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
736 ob_rr_theme->handle_height > 0)
738 XMoveResizeWindow(obt_display, self->handle,
740 FRAME_HANDLE_Y(self) + self->bwidth,
741 self->width, ob_rr_theme->handle_height);
742 XMapWindow(obt_display, self->handle);
744 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
745 XMoveResizeWindow(obt_display, self->lgrip,
747 ob_rr_theme->grip_width,
748 ob_rr_theme->handle_height);
749 XMoveResizeWindow(obt_display, self->rgrip,
750 self->width - ob_rr_theme->grip_width,
752 ob_rr_theme->grip_width,
753 ob_rr_theme->handle_height);
755 XMapWindow(obt_display, self->lgrip);
756 XMapWindow(obt_display, self->rgrip);
758 XUnmapWindow(obt_display, self->lgrip);
759 XUnmapWindow(obt_display, self->rgrip);
762 XUnmapWindow(obt_display, self->lgrip);
763 XUnmapWindow(obt_display, self->rgrip);
765 XUnmapWindow(obt_display, self->handle);
768 if (self->bwidth && !self->max_horz &&
769 (self->client->area.height + self->size.top +
770 self->size.bottom) > ob_rr_theme->grip_width * 2)
772 XMoveResizeWindow(obt_display, self->left,
774 self->bwidth + ob_rr_theme->grip_width,
776 self->client->area.height +
777 self->size.top + self->size.bottom -
778 ob_rr_theme->grip_width * 2);
780 XMapWindow(obt_display, self->left);
782 XUnmapWindow(obt_display, self->left);
784 if (self->bwidth && !self->max_horz &&
785 (self->client->area.height + self->size.top +
786 self->size.bottom) > ob_rr_theme->grip_width * 2)
788 XMoveResizeWindow(obt_display, self->right,
789 self->client->area.width + self->cbwidth_l +
790 self->cbwidth_r + self->bwidth,
791 self->bwidth + ob_rr_theme->grip_width,
793 self->client->area.height +
794 self->size.top + self->size.bottom -
795 ob_rr_theme->grip_width * 2);
797 XMapWindow(obt_display, self->right);
799 XUnmapWindow(obt_display, self->right);
801 XMoveResizeWindow(obt_display, self->backback,
802 self->size.left, self->size.top,
803 self->client->area.width,
804 self->client->area.height);
808 /* shading can change without being moved or resized */
809 RECT_SET_SIZE(self->area,
810 self->client->area.width +
811 self->size.left + self->size.right,
812 (self->client->shaded ?
813 ob_rr_theme->title_height + self->bwidth * 2:
814 self->client->area.height +
815 self->size.top + self->size.bottom));
817 if ((moved || resized) && !fake) {
818 /* find the new coordinates, done after setting the frame.size, for
819 frame_client_gravity. */
820 self->area.x = self->client->area.x;
821 self->area.y = self->client->area.y;
822 frame_client_gravity(self, &self->area.x, &self->area.y);
826 if (!frame_iconify_animating(self))
827 /* move and resize the top level frame.
828 shading can change without being moved or resized.
830 but don't do this during an iconify animation. it will be
831 reflected afterwards.
833 XMoveResizeWindow(obt_display, self->window,
839 /* when the client has StaticGravity, it likes to move around.
840 also this correctly positions the client when it maps.
841 this also needs to be run when the frame's decorations sizes change!
843 XMoveWindow(obt_display, self->client->window,
844 self->size.left, self->size.top);
847 self->need_render = TRUE;
848 framerender_frame(self);
849 frame_adjust_shape(self);
852 if (!STRUT_EQUAL(self->size, oldsize)) {
854 vals[0] = self->size.left;
855 vals[1] = self->size.right;
856 vals[2] = self->size.top;
857 vals[3] = self->size.bottom;
858 OBT_PROP_SETA32(self->client->window, NET_FRAME_EXTENTS,
860 OBT_PROP_SETA32(self->client->window, KDE_NET_WM_FRAME_STRUT,
864 /* if this occurs while we are focus cycling, the indicator needs to
866 if (focus_cycle_target == self->client)
867 focus_cycle_update_indicator(self->client);
869 if (resized && (self->decorations & OB_FRAME_DECOR_TITLEBAR) &&
872 XResizeWindow(obt_display, self->label, self->label_width,
873 ob_rr_theme->label_height);
877 static void frame_adjust_cursors(ObFrame *self)
879 if ((self->functions & OB_CLIENT_FUNC_RESIZE) !=
880 (self->client->functions & OB_CLIENT_FUNC_RESIZE) ||
881 self->max_horz != self->client->max_horz ||
882 self->max_vert != self->client->max_vert ||
883 self->shaded != self->client->shaded)
885 gboolean r = (self->client->functions & OB_CLIENT_FUNC_RESIZE) &&
886 !(self->client->max_horz && self->client->max_vert);
887 gboolean topbot = !self->client->max_vert;
888 gboolean sh = self->client->shaded;
889 XSetWindowAttributes a;
891 /* these ones turn off when max vert, and some when shaded */
892 a.cursor = ob_cursor(r && topbot && !sh ?
893 OB_CURSOR_NORTH : OB_CURSOR_NONE);
894 XChangeWindowAttributes(obt_display, self->topresize, CWCursor, &a);
895 XChangeWindowAttributes(obt_display, self->titletop, CWCursor, &a);
896 a.cursor = ob_cursor(r && topbot ? OB_CURSOR_SOUTH : OB_CURSOR_NONE);
897 XChangeWindowAttributes(obt_display, self->handle, CWCursor, &a);
898 XChangeWindowAttributes(obt_display, self->handletop, CWCursor, &a);
899 XChangeWindowAttributes(obt_display, self->handlebottom, CWCursor, &a);
900 XChangeWindowAttributes(obt_display, self->innerbottom, CWCursor, &a);
902 /* these ones change when shaded */
903 a.cursor = ob_cursor(r ? (sh ? OB_CURSOR_WEST : OB_CURSOR_NORTHWEST) :
905 XChangeWindowAttributes(obt_display, self->titleleft, CWCursor, &a);
906 XChangeWindowAttributes(obt_display, self->tltresize, CWCursor, &a);
907 XChangeWindowAttributes(obt_display, self->tllresize, CWCursor, &a);
908 XChangeWindowAttributes(obt_display, self->titletopleft, CWCursor, &a);
909 a.cursor = ob_cursor(r ? (sh ? OB_CURSOR_EAST : OB_CURSOR_NORTHEAST) :
911 XChangeWindowAttributes(obt_display, self->titleright, CWCursor, &a);
912 XChangeWindowAttributes(obt_display, self->trtresize, CWCursor, &a);
913 XChangeWindowAttributes(obt_display, self->trrresize, CWCursor, &a);
914 XChangeWindowAttributes(obt_display, self->titletopright, CWCursor,&a);
916 /* these ones are pretty static */
917 a.cursor = ob_cursor(r ? OB_CURSOR_WEST : OB_CURSOR_NONE);
918 XChangeWindowAttributes(obt_display, self->left, CWCursor, &a);
919 XChangeWindowAttributes(obt_display, self->innerleft, CWCursor, &a);
920 a.cursor = ob_cursor(r ? OB_CURSOR_EAST : OB_CURSOR_NONE);
921 XChangeWindowAttributes(obt_display, self->right, CWCursor, &a);
922 XChangeWindowAttributes(obt_display, self->innerright, CWCursor, &a);
923 a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHWEST : OB_CURSOR_NONE);
924 XChangeWindowAttributes(obt_display, self->lgrip, CWCursor, &a);
925 XChangeWindowAttributes(obt_display, self->handleleft, CWCursor, &a);
926 XChangeWindowAttributes(obt_display, self->lgripleft, CWCursor, &a);
927 XChangeWindowAttributes(obt_display, self->lgriptop, CWCursor, &a);
928 XChangeWindowAttributes(obt_display, self->lgripbottom, CWCursor, &a);
929 XChangeWindowAttributes(obt_display, self->innerbll, CWCursor, &a);
930 XChangeWindowAttributes(obt_display, self->innerblb, CWCursor, &a);
931 a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHEAST : OB_CURSOR_NONE);
932 XChangeWindowAttributes(obt_display, self->rgrip, CWCursor, &a);
933 XChangeWindowAttributes(obt_display, self->handleright, CWCursor, &a);
934 XChangeWindowAttributes(obt_display, self->rgripright, CWCursor, &a);
935 XChangeWindowAttributes(obt_display, self->rgriptop, CWCursor, &a);
936 XChangeWindowAttributes(obt_display, self->rgripbottom, CWCursor, &a);
937 XChangeWindowAttributes(obt_display, self->innerbrr, CWCursor, &a);
938 XChangeWindowAttributes(obt_display, self->innerbrb, CWCursor, &a);
942 void frame_adjust_client_area(ObFrame *self)
944 /* adjust the window which is there to prevent flashing on unmap */
945 XMoveResizeWindow(obt_display, self->backfront, 0, 0,
946 self->client->area.width,
947 self->client->area.height);
950 void frame_adjust_state(ObFrame *self)
952 self->need_render = TRUE;
953 framerender_frame(self);
956 void frame_adjust_focus(ObFrame *self, gboolean hilite)
958 ob_debug_type(OB_DEBUG_FOCUS,
959 "Frame for 0x%x has focus: %d\n",
960 self->client->window, hilite);
961 self->focused = hilite;
962 self->need_render = TRUE;
963 framerender_frame(self);
967 void frame_adjust_title(ObFrame *self)
969 self->need_render = TRUE;
970 framerender_frame(self);
973 void frame_adjust_icon(ObFrame *self)
975 self->need_render = TRUE;
976 framerender_frame(self);
979 void frame_grab_client(ObFrame *self)
981 /* DO NOT map the client window here. we used to do that, but it is bogus.
982 we need to set up the client's dimensions and everything before we
983 send a mapnotify or we create race conditions.
986 /* reparent the client to the frame */
987 XReparentWindow(obt_display, self->client->window, self->window, 0, 0);
990 When reparenting the client window, it is usually not mapped yet, since
991 this occurs from a MapRequest. However, in the case where Openbox is
992 starting up, the window is already mapped, so we'll see an unmap event
995 if (ob_state() == OB_STATE_STARTING)
996 ++self->client->ignore_unmaps;
998 /* select the event mask on the client's parent (to receive config/map
999 req's) the ButtonPress is to catch clicks on the client border */
1000 XSelectInput(obt_display, self->window, FRAME_EVENTMASK);
1002 /* set all the windows for the frame in the window_map */
1003 window_add(&self->window, CLIENT_AS_WINDOW(self->client));
1004 window_add(&self->backback, CLIENT_AS_WINDOW(self->client));
1005 window_add(&self->backfront, CLIENT_AS_WINDOW(self->client));
1006 window_add(&self->innerleft, CLIENT_AS_WINDOW(self->client));
1007 window_add(&self->innertop, CLIENT_AS_WINDOW(self->client));
1008 window_add(&self->innerright, CLIENT_AS_WINDOW(self->client));
1009 window_add(&self->innerbottom, CLIENT_AS_WINDOW(self->client));
1010 window_add(&self->innerblb, CLIENT_AS_WINDOW(self->client));
1011 window_add(&self->innerbll, CLIENT_AS_WINDOW(self->client));
1012 window_add(&self->innerbrb, CLIENT_AS_WINDOW(self->client));
1013 window_add(&self->innerbrr, CLIENT_AS_WINDOW(self->client));
1014 window_add(&self->title, CLIENT_AS_WINDOW(self->client));
1015 window_add(&self->label, CLIENT_AS_WINDOW(self->client));
1016 window_add(&self->max, CLIENT_AS_WINDOW(self->client));
1017 window_add(&self->close, CLIENT_AS_WINDOW(self->client));
1018 window_add(&self->desk, CLIENT_AS_WINDOW(self->client));
1019 window_add(&self->shade, CLIENT_AS_WINDOW(self->client));
1020 window_add(&self->icon, CLIENT_AS_WINDOW(self->client));
1021 window_add(&self->iconify, CLIENT_AS_WINDOW(self->client));
1022 window_add(&self->handle, CLIENT_AS_WINDOW(self->client));
1023 window_add(&self->lgrip, CLIENT_AS_WINDOW(self->client));
1024 window_add(&self->rgrip, CLIENT_AS_WINDOW(self->client));
1025 window_add(&self->topresize, CLIENT_AS_WINDOW(self->client));
1026 window_add(&self->tltresize, CLIENT_AS_WINDOW(self->client));
1027 window_add(&self->tllresize, CLIENT_AS_WINDOW(self->client));
1028 window_add(&self->trtresize, CLIENT_AS_WINDOW(self->client));
1029 window_add(&self->trrresize, CLIENT_AS_WINDOW(self->client));
1030 window_add(&self->left, CLIENT_AS_WINDOW(self->client));
1031 window_add(&self->right, CLIENT_AS_WINDOW(self->client));
1032 window_add(&self->titleleft, CLIENT_AS_WINDOW(self->client));
1033 window_add(&self->titletop, CLIENT_AS_WINDOW(self->client));
1034 window_add(&self->titletopleft, CLIENT_AS_WINDOW(self->client));
1035 window_add(&self->titletopright, CLIENT_AS_WINDOW(self->client));
1036 window_add(&self->titleright, CLIENT_AS_WINDOW(self->client));
1037 window_add(&self->titlebottom, CLIENT_AS_WINDOW(self->client));
1038 window_add(&self->handleleft, CLIENT_AS_WINDOW(self->client));
1039 window_add(&self->handletop, CLIENT_AS_WINDOW(self->client));
1040 window_add(&self->handleright, CLIENT_AS_WINDOW(self->client));
1041 window_add(&self->handlebottom, CLIENT_AS_WINDOW(self->client));
1042 window_add(&self->lgripleft, CLIENT_AS_WINDOW(self->client));
1043 window_add(&self->lgriptop, CLIENT_AS_WINDOW(self->client));
1044 window_add(&self->lgripbottom, CLIENT_AS_WINDOW(self->client));
1045 window_add(&self->rgripright, CLIENT_AS_WINDOW(self->client));
1046 window_add(&self->rgriptop, CLIENT_AS_WINDOW(self->client));
1047 window_add(&self->rgripbottom, CLIENT_AS_WINDOW(self->client));
1050 static gboolean find_reparent(XEvent *e, gpointer data)
1052 const ObFrame *self = data;
1054 /* Find ReparentNotify events for the window that aren't being reparented into the
1055 frame, thus the client reparenting itself off the frame. */
1056 return e->type == ReparentNotify && e->xreparent.window == self->client->window &&
1057 e->xreparent.parent != self->window;
1060 void frame_release_client(ObFrame *self)
1062 /* if there was any animation going on, kill it */
1063 obt_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
1066 /* check if the app has already reparented its window away */
1067 if (!xqueue_exists_local(find_reparent, self)) {
1068 /* according to the ICCCM - if the client doesn't reparent itself,
1069 then we will reparent the window to root for them */
1070 XReparentWindow(obt_display, self->client->window, obt_root(ob_screen),
1071 self->client->area.x, self->client->area.y);
1074 /* remove all the windows for the frame from the window_map */
1075 window_remove(self->window);
1076 window_remove(self->backback);
1077 window_remove(self->backfront);
1078 window_remove(self->innerleft);
1079 window_remove(self->innertop);
1080 window_remove(self->innerright);
1081 window_remove(self->innerbottom);
1082 window_remove(self->innerblb);
1083 window_remove(self->innerbll);
1084 window_remove(self->innerbrb);
1085 window_remove(self->innerbrr);
1086 window_remove(self->title);
1087 window_remove(self->label);
1088 window_remove(self->max);
1089 window_remove(self->close);
1090 window_remove(self->desk);
1091 window_remove(self->shade);
1092 window_remove(self->icon);
1093 window_remove(self->iconify);
1094 window_remove(self->handle);
1095 window_remove(self->lgrip);
1096 window_remove(self->rgrip);
1097 window_remove(self->topresize);
1098 window_remove(self->tltresize);
1099 window_remove(self->tllresize);
1100 window_remove(self->trtresize);
1101 window_remove(self->trrresize);
1102 window_remove(self->left);
1103 window_remove(self->right);
1104 window_remove(self->titleleft);
1105 window_remove(self->titletop);
1106 window_remove(self->titletopleft);
1107 window_remove(self->titletopright);
1108 window_remove(self->titleright);
1109 window_remove(self->titlebottom);
1110 window_remove(self->handleleft);
1111 window_remove(self->handletop);
1112 window_remove(self->handleright);
1113 window_remove(self->handlebottom);
1114 window_remove(self->lgripleft);
1115 window_remove(self->lgriptop);
1116 window_remove(self->lgripbottom);
1117 window_remove(self->rgripright);
1118 window_remove(self->rgriptop);
1119 window_remove(self->rgripbottom);
1121 obt_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, self, TRUE);
1124 /* is there anything present between us and the label? */
1125 static gboolean is_button_present(ObFrame *self, const gchar *lc, gint dir) {
1126 for (; *lc != '\0' && lc >= config_title_layout; lc += dir) {
1127 if (*lc == ' ') continue; /* it was invalid */
1128 if (*lc == 'N' && self->decorations & OB_FRAME_DECOR_ICON)
1130 if (*lc == 'D' && self->decorations & OB_FRAME_DECOR_ALLDESKTOPS)
1132 if (*lc == 'S' && self->decorations & OB_FRAME_DECOR_SHADE)
1134 if (*lc == 'I' && self->decorations & OB_FRAME_DECOR_ICONIFY)
1136 if (*lc == 'M' && self->decorations & OB_FRAME_DECOR_MAXIMIZE)
1138 if (*lc == 'C' && self->decorations & OB_FRAME_DECOR_CLOSE)
1140 if (*lc == 'L') return FALSE;
1145 static void place_button(ObFrame *self, const char *lc, gint bwidth,
1147 gint *x, gint *button_on, gint *button_x)
1149 if (!(*button_on = is_button_present(self, lc, i)))
1152 self->label_width -= bwidth;
1157 if (self->label_x <= left || *x > self->label_x) {
1160 /* the button would have been drawn on top of another button */
1162 self->label_width += bwidth;
1167 static void layout_title(ObFrame *self)
1172 const gint bwidth = ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
1173 /* position of the leftmost button */
1174 const gint left = ob_rr_theme->paddingx + 1;
1175 /* position of the rightmost button */
1176 const gint right = self->width;
1178 /* turn them all off */
1179 self->icon_on = self->desk_on = self->shade_on = self->iconify_on =
1180 self->max_on = self->close_on = self->label_on = FALSE;
1181 self->label_width = self->width - (ob_rr_theme->paddingx + 1) * 2;
1182 self->leftmost = self->rightmost = OB_FRAME_CONTEXT_NONE;
1184 /* figure out what's being shown, find each element's position, and the
1187 do the ones before the label, then after the label,
1188 i will be +1 the first time through when working to the left,
1189 and -1 the second time through when working to the right */
1190 for (i = 1; i >= -1; i-=2) {
1192 ObFrameContext *firstcon;
1196 lc = config_title_layout;
1197 firstcon = &self->leftmost;
1200 lc = config_title_layout + strlen(config_title_layout)-1;
1201 firstcon = &self->rightmost;
1204 /* stop at the end of the string (or the label, which calls break) */
1205 for (; *lc != '\0' && lc >= config_title_layout; lc+=i) {
1208 self->label_on = TRUE;
1211 break; /* break the for loop, do other side of label */
1212 } else if (*lc == 'N') {
1213 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICON;
1214 /* icon is bigger than buttons */
1215 place_button(self, lc, bwidth + 2, left, i, &x, &self->icon_on, &self->icon_x);
1216 } else if (*lc == 'D') {
1217 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ALLDESKTOPS;
1218 place_button(self, lc, bwidth, left, i, &x, &self->desk_on, &self->desk_x);
1219 } else if (*lc == 'S') {
1220 if (firstcon) *firstcon = OB_FRAME_CONTEXT_SHADE;
1221 place_button(self, lc, bwidth, left, i, &x, &self->shade_on, &self->shade_x);
1222 } else if (*lc == 'I') {
1223 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICONIFY;
1224 place_button(self, lc, bwidth, left, i, &x, &self->iconify_on, &self->iconify_x);
1225 } else if (*lc == 'M') {
1226 if (firstcon) *firstcon = OB_FRAME_CONTEXT_MAXIMIZE;
1227 place_button(self, lc, bwidth, left, i, &x, &self->max_on, &self->max_x);
1228 } else if (*lc == 'C') {
1229 if (firstcon) *firstcon = OB_FRAME_CONTEXT_CLOSE;
1230 place_button(self, lc, bwidth, left, i, &x, &self->close_on, &self->close_x);
1232 continue; /* don't set firstcon */
1237 /* position and map the elements */
1238 if (self->icon_on) {
1239 XMapWindow(obt_display, self->icon);
1240 XMoveWindow(obt_display, self->icon, self->icon_x,
1241 ob_rr_theme->paddingy);
1243 XUnmapWindow(obt_display, self->icon);
1245 if (self->desk_on) {
1246 XMapWindow(obt_display, self->desk);
1247 XMoveWindow(obt_display, self->desk, self->desk_x,
1248 ob_rr_theme->paddingy + 1);
1250 XUnmapWindow(obt_display, self->desk);
1252 if (self->shade_on) {
1253 XMapWindow(obt_display, self->shade);
1254 XMoveWindow(obt_display, self->shade, self->shade_x,
1255 ob_rr_theme->paddingy + 1);
1257 XUnmapWindow(obt_display, self->shade);
1259 if (self->iconify_on) {
1260 XMapWindow(obt_display, self->iconify);
1261 XMoveWindow(obt_display, self->iconify, self->iconify_x,
1262 ob_rr_theme->paddingy + 1);
1264 XUnmapWindow(obt_display, self->iconify);
1267 XMapWindow(obt_display, self->max);
1268 XMoveWindow(obt_display, self->max, self->max_x,
1269 ob_rr_theme->paddingy + 1);
1271 XUnmapWindow(obt_display, self->max);
1273 if (self->close_on) {
1274 XMapWindow(obt_display, self->close);
1275 XMoveWindow(obt_display, self->close, self->close_x,
1276 ob_rr_theme->paddingy + 1);
1278 XUnmapWindow(obt_display, self->close);
1280 if (self->label_on && self->label_width > 0) {
1281 XMapWindow(obt_display, self->label);
1282 XMoveWindow(obt_display, self->label, self->label_x,
1283 ob_rr_theme->paddingy);
1285 XUnmapWindow(obt_display, self->label);
1288 gboolean frame_next_context_from_string(gchar *names, ObFrameContext *cx)
1292 if (!*names) /* empty string */
1295 /* find the first space */
1296 for (p = names; *p; p = g_utf8_next_char(p)) {
1297 const gunichar c = g_utf8_get_char(p);
1298 if (g_unichar_isspace(c)) break;
1302 /* leading spaces in the string */
1303 n = g_utf8_next_char(names);
1304 if (!frame_next_context_from_string(n, cx))
1309 /* delete the space with null zero(s) */
1310 while (n < g_utf8_next_char(p))
1314 *cx = frame_context_from_string(names);
1316 /* find the next non-space */
1317 for (; *n; n = g_utf8_next_char(n)) {
1318 const gunichar c = g_utf8_get_char(n);
1319 if (!g_unichar_isspace(c)) break;
1323 /* delete everything we just read (copy everything at n to the start of
1325 for (p = names; *n; ++p, ++n)
1332 ObFrameContext frame_context_from_string(const gchar *name)
1334 if (!g_ascii_strcasecmp("Desktop", name))
1335 return OB_FRAME_CONTEXT_DESKTOP;
1336 else if (!g_ascii_strcasecmp("Root", name))
1337 return OB_FRAME_CONTEXT_ROOT;
1338 else if (!g_ascii_strcasecmp("Client", name))
1339 return OB_FRAME_CONTEXT_CLIENT;
1340 else if (!g_ascii_strcasecmp("Titlebar", name))
1341 return OB_FRAME_CONTEXT_TITLEBAR;
1342 else if (!g_ascii_strcasecmp("Frame", name))
1343 return OB_FRAME_CONTEXT_FRAME;
1344 else if (!g_ascii_strcasecmp("TLCorner", name))
1345 return OB_FRAME_CONTEXT_TLCORNER;
1346 else if (!g_ascii_strcasecmp("TRCorner", name))
1347 return OB_FRAME_CONTEXT_TRCORNER;
1348 else if (!g_ascii_strcasecmp("BLCorner", name))
1349 return OB_FRAME_CONTEXT_BLCORNER;
1350 else if (!g_ascii_strcasecmp("BRCorner", name))
1351 return OB_FRAME_CONTEXT_BRCORNER;
1352 else if (!g_ascii_strcasecmp("Top", name))
1353 return OB_FRAME_CONTEXT_TOP;
1354 else if (!g_ascii_strcasecmp("Bottom", name))
1355 return OB_FRAME_CONTEXT_BOTTOM;
1356 else if (!g_ascii_strcasecmp("Left", name))
1357 return OB_FRAME_CONTEXT_LEFT;
1358 else if (!g_ascii_strcasecmp("Right", name))
1359 return OB_FRAME_CONTEXT_RIGHT;
1360 else if (!g_ascii_strcasecmp("Maximize", name))
1361 return OB_FRAME_CONTEXT_MAXIMIZE;
1362 else if (!g_ascii_strcasecmp("AllDesktops", name))
1363 return OB_FRAME_CONTEXT_ALLDESKTOPS;
1364 else if (!g_ascii_strcasecmp("Shade", name))
1365 return OB_FRAME_CONTEXT_SHADE;
1366 else if (!g_ascii_strcasecmp("Iconify", name))
1367 return OB_FRAME_CONTEXT_ICONIFY;
1368 else if (!g_ascii_strcasecmp("Icon", name))
1369 return OB_FRAME_CONTEXT_ICON;
1370 else if (!g_ascii_strcasecmp("Close", name))
1371 return OB_FRAME_CONTEXT_CLOSE;
1372 else if (!g_ascii_strcasecmp("MoveResize", name))
1373 return OB_FRAME_CONTEXT_MOVE_RESIZE;
1374 return OB_FRAME_CONTEXT_NONE;
1377 ObFrameContext frame_context(ObClient *client, Window win, gint x, gint y)
1381 if (moveresize_in_progress)
1382 return OB_FRAME_CONTEXT_MOVE_RESIZE;
1384 if (win == obt_root(ob_screen))
1385 return OB_FRAME_CONTEXT_ROOT ;
1386 if (client == NULL) return OB_FRAME_CONTEXT_NONE;
1387 if (win == client->window) {
1388 /* conceptually, this is the desktop, as far as users are
1390 if (client->type == OB_CLIENT_TYPE_DESKTOP)
1391 return OB_FRAME_CONTEXT_DESKTOP;
1392 return OB_FRAME_CONTEXT_CLIENT;
1395 self = client->frame;
1397 /* when the user clicks in the corners of the titlebar and the client
1398 is fully maximized, then treat it like they clicked in the
1399 button that is there */
1400 if (self->max_horz && self->max_vert &&
1401 (win == self->title || win == self->titletop ||
1402 win == self->titleleft || win == self->titletopleft ||
1403 win == self->titleright || win == self->titletopright))
1405 /* get the mouse coords in reference to the whole frame */
1409 /* these windows are down a border width from the top of the frame */
1410 if (win == self->title ||
1411 win == self->titleleft || win == self->titleright)
1414 /* title is a border width in from the edge */
1415 if (win == self->title)
1417 /* titletop is a bit to the right */
1418 else if (win == self->titletop)
1419 fx += ob_rr_theme->grip_width + self->bwidth;
1420 /* titletopright is way to the right edge */
1421 else if (win == self->titletopright)
1422 fx += self->area.width - (ob_rr_theme->grip_width + self->bwidth);
1423 /* titleright is even more way to the right edge */
1424 else if (win == self->titleright)
1425 fx += self->area.width - self->bwidth;
1427 /* figure out if we're over the area that should be considered a
1429 if (fy < self->bwidth + ob_rr_theme->paddingy + 1 +
1430 ob_rr_theme->button_size)
1432 if (fx < (self->bwidth + ob_rr_theme->paddingx + 1 +
1433 ob_rr_theme->button_size))
1435 if (self->leftmost != OB_FRAME_CONTEXT_NONE)
1436 return self->leftmost;
1438 else if (fx >= (self->area.width -
1439 (self->bwidth + ob_rr_theme->paddingx + 1 +
1440 ob_rr_theme->button_size)))
1442 if (self->rightmost != OB_FRAME_CONTEXT_NONE)
1443 return self->rightmost;
1447 /* there is no resizing maximized windows so make them the titlebar
1449 return OB_FRAME_CONTEXT_TITLEBAR;
1451 else if (self->max_vert &&
1452 (win == self->titletop || win == self->topresize))
1453 /* can't resize vertically when max vert */
1454 return OB_FRAME_CONTEXT_TITLEBAR;
1455 else if (self->shaded &&
1456 (win == self->titletop || win == self->topresize))
1457 /* can't resize vertically when shaded */
1458 return OB_FRAME_CONTEXT_TITLEBAR;
1460 if (win == self->window) return OB_FRAME_CONTEXT_FRAME;
1461 if (win == self->label) return OB_FRAME_CONTEXT_TITLEBAR;
1462 if (win == self->handle) return OB_FRAME_CONTEXT_BOTTOM;
1463 if (win == self->handletop) return OB_FRAME_CONTEXT_BOTTOM;
1464 if (win == self->handlebottom) return OB_FRAME_CONTEXT_BOTTOM;
1465 if (win == self->handleleft) return OB_FRAME_CONTEXT_BLCORNER;
1466 if (win == self->lgrip) return OB_FRAME_CONTEXT_BLCORNER;
1467 if (win == self->lgripleft) return OB_FRAME_CONTEXT_BLCORNER;
1468 if (win == self->lgriptop) return OB_FRAME_CONTEXT_BLCORNER;
1469 if (win == self->lgripbottom) return OB_FRAME_CONTEXT_BLCORNER;
1470 if (win == self->handleright) return OB_FRAME_CONTEXT_BRCORNER;
1471 if (win == self->rgrip) return OB_FRAME_CONTEXT_BRCORNER;
1472 if (win == self->rgripright) return OB_FRAME_CONTEXT_BRCORNER;
1473 if (win == self->rgriptop) return OB_FRAME_CONTEXT_BRCORNER;
1474 if (win == self->rgripbottom) return OB_FRAME_CONTEXT_BRCORNER;
1475 if (win == self->title) return OB_FRAME_CONTEXT_TITLEBAR;
1476 if (win == self->titlebottom) return OB_FRAME_CONTEXT_TITLEBAR;
1477 if (win == self->titleleft) return OB_FRAME_CONTEXT_TLCORNER;
1478 if (win == self->titletopleft) return OB_FRAME_CONTEXT_TLCORNER;
1479 if (win == self->titleright) return OB_FRAME_CONTEXT_TRCORNER;
1480 if (win == self->titletopright) return OB_FRAME_CONTEXT_TRCORNER;
1481 if (win == self->titletop) return OB_FRAME_CONTEXT_TOP;
1482 if (win == self->topresize) return OB_FRAME_CONTEXT_TOP;
1483 if (win == self->tltresize) return OB_FRAME_CONTEXT_TLCORNER;
1484 if (win == self->tllresize) return OB_FRAME_CONTEXT_TLCORNER;
1485 if (win == self->trtresize) return OB_FRAME_CONTEXT_TRCORNER;
1486 if (win == self->trrresize) return OB_FRAME_CONTEXT_TRCORNER;
1487 if (win == self->left) return OB_FRAME_CONTEXT_LEFT;
1488 if (win == self->right) return OB_FRAME_CONTEXT_RIGHT;
1489 if (win == self->innertop) return OB_FRAME_CONTEXT_TITLEBAR;
1490 if (win == self->innerleft) return OB_FRAME_CONTEXT_LEFT;
1491 if (win == self->innerbottom) return OB_FRAME_CONTEXT_BOTTOM;
1492 if (win == self->innerright) return OB_FRAME_CONTEXT_RIGHT;
1493 if (win == self->innerbll) return OB_FRAME_CONTEXT_BLCORNER;
1494 if (win == self->innerblb) return OB_FRAME_CONTEXT_BLCORNER;
1495 if (win == self->innerbrr) return OB_FRAME_CONTEXT_BRCORNER;
1496 if (win == self->innerbrb) return OB_FRAME_CONTEXT_BRCORNER;
1497 if (win == self->max) return OB_FRAME_CONTEXT_MAXIMIZE;
1498 if (win == self->iconify) return OB_FRAME_CONTEXT_ICONIFY;
1499 if (win == self->close) return OB_FRAME_CONTEXT_CLOSE;
1500 if (win == self->icon) return OB_FRAME_CONTEXT_ICON;
1501 if (win == self->desk) return OB_FRAME_CONTEXT_ALLDESKTOPS;
1502 if (win == self->shade) return OB_FRAME_CONTEXT_SHADE;
1504 return OB_FRAME_CONTEXT_NONE;
1507 void frame_client_gravity(ObFrame *self, gint *x, gint *y)
1510 switch (self->client->gravity) {
1512 case NorthWestGravity:
1513 case SouthWestGravity:
1520 /* the middle of the client will be the middle of the frame */
1521 *x -= (self->size.right - self->size.left) / 2;
1524 case NorthEastGravity:
1525 case SouthEastGravity:
1527 /* the right side of the client will be the right side of the frame */
1528 *x -= self->size.right + self->size.left -
1529 self->client->border_width * 2;
1534 /* the client's position won't move */
1535 *x -= self->size.left - self->client->border_width;
1540 switch (self->client->gravity) {
1542 case NorthWestGravity:
1543 case NorthEastGravity:
1550 /* the middle of the client will be the middle of the frame */
1551 *y -= (self->size.bottom - self->size.top) / 2;
1554 case SouthWestGravity:
1555 case SouthEastGravity:
1557 /* the bottom of the client will be the bottom of the frame */
1558 *y -= self->size.bottom + self->size.top -
1559 self->client->border_width * 2;
1564 /* the client's position won't move */
1565 *y -= self->size.top - self->client->border_width;
1570 void frame_frame_gravity(ObFrame *self, gint *x, gint *y)
1573 switch (self->client->gravity) {
1575 case NorthWestGravity:
1577 case SouthWestGravity:
1582 /* the middle of the client will be the middle of the frame */
1583 *x += (self->size.right - self->size.left) / 2;
1585 case NorthEastGravity:
1587 case SouthEastGravity:
1588 /* the right side of the client will be the right side of the frame */
1589 *x += self->size.right + self->size.left -
1590 self->client->border_width * 2;
1594 /* the client's position won't move */
1595 *x += self->size.left - self->client->border_width;
1600 switch (self->client->gravity) {
1602 case NorthWestGravity:
1604 case NorthEastGravity:
1609 /* the middle of the client will be the middle of the frame */
1610 *y += (self->size.bottom - self->size.top) / 2;
1612 case SouthWestGravity:
1614 case SouthEastGravity:
1615 /* the bottom of the client will be the bottom of the frame */
1616 *y += self->size.bottom + self->size.top -
1617 self->client->border_width * 2;
1621 /* the client's position won't move */
1622 *y += self->size.top - self->client->border_width;
1627 void frame_rect_to_frame(ObFrame *self, Rect *r)
1629 r->width += self->size.left + self->size.right;
1630 r->height += self->size.top + self->size.bottom;
1631 frame_client_gravity(self, &r->x, &r->y);
1634 void frame_rect_to_client(ObFrame *self, Rect *r)
1636 r->width -= self->size.left + self->size.right;
1637 r->height -= self->size.top + self->size.bottom;
1638 frame_frame_gravity(self, &r->x, &r->y);
1641 static void flash_done(gpointer data)
1643 ObFrame *self = data;
1645 if (self->focused != self->flash_on)
1646 frame_adjust_focus(self, self->focused);
1649 static gboolean flash_timeout(gpointer data)
1651 ObFrame *self = data;
1654 g_get_current_time(&now);
1655 if (now.tv_sec > self->flash_end.tv_sec ||
1656 (now.tv_sec == self->flash_end.tv_sec &&
1657 now.tv_usec >= self->flash_end.tv_usec))
1658 self->flashing = FALSE;
1660 if (!self->flashing)
1661 return FALSE; /* we are done */
1663 self->flash_on = !self->flash_on;
1664 if (!self->focused) {
1665 frame_adjust_focus(self, self->flash_on);
1666 self->focused = FALSE;
1669 return TRUE; /* go again */
1672 void frame_flash_start(ObFrame *self)
1674 self->flash_on = self->focused;
1676 if (!self->flashing)
1677 obt_main_loop_timeout_add(ob_main_loop,
1678 G_USEC_PER_SEC * 0.6,
1683 g_get_current_time(&self->flash_end);
1684 g_time_val_add(&self->flash_end, G_USEC_PER_SEC * 5);
1686 self->flashing = TRUE;
1689 void frame_flash_stop(ObFrame *self)
1691 self->flashing = FALSE;
1694 static gulong frame_animate_iconify_time_left(ObFrame *self,
1695 const GTimeVal *now)
1698 sec = self->iconify_animation_end.tv_sec - now->tv_sec;
1699 usec = self->iconify_animation_end.tv_usec - now->tv_usec;
1701 usec += G_USEC_PER_SEC;
1704 /* no negative values */
1705 return MAX(sec * G_USEC_PER_SEC + usec, 0);
1708 static gboolean frame_animate_iconify(gpointer p)
1712 gint iconx, icony, iconw;
1715 gboolean iconifying;
1717 if (self->client->icon_geometry.width == 0) {
1718 /* there is no icon geometry set so just go straight down */
1721 a = screen_physical_area_monitor(screen_find_monitor(&self->area));
1722 iconx = self->area.x + self->area.width / 2 + 32;
1723 icony = a->y + a->width;
1726 iconx = self->client->icon_geometry.x;
1727 icony = self->client->icon_geometry.y;
1728 iconw = self->client->icon_geometry.width;
1731 iconifying = self->iconify_animation_going > 0;
1733 /* how far do we have left to go ? */
1734 g_get_current_time(&now);
1735 time = frame_animate_iconify_time_left(self, &now);
1737 if ((time > 0 && iconifying) || (time == 0 && !iconifying)) {
1738 /* start where the frame is supposed to be */
1741 w = self->area.width;
1742 h = self->area.height;
1744 /* start at the icon */
1748 h = self->size.top; /* just the titlebar */
1755 dx = self->area.x - iconx;
1756 dy = self->area.y - icony;
1757 dw = self->area.width - self->bwidth * 2 - iconw;
1758 /* if restoring, we move in the opposite direction */
1759 if (!iconifying) { dx = -dx; dy = -dy; dw = -dw; }
1761 elapsed = FRAME_ANIMATE_ICONIFY_TIME - time;
1762 x = x - (dx * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1763 y = y - (dy * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1764 w = w - (dw * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1765 h = self->size.top; /* just the titlebar */
1768 XMoveResizeWindow(obt_display, self->window, x, y, w, h);
1769 XFlush(obt_display);
1772 frame_end_iconify_animation(self);
1774 return time > 0; /* repeat until we're out of time */
1777 void frame_end_iconify_animation(ObFrame *self)
1779 /* see if there is an animation going */
1780 if (self->iconify_animation_going == 0) return;
1783 XUnmapWindow(obt_display, self->window);
1785 /* Send a ConfigureNotify when the animation is done, this fixes
1786 KDE's pager showing the window in the wrong place. since the
1787 window is mapped at a different location and is then moved, we
1788 need to send the synthetic configurenotify, since apps may have
1789 read the position when the client mapped, apparently. */
1790 client_reconfigure(self->client, TRUE);
1793 /* we're not animating any more ! */
1794 self->iconify_animation_going = 0;
1796 XMoveResizeWindow(obt_display, self->window,
1797 self->area.x, self->area.y,
1798 self->area.width, self->area.height);
1799 /* we delay re-rendering until after we're done animating */
1800 framerender_frame(self);
1801 XFlush(obt_display);
1804 void frame_begin_iconify_animation(ObFrame *self, gboolean iconifying)
1807 gboolean new_anim = FALSE;
1808 gboolean set_end = TRUE;
1811 /* if there is no titlebar, just don't animate for now
1812 XXX it would be nice tho.. */
1813 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1816 /* get the current time */
1817 g_get_current_time(&now);
1819 /* get how long until the end */
1820 time = FRAME_ANIMATE_ICONIFY_TIME;
1821 if (self->iconify_animation_going) {
1822 if (!!iconifying != (self->iconify_animation_going > 0)) {
1823 /* animation was already going on in the opposite direction */
1824 time = time - frame_animate_iconify_time_left(self, &now);
1826 /* animation was already going in the same direction */
1830 self->iconify_animation_going = iconifying ? 1 : -1;
1832 /* set the ending time */
1834 self->iconify_animation_end.tv_sec = now.tv_sec;
1835 self->iconify_animation_end.tv_usec = now.tv_usec;
1836 g_time_val_add(&self->iconify_animation_end, time);
1840 obt_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
1842 obt_main_loop_timeout_add(ob_main_loop,
1843 FRAME_ANIMATE_ICONIFY_STEP_TIME,
1844 frame_animate_iconify, self,
1845 g_direct_equal, NULL);
1847 /* do the first step */
1848 frame_animate_iconify(self);
1850 /* show it during the animation even if it is not "visible" */
1852 XMapWindow(obt_display, self->window);