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 /* the offsets for the titlebar elements from the edge of the titlebar.
52 negative means from the right edge. */
62 static void flash_done(gpointer data
);
63 static gboolean
flash_timeout(gpointer data
);
65 static void layout_title(ObFrame
*self
);
66 static void set_theme_statics(ObFrame
*self
);
67 static void free_theme_statics(ObFrame
*self
);
68 static gboolean
frame_animate_iconify(gpointer self
);
70 static Window
createWindow(Window parent
, Visual
*visual
,
71 gulong mask
, XSetWindowAttributes
*attrib
)
73 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
74 (visual
? 32 : RrDepth(ob_rr_inst
)), InputOutput
,
75 (visual
? visual
: RrVisual(ob_rr_inst
)),
80 static Visual
*check_32bit_client(ObClient
*c
)
82 XWindowAttributes wattrib
;
85 ret
= XGetWindowAttributes(ob_display
, c
->window
, &wattrib
);
86 g_assert(ret
!= BadDrawable
);
87 g_assert(ret
!= BadWindow
);
89 if (wattrib
.depth
== 32)
90 return wattrib
.visual
;
94 ObFrame
*frame_new(ObClient
*client
)
96 XSetWindowAttributes attrib
;
101 self
= g_new0(ObFrame
, 1);
103 visual
= check_32bit_client(client
);
105 /* create the non-visible decor windows */
109 /* client has a 32-bit visual */
110 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
111 /* create a colormap with the visual */
112 self
->colormap
= attrib
.colormap
=
113 XCreateColormap(ob_display
,
114 RootWindow(ob_display
, ob_screen
),
116 attrib
.background_pixel
= BlackPixel(ob_display
, 0);
117 attrib
.border_pixel
= BlackPixel(ob_display
, 0);
119 attrib
.event_mask
= FRAME_EVENTMASK
;
120 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
), visual
,
123 attrib
.event_mask
= INNER_EVENTMASK
;
124 self
->inner
= createWindow(self
->window
, visual
, mask
, &attrib
);
126 mask
&= ~CWEventMask
;
127 self
->plate
= createWindow(self
->inner
, visual
, mask
, &attrib
);
129 /* create the visible decor windows */
133 /* client has a 32-bit visual */
134 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
135 attrib
.colormap
= RrColormap(ob_rr_inst
);
137 attrib
.event_mask
= ELEMENT_EVENTMASK
;
138 self
->title
= createWindow(self
->window
, NULL
, mask
, &attrib
);
141 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHWEST
);
142 self
->tltresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
143 self
->tllresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
144 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHEAST
);
145 self
->trtresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
146 self
->trrresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
149 self
->label
= createWindow(self
->title
, NULL
, mask
, &attrib
);
150 self
->max
= createWindow(self
->title
, NULL
, mask
, &attrib
);
151 self
->close
= createWindow(self
->title
, NULL
, mask
, &attrib
);
152 self
->desk
= createWindow(self
->title
, NULL
, mask
, &attrib
);
153 self
->shade
= createWindow(self
->title
, NULL
, mask
, &attrib
);
154 self
->icon
= createWindow(self
->title
, NULL
, mask
, &attrib
);
155 self
->iconify
= createWindow(self
->title
, NULL
, mask
, &attrib
);
156 self
->handle
= createWindow(self
->window
, NULL
, mask
, &attrib
);
159 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHWEST
);
160 self
->lgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
161 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHEAST
);
162 self
->rgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
164 self
->focused
= FALSE
;
166 /* the other stuff is shown based on decor settings */
167 XMapWindow(ob_display
, self
->plate
);
168 XMapWindow(ob_display
, self
->inner
);
169 XMapWindow(ob_display
, self
->lgrip
);
170 XMapWindow(ob_display
, self
->rgrip
);
171 XMapWindow(ob_display
, self
->label
);
173 self
->max_press
= self
->close_press
= self
->desk_press
=
174 self
->iconify_press
= self
->shade_press
= FALSE
;
175 self
->max_hover
= self
->close_hover
= self
->desk_hover
=
176 self
->iconify_hover
= self
->shade_hover
= FALSE
;
178 set_theme_statics(self
);
180 return (ObFrame
*)self
;
183 static void set_theme_statics(ObFrame
*self
)
185 /* set colors/appearance/sizes for stuff that doesn't change */
186 XSetWindowBorder(ob_display
, self
->window
,
187 RrColorPixel(ob_rr_theme
->frame_b_color
));
188 XSetWindowBorder(ob_display
, self
->inner
,
189 RrColorPixel(ob_rr_theme
->frame_b_color
));
190 XSetWindowBorder(ob_display
, self
->title
,
191 RrColorPixel(ob_rr_theme
->frame_b_color
));
192 XSetWindowBorder(ob_display
, self
->handle
,
193 RrColorPixel(ob_rr_theme
->frame_b_color
));
194 XSetWindowBorder(ob_display
, self
->rgrip
,
195 RrColorPixel(ob_rr_theme
->frame_b_color
));
196 XSetWindowBorder(ob_display
, self
->lgrip
,
197 RrColorPixel(ob_rr_theme
->frame_b_color
));
199 XResizeWindow(ob_display
, self
->max
,
200 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
201 XResizeWindow(ob_display
, self
->iconify
,
202 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
203 XResizeWindow(ob_display
, self
->icon
,
204 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
205 XResizeWindow(ob_display
, self
->close
,
206 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
207 XResizeWindow(ob_display
, self
->desk
,
208 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
209 XResizeWindow(ob_display
, self
->shade
,
210 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
211 if (ob_rr_theme
->handle_height
> 0) {
212 XResizeWindow(ob_display
, self
->lgrip
,
213 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
214 XResizeWindow(ob_display
, self
->rgrip
,
215 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
217 XResizeWindow(ob_display
, self
->tltresize
,
218 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
219 XResizeWindow(ob_display
, self
->trtresize
,
220 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
221 XResizeWindow(ob_display
, self
->tllresize
,
222 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
223 XResizeWindow(ob_display
, self
->trrresize
,
224 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
226 /* set up the dynamic appearances */
227 self
->a_unfocused_title
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_title
);
228 self
->a_focused_title
= RrAppearanceCopy(ob_rr_theme
->a_focused_title
);
229 self
->a_unfocused_label
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_label
);
230 self
->a_focused_label
= RrAppearanceCopy(ob_rr_theme
->a_focused_label
);
231 self
->a_unfocused_handle
=
232 RrAppearanceCopy(ob_rr_theme
->a_unfocused_handle
);
233 self
->a_focused_handle
= RrAppearanceCopy(ob_rr_theme
->a_focused_handle
);
234 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_icon
);
237 static void free_theme_statics(ObFrame
*self
)
239 RrAppearanceFree(self
->a_unfocused_title
);
240 RrAppearanceFree(self
->a_focused_title
);
241 RrAppearanceFree(self
->a_unfocused_label
);
242 RrAppearanceFree(self
->a_focused_label
);
243 RrAppearanceFree(self
->a_unfocused_handle
);
244 RrAppearanceFree(self
->a_focused_handle
);
245 RrAppearanceFree(self
->a_icon
);
248 static void frame_free(ObFrame
*self
)
250 free_theme_statics(self
);
252 XDestroyWindow(ob_display
, self
->window
);
254 XFreeColormap(ob_display
, self
->colormap
);
259 void frame_show(ObFrame
*self
)
261 if (!self
->visible
) {
262 self
->visible
= TRUE
;
263 XMapWindow(ob_display
, self
->client
->window
);
264 XMapWindow(ob_display
, self
->window
);
268 void frame_hide(ObFrame
*self
)
271 self
->visible
= FALSE
;
272 if (!frame_iconify_animating(self
))
273 XUnmapWindow(ob_display
, self
->window
);
274 /* we unmap the client itself so that we can get MapRequest
275 events, and because the ICCCM tells us to! */
276 XUnmapWindow(ob_display
, self
->client
->window
);
277 self
->client
->ignore_unmaps
+= 1;
281 void frame_adjust_theme(ObFrame
*self
)
283 free_theme_statics(self
);
284 set_theme_statics(self
);
287 void frame_adjust_shape(ObFrame
*self
)
293 if (!self
->client
->shaped
) {
294 /* clear the shape on the frame window */
295 XShapeCombineMask(ob_display
, self
->window
, ShapeBounding
,
296 self
->innersize
.left
,
300 /* make the frame's shape match the clients */
301 XShapeCombineShape(ob_display
, self
->window
, ShapeBounding
,
302 self
->innersize
.left
,
304 self
->client
->window
,
305 ShapeBounding
, ShapeSet
);
308 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
309 xrect
[0].x
= -ob_rr_theme
->fbwidth
;
310 xrect
[0].y
= -ob_rr_theme
->fbwidth
;
311 xrect
[0].width
= self
->width
+ self
->rbwidth
* 2;
312 xrect
[0].height
= ob_rr_theme
->title_height
+
317 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
) {
318 xrect
[1].x
= -ob_rr_theme
->fbwidth
;
319 xrect
[1].y
= FRAME_HANDLE_Y(self
);
320 xrect
[1].width
= self
->width
+ self
->rbwidth
* 2;
321 xrect
[1].height
= ob_rr_theme
->handle_height
+
326 XShapeCombineRectangles(ob_display
, self
->window
,
327 ShapeBounding
, 0, 0, xrect
, num
,
328 ShapeUnion
, Unsorted
);
333 void frame_adjust_area(ObFrame
*self
, gboolean moved
,
334 gboolean resized
, gboolean fake
)
338 oldsize
= self
->size
;
341 self
->decorations
= self
->client
->decorations
;
342 self
->max_horz
= self
->client
->max_horz
;
344 if (self
->decorations
& OB_FRAME_DECOR_BORDER
) {
345 self
->bwidth
= ob_rr_theme
->fbwidth
;
346 self
->cbwidth_x
= ob_rr_theme
->cbwidthx
;
347 self
->cbwidth_y
= ob_rr_theme
->cbwidthy
;
349 self
->bwidth
= self
->cbwidth_x
= self
->cbwidth_y
= 0;
351 self
->rbwidth
= self
->bwidth
;
354 self
->bwidth
= self
->cbwidth_x
= 0;
356 STRUT_SET(self
->innersize
,
361 self
->width
= self
->client
->area
.width
+ self
->cbwidth_x
* 2 -
362 (self
->max_horz
? self
->rbwidth
* 2 : 0);
363 self
->width
= MAX(self
->width
, 1); /* no lower than 1 */
365 /* set border widths */
367 XSetWindowBorderWidth(ob_display
, self
->window
, self
->bwidth
);
368 XSetWindowBorderWidth(ob_display
, self
->inner
, self
->bwidth
);
369 XSetWindowBorderWidth(ob_display
, self
->title
, self
->rbwidth
);
370 XSetWindowBorderWidth(ob_display
, self
->handle
, self
->rbwidth
);
371 XSetWindowBorderWidth(ob_display
, self
->lgrip
, self
->rbwidth
);
372 XSetWindowBorderWidth(ob_display
, self
->rgrip
, self
->rbwidth
);
375 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
376 self
->innersize
.top
+= ob_rr_theme
->title_height
+ self
->rbwidth
+
377 (self
->rbwidth
- self
->bwidth
);
378 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
379 ob_rr_theme
->handle_height
> 0)
380 self
->innersize
.bottom
+= ob_rr_theme
->handle_height
+
381 self
->rbwidth
+ (self
->rbwidth
- self
->bwidth
);
383 /* position/size and map/unmap all the windows */
386 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
387 XMoveResizeWindow(ob_display
, self
->title
,
388 -self
->bwidth
, -self
->bwidth
,
389 self
->width
, ob_rr_theme
->title_height
);
390 XMapWindow(ob_display
, self
->title
);
392 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
393 XMoveWindow(ob_display
, self
->tltresize
, 0, 0);
394 XMoveWindow(ob_display
, self
->tllresize
, 0, 0);
395 XMoveWindow(ob_display
, self
->trtresize
,
396 self
->width
- ob_rr_theme
->grip_width
, 0);
397 XMoveWindow(ob_display
, self
->trrresize
,
398 self
->width
- ob_rr_theme
->paddingx
- 1, 0);
399 XMapWindow(ob_display
, self
->tltresize
);
400 XMapWindow(ob_display
, self
->tllresize
);
401 XMapWindow(ob_display
, self
->trtresize
);
402 XMapWindow(ob_display
, self
->trrresize
);
404 XUnmapWindow(ob_display
, self
->tltresize
);
405 XUnmapWindow(ob_display
, self
->tllresize
);
406 XUnmapWindow(ob_display
, self
->trtresize
);
407 XUnmapWindow(ob_display
, self
->trrresize
);
410 XUnmapWindow(ob_display
, self
->title
);
413 if ((self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
414 /* layout the title bar elements */
418 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
419 ob_rr_theme
->handle_height
> 0)
421 XMoveResizeWindow(ob_display
, self
->handle
,
422 -self
->bwidth
, FRAME_HANDLE_Y(self
),
423 self
->width
, ob_rr_theme
->handle_height
);
424 XMapWindow(ob_display
, self
->handle
);
426 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
427 XMoveWindow(ob_display
, self
->lgrip
,
428 -self
->rbwidth
, -self
->rbwidth
);
429 XMoveWindow(ob_display
, self
->rgrip
,
430 -self
->rbwidth
+ self
->width
-
431 ob_rr_theme
->grip_width
, -self
->rbwidth
);
432 XMapWindow(ob_display
, self
->lgrip
);
433 XMapWindow(ob_display
, self
->rgrip
);
435 XUnmapWindow(ob_display
, self
->lgrip
);
436 XUnmapWindow(ob_display
, self
->rgrip
);
439 XUnmapWindow(ob_display
, self
->handle
);
441 /* move and resize the inner border window which contains the plate
443 XMoveResizeWindow(ob_display
, self
->inner
,
444 self
->innersize
.left
- self
->cbwidth_x
-
446 self
->innersize
.top
- self
->cbwidth_y
-
448 self
->client
->area
.width
+
450 self
->client
->area
.height
+
451 self
->cbwidth_y
* 2);
454 XMoveWindow(ob_display
, self
->plate
,
455 self
->cbwidth_x
, self
->cbwidth_y
);
457 /* when the client has StaticGravity, it likes to move around. */
458 XMoveWindow(ob_display
, self
->client
->window
, 0, 0);
461 STRUT_SET(self
->size
,
462 self
->innersize
.left
+ self
->bwidth
,
463 self
->innersize
.top
+ self
->bwidth
,
464 self
->innersize
.right
+ self
->bwidth
,
465 self
->innersize
.bottom
+ self
->bwidth
);
468 /* shading can change without being moved or resized */
469 RECT_SET_SIZE(self
->area
,
470 self
->client
->area
.width
+
471 self
->size
.left
+ self
->size
.right
,
472 (self
->client
->shaded
?
473 ob_rr_theme
->title_height
+ self
->rbwidth
* 2:
474 self
->client
->area
.height
+
475 self
->size
.top
+ self
->size
.bottom
));
477 if (moved
|| resized
) {
478 /* find the new coordinates, done after setting the frame.size, for
479 frame_client_gravity. */
480 self
->area
.x
= self
->client
->area
.x
;
481 self
->area
.y
= self
->client
->area
.y
;
482 frame_client_gravity(self
, &self
->area
.x
, &self
->area
.y
,
483 self
->client
->area
.width
,
484 self
->client
->area
.height
);
488 if (!frame_iconify_animating(self
))
489 /* move and resize the top level frame.
490 shading can change without being moved or resized.
492 but don't do this during an iconify animation. it will be
493 reflected afterwards.
495 XMoveResizeWindow(ob_display
, self
->window
,
496 self
->area
.x
, self
->area
.y
,
497 self
->area
.width
- self
->bwidth
* 2,
498 self
->area
.height
- self
->bwidth
* 2);
501 framerender_frame(self
);
502 frame_adjust_shape(self
);
505 if (!STRUT_EQUAL(self
->size
, oldsize
)) {
507 vals
[0] = self
->size
.left
;
508 vals
[1] = self
->size
.right
;
509 vals
[2] = self
->size
.top
;
510 vals
[3] = self
->size
.bottom
;
511 PROP_SETA32(self
->client
->window
, net_frame_extents
,
513 PROP_SETA32(self
->client
->window
, kde_net_wm_frame_strut
,
517 /* if this occurs while we are focus cycling, the indicator needs to
519 if (focus_cycle_target
== self
->client
)
520 focus_cycle_draw_indicator();
522 if (resized
&& (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
523 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
524 ob_rr_theme
->label_height
);
527 void frame_adjust_client_area(ObFrame
*self
)
529 /* resize the plate */
530 XResizeWindow(ob_display
, self
->plate
,
531 self
->client
->area
.width
, self
->client
->area
.height
);
534 void frame_adjust_state(ObFrame
*self
)
536 framerender_frame(self
);
539 void frame_adjust_focus(ObFrame
*self
, gboolean hilite
)
541 self
->focused
= hilite
;
542 framerender_frame(self
);
546 void frame_adjust_title(ObFrame
*self
)
548 framerender_frame(self
);
551 void frame_adjust_icon(ObFrame
*self
)
553 framerender_frame(self
);
556 void frame_grab_client(ObFrame
*self
, ObClient
*client
)
558 self
->client
= client
;
560 /* reparent the client to the frame */
561 XReparentWindow(ob_display
, client
->window
, self
->plate
, 0, 0);
563 When reparenting the client window, it is usually not mapped yet, since
564 this occurs from a MapRequest. However, in the case where Openbox is
565 starting up, the window is already mapped, so we'll see unmap events for
566 it. There are 2 unmap events generated that we see, one with the 'event'
567 member set the root window, and one set to the client, but both get
568 handled and need to be ignored.
570 if (ob_state() == OB_STATE_STARTING
)
571 client
->ignore_unmaps
+= 2;
573 /* select the event mask on the client's parent (to receive config/map
574 req's) the ButtonPress is to catch clicks on the client border */
575 XSelectInput(ob_display
, self
->plate
, PLATE_EVENTMASK
);
577 /* map the client so it maps when the frame does */
578 XMapWindow(ob_display
, client
->window
);
580 /* adjust the frame to the client's size */
581 frame_adjust_area(self
, FALSE
, TRUE
, FALSE
);
583 /* set all the windows for the frame in the window_map */
584 g_hash_table_insert(window_map
, &self
->window
, client
);
585 g_hash_table_insert(window_map
, &self
->plate
, client
);
586 g_hash_table_insert(window_map
, &self
->inner
, client
);
587 g_hash_table_insert(window_map
, &self
->title
, client
);
588 g_hash_table_insert(window_map
, &self
->label
, client
);
589 g_hash_table_insert(window_map
, &self
->max
, client
);
590 g_hash_table_insert(window_map
, &self
->close
, client
);
591 g_hash_table_insert(window_map
, &self
->desk
, client
);
592 g_hash_table_insert(window_map
, &self
->shade
, client
);
593 g_hash_table_insert(window_map
, &self
->icon
, client
);
594 g_hash_table_insert(window_map
, &self
->iconify
, client
);
595 g_hash_table_insert(window_map
, &self
->handle
, client
);
596 g_hash_table_insert(window_map
, &self
->lgrip
, client
);
597 g_hash_table_insert(window_map
, &self
->rgrip
, client
);
598 g_hash_table_insert(window_map
, &self
->tltresize
, client
);
599 g_hash_table_insert(window_map
, &self
->tllresize
, client
);
600 g_hash_table_insert(window_map
, &self
->trtresize
, client
);
601 g_hash_table_insert(window_map
, &self
->trrresize
, client
);
604 void frame_release_client(ObFrame
*self
, ObClient
*client
)
607 gboolean reparent
= TRUE
;
609 g_assert(self
->client
== client
);
611 /* if there was any animation going on, kill it */
612 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
615 /* check if the app has already reparented its window away */
616 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
617 ReparentNotify
, &ev
))
619 /* This check makes sure we don't catch our own reparent action to
620 our frame window. This doesn't count as the app reparenting itself
623 Reparent events that are generated by us are just discarded here.
624 They are of no consequence to us anyhow.
626 if (ev
.xreparent
.parent
!= self
->plate
) {
628 XPutBackEvent(ob_display
, &ev
);
634 /* according to the ICCCM - if the client doesn't reparent itself,
635 then we will reparent the window to root for them */
636 XReparentWindow(ob_display
, client
->window
,
637 RootWindow(ob_display
, ob_screen
),
642 /* remove all the windows for the frame from the window_map */
643 g_hash_table_remove(window_map
, &self
->window
);
644 g_hash_table_remove(window_map
, &self
->plate
);
645 g_hash_table_remove(window_map
, &self
->inner
);
646 g_hash_table_remove(window_map
, &self
->title
);
647 g_hash_table_remove(window_map
, &self
->label
);
648 g_hash_table_remove(window_map
, &self
->max
);
649 g_hash_table_remove(window_map
, &self
->close
);
650 g_hash_table_remove(window_map
, &self
->desk
);
651 g_hash_table_remove(window_map
, &self
->shade
);
652 g_hash_table_remove(window_map
, &self
->icon
);
653 g_hash_table_remove(window_map
, &self
->iconify
);
654 g_hash_table_remove(window_map
, &self
->handle
);
655 g_hash_table_remove(window_map
, &self
->lgrip
);
656 g_hash_table_remove(window_map
, &self
->rgrip
);
657 g_hash_table_remove(window_map
, &self
->tltresize
);
658 g_hash_table_remove(window_map
, &self
->tllresize
);
659 g_hash_table_remove(window_map
, &self
->trtresize
);
660 g_hash_table_remove(window_map
, &self
->trrresize
);
662 ob_main_loop_timeout_remove_data(ob_main_loop
, flash_timeout
, self
, TRUE
);
667 /* is there anything present between us and the label? */
668 static gboolean
is_button_present(ObFrame
*self
, const gchar
*lc
, gint dir
) {
669 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+= dir
) {
670 if (*lc
== ' ') continue; /* it was invalid */
671 if (*lc
== 'N' && self
->decorations
& OB_FRAME_DECOR_ICON
)
673 if (*lc
== 'D' && self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
)
675 if (*lc
== 'S' && self
->decorations
& OB_FRAME_DECOR_SHADE
)
677 if (*lc
== 'I' && self
->decorations
& OB_FRAME_DECOR_ICONIFY
)
679 if (*lc
== 'M' && self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
)
681 if (*lc
== 'C' && self
->decorations
& OB_FRAME_DECOR_CLOSE
)
683 if (*lc
== 'L') return FALSE
;
688 static void layout_title(ObFrame
*self
)
693 const gint bwidth
= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
694 /* position of the left most button */
695 const gint left
= ob_rr_theme
->paddingx
+ 1;
696 /* position of the right most button */
697 const gint right
= self
->width
- bwidth
;
699 /* turn them all off */
700 self
->icon_on
= self
->desk_on
= self
->shade_on
= self
->iconify_on
=
701 self
->max_on
= self
->close_on
= self
->label_on
= FALSE
;
702 self
->label_width
= self
->width
- (ob_rr_theme
->paddingx
+ 1) * 2;
704 /* figure out what's being show, find each element's position, and the
707 do the ones before the label, then after the label,
708 i will be +1 the first time through when working to the left,
709 and -1 the second time through when working to the right */
710 for (i
= 1; i
>= -1; i
-=2) {
713 lc
= config_title_layout
;
716 lc
= config_title_layout
+ strlen(config_title_layout
)-1;
719 /* stop at the end of the string (or the label, which calls break) */
720 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+=i
)
723 self
->label_on
= TRUE
;
726 break; /* break the for loop, do other side of label */
727 } else if (*lc
== 'N') {
728 if ((self
->icon_on
= is_button_present(self
, lc
, i
))) {
729 /* icon gets extra padding */
730 self
->label_width
-= bwidth
+ 2;
731 self
->icon_x
= x
+ (i
* 1);
732 x
+= i
* (bwidth
+ 2);
734 } else if (*lc
== 'D') {
735 if ((self
->desk_on
= is_button_present(self
, lc
, i
))) {
736 self
->label_width
-= bwidth
;
740 } else if (*lc
== 'S') {
741 if ((self
->shade_on
= is_button_present(self
, lc
, i
))) {
742 self
->label_width
-= bwidth
;
746 } else if (*lc
== 'I') {
747 if ((self
->iconify_on
= is_button_present(self
, lc
, i
))) {
748 self
->label_width
-= bwidth
;
752 } else if (*lc
== 'M') {
753 if ((self
->max_on
= is_button_present(self
, lc
, i
))) {
754 self
->label_width
-= bwidth
;
758 } else if (*lc
== 'C') {
759 if ((self
->close_on
= is_button_present(self
, lc
, i
))) {
760 self
->label_width
-= bwidth
;
767 /* position and map the elements */
769 XMapWindow(ob_display
, self
->icon
);
770 XMoveWindow(ob_display
, self
->icon
, self
->icon_x
,
771 ob_rr_theme
->paddingy
);
773 XUnmapWindow(ob_display
, self
->icon
);
776 XMapWindow(ob_display
, self
->desk
);
777 XMoveWindow(ob_display
, self
->desk
, self
->desk_x
,
778 ob_rr_theme
->paddingy
+ 1);
780 XUnmapWindow(ob_display
, self
->desk
);
782 if (self
->shade_on
) {
783 XMapWindow(ob_display
, self
->shade
);
784 XMoveWindow(ob_display
, self
->shade
, self
->shade_x
,
785 ob_rr_theme
->paddingy
+ 1);
787 XUnmapWindow(ob_display
, self
->shade
);
789 if (self
->iconify_on
) {
790 XMapWindow(ob_display
, self
->iconify
);
791 XMoveWindow(ob_display
, self
->iconify
, self
->iconify_x
,
792 ob_rr_theme
->paddingy
+ 1);
794 XUnmapWindow(ob_display
, self
->iconify
);
797 XMapWindow(ob_display
, self
->max
);
798 XMoveWindow(ob_display
, self
->max
, self
->max_x
,
799 ob_rr_theme
->paddingy
+ 1);
801 XUnmapWindow(ob_display
, self
->max
);
803 if (self
->close_on
) {
804 XMapWindow(ob_display
, self
->close
);
805 XMoveWindow(ob_display
, self
->close
, self
->close_x
,
806 ob_rr_theme
->paddingy
+ 1);
808 XUnmapWindow(ob_display
, self
->close
);
810 if (self
->label_on
) {
811 self
->label_width
= MAX(1, self
->label_width
); /* no lower than 1 */
812 XMapWindow(ob_display
, self
->label
);
813 XMoveWindow(ob_display
, self
->label
, self
->label_x
,
814 ob_rr_theme
->paddingy
);
816 XUnmapWindow(ob_display
, self
->label
);
819 ObFrameContext
frame_context_from_string(const gchar
*name
)
821 if (!g_ascii_strcasecmp("Desktop", name
))
822 return OB_FRAME_CONTEXT_DESKTOP
;
823 else if (!g_ascii_strcasecmp("Client", name
))
824 return OB_FRAME_CONTEXT_CLIENT
;
825 else if (!g_ascii_strcasecmp("Titlebar", name
))
826 return OB_FRAME_CONTEXT_TITLEBAR
;
827 else if (!g_ascii_strcasecmp("Handle", name
))
828 return OB_FRAME_CONTEXT_HANDLE
;
829 else if (!g_ascii_strcasecmp("Frame", name
))
830 return OB_FRAME_CONTEXT_FRAME
;
831 else if (!g_ascii_strcasecmp("TLCorner", name
))
832 return OB_FRAME_CONTEXT_TLCORNER
;
833 else if (!g_ascii_strcasecmp("TRCorner", name
))
834 return OB_FRAME_CONTEXT_TRCORNER
;
835 else if (!g_ascii_strcasecmp("BLCorner", name
))
836 return OB_FRAME_CONTEXT_BLCORNER
;
837 else if (!g_ascii_strcasecmp("BRCorner", name
))
838 return OB_FRAME_CONTEXT_BRCORNER
;
839 else if (!g_ascii_strcasecmp("Maximize", name
))
840 return OB_FRAME_CONTEXT_MAXIMIZE
;
841 else if (!g_ascii_strcasecmp("AllDesktops", name
))
842 return OB_FRAME_CONTEXT_ALLDESKTOPS
;
843 else if (!g_ascii_strcasecmp("Shade", name
))
844 return OB_FRAME_CONTEXT_SHADE
;
845 else if (!g_ascii_strcasecmp("Iconify", name
))
846 return OB_FRAME_CONTEXT_ICONIFY
;
847 else if (!g_ascii_strcasecmp("Icon", name
))
848 return OB_FRAME_CONTEXT_ICON
;
849 else if (!g_ascii_strcasecmp("Close", name
))
850 return OB_FRAME_CONTEXT_CLOSE
;
851 else if (!g_ascii_strcasecmp("MoveResize", name
))
852 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
853 return OB_FRAME_CONTEXT_NONE
;
856 ObFrameContext
frame_context(ObClient
*client
, Window win
)
860 if (moveresize_in_progress
)
861 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
863 if (win
== RootWindow(ob_display
, ob_screen
))
864 return OB_FRAME_CONTEXT_DESKTOP
;
865 if (client
== NULL
) return OB_FRAME_CONTEXT_NONE
;
866 if (win
== client
->window
) {
867 /* conceptually, this is the desktop, as far as users are
869 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
870 return OB_FRAME_CONTEXT_DESKTOP
;
871 return OB_FRAME_CONTEXT_CLIENT
;
874 self
= client
->frame
;
875 if (win
== self
->inner
|| win
== self
->plate
) {
876 /* conceptually, this is the desktop, as far as users are
878 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
879 return OB_FRAME_CONTEXT_DESKTOP
;
880 return OB_FRAME_CONTEXT_CLIENT
;
883 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
884 if (win
== self
->title
) return OB_FRAME_CONTEXT_TITLEBAR
;
885 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
886 if (win
== self
->handle
) return OB_FRAME_CONTEXT_HANDLE
;
887 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
888 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
889 if (win
== self
->tltresize
) return OB_FRAME_CONTEXT_TLCORNER
;
890 if (win
== self
->tllresize
) return OB_FRAME_CONTEXT_TLCORNER
;
891 if (win
== self
->trtresize
) return OB_FRAME_CONTEXT_TRCORNER
;
892 if (win
== self
->trrresize
) return OB_FRAME_CONTEXT_TRCORNER
;
893 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
894 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
895 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
896 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
897 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
898 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
900 return OB_FRAME_CONTEXT_NONE
;
903 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
906 switch (self
->client
->gravity
) {
908 case NorthWestGravity
:
909 case SouthWestGravity
:
916 *x
-= (self
->size
.left
+ w
) / 2;
919 case NorthEastGravity
:
920 case SouthEastGravity
:
922 *x
-= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
927 *x
-= self
->size
.left
;
932 switch (self
->client
->gravity
) {
934 case NorthWestGravity
:
935 case NorthEastGravity
:
942 *y
-= (self
->size
.top
+ h
) / 2;
945 case SouthWestGravity
:
946 case SouthEastGravity
:
948 *y
-= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
953 *y
-= self
->size
.top
;
958 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
961 switch (self
->client
->gravity
) {
963 case NorthWestGravity
:
965 case SouthWestGravity
:
970 *x
+= (self
->size
.left
+ w
) / 2;
972 case NorthEastGravity
:
974 case SouthEastGravity
:
975 *x
+= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
979 *x
+= self
->size
.left
;
984 switch (self
->client
->gravity
) {
986 case NorthWestGravity
:
988 case NorthEastGravity
:
993 *y
+= (self
->size
.top
+ h
) / 2;
995 case SouthWestGravity
:
997 case SouthEastGravity
:
998 *y
+= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
1002 *y
+= self
->size
.top
;
1007 static void flash_done(gpointer data
)
1009 ObFrame
*self
= data
;
1011 if (self
->focused
!= self
->flash_on
)
1012 frame_adjust_focus(self
, self
->focused
);
1015 static gboolean
flash_timeout(gpointer data
)
1017 ObFrame
*self
= data
;
1020 g_get_current_time(&now
);
1021 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
1022 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
1023 now
.tv_usec
>= self
->flash_end
.tv_usec
))
1024 self
->flashing
= FALSE
;
1026 if (!self
->flashing
)
1027 return FALSE
; /* we are done */
1029 self
->flash_on
= !self
->flash_on
;
1030 if (!self
->focused
) {
1031 frame_adjust_focus(self
, self
->flash_on
);
1032 self
->focused
= FALSE
;
1035 return TRUE
; /* go again */
1038 void frame_flash_start(ObFrame
*self
)
1040 self
->flash_on
= self
->focused
;
1042 if (!self
->flashing
)
1043 ob_main_loop_timeout_add(ob_main_loop
,
1044 G_USEC_PER_SEC
* 0.6,
1049 g_get_current_time(&self
->flash_end
);
1050 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
1052 self
->flashing
= TRUE
;
1055 void frame_flash_stop(ObFrame
*self
)
1057 self
->flashing
= FALSE
;
1060 static gulong
frame_animate_iconify_time_left(ObFrame
*self
,
1061 const GTimeVal
*now
)
1064 sec
= self
->iconify_animation_end
.tv_sec
- now
->tv_sec
;
1065 usec
= self
->iconify_animation_end
.tv_usec
- now
->tv_usec
;
1067 usec
+= G_USEC_PER_SEC
;
1070 /* no negative values */
1071 return MAX(sec
* G_USEC_PER_SEC
+ usec
, 0);
1074 static gboolean
frame_animate_iconify(gpointer p
)
1078 gint iconx
, icony
, iconw
;
1081 gboolean iconifying
;
1083 if (self
->client
->icon_geometry
.width
== 0) {
1084 /* there is no icon geometry set so just go straight down */
1085 Rect
*a
= screen_physical_area();
1086 iconx
= self
->area
.x
+ self
->area
.width
/ 2 + 32;
1087 icony
= a
->y
+ a
->width
;
1090 iconx
= self
->client
->icon_geometry
.x
;
1091 icony
= self
->client
->icon_geometry
.y
;
1092 iconw
= self
->client
->icon_geometry
.width
;
1095 iconifying
= self
->iconify_animation_going
> 0;
1097 /* how far do we have left to go ? */
1098 g_get_current_time(&now
);
1099 time
= frame_animate_iconify_time_left(self
, &now
);
1101 if (time
== 0 || iconifying
) {
1102 /* start where the frame is supposed to be */
1105 w
= self
->area
.width
- self
->bwidth
* 2;
1106 h
= self
->area
.height
- self
->bwidth
* 2;
1108 /* start at the icon */
1112 h
= self
->innersize
.top
; /* just the titlebar */
1119 dx
= self
->area
.x
- iconx
;
1120 dy
= self
->area
.y
- icony
;
1121 dw
= self
->area
.width
- self
->bwidth
* 2 - iconw
;
1122 /* if restoring, we move in the opposite direction */
1123 if (!iconifying
) { dx
= -dx
; dy
= -dy
; dw
= -dw
; }
1125 elapsed
= FRAME_ANIMATE_ICONIFY_TIME
- time
;
1126 x
= x
- (dx
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1127 y
= y
- (dy
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1128 w
= w
- (dw
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1129 h
= self
->innersize
.top
; /* just the titlebar */
1133 frame_end_iconify_animation(self
);
1135 XMoveResizeWindow(ob_display
, self
->window
, x
, y
, w
, h
);
1139 return time
> 0; /* repeat until we're out of time */
1142 void frame_end_iconify_animation(ObFrame
*self
)
1144 /* see if there is an animation going */
1145 if (self
->iconify_animation_going
== 0) return;
1148 XUnmapWindow(ob_display
, self
->window
);
1150 /* we're not animating any more ! */
1151 self
->iconify_animation_going
= 0;
1153 XMoveResizeWindow(ob_display
, self
->window
,
1154 self
->area
.x
, self
->area
.y
,
1155 self
->area
.width
- self
->bwidth
* 2,
1156 self
->area
.height
- self
->bwidth
* 2);
1160 void frame_begin_iconify_animation(ObFrame
*self
, gboolean iconifying
)
1163 gboolean new_anim
= FALSE
;
1164 gboolean set_end
= TRUE
;
1167 /* if there is no titlebar, just don't animate for now
1168 XXX it would be nice tho.. */
1169 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1172 /* get the current time */
1173 g_get_current_time(&now
);
1175 /* get how long until the end */
1176 time
= FRAME_ANIMATE_ICONIFY_TIME
;
1177 if (self
->iconify_animation_going
) {
1178 if (!!iconifying
!= (self
->iconify_animation_going
> 0)) {
1179 /* animation was already going on in the opposite direction */
1180 time
= time
- frame_animate_iconify_time_left(self
, &now
);
1182 /* animation was already going in the same direction */
1186 self
->iconify_animation_going
= iconifying
? 1 : -1;
1188 /* set the ending time */
1190 self
->iconify_animation_end
.tv_sec
= now
.tv_sec
;
1191 self
->iconify_animation_end
.tv_usec
= now
.tv_usec
;
1192 g_time_val_add(&self
->iconify_animation_end
, time
);
1196 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
1198 ob_main_loop_timeout_add(ob_main_loop
,
1199 FRAME_ANIMATE_ICONIFY_STEP_TIME
,
1200 frame_animate_iconify
, self
,
1201 g_direct_equal
, NULL
);
1203 /* do the first step */
1204 frame_animate_iconify(self
);
1206 /* show it during the animation even if it is not "visible" */
1208 XMapWindow(ob_display
, self
->window
);