1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 frame.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
23 #include "extensions.h"
26 #include "framerender.h"
29 #include "moveresize.h"
30 #include "render/theme.h"
32 #define PLATE_EVENTMASK (SubstructureRedirectMask | ButtonPressMask | \
34 #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
35 ButtonPressMask | ButtonReleaseMask | \
37 #define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \
38 ButtonMotionMask | ExposureMask | \
39 EnterWindowMask | LeaveWindowMask)
41 #define FRAME_HANDLE_Y(f) (f->innersize.top + f->client->area.height + \
44 static void layout_title(ObFrame
*self
);
45 static void flash_done(gpointer data
);
46 static gboolean
flash_timeout(gpointer data
);
48 static void set_theme_statics(ObFrame
*self
);
49 static void free_theme_statics(ObFrame
*self
);
51 static Window
createWindow(Window parent
, Visual
*visual
,
52 gulong mask
, XSetWindowAttributes
*attrib
)
54 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
55 (visual
? 32 : RrDepth(ob_rr_inst
)), InputOutput
,
56 (visual
? visual
: RrVisual(ob_rr_inst
)),
61 static Visual
*check_32bit_client(ObClient
*c
)
63 XWindowAttributes wattrib
;
66 ret
= XGetWindowAttributes(ob_display
, c
->window
, &wattrib
);
67 g_assert(ret
!= BadDrawable
);
68 g_assert(ret
!= BadWindow
);
70 if (wattrib
.depth
== 32)
71 return wattrib
.visual
;
75 ObFrame
*frame_new(ObClient
*client
)
77 XSetWindowAttributes attrib
;
82 self
= g_new0(ObFrame
, 1);
84 self
->obscured
= TRUE
;
86 visual
= check_32bit_client(client
);
88 /* create the non-visible decor windows */
92 /* client has a 32-bit visual */
93 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
94 /* create a colormap with the visual */
95 self
->colormap
= attrib
.colormap
=
96 XCreateColormap(ob_display
,
97 RootWindow(ob_display
, ob_screen
),
99 attrib
.background_pixel
= BlackPixel(ob_display
, 0);
100 attrib
.border_pixel
= BlackPixel(ob_display
, 0);
102 attrib
.event_mask
= FRAME_EVENTMASK
;
103 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
), visual
,
105 mask
&= ~CWEventMask
;
106 self
->plate
= createWindow(self
->window
, visual
, mask
, &attrib
);
108 /* create the visible decor windows */
112 /* client has a 32-bit visual */
113 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
114 attrib
.colormap
= RrColormap(ob_rr_inst
);
116 attrib
.event_mask
= ELEMENT_EVENTMASK
;
117 self
->title
= createWindow(self
->window
, NULL
, mask
, &attrib
);
120 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHWEST
);
121 self
->tltresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
122 self
->tllresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
123 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHEAST
);
124 self
->trtresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
125 self
->trrresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
128 self
->label
= createWindow(self
->title
, NULL
, mask
, &attrib
);
129 self
->max
= createWindow(self
->title
, NULL
, mask
, &attrib
);
130 self
->close
= createWindow(self
->title
, NULL
, mask
, &attrib
);
131 self
->desk
= createWindow(self
->title
, NULL
, mask
, &attrib
);
132 self
->shade
= createWindow(self
->title
, NULL
, mask
, &attrib
);
133 self
->icon
= createWindow(self
->title
, NULL
, mask
, &attrib
);
134 self
->iconify
= createWindow(self
->title
, NULL
, mask
, &attrib
);
135 self
->handle
= createWindow(self
->window
, NULL
, mask
, &attrib
);
138 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHWEST
);
139 self
->lgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
140 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHEAST
);
141 self
->rgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
143 self
->focused
= FALSE
;
145 /* the other stuff is shown based on decor settings */
146 XMapWindow(ob_display
, self
->plate
);
147 XMapWindow(ob_display
, self
->lgrip
);
148 XMapWindow(ob_display
, self
->rgrip
);
149 XMapWindow(ob_display
, self
->label
);
151 self
->max_press
= self
->close_press
= self
->desk_press
=
152 self
->iconify_press
= self
->shade_press
= FALSE
;
153 self
->max_hover
= self
->close_hover
= self
->desk_hover
=
154 self
->iconify_hover
= self
->shade_hover
= FALSE
;
156 set_theme_statics(self
);
158 return (ObFrame
*)self
;
161 static void set_theme_statics(ObFrame
*self
)
163 /* set colors/appearance/sizes for stuff that doesn't change */
164 XSetWindowBorder(ob_display
, self
->window
,
165 RrColorPixel(ob_rr_theme
->frame_b_color
));
166 XSetWindowBorder(ob_display
, self
->title
,
167 RrColorPixel(ob_rr_theme
->frame_b_color
));
168 XSetWindowBorder(ob_display
, self
->handle
,
169 RrColorPixel(ob_rr_theme
->frame_b_color
));
170 XSetWindowBorder(ob_display
, self
->rgrip
,
171 RrColorPixel(ob_rr_theme
->frame_b_color
));
172 XSetWindowBorder(ob_display
, self
->lgrip
,
173 RrColorPixel(ob_rr_theme
->frame_b_color
));
175 XResizeWindow(ob_display
, self
->max
,
176 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
177 XResizeWindow(ob_display
, self
->iconify
,
178 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
179 XResizeWindow(ob_display
, self
->icon
,
180 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
181 XResizeWindow(ob_display
, self
->close
,
182 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
183 XResizeWindow(ob_display
, self
->desk
,
184 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
185 XResizeWindow(ob_display
, self
->shade
,
186 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
187 if (ob_rr_theme
->handle_height
> 0) {
188 XResizeWindow(ob_display
, self
->lgrip
,
189 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
190 XResizeWindow(ob_display
, self
->rgrip
,
191 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
193 XResizeWindow(ob_display
, self
->tltresize
,
194 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
195 XResizeWindow(ob_display
, self
->trtresize
,
196 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
197 XResizeWindow(ob_display
, self
->tllresize
,
198 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
199 XResizeWindow(ob_display
, self
->trrresize
,
200 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
202 /* set up the dynamic appearances */
203 self
->a_unfocused_title
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_title
);
204 self
->a_focused_title
= RrAppearanceCopy(ob_rr_theme
->a_focused_title
);
205 self
->a_unfocused_label
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_label
);
206 self
->a_focused_label
= RrAppearanceCopy(ob_rr_theme
->a_focused_label
);
207 self
->a_unfocused_handle
=
208 RrAppearanceCopy(ob_rr_theme
->a_unfocused_handle
);
209 self
->a_focused_handle
= RrAppearanceCopy(ob_rr_theme
->a_focused_handle
);
210 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_icon
);
213 static void free_theme_statics(ObFrame
*self
)
215 RrAppearanceFree(self
->a_unfocused_title
);
216 RrAppearanceFree(self
->a_focused_title
);
217 RrAppearanceFree(self
->a_unfocused_label
);
218 RrAppearanceFree(self
->a_focused_label
);
219 RrAppearanceFree(self
->a_unfocused_handle
);
220 RrAppearanceFree(self
->a_focused_handle
);
221 RrAppearanceFree(self
->a_icon
);
224 static void frame_free(ObFrame
*self
)
226 free_theme_statics(self
);
228 XDestroyWindow(ob_display
, self
->window
);
230 XFreeColormap(ob_display
, self
->colormap
);
235 void frame_show(ObFrame
*self
)
237 if (!self
->visible
) {
238 self
->visible
= TRUE
;
239 XMapWindow(ob_display
, self
->client
->window
);
240 XMapWindow(ob_display
, self
->window
);
241 self
->firstmap
= TRUE
;
245 void frame_hide(ObFrame
*self
)
247 if (self
->visible
|| self
->firstmap
== FALSE
) {
249 self
->visible
= FALSE
;
250 self
->client
->ignore_unmaps
+= 2;
251 /* we unmap the client itself so that we can get MapRequest
252 events, and because the ICCCM tells us to! */
253 XUnmapWindow(ob_display
, self
->window
);
254 XUnmapWindow(ob_display
, self
->client
->window
);
256 /* the frame wasn't visible, but the frame is being hidden now.
257 so we don't need to unmap the frame, but we do need to unmap
259 self
->client
->ignore_unmaps
+= 1;
260 XUnmapWindow(ob_display
, self
->client
->window
);
262 self
->firstmap
= TRUE
;
266 void frame_adjust_theme(ObFrame
*self
)
268 free_theme_statics(self
);
269 set_theme_statics(self
);
272 void frame_adjust_shape(ObFrame
*self
)
278 if (!self
->client
->shaped
) {
279 /* clear the shape on the frame window */
280 XShapeCombineMask(ob_display
, self
->window
, ShapeBounding
,
281 self
->innersize
.left
,
285 /* make the frame's shape match the clients */
286 XShapeCombineShape(ob_display
, self
->window
, ShapeBounding
,
287 self
->innersize
.left
,
289 self
->client
->window
,
290 ShapeBounding
, ShapeSet
);
293 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
294 xrect
[0].x
= -ob_rr_theme
->fbwidth
;
295 xrect
[0].y
= -ob_rr_theme
->fbwidth
;
296 xrect
[0].width
= self
->width
+ self
->rbwidth
* 2;
297 xrect
[0].height
= ob_rr_theme
->title_height
+
302 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
) {
303 xrect
[1].x
= -ob_rr_theme
->fbwidth
;
304 xrect
[1].y
= FRAME_HANDLE_Y(self
);
305 xrect
[1].width
= self
->width
+ self
->rbwidth
* 2;
306 xrect
[1].height
= ob_rr_theme
->handle_height
+
311 XShapeCombineRectangles(ob_display
, self
->window
,
312 ShapeBounding
, 0, 0, xrect
, num
,
313 ShapeUnion
, Unsorted
);
318 void frame_adjust_area(ObFrame
*self
, gboolean moved
,
319 gboolean resized
, gboolean fake
)
323 oldsize
= self
->size
;
326 self
->decorations
= self
->client
->decorations
;
327 self
->max_horz
= self
->client
->max_horz
;
329 if (self
->decorations
& OB_FRAME_DECOR_BORDER
) {
330 self
->bwidth
= ob_rr_theme
->fbwidth
;
331 self
->cbwidth_x
= ob_rr_theme
->cbwidthx
;
332 self
->cbwidth_y
= ob_rr_theme
->cbwidthy
;
334 self
->bwidth
= self
->cbwidth_x
= self
->cbwidth_y
= 0;
336 self
->rbwidth
= self
->bwidth
;
339 self
->bwidth
= self
->cbwidth_x
= 0;
341 STRUT_SET(self
->innersize
,
346 self
->width
= self
->client
->area
.width
+ self
->cbwidth_x
* 2 -
347 (self
->max_horz
? self
->rbwidth
* 2 : 0);
348 self
->width
= MAX(self
->width
, 1); /* no lower than 1 */
350 /* set border widths */
352 XSetWindowBorderWidth(ob_display
, self
->window
, self
->bwidth
);
353 XSetWindowBorderWidth(ob_display
, self
->title
, self
->rbwidth
);
354 XSetWindowBorderWidth(ob_display
, self
->handle
, self
->rbwidth
);
355 XSetWindowBorderWidth(ob_display
, self
->lgrip
, self
->rbwidth
);
356 XSetWindowBorderWidth(ob_display
, self
->rgrip
, self
->rbwidth
);
359 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
360 self
->innersize
.top
+= ob_rr_theme
->title_height
+ self
->rbwidth
+
361 (self
->rbwidth
- self
->bwidth
);
362 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
363 ob_rr_theme
->handle_height
> 0)
364 self
->innersize
.bottom
+= ob_rr_theme
->handle_height
+
365 self
->rbwidth
+ (self
->rbwidth
- self
->bwidth
);
367 /* they all default off, they're turned on in layout_title */
371 self
->iconify_x
= -1;
376 /* position/size and map/unmap all the windows */
379 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
380 XMoveResizeWindow(ob_display
, self
->title
,
381 -self
->bwidth
, -self
->bwidth
,
382 self
->width
, ob_rr_theme
->title_height
);
383 XMapWindow(ob_display
, self
->title
);
385 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
386 XMoveWindow(ob_display
, self
->tltresize
, 0, 0);
387 XMoveWindow(ob_display
, self
->tllresize
, 0, 0);
388 XMoveWindow(ob_display
, self
->trtresize
,
389 self
->width
- ob_rr_theme
->grip_width
, 0);
390 XMoveWindow(ob_display
, self
->trrresize
,
391 self
->width
- ob_rr_theme
->paddingx
- 1, 0);
392 XMapWindow(ob_display
, self
->tltresize
);
393 XMapWindow(ob_display
, self
->tllresize
);
394 XMapWindow(ob_display
, self
->trtresize
);
395 XMapWindow(ob_display
, self
->trrresize
);
397 XUnmapWindow(ob_display
, self
->tltresize
);
398 XUnmapWindow(ob_display
, self
->tllresize
);
399 XUnmapWindow(ob_display
, self
->trtresize
);
400 XUnmapWindow(ob_display
, self
->trrresize
);
403 XUnmapWindow(ob_display
, self
->title
);
406 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
407 /* layout the title bar elements */
411 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
412 ob_rr_theme
->handle_height
> 0)
414 XMoveResizeWindow(ob_display
, self
->handle
,
415 -self
->bwidth
, FRAME_HANDLE_Y(self
),
416 self
->width
, ob_rr_theme
->handle_height
);
417 XMapWindow(ob_display
, self
->handle
);
419 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
420 XMoveWindow(ob_display
, self
->lgrip
,
421 -self
->rbwidth
, -self
->rbwidth
);
422 XMoveWindow(ob_display
, self
->rgrip
,
423 -self
->rbwidth
+ self
->width
-
424 ob_rr_theme
->grip_width
, -self
->rbwidth
);
425 XMapWindow(ob_display
, self
->lgrip
);
426 XMapWindow(ob_display
, self
->rgrip
);
428 XUnmapWindow(ob_display
, self
->lgrip
);
429 XUnmapWindow(ob_display
, self
->rgrip
);
432 XUnmapWindow(ob_display
, self
->handle
);
434 /* move and resize the plate */
435 XMoveResizeWindow(ob_display
, self
->plate
,
436 self
->innersize
.left
- self
->cbwidth_x
,
437 self
->innersize
.top
- self
->cbwidth_y
,
438 self
->client
->area
.width
+ self
->cbwidth_x
* 2,
439 self
->client
->area
.height
+ self
->cbwidth_y
* 2);
440 /* when the client has StaticGravity, it likes to move around. */
441 XMoveWindow(ob_display
, self
->client
->window
,
442 self
->cbwidth_x
, self
->cbwidth_y
);
445 STRUT_SET(self
->size
,
446 self
->innersize
.left
+ self
->bwidth
,
447 self
->innersize
.top
+ self
->bwidth
,
448 self
->innersize
.right
+ self
->bwidth
,
449 self
->innersize
.bottom
+ self
->bwidth
);
452 /* shading can change without being moved or resized */
453 RECT_SET_SIZE(self
->area
,
454 self
->client
->area
.width
+
455 self
->size
.left
+ self
->size
.right
,
456 (self
->client
->shaded
?
457 ob_rr_theme
->title_height
+ self
->rbwidth
* 2:
458 self
->client
->area
.height
+
459 self
->size
.top
+ self
->size
.bottom
));
462 /* find the new coordinates, done after setting the frame.size, for
463 frame_client_gravity. */
464 self
->area
.x
= self
->client
->area
.x
;
465 self
->area
.y
= self
->client
->area
.y
;
466 frame_client_gravity(self
, &self
->area
.x
, &self
->area
.y
);
470 /* move and resize the top level frame.
471 shading can change without being moved or resized */
472 XMoveResizeWindow(ob_display
, self
->window
,
473 self
->area
.x
, self
->area
.y
,
474 self
->area
.width
- self
->bwidth
* 2,
475 self
->area
.height
- self
->bwidth
* 2);
478 framerender_frame(self
);
479 frame_adjust_shape(self
);
482 if (!STRUT_EQUAL(self
->size
, oldsize
)) {
484 vals
[0] = self
->size
.left
;
485 vals
[1] = self
->size
.right
;
486 vals
[2] = self
->size
.top
;
487 vals
[3] = self
->size
.bottom
;
488 PROP_SETA32(self
->client
->window
, net_frame_extents
,
492 /* if this occurs while we are focus cycling, the indicator needs to
494 if (focus_cycle_target
== self
->client
)
495 focus_cycle_draw_indicator();
497 if (resized
&& (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
498 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
499 ob_rr_theme
->label_height
);
502 void frame_adjust_state(ObFrame
*self
)
504 framerender_frame(self
);
507 void frame_adjust_focus(ObFrame
*self
, gboolean hilite
)
509 self
->focused
= hilite
;
510 framerender_frame(self
);
513 void frame_adjust_title(ObFrame
*self
)
515 framerender_frame(self
);
518 void frame_adjust_icon(ObFrame
*self
)
520 framerender_frame(self
);
523 void frame_grab_client(ObFrame
*self
, ObClient
*client
)
525 self
->client
= client
;
527 /* reparent the client to the frame */
528 XReparentWindow(ob_display
, client
->window
, self
->plate
, 0, 0);
530 When reparenting the client window, it is usually not mapped yet, since
531 this occurs from a MapRequest. However, in the case where Openbox is
532 starting up, the window is already mapped, so we'll see unmap events for
533 it. There are 2 unmap events generated that we see, one with the 'event'
534 member set the root window, and one set to the client, but both get
535 handled and need to be ignored.
537 if (ob_state() == OB_STATE_STARTING
)
538 client
->ignore_unmaps
+= 2;
540 /* select the event mask on the client's parent (to receive config/map
541 req's) the ButtonPress is to catch clicks on the client border */
542 XSelectInput(ob_display
, self
->plate
, PLATE_EVENTMASK
);
544 frame_adjust_area(self
, TRUE
, TRUE
, FALSE
);
546 /* map the client so it maps when the frame does */
547 XMapWindow(ob_display
, client
->window
);
549 /* set all the windows for the frame in the window_map */
550 g_hash_table_insert(window_map
, &self
->window
, client
);
551 g_hash_table_insert(window_map
, &self
->plate
, client
);
552 g_hash_table_insert(window_map
, &self
->title
, client
);
553 g_hash_table_insert(window_map
, &self
->label
, client
);
554 g_hash_table_insert(window_map
, &self
->max
, client
);
555 g_hash_table_insert(window_map
, &self
->close
, client
);
556 g_hash_table_insert(window_map
, &self
->desk
, client
);
557 g_hash_table_insert(window_map
, &self
->shade
, client
);
558 g_hash_table_insert(window_map
, &self
->icon
, client
);
559 g_hash_table_insert(window_map
, &self
->iconify
, client
);
560 g_hash_table_insert(window_map
, &self
->handle
, client
);
561 g_hash_table_insert(window_map
, &self
->lgrip
, client
);
562 g_hash_table_insert(window_map
, &self
->rgrip
, client
);
563 g_hash_table_insert(window_map
, &self
->tltresize
, client
);
564 g_hash_table_insert(window_map
, &self
->tllresize
, client
);
565 g_hash_table_insert(window_map
, &self
->trtresize
, client
);
566 g_hash_table_insert(window_map
, &self
->trrresize
, client
);
569 void frame_release_client(ObFrame
*self
, ObClient
*client
)
572 gboolean reparent
= TRUE
;
574 g_assert(self
->client
== client
);
576 /* check if the app has already reparented its window away */
577 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
578 ReparentNotify
, &ev
))
580 /* This check makes sure we don't catch our own reparent action to
581 our frame window. This doesn't count as the app reparenting itself
584 Reparent events that are generated by us are just discarded here.
585 They are of no consequence to us anyhow.
587 if (ev
.xreparent
.parent
!= self
->plate
) {
589 XPutBackEvent(ob_display
, &ev
);
595 /* according to the ICCCM - if the client doesn't reparent itself,
596 then we will reparent the window to root for them */
597 XReparentWindow(ob_display
, client
->window
,
598 RootWindow(ob_display
, ob_screen
),
603 /* remove all the windows for the frame from the window_map */
604 g_hash_table_remove(window_map
, &self
->window
);
605 g_hash_table_remove(window_map
, &self
->plate
);
606 g_hash_table_remove(window_map
, &self
->title
);
607 g_hash_table_remove(window_map
, &self
->label
);
608 g_hash_table_remove(window_map
, &self
->max
);
609 g_hash_table_remove(window_map
, &self
->close
);
610 g_hash_table_remove(window_map
, &self
->desk
);
611 g_hash_table_remove(window_map
, &self
->shade
);
612 g_hash_table_remove(window_map
, &self
->icon
);
613 g_hash_table_remove(window_map
, &self
->iconify
);
614 g_hash_table_remove(window_map
, &self
->handle
);
615 g_hash_table_remove(window_map
, &self
->lgrip
);
616 g_hash_table_remove(window_map
, &self
->rgrip
);
617 g_hash_table_remove(window_map
, &self
->tltresize
);
618 g_hash_table_remove(window_map
, &self
->tllresize
);
619 g_hash_table_remove(window_map
, &self
->trtresize
);
620 g_hash_table_remove(window_map
, &self
->trrresize
);
622 ob_main_loop_timeout_remove_data(ob_main_loop
, flash_timeout
, self
, TRUE
);
627 static void layout_title(ObFrame
*self
)
631 gboolean n
, d
, i
, l
, m
, c
, s
;
633 n
= d
= i
= l
= m
= c
= s
= FALSE
;
635 /* figure out whats being shown, and the width of the label */
636 self
->label_width
= self
->width
- (ob_rr_theme
->paddingx
+ 1) * 2;
637 for (lc
= config_title_layout
; *lc
!= '\0'; ++lc
) {
640 if (n
) { *lc
= ' '; break; } /* rm duplicates */
642 self
->label_width
-= (ob_rr_theme
->button_size
+ 2 +
643 ob_rr_theme
->paddingx
+ 1);
646 if (d
) { *lc
= ' '; break; }
647 if (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
)
648 && config_theme_hidedisabled
)
651 self
->label_width
-= (ob_rr_theme
->button_size
+
652 ob_rr_theme
->paddingx
+ 1);
655 if (s
) { *lc
= ' '; break; }
656 if (!(self
->decorations
& OB_FRAME_DECOR_SHADE
)
657 && config_theme_hidedisabled
)
660 self
->label_width
-= (ob_rr_theme
->button_size
+
661 ob_rr_theme
->paddingx
+ 1);
664 if (i
) { *lc
= ' '; break; }
665 if (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
)
666 && config_theme_hidedisabled
)
669 self
->label_width
-= (ob_rr_theme
->button_size
+
670 ob_rr_theme
->paddingx
+ 1);
673 if (l
) { *lc
= ' '; break; }
677 if (m
) { *lc
= ' '; break; }
678 if (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
)
679 && config_theme_hidedisabled
)
682 self
->label_width
-= (ob_rr_theme
->button_size
+
683 ob_rr_theme
->paddingx
+ 1);
686 if (c
) { *lc
= ' '; break; }
687 if (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
)
688 && config_theme_hidedisabled
)
691 self
->label_width
-= (ob_rr_theme
->button_size
+
692 ob_rr_theme
->paddingx
+ 1);
696 if (self
->label_width
< 1) self
->label_width
= 1;
698 if (!n
) XUnmapWindow(ob_display
, self
->icon
);
699 if (!d
) XUnmapWindow(ob_display
, self
->desk
);
700 if (!s
) XUnmapWindow(ob_display
, self
->shade
);
701 if (!i
) XUnmapWindow(ob_display
, self
->iconify
);
702 if (!l
) XUnmapWindow(ob_display
, self
->label
);
703 if (!m
) XUnmapWindow(ob_display
, self
->max
);
704 if (!c
) XUnmapWindow(ob_display
, self
->close
);
706 x
= ob_rr_theme
->paddingx
+ 1;
707 for (lc
= config_title_layout
; *lc
!= '\0'; ++lc
) {
712 XMapWindow(ob_display
, self
->icon
);
713 XMoveWindow(ob_display
, self
->icon
, x
, ob_rr_theme
->paddingy
);
714 x
+= ob_rr_theme
->button_size
+ 2 + ob_rr_theme
->paddingx
+ 1;
719 XMapWindow(ob_display
, self
->desk
);
720 XMoveWindow(ob_display
, self
->desk
, x
, ob_rr_theme
->paddingy
+ 1);
721 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
726 XMapWindow(ob_display
, self
->shade
);
727 XMoveWindow(ob_display
, self
->shade
, x
, ob_rr_theme
->paddingy
+ 1);
728 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
733 XMapWindow(ob_display
, self
->iconify
);
734 XMoveWindow(ob_display
,self
->iconify
, x
, ob_rr_theme
->paddingy
+ 1);
735 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
740 XMapWindow(ob_display
, self
->label
);
741 XMoveWindow(ob_display
, self
->label
, x
, ob_rr_theme
->paddingy
);
742 x
+= self
->label_width
+ ob_rr_theme
->paddingx
+ 1;
747 XMapWindow(ob_display
, self
->max
);
748 XMoveWindow(ob_display
, self
->max
, x
, ob_rr_theme
->paddingy
+ 1);
749 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
754 XMapWindow(ob_display
, self
->close
);
755 XMoveWindow(ob_display
, self
->close
, x
, ob_rr_theme
->paddingy
+ 1);
756 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
762 ObFrameContext
frame_context_from_string(const gchar
*name
)
764 if (!g_ascii_strcasecmp("Desktop", name
))
765 return OB_FRAME_CONTEXT_DESKTOP
;
766 else if (!g_ascii_strcasecmp("Client", name
))
767 return OB_FRAME_CONTEXT_CLIENT
;
768 else if (!g_ascii_strcasecmp("Titlebar", name
))
769 return OB_FRAME_CONTEXT_TITLEBAR
;
770 else if (!g_ascii_strcasecmp("Handle", name
))
771 return OB_FRAME_CONTEXT_HANDLE
;
772 else if (!g_ascii_strcasecmp("Frame", name
))
773 return OB_FRAME_CONTEXT_FRAME
;
774 else if (!g_ascii_strcasecmp("TLCorner", name
))
775 return OB_FRAME_CONTEXT_TLCORNER
;
776 else if (!g_ascii_strcasecmp("TRCorner", name
))
777 return OB_FRAME_CONTEXT_TRCORNER
;
778 else if (!g_ascii_strcasecmp("BLCorner", name
))
779 return OB_FRAME_CONTEXT_BLCORNER
;
780 else if (!g_ascii_strcasecmp("BRCorner", name
))
781 return OB_FRAME_CONTEXT_BRCORNER
;
782 else if (!g_ascii_strcasecmp("Maximize", name
))
783 return OB_FRAME_CONTEXT_MAXIMIZE
;
784 else if (!g_ascii_strcasecmp("AllDesktops", name
))
785 return OB_FRAME_CONTEXT_ALLDESKTOPS
;
786 else if (!g_ascii_strcasecmp("Shade", name
))
787 return OB_FRAME_CONTEXT_SHADE
;
788 else if (!g_ascii_strcasecmp("Iconify", name
))
789 return OB_FRAME_CONTEXT_ICONIFY
;
790 else if (!g_ascii_strcasecmp("Icon", name
))
791 return OB_FRAME_CONTEXT_ICON
;
792 else if (!g_ascii_strcasecmp("Close", name
))
793 return OB_FRAME_CONTEXT_CLOSE
;
794 else if (!g_ascii_strcasecmp("MoveResize", name
))
795 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
796 return OB_FRAME_CONTEXT_NONE
;
799 ObFrameContext
frame_context(ObClient
*client
, Window win
)
803 if (moveresize_in_progress
)
804 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
806 if (win
== RootWindow(ob_display
, ob_screen
))
807 return OB_FRAME_CONTEXT_DESKTOP
;
808 if (client
== NULL
) return OB_FRAME_CONTEXT_NONE
;
809 if (win
== client
->window
) {
810 /* conceptually, this is the desktop, as far as users are
812 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
813 return OB_FRAME_CONTEXT_DESKTOP
;
814 return OB_FRAME_CONTEXT_CLIENT
;
817 self
= client
->frame
;
818 if (win
== self
->plate
) {
819 /* conceptually, this is the desktop, as far as users are
821 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
822 return OB_FRAME_CONTEXT_DESKTOP
;
823 return OB_FRAME_CONTEXT_CLIENT
;
826 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
827 if (win
== self
->title
) return OB_FRAME_CONTEXT_TITLEBAR
;
828 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
829 if (win
== self
->handle
) return OB_FRAME_CONTEXT_HANDLE
;
830 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
831 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
832 if (win
== self
->tltresize
) return OB_FRAME_CONTEXT_TLCORNER
;
833 if (win
== self
->tllresize
) return OB_FRAME_CONTEXT_TLCORNER
;
834 if (win
== self
->trtresize
) return OB_FRAME_CONTEXT_TRCORNER
;
835 if (win
== self
->trrresize
) return OB_FRAME_CONTEXT_TRCORNER
;
836 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
837 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
838 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
839 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
840 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
841 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
843 return OB_FRAME_CONTEXT_NONE
;
846 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
)
849 switch (self
->client
->gravity
) {
851 case NorthWestGravity
:
852 case SouthWestGravity
:
859 *x
-= (self
->size
.left
+ self
->size
.right
) / 2;
862 case NorthEastGravity
:
863 case SouthEastGravity
:
865 *x
-= self
->size
.left
+ self
->size
.right
;
870 *x
-= self
->size
.left
;
875 switch (self
->client
->gravity
) {
877 case NorthWestGravity
:
878 case NorthEastGravity
:
885 *y
-= (self
->size
.top
+ self
->size
.bottom
) / 2;
888 case SouthWestGravity
:
889 case SouthEastGravity
:
891 *y
-= self
->size
.top
+ self
->size
.bottom
;
896 *y
-= self
->size
.top
;
901 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
)
904 switch (self
->client
->gravity
) {
906 case NorthWestGravity
:
908 case SouthWestGravity
:
913 *x
+= (self
->size
.left
+ self
->size
.right
) / 2;
915 case NorthEastGravity
:
917 case SouthEastGravity
:
918 *x
+= self
->size
.left
+ self
->size
.right
;
922 *x
+= self
->size
.left
;
927 switch (self
->client
->gravity
) {
929 case NorthWestGravity
:
931 case NorthEastGravity
:
936 *y
+= (self
->size
.top
+ self
->size
.bottom
) / 2;
938 case SouthWestGravity
:
940 case SouthEastGravity
:
941 *y
+= self
->size
.top
+ self
->size
.bottom
;
945 *y
+= self
->size
.top
;
950 static void flash_done(gpointer data
)
952 ObFrame
*self
= data
;
954 if (self
->focused
!= self
->flash_on
)
955 frame_adjust_focus(self
, self
->focused
);
958 static gboolean
flash_timeout(gpointer data
)
960 ObFrame
*self
= data
;
963 g_get_current_time(&now
);
964 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
965 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
966 now
.tv_usec
>= self
->flash_end
.tv_usec
))
967 self
->flashing
= FALSE
;
970 return FALSE
; /* we are done */
972 self
->flash_on
= !self
->flash_on
;
973 if (!self
->focused
) {
974 frame_adjust_focus(self
, self
->flash_on
);
975 self
->focused
= FALSE
;
978 return TRUE
; /* go again */
981 void frame_flash_start(ObFrame
*self
)
983 self
->flash_on
= self
->focused
;
986 ob_main_loop_timeout_add(ob_main_loop
,
987 G_USEC_PER_SEC
* 0.6,
991 g_get_current_time(&self
->flash_end
);
992 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
994 self
->flashing
= TRUE
;
997 void frame_flash_stop(ObFrame
*self
)
999 self
->flashing
= FALSE
;