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 | \
37 ButtonMotionMask | PointerMotionMask | \
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 flash_done(gpointer data
);
52 static gboolean
flash_timeout(gpointer data
);
54 static void layout_title(ObFrame
*self
);
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);
91 self
->client
= client
;
93 visual
= check_32bit_client(client
);
95 /* create the non-visible decor windows */
99 /* client has a 32-bit visual */
100 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
101 /* create a colormap with the visual */
102 self
->colormap
= attrib
.colormap
=
103 XCreateColormap(ob_display
,
104 RootWindow(ob_display
, ob_screen
),
106 attrib
.background_pixel
= BlackPixel(ob_display
, 0);
107 attrib
.border_pixel
= BlackPixel(ob_display
, 0);
109 attrib
.event_mask
= FRAME_EVENTMASK
;
110 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
), visual
,
113 attrib
.event_mask
= INNER_EVENTMASK
;
114 self
->inner
= createWindow(self
->window
, visual
, mask
, &attrib
);
116 mask
&= ~CWEventMask
;
117 self
->plate
= createWindow(self
->inner
, visual
, mask
, &attrib
);
119 /* create the visible decor windows */
123 /* client has a 32-bit visual */
124 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
125 attrib
.colormap
= RrColormap(ob_rr_inst
);
127 attrib
.event_mask
= ELEMENT_EVENTMASK
;
128 self
->title
= createWindow(self
->window
, NULL
, mask
, &attrib
);
131 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTH
);
132 self
->topresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
133 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHWEST
);
134 self
->tltresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
135 self
->tllresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
136 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHEAST
);
137 self
->trtresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
138 self
->trrresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
141 self
->label
= createWindow(self
->title
, NULL
, mask
, &attrib
);
142 self
->max
= createWindow(self
->title
, NULL
, mask
, &attrib
);
143 self
->close
= createWindow(self
->title
, NULL
, mask
, &attrib
);
144 self
->desk
= createWindow(self
->title
, NULL
, mask
, &attrib
);
145 self
->shade
= createWindow(self
->title
, NULL
, mask
, &attrib
);
146 self
->icon
= createWindow(self
->title
, NULL
, mask
, &attrib
);
147 self
->iconify
= createWindow(self
->title
, NULL
, mask
, &attrib
);
150 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTH
);
151 self
->handle
= createWindow(self
->window
, NULL
, mask
, &attrib
);
152 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHWEST
);
153 self
->lgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
154 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHEAST
);
155 self
->rgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
157 self
->focused
= FALSE
;
159 /* the other stuff is shown based on decor settings */
160 XMapWindow(ob_display
, self
->plate
);
161 XMapWindow(ob_display
, self
->inner
);
162 XMapWindow(ob_display
, self
->lgrip
);
163 XMapWindow(ob_display
, self
->rgrip
);
164 XMapWindow(ob_display
, self
->label
);
166 self
->max_press
= self
->close_press
= self
->desk_press
=
167 self
->iconify_press
= self
->shade_press
= FALSE
;
168 self
->max_hover
= self
->close_hover
= self
->desk_hover
=
169 self
->iconify_hover
= self
->shade_hover
= FALSE
;
171 set_theme_statics(self
);
173 return (ObFrame
*)self
;
176 static void set_theme_statics(ObFrame
*self
)
178 /* set colors/appearance/sizes for stuff that doesn't change */
179 XResizeWindow(ob_display
, self
->max
,
180 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
181 XResizeWindow(ob_display
, self
->iconify
,
182 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
183 XResizeWindow(ob_display
, self
->icon
,
184 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
185 XResizeWindow(ob_display
, self
->close
,
186 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
187 XResizeWindow(ob_display
, self
->desk
,
188 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
189 XResizeWindow(ob_display
, self
->shade
,
190 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
191 if (ob_rr_theme
->handle_height
> 0) {
192 XResizeWindow(ob_display
, self
->lgrip
,
193 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
194 XResizeWindow(ob_display
, self
->rgrip
,
195 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
197 XResizeWindow(ob_display
, self
->tltresize
,
198 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
199 XResizeWindow(ob_display
, self
->trtresize
,
200 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
201 XResizeWindow(ob_display
, self
->tllresize
,
202 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
203 XResizeWindow(ob_display
, self
->trrresize
,
204 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
206 /* set up the dynamic appearances */
207 self
->a_unfocused_title
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_title
);
208 self
->a_focused_title
= RrAppearanceCopy(ob_rr_theme
->a_focused_title
);
209 self
->a_unfocused_label
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_label
);
210 self
->a_focused_label
= RrAppearanceCopy(ob_rr_theme
->a_focused_label
);
211 self
->a_unfocused_handle
=
212 RrAppearanceCopy(ob_rr_theme
->a_unfocused_handle
);
213 self
->a_focused_handle
= RrAppearanceCopy(ob_rr_theme
->a_focused_handle
);
214 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_icon
);
217 static void free_theme_statics(ObFrame
*self
)
219 RrAppearanceFree(self
->a_unfocused_title
);
220 RrAppearanceFree(self
->a_focused_title
);
221 RrAppearanceFree(self
->a_unfocused_label
);
222 RrAppearanceFree(self
->a_focused_label
);
223 RrAppearanceFree(self
->a_unfocused_handle
);
224 RrAppearanceFree(self
->a_focused_handle
);
225 RrAppearanceFree(self
->a_icon
);
228 void frame_free(ObFrame
*self
)
230 free_theme_statics(self
);
232 XDestroyWindow(ob_display
, self
->window
);
234 XFreeColormap(ob_display
, self
->colormap
);
239 void frame_show(ObFrame
*self
)
241 if (!self
->visible
) {
242 self
->visible
= TRUE
;
243 XMapWindow(ob_display
, self
->client
->window
);
244 XMapWindow(ob_display
, self
->window
);
248 void frame_hide(ObFrame
*self
)
251 self
->visible
= FALSE
;
252 if (!frame_iconify_animating(self
))
253 XUnmapWindow(ob_display
, self
->window
);
254 /* we unmap the client itself so that we can get MapRequest
255 events, and because the ICCCM tells us to! */
256 XUnmapWindow(ob_display
, self
->client
->window
);
257 self
->client
->ignore_unmaps
+= 1;
261 void frame_adjust_theme(ObFrame
*self
)
263 free_theme_statics(self
);
264 set_theme_statics(self
);
267 void frame_adjust_shape(ObFrame
*self
)
273 if (!self
->client
->shaped
) {
274 /* clear the shape on the frame window */
275 XShapeCombineMask(ob_display
, self
->window
, ShapeBounding
,
276 self
->innersize
.left
,
280 /* make the frame's shape match the clients */
281 XShapeCombineShape(ob_display
, self
->window
, ShapeBounding
,
282 self
->innersize
.left
,
284 self
->client
->window
,
285 ShapeBounding
, ShapeSet
);
288 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
289 xrect
[0].x
= -ob_rr_theme
->fbwidth
;
290 xrect
[0].y
= -ob_rr_theme
->fbwidth
;
291 xrect
[0].width
= self
->width
+ self
->rbwidth
* 2;
292 xrect
[0].height
= ob_rr_theme
->title_height
+
297 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
) {
298 xrect
[1].x
= -ob_rr_theme
->fbwidth
;
299 xrect
[1].y
= FRAME_HANDLE_Y(self
);
300 xrect
[1].width
= self
->width
+ self
->rbwidth
* 2;
301 xrect
[1].height
= ob_rr_theme
->handle_height
+
306 XShapeCombineRectangles(ob_display
, self
->window
,
307 ShapeBounding
, 0, 0, xrect
, num
,
308 ShapeUnion
, Unsorted
);
313 void frame_adjust_area(ObFrame
*self
, gboolean moved
,
314 gboolean resized
, gboolean fake
)
318 oldsize
= self
->size
;
321 self
->decorations
= self
->client
->decorations
;
322 self
->max_horz
= self
->client
->max_horz
;
324 if (self
->decorations
& OB_FRAME_DECOR_BORDER
) {
325 self
->bwidth
= ob_rr_theme
->fbwidth
;
326 self
->cbwidth_x
= ob_rr_theme
->cbwidthx
;
327 self
->cbwidth_y
= ob_rr_theme
->cbwidthy
;
329 self
->bwidth
= self
->cbwidth_x
= self
->cbwidth_y
= 0;
331 self
->rbwidth
= self
->bwidth
;
334 self
->bwidth
= self
->cbwidth_x
= 0;
336 STRUT_SET(self
->innersize
,
341 self
->width
= self
->client
->area
.width
+ self
->cbwidth_x
* 2 -
342 (self
->max_horz
? self
->rbwidth
* 2 : 0);
343 self
->width
= MAX(self
->width
, 1); /* no lower than 1 */
345 /* set border widths */
347 XSetWindowBorderWidth(ob_display
, self
->window
, self
->bwidth
);
348 XSetWindowBorderWidth(ob_display
, self
->inner
, self
->bwidth
);
349 XSetWindowBorderWidth(ob_display
, self
->title
, self
->rbwidth
);
350 XSetWindowBorderWidth(ob_display
, self
->handle
, self
->rbwidth
);
351 XSetWindowBorderWidth(ob_display
, self
->lgrip
, self
->rbwidth
);
352 XSetWindowBorderWidth(ob_display
, self
->rgrip
, self
->rbwidth
);
355 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
356 self
->innersize
.top
+= ob_rr_theme
->title_height
+ self
->rbwidth
+
357 (self
->rbwidth
- self
->bwidth
);
358 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
359 ob_rr_theme
->handle_height
> 0)
360 self
->innersize
.bottom
+= ob_rr_theme
->handle_height
+
361 self
->rbwidth
+ (self
->rbwidth
- self
->bwidth
);
363 /* position/size and map/unmap all the windows */
366 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
367 XMoveResizeWindow(ob_display
, self
->title
,
368 -self
->bwidth
, -self
->bwidth
,
369 self
->width
, ob_rr_theme
->title_height
);
370 XMapWindow(ob_display
, self
->title
);
372 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
373 XMoveResizeWindow(ob_display
, self
->topresize
,
374 ob_rr_theme
->grip_width
+ self
->bwidth
,
376 self
->width
- (ob_rr_theme
->grip_width
+
378 ob_rr_theme
->paddingy
+ 1);
380 XMoveWindow(ob_display
, self
->tltresize
, 0, 0);
381 XMoveWindow(ob_display
, self
->tllresize
, 0, 0);
382 XMoveWindow(ob_display
, self
->trtresize
,
383 self
->width
- ob_rr_theme
->grip_width
, 0);
384 XMoveWindow(ob_display
, self
->trrresize
,
385 self
->width
- ob_rr_theme
->paddingx
- 1, 0);
387 XMapWindow(ob_display
, self
->topresize
);
388 XMapWindow(ob_display
, self
->tltresize
);
389 XMapWindow(ob_display
, self
->tllresize
);
390 XMapWindow(ob_display
, self
->trtresize
);
391 XMapWindow(ob_display
, self
->trrresize
);
393 XUnmapWindow(ob_display
, self
->topresize
);
394 XUnmapWindow(ob_display
, self
->tltresize
);
395 XUnmapWindow(ob_display
, self
->tllresize
);
396 XUnmapWindow(ob_display
, self
->trtresize
);
397 XUnmapWindow(ob_display
, self
->trrresize
);
400 XUnmapWindow(ob_display
, self
->title
);
403 if ((self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
404 /* layout the title bar elements */
408 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
409 ob_rr_theme
->handle_height
> 0)
411 XMoveResizeWindow(ob_display
, self
->handle
,
412 -self
->bwidth
, FRAME_HANDLE_Y(self
),
413 self
->width
, ob_rr_theme
->handle_height
);
414 XMapWindow(ob_display
, self
->handle
);
416 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
417 XMoveWindow(ob_display
, self
->lgrip
,
418 -self
->rbwidth
, -self
->rbwidth
);
419 XMoveWindow(ob_display
, self
->rgrip
,
420 -self
->rbwidth
+ self
->width
-
421 ob_rr_theme
->grip_width
, -self
->rbwidth
);
422 XMapWindow(ob_display
, self
->lgrip
);
423 XMapWindow(ob_display
, self
->rgrip
);
425 XUnmapWindow(ob_display
, self
->lgrip
);
426 XUnmapWindow(ob_display
, self
->rgrip
);
429 XUnmapWindow(ob_display
, self
->handle
);
431 /* move and resize the inner border window which contains the plate
433 XMoveResizeWindow(ob_display
, self
->inner
,
434 self
->innersize
.left
- self
->cbwidth_x
-
436 self
->innersize
.top
- self
->cbwidth_y
-
438 self
->client
->area
.width
+
440 self
->client
->area
.height
+
441 self
->cbwidth_y
* 2);
444 XMoveWindow(ob_display
, self
->plate
,
445 self
->cbwidth_x
, self
->cbwidth_y
);
447 /* when the client has StaticGravity, it likes to move around. */
448 XMoveWindow(ob_display
, self
->client
->window
, 0, 0);
451 STRUT_SET(self
->size
,
452 self
->innersize
.left
+ self
->bwidth
,
453 self
->innersize
.top
+ self
->bwidth
,
454 self
->innersize
.right
+ self
->bwidth
,
455 self
->innersize
.bottom
+ self
->bwidth
);
458 /* shading can change without being moved or resized */
459 RECT_SET_SIZE(self
->area
,
460 self
->client
->area
.width
+
461 self
->size
.left
+ self
->size
.right
,
462 (self
->client
->shaded
?
463 ob_rr_theme
->title_height
+ self
->rbwidth
* 2:
464 self
->client
->area
.height
+
465 self
->size
.top
+ self
->size
.bottom
));
467 if (moved
|| resized
) {
468 /* find the new coordinates, done after setting the frame.size, for
469 frame_client_gravity. */
470 self
->area
.x
= self
->client
->area
.x
;
471 self
->area
.y
= self
->client
->area
.y
;
472 frame_client_gravity(self
, &self
->area
.x
, &self
->area
.y
,
473 self
->client
->area
.width
,
474 self
->client
->area
.height
);
478 if (!frame_iconify_animating(self
))
479 /* move and resize the top level frame.
480 shading can change without being moved or resized.
482 but don't do this during an iconify animation. it will be
483 reflected afterwards.
485 XMoveResizeWindow(ob_display
, self
->window
,
486 self
->area
.x
, self
->area
.y
,
487 self
->area
.width
- self
->bwidth
* 2,
488 self
->area
.height
- self
->bwidth
* 2);
491 framerender_frame(self
);
492 frame_adjust_shape(self
);
495 if (!STRUT_EQUAL(self
->size
, oldsize
)) {
497 vals
[0] = self
->size
.left
;
498 vals
[1] = self
->size
.right
;
499 vals
[2] = self
->size
.top
;
500 vals
[3] = self
->size
.bottom
;
501 PROP_SETA32(self
->client
->window
, net_frame_extents
,
503 PROP_SETA32(self
->client
->window
, kde_net_wm_frame_strut
,
507 /* if this occurs while we are focus cycling, the indicator needs to
509 if (focus_cycle_target
== self
->client
)
510 focus_cycle_draw_indicator();
512 if (resized
&& (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
513 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
514 ob_rr_theme
->label_height
);
517 void frame_adjust_client_area(ObFrame
*self
)
519 /* resize the plate */
520 XResizeWindow(ob_display
, self
->plate
,
521 self
->client
->area
.width
, self
->client
->area
.height
);
524 void frame_adjust_state(ObFrame
*self
)
526 framerender_frame(self
);
529 void frame_adjust_focus(ObFrame
*self
, gboolean hilite
)
531 self
->focused
= hilite
;
532 framerender_frame(self
);
536 void frame_adjust_title(ObFrame
*self
)
538 framerender_frame(self
);
541 void frame_adjust_icon(ObFrame
*self
)
543 framerender_frame(self
);
546 void frame_grab_client(ObFrame
*self
)
548 /* reparent the client to the frame */
549 XReparentWindow(ob_display
, self
->client
->window
, self
->plate
, 0, 0);
551 When reparenting the client window, it is usually not mapped yet, since
552 this occurs from a MapRequest. However, in the case where Openbox is
553 starting up, the window is already mapped, so we'll see unmap events for
554 it. There are 2 unmap events generated that we see, one with the 'event'
555 member set the root window, and one set to the client, but both get
556 handled and need to be ignored.
558 if (ob_state() == OB_STATE_STARTING
)
559 self
->client
->ignore_unmaps
+= 2;
561 /* select the event mask on the client's parent (to receive config/map
562 req's) the ButtonPress is to catch clicks on the client border */
563 XSelectInput(ob_display
, self
->plate
, PLATE_EVENTMASK
);
565 /* map the client so it maps when the frame does */
566 XMapWindow(ob_display
, self
->client
->window
);
568 /* set all the windows for the frame in the window_map */
569 g_hash_table_insert(window_map
, &self
->window
, self
->client
);
570 g_hash_table_insert(window_map
, &self
->plate
, self
->client
);
571 g_hash_table_insert(window_map
, &self
->inner
, self
->client
);
572 g_hash_table_insert(window_map
, &self
->title
, self
->client
);
573 g_hash_table_insert(window_map
, &self
->label
, self
->client
);
574 g_hash_table_insert(window_map
, &self
->max
, self
->client
);
575 g_hash_table_insert(window_map
, &self
->close
, self
->client
);
576 g_hash_table_insert(window_map
, &self
->desk
, self
->client
);
577 g_hash_table_insert(window_map
, &self
->shade
, self
->client
);
578 g_hash_table_insert(window_map
, &self
->icon
, self
->client
);
579 g_hash_table_insert(window_map
, &self
->iconify
, self
->client
);
580 g_hash_table_insert(window_map
, &self
->handle
, self
->client
);
581 g_hash_table_insert(window_map
, &self
->lgrip
, self
->client
);
582 g_hash_table_insert(window_map
, &self
->rgrip
, self
->client
);
583 g_hash_table_insert(window_map
, &self
->topresize
, self
->client
);
584 g_hash_table_insert(window_map
, &self
->tltresize
, self
->client
);
585 g_hash_table_insert(window_map
, &self
->tllresize
, self
->client
);
586 g_hash_table_insert(window_map
, &self
->trtresize
, self
->client
);
587 g_hash_table_insert(window_map
, &self
->trrresize
, self
->client
);
590 void frame_release_client(ObFrame
*self
)
593 gboolean reparent
= TRUE
;
595 /* if there was any animation going on, kill it */
596 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
599 /* check if the app has already reparented its window away */
600 while (XCheckTypedWindowEvent(ob_display
, self
->client
->window
,
601 ReparentNotify
, &ev
))
603 /* This check makes sure we don't catch our own reparent action to
604 our frame window. This doesn't count as the app reparenting itself
607 Reparent events that are generated by us are just discarded here.
608 They are of no consequence to us anyhow.
610 if (ev
.xreparent
.parent
!= self
->plate
) {
612 XPutBackEvent(ob_display
, &ev
);
618 /* according to the ICCCM - if the client doesn't reparent itself,
619 then we will reparent the window to root for them */
620 XReparentWindow(ob_display
, self
->client
->window
,
621 RootWindow(ob_display
, ob_screen
),
622 self
->client
->area
.x
,
623 self
->client
->area
.y
);
626 /* remove all the windows for the frame from the window_map */
627 g_hash_table_remove(window_map
, &self
->window
);
628 g_hash_table_remove(window_map
, &self
->plate
);
629 g_hash_table_remove(window_map
, &self
->inner
);
630 g_hash_table_remove(window_map
, &self
->title
);
631 g_hash_table_remove(window_map
, &self
->label
);
632 g_hash_table_remove(window_map
, &self
->max
);
633 g_hash_table_remove(window_map
, &self
->close
);
634 g_hash_table_remove(window_map
, &self
->desk
);
635 g_hash_table_remove(window_map
, &self
->shade
);
636 g_hash_table_remove(window_map
, &self
->icon
);
637 g_hash_table_remove(window_map
, &self
->iconify
);
638 g_hash_table_remove(window_map
, &self
->handle
);
639 g_hash_table_remove(window_map
, &self
->lgrip
);
640 g_hash_table_remove(window_map
, &self
->rgrip
);
641 g_hash_table_remove(window_map
, &self
->topresize
);
642 g_hash_table_remove(window_map
, &self
->tltresize
);
643 g_hash_table_remove(window_map
, &self
->tllresize
);
644 g_hash_table_remove(window_map
, &self
->trtresize
);
645 g_hash_table_remove(window_map
, &self
->trrresize
);
647 ob_main_loop_timeout_remove_data(ob_main_loop
, flash_timeout
, self
, TRUE
);
650 /* is there anything present between us and the label? */
651 static gboolean
is_button_present(ObFrame
*self
, const gchar
*lc
, gint dir
) {
652 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+= dir
) {
653 if (*lc
== ' ') continue; /* it was invalid */
654 if (*lc
== 'N' && self
->decorations
& OB_FRAME_DECOR_ICON
)
656 if (*lc
== 'D' && self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
)
658 if (*lc
== 'S' && self
->decorations
& OB_FRAME_DECOR_SHADE
)
660 if (*lc
== 'I' && self
->decorations
& OB_FRAME_DECOR_ICONIFY
)
662 if (*lc
== 'M' && self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
)
664 if (*lc
== 'C' && self
->decorations
& OB_FRAME_DECOR_CLOSE
)
666 if (*lc
== 'L') return FALSE
;
671 static void layout_title(ObFrame
*self
)
676 const gint bwidth
= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
677 /* position of the left most button */
678 const gint left
= ob_rr_theme
->paddingx
+ 1;
679 /* position of the right most button */
680 const gint right
= self
->width
- bwidth
;
682 /* turn them all off */
683 self
->icon_on
= self
->desk_on
= self
->shade_on
= self
->iconify_on
=
684 self
->max_on
= self
->close_on
= self
->label_on
= FALSE
;
685 self
->label_width
= self
->width
- (ob_rr_theme
->paddingx
+ 1) * 2;
686 self
->leftmost
= self
->rightmost
= OB_FRAME_CONTEXT_NONE
;
688 /* figure out what's being show, find each element's position, and the
691 do the ones before the label, then after the label,
692 i will be +1 the first time through when working to the left,
693 and -1 the second time through when working to the right */
694 for (i
= 1; i
>= -1; i
-=2) {
696 ObFrameContext
*firstcon
;
700 lc
= config_title_layout
;
701 firstcon
= &self
->leftmost
;
704 lc
= config_title_layout
+ strlen(config_title_layout
)-1;
705 firstcon
= &self
->rightmost
;
708 /* stop at the end of the string (or the label, which calls break) */
709 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+=i
) {
712 self
->label_on
= TRUE
;
715 break; /* break the for loop, do other side of label */
716 } else if (*lc
== 'N') {
717 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICON
;
718 if ((self
->icon_on
= is_button_present(self
, lc
, i
))) {
719 /* icon is bigger than buttons */
720 self
->label_width
-= bwidth
+ 2;
722 x
+= i
* (bwidth
+ 2);
724 } else if (*lc
== 'D') {
725 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ALLDESKTOPS
;
726 if ((self
->desk_on
= is_button_present(self
, lc
, i
))) {
727 self
->label_width
-= bwidth
;
731 } else if (*lc
== 'S') {
732 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_SHADE
;
733 if ((self
->shade_on
= is_button_present(self
, lc
, i
))) {
734 self
->label_width
-= bwidth
;
738 } else if (*lc
== 'I') {
739 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICONIFY
;
740 if ((self
->iconify_on
= is_button_present(self
, lc
, i
))) {
741 self
->label_width
-= bwidth
;
745 } else if (*lc
== 'M') {
746 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_MAXIMIZE
;
747 if ((self
->max_on
= is_button_present(self
, lc
, i
))) {
748 self
->label_width
-= bwidth
;
752 } else if (*lc
== 'C') {
753 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_CLOSE
;
754 if ((self
->close_on
= is_button_present(self
, lc
, i
))) {
755 self
->label_width
-= bwidth
;
760 continue; /* don't set firstcon */
765 /* position and map the elements */
767 XMapWindow(ob_display
, self
->icon
);
768 XMoveWindow(ob_display
, self
->icon
, self
->icon_x
,
769 ob_rr_theme
->paddingy
);
771 XUnmapWindow(ob_display
, self
->icon
);
774 XMapWindow(ob_display
, self
->desk
);
775 XMoveWindow(ob_display
, self
->desk
, self
->desk_x
,
776 ob_rr_theme
->paddingy
+ 1);
778 XUnmapWindow(ob_display
, self
->desk
);
780 if (self
->shade_on
) {
781 XMapWindow(ob_display
, self
->shade
);
782 XMoveWindow(ob_display
, self
->shade
, self
->shade_x
,
783 ob_rr_theme
->paddingy
+ 1);
785 XUnmapWindow(ob_display
, self
->shade
);
787 if (self
->iconify_on
) {
788 XMapWindow(ob_display
, self
->iconify
);
789 XMoveWindow(ob_display
, self
->iconify
, self
->iconify_x
,
790 ob_rr_theme
->paddingy
+ 1);
792 XUnmapWindow(ob_display
, self
->iconify
);
795 XMapWindow(ob_display
, self
->max
);
796 XMoveWindow(ob_display
, self
->max
, self
->max_x
,
797 ob_rr_theme
->paddingy
+ 1);
799 XUnmapWindow(ob_display
, self
->max
);
801 if (self
->close_on
) {
802 XMapWindow(ob_display
, self
->close
);
803 XMoveWindow(ob_display
, self
->close
, self
->close_x
,
804 ob_rr_theme
->paddingy
+ 1);
806 XUnmapWindow(ob_display
, self
->close
);
808 if (self
->label_on
) {
809 self
->label_width
= MAX(1, self
->label_width
); /* no lower than 1 */
810 XMapWindow(ob_display
, self
->label
);
811 XMoveWindow(ob_display
, self
->label
, self
->label_x
,
812 ob_rr_theme
->paddingy
);
814 XUnmapWindow(ob_display
, self
->label
);
817 ObFrameContext
frame_context_from_string(const gchar
*name
)
819 if (!g_ascii_strcasecmp("Desktop", name
))
820 return OB_FRAME_CONTEXT_DESKTOP
;
821 else if (!g_ascii_strcasecmp("Client", name
))
822 return OB_FRAME_CONTEXT_CLIENT
;
823 else if (!g_ascii_strcasecmp("Titlebar", name
))
824 return OB_FRAME_CONTEXT_TITLEBAR
;
825 else if (!g_ascii_strcasecmp("Frame", name
))
826 return OB_FRAME_CONTEXT_FRAME
;
827 else if (!g_ascii_strcasecmp("TLCorner", name
))
828 return OB_FRAME_CONTEXT_TLCORNER
;
829 else if (!g_ascii_strcasecmp("TRCorner", name
))
830 return OB_FRAME_CONTEXT_TRCORNER
;
831 else if (!g_ascii_strcasecmp("BLCorner", name
))
832 return OB_FRAME_CONTEXT_BLCORNER
;
833 else if (!g_ascii_strcasecmp("BRCorner", name
))
834 return OB_FRAME_CONTEXT_BRCORNER
;
835 else if (!g_ascii_strcasecmp("Top", name
))
836 return OB_FRAME_CONTEXT_TOP
;
837 else if (!g_ascii_strcasecmp("Bottom", name
))
838 return OB_FRAME_CONTEXT_BOTTOM
;
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
, gint x
, gint y
)
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
->title
) {
884 /* when the user clicks in the corners of the titlebar and the client
885 is fully maximized, then treat it like they clicked in the
886 button that is there */
887 if (self
->client
->max_horz
&& self
->client
->max_vert
&&
888 y
< ob_rr_theme
->paddingy
+ 1 + ob_rr_theme
->button_size
)
890 if (x
< ((ob_rr_theme
->paddingx
+ 1) * 2 +
891 ob_rr_theme
->button_size
)) {
892 if (self
->leftmost
!= OB_FRAME_CONTEXT_NONE
)
893 return self
->leftmost
;
895 else if (x
> (self
->width
-
896 (ob_rr_theme
->paddingx
+ 1 +
897 ob_rr_theme
->button_size
)))
899 if (self
->rightmost
!= OB_FRAME_CONTEXT_NONE
)
900 return self
->rightmost
;
903 return OB_FRAME_CONTEXT_TITLEBAR
;
906 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
907 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
908 if (win
== self
->handle
) return OB_FRAME_CONTEXT_BOTTOM
;
909 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
910 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
911 if (win
== self
->topresize
) return OB_FRAME_CONTEXT_TOP
;
912 if (win
== self
->tltresize
) return OB_FRAME_CONTEXT_TLCORNER
;
913 if (win
== self
->tllresize
) return OB_FRAME_CONTEXT_TLCORNER
;
914 if (win
== self
->trtresize
) return OB_FRAME_CONTEXT_TRCORNER
;
915 if (win
== self
->trrresize
) return OB_FRAME_CONTEXT_TRCORNER
;
916 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
917 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
918 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
919 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
920 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
921 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
923 return OB_FRAME_CONTEXT_NONE
;
926 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
929 switch (self
->client
->gravity
) {
931 case NorthWestGravity
:
932 case SouthWestGravity
:
939 *x
-= (self
->size
.left
+ w
) / 2;
942 case NorthEastGravity
:
943 case SouthEastGravity
:
945 *x
-= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
950 *x
-= self
->size
.left
;
955 switch (self
->client
->gravity
) {
957 case NorthWestGravity
:
958 case NorthEastGravity
:
965 *y
-= (self
->size
.top
+ h
) / 2;
968 case SouthWestGravity
:
969 case SouthEastGravity
:
971 *y
-= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
976 *y
-= self
->size
.top
;
981 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
984 switch (self
->client
->gravity
) {
986 case NorthWestGravity
:
988 case SouthWestGravity
:
993 *x
+= (self
->size
.left
+ w
) / 2;
995 case NorthEastGravity
:
997 case SouthEastGravity
:
998 *x
+= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
1002 *x
+= self
->size
.left
;
1007 switch (self
->client
->gravity
) {
1009 case NorthWestGravity
:
1011 case NorthEastGravity
:
1016 *y
+= (self
->size
.top
+ h
) / 2;
1018 case SouthWestGravity
:
1020 case SouthEastGravity
:
1021 *y
+= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
1025 *y
+= self
->size
.top
;
1030 static void flash_done(gpointer data
)
1032 ObFrame
*self
= data
;
1034 if (self
->focused
!= self
->flash_on
)
1035 frame_adjust_focus(self
, self
->focused
);
1038 static gboolean
flash_timeout(gpointer data
)
1040 ObFrame
*self
= data
;
1043 g_get_current_time(&now
);
1044 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
1045 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
1046 now
.tv_usec
>= self
->flash_end
.tv_usec
))
1047 self
->flashing
= FALSE
;
1049 if (!self
->flashing
)
1050 return FALSE
; /* we are done */
1052 self
->flash_on
= !self
->flash_on
;
1053 if (!self
->focused
) {
1054 frame_adjust_focus(self
, self
->flash_on
);
1055 self
->focused
= FALSE
;
1058 return TRUE
; /* go again */
1061 void frame_flash_start(ObFrame
*self
)
1063 self
->flash_on
= self
->focused
;
1065 if (!self
->flashing
)
1066 ob_main_loop_timeout_add(ob_main_loop
,
1067 G_USEC_PER_SEC
* 0.6,
1072 g_get_current_time(&self
->flash_end
);
1073 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
1075 self
->flashing
= TRUE
;
1078 void frame_flash_stop(ObFrame
*self
)
1080 self
->flashing
= FALSE
;
1083 static gulong
frame_animate_iconify_time_left(ObFrame
*self
,
1084 const GTimeVal
*now
)
1087 sec
= self
->iconify_animation_end
.tv_sec
- now
->tv_sec
;
1088 usec
= self
->iconify_animation_end
.tv_usec
- now
->tv_usec
;
1090 usec
+= G_USEC_PER_SEC
;
1093 /* no negative values */
1094 return MAX(sec
* G_USEC_PER_SEC
+ usec
, 0);
1097 static gboolean
frame_animate_iconify(gpointer p
)
1101 gint iconx
, icony
, iconw
;
1104 gboolean iconifying
;
1106 if (self
->client
->icon_geometry
.width
== 0) {
1107 /* there is no icon geometry set so just go straight down */
1108 Rect
*a
= screen_physical_area();
1109 iconx
= self
->area
.x
+ self
->area
.width
/ 2 + 32;
1110 icony
= a
->y
+ a
->width
;
1113 iconx
= self
->client
->icon_geometry
.x
;
1114 icony
= self
->client
->icon_geometry
.y
;
1115 iconw
= self
->client
->icon_geometry
.width
;
1118 iconifying
= self
->iconify_animation_going
> 0;
1120 /* how far do we have left to go ? */
1121 g_get_current_time(&now
);
1122 time
= frame_animate_iconify_time_left(self
, &now
);
1124 if (time
== 0 || iconifying
) {
1125 /* start where the frame is supposed to be */
1128 w
= self
->area
.width
- self
->bwidth
* 2;
1129 h
= self
->area
.height
- self
->bwidth
* 2;
1131 /* start at the icon */
1135 h
= self
->innersize
.top
; /* just the titlebar */
1142 dx
= self
->area
.x
- iconx
;
1143 dy
= self
->area
.y
- icony
;
1144 dw
= self
->area
.width
- self
->bwidth
* 2 - iconw
;
1145 /* if restoring, we move in the opposite direction */
1146 if (!iconifying
) { dx
= -dx
; dy
= -dy
; dw
= -dw
; }
1148 elapsed
= FRAME_ANIMATE_ICONIFY_TIME
- time
;
1149 x
= x
- (dx
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1150 y
= y
- (dy
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1151 w
= w
- (dw
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1152 h
= self
->innersize
.top
; /* just the titlebar */
1156 frame_end_iconify_animation(self
);
1158 XMoveResizeWindow(ob_display
, self
->window
, x
, y
, w
, h
);
1162 return time
> 0; /* repeat until we're out of time */
1165 void frame_end_iconify_animation(ObFrame
*self
)
1167 /* see if there is an animation going */
1168 if (self
->iconify_animation_going
== 0) return;
1171 XUnmapWindow(ob_display
, self
->window
);
1173 /* we're not animating any more ! */
1174 self
->iconify_animation_going
= 0;
1176 XMoveResizeWindow(ob_display
, self
->window
,
1177 self
->area
.x
, self
->area
.y
,
1178 self
->area
.width
- self
->bwidth
* 2,
1179 self
->area
.height
- self
->bwidth
* 2);
1183 void frame_begin_iconify_animation(ObFrame
*self
, gboolean iconifying
)
1186 gboolean new_anim
= FALSE
;
1187 gboolean set_end
= TRUE
;
1190 /* if there is no titlebar, just don't animate for now
1191 XXX it would be nice tho.. */
1192 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1195 /* get the current time */
1196 g_get_current_time(&now
);
1198 /* get how long until the end */
1199 time
= FRAME_ANIMATE_ICONIFY_TIME
;
1200 if (self
->iconify_animation_going
) {
1201 if (!!iconifying
!= (self
->iconify_animation_going
> 0)) {
1202 /* animation was already going on in the opposite direction */
1203 time
= time
- frame_animate_iconify_time_left(self
, &now
);
1205 /* animation was already going in the same direction */
1209 self
->iconify_animation_going
= iconifying
? 1 : -1;
1211 /* set the ending time */
1213 self
->iconify_animation_end
.tv_sec
= now
.tv_sec
;
1214 self
->iconify_animation_end
.tv_usec
= now
.tv_usec
;
1215 g_time_val_add(&self
->iconify_animation_end
, time
);
1219 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
1221 ob_main_loop_timeout_add(ob_main_loop
,
1222 FRAME_ANIMATE_ICONIFY_STEP_TIME
,
1223 frame_animate_iconify
, self
,
1224 g_direct_equal
, NULL
);
1226 /* do the first step */
1227 frame_animate_iconify(self
);
1229 /* show it during the animation even if it is not "visible" */
1231 XMapWindow(ob_display
, self
->window
);