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"
31 #include "render/theme.h"
33 #define PLATE_EVENTMASK (SubstructureRedirectMask | FocusChangeMask)
34 #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
35 ButtonPressMask | ButtonReleaseMask)
36 #define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \
38 EnterWindowMask | LeaveWindowMask)
39 /* The inner window does not need enter/leave events.
40 If it does get them, then it needs its own context for enter events
41 because sloppy focus will focus the window when you enter the inner window
43 #define INNER_EVENTMASK (ButtonPressMask)
45 #define FRAME_ANIMATE_ICONIFY_TIME 150000 /* .15 seconds */
46 #define FRAME_ANIMATE_ICONIFY_STEP_TIME (G_USEC_PER_SEC / 60) /* 60 Hz */
48 #define FRAME_HANDLE_Y(f) (f->innersize.top + f->client->area.height + \
51 static void layout_title(ObFrame
*self
);
52 static void flash_done(gpointer data
);
53 static gboolean
flash_timeout(gpointer data
);
55 static void set_theme_statics(ObFrame
*self
);
56 static void free_theme_statics(ObFrame
*self
);
57 static gboolean
frame_animate_iconify(gpointer self
);
59 static Window
createWindow(Window parent
, Visual
*visual
,
60 gulong mask
, XSetWindowAttributes
*attrib
)
62 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
63 (visual
? 32 : RrDepth(ob_rr_inst
)), InputOutput
,
64 (visual
? visual
: RrVisual(ob_rr_inst
)),
69 static Visual
*check_32bit_client(ObClient
*c
)
71 XWindowAttributes wattrib
;
74 ret
= XGetWindowAttributes(ob_display
, c
->window
, &wattrib
);
75 g_assert(ret
!= BadDrawable
);
76 g_assert(ret
!= BadWindow
);
78 if (wattrib
.depth
== 32)
79 return wattrib
.visual
;
83 ObFrame
*frame_new(ObClient
*client
)
85 XSetWindowAttributes attrib
;
90 self
= g_new0(ObFrame
, 1);
92 visual
= check_32bit_client(client
);
94 /* create the non-visible decor windows */
98 /* client has a 32-bit visual */
99 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
100 /* create a colormap with the visual */
101 self
->colormap
= attrib
.colormap
=
102 XCreateColormap(ob_display
,
103 RootWindow(ob_display
, ob_screen
),
105 attrib
.background_pixel
= BlackPixel(ob_display
, 0);
106 attrib
.border_pixel
= BlackPixel(ob_display
, 0);
108 attrib
.event_mask
= FRAME_EVENTMASK
;
109 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
), visual
,
112 attrib
.event_mask
= INNER_EVENTMASK
;
113 self
->inner
= createWindow(self
->window
, visual
, mask
, &attrib
);
115 mask
&= ~CWEventMask
;
116 self
->plate
= createWindow(self
->inner
, visual
, mask
, &attrib
);
118 /* create the visible decor windows */
122 /* client has a 32-bit visual */
123 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
124 attrib
.colormap
= RrColormap(ob_rr_inst
);
126 attrib
.event_mask
= ELEMENT_EVENTMASK
;
127 self
->title
= createWindow(self
->window
, NULL
, mask
, &attrib
);
130 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHWEST
);
131 self
->tltresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
132 self
->tllresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
133 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHEAST
);
134 self
->trtresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
135 self
->trrresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
138 self
->label
= createWindow(self
->title
, NULL
, mask
, &attrib
);
139 self
->max
= createWindow(self
->title
, NULL
, mask
, &attrib
);
140 self
->close
= createWindow(self
->title
, NULL
, mask
, &attrib
);
141 self
->desk
= createWindow(self
->title
, NULL
, mask
, &attrib
);
142 self
->shade
= createWindow(self
->title
, NULL
, mask
, &attrib
);
143 self
->icon
= createWindow(self
->title
, NULL
, mask
, &attrib
);
144 self
->iconify
= createWindow(self
->title
, NULL
, mask
, &attrib
);
145 self
->handle
= createWindow(self
->window
, NULL
, mask
, &attrib
);
148 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHWEST
);
149 self
->lgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
150 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHEAST
);
151 self
->rgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
153 self
->focused
= FALSE
;
155 /* the other stuff is shown based on decor settings */
156 XMapWindow(ob_display
, self
->plate
);
157 XMapWindow(ob_display
, self
->inner
);
158 XMapWindow(ob_display
, self
->lgrip
);
159 XMapWindow(ob_display
, self
->rgrip
);
160 XMapWindow(ob_display
, self
->label
);
162 self
->max_press
= self
->close_press
= self
->desk_press
=
163 self
->iconify_press
= self
->shade_press
= FALSE
;
164 self
->max_hover
= self
->close_hover
= self
->desk_hover
=
165 self
->iconify_hover
= self
->shade_hover
= FALSE
;
167 set_theme_statics(self
);
169 return (ObFrame
*)self
;
172 static void set_theme_statics(ObFrame
*self
)
174 /* set colors/appearance/sizes for stuff that doesn't change */
175 XSetWindowBorder(ob_display
, self
->window
,
176 RrColorPixel(ob_rr_theme
->frame_b_color
));
177 XSetWindowBorder(ob_display
, self
->inner
,
178 RrColorPixel(ob_rr_theme
->frame_b_color
));
179 XSetWindowBorder(ob_display
, self
->title
,
180 RrColorPixel(ob_rr_theme
->frame_b_color
));
181 XSetWindowBorder(ob_display
, self
->handle
,
182 RrColorPixel(ob_rr_theme
->frame_b_color
));
183 XSetWindowBorder(ob_display
, self
->rgrip
,
184 RrColorPixel(ob_rr_theme
->frame_b_color
));
185 XSetWindowBorder(ob_display
, self
->lgrip
,
186 RrColorPixel(ob_rr_theme
->frame_b_color
));
188 XResizeWindow(ob_display
, self
->max
,
189 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
190 XResizeWindow(ob_display
, self
->iconify
,
191 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
192 XResizeWindow(ob_display
, self
->icon
,
193 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
194 XResizeWindow(ob_display
, self
->close
,
195 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
196 XResizeWindow(ob_display
, self
->desk
,
197 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
198 XResizeWindow(ob_display
, self
->shade
,
199 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
200 if (ob_rr_theme
->handle_height
> 0) {
201 XResizeWindow(ob_display
, self
->lgrip
,
202 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
203 XResizeWindow(ob_display
, self
->rgrip
,
204 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
206 XResizeWindow(ob_display
, self
->tltresize
,
207 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
208 XResizeWindow(ob_display
, self
->trtresize
,
209 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
210 XResizeWindow(ob_display
, self
->tllresize
,
211 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
212 XResizeWindow(ob_display
, self
->trrresize
,
213 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
215 /* set up the dynamic appearances */
216 self
->a_unfocused_title
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_title
);
217 self
->a_focused_title
= RrAppearanceCopy(ob_rr_theme
->a_focused_title
);
218 self
->a_unfocused_label
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_label
);
219 self
->a_focused_label
= RrAppearanceCopy(ob_rr_theme
->a_focused_label
);
220 self
->a_unfocused_handle
=
221 RrAppearanceCopy(ob_rr_theme
->a_unfocused_handle
);
222 self
->a_focused_handle
= RrAppearanceCopy(ob_rr_theme
->a_focused_handle
);
223 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_icon
);
226 static void free_theme_statics(ObFrame
*self
)
228 RrAppearanceFree(self
->a_unfocused_title
);
229 RrAppearanceFree(self
->a_focused_title
);
230 RrAppearanceFree(self
->a_unfocused_label
);
231 RrAppearanceFree(self
->a_focused_label
);
232 RrAppearanceFree(self
->a_unfocused_handle
);
233 RrAppearanceFree(self
->a_focused_handle
);
234 RrAppearanceFree(self
->a_icon
);
237 static void frame_free(ObFrame
*self
)
239 free_theme_statics(self
);
241 XDestroyWindow(ob_display
, self
->window
);
243 XFreeColormap(ob_display
, self
->colormap
);
248 void frame_show(ObFrame
*self
)
250 if (!self
->visible
) {
251 self
->visible
= TRUE
;
252 XMapWindow(ob_display
, self
->client
->window
);
253 XMapWindow(ob_display
, self
->window
);
257 void frame_hide(ObFrame
*self
)
260 self
->visible
= FALSE
;
261 if (!frame_iconify_animating(self
))
262 XUnmapWindow(ob_display
, self
->window
);
263 /* we unmap the client itself so that we can get MapRequest
264 events, and because the ICCCM tells us to! */
265 XUnmapWindow(ob_display
, self
->client
->window
);
266 self
->client
->ignore_unmaps
+= 1;
270 void frame_adjust_theme(ObFrame
*self
)
272 free_theme_statics(self
);
273 set_theme_statics(self
);
276 void frame_adjust_shape(ObFrame
*self
)
282 if (!self
->client
->shaped
) {
283 /* clear the shape on the frame window */
284 XShapeCombineMask(ob_display
, self
->window
, ShapeBounding
,
285 self
->innersize
.left
,
289 /* make the frame's shape match the clients */
290 XShapeCombineShape(ob_display
, self
->window
, ShapeBounding
,
291 self
->innersize
.left
,
293 self
->client
->window
,
294 ShapeBounding
, ShapeSet
);
297 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
298 xrect
[0].x
= -ob_rr_theme
->fbwidth
;
299 xrect
[0].y
= -ob_rr_theme
->fbwidth
;
300 xrect
[0].width
= self
->width
+ self
->rbwidth
* 2;
301 xrect
[0].height
= ob_rr_theme
->title_height
+
306 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
) {
307 xrect
[1].x
= -ob_rr_theme
->fbwidth
;
308 xrect
[1].y
= FRAME_HANDLE_Y(self
);
309 xrect
[1].width
= self
->width
+ self
->rbwidth
* 2;
310 xrect
[1].height
= ob_rr_theme
->handle_height
+
315 XShapeCombineRectangles(ob_display
, self
->window
,
316 ShapeBounding
, 0, 0, xrect
, num
,
317 ShapeUnion
, Unsorted
);
322 void frame_adjust_area(ObFrame
*self
, gboolean moved
,
323 gboolean resized
, gboolean fake
)
327 oldsize
= self
->size
;
330 self
->decorations
= self
->client
->decorations
;
331 self
->max_horz
= self
->client
->max_horz
;
333 if (self
->decorations
& OB_FRAME_DECOR_BORDER
) {
334 self
->bwidth
= ob_rr_theme
->fbwidth
;
335 self
->cbwidth_x
= ob_rr_theme
->cbwidthx
;
336 self
->cbwidth_y
= ob_rr_theme
->cbwidthy
;
338 self
->bwidth
= self
->cbwidth_x
= self
->cbwidth_y
= 0;
340 self
->rbwidth
= self
->bwidth
;
343 self
->bwidth
= self
->cbwidth_x
= 0;
345 STRUT_SET(self
->innersize
,
350 self
->width
= self
->client
->area
.width
+ self
->cbwidth_x
* 2 -
351 (self
->max_horz
? self
->rbwidth
* 2 : 0);
352 self
->width
= MAX(self
->width
, 1); /* no lower than 1 */
354 /* set border widths */
356 XSetWindowBorderWidth(ob_display
, self
->window
, self
->bwidth
);
357 XSetWindowBorderWidth(ob_display
, self
->inner
, self
->bwidth
);
358 XSetWindowBorderWidth(ob_display
, self
->title
, self
->rbwidth
);
359 XSetWindowBorderWidth(ob_display
, self
->handle
, self
->rbwidth
);
360 XSetWindowBorderWidth(ob_display
, self
->lgrip
, self
->rbwidth
);
361 XSetWindowBorderWidth(ob_display
, self
->rgrip
, self
->rbwidth
);
364 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
365 self
->innersize
.top
+= ob_rr_theme
->title_height
+ self
->rbwidth
+
366 (self
->rbwidth
- self
->bwidth
);
367 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
368 ob_rr_theme
->handle_height
> 0)
369 self
->innersize
.bottom
+= ob_rr_theme
->handle_height
+
370 self
->rbwidth
+ (self
->rbwidth
- self
->bwidth
);
372 /* they all default off, they're turned on in layout_title */
376 self
->iconify_x
= -1;
381 /* position/size and map/unmap all the windows */
384 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
385 XMoveResizeWindow(ob_display
, self
->title
,
386 -self
->bwidth
, -self
->bwidth
,
387 self
->width
, ob_rr_theme
->title_height
);
388 XMapWindow(ob_display
, self
->title
);
390 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
391 XMoveWindow(ob_display
, self
->tltresize
, 0, 0);
392 XMoveWindow(ob_display
, self
->tllresize
, 0, 0);
393 XMoveWindow(ob_display
, self
->trtresize
,
394 self
->width
- ob_rr_theme
->grip_width
, 0);
395 XMoveWindow(ob_display
, self
->trrresize
,
396 self
->width
- ob_rr_theme
->paddingx
- 1, 0);
397 XMapWindow(ob_display
, self
->tltresize
);
398 XMapWindow(ob_display
, self
->tllresize
);
399 XMapWindow(ob_display
, self
->trtresize
);
400 XMapWindow(ob_display
, self
->trrresize
);
402 XUnmapWindow(ob_display
, self
->tltresize
);
403 XUnmapWindow(ob_display
, self
->tllresize
);
404 XUnmapWindow(ob_display
, self
->trtresize
);
405 XUnmapWindow(ob_display
, self
->trrresize
);
408 XUnmapWindow(ob_display
, self
->title
);
411 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
412 /* layout the title bar elements */
416 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
417 ob_rr_theme
->handle_height
> 0)
419 XMoveResizeWindow(ob_display
, self
->handle
,
420 -self
->bwidth
, FRAME_HANDLE_Y(self
),
421 self
->width
, ob_rr_theme
->handle_height
);
422 XMapWindow(ob_display
, self
->handle
);
424 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
425 XMoveWindow(ob_display
, self
->lgrip
,
426 -self
->rbwidth
, -self
->rbwidth
);
427 XMoveWindow(ob_display
, self
->rgrip
,
428 -self
->rbwidth
+ self
->width
-
429 ob_rr_theme
->grip_width
, -self
->rbwidth
);
430 XMapWindow(ob_display
, self
->lgrip
);
431 XMapWindow(ob_display
, self
->rgrip
);
433 XUnmapWindow(ob_display
, self
->lgrip
);
434 XUnmapWindow(ob_display
, self
->rgrip
);
437 XUnmapWindow(ob_display
, self
->handle
);
439 /* move and resize the inner border window which contains the plate
441 XMoveResizeWindow(ob_display
, self
->inner
,
442 self
->innersize
.left
- self
->cbwidth_x
-
444 self
->innersize
.top
- self
->cbwidth_y
-
446 self
->client
->area
.width
+
448 self
->client
->area
.height
+
449 self
->cbwidth_y
* 2);
452 XMoveWindow(ob_display
, self
->plate
,
453 self
->cbwidth_x
, self
->cbwidth_y
);
455 /* when the client has StaticGravity, it likes to move around. */
456 XMoveWindow(ob_display
, self
->client
->window
, 0, 0);
459 STRUT_SET(self
->size
,
460 self
->innersize
.left
+ self
->bwidth
,
461 self
->innersize
.top
+ self
->bwidth
,
462 self
->innersize
.right
+ self
->bwidth
,
463 self
->innersize
.bottom
+ self
->bwidth
);
466 /* shading can change without being moved or resized */
467 RECT_SET_SIZE(self
->area
,
468 self
->client
->area
.width
+
469 self
->size
.left
+ self
->size
.right
,
470 (self
->client
->shaded
?
471 ob_rr_theme
->title_height
+ self
->rbwidth
* 2:
472 self
->client
->area
.height
+
473 self
->size
.top
+ self
->size
.bottom
));
475 if (moved
|| resized
) {
476 /* find the new coordinates, done after setting the frame.size, for
477 frame_client_gravity. */
478 self
->area
.x
= self
->client
->area
.x
;
479 self
->area
.y
= self
->client
->area
.y
;
480 frame_client_gravity(self
, &self
->area
.x
, &self
->area
.y
,
481 self
->client
->area
.width
,
482 self
->client
->area
.height
);
486 if (!frame_iconify_animating(self
))
487 /* move and resize the top level frame.
488 shading can change without being moved or resized.
490 but don't do this during an iconify animation. it will be
491 reflected afterwards.
493 XMoveResizeWindow(ob_display
, self
->window
,
494 self
->area
.x
, self
->area
.y
,
495 self
->area
.width
- self
->bwidth
* 2,
496 self
->area
.height
- self
->bwidth
* 2);
499 framerender_frame(self
);
500 frame_adjust_shape(self
);
503 if (!STRUT_EQUAL(self
->size
, oldsize
)) {
505 vals
[0] = self
->size
.left
;
506 vals
[1] = self
->size
.right
;
507 vals
[2] = self
->size
.top
;
508 vals
[3] = self
->size
.bottom
;
509 PROP_SETA32(self
->client
->window
, net_frame_extents
,
511 PROP_SETA32(self
->client
->window
, kde_net_wm_frame_strut
,
515 /* if this occurs while we are focus cycling, the indicator needs to
517 if (focus_cycle_target
== self
->client
)
518 focus_cycle_draw_indicator();
520 if (resized
&& (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
521 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
522 ob_rr_theme
->label_height
);
525 void frame_adjust_client_area(ObFrame
*self
)
527 /* resize the plate */
528 XResizeWindow(ob_display
, self
->plate
,
529 self
->client
->area
.width
, self
->client
->area
.height
);
532 void frame_adjust_state(ObFrame
*self
)
534 framerender_frame(self
);
537 void frame_adjust_focus(ObFrame
*self
, gboolean hilite
)
539 self
->focused
= hilite
;
540 framerender_frame(self
);
544 void frame_adjust_title(ObFrame
*self
)
546 framerender_frame(self
);
549 void frame_adjust_icon(ObFrame
*self
)
551 framerender_frame(self
);
554 void frame_grab_client(ObFrame
*self
, ObClient
*client
)
556 self
->client
= client
;
558 /* reparent the client to the frame */
559 XReparentWindow(ob_display
, client
->window
, self
->plate
, 0, 0);
561 When reparenting the client window, it is usually not mapped yet, since
562 this occurs from a MapRequest. However, in the case where Openbox is
563 starting up, the window is already mapped, so we'll see unmap events for
564 it. There are 2 unmap events generated that we see, one with the 'event'
565 member set the root window, and one set to the client, but both get
566 handled and need to be ignored.
568 if (ob_state() == OB_STATE_STARTING
)
569 client
->ignore_unmaps
+= 2;
571 /* select the event mask on the client's parent (to receive config/map
572 req's) the ButtonPress is to catch clicks on the client border */
573 XSelectInput(ob_display
, self
->plate
, PLATE_EVENTMASK
);
575 frame_adjust_area(self
, TRUE
, TRUE
, FALSE
);
577 /* map the client so it maps when the frame does */
578 XMapWindow(ob_display
, client
->window
);
580 /* set all the windows for the frame in the window_map */
581 g_hash_table_insert(window_map
, &self
->window
, client
);
582 g_hash_table_insert(window_map
, &self
->plate
, client
);
583 g_hash_table_insert(window_map
, &self
->inner
, client
);
584 g_hash_table_insert(window_map
, &self
->title
, client
);
585 g_hash_table_insert(window_map
, &self
->label
, client
);
586 g_hash_table_insert(window_map
, &self
->max
, client
);
587 g_hash_table_insert(window_map
, &self
->close
, client
);
588 g_hash_table_insert(window_map
, &self
->desk
, client
);
589 g_hash_table_insert(window_map
, &self
->shade
, client
);
590 g_hash_table_insert(window_map
, &self
->icon
, client
);
591 g_hash_table_insert(window_map
, &self
->iconify
, client
);
592 g_hash_table_insert(window_map
, &self
->handle
, client
);
593 g_hash_table_insert(window_map
, &self
->lgrip
, client
);
594 g_hash_table_insert(window_map
, &self
->rgrip
, client
);
595 g_hash_table_insert(window_map
, &self
->tltresize
, client
);
596 g_hash_table_insert(window_map
, &self
->tllresize
, client
);
597 g_hash_table_insert(window_map
, &self
->trtresize
, client
);
598 g_hash_table_insert(window_map
, &self
->trrresize
, client
);
601 void frame_release_client(ObFrame
*self
, ObClient
*client
)
604 gboolean reparent
= TRUE
;
606 g_assert(self
->client
== client
);
608 /* if there was any animation going on, kill it */
609 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
612 /* check if the app has already reparented its window away */
613 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
614 ReparentNotify
, &ev
))
616 /* This check makes sure we don't catch our own reparent action to
617 our frame window. This doesn't count as the app reparenting itself
620 Reparent events that are generated by us are just discarded here.
621 They are of no consequence to us anyhow.
623 if (ev
.xreparent
.parent
!= self
->plate
) {
625 XPutBackEvent(ob_display
, &ev
);
631 /* according to the ICCCM - if the client doesn't reparent itself,
632 then we will reparent the window to root for them */
633 XReparentWindow(ob_display
, client
->window
,
634 RootWindow(ob_display
, ob_screen
),
639 /* remove all the windows for the frame from the window_map */
640 g_hash_table_remove(window_map
, &self
->window
);
641 g_hash_table_remove(window_map
, &self
->plate
);
642 g_hash_table_remove(window_map
, &self
->inner
);
643 g_hash_table_remove(window_map
, &self
->title
);
644 g_hash_table_remove(window_map
, &self
->label
);
645 g_hash_table_remove(window_map
, &self
->max
);
646 g_hash_table_remove(window_map
, &self
->close
);
647 g_hash_table_remove(window_map
, &self
->desk
);
648 g_hash_table_remove(window_map
, &self
->shade
);
649 g_hash_table_remove(window_map
, &self
->icon
);
650 g_hash_table_remove(window_map
, &self
->iconify
);
651 g_hash_table_remove(window_map
, &self
->handle
);
652 g_hash_table_remove(window_map
, &self
->lgrip
);
653 g_hash_table_remove(window_map
, &self
->rgrip
);
654 g_hash_table_remove(window_map
, &self
->tltresize
);
655 g_hash_table_remove(window_map
, &self
->tllresize
);
656 g_hash_table_remove(window_map
, &self
->trtresize
);
657 g_hash_table_remove(window_map
, &self
->trrresize
);
659 ob_main_loop_timeout_remove_data(ob_main_loop
, flash_timeout
, self
, TRUE
);
664 static void layout_title(ObFrame
*self
)
668 gboolean n
, d
, i
, l
, m
, c
, s
;
670 n
= d
= i
= l
= m
= c
= s
= FALSE
;
672 /* figure out whats being shown, and the width of the label */
673 self
->label_width
= self
->width
- (ob_rr_theme
->paddingx
+ 1) * 2;
674 for (lc
= config_title_layout
; *lc
!= '\0'; ++lc
) {
677 if (n
) { *lc
= ' '; break; } /* rm duplicates */
679 self
->label_width
-= (ob_rr_theme
->button_size
+ 2 +
680 ob_rr_theme
->paddingx
+ 1);
683 if (d
) { *lc
= ' '; break; }
684 if (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
)
685 && config_theme_hidedisabled
)
688 self
->label_width
-= (ob_rr_theme
->button_size
+
689 ob_rr_theme
->paddingx
+ 1);
692 if (s
) { *lc
= ' '; break; }
693 if (!(self
->decorations
& OB_FRAME_DECOR_SHADE
)
694 && config_theme_hidedisabled
)
697 self
->label_width
-= (ob_rr_theme
->button_size
+
698 ob_rr_theme
->paddingx
+ 1);
701 if (i
) { *lc
= ' '; break; }
702 if (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
)
703 && config_theme_hidedisabled
)
706 self
->label_width
-= (ob_rr_theme
->button_size
+
707 ob_rr_theme
->paddingx
+ 1);
710 if (l
) { *lc
= ' '; break; }
714 if (m
) { *lc
= ' '; break; }
715 if (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
)
716 && config_theme_hidedisabled
)
719 self
->label_width
-= (ob_rr_theme
->button_size
+
720 ob_rr_theme
->paddingx
+ 1);
723 if (c
) { *lc
= ' '; break; }
724 if (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
)
725 && config_theme_hidedisabled
)
728 self
->label_width
-= (ob_rr_theme
->button_size
+
729 ob_rr_theme
->paddingx
+ 1);
733 if (self
->label_width
< 1) self
->label_width
= 1;
735 if (!n
) XUnmapWindow(ob_display
, self
->icon
);
736 if (!d
) XUnmapWindow(ob_display
, self
->desk
);
737 if (!s
) XUnmapWindow(ob_display
, self
->shade
);
738 if (!i
) XUnmapWindow(ob_display
, self
->iconify
);
739 if (!l
) XUnmapWindow(ob_display
, self
->label
);
740 if (!m
) XUnmapWindow(ob_display
, self
->max
);
741 if (!c
) XUnmapWindow(ob_display
, self
->close
);
743 x
= ob_rr_theme
->paddingx
+ 1;
744 for (lc
= config_title_layout
; *lc
!= '\0'; ++lc
) {
749 XMapWindow(ob_display
, self
->icon
);
750 XMoveWindow(ob_display
, self
->icon
, x
, ob_rr_theme
->paddingy
);
751 x
+= ob_rr_theme
->button_size
+ 2 + ob_rr_theme
->paddingx
+ 1;
756 XMapWindow(ob_display
, self
->desk
);
757 XMoveWindow(ob_display
, self
->desk
, x
, ob_rr_theme
->paddingy
+ 1);
758 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
763 XMapWindow(ob_display
, self
->shade
);
764 XMoveWindow(ob_display
, self
->shade
, x
, ob_rr_theme
->paddingy
+ 1);
765 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
770 XMapWindow(ob_display
, self
->iconify
);
771 XMoveWindow(ob_display
,self
->iconify
, x
, ob_rr_theme
->paddingy
+ 1);
772 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
777 XMapWindow(ob_display
, self
->label
);
778 XMoveWindow(ob_display
, self
->label
, x
, ob_rr_theme
->paddingy
);
779 x
+= self
->label_width
+ ob_rr_theme
->paddingx
+ 1;
784 XMapWindow(ob_display
, self
->max
);
785 XMoveWindow(ob_display
, self
->max
, x
, ob_rr_theme
->paddingy
+ 1);
786 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
791 XMapWindow(ob_display
, self
->close
);
792 XMoveWindow(ob_display
, self
->close
, x
, ob_rr_theme
->paddingy
+ 1);
793 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
799 ObFrameContext
frame_context_from_string(const gchar
*name
)
801 if (!g_ascii_strcasecmp("Desktop", name
))
802 return OB_FRAME_CONTEXT_DESKTOP
;
803 else if (!g_ascii_strcasecmp("Client", name
))
804 return OB_FRAME_CONTEXT_CLIENT
;
805 else if (!g_ascii_strcasecmp("Titlebar", name
))
806 return OB_FRAME_CONTEXT_TITLEBAR
;
807 else if (!g_ascii_strcasecmp("Handle", name
))
808 return OB_FRAME_CONTEXT_HANDLE
;
809 else if (!g_ascii_strcasecmp("Frame", name
))
810 return OB_FRAME_CONTEXT_FRAME
;
811 else if (!g_ascii_strcasecmp("TLCorner", name
))
812 return OB_FRAME_CONTEXT_TLCORNER
;
813 else if (!g_ascii_strcasecmp("TRCorner", name
))
814 return OB_FRAME_CONTEXT_TRCORNER
;
815 else if (!g_ascii_strcasecmp("BLCorner", name
))
816 return OB_FRAME_CONTEXT_BLCORNER
;
817 else if (!g_ascii_strcasecmp("BRCorner", name
))
818 return OB_FRAME_CONTEXT_BRCORNER
;
819 else if (!g_ascii_strcasecmp("Maximize", name
))
820 return OB_FRAME_CONTEXT_MAXIMIZE
;
821 else if (!g_ascii_strcasecmp("AllDesktops", name
))
822 return OB_FRAME_CONTEXT_ALLDESKTOPS
;
823 else if (!g_ascii_strcasecmp("Shade", name
))
824 return OB_FRAME_CONTEXT_SHADE
;
825 else if (!g_ascii_strcasecmp("Iconify", name
))
826 return OB_FRAME_CONTEXT_ICONIFY
;
827 else if (!g_ascii_strcasecmp("Icon", name
))
828 return OB_FRAME_CONTEXT_ICON
;
829 else if (!g_ascii_strcasecmp("Close", name
))
830 return OB_FRAME_CONTEXT_CLOSE
;
831 else if (!g_ascii_strcasecmp("MoveResize", name
))
832 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
833 return OB_FRAME_CONTEXT_NONE
;
836 ObFrameContext
frame_context(ObClient
*client
, Window win
)
840 if (moveresize_in_progress
)
841 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
843 if (win
== RootWindow(ob_display
, ob_screen
))
844 return OB_FRAME_CONTEXT_DESKTOP
;
845 if (client
== NULL
) return OB_FRAME_CONTEXT_NONE
;
846 if (win
== client
->window
) {
847 /* conceptually, this is the desktop, as far as users are
849 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
850 return OB_FRAME_CONTEXT_DESKTOP
;
851 return OB_FRAME_CONTEXT_CLIENT
;
854 self
= client
->frame
;
855 if (win
== self
->inner
|| win
== self
->plate
) {
856 /* conceptually, this is the desktop, as far as users are
858 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
859 return OB_FRAME_CONTEXT_DESKTOP
;
860 return OB_FRAME_CONTEXT_CLIENT
;
863 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
864 if (win
== self
->title
) return OB_FRAME_CONTEXT_TITLEBAR
;
865 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
866 if (win
== self
->handle
) return OB_FRAME_CONTEXT_HANDLE
;
867 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
868 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
869 if (win
== self
->tltresize
) return OB_FRAME_CONTEXT_TLCORNER
;
870 if (win
== self
->tllresize
) return OB_FRAME_CONTEXT_TLCORNER
;
871 if (win
== self
->trtresize
) return OB_FRAME_CONTEXT_TRCORNER
;
872 if (win
== self
->trrresize
) return OB_FRAME_CONTEXT_TRCORNER
;
873 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
874 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
875 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
876 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
877 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
878 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
880 return OB_FRAME_CONTEXT_NONE
;
883 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
886 switch (self
->client
->gravity
) {
888 case NorthWestGravity
:
889 case SouthWestGravity
:
896 *x
-= (self
->size
.left
+ w
) / 2;
899 case NorthEastGravity
:
900 case SouthEastGravity
:
902 *x
-= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
907 *x
-= self
->size
.left
;
912 switch (self
->client
->gravity
) {
914 case NorthWestGravity
:
915 case NorthEastGravity
:
922 *y
-= (self
->size
.top
+ h
) / 2;
925 case SouthWestGravity
:
926 case SouthEastGravity
:
928 *y
-= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
933 *y
-= self
->size
.top
;
938 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
941 switch (self
->client
->gravity
) {
943 case NorthWestGravity
:
945 case SouthWestGravity
:
950 *x
+= (self
->size
.left
+ w
) / 2;
952 case NorthEastGravity
:
954 case SouthEastGravity
:
955 *x
+= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
959 *x
+= self
->size
.left
;
964 switch (self
->client
->gravity
) {
966 case NorthWestGravity
:
968 case NorthEastGravity
:
973 *y
+= (self
->size
.top
+ h
) / 2;
975 case SouthWestGravity
:
977 case SouthEastGravity
:
978 *y
+= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
982 *y
+= self
->size
.top
;
987 static void flash_done(gpointer data
)
989 ObFrame
*self
= data
;
991 if (self
->focused
!= self
->flash_on
)
992 frame_adjust_focus(self
, self
->focused
);
995 static gboolean
flash_timeout(gpointer data
)
997 ObFrame
*self
= data
;
1000 g_get_current_time(&now
);
1001 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
1002 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
1003 now
.tv_usec
>= self
->flash_end
.tv_usec
))
1004 self
->flashing
= FALSE
;
1006 if (!self
->flashing
)
1007 return FALSE
; /* we are done */
1009 self
->flash_on
= !self
->flash_on
;
1010 if (!self
->focused
) {
1011 frame_adjust_focus(self
, self
->flash_on
);
1012 self
->focused
= FALSE
;
1015 return TRUE
; /* go again */
1018 void frame_flash_start(ObFrame
*self
)
1020 self
->flash_on
= self
->focused
;
1022 if (!self
->flashing
)
1023 ob_main_loop_timeout_add(ob_main_loop
,
1024 G_USEC_PER_SEC
* 0.6,
1029 g_get_current_time(&self
->flash_end
);
1030 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
1032 self
->flashing
= TRUE
;
1035 void frame_flash_stop(ObFrame
*self
)
1037 self
->flashing
= FALSE
;
1040 static gulong
frame_animate_iconify_time_left(ObFrame
*self
,
1041 const GTimeVal
*now
)
1044 sec
= self
->iconify_animation_end
.tv_sec
- now
->tv_sec
;
1045 usec
= self
->iconify_animation_end
.tv_usec
- now
->tv_usec
;
1047 usec
+= G_USEC_PER_SEC
;
1050 /* no negative values */
1051 return MAX(sec
* G_USEC_PER_SEC
+ usec
, 0);
1054 static gboolean
frame_animate_iconify(gpointer p
)
1058 gint iconx
, icony
, iconw
;
1061 gboolean iconifying
;
1063 if (self
->client
->icon_geometry
.width
== 0) {
1064 /* there is no icon geometry set so just go straight down */
1065 Rect
*a
= screen_physical_area();
1066 iconx
= self
->area
.x
+ self
->area
.width
/ 2 + 32;
1067 icony
= a
->y
+ a
->width
;
1070 iconx
= self
->client
->icon_geometry
.x
;
1071 icony
= self
->client
->icon_geometry
.y
;
1072 iconw
= self
->client
->icon_geometry
.width
;
1075 iconifying
= self
->iconify_animation_going
> 0;
1077 /* how far do we have left to go ? */
1078 g_get_current_time(&now
);
1079 time
= frame_animate_iconify_time_left(self
, &now
);
1081 if (time
== 0 || iconifying
) {
1082 /* start where the frame is supposed to be */
1085 w
= self
->area
.width
- self
->bwidth
* 2;
1086 h
= self
->area
.height
- self
->bwidth
* 2;
1088 /* start at the icon */
1092 h
= self
->innersize
.top
; /* just the titlebar */
1099 dx
= self
->area
.x
- iconx
;
1100 dy
= self
->area
.y
- icony
;
1101 dw
= self
->area
.width
- self
->bwidth
* 2 - iconw
;
1102 /* if restoring, we move in the opposite direction */
1103 if (!iconifying
) { dx
= -dx
; dy
= -dy
; dw
= -dw
; }
1105 elapsed
= FRAME_ANIMATE_ICONIFY_TIME
- time
;
1106 x
= x
- (dx
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1107 y
= y
- (dy
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1108 w
= w
- (dw
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1109 h
= self
->innersize
.top
; /* just the titlebar */
1113 frame_end_iconify_animation(self
);
1115 XMoveResizeWindow(ob_display
, self
->window
, x
, y
, w
, h
);
1119 return time
> 0; /* repeat until we're out of time */
1122 void frame_end_iconify_animation(ObFrame
*self
)
1124 /* see if there is an animation going */
1125 if (self
->iconify_animation_going
== 0) return;
1128 XUnmapWindow(ob_display
, self
->window
);
1130 /* we're not animating any more ! */
1131 self
->iconify_animation_going
= 0;
1133 XMoveResizeWindow(ob_display
, self
->window
,
1134 self
->area
.x
, self
->area
.y
,
1135 self
->area
.width
- self
->bwidth
* 2,
1136 self
->area
.height
- self
->bwidth
* 2);
1140 void frame_begin_iconify_animation(ObFrame
*self
, gboolean iconifying
)
1143 gboolean new_anim
= FALSE
;
1144 gboolean set_end
= TRUE
;
1147 /* if there is no titlebar, just don't animate for now
1148 XXX it would be nice tho.. */
1149 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1152 /* get the current time */
1153 g_get_current_time(&now
);
1155 /* get how long until the end */
1156 time
= FRAME_ANIMATE_ICONIFY_TIME
;
1157 if (self
->iconify_animation_going
) {
1158 if (!!iconifying
!= (self
->iconify_animation_going
> 0)) {
1159 /* animation was already going on in the opposite direction */
1160 time
= time
- frame_animate_iconify_time_left(self
, &now
);
1162 /* animation was already going in the same direction */
1166 self
->iconify_animation_going
= iconifying
? 1 : -1;
1168 /* set the ending time */
1170 self
->iconify_animation_end
.tv_sec
= now
.tv_sec
;
1171 self
->iconify_animation_end
.tv_usec
= now
.tv_usec
;
1172 g_time_val_add(&self
->iconify_animation_end
, time
);
1176 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
1178 ob_main_loop_timeout_add(ob_main_loop
,
1179 FRAME_ANIMATE_ICONIFY_STEP_TIME
,
1180 frame_animate_iconify
, self
,
1181 g_direct_equal
, NULL
);
1183 /* do the first step */
1184 frame_animate_iconify(self
);
1186 /* show it during the animation even if it is not "visible" */
1188 XMapWindow(ob_display
, self
->window
);