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"
29 #include "moveresize.h"
30 #include "render/theme.h"
32 #define PLATE_EVENTMASK (SubstructureRedirectMask | FocusChangeMask)
33 #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
34 ButtonPressMask | ButtonReleaseMask)
35 #define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \
37 EnterWindowMask | LeaveWindowMask)
38 /* The inner window does not need enter/leave events.
39 If it does get them, then it needs its own context for enter events
40 because sloppy focus will focus the window when you enter the inner window
42 #define INNER_EVENTMASK (ButtonPressMask)
44 #define FRAME_ANIMATE_ICONIFY_STEPS 20
45 #define FRAME_ANIMATE_ICONIFY_TIME (G_USEC_PER_SEC/5)
47 #define FRAME_HANDLE_Y(f) (f->innersize.top + f->client->area.height + \
50 static void layout_title(ObFrame *self);
51 static void flash_done(gpointer data);
52 static gboolean flash_timeout(gpointer data);
54 static void set_theme_statics(ObFrame *self);
55 static void free_theme_statics(ObFrame *self);
56 static gboolean frame_animate_iconify(gpointer self);
58 static Window createWindow(Window parent, Visual *visual,
59 gulong mask, XSetWindowAttributes *attrib)
61 return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
62 (visual ? 32 : RrDepth(ob_rr_inst)), InputOutput,
63 (visual ? visual : RrVisual(ob_rr_inst)),
68 static Visual *check_32bit_client(ObClient *c)
70 XWindowAttributes wattrib;
73 ret = XGetWindowAttributes(ob_display, c->window, &wattrib);
74 g_assert(ret != BadDrawable);
75 g_assert(ret != BadWindow);
77 if (wattrib.depth == 32)
78 return wattrib.visual;
82 ObFrame *frame_new(ObClient *client)
84 XSetWindowAttributes attrib;
89 self = g_new0(ObFrame, 1);
91 visual = check_32bit_client(client);
93 /* create the non-visible decor windows */
97 /* client has a 32-bit visual */
98 mask |= CWColormap | CWBackPixel | CWBorderPixel;
99 /* create a colormap with the visual */
100 self->colormap = attrib.colormap =
101 XCreateColormap(ob_display,
102 RootWindow(ob_display, ob_screen),
104 attrib.background_pixel = BlackPixel(ob_display, 0);
105 attrib.border_pixel = BlackPixel(ob_display, 0);
107 attrib.event_mask = FRAME_EVENTMASK;
108 self->window = createWindow(RootWindow(ob_display, ob_screen), visual,
111 attrib.event_mask = INNER_EVENTMASK;
112 self->inner = createWindow(self->window, visual, mask, &attrib);
114 mask &= ~CWEventMask;
115 self->plate = createWindow(self->inner, visual, mask, &attrib);
117 /* create the visible decor windows */
121 /* client has a 32-bit visual */
122 mask |= CWColormap | CWBackPixel | CWBorderPixel;
123 attrib.colormap = RrColormap(ob_rr_inst);
125 attrib.event_mask = ELEMENT_EVENTMASK;
126 self->title = createWindow(self->window, NULL, mask, &attrib);
129 attrib.cursor = ob_cursor(OB_CURSOR_NORTHWEST);
130 self->tltresize = createWindow(self->title, NULL, mask, &attrib);
131 self->tllresize = createWindow(self->title, NULL, mask, &attrib);
132 attrib.cursor = ob_cursor(OB_CURSOR_NORTHEAST);
133 self->trtresize = createWindow(self->title, NULL, mask, &attrib);
134 self->trrresize = createWindow(self->title, NULL, mask, &attrib);
137 self->label = createWindow(self->title, NULL, mask, &attrib);
138 self->max = createWindow(self->title, NULL, mask, &attrib);
139 self->close = createWindow(self->title, NULL, mask, &attrib);
140 self->desk = createWindow(self->title, NULL, mask, &attrib);
141 self->shade = createWindow(self->title, NULL, mask, &attrib);
142 self->icon = createWindow(self->title, NULL, mask, &attrib);
143 self->iconify = createWindow(self->title, NULL, mask, &attrib);
144 self->handle = createWindow(self->window, NULL, mask, &attrib);
147 attrib.cursor = ob_cursor(OB_CURSOR_SOUTHWEST);
148 self->lgrip = createWindow(self->handle, NULL, mask, &attrib);
149 attrib.cursor = ob_cursor(OB_CURSOR_SOUTHEAST);
150 self->rgrip = createWindow(self->handle, NULL, mask, &attrib);
152 self->focused = FALSE;
154 /* the other stuff is shown based on decor settings */
155 XMapWindow(ob_display, self->plate);
156 XMapWindow(ob_display, self->inner);
157 XMapWindow(ob_display, self->lgrip);
158 XMapWindow(ob_display, self->rgrip);
159 XMapWindow(ob_display, self->label);
161 self->max_press = self->close_press = self->desk_press =
162 self->iconify_press = self->shade_press = FALSE;
163 self->max_hover = self->close_hover = self->desk_hover =
164 self->iconify_hover = self->shade_hover = FALSE;
166 set_theme_statics(self);
168 return (ObFrame*)self;
171 static void set_theme_statics(ObFrame *self)
173 /* set colors/appearance/sizes for stuff that doesn't change */
174 XSetWindowBorder(ob_display, self->window,
175 RrColorPixel(ob_rr_theme->frame_b_color));
176 XSetWindowBorder(ob_display, self->inner,
177 RrColorPixel(ob_rr_theme->frame_b_color));
178 XSetWindowBorder(ob_display, self->title,
179 RrColorPixel(ob_rr_theme->frame_b_color));
180 XSetWindowBorder(ob_display, self->handle,
181 RrColorPixel(ob_rr_theme->frame_b_color));
182 XSetWindowBorder(ob_display, self->rgrip,
183 RrColorPixel(ob_rr_theme->frame_b_color));
184 XSetWindowBorder(ob_display, self->lgrip,
185 RrColorPixel(ob_rr_theme->frame_b_color));
187 XResizeWindow(ob_display, self->max,
188 ob_rr_theme->button_size, ob_rr_theme->button_size);
189 XResizeWindow(ob_display, self->iconify,
190 ob_rr_theme->button_size, ob_rr_theme->button_size);
191 XResizeWindow(ob_display, self->icon,
192 ob_rr_theme->button_size + 2, ob_rr_theme->button_size + 2);
193 XResizeWindow(ob_display, self->close,
194 ob_rr_theme->button_size, ob_rr_theme->button_size);
195 XResizeWindow(ob_display, self->desk,
196 ob_rr_theme->button_size, ob_rr_theme->button_size);
197 XResizeWindow(ob_display, self->shade,
198 ob_rr_theme->button_size, ob_rr_theme->button_size);
199 if (ob_rr_theme->handle_height > 0) {
200 XResizeWindow(ob_display, self->lgrip,
201 ob_rr_theme->grip_width, ob_rr_theme->handle_height);
202 XResizeWindow(ob_display, self->rgrip,
203 ob_rr_theme->grip_width, ob_rr_theme->handle_height);
205 XResizeWindow(ob_display, self->tltresize,
206 ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
207 XResizeWindow(ob_display, self->trtresize,
208 ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
209 XResizeWindow(ob_display, self->tllresize,
210 ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
211 XResizeWindow(ob_display, self->trrresize,
212 ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
214 /* set up the dynamic appearances */
215 self->a_unfocused_title = RrAppearanceCopy(ob_rr_theme->a_unfocused_title);
216 self->a_focused_title = RrAppearanceCopy(ob_rr_theme->a_focused_title);
217 self->a_unfocused_label = RrAppearanceCopy(ob_rr_theme->a_unfocused_label);
218 self->a_focused_label = RrAppearanceCopy(ob_rr_theme->a_focused_label);
219 self->a_unfocused_handle =
220 RrAppearanceCopy(ob_rr_theme->a_unfocused_handle);
221 self->a_focused_handle = RrAppearanceCopy(ob_rr_theme->a_focused_handle);
222 self->a_icon = RrAppearanceCopy(ob_rr_theme->a_icon);
225 static void free_theme_statics(ObFrame *self)
227 RrAppearanceFree(self->a_unfocused_title);
228 RrAppearanceFree(self->a_focused_title);
229 RrAppearanceFree(self->a_unfocused_label);
230 RrAppearanceFree(self->a_focused_label);
231 RrAppearanceFree(self->a_unfocused_handle);
232 RrAppearanceFree(self->a_focused_handle);
233 RrAppearanceFree(self->a_icon);
236 static void frame_free(ObFrame *self)
238 free_theme_statics(self);
240 XDestroyWindow(ob_display, self->window);
242 XFreeColormap(ob_display, self->colormap);
247 void frame_show(ObFrame *self)
249 if (!self->visible) {
250 self->visible = TRUE;
251 XMapWindow(ob_display, self->client->window);
252 XMapWindow(ob_display, self->window);
256 void frame_hide(ObFrame *self)
259 self->visible = FALSE;
260 self->client->ignore_unmaps += 1;
261 /* we unmap the client itself so that we can get MapRequest
262 events, and because the ICCCM tells us to! */
263 XUnmapWindow(ob_display, self->window);
264 XUnmapWindow(ob_display, self->client->window);
268 void frame_adjust_theme(ObFrame *self)
270 free_theme_statics(self);
271 set_theme_statics(self);
274 void frame_adjust_shape(ObFrame *self)
280 if (!self->client->shaped) {
281 /* clear the shape on the frame window */
282 XShapeCombineMask(ob_display, self->window, ShapeBounding,
283 self->innersize.left,
287 /* make the frame's shape match the clients */
288 XShapeCombineShape(ob_display, self->window, ShapeBounding,
289 self->innersize.left,
291 self->client->window,
292 ShapeBounding, ShapeSet);
295 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
296 xrect[0].x = -ob_rr_theme->fbwidth;
297 xrect[0].y = -ob_rr_theme->fbwidth;
298 xrect[0].width = self->width + self->rbwidth * 2;
299 xrect[0].height = ob_rr_theme->title_height +
304 if (self->decorations & OB_FRAME_DECOR_HANDLE) {
305 xrect[1].x = -ob_rr_theme->fbwidth;
306 xrect[1].y = FRAME_HANDLE_Y(self);
307 xrect[1].width = self->width + self->rbwidth * 2;
308 xrect[1].height = ob_rr_theme->handle_height +
313 XShapeCombineRectangles(ob_display, self->window,
314 ShapeBounding, 0, 0, xrect, num,
315 ShapeUnion, Unsorted);
320 void frame_adjust_area(ObFrame *self, gboolean moved,
321 gboolean resized, gboolean fake)
325 oldsize = self->size;
328 self->decorations = self->client->decorations;
329 self->max_horz = self->client->max_horz;
331 if (self->decorations & OB_FRAME_DECOR_BORDER) {
332 self->bwidth = ob_rr_theme->fbwidth;
333 self->cbwidth_x = ob_rr_theme->cbwidthx;
334 self->cbwidth_y = ob_rr_theme->cbwidthy;
336 self->bwidth = self->cbwidth_x = self->cbwidth_y = 0;
338 self->rbwidth = self->bwidth;
341 self->bwidth = self->cbwidth_x = 0;
343 STRUT_SET(self->innersize,
348 self->width = self->client->area.width + self->cbwidth_x * 2 -
349 (self->max_horz ? self->rbwidth * 2 : 0);
350 self->width = MAX(self->width, 1); /* no lower than 1 */
352 /* set border widths */
354 XSetWindowBorderWidth(ob_display, self->window, self->bwidth);
355 XSetWindowBorderWidth(ob_display, self->inner, self->bwidth);
356 XSetWindowBorderWidth(ob_display, self->title, self->rbwidth);
357 XSetWindowBorderWidth(ob_display, self->handle, self->rbwidth);
358 XSetWindowBorderWidth(ob_display, self->lgrip, self->rbwidth);
359 XSetWindowBorderWidth(ob_display, self->rgrip, self->rbwidth);
362 if (self->decorations & OB_FRAME_DECOR_TITLEBAR)
363 self->innersize.top += ob_rr_theme->title_height + self->rbwidth +
364 (self->rbwidth - self->bwidth);
365 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
366 ob_rr_theme->handle_height > 0)
367 self->innersize.bottom += ob_rr_theme->handle_height +
368 self->rbwidth + (self->rbwidth - self->bwidth);
370 /* they all default off, they're turned on in layout_title */
374 self->iconify_x = -1;
379 /* position/size and map/unmap all the windows */
382 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
383 XMoveResizeWindow(ob_display, self->title,
384 -self->bwidth, -self->bwidth,
385 self->width, ob_rr_theme->title_height);
386 XMapWindow(ob_display, self->title);
388 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
389 XMoveWindow(ob_display, self->tltresize, 0, 0);
390 XMoveWindow(ob_display, self->tllresize, 0, 0);
391 XMoveWindow(ob_display, self->trtresize,
392 self->width - ob_rr_theme->grip_width, 0);
393 XMoveWindow(ob_display, self->trrresize,
394 self->width - ob_rr_theme->paddingx - 1, 0);
395 XMapWindow(ob_display, self->tltresize);
396 XMapWindow(ob_display, self->tllresize);
397 XMapWindow(ob_display, self->trtresize);
398 XMapWindow(ob_display, self->trrresize);
400 XUnmapWindow(ob_display, self->tltresize);
401 XUnmapWindow(ob_display, self->tllresize);
402 XUnmapWindow(ob_display, self->trtresize);
403 XUnmapWindow(ob_display, self->trrresize);
406 XUnmapWindow(ob_display, self->title);
409 if (self->decorations & OB_FRAME_DECOR_TITLEBAR)
410 /* layout the title bar elements */
414 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
415 ob_rr_theme->handle_height > 0)
417 XMoveResizeWindow(ob_display, self->handle,
418 -self->bwidth, FRAME_HANDLE_Y(self),
419 self->width, ob_rr_theme->handle_height);
420 XMapWindow(ob_display, self->handle);
422 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
423 XMoveWindow(ob_display, self->lgrip,
424 -self->rbwidth, -self->rbwidth);
425 XMoveWindow(ob_display, self->rgrip,
426 -self->rbwidth + self->width -
427 ob_rr_theme->grip_width, -self->rbwidth);
428 XMapWindow(ob_display, self->lgrip);
429 XMapWindow(ob_display, self->rgrip);
431 XUnmapWindow(ob_display, self->lgrip);
432 XUnmapWindow(ob_display, self->rgrip);
435 XUnmapWindow(ob_display, self->handle);
437 /* move and resize the inner border window which contains the plate
439 XMoveResizeWindow(ob_display, self->inner,
440 self->innersize.left - self->cbwidth_x -
442 self->innersize.top - self->cbwidth_y -
444 self->client->area.width +
446 self->client->area.height +
447 self->cbwidth_y * 2);
450 XMoveWindow(ob_display, self->plate,
451 self->cbwidth_x, self->cbwidth_y);
453 /* when the client has StaticGravity, it likes to move around. */
454 XMoveWindow(ob_display, self->client->window, 0, 0);
457 STRUT_SET(self->size,
458 self->innersize.left + self->bwidth,
459 self->innersize.top + self->bwidth,
460 self->innersize.right + self->bwidth,
461 self->innersize.bottom + self->bwidth);
464 /* shading can change without being moved or resized */
465 RECT_SET_SIZE(self->area,
466 self->client->area.width +
467 self->size.left + self->size.right,
468 (self->client->shaded ?
469 ob_rr_theme->title_height + self->rbwidth * 2:
470 self->client->area.height +
471 self->size.top + self->size.bottom));
473 if (moved || resized) {
474 /* find the new coordinates, done after setting the frame.size, for
475 frame_client_gravity. */
476 self->area.x = self->client->area.x;
477 self->area.y = self->client->area.y;
478 frame_client_gravity(self, &self->area.x, &self->area.y,
479 self->client->area.width,
480 self->client->area.height);
483 if (!fake && !self->iconify_animation_step) {
484 /* move and resize the top level frame.
485 shading can change without being moved or resized.
487 but don't do this during an iconify animation. it will be
488 reflected afterwards.
490 XMoveResizeWindow(ob_display, self->window,
491 self->area.x, self->area.y,
492 self->area.width - self->bwidth * 2,
493 self->area.height - self->bwidth * 2);
496 framerender_frame(self);
497 frame_adjust_shape(self);
500 if (!STRUT_EQUAL(self->size, oldsize)) {
502 vals[0] = self->size.left;
503 vals[1] = self->size.right;
504 vals[2] = self->size.top;
505 vals[3] = self->size.bottom;
506 PROP_SETA32(self->client->window, net_frame_extents,
510 /* if this occurs while we are focus cycling, the indicator needs to
512 if (focus_cycle_target == self->client)
513 focus_cycle_draw_indicator();
515 if (resized && (self->decorations & OB_FRAME_DECOR_TITLEBAR))
516 XResizeWindow(ob_display, self->label, self->label_width,
517 ob_rr_theme->label_height);
520 void frame_adjust_client_area(ObFrame *self)
522 /* resize the plate */
523 XResizeWindow(ob_display, self->plate,
524 self->client->area.width, self->client->area.height);
527 void frame_adjust_state(ObFrame *self)
529 framerender_frame(self);
532 void frame_adjust_focus(ObFrame *self, gboolean hilite)
534 self->focused = hilite;
535 framerender_frame(self);
539 void frame_adjust_title(ObFrame *self)
541 framerender_frame(self);
544 void frame_adjust_icon(ObFrame *self)
546 framerender_frame(self);
549 void frame_grab_client(ObFrame *self, ObClient *client)
551 self->client = client;
553 /* reparent the client to the frame */
554 XReparentWindow(ob_display, client->window, self->plate, 0, 0);
556 When reparenting the client window, it is usually not mapped yet, since
557 this occurs from a MapRequest. However, in the case where Openbox is
558 starting up, the window is already mapped, so we'll see unmap events for
559 it. There are 2 unmap events generated that we see, one with the 'event'
560 member set the root window, and one set to the client, but both get
561 handled and need to be ignored.
563 if (ob_state() == OB_STATE_STARTING)
564 client->ignore_unmaps += 2;
566 /* select the event mask on the client's parent (to receive config/map
567 req's) the ButtonPress is to catch clicks on the client border */
568 XSelectInput(ob_display, self->plate, PLATE_EVENTMASK);
570 frame_adjust_area(self, TRUE, TRUE, FALSE);
572 /* map the client so it maps when the frame does */
573 XMapWindow(ob_display, client->window);
575 /* set all the windows for the frame in the window_map */
576 g_hash_table_insert(window_map, &self->window, client);
577 g_hash_table_insert(window_map, &self->plate, client);
578 g_hash_table_insert(window_map, &self->inner, client);
579 g_hash_table_insert(window_map, &self->title, client);
580 g_hash_table_insert(window_map, &self->label, client);
581 g_hash_table_insert(window_map, &self->max, client);
582 g_hash_table_insert(window_map, &self->close, client);
583 g_hash_table_insert(window_map, &self->desk, client);
584 g_hash_table_insert(window_map, &self->shade, client);
585 g_hash_table_insert(window_map, &self->icon, client);
586 g_hash_table_insert(window_map, &self->iconify, client);
587 g_hash_table_insert(window_map, &self->handle, client);
588 g_hash_table_insert(window_map, &self->lgrip, client);
589 g_hash_table_insert(window_map, &self->rgrip, client);
590 g_hash_table_insert(window_map, &self->tltresize, client);
591 g_hash_table_insert(window_map, &self->tllresize, client);
592 g_hash_table_insert(window_map, &self->trtresize, client);
593 g_hash_table_insert(window_map, &self->trrresize, client);
596 void frame_release_client(ObFrame *self, ObClient *client)
599 gboolean reparent = TRUE;
601 g_assert(self->client == client);
603 /* if there was any animation going on, kill it */
604 ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
607 /* check if the app has already reparented its window away */
608 while (XCheckTypedWindowEvent(ob_display, client->window,
609 ReparentNotify, &ev))
611 /* This check makes sure we don't catch our own reparent action to
612 our frame window. This doesn't count as the app reparenting itself
615 Reparent events that are generated by us are just discarded here.
616 They are of no consequence to us anyhow.
618 if (ev.xreparent.parent != self->plate) {
620 XPutBackEvent(ob_display, &ev);
626 /* according to the ICCCM - if the client doesn't reparent itself,
627 then we will reparent the window to root for them */
628 XReparentWindow(ob_display, client->window,
629 RootWindow(ob_display, ob_screen),
634 /* remove all the windows for the frame from the window_map */
635 g_hash_table_remove(window_map, &self->window);
636 g_hash_table_remove(window_map, &self->plate);
637 g_hash_table_remove(window_map, &self->inner);
638 g_hash_table_remove(window_map, &self->title);
639 g_hash_table_remove(window_map, &self->label);
640 g_hash_table_remove(window_map, &self->max);
641 g_hash_table_remove(window_map, &self->close);
642 g_hash_table_remove(window_map, &self->desk);
643 g_hash_table_remove(window_map, &self->shade);
644 g_hash_table_remove(window_map, &self->icon);
645 g_hash_table_remove(window_map, &self->iconify);
646 g_hash_table_remove(window_map, &self->handle);
647 g_hash_table_remove(window_map, &self->lgrip);
648 g_hash_table_remove(window_map, &self->rgrip);
649 g_hash_table_remove(window_map, &self->tltresize);
650 g_hash_table_remove(window_map, &self->tllresize);
651 g_hash_table_remove(window_map, &self->trtresize);
652 g_hash_table_remove(window_map, &self->trrresize);
654 ob_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, self, TRUE);
659 static void layout_title(ObFrame *self)
663 gboolean n, d, i, l, m, c, s;
665 n = d = i = l = m = c = s = FALSE;
667 /* figure out whats being shown, and the width of the label */
668 self->label_width = self->width - (ob_rr_theme->paddingx + 1) * 2;
669 for (lc = config_title_layout; *lc != '\0'; ++lc) {
672 if (n) { *lc = ' '; break; } /* rm duplicates */
674 self->label_width -= (ob_rr_theme->button_size + 2 +
675 ob_rr_theme->paddingx + 1);
678 if (d) { *lc = ' '; break; }
679 if (!(self->decorations & OB_FRAME_DECOR_ALLDESKTOPS)
680 && config_theme_hidedisabled)
683 self->label_width -= (ob_rr_theme->button_size +
684 ob_rr_theme->paddingx + 1);
687 if (s) { *lc = ' '; break; }
688 if (!(self->decorations & OB_FRAME_DECOR_SHADE)
689 && config_theme_hidedisabled)
692 self->label_width -= (ob_rr_theme->button_size +
693 ob_rr_theme->paddingx + 1);
696 if (i) { *lc = ' '; break; }
697 if (!(self->decorations & OB_FRAME_DECOR_ICONIFY)
698 && config_theme_hidedisabled)
701 self->label_width -= (ob_rr_theme->button_size +
702 ob_rr_theme->paddingx + 1);
705 if (l) { *lc = ' '; break; }
709 if (m) { *lc = ' '; break; }
710 if (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE)
711 && config_theme_hidedisabled)
714 self->label_width -= (ob_rr_theme->button_size +
715 ob_rr_theme->paddingx + 1);
718 if (c) { *lc = ' '; break; }
719 if (!(self->decorations & OB_FRAME_DECOR_CLOSE)
720 && config_theme_hidedisabled)
723 self->label_width -= (ob_rr_theme->button_size +
724 ob_rr_theme->paddingx + 1);
728 if (self->label_width < 1) self->label_width = 1;
730 if (!n) XUnmapWindow(ob_display, self->icon);
731 if (!d) XUnmapWindow(ob_display, self->desk);
732 if (!s) XUnmapWindow(ob_display, self->shade);
733 if (!i) XUnmapWindow(ob_display, self->iconify);
734 if (!l) XUnmapWindow(ob_display, self->label);
735 if (!m) XUnmapWindow(ob_display, self->max);
736 if (!c) XUnmapWindow(ob_display, self->close);
738 x = ob_rr_theme->paddingx + 1;
739 for (lc = config_title_layout; *lc != '\0'; ++lc) {
744 XMapWindow(ob_display, self->icon);
745 XMoveWindow(ob_display, self->icon, x, ob_rr_theme->paddingy);
746 x += ob_rr_theme->button_size + 2 + ob_rr_theme->paddingx + 1;
751 XMapWindow(ob_display, self->desk);
752 XMoveWindow(ob_display, self->desk, x, ob_rr_theme->paddingy + 1);
753 x += ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
758 XMapWindow(ob_display, self->shade);
759 XMoveWindow(ob_display, self->shade, x, ob_rr_theme->paddingy + 1);
760 x += ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
765 XMapWindow(ob_display, self->iconify);
766 XMoveWindow(ob_display,self->iconify, x, ob_rr_theme->paddingy + 1);
767 x += ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
772 XMapWindow(ob_display, self->label);
773 XMoveWindow(ob_display, self->label, x, ob_rr_theme->paddingy);
774 x += self->label_width + ob_rr_theme->paddingx + 1;
779 XMapWindow(ob_display, self->max);
780 XMoveWindow(ob_display, self->max, x, ob_rr_theme->paddingy + 1);
781 x += ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
786 XMapWindow(ob_display, self->close);
787 XMoveWindow(ob_display, self->close, x, ob_rr_theme->paddingy + 1);
788 x += ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
794 ObFrameContext frame_context_from_string(const gchar *name)
796 if (!g_ascii_strcasecmp("Desktop", name))
797 return OB_FRAME_CONTEXT_DESKTOP;
798 else if (!g_ascii_strcasecmp("Client", name))
799 return OB_FRAME_CONTEXT_CLIENT;
800 else if (!g_ascii_strcasecmp("Titlebar", name))
801 return OB_FRAME_CONTEXT_TITLEBAR;
802 else if (!g_ascii_strcasecmp("Handle", name))
803 return OB_FRAME_CONTEXT_HANDLE;
804 else if (!g_ascii_strcasecmp("Frame", name))
805 return OB_FRAME_CONTEXT_FRAME;
806 else if (!g_ascii_strcasecmp("TLCorner", name))
807 return OB_FRAME_CONTEXT_TLCORNER;
808 else if (!g_ascii_strcasecmp("TRCorner", name))
809 return OB_FRAME_CONTEXT_TRCORNER;
810 else if (!g_ascii_strcasecmp("BLCorner", name))
811 return OB_FRAME_CONTEXT_BLCORNER;
812 else if (!g_ascii_strcasecmp("BRCorner", name))
813 return OB_FRAME_CONTEXT_BRCORNER;
814 else if (!g_ascii_strcasecmp("Maximize", name))
815 return OB_FRAME_CONTEXT_MAXIMIZE;
816 else if (!g_ascii_strcasecmp("AllDesktops", name))
817 return OB_FRAME_CONTEXT_ALLDESKTOPS;
818 else if (!g_ascii_strcasecmp("Shade", name))
819 return OB_FRAME_CONTEXT_SHADE;
820 else if (!g_ascii_strcasecmp("Iconify", name))
821 return OB_FRAME_CONTEXT_ICONIFY;
822 else if (!g_ascii_strcasecmp("Icon", name))
823 return OB_FRAME_CONTEXT_ICON;
824 else if (!g_ascii_strcasecmp("Close", name))
825 return OB_FRAME_CONTEXT_CLOSE;
826 else if (!g_ascii_strcasecmp("MoveResize", name))
827 return OB_FRAME_CONTEXT_MOVE_RESIZE;
828 return OB_FRAME_CONTEXT_NONE;
831 ObFrameContext frame_context(ObClient *client, Window win)
835 if (moveresize_in_progress)
836 return OB_FRAME_CONTEXT_MOVE_RESIZE;
838 if (win == RootWindow(ob_display, ob_screen))
839 return OB_FRAME_CONTEXT_DESKTOP;
840 if (client == NULL) return OB_FRAME_CONTEXT_NONE;
841 if (win == client->window) {
842 /* conceptually, this is the desktop, as far as users are
844 if (client->type == OB_CLIENT_TYPE_DESKTOP)
845 return OB_FRAME_CONTEXT_DESKTOP;
846 return OB_FRAME_CONTEXT_CLIENT;
849 self = client->frame;
850 if (win == self->inner || win == self->plate) {
851 /* conceptually, this is the desktop, as far as users are
853 if (client->type == OB_CLIENT_TYPE_DESKTOP)
854 return OB_FRAME_CONTEXT_DESKTOP;
855 return OB_FRAME_CONTEXT_CLIENT;
858 if (win == self->window) return OB_FRAME_CONTEXT_FRAME;
859 if (win == self->title) return OB_FRAME_CONTEXT_TITLEBAR;
860 if (win == self->label) return OB_FRAME_CONTEXT_TITLEBAR;
861 if (win == self->handle) return OB_FRAME_CONTEXT_HANDLE;
862 if (win == self->lgrip) return OB_FRAME_CONTEXT_BLCORNER;
863 if (win == self->rgrip) return OB_FRAME_CONTEXT_BRCORNER;
864 if (win == self->tltresize) return OB_FRAME_CONTEXT_TLCORNER;
865 if (win == self->tllresize) return OB_FRAME_CONTEXT_TLCORNER;
866 if (win == self->trtresize) return OB_FRAME_CONTEXT_TRCORNER;
867 if (win == self->trrresize) return OB_FRAME_CONTEXT_TRCORNER;
868 if (win == self->max) return OB_FRAME_CONTEXT_MAXIMIZE;
869 if (win == self->iconify) return OB_FRAME_CONTEXT_ICONIFY;
870 if (win == self->close) return OB_FRAME_CONTEXT_CLOSE;
871 if (win == self->icon) return OB_FRAME_CONTEXT_ICON;
872 if (win == self->desk) return OB_FRAME_CONTEXT_ALLDESKTOPS;
873 if (win == self->shade) return OB_FRAME_CONTEXT_SHADE;
875 return OB_FRAME_CONTEXT_NONE;
878 void frame_client_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h)
881 switch (self->client->gravity) {
883 case NorthWestGravity:
884 case SouthWestGravity:
891 *x -= (self->size.left + w) / 2;
894 case NorthEastGravity:
895 case SouthEastGravity:
897 *x -= (self->size.left + self->size.right + w) - 1;
902 *x -= self->size.left;
907 switch (self->client->gravity) {
909 case NorthWestGravity:
910 case NorthEastGravity:
917 *y -= (self->size.top + h) / 2;
920 case SouthWestGravity:
921 case SouthEastGravity:
923 *y -= (self->size.top + self->size.bottom + h) - 1;
928 *y -= self->size.top;
933 void frame_frame_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h)
936 switch (self->client->gravity) {
938 case NorthWestGravity:
940 case SouthWestGravity:
945 *x += (self->size.left + w) / 2;
947 case NorthEastGravity:
949 case SouthEastGravity:
950 *x += (self->size.left + self->size.right + w) - 1;
954 *x += self->size.left;
959 switch (self->client->gravity) {
961 case NorthWestGravity:
963 case NorthEastGravity:
968 *y += (self->size.top + h) / 2;
970 case SouthWestGravity:
972 case SouthEastGravity:
973 *y += (self->size.top + self->size.bottom + h) - 1;
977 *y += self->size.top;
982 static void flash_done(gpointer data)
984 ObFrame *self = data;
986 if (self->focused != self->flash_on)
987 frame_adjust_focus(self, self->focused);
990 static gboolean flash_timeout(gpointer data)
992 ObFrame *self = data;
995 g_get_current_time(&now);
996 if (now.tv_sec > self->flash_end.tv_sec ||
997 (now.tv_sec == self->flash_end.tv_sec &&
998 now.tv_usec >= self->flash_end.tv_usec))
999 self->flashing = FALSE;
1001 if (!self->flashing)
1002 return FALSE; /* we are done */
1004 self->flash_on = !self->flash_on;
1005 if (!self->focused) {
1006 frame_adjust_focus(self, self->flash_on);
1007 self->focused = FALSE;
1010 return TRUE; /* go again */
1013 void frame_flash_start(ObFrame *self)
1015 self->flash_on = self->focused;
1017 if (!self->flashing)
1018 ob_main_loop_timeout_add(ob_main_loop,
1019 G_USEC_PER_SEC * 0.6,
1024 g_get_current_time(&self->flash_end);
1025 g_time_val_add(&self->flash_end, G_USEC_PER_SEC * 5);
1027 self->flashing = TRUE;
1030 void frame_flash_stop(ObFrame *self)
1032 self->flashing = FALSE;
1035 static gboolean frame_animate_iconify(gpointer p)
1038 gint step = self->iconify_animation_step;
1039 gint absstep, nextstep;
1041 gint iconx, icony, iconw;
1043 if (self->client->icon_geometry.width == 0) {
1044 /* there is no icon geometry set so just go straight down */
1045 Rect *a = screen_physical_area();
1046 iconx = self->area.x + self->area.width / 2 + 32;
1047 icony = a->y + a->width;
1050 iconx = self->client->icon_geometry.x;
1051 icony = self->client->icon_geometry.y;
1052 iconw = self->client->icon_geometry.width;
1056 absstep = FRAME_ANIMATE_ICONIFY_STEPS - step + 1;
1058 absstep = FRAME_ANIMATE_ICONIFY_STEPS + step + 1;
1061 /* start where the frame is supposed to be */
1064 w = self->area.width - self->bwidth * 2;
1065 h = self->area.height - self->bwidth * 2;
1067 /* start at the icon */
1071 h = self->innersize.top; /* just the titlebar */
1076 dx = self->area.x - iconx;
1077 dy = self->area.y - icony;
1078 dw = self->area.width - self->bwidth * 2 - iconw;
1079 /* if restoring, we move in the opposite direction */
1080 if (step < 0) { dx = -dx; dy = -dy; dw = -dw; }
1081 x = x - dx / FRAME_ANIMATE_ICONIFY_STEPS * absstep;
1082 y = y - dy / FRAME_ANIMATE_ICONIFY_STEPS * absstep;
1083 w = w - dw / FRAME_ANIMATE_ICONIFY_STEPS * absstep;
1084 h = self->innersize.top; /* just the titlebar */
1087 /* move one step forward */
1088 self->iconify_animation_step = step + (step < 0 ? 1 : (step > 0 ? -1 : 0));
1090 /* call the callback when it's done */
1091 if (step == 0 && self->iconify_animation_cb)
1092 self->iconify_animation_cb(self->iconify_animation_data);
1094 /* move to the next spot (after the callback for the animation ending) */
1095 XMoveResizeWindow(ob_display, self->window, x, y, w, h);
1098 return step != 0; /* repeat until step is 0 */
1101 void frame_begin_iconify_animation(ObFrame *self, gboolean iconifying,
1102 ObFrameIconifyAnimateFunc callback,
1106 if (self->iconify_animation_step == 0) /* wasnt doing anything */
1107 self->iconify_animation_step = FRAME_ANIMATE_ICONIFY_STEPS;
1108 else if (self->iconify_animation_step < 0) /* was deiconifying */
1109 self->iconify_animation_step =
1110 FRAME_ANIMATE_ICONIFY_STEPS + self->iconify_animation_step;
1112 if (self->iconify_animation_step == 0) /* wasnt doing anything */
1113 self->iconify_animation_step = -FRAME_ANIMATE_ICONIFY_STEPS;
1114 else if (self->iconify_animation_step > 0) /* was iconifying */
1115 self->iconify_animation_step =
1116 -FRAME_ANIMATE_ICONIFY_STEPS + self->iconify_animation_step;
1118 self->iconify_animation_cb = callback;
1119 self->iconify_animation_data = data;
1121 if (self->iconify_animation_step == FRAME_ANIMATE_ICONIFY_STEPS ||
1122 self->iconify_animation_step == -FRAME_ANIMATE_ICONIFY_STEPS)
1124 ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
1126 ob_main_loop_timeout_add(ob_main_loop,
1127 FRAME_ANIMATE_ICONIFY_TIME /
1128 FRAME_ANIMATE_ICONIFY_STEPS,
1129 frame_animate_iconify, self,
1130 g_direct_equal, NULL);
1131 /* do the first step */
1132 frame_animate_iconify(self);