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/10)
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(ob_main_loop
, frame_animate_iconify
);
606 /* check if the app has already reparented its window away */
607 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
608 ReparentNotify
, &ev
))
610 /* This check makes sure we don't catch our own reparent action to
611 our frame window. This doesn't count as the app reparenting itself
614 Reparent events that are generated by us are just discarded here.
615 They are of no consequence to us anyhow.
617 if (ev
.xreparent
.parent
!= self
->plate
) {
619 XPutBackEvent(ob_display
, &ev
);
625 /* according to the ICCCM - if the client doesn't reparent itself,
626 then we will reparent the window to root for them */
627 XReparentWindow(ob_display
, client
->window
,
628 RootWindow(ob_display
, ob_screen
),
633 /* remove all the windows for the frame from the window_map */
634 g_hash_table_remove(window_map
, &self
->window
);
635 g_hash_table_remove(window_map
, &self
->plate
);
636 g_hash_table_remove(window_map
, &self
->inner
);
637 g_hash_table_remove(window_map
, &self
->title
);
638 g_hash_table_remove(window_map
, &self
->label
);
639 g_hash_table_remove(window_map
, &self
->max
);
640 g_hash_table_remove(window_map
, &self
->close
);
641 g_hash_table_remove(window_map
, &self
->desk
);
642 g_hash_table_remove(window_map
, &self
->shade
);
643 g_hash_table_remove(window_map
, &self
->icon
);
644 g_hash_table_remove(window_map
, &self
->iconify
);
645 g_hash_table_remove(window_map
, &self
->handle
);
646 g_hash_table_remove(window_map
, &self
->lgrip
);
647 g_hash_table_remove(window_map
, &self
->rgrip
);
648 g_hash_table_remove(window_map
, &self
->tltresize
);
649 g_hash_table_remove(window_map
, &self
->tllresize
);
650 g_hash_table_remove(window_map
, &self
->trtresize
);
651 g_hash_table_remove(window_map
, &self
->trrresize
);
653 ob_main_loop_timeout_remove_data(ob_main_loop
, flash_timeout
, self
, TRUE
);
658 static void layout_title(ObFrame
*self
)
662 gboolean n
, d
, i
, l
, m
, c
, s
;
664 n
= d
= i
= l
= m
= c
= s
= FALSE
;
666 /* figure out whats being shown, and the width of the label */
667 self
->label_width
= self
->width
- (ob_rr_theme
->paddingx
+ 1) * 2;
668 for (lc
= config_title_layout
; *lc
!= '\0'; ++lc
) {
671 if (n
) { *lc
= ' '; break; } /* rm duplicates */
673 self
->label_width
-= (ob_rr_theme
->button_size
+ 2 +
674 ob_rr_theme
->paddingx
+ 1);
677 if (d
) { *lc
= ' '; break; }
678 if (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
)
679 && config_theme_hidedisabled
)
682 self
->label_width
-= (ob_rr_theme
->button_size
+
683 ob_rr_theme
->paddingx
+ 1);
686 if (s
) { *lc
= ' '; break; }
687 if (!(self
->decorations
& OB_FRAME_DECOR_SHADE
)
688 && config_theme_hidedisabled
)
691 self
->label_width
-= (ob_rr_theme
->button_size
+
692 ob_rr_theme
->paddingx
+ 1);
695 if (i
) { *lc
= ' '; break; }
696 if (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
)
697 && config_theme_hidedisabled
)
700 self
->label_width
-= (ob_rr_theme
->button_size
+
701 ob_rr_theme
->paddingx
+ 1);
704 if (l
) { *lc
= ' '; break; }
708 if (m
) { *lc
= ' '; break; }
709 if (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
)
710 && config_theme_hidedisabled
)
713 self
->label_width
-= (ob_rr_theme
->button_size
+
714 ob_rr_theme
->paddingx
+ 1);
717 if (c
) { *lc
= ' '; break; }
718 if (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
)
719 && config_theme_hidedisabled
)
722 self
->label_width
-= (ob_rr_theme
->button_size
+
723 ob_rr_theme
->paddingx
+ 1);
727 if (self
->label_width
< 1) self
->label_width
= 1;
729 if (!n
) XUnmapWindow(ob_display
, self
->icon
);
730 if (!d
) XUnmapWindow(ob_display
, self
->desk
);
731 if (!s
) XUnmapWindow(ob_display
, self
->shade
);
732 if (!i
) XUnmapWindow(ob_display
, self
->iconify
);
733 if (!l
) XUnmapWindow(ob_display
, self
->label
);
734 if (!m
) XUnmapWindow(ob_display
, self
->max
);
735 if (!c
) XUnmapWindow(ob_display
, self
->close
);
737 x
= ob_rr_theme
->paddingx
+ 1;
738 for (lc
= config_title_layout
; *lc
!= '\0'; ++lc
) {
743 XMapWindow(ob_display
, self
->icon
);
744 XMoveWindow(ob_display
, self
->icon
, x
, ob_rr_theme
->paddingy
);
745 x
+= ob_rr_theme
->button_size
+ 2 + ob_rr_theme
->paddingx
+ 1;
750 XMapWindow(ob_display
, self
->desk
);
751 XMoveWindow(ob_display
, self
->desk
, x
, ob_rr_theme
->paddingy
+ 1);
752 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
757 XMapWindow(ob_display
, self
->shade
);
758 XMoveWindow(ob_display
, self
->shade
, x
, ob_rr_theme
->paddingy
+ 1);
759 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
764 XMapWindow(ob_display
, self
->iconify
);
765 XMoveWindow(ob_display
,self
->iconify
, x
, ob_rr_theme
->paddingy
+ 1);
766 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
771 XMapWindow(ob_display
, self
->label
);
772 XMoveWindow(ob_display
, self
->label
, x
, ob_rr_theme
->paddingy
);
773 x
+= self
->label_width
+ ob_rr_theme
->paddingx
+ 1;
778 XMapWindow(ob_display
, self
->max
);
779 XMoveWindow(ob_display
, self
->max
, x
, ob_rr_theme
->paddingy
+ 1);
780 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
785 XMapWindow(ob_display
, self
->close
);
786 XMoveWindow(ob_display
, self
->close
, x
, ob_rr_theme
->paddingy
+ 1);
787 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
793 ObFrameContext
frame_context_from_string(const gchar
*name
)
795 if (!g_ascii_strcasecmp("Desktop", name
))
796 return OB_FRAME_CONTEXT_DESKTOP
;
797 else if (!g_ascii_strcasecmp("Client", name
))
798 return OB_FRAME_CONTEXT_CLIENT
;
799 else if (!g_ascii_strcasecmp("Titlebar", name
))
800 return OB_FRAME_CONTEXT_TITLEBAR
;
801 else if (!g_ascii_strcasecmp("Handle", name
))
802 return OB_FRAME_CONTEXT_HANDLE
;
803 else if (!g_ascii_strcasecmp("Frame", name
))
804 return OB_FRAME_CONTEXT_FRAME
;
805 else if (!g_ascii_strcasecmp("TLCorner", name
))
806 return OB_FRAME_CONTEXT_TLCORNER
;
807 else if (!g_ascii_strcasecmp("TRCorner", name
))
808 return OB_FRAME_CONTEXT_TRCORNER
;
809 else if (!g_ascii_strcasecmp("BLCorner", name
))
810 return OB_FRAME_CONTEXT_BLCORNER
;
811 else if (!g_ascii_strcasecmp("BRCorner", name
))
812 return OB_FRAME_CONTEXT_BRCORNER
;
813 else if (!g_ascii_strcasecmp("Maximize", name
))
814 return OB_FRAME_CONTEXT_MAXIMIZE
;
815 else if (!g_ascii_strcasecmp("AllDesktops", name
))
816 return OB_FRAME_CONTEXT_ALLDESKTOPS
;
817 else if (!g_ascii_strcasecmp("Shade", name
))
818 return OB_FRAME_CONTEXT_SHADE
;
819 else if (!g_ascii_strcasecmp("Iconify", name
))
820 return OB_FRAME_CONTEXT_ICONIFY
;
821 else if (!g_ascii_strcasecmp("Icon", name
))
822 return OB_FRAME_CONTEXT_ICON
;
823 else if (!g_ascii_strcasecmp("Close", name
))
824 return OB_FRAME_CONTEXT_CLOSE
;
825 else if (!g_ascii_strcasecmp("MoveResize", name
))
826 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
827 return OB_FRAME_CONTEXT_NONE
;
830 ObFrameContext
frame_context(ObClient
*client
, Window win
)
834 if (moveresize_in_progress
)
835 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
837 if (win
== RootWindow(ob_display
, ob_screen
))
838 return OB_FRAME_CONTEXT_DESKTOP
;
839 if (client
== NULL
) return OB_FRAME_CONTEXT_NONE
;
840 if (win
== client
->window
) {
841 /* conceptually, this is the desktop, as far as users are
843 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
844 return OB_FRAME_CONTEXT_DESKTOP
;
845 return OB_FRAME_CONTEXT_CLIENT
;
848 self
= client
->frame
;
849 if (win
== self
->inner
|| win
== self
->plate
) {
850 /* conceptually, this is the desktop, as far as users are
852 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
853 return OB_FRAME_CONTEXT_DESKTOP
;
854 return OB_FRAME_CONTEXT_CLIENT
;
857 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
858 if (win
== self
->title
) return OB_FRAME_CONTEXT_TITLEBAR
;
859 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
860 if (win
== self
->handle
) return OB_FRAME_CONTEXT_HANDLE
;
861 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
862 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
863 if (win
== self
->tltresize
) return OB_FRAME_CONTEXT_TLCORNER
;
864 if (win
== self
->tllresize
) return OB_FRAME_CONTEXT_TLCORNER
;
865 if (win
== self
->trtresize
) return OB_FRAME_CONTEXT_TRCORNER
;
866 if (win
== self
->trrresize
) return OB_FRAME_CONTEXT_TRCORNER
;
867 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
868 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
869 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
870 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
871 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
872 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
874 return OB_FRAME_CONTEXT_NONE
;
877 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
880 switch (self
->client
->gravity
) {
882 case NorthWestGravity
:
883 case SouthWestGravity
:
890 *x
-= (self
->size
.left
+ w
) / 2;
893 case NorthEastGravity
:
894 case SouthEastGravity
:
896 *x
-= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
901 *x
-= self
->size
.left
;
906 switch (self
->client
->gravity
) {
908 case NorthWestGravity
:
909 case NorthEastGravity
:
916 *y
-= (self
->size
.top
+ h
) / 2;
919 case SouthWestGravity
:
920 case SouthEastGravity
:
922 *y
-= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
927 *y
-= self
->size
.top
;
932 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
935 switch (self
->client
->gravity
) {
937 case NorthWestGravity
:
939 case SouthWestGravity
:
944 *x
+= (self
->size
.left
+ w
) / 2;
946 case NorthEastGravity
:
948 case SouthEastGravity
:
949 *x
+= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
953 *x
+= self
->size
.left
;
958 switch (self
->client
->gravity
) {
960 case NorthWestGravity
:
962 case NorthEastGravity
:
967 *y
+= (self
->size
.top
+ h
) / 2;
969 case SouthWestGravity
:
971 case SouthEastGravity
:
972 *y
+= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
976 *y
+= self
->size
.top
;
981 static void flash_done(gpointer data
)
983 ObFrame
*self
= data
;
985 if (self
->focused
!= self
->flash_on
)
986 frame_adjust_focus(self
, self
->focused
);
989 static gboolean
flash_timeout(gpointer data
)
991 ObFrame
*self
= data
;
994 g_get_current_time(&now
);
995 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
996 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
997 now
.tv_usec
>= self
->flash_end
.tv_usec
))
998 self
->flashing
= FALSE
;
1000 if (!self
->flashing
)
1001 return FALSE
; /* we are done */
1003 self
->flash_on
= !self
->flash_on
;
1004 if (!self
->focused
) {
1005 frame_adjust_focus(self
, self
->flash_on
);
1006 self
->focused
= FALSE
;
1009 return TRUE
; /* go again */
1012 void frame_flash_start(ObFrame
*self
)
1014 self
->flash_on
= self
->focused
;
1016 if (!self
->flashing
)
1017 ob_main_loop_timeout_add(ob_main_loop
,
1018 G_USEC_PER_SEC
* 0.6,
1023 g_get_current_time(&self
->flash_end
);
1024 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
1026 self
->flashing
= TRUE
;
1029 void frame_flash_stop(ObFrame
*self
)
1031 self
->flashing
= FALSE
;
1034 static gboolean
frame_animate_iconify(gpointer p
)
1037 gint step
= self
->iconify_animation_step
;
1038 gint absstep
, nextstep
;
1040 gint iconx
, icony
, iconw
;
1042 if (self
->client
->icon_geometry
.width
== 0) {
1043 /* there is no icon geometry set so just go straight down */
1044 Rect
*a
= screen_physical_area();
1045 iconx
= self
->area
.x
+ self
->area
.width
/ 2 + 32;
1046 icony
= a
->y
+ a
->width
;
1049 iconx
= self
->client
->icon_geometry
.x
;
1050 icony
= self
->client
->icon_geometry
.y
;
1051 iconw
= self
->client
->icon_geometry
.width
;
1055 absstep
= FRAME_ANIMATE_ICONIFY_STEPS
- step
+ 1;
1057 absstep
= FRAME_ANIMATE_ICONIFY_STEPS
+ step
+ 1;
1060 /* start where the frame is supposed to be */
1063 w
= self
->area
.width
- self
->bwidth
* 2;
1064 h
= self
->area
.height
- self
->bwidth
* 2;
1066 /* start at the icon */
1070 h
= self
->innersize
.top
; /* just the titlebar */
1075 dx
= self
->area
.x
- iconx
;
1076 dy
= self
->area
.y
- icony
;
1077 dw
= self
->area
.width
- self
->bwidth
* 2 - iconw
;
1078 /* if restoring, we move in the opposite direction */
1079 if (step
< 0) { dx
= -dx
; dy
= -dy
; dw
= -dw
; }
1080 x
= x
- dx
/ FRAME_ANIMATE_ICONIFY_STEPS
* absstep
;
1081 y
= y
- dy
/ FRAME_ANIMATE_ICONIFY_STEPS
* absstep
;
1082 w
= w
- dw
/ FRAME_ANIMATE_ICONIFY_STEPS
* absstep
;
1083 h
= self
->innersize
.top
; /* just the titlebar */
1086 /* move one step forward */
1087 self
->iconify_animation_step
= step
+ (step
< 0 ? 1 : (step
> 0 ? -1 : 0));
1089 /* call the callback when it's done */
1090 if (step
== 0 && self
->iconify_animation_cb
)
1091 self
->iconify_animation_cb(self
->iconify_animation_data
);
1093 /* move to the next spot (after the callback for the animation ending) */
1094 XMoveResizeWindow(ob_display
, self
->window
, x
, y
, w
, h
);
1097 return step
!= 0; /* repeat until step is 0 */
1100 void frame_begin_iconify_animation(ObFrame
*self
, gboolean iconifying
,
1101 ObFrameIconifyAnimateFunc callback
,
1105 if (self
->iconify_animation_step
== 0) /* wasnt doing anything */
1106 self
->iconify_animation_step
= FRAME_ANIMATE_ICONIFY_STEPS
;
1107 else if (self
->iconify_animation_step
< 0) /* was deiconifying */
1108 self
->iconify_animation_step
=
1109 FRAME_ANIMATE_ICONIFY_STEPS
+ self
->iconify_animation_step
;
1111 if (self
->iconify_animation_step
== 0) /* wasnt doing anything */
1112 self
->iconify_animation_step
= -FRAME_ANIMATE_ICONIFY_STEPS
;
1113 else if (self
->iconify_animation_step
> 0) /* was iconifying */
1114 self
->iconify_animation_step
=
1115 -FRAME_ANIMATE_ICONIFY_STEPS
+ self
->iconify_animation_step
;
1117 self
->iconify_animation_cb
= callback
;
1118 self
->iconify_animation_data
= data
;
1120 if (self
->iconify_animation_step
== FRAME_ANIMATE_ICONIFY_STEPS
||
1121 self
->iconify_animation_step
== -FRAME_ANIMATE_ICONIFY_STEPS
)
1123 ob_main_loop_timeout_remove(ob_main_loop
, frame_animate_iconify
);
1124 ob_main_loop_timeout_add(ob_main_loop
,
1125 FRAME_ANIMATE_ICONIFY_TIME
/
1126 FRAME_ANIMATE_ICONIFY_STEPS
,
1127 frame_animate_iconify
, self
,
1128 g_direct_equal
, NULL
);
1129 /* do the first step */
1130 frame_animate_iconify(self
);