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 /* 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);
102 self
->client
= client
;
104 visual
= check_32bit_client(client
);
106 /* create the non-visible decor windows */
110 /* client has a 32-bit visual */
111 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
112 /* create a colormap with the visual */
113 self
->colormap
= attrib
.colormap
=
114 XCreateColormap(ob_display
,
115 RootWindow(ob_display
, ob_screen
),
117 attrib
.background_pixel
= BlackPixel(ob_display
, 0);
118 attrib
.border_pixel
= BlackPixel(ob_display
, 0);
120 attrib
.event_mask
= FRAME_EVENTMASK
;
121 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
), visual
,
124 attrib
.event_mask
= INNER_EVENTMASK
;
125 self
->inner
= createWindow(self
->window
, visual
, mask
, &attrib
);
127 mask
&= ~CWEventMask
;
128 self
->plate
= createWindow(self
->inner
, visual
, mask
, &attrib
);
130 /* create the visible decor windows */
134 /* client has a 32-bit visual */
135 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
136 attrib
.colormap
= RrColormap(ob_rr_inst
);
138 attrib
.event_mask
= ELEMENT_EVENTMASK
;
139 self
->title
= createWindow(self
->window
, NULL
, mask
, &attrib
);
142 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHWEST
);
143 self
->tltresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
144 self
->tllresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
145 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHEAST
);
146 self
->trtresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
147 self
->trrresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
150 self
->label
= createWindow(self
->title
, NULL
, mask
, &attrib
);
151 self
->max
= createWindow(self
->title
, NULL
, mask
, &attrib
);
152 self
->close
= createWindow(self
->title
, NULL
, mask
, &attrib
);
153 self
->desk
= createWindow(self
->title
, NULL
, mask
, &attrib
);
154 self
->shade
= createWindow(self
->title
, NULL
, mask
, &attrib
);
155 self
->icon
= createWindow(self
->title
, NULL
, mask
, &attrib
);
156 self
->iconify
= createWindow(self
->title
, NULL
, mask
, &attrib
);
157 self
->handle
= createWindow(self
->window
, NULL
, mask
, &attrib
);
160 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHWEST
);
161 self
->lgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
162 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHEAST
);
163 self
->rgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
165 self
->focused
= FALSE
;
167 /* the other stuff is shown based on decor settings */
168 XMapWindow(ob_display
, self
->plate
);
169 XMapWindow(ob_display
, self
->inner
);
170 XMapWindow(ob_display
, self
->lgrip
);
171 XMapWindow(ob_display
, self
->rgrip
);
172 XMapWindow(ob_display
, self
->label
);
174 self
->max_press
= self
->close_press
= self
->desk_press
=
175 self
->iconify_press
= self
->shade_press
= FALSE
;
176 self
->max_hover
= self
->close_hover
= self
->desk_hover
=
177 self
->iconify_hover
= self
->shade_hover
= FALSE
;
179 set_theme_statics(self
);
181 return (ObFrame
*)self
;
184 static void set_theme_statics(ObFrame
*self
)
186 /* set colors/appearance/sizes for stuff that doesn't change */
187 XSetWindowBorder(ob_display
, self
->window
,
188 RrColorPixel(ob_rr_theme
->frame_b_color
));
189 XSetWindowBorder(ob_display
, self
->inner
,
190 RrColorPixel(ob_rr_theme
->frame_b_color
));
191 XSetWindowBorder(ob_display
, self
->title
,
192 RrColorPixel(ob_rr_theme
->frame_b_color
));
193 XSetWindowBorder(ob_display
, self
->handle
,
194 RrColorPixel(ob_rr_theme
->frame_b_color
));
195 XSetWindowBorder(ob_display
, self
->rgrip
,
196 RrColorPixel(ob_rr_theme
->frame_b_color
));
197 XSetWindowBorder(ob_display
, self
->lgrip
,
198 RrColorPixel(ob_rr_theme
->frame_b_color
));
200 XResizeWindow(ob_display
, self
->max
,
201 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
202 XResizeWindow(ob_display
, self
->iconify
,
203 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
204 XResizeWindow(ob_display
, self
->icon
,
205 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
206 XResizeWindow(ob_display
, self
->close
,
207 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
208 XResizeWindow(ob_display
, self
->desk
,
209 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
210 XResizeWindow(ob_display
, self
->shade
,
211 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
212 if (ob_rr_theme
->handle_height
> 0) {
213 XResizeWindow(ob_display
, self
->lgrip
,
214 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
215 XResizeWindow(ob_display
, self
->rgrip
,
216 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
218 XResizeWindow(ob_display
, self
->tltresize
,
219 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
220 XResizeWindow(ob_display
, self
->trtresize
,
221 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
222 XResizeWindow(ob_display
, self
->tllresize
,
223 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
224 XResizeWindow(ob_display
, self
->trrresize
,
225 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
227 /* set up the dynamic appearances */
228 self
->a_unfocused_title
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_title
);
229 self
->a_focused_title
= RrAppearanceCopy(ob_rr_theme
->a_focused_title
);
230 self
->a_unfocused_label
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_label
);
231 self
->a_focused_label
= RrAppearanceCopy(ob_rr_theme
->a_focused_label
);
232 self
->a_unfocused_handle
=
233 RrAppearanceCopy(ob_rr_theme
->a_unfocused_handle
);
234 self
->a_focused_handle
= RrAppearanceCopy(ob_rr_theme
->a_focused_handle
);
235 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_icon
);
238 static void free_theme_statics(ObFrame
*self
)
240 RrAppearanceFree(self
->a_unfocused_title
);
241 RrAppearanceFree(self
->a_focused_title
);
242 RrAppearanceFree(self
->a_unfocused_label
);
243 RrAppearanceFree(self
->a_focused_label
);
244 RrAppearanceFree(self
->a_unfocused_handle
);
245 RrAppearanceFree(self
->a_focused_handle
);
246 RrAppearanceFree(self
->a_icon
);
249 void frame_free(ObFrame
*self
)
251 free_theme_statics(self
);
253 XDestroyWindow(ob_display
, self
->window
);
255 XFreeColormap(ob_display
, self
->colormap
);
260 void frame_show(ObFrame
*self
)
262 if (!self
->visible
) {
263 self
->visible
= TRUE
;
264 XMapWindow(ob_display
, self
->client
->window
);
265 XMapWindow(ob_display
, self
->window
);
269 void frame_hide(ObFrame
*self
)
272 self
->visible
= FALSE
;
273 if (!frame_iconify_animating(self
))
274 XUnmapWindow(ob_display
, self
->window
);
275 /* we unmap the client itself so that we can get MapRequest
276 events, and because the ICCCM tells us to! */
277 XUnmapWindow(ob_display
, self
->client
->window
);
278 self
->client
->ignore_unmaps
+= 1;
282 void frame_adjust_theme(ObFrame
*self
)
284 free_theme_statics(self
);
285 set_theme_statics(self
);
288 void frame_adjust_shape(ObFrame
*self
)
294 if (!self
->client
->shaped
) {
295 /* clear the shape on the frame window */
296 XShapeCombineMask(ob_display
, self
->window
, ShapeBounding
,
297 self
->innersize
.left
,
301 /* make the frame's shape match the clients */
302 XShapeCombineShape(ob_display
, self
->window
, ShapeBounding
,
303 self
->innersize
.left
,
305 self
->client
->window
,
306 ShapeBounding
, ShapeSet
);
309 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
310 xrect
[0].x
= -ob_rr_theme
->fbwidth
;
311 xrect
[0].y
= -ob_rr_theme
->fbwidth
;
312 xrect
[0].width
= self
->width
+ self
->rbwidth
* 2;
313 xrect
[0].height
= ob_rr_theme
->title_height
+
318 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
) {
319 xrect
[1].x
= -ob_rr_theme
->fbwidth
;
320 xrect
[1].y
= FRAME_HANDLE_Y(self
);
321 xrect
[1].width
= self
->width
+ self
->rbwidth
* 2;
322 xrect
[1].height
= ob_rr_theme
->handle_height
+
327 XShapeCombineRectangles(ob_display
, self
->window
,
328 ShapeBounding
, 0, 0, xrect
, num
,
329 ShapeUnion
, Unsorted
);
334 void frame_adjust_area(ObFrame
*self
, gboolean moved
,
335 gboolean resized
, gboolean fake
)
339 oldsize
= self
->size
;
342 self
->decorations
= self
->client
->decorations
;
343 self
->max_horz
= self
->client
->max_horz
;
345 if (self
->decorations
& OB_FRAME_DECOR_BORDER
) {
346 self
->bwidth
= ob_rr_theme
->fbwidth
;
347 self
->cbwidth_x
= ob_rr_theme
->cbwidthx
;
348 self
->cbwidth_y
= ob_rr_theme
->cbwidthy
;
350 self
->bwidth
= self
->cbwidth_x
= self
->cbwidth_y
= 0;
352 self
->rbwidth
= self
->bwidth
;
355 self
->bwidth
= self
->cbwidth_x
= 0;
357 STRUT_SET(self
->innersize
,
362 self
->width
= self
->client
->area
.width
+ self
->cbwidth_x
* 2 -
363 (self
->max_horz
? self
->rbwidth
* 2 : 0);
364 self
->width
= MAX(self
->width
, 1); /* no lower than 1 */
366 /* set border widths */
368 XSetWindowBorderWidth(ob_display
, self
->window
, self
->bwidth
);
369 XSetWindowBorderWidth(ob_display
, self
->inner
, self
->bwidth
);
370 XSetWindowBorderWidth(ob_display
, self
->title
, self
->rbwidth
);
371 XSetWindowBorderWidth(ob_display
, self
->handle
, self
->rbwidth
);
372 XSetWindowBorderWidth(ob_display
, self
->lgrip
, self
->rbwidth
);
373 XSetWindowBorderWidth(ob_display
, self
->rgrip
, self
->rbwidth
);
376 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
377 self
->innersize
.top
+= ob_rr_theme
->title_height
+ self
->rbwidth
+
378 (self
->rbwidth
- self
->bwidth
);
379 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
380 ob_rr_theme
->handle_height
> 0)
381 self
->innersize
.bottom
+= ob_rr_theme
->handle_height
+
382 self
->rbwidth
+ (self
->rbwidth
- self
->bwidth
);
384 /* position/size and map/unmap all the windows */
387 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
388 XMoveResizeWindow(ob_display
, self
->title
,
389 -self
->bwidth
, -self
->bwidth
,
390 self
->width
, ob_rr_theme
->title_height
);
391 XMapWindow(ob_display
, self
->title
);
393 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
394 XMoveWindow(ob_display
, self
->tltresize
, 0, 0);
395 XMoveWindow(ob_display
, self
->tllresize
, 0, 0);
396 XMoveWindow(ob_display
, self
->trtresize
,
397 self
->width
- ob_rr_theme
->grip_width
, 0);
398 XMoveWindow(ob_display
, self
->trrresize
,
399 self
->width
- ob_rr_theme
->paddingx
- 1, 0);
400 XMapWindow(ob_display
, self
->tltresize
);
401 XMapWindow(ob_display
, self
->tllresize
);
402 XMapWindow(ob_display
, self
->trtresize
);
403 XMapWindow(ob_display
, self
->trrresize
);
405 XUnmapWindow(ob_display
, self
->tltresize
);
406 XUnmapWindow(ob_display
, self
->tllresize
);
407 XUnmapWindow(ob_display
, self
->trtresize
);
408 XUnmapWindow(ob_display
, self
->trrresize
);
411 XUnmapWindow(ob_display
, self
->title
);
414 if ((self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
415 /* layout the title bar elements */
419 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
420 ob_rr_theme
->handle_height
> 0)
422 XMoveResizeWindow(ob_display
, self
->handle
,
423 -self
->bwidth
, FRAME_HANDLE_Y(self
),
424 self
->width
, ob_rr_theme
->handle_height
);
425 XMapWindow(ob_display
, self
->handle
);
427 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
428 XMoveWindow(ob_display
, self
->lgrip
,
429 -self
->rbwidth
, -self
->rbwidth
);
430 XMoveWindow(ob_display
, self
->rgrip
,
431 -self
->rbwidth
+ self
->width
-
432 ob_rr_theme
->grip_width
, -self
->rbwidth
);
433 XMapWindow(ob_display
, self
->lgrip
);
434 XMapWindow(ob_display
, self
->rgrip
);
436 XUnmapWindow(ob_display
, self
->lgrip
);
437 XUnmapWindow(ob_display
, self
->rgrip
);
440 XUnmapWindow(ob_display
, self
->handle
);
442 /* move and resize the inner border window which contains the plate
444 XMoveResizeWindow(ob_display
, self
->inner
,
445 self
->innersize
.left
- self
->cbwidth_x
-
447 self
->innersize
.top
- self
->cbwidth_y
-
449 self
->client
->area
.width
+
451 self
->client
->area
.height
+
452 self
->cbwidth_y
* 2);
455 XMoveWindow(ob_display
, self
->plate
,
456 self
->cbwidth_x
, self
->cbwidth_y
);
458 /* when the client has StaticGravity, it likes to move around. */
459 XMoveWindow(ob_display
, self
->client
->window
, 0, 0);
462 STRUT_SET(self
->size
,
463 self
->innersize
.left
+ self
->bwidth
,
464 self
->innersize
.top
+ self
->bwidth
,
465 self
->innersize
.right
+ self
->bwidth
,
466 self
->innersize
.bottom
+ self
->bwidth
);
469 /* shading can change without being moved or resized */
470 RECT_SET_SIZE(self
->area
,
471 self
->client
->area
.width
+
472 self
->size
.left
+ self
->size
.right
,
473 (self
->client
->shaded
?
474 ob_rr_theme
->title_height
+ self
->rbwidth
* 2:
475 self
->client
->area
.height
+
476 self
->size
.top
+ self
->size
.bottom
));
478 if (moved
|| resized
) {
479 /* find the new coordinates, done after setting the frame.size, for
480 frame_client_gravity. */
481 self
->area
.x
= self
->client
->area
.x
;
482 self
->area
.y
= self
->client
->area
.y
;
483 frame_client_gravity(self
, &self
->area
.x
, &self
->area
.y
,
484 self
->client
->area
.width
,
485 self
->client
->area
.height
);
489 if (!frame_iconify_animating(self
))
490 /* move and resize the top level frame.
491 shading can change without being moved or resized.
493 but don't do this during an iconify animation. it will be
494 reflected afterwards.
496 XMoveResizeWindow(ob_display
, self
->window
,
497 self
->area
.x
, self
->area
.y
,
498 self
->area
.width
- self
->bwidth
* 2,
499 self
->area
.height
- self
->bwidth
* 2);
502 framerender_frame(self
);
503 frame_adjust_shape(self
);
506 if (!STRUT_EQUAL(self
->size
, oldsize
)) {
508 vals
[0] = self
->size
.left
;
509 vals
[1] = self
->size
.right
;
510 vals
[2] = self
->size
.top
;
511 vals
[3] = self
->size
.bottom
;
512 PROP_SETA32(self
->client
->window
, net_frame_extents
,
514 PROP_SETA32(self
->client
->window
, kde_net_wm_frame_strut
,
518 /* if this occurs while we are focus cycling, the indicator needs to
520 if (focus_cycle_target
== self
->client
)
521 focus_cycle_draw_indicator();
523 if (resized
&& (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
524 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
525 ob_rr_theme
->label_height
);
528 void frame_adjust_client_area(ObFrame
*self
)
530 /* resize the plate */
531 XResizeWindow(ob_display
, self
->plate
,
532 self
->client
->area
.width
, self
->client
->area
.height
);
535 void frame_adjust_state(ObFrame
*self
)
537 framerender_frame(self
);
540 void frame_adjust_focus(ObFrame
*self
, gboolean hilite
)
542 self
->focused
= hilite
;
543 framerender_frame(self
);
547 void frame_adjust_title(ObFrame
*self
)
549 framerender_frame(self
);
552 void frame_adjust_icon(ObFrame
*self
)
554 framerender_frame(self
);
557 void frame_grab_client(ObFrame
*self
)
559 /* reparent the client to the frame */
560 XReparentWindow(ob_display
, self
->client
->window
, self
->plate
, 0, 0);
562 When reparenting the client window, it is usually not mapped yet, since
563 this occurs from a MapRequest. However, in the case where Openbox is
564 starting up, the window is already mapped, so we'll see unmap events for
565 it. There are 2 unmap events generated that we see, one with the 'event'
566 member set the root window, and one set to the client, but both get
567 handled and need to be ignored.
569 if (ob_state() == OB_STATE_STARTING
)
570 self
->client
->ignore_unmaps
+= 2;
572 /* select the event mask on the client's parent (to receive config/map
573 req's) the ButtonPress is to catch clicks on the client border */
574 XSelectInput(ob_display
, self
->plate
, PLATE_EVENTMASK
);
576 /* map the client so it maps when the frame does */
577 XMapWindow(ob_display
, self
->client
->window
);
579 /* adjust the frame to the client's size */
580 frame_adjust_area(self
, FALSE
, TRUE
, FALSE
);
582 /* set all the windows for the frame in the window_map */
583 g_hash_table_insert(window_map
, &self
->window
, self
->client
);
584 g_hash_table_insert(window_map
, &self
->plate
, self
->client
);
585 g_hash_table_insert(window_map
, &self
->inner
, self
->client
);
586 g_hash_table_insert(window_map
, &self
->title
, self
->client
);
587 g_hash_table_insert(window_map
, &self
->label
, self
->client
);
588 g_hash_table_insert(window_map
, &self
->max
, self
->client
);
589 g_hash_table_insert(window_map
, &self
->close
, self
->client
);
590 g_hash_table_insert(window_map
, &self
->desk
, self
->client
);
591 g_hash_table_insert(window_map
, &self
->shade
, self
->client
);
592 g_hash_table_insert(window_map
, &self
->icon
, self
->client
);
593 g_hash_table_insert(window_map
, &self
->iconify
, self
->client
);
594 g_hash_table_insert(window_map
, &self
->handle
, self
->client
);
595 g_hash_table_insert(window_map
, &self
->lgrip
, self
->client
);
596 g_hash_table_insert(window_map
, &self
->rgrip
, self
->client
);
597 g_hash_table_insert(window_map
, &self
->tltresize
, self
->client
);
598 g_hash_table_insert(window_map
, &self
->tllresize
, self
->client
);
599 g_hash_table_insert(window_map
, &self
->trtresize
, self
->client
);
600 g_hash_table_insert(window_map
, &self
->trrresize
, self
->client
);
603 void frame_release_client(ObFrame
*self
)
606 gboolean reparent
= TRUE
;
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
, self
->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
, self
->client
->window
,
634 RootWindow(ob_display
, ob_screen
),
635 self
->client
->area
.x
,
636 self
->client
->area
.y
);
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
);
662 /* is there anything present between us and the label? */
663 static gboolean
is_button_present(ObFrame
*self
, const gchar
*lc
, gint dir
) {
664 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+= dir
) {
665 if (*lc
== ' ') continue; /* it was invalid */
666 if (*lc
== 'N' && self
->decorations
& OB_FRAME_DECOR_ICON
)
668 if (*lc
== 'D' && self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
)
670 if (*lc
== 'S' && self
->decorations
& OB_FRAME_DECOR_SHADE
)
672 if (*lc
== 'I' && self
->decorations
& OB_FRAME_DECOR_ICONIFY
)
674 if (*lc
== 'M' && self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
)
676 if (*lc
== 'C' && self
->decorations
& OB_FRAME_DECOR_CLOSE
)
678 if (*lc
== 'L') return FALSE
;
683 static void layout_title(ObFrame
*self
)
688 const gint bwidth
= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
689 /* position of the left most button */
690 const gint left
= ob_rr_theme
->paddingx
+ 1;
691 /* position of the right most button */
692 const gint right
= self
->width
- bwidth
;
694 /* turn them all off */
695 self
->icon_on
= self
->desk_on
= self
->shade_on
= self
->iconify_on
=
696 self
->max_on
= self
->close_on
= self
->label_on
= FALSE
;
697 self
->label_width
= self
->width
- (ob_rr_theme
->paddingx
+ 1) * 2;
698 self
->leftmost
= self
->rightmost
= OB_FRAME_CONTEXT_NONE
;
700 /* figure out what's being show, find each element's position, and the
703 do the ones before the label, then after the label,
704 i will be +1 the first time through when working to the left,
705 and -1 the second time through when working to the right */
706 for (i
= 1; i
>= -1; i
-=2) {
708 ObFrameContext
*firstcon
;
712 lc
= config_title_layout
;
713 firstcon
= &self
->leftmost
;
716 lc
= config_title_layout
+ strlen(config_title_layout
)-1;
717 firstcon
= &self
->rightmost
;
720 /* stop at the end of the string (or the label, which calls break) */
721 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+=i
) {
724 self
->label_on
= TRUE
;
727 break; /* break the for loop, do other side of label */
728 } else if (*lc
== 'N') {
729 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICON
;
730 if ((self
->icon_on
= is_button_present(self
, lc
, i
))) {
731 /* icon is bigger than buttons */
732 self
->label_width
-= bwidth
+ 2;
734 x
+= i
* (bwidth
+ 2);
736 } else if (*lc
== 'D') {
737 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ALLDESKTOPS
;
738 if ((self
->desk_on
= is_button_present(self
, lc
, i
))) {
739 self
->label_width
-= bwidth
;
743 } else if (*lc
== 'S') {
744 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_SHADE
;
745 if ((self
->shade_on
= is_button_present(self
, lc
, i
))) {
746 self
->label_width
-= bwidth
;
750 } else if (*lc
== 'I') {
751 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICONIFY
;
752 if ((self
->iconify_on
= is_button_present(self
, lc
, i
))) {
753 self
->label_width
-= bwidth
;
757 } else if (*lc
== 'M') {
758 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_MAXIMIZE
;
759 if ((self
->max_on
= is_button_present(self
, lc
, i
))) {
760 self
->label_width
-= bwidth
;
764 } else if (*lc
== 'C') {
765 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_CLOSE
;
766 if ((self
->close_on
= is_button_present(self
, lc
, i
))) {
767 self
->label_width
-= bwidth
;
772 continue; /* don't set firstcon */
777 /* position and map the elements */
779 XMapWindow(ob_display
, self
->icon
);
780 XMoveWindow(ob_display
, self
->icon
, self
->icon_x
,
781 ob_rr_theme
->paddingy
);
783 XUnmapWindow(ob_display
, self
->icon
);
786 XMapWindow(ob_display
, self
->desk
);
787 XMoveWindow(ob_display
, self
->desk
, self
->desk_x
,
788 ob_rr_theme
->paddingy
+ 1);
790 XUnmapWindow(ob_display
, self
->desk
);
792 if (self
->shade_on
) {
793 XMapWindow(ob_display
, self
->shade
);
794 XMoveWindow(ob_display
, self
->shade
, self
->shade_x
,
795 ob_rr_theme
->paddingy
+ 1);
797 XUnmapWindow(ob_display
, self
->shade
);
799 if (self
->iconify_on
) {
800 XMapWindow(ob_display
, self
->iconify
);
801 XMoveWindow(ob_display
, self
->iconify
, self
->iconify_x
,
802 ob_rr_theme
->paddingy
+ 1);
804 XUnmapWindow(ob_display
, self
->iconify
);
807 XMapWindow(ob_display
, self
->max
);
808 XMoveWindow(ob_display
, self
->max
, self
->max_x
,
809 ob_rr_theme
->paddingy
+ 1);
811 XUnmapWindow(ob_display
, self
->max
);
813 if (self
->close_on
) {
814 XMapWindow(ob_display
, self
->close
);
815 XMoveWindow(ob_display
, self
->close
, self
->close_x
,
816 ob_rr_theme
->paddingy
+ 1);
818 XUnmapWindow(ob_display
, self
->close
);
820 if (self
->label_on
) {
821 self
->label_width
= MAX(1, self
->label_width
); /* no lower than 1 */
822 XMapWindow(ob_display
, self
->label
);
823 XMoveWindow(ob_display
, self
->label
, self
->label_x
,
824 ob_rr_theme
->paddingy
);
826 XUnmapWindow(ob_display
, self
->label
);
829 ObFrameContext
frame_context_from_string(const gchar
*name
)
831 if (!g_ascii_strcasecmp("Desktop", name
))
832 return OB_FRAME_CONTEXT_DESKTOP
;
833 else if (!g_ascii_strcasecmp("Client", name
))
834 return OB_FRAME_CONTEXT_CLIENT
;
835 else if (!g_ascii_strcasecmp("Titlebar", name
))
836 return OB_FRAME_CONTEXT_TITLEBAR
;
837 else if (!g_ascii_strcasecmp("Handle", name
))
838 return OB_FRAME_CONTEXT_HANDLE
;
839 else if (!g_ascii_strcasecmp("Frame", name
))
840 return OB_FRAME_CONTEXT_FRAME
;
841 else if (!g_ascii_strcasecmp("TLCorner", name
))
842 return OB_FRAME_CONTEXT_TLCORNER
;
843 else if (!g_ascii_strcasecmp("TRCorner", name
))
844 return OB_FRAME_CONTEXT_TRCORNER
;
845 else if (!g_ascii_strcasecmp("BLCorner", name
))
846 return OB_FRAME_CONTEXT_BLCORNER
;
847 else if (!g_ascii_strcasecmp("BRCorner", name
))
848 return OB_FRAME_CONTEXT_BRCORNER
;
849 else if (!g_ascii_strcasecmp("Maximize", name
))
850 return OB_FRAME_CONTEXT_MAXIMIZE
;
851 else if (!g_ascii_strcasecmp("AllDesktops", name
))
852 return OB_FRAME_CONTEXT_ALLDESKTOPS
;
853 else if (!g_ascii_strcasecmp("Shade", name
))
854 return OB_FRAME_CONTEXT_SHADE
;
855 else if (!g_ascii_strcasecmp("Iconify", name
))
856 return OB_FRAME_CONTEXT_ICONIFY
;
857 else if (!g_ascii_strcasecmp("Icon", name
))
858 return OB_FRAME_CONTEXT_ICON
;
859 else if (!g_ascii_strcasecmp("Close", name
))
860 return OB_FRAME_CONTEXT_CLOSE
;
861 else if (!g_ascii_strcasecmp("MoveResize", name
))
862 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
863 return OB_FRAME_CONTEXT_NONE
;
866 ObFrameContext
frame_context(ObClient
*client
, Window win
, gint x
, gint y
)
870 if (moveresize_in_progress
)
871 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
873 if (win
== RootWindow(ob_display
, ob_screen
))
874 return OB_FRAME_CONTEXT_DESKTOP
;
875 if (client
== NULL
) return OB_FRAME_CONTEXT_NONE
;
876 if (win
== client
->window
) {
877 /* conceptually, this is the desktop, as far as users are
879 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
880 return OB_FRAME_CONTEXT_DESKTOP
;
881 return OB_FRAME_CONTEXT_CLIENT
;
884 self
= client
->frame
;
885 if (win
== self
->inner
|| win
== self
->plate
) {
886 /* conceptually, this is the desktop, as far as users are
888 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
889 return OB_FRAME_CONTEXT_DESKTOP
;
890 return OB_FRAME_CONTEXT_CLIENT
;
893 if (win
== self
->title
) {
894 /* when the user clicks in the corners of the titlebar and the client
895 is fully maximized, then treat it like they clicked in the
896 button that is there */
897 if (self
->client
->max_horz
&& self
->client
->max_vert
&&
898 y
< ob_rr_theme
->paddingy
+ 1 + ob_rr_theme
->button_size
)
900 if (x
< ((ob_rr_theme
->paddingx
+ 1) * 2 +
901 ob_rr_theme
->button_size
)) {
902 if (self
->leftmost
!= OB_FRAME_CONTEXT_NONE
)
903 return self
->leftmost
;
905 else if (x
> (self
->width
-
906 (ob_rr_theme
->paddingx
+ 1 +
907 ob_rr_theme
->button_size
)))
909 if (self
->rightmost
!= OB_FRAME_CONTEXT_NONE
)
910 return self
->rightmost
;
913 return OB_FRAME_CONTEXT_TITLEBAR
;
916 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
917 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
918 if (win
== self
->handle
) return OB_FRAME_CONTEXT_HANDLE
;
919 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
920 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
921 if (win
== self
->tltresize
) return OB_FRAME_CONTEXT_TLCORNER
;
922 if (win
== self
->tllresize
) return OB_FRAME_CONTEXT_TLCORNER
;
923 if (win
== self
->trtresize
) return OB_FRAME_CONTEXT_TRCORNER
;
924 if (win
== self
->trrresize
) return OB_FRAME_CONTEXT_TRCORNER
;
925 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
926 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
927 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
928 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
929 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
930 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
932 return OB_FRAME_CONTEXT_NONE
;
935 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
938 switch (self
->client
->gravity
) {
940 case NorthWestGravity
:
941 case SouthWestGravity
:
948 *x
-= (self
->size
.left
+ w
) / 2;
951 case NorthEastGravity
:
952 case SouthEastGravity
:
954 *x
-= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
959 *x
-= self
->size
.left
;
964 switch (self
->client
->gravity
) {
966 case NorthWestGravity
:
967 case NorthEastGravity
:
974 *y
-= (self
->size
.top
+ h
) / 2;
977 case SouthWestGravity
:
978 case SouthEastGravity
:
980 *y
-= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
985 *y
-= self
->size
.top
;
990 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
993 switch (self
->client
->gravity
) {
995 case NorthWestGravity
:
997 case SouthWestGravity
:
1002 *x
+= (self
->size
.left
+ w
) / 2;
1004 case NorthEastGravity
:
1006 case SouthEastGravity
:
1007 *x
+= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
1011 *x
+= self
->size
.left
;
1016 switch (self
->client
->gravity
) {
1018 case NorthWestGravity
:
1020 case NorthEastGravity
:
1025 *y
+= (self
->size
.top
+ h
) / 2;
1027 case SouthWestGravity
:
1029 case SouthEastGravity
:
1030 *y
+= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
1034 *y
+= self
->size
.top
;
1039 static void flash_done(gpointer data
)
1041 ObFrame
*self
= data
;
1043 if (self
->focused
!= self
->flash_on
)
1044 frame_adjust_focus(self
, self
->focused
);
1047 static gboolean
flash_timeout(gpointer data
)
1049 ObFrame
*self
= data
;
1052 g_get_current_time(&now
);
1053 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
1054 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
1055 now
.tv_usec
>= self
->flash_end
.tv_usec
))
1056 self
->flashing
= FALSE
;
1058 if (!self
->flashing
)
1059 return FALSE
; /* we are done */
1061 self
->flash_on
= !self
->flash_on
;
1062 if (!self
->focused
) {
1063 frame_adjust_focus(self
, self
->flash_on
);
1064 self
->focused
= FALSE
;
1067 return TRUE
; /* go again */
1070 void frame_flash_start(ObFrame
*self
)
1072 self
->flash_on
= self
->focused
;
1074 if (!self
->flashing
)
1075 ob_main_loop_timeout_add(ob_main_loop
,
1076 G_USEC_PER_SEC
* 0.6,
1081 g_get_current_time(&self
->flash_end
);
1082 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
1084 self
->flashing
= TRUE
;
1087 void frame_flash_stop(ObFrame
*self
)
1089 self
->flashing
= FALSE
;
1092 static gulong
frame_animate_iconify_time_left(ObFrame
*self
,
1093 const GTimeVal
*now
)
1096 sec
= self
->iconify_animation_end
.tv_sec
- now
->tv_sec
;
1097 usec
= self
->iconify_animation_end
.tv_usec
- now
->tv_usec
;
1099 usec
+= G_USEC_PER_SEC
;
1102 /* no negative values */
1103 return MAX(sec
* G_USEC_PER_SEC
+ usec
, 0);
1106 static gboolean
frame_animate_iconify(gpointer p
)
1110 gint iconx
, icony
, iconw
;
1113 gboolean iconifying
;
1115 if (self
->client
->icon_geometry
.width
== 0) {
1116 /* there is no icon geometry set so just go straight down */
1117 Rect
*a
= screen_physical_area();
1118 iconx
= self
->area
.x
+ self
->area
.width
/ 2 + 32;
1119 icony
= a
->y
+ a
->width
;
1122 iconx
= self
->client
->icon_geometry
.x
;
1123 icony
= self
->client
->icon_geometry
.y
;
1124 iconw
= self
->client
->icon_geometry
.width
;
1127 iconifying
= self
->iconify_animation_going
> 0;
1129 /* how far do we have left to go ? */
1130 g_get_current_time(&now
);
1131 time
= frame_animate_iconify_time_left(self
, &now
);
1133 if (time
== 0 || iconifying
) {
1134 /* start where the frame is supposed to be */
1137 w
= self
->area
.width
- self
->bwidth
* 2;
1138 h
= self
->area
.height
- self
->bwidth
* 2;
1140 /* start at the icon */
1144 h
= self
->innersize
.top
; /* just the titlebar */
1151 dx
= self
->area
.x
- iconx
;
1152 dy
= self
->area
.y
- icony
;
1153 dw
= self
->area
.width
- self
->bwidth
* 2 - iconw
;
1154 /* if restoring, we move in the opposite direction */
1155 if (!iconifying
) { dx
= -dx
; dy
= -dy
; dw
= -dw
; }
1157 elapsed
= FRAME_ANIMATE_ICONIFY_TIME
- time
;
1158 x
= x
- (dx
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1159 y
= y
- (dy
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1160 w
= w
- (dw
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1161 h
= self
->innersize
.top
; /* just the titlebar */
1165 frame_end_iconify_animation(self
);
1167 XMoveResizeWindow(ob_display
, self
->window
, x
, y
, w
, h
);
1171 return time
> 0; /* repeat until we're out of time */
1174 void frame_end_iconify_animation(ObFrame
*self
)
1176 /* see if there is an animation going */
1177 if (self
->iconify_animation_going
== 0) return;
1180 XUnmapWindow(ob_display
, self
->window
);
1182 /* we're not animating any more ! */
1183 self
->iconify_animation_going
= 0;
1185 XMoveResizeWindow(ob_display
, self
->window
,
1186 self
->area
.x
, self
->area
.y
,
1187 self
->area
.width
- self
->bwidth
* 2,
1188 self
->area
.height
- self
->bwidth
* 2);
1192 void frame_begin_iconify_animation(ObFrame
*self
, gboolean iconifying
)
1195 gboolean new_anim
= FALSE
;
1196 gboolean set_end
= TRUE
;
1199 /* if there is no titlebar, just don't animate for now
1200 XXX it would be nice tho.. */
1201 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1204 /* get the current time */
1205 g_get_current_time(&now
);
1207 /* get how long until the end */
1208 time
= FRAME_ANIMATE_ICONIFY_TIME
;
1209 if (self
->iconify_animation_going
) {
1210 if (!!iconifying
!= (self
->iconify_animation_going
> 0)) {
1211 /* animation was already going on in the opposite direction */
1212 time
= time
- frame_animate_iconify_time_left(self
, &now
);
1214 /* animation was already going in the same direction */
1218 self
->iconify_animation_going
= iconifying
? 1 : -1;
1220 /* set the ending time */
1222 self
->iconify_animation_end
.tv_sec
= now
.tv_sec
;
1223 self
->iconify_animation_end
.tv_usec
= now
.tv_usec
;
1224 g_time_val_add(&self
->iconify_animation_end
, time
);
1228 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
1230 ob_main_loop_timeout_add(ob_main_loop
,
1231 FRAME_ANIMATE_ICONIFY_STEP_TIME
,
1232 frame_animate_iconify
, self
,
1233 g_direct_equal
, NULL
);
1235 /* do the first step */
1236 frame_animate_iconify(self
);
1238 /* show it during the animation even if it is not "visible" */
1240 XMapWindow(ob_display
, self
->window
);