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"
28 #include "focus_cycle.h"
29 #include "focus_cycle_indicator.h"
30 #include "moveresize.h"
32 #include "render/theme.h"
34 #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
35 ButtonPressMask | ButtonReleaseMask | \
36 SubstructureRedirectMask | FocusChangeMask)
37 #define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \
38 ButtonMotionMask | PointerMotionMask | \
39 EnterWindowMask | LeaveWindowMask)
41 #define FRAME_ANIMATE_ICONIFY_TIME 150000 /* .15 seconds */
42 #define FRAME_ANIMATE_ICONIFY_STEP_TIME (G_USEC_PER_SEC / 60) /* 60 Hz */
44 #define FRAME_HANDLE_Y(f) (f->size.top + f->client->area.height + f->cbwidth_b)
46 static void flash_done(gpointer data
);
47 static gboolean
flash_timeout(gpointer data
);
49 static void layout_title(ObFrame
*self
);
50 static void set_theme_statics(ObFrame
*self
);
51 static void free_theme_statics(ObFrame
*self
);
52 static gboolean
frame_animate_iconify(gpointer self
);
53 static void frame_adjust_cursors(ObFrame
*self
);
55 static Window
createWindow(Window parent
, Visual
*visual
,
56 gulong mask
, XSetWindowAttributes
*attrib
)
58 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
59 (visual
? 32 : RrDepth(ob_rr_inst
)), InputOutput
,
60 (visual
? visual
: RrVisual(ob_rr_inst
)),
65 static Visual
*check_32bit_client(ObClient
*c
)
67 XWindowAttributes wattrib
;
70 /* we're already running at 32 bit depth, yay. we don't need to use their
72 if (RrDepth(ob_rr_inst
) == 32)
75 ret
= XGetWindowAttributes(ob_display
, c
->window
, &wattrib
);
76 g_assert(ret
!= BadDrawable
);
77 g_assert(ret
!= BadWindow
);
79 if (wattrib
.depth
== 32)
80 return wattrib
.visual
;
84 ObFrame
*frame_new(ObClient
*client
)
86 XSetWindowAttributes attrib
;
91 self
= g_new0(ObFrame
, 1);
92 self
->client
= client
;
94 visual
= check_32bit_client(client
);
96 /* create the non-visible decor windows */
100 /* client has a 32-bit visual */
101 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
102 /* create a colormap with the visual */
103 self
->colormap
= attrib
.colormap
=
104 XCreateColormap(ob_display
,
105 RootWindow(ob_display
, ob_screen
),
107 attrib
.background_pixel
= BlackPixel(ob_display
, ob_screen
);
108 attrib
.border_pixel
= BlackPixel(ob_display
, ob_screen
);
110 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
), visual
,
113 /* create the visible decor windows */
117 /* client has a 32-bit visual */
118 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
119 attrib
.colormap
= RrColormap(ob_rr_inst
);
122 self
->backback
= createWindow(self
->window
, NULL
, mask
, &attrib
);
123 self
->backfront
= createWindow(self
->backback
, NULL
, mask
, &attrib
);
126 attrib
.event_mask
= ELEMENT_EVENTMASK
;
127 self
->title
= createWindow(self
->window
, NULL
, mask
, &attrib
);
128 self
->titleleft
= createWindow(self
->window
, NULL
, mask
, &attrib
);
129 self
->titletop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
130 self
->titletopleft
= createWindow(self
->window
, NULL
, mask
, &attrib
);
131 self
->titletopright
= createWindow(self
->window
, NULL
, mask
, &attrib
);
132 self
->titleright
= createWindow(self
->window
, NULL
, mask
, &attrib
);
133 self
->titlebottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
135 self
->topresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
136 self
->tltresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
137 self
->tllresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
138 self
->trtresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
139 self
->trrresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
141 self
->left
= createWindow(self
->window
, NULL
, mask
, &attrib
);
142 self
->right
= createWindow(self
->window
, NULL
, mask
, &attrib
);
144 self
->innerleft
= createWindow(self
->window
, NULL
, mask
, &attrib
);
145 self
->innertop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
146 self
->innerright
= createWindow(self
->window
, NULL
, mask
, &attrib
);
147 self
->innerbottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
149 self
->label
= createWindow(self
->title
, NULL
, mask
, &attrib
);
150 self
->max
= createWindow(self
->title
, NULL
, mask
, &attrib
);
151 self
->close
= createWindow(self
->title
, NULL
, mask
, &attrib
);
152 self
->desk
= createWindow(self
->title
, NULL
, mask
, &attrib
);
153 self
->shade
= createWindow(self
->title
, NULL
, mask
, &attrib
);
154 self
->icon
= createWindow(self
->title
, NULL
, mask
, &attrib
);
155 self
->iconify
= createWindow(self
->title
, NULL
, mask
, &attrib
);
157 self
->handle
= createWindow(self
->window
, NULL
, mask
, &attrib
);
158 self
->lgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
159 self
->rgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
161 self
->handleleft
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
162 self
->handleright
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
164 self
->handletop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
165 self
->handlebottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
166 self
->lgripleft
= createWindow(self
->window
, NULL
, mask
, &attrib
);
167 self
->lgriptop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
168 self
->lgripbottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
169 self
->rgripright
= createWindow(self
->window
, NULL
, mask
, &attrib
);
170 self
->rgriptop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
171 self
->rgripbottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
173 self
->focused
= FALSE
;
175 /* the other stuff is shown based on decor settings */
176 XMapWindow(ob_display
, self
->label
);
177 XMapWindow(ob_display
, self
->backback
);
178 XMapWindow(ob_display
, self
->backfront
);
180 self
->max_press
= self
->close_press
= self
->desk_press
=
181 self
->iconify_press
= self
->shade_press
= FALSE
;
182 self
->max_hover
= self
->close_hover
= self
->desk_hover
=
183 self
->iconify_hover
= self
->shade_hover
= FALSE
;
185 set_theme_statics(self
);
187 return (ObFrame
*)self
;
190 static void set_theme_statics(ObFrame
*self
)
192 /* set colors/appearance/sizes for stuff that doesn't change */
193 XResizeWindow(ob_display
, self
->max
,
194 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
195 XResizeWindow(ob_display
, self
->iconify
,
196 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
197 XResizeWindow(ob_display
, self
->icon
,
198 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
199 XResizeWindow(ob_display
, self
->close
,
200 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
201 XResizeWindow(ob_display
, self
->desk
,
202 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
203 XResizeWindow(ob_display
, self
->shade
,
204 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
205 XResizeWindow(ob_display
, self
->tltresize
,
206 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
207 XResizeWindow(ob_display
, self
->trtresize
,
208 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
209 XResizeWindow(ob_display
, self
->tllresize
,
210 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
211 XResizeWindow(ob_display
, self
->trrresize
,
212 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
214 /* set up the dynamic appearances */
215 self
->a_unfocused_title
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_title
);
216 self
->a_focused_title
= RrAppearanceCopy(ob_rr_theme
->a_focused_title
);
217 self
->a_unfocused_label
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_label
);
218 self
->a_focused_label
= RrAppearanceCopy(ob_rr_theme
->a_focused_label
);
219 self
->a_unfocused_handle
=
220 RrAppearanceCopy(ob_rr_theme
->a_unfocused_handle
);
221 self
->a_focused_handle
= RrAppearanceCopy(ob_rr_theme
->a_focused_handle
);
222 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_icon
);
225 static void free_theme_statics(ObFrame
*self
)
227 RrAppearanceFree(self
->a_unfocused_title
);
228 RrAppearanceFree(self
->a_focused_title
);
229 RrAppearanceFree(self
->a_unfocused_label
);
230 RrAppearanceFree(self
->a_focused_label
);
231 RrAppearanceFree(self
->a_unfocused_handle
);
232 RrAppearanceFree(self
->a_focused_handle
);
233 RrAppearanceFree(self
->a_icon
);
236 void frame_free(ObFrame
*self
)
238 free_theme_statics(self
);
240 XDestroyWindow(ob_display
, self
->window
);
242 XFreeColormap(ob_display
, self
->colormap
);
247 void frame_show(ObFrame
*self
)
249 if (!self
->visible
) {
250 self
->visible
= TRUE
;
251 XMapWindow(ob_display
, self
->client
->window
);
252 XMapWindow(ob_display
, self
->window
);
256 void frame_hide(ObFrame
*self
)
259 self
->visible
= FALSE
;
260 if (!frame_iconify_animating(self
))
261 XUnmapWindow(ob_display
, self
->window
);
262 /* we unmap the client itself so that we can get MapRequest
263 events, and because the ICCCM tells us to! */
264 XUnmapWindow(ob_display
, self
->client
->window
);
265 self
->client
->ignore_unmaps
+= 1;
269 void frame_adjust_theme(ObFrame
*self
)
271 free_theme_statics(self
);
272 set_theme_statics(self
);
275 void frame_adjust_shape(ObFrame
*self
)
281 if (!self
->client
->shaped
) {
282 /* clear the shape on the frame window */
283 XShapeCombineMask(ob_display
, self
->window
, ShapeBounding
,
288 /* make the frame's shape match the clients */
289 XShapeCombineShape(ob_display
, self
->window
, ShapeBounding
,
292 self
->client
->window
,
293 ShapeBounding
, ShapeSet
);
296 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
299 xrect
[0].width
= self
->area
.width
;
300 xrect
[0].height
= ob_rr_theme
->title_height
+
301 self
->bwidth
+ self
->rbwidth
;
305 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
306 ob_rr_theme
->handle_height
> 0)
309 xrect
[1].y
= FRAME_HANDLE_Y(self
);
310 xrect
[1].width
= self
->area
.width
;
311 xrect
[1].height
= ob_rr_theme
->handle_height
+
316 XShapeCombineRectangles(ob_display
, self
->window
,
317 ShapeBounding
, 0, 0, xrect
, num
,
318 ShapeUnion
, Unsorted
);
323 void frame_adjust_area(ObFrame
*self
, gboolean moved
,
324 gboolean resized
, gboolean fake
)
328 oldsize
= self
->size
;
331 /* do this before changing the frame's status like max_horz max_vert */
332 frame_adjust_cursors(self
);
334 self
->functions
= self
->client
->functions
;
335 self
->decorations
= self
->client
->decorations
;
336 self
->max_horz
= self
->client
->max_horz
;
337 self
->max_vert
= self
->client
->max_vert
;
339 if (self
->decorations
& OB_FRAME_DECOR_BORDER
) {
340 self
->bwidth
= ob_rr_theme
->fbwidth
;
341 self
->cbwidth_l
= self
->cbwidth_r
= ob_rr_theme
->cbwidthx
;
342 self
->cbwidth_t
= self
->cbwidth_b
= ob_rr_theme
->cbwidthy
;
344 self
->bwidth
= self
->cbwidth_l
= self
->cbwidth_t
=
345 self
->cbwidth_r
= self
->cbwidth_b
= 0;
347 self
->rbwidth
= self
->bwidth
;
349 if (self
->max_horz
) {
350 self
->cbwidth_l
= self
->cbwidth_r
= 0;
351 self
->width
= self
->client
->area
.width
- self
->bwidth
* 2;
355 self
->width
= self
->client
->area
.width
+
356 self
->cbwidth_l
+ self
->cbwidth_r
;
358 /* some elements are sized based of the width, so don't let them have
360 self
->width
= MAX(self
->width
,
361 (ob_rr_theme
->grip_width
+ self
->bwidth
) * 2 + 1);
363 STRUT_SET(self
->size
,
364 self
->cbwidth_l
+ (!self
->max_horz
? self
->bwidth
: 0),
365 self
->cbwidth_t
+ self
->bwidth
,
366 self
->cbwidth_r
+ (!self
->max_horz
? self
->bwidth
: 0),
367 self
->cbwidth_b
+ (!self
->max_horz
|| !self
->max_vert
? self
->bwidth
: 0));
369 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
370 self
->size
.top
+= ob_rr_theme
->title_height
+ self
->rbwidth
;
371 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
372 ob_rr_theme
->handle_height
> 0)
374 self
->size
.bottom
+= ob_rr_theme
->handle_height
+ self
->bwidth
;
377 /* position/size and map/unmap all the windows */
380 if (self
->cbwidth_l
) {
381 XMoveResizeWindow(ob_display
, self
->innerleft
,
382 self
->size
.left
- self
->cbwidth_l
,
384 self
->cbwidth_l
, self
->client
->area
.height
);
386 XMapWindow(ob_display
, self
->innerleft
);
388 XUnmapWindow(ob_display
, self
->innerleft
);
390 if (self
->cbwidth_r
) {
391 XMoveResizeWindow(ob_display
, self
->innerright
,
392 self
->size
.left
+ self
->client
->area
.width
,
394 self
->cbwidth_r
, self
->client
->area
.height
);
396 XMapWindow(ob_display
, self
->innerright
);
398 XUnmapWindow(ob_display
, self
->innerright
);
400 if (self
->cbwidth_t
) {
401 XMoveResizeWindow(ob_display
, self
->innertop
,
402 self
->size
.left
- self
->cbwidth_l
,
403 self
->size
.top
- self
->cbwidth_t
,
404 self
->client
->area
.width
+
405 self
->cbwidth_l
+ self
->cbwidth_r
,
408 XMapWindow(ob_display
, self
->innertop
);
410 XUnmapWindow(ob_display
, self
->innertop
);
412 if (self
->cbwidth_b
) {
413 XMoveResizeWindow(ob_display
, self
->innerbottom
,
414 self
->size
.left
- self
->cbwidth_l
,
415 self
->size
.top
+ self
->client
->area
.height
,
416 self
->client
->area
.width
+
417 self
->cbwidth_l
+ self
->cbwidth_r
,
420 XMapWindow(ob_display
, self
->innerbottom
);
422 XUnmapWindow(ob_display
, self
->innerbottom
);
427 /* height of titleleft and titleright */
428 titlesides
= (!self
->max_horz
?
429 ob_rr_theme
->grip_width
:
430 self
->size
.top
- self
->bwidth
);
432 XMoveResizeWindow(ob_display
, self
->titletop
,
433 ob_rr_theme
->grip_width
+ self
->bwidth
, 0,
434 /* width + bwidth*2 - bwidth*2 - grips*2 */
435 self
->width
- ob_rr_theme
->grip_width
* 2,
437 XMoveResizeWindow(ob_display
, self
->titletopleft
,
439 ob_rr_theme
->grip_width
+ self
->bwidth
,
441 XMoveResizeWindow(ob_display
, self
->titletopright
,
442 self
->client
->area
.width
+
443 self
->size
.left
+ self
->size
.right
-
444 ob_rr_theme
->grip_width
- self
->bwidth
,
446 ob_rr_theme
->grip_width
+ self
->bwidth
,
449 if (titlesides
> 0) {
450 XMoveResizeWindow(ob_display
, self
->titleleft
,
454 XMoveResizeWindow(ob_display
, self
->titleright
,
455 self
->client
->area
.width
+
456 self
->size
.left
+ self
->size
.right
-
462 XMapWindow(ob_display
, self
->titleleft
);
463 XMapWindow(ob_display
, self
->titleright
);
465 XUnmapWindow(ob_display
, self
->titleleft
);
466 XUnmapWindow(ob_display
, self
->titleright
);
469 XMapWindow(ob_display
, self
->titletop
);
470 XMapWindow(ob_display
, self
->titletopleft
);
471 XMapWindow(ob_display
, self
->titletopright
);
473 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
&&
476 XMoveResizeWindow(ob_display
, self
->titlebottom
,
478 ob_rr_theme
->title_height
+ self
->bwidth
,
482 XMapWindow(ob_display
, self
->titlebottom
);
484 XUnmapWindow(ob_display
, self
->titlebottom
);
486 XUnmapWindow(ob_display
, self
->titlebottom
);
488 XUnmapWindow(ob_display
, self
->titletop
);
489 XUnmapWindow(ob_display
, self
->titletopleft
);
490 XUnmapWindow(ob_display
, self
->titletopright
);
491 XUnmapWindow(ob_display
, self
->titleleft
);
492 XUnmapWindow(ob_display
, self
->titleright
);
495 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
496 XMoveResizeWindow(ob_display
, self
->title
,
497 self
->bwidth
, self
->bwidth
,
498 self
->width
, ob_rr_theme
->title_height
);
500 XMapWindow(ob_display
, self
->title
);
502 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
503 XMoveResizeWindow(ob_display
, self
->topresize
,
504 ob_rr_theme
->grip_width
,
506 self
->width
- ob_rr_theme
->grip_width
*2,
507 ob_rr_theme
->paddingy
+ 1);
509 XMoveWindow(ob_display
, self
->tltresize
, 0, 0);
510 XMoveWindow(ob_display
, self
->tllresize
, 0, 0);
511 XMoveWindow(ob_display
, self
->trtresize
,
512 self
->width
- ob_rr_theme
->grip_width
, 0);
513 XMoveWindow(ob_display
, self
->trrresize
,
514 self
->width
- ob_rr_theme
->paddingx
- 1, 0);
516 XMapWindow(ob_display
, self
->topresize
);
517 XMapWindow(ob_display
, self
->tltresize
);
518 XMapWindow(ob_display
, self
->tllresize
);
519 XMapWindow(ob_display
, self
->trtresize
);
520 XMapWindow(ob_display
, self
->trrresize
);
522 XUnmapWindow(ob_display
, self
->topresize
);
523 XUnmapWindow(ob_display
, self
->tltresize
);
524 XUnmapWindow(ob_display
, self
->tllresize
);
525 XUnmapWindow(ob_display
, self
->trtresize
);
526 XUnmapWindow(ob_display
, self
->trrresize
);
529 XUnmapWindow(ob_display
, self
->title
);
532 if ((self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
533 /* layout the title bar elements */
537 if (self
->bwidth
&& self
->size
.bottom
) {
538 XMoveResizeWindow(ob_display
, self
->handlebottom
,
539 ob_rr_theme
->grip_width
+
541 self
->size
.top
+ self
->client
->area
.height
+
542 self
->size
.bottom
- self
->bwidth
,
543 self
->width
- (ob_rr_theme
->grip_width
+
547 XMoveResizeWindow(ob_display
, self
->lgripleft
,
549 self
->size
.top
+ self
->client
->area
.height
+
552 ob_rr_theme
->grip_width
:
553 self
->size
.bottom
- self
->cbwidth_b
),
556 ob_rr_theme
->grip_width
:
557 self
->size
.bottom
- self
->cbwidth_b
));
558 XMoveResizeWindow(ob_display
, self
->rgripright
,
559 self
->size
.left
+ self
->client
->area
.width
+
560 self
->size
.right
- self
->bwidth
,
561 self
->size
.top
+ self
->client
->area
.height
+
564 ob_rr_theme
->grip_width
:
565 self
->size
.bottom
- self
->cbwidth_b
),
568 ob_rr_theme
->grip_width
:
569 self
->size
.bottom
- self
->cbwidth_b
));
571 XMoveResizeWindow(ob_display
, self
->lgripbottom
,
573 self
->size
.top
+ self
->client
->area
.height
+
574 self
->size
.bottom
- self
->bwidth
,
575 ob_rr_theme
->grip_width
+ self
->bwidth
,
577 XMoveResizeWindow(ob_display
, self
->rgripbottom
,
578 self
->size
.left
+ self
->client
->area
.width
+
579 self
->size
.right
- self
->bwidth
* 2 -
580 ob_rr_theme
->grip_width
,
581 self
->size
.top
+ self
->client
->area
.height
+
582 self
->size
.bottom
- self
->bwidth
,
583 ob_rr_theme
->grip_width
+ self
->bwidth
,
586 XMapWindow(ob_display
, self
->handlebottom
);
587 XMapWindow(ob_display
, self
->lgripleft
);
588 XMapWindow(ob_display
, self
->rgripright
);
589 XMapWindow(ob_display
, self
->lgripbottom
);
590 XMapWindow(ob_display
, self
->rgripbottom
);
592 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
593 ob_rr_theme
->handle_height
> 0)
595 XMoveResizeWindow(ob_display
, self
->handletop
,
596 ob_rr_theme
->grip_width
+
598 FRAME_HANDLE_Y(self
),
599 self
->width
- (ob_rr_theme
->grip_width
+
602 XMapWindow(ob_display
, self
->handletop
);
604 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
605 XMoveResizeWindow(ob_display
, self
->handleleft
,
606 ob_rr_theme
->grip_width
,
609 ob_rr_theme
->handle_height
);
610 XMoveResizeWindow(ob_display
, self
->handleright
,
612 ob_rr_theme
->grip_width
-
616 ob_rr_theme
->handle_height
);
618 XMoveResizeWindow(ob_display
, self
->lgriptop
,
620 FRAME_HANDLE_Y(self
),
621 ob_rr_theme
->grip_width
+
624 XMoveResizeWindow(ob_display
, self
->rgriptop
,
626 self
->client
->area
.width
+
627 self
->size
.right
- self
->bwidth
* 2 -
628 ob_rr_theme
->grip_width
,
629 FRAME_HANDLE_Y(self
),
630 ob_rr_theme
->grip_width
+
634 XMapWindow(ob_display
, self
->handleleft
);
635 XMapWindow(ob_display
, self
->handleright
);
636 XMapWindow(ob_display
, self
->lgriptop
);
637 XMapWindow(ob_display
, self
->rgriptop
);
639 XUnmapWindow(ob_display
, self
->handleleft
);
640 XUnmapWindow(ob_display
, self
->handleright
);
641 XUnmapWindow(ob_display
, self
->lgriptop
);
642 XUnmapWindow(ob_display
, self
->rgriptop
);
645 XUnmapWindow(ob_display
, self
->handleleft
);
646 XUnmapWindow(ob_display
, self
->handleright
);
647 XUnmapWindow(ob_display
, self
->lgriptop
);
648 XUnmapWindow(ob_display
, self
->rgriptop
);
650 XUnmapWindow(ob_display
, self
->handletop
);
653 XUnmapWindow(ob_display
, self
->handleleft
);
654 XUnmapWindow(ob_display
, self
->handleright
);
655 XUnmapWindow(ob_display
, self
->lgriptop
);
656 XUnmapWindow(ob_display
, self
->rgriptop
);
658 XUnmapWindow(ob_display
, self
->handletop
);
660 XUnmapWindow(ob_display
, self
->handlebottom
);
661 XUnmapWindow(ob_display
, self
->lgripleft
);
662 XUnmapWindow(ob_display
, self
->rgripright
);
663 XUnmapWindow(ob_display
, self
->lgripbottom
);
664 XUnmapWindow(ob_display
, self
->rgripbottom
);
667 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
668 ob_rr_theme
->handle_height
> 0)
670 XMoveResizeWindow(ob_display
, self
->handle
,
672 FRAME_HANDLE_Y(self
) + self
->bwidth
,
673 self
->width
, ob_rr_theme
->handle_height
);
674 XMapWindow(ob_display
, self
->handle
);
676 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
677 XMoveResizeWindow(ob_display
, self
->lgrip
,
679 ob_rr_theme
->grip_width
,
680 ob_rr_theme
->handle_height
);
681 XMoveResizeWindow(ob_display
, self
->rgrip
,
682 self
->width
- ob_rr_theme
->grip_width
,
684 ob_rr_theme
->grip_width
,
685 ob_rr_theme
->handle_height
);
687 XMapWindow(ob_display
, self
->lgrip
);
688 XMapWindow(ob_display
, self
->rgrip
);
690 XUnmapWindow(ob_display
, self
->lgrip
);
691 XUnmapWindow(ob_display
, self
->rgrip
);
694 XUnmapWindow(ob_display
, self
->lgrip
);
695 XUnmapWindow(ob_display
, self
->rgrip
);
697 XUnmapWindow(ob_display
, self
->handle
);
700 if (self
->bwidth
&& !self
->max_horz
) {
701 XMoveResizeWindow(ob_display
, self
->left
,
703 self
->bwidth
+ ob_rr_theme
->grip_width
,
705 self
->client
->area
.height
+
706 self
->size
.top
+ self
->size
.bottom
-
707 ob_rr_theme
->grip_width
* 2);
709 XMapWindow(ob_display
, self
->left
);
711 XUnmapWindow(ob_display
, self
->left
);
713 if (self
->bwidth
&& !self
->max_horz
) {
714 XMoveResizeWindow(ob_display
, self
->right
,
715 self
->client
->area
.width
+
716 self
->cbwidth_l
+ self
->cbwidth_r
+ self
->bwidth
,
717 self
->bwidth
+ ob_rr_theme
->grip_width
,
719 self
->client
->area
.height
+
720 self
->size
.top
+ self
->size
.bottom
-
721 ob_rr_theme
->grip_width
* 2);
723 XMapWindow(ob_display
, self
->right
);
725 XUnmapWindow(ob_display
, self
->right
);
727 XMoveResizeWindow(ob_display
, self
->backback
,
728 self
->size
.left
, self
->size
.top
,
729 self
->client
->area
.width
,
730 self
->client
->area
.height
);
734 /* shading can change without being moved or resized */
735 RECT_SET_SIZE(self
->area
,
736 self
->client
->area
.width
+
737 self
->size
.left
+ self
->size
.right
,
738 (self
->client
->shaded
?
739 ob_rr_theme
->title_height
+ self
->bwidth
* 2:
740 self
->client
->area
.height
+
741 self
->size
.top
+ self
->size
.bottom
));
743 if ((moved
|| resized
) && !fake
) {
744 /* find the new coordinates, done after setting the frame.size, for
745 frame_client_gravity. */
746 self
->area
.x
= self
->client
->area
.x
;
747 self
->area
.y
= self
->client
->area
.y
;
748 frame_client_gravity(self
, &self
->area
.x
, &self
->area
.y
,
749 self
->client
->area
.width
,
750 self
->client
->area
.height
);
754 if (!frame_iconify_animating(self
))
755 /* move and resize the top level frame.
756 shading can change without being moved or resized.
758 but don't do this during an iconify animation. it will be
759 reflected afterwards.
761 XMoveResizeWindow(ob_display
, self
->window
,
767 /* when the client has StaticGravity, it likes to move around. */
768 XMoveWindow(ob_display
, self
->client
->window
,
769 self
->size
.left
, self
->size
.top
);
772 framerender_frame(self
);
773 frame_adjust_shape(self
);
776 if (!STRUT_EQUAL(self
->size
, oldsize
)) {
778 vals
[0] = self
->size
.left
;
779 vals
[1] = self
->size
.right
;
780 vals
[2] = self
->size
.top
;
781 vals
[3] = self
->size
.bottom
;
782 PROP_SETA32(self
->client
->window
, net_frame_extents
,
784 PROP_SETA32(self
->client
->window
, kde_net_wm_frame_strut
,
788 /* if this occurs while we are focus cycling, the indicator needs to
790 if (focus_cycle_target
== self
->client
)
791 focus_cycle_draw_indicator(self
->client
);
793 if (resized
&& (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
794 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
795 ob_rr_theme
->label_height
);
799 static void frame_adjust_cursors(ObFrame
*self
)
801 if ((self
->functions
& OB_CLIENT_FUNC_RESIZE
) !=
802 (self
->client
->functions
& OB_CLIENT_FUNC_RESIZE
) ||
803 self
->max_horz
!= self
->client
->max_horz
||
804 self
->max_vert
!= self
->client
->max_vert
)
806 gboolean r
= (self
->client
->functions
& OB_CLIENT_FUNC_RESIZE
) &&
807 !(self
->client
->max_horz
&& self
->client
->max_vert
);
808 gboolean topbot
= !self
->client
->max_vert
;
809 XSetWindowAttributes a
;
811 /* these ones turn off when max vert */
812 a
.cursor
= ob_cursor(r
&& topbot
? OB_CURSOR_NORTH
: OB_CURSOR_NONE
);
813 XChangeWindowAttributes(ob_display
, self
->topresize
, CWCursor
, &a
);
814 XChangeWindowAttributes(ob_display
, self
->titletop
, CWCursor
, &a
);
815 a
.cursor
= ob_cursor(r
&& topbot
? OB_CURSOR_SOUTH
: OB_CURSOR_NONE
);
816 XChangeWindowAttributes(ob_display
, self
->handle
, CWCursor
, &a
);
817 XChangeWindowAttributes(ob_display
, self
->handletop
, CWCursor
, &a
);
818 XChangeWindowAttributes(ob_display
, self
->handlebottom
, CWCursor
, &a
);
819 XChangeWindowAttributes(ob_display
, self
->innerbottom
, CWCursor
, &a
);
821 /* these ones don't */
822 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTHWEST
: OB_CURSOR_NONE
);
823 XChangeWindowAttributes(ob_display
, self
->tltresize
, CWCursor
, &a
);
824 XChangeWindowAttributes(ob_display
, self
->tllresize
, CWCursor
, &a
);
825 XChangeWindowAttributes(ob_display
, self
->titletopleft
, CWCursor
, &a
);
826 XChangeWindowAttributes(ob_display
, self
->titleleft
, CWCursor
, &a
);
827 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTHEAST
: OB_CURSOR_NONE
);
828 XChangeWindowAttributes(ob_display
, self
->trtresize
, CWCursor
, &a
);
829 XChangeWindowAttributes(ob_display
, self
->trrresize
, CWCursor
, &a
);
830 XChangeWindowAttributes(ob_display
, self
->titletopright
, CWCursor
, &a
);
831 XChangeWindowAttributes(ob_display
, self
->titleright
, CWCursor
, &a
);
832 a
.cursor
= ob_cursor(r
? OB_CURSOR_WEST
: OB_CURSOR_NONE
);
833 XChangeWindowAttributes(ob_display
, self
->left
, CWCursor
, &a
);
834 XChangeWindowAttributes(ob_display
, self
->innerleft
, CWCursor
, &a
);
835 a
.cursor
= ob_cursor(r
? OB_CURSOR_EAST
: OB_CURSOR_NONE
);
836 XChangeWindowAttributes(ob_display
, self
->right
, CWCursor
, &a
);
837 XChangeWindowAttributes(ob_display
, self
->innerright
, CWCursor
, &a
);
838 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTHWEST
: OB_CURSOR_NONE
);
839 XChangeWindowAttributes(ob_display
, self
->lgrip
, CWCursor
, &a
);
840 XChangeWindowAttributes(ob_display
, self
->handleleft
, CWCursor
, &a
);
841 XChangeWindowAttributes(ob_display
, self
->lgripleft
, CWCursor
, &a
);
842 XChangeWindowAttributes(ob_display
, self
->lgriptop
, CWCursor
, &a
);
843 XChangeWindowAttributes(ob_display
, self
->lgripbottom
, CWCursor
, &a
);
844 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTHEAST
: OB_CURSOR_NONE
);
845 XChangeWindowAttributes(ob_display
, self
->rgrip
, CWCursor
, &a
);
846 XChangeWindowAttributes(ob_display
, self
->handleright
, CWCursor
, &a
);
847 XChangeWindowAttributes(ob_display
, self
->rgripright
, CWCursor
, &a
);
848 XChangeWindowAttributes(ob_display
, self
->rgriptop
, CWCursor
, &a
);
849 XChangeWindowAttributes(ob_display
, self
->rgripbottom
, CWCursor
, &a
);
853 void frame_adjust_client_area(ObFrame
*self
)
855 /* adjust the window which is there to prevent flashing on unmap */
856 XMoveResizeWindow(ob_display
, self
->backfront
, 0, 0,
857 self
->client
->area
.width
,
858 self
->client
->area
.height
);
861 void frame_adjust_state(ObFrame
*self
)
863 framerender_frame(self
);
866 void frame_adjust_focus(ObFrame
*self
, gboolean hilite
)
868 self
->focused
= hilite
;
869 framerender_frame(self
);
873 void frame_adjust_title(ObFrame
*self
)
875 framerender_frame(self
);
878 void frame_adjust_icon(ObFrame
*self
)
880 framerender_frame(self
);
883 void frame_grab_client(ObFrame
*self
)
885 /* DO NOT map the client window here. we used to do that, but it is bogus.
886 we need to set up the client's dimensions and everything before we
887 send a mapnotify or we create race conditions.
890 /* reparent the client to the frame */
891 XReparentWindow(ob_display
, self
->client
->window
, self
->window
, 0, 0);
894 When reparenting the client window, it is usually not mapped yet, since
895 this occurs from a MapRequest. However, in the case where Openbox is
896 starting up, the window is already mapped, so we'll see an unmap event
899 if (ob_state() == OB_STATE_STARTING
)
900 ++self
->client
->ignore_unmaps
;
902 /* select the event mask on the client's parent (to receive config/map
903 req's) the ButtonPress is to catch clicks on the client border */
904 XSelectInput(ob_display
, self
->window
, FRAME_EVENTMASK
);
906 /* set all the windows for the frame in the window_map */
907 g_hash_table_insert(window_map
, &self
->window
, self
->client
);
908 g_hash_table_insert(window_map
, &self
->backback
, self
->client
);
909 g_hash_table_insert(window_map
, &self
->backfront
, self
->client
);
910 g_hash_table_insert(window_map
, &self
->innerleft
, self
->client
);
911 g_hash_table_insert(window_map
, &self
->innertop
, self
->client
);
912 g_hash_table_insert(window_map
, &self
->innerright
, self
->client
);
913 g_hash_table_insert(window_map
, &self
->innerbottom
, self
->client
);
914 g_hash_table_insert(window_map
, &self
->title
, self
->client
);
915 g_hash_table_insert(window_map
, &self
->label
, self
->client
);
916 g_hash_table_insert(window_map
, &self
->max
, self
->client
);
917 g_hash_table_insert(window_map
, &self
->close
, self
->client
);
918 g_hash_table_insert(window_map
, &self
->desk
, self
->client
);
919 g_hash_table_insert(window_map
, &self
->shade
, self
->client
);
920 g_hash_table_insert(window_map
, &self
->icon
, self
->client
);
921 g_hash_table_insert(window_map
, &self
->iconify
, self
->client
);
922 g_hash_table_insert(window_map
, &self
->handle
, self
->client
);
923 g_hash_table_insert(window_map
, &self
->lgrip
, self
->client
);
924 g_hash_table_insert(window_map
, &self
->rgrip
, self
->client
);
925 g_hash_table_insert(window_map
, &self
->topresize
, self
->client
);
926 g_hash_table_insert(window_map
, &self
->tltresize
, self
->client
);
927 g_hash_table_insert(window_map
, &self
->tllresize
, self
->client
);
928 g_hash_table_insert(window_map
, &self
->trtresize
, self
->client
);
929 g_hash_table_insert(window_map
, &self
->trrresize
, self
->client
);
930 g_hash_table_insert(window_map
, &self
->left
, self
->client
);
931 g_hash_table_insert(window_map
, &self
->right
, self
->client
);
932 g_hash_table_insert(window_map
, &self
->titleleft
, self
->client
);
933 g_hash_table_insert(window_map
, &self
->titletop
, self
->client
);
934 g_hash_table_insert(window_map
, &self
->titletopleft
, self
->client
);
935 g_hash_table_insert(window_map
, &self
->titletopright
, self
->client
);
936 g_hash_table_insert(window_map
, &self
->titleright
, self
->client
);
937 g_hash_table_insert(window_map
, &self
->titlebottom
, self
->client
);
938 g_hash_table_insert(window_map
, &self
->handleleft
, self
->client
);
939 g_hash_table_insert(window_map
, &self
->handletop
, self
->client
);
940 g_hash_table_insert(window_map
, &self
->handleright
, self
->client
);
941 g_hash_table_insert(window_map
, &self
->handlebottom
, self
->client
);
942 g_hash_table_insert(window_map
, &self
->lgripleft
, self
->client
);
943 g_hash_table_insert(window_map
, &self
->lgriptop
, self
->client
);
944 g_hash_table_insert(window_map
, &self
->lgripbottom
, self
->client
);
945 g_hash_table_insert(window_map
, &self
->rgripright
, self
->client
);
946 g_hash_table_insert(window_map
, &self
->rgriptop
, self
->client
);
947 g_hash_table_insert(window_map
, &self
->rgripbottom
, self
->client
);
950 void frame_release_client(ObFrame
*self
)
953 gboolean reparent
= TRUE
;
955 /* if there was any animation going on, kill it */
956 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
959 /* check if the app has already reparented its window away */
960 while (XCheckTypedWindowEvent(ob_display
, self
->client
->window
,
961 ReparentNotify
, &ev
))
963 /* This check makes sure we don't catch our own reparent action to
964 our frame window. This doesn't count as the app reparenting itself
967 Reparent events that are generated by us are just discarded here.
968 They are of no consequence to us anyhow.
970 if (ev
.xreparent
.parent
!= self
->window
) {
972 XPutBackEvent(ob_display
, &ev
);
978 /* according to the ICCCM - if the client doesn't reparent itself,
979 then we will reparent the window to root for them */
980 XReparentWindow(ob_display
, self
->client
->window
,
981 RootWindow(ob_display
, ob_screen
),
982 self
->client
->area
.x
,
983 self
->client
->area
.y
);
986 /* remove all the windows for the frame from the window_map */
987 g_hash_table_remove(window_map
, &self
->window
);
988 g_hash_table_remove(window_map
, &self
->backback
);
989 g_hash_table_remove(window_map
, &self
->backfront
);
990 g_hash_table_remove(window_map
, &self
->innerleft
);
991 g_hash_table_remove(window_map
, &self
->innertop
);
992 g_hash_table_remove(window_map
, &self
->innerright
);
993 g_hash_table_remove(window_map
, &self
->innerbottom
);
994 g_hash_table_remove(window_map
, &self
->title
);
995 g_hash_table_remove(window_map
, &self
->label
);
996 g_hash_table_remove(window_map
, &self
->max
);
997 g_hash_table_remove(window_map
, &self
->close
);
998 g_hash_table_remove(window_map
, &self
->desk
);
999 g_hash_table_remove(window_map
, &self
->shade
);
1000 g_hash_table_remove(window_map
, &self
->icon
);
1001 g_hash_table_remove(window_map
, &self
->iconify
);
1002 g_hash_table_remove(window_map
, &self
->handle
);
1003 g_hash_table_remove(window_map
, &self
->lgrip
);
1004 g_hash_table_remove(window_map
, &self
->rgrip
);
1005 g_hash_table_remove(window_map
, &self
->topresize
);
1006 g_hash_table_remove(window_map
, &self
->tltresize
);
1007 g_hash_table_remove(window_map
, &self
->tllresize
);
1008 g_hash_table_remove(window_map
, &self
->trtresize
);
1009 g_hash_table_remove(window_map
, &self
->trrresize
);
1010 g_hash_table_remove(window_map
, &self
->left
);
1011 g_hash_table_remove(window_map
, &self
->right
);
1012 g_hash_table_remove(window_map
, &self
->titleleft
);
1013 g_hash_table_remove(window_map
, &self
->titletop
);
1014 g_hash_table_remove(window_map
, &self
->titletopleft
);
1015 g_hash_table_remove(window_map
, &self
->titletopright
);
1016 g_hash_table_remove(window_map
, &self
->titleright
);
1017 g_hash_table_remove(window_map
, &self
->titlebottom
);
1018 g_hash_table_remove(window_map
, &self
->handleleft
);
1019 g_hash_table_remove(window_map
, &self
->handletop
);
1020 g_hash_table_remove(window_map
, &self
->handleright
);
1021 g_hash_table_remove(window_map
, &self
->handlebottom
);
1022 g_hash_table_remove(window_map
, &self
->lgripleft
);
1023 g_hash_table_remove(window_map
, &self
->lgriptop
);
1024 g_hash_table_remove(window_map
, &self
->lgripbottom
);
1025 g_hash_table_remove(window_map
, &self
->rgripright
);
1026 g_hash_table_remove(window_map
, &self
->rgriptop
);
1027 g_hash_table_remove(window_map
, &self
->rgripbottom
);
1029 ob_main_loop_timeout_remove_data(ob_main_loop
, flash_timeout
, self
, TRUE
);
1032 /* is there anything present between us and the label? */
1033 static gboolean
is_button_present(ObFrame
*self
, const gchar
*lc
, gint dir
) {
1034 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+= dir
) {
1035 if (*lc
== ' ') continue; /* it was invalid */
1036 if (*lc
== 'N' && self
->decorations
& OB_FRAME_DECOR_ICON
)
1038 if (*lc
== 'D' && self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
)
1040 if (*lc
== 'S' && self
->decorations
& OB_FRAME_DECOR_SHADE
)
1042 if (*lc
== 'I' && self
->decorations
& OB_FRAME_DECOR_ICONIFY
)
1044 if (*lc
== 'M' && self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
)
1046 if (*lc
== 'C' && self
->decorations
& OB_FRAME_DECOR_CLOSE
)
1048 if (*lc
== 'L') return FALSE
;
1053 static void layout_title(ObFrame
*self
)
1058 const gint bwidth
= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
1059 /* position of the left most button */
1060 const gint left
= ob_rr_theme
->paddingx
+ 1;
1061 /* position of the right most button */
1062 const gint right
= self
->width
;
1064 /* turn them all off */
1065 self
->icon_on
= self
->desk_on
= self
->shade_on
= self
->iconify_on
=
1066 self
->max_on
= self
->close_on
= self
->label_on
= FALSE
;
1067 self
->label_width
= self
->width
- (ob_rr_theme
->paddingx
+ 1) * 2;
1068 self
->leftmost
= self
->rightmost
= OB_FRAME_CONTEXT_NONE
;
1070 /* figure out what's being show, find each element's position, and the
1073 do the ones before the label, then after the label,
1074 i will be +1 the first time through when working to the left,
1075 and -1 the second time through when working to the right */
1076 for (i
= 1; i
>= -1; i
-=2) {
1078 ObFrameContext
*firstcon
;
1082 lc
= config_title_layout
;
1083 firstcon
= &self
->leftmost
;
1086 lc
= config_title_layout
+ strlen(config_title_layout
)-1;
1087 firstcon
= &self
->rightmost
;
1090 /* stop at the end of the string (or the label, which calls break) */
1091 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+=i
) {
1094 self
->label_on
= TRUE
;
1097 break; /* break the for loop, do other side of label */
1098 } else if (*lc
== 'N') {
1099 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICON
;
1100 if ((self
->icon_on
= is_button_present(self
, lc
, i
))) {
1101 /* icon is bigger than buttons */
1102 self
->label_width
-= bwidth
+ 2;
1103 if (i
> 0) self
->icon_x
= x
;
1104 x
+= i
* (bwidth
+ 2);
1105 if (i
< 0) self
->icon_x
= x
;
1107 } else if (*lc
== 'D') {
1108 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ALLDESKTOPS
;
1109 if ((self
->desk_on
= is_button_present(self
, lc
, i
))) {
1110 self
->label_width
-= bwidth
;
1111 if (i
> 0) self
->desk_x
= x
;
1113 if (i
< 0) self
->desk_x
= x
;
1115 } else if (*lc
== 'S') {
1116 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_SHADE
;
1117 if ((self
->shade_on
= is_button_present(self
, lc
, i
))) {
1118 self
->label_width
-= bwidth
;
1119 if (i
> 0) self
->shade_x
= x
;
1121 if (i
< 0) self
->shade_x
= x
;
1123 } else if (*lc
== 'I') {
1124 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICONIFY
;
1125 if ((self
->iconify_on
= is_button_present(self
, lc
, i
))) {
1126 self
->label_width
-= bwidth
;
1127 if (i
> 0) self
->iconify_x
= x
;
1129 if (i
< 0) self
->iconify_x
= x
;
1131 } else if (*lc
== 'M') {
1132 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_MAXIMIZE
;
1133 if ((self
->max_on
= is_button_present(self
, lc
, i
))) {
1134 self
->label_width
-= bwidth
;
1135 if (i
> 0) self
->max_x
= x
;
1137 if (i
< 0) self
->max_x
= x
;
1139 } else if (*lc
== 'C') {
1140 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_CLOSE
;
1141 if ((self
->close_on
= is_button_present(self
, lc
, i
))) {
1142 self
->label_width
-= bwidth
;
1143 if (i
> 0) self
->close_x
= x
;
1145 if (i
< 0) self
->close_x
= x
;
1148 continue; /* don't set firstcon */
1153 /* position and map the elements */
1154 if (self
->icon_on
) {
1155 XMapWindow(ob_display
, self
->icon
);
1156 XMoveWindow(ob_display
, self
->icon
, self
->icon_x
,
1157 ob_rr_theme
->paddingy
);
1159 XUnmapWindow(ob_display
, self
->icon
);
1161 if (self
->desk_on
) {
1162 XMapWindow(ob_display
, self
->desk
);
1163 XMoveWindow(ob_display
, self
->desk
, self
->desk_x
,
1164 ob_rr_theme
->paddingy
+ 1);
1166 XUnmapWindow(ob_display
, self
->desk
);
1168 if (self
->shade_on
) {
1169 XMapWindow(ob_display
, self
->shade
);
1170 XMoveWindow(ob_display
, self
->shade
, self
->shade_x
,
1171 ob_rr_theme
->paddingy
+ 1);
1173 XUnmapWindow(ob_display
, self
->shade
);
1175 if (self
->iconify_on
) {
1176 XMapWindow(ob_display
, self
->iconify
);
1177 XMoveWindow(ob_display
, self
->iconify
, self
->iconify_x
,
1178 ob_rr_theme
->paddingy
+ 1);
1180 XUnmapWindow(ob_display
, self
->iconify
);
1183 XMapWindow(ob_display
, self
->max
);
1184 XMoveWindow(ob_display
, self
->max
, self
->max_x
,
1185 ob_rr_theme
->paddingy
+ 1);
1187 XUnmapWindow(ob_display
, self
->max
);
1189 if (self
->close_on
) {
1190 XMapWindow(ob_display
, self
->close
);
1191 XMoveWindow(ob_display
, self
->close
, self
->close_x
,
1192 ob_rr_theme
->paddingy
+ 1);
1194 XUnmapWindow(ob_display
, self
->close
);
1196 if (self
->label_on
) {
1197 self
->label_width
= MAX(1, self
->label_width
); /* no lower than 1 */
1198 XMapWindow(ob_display
, self
->label
);
1199 XMoveWindow(ob_display
, self
->label
, self
->label_x
,
1200 ob_rr_theme
->paddingy
);
1202 XUnmapWindow(ob_display
, self
->label
);
1205 ObFrameContext
frame_context_from_string(const gchar
*name
)
1207 if (!g_ascii_strcasecmp("Desktop", name
))
1208 return OB_FRAME_CONTEXT_DESKTOP
;
1209 else if (!g_ascii_strcasecmp("Root", name
))
1210 return OB_FRAME_CONTEXT_ROOT
;
1211 else if (!g_ascii_strcasecmp("Client", name
))
1212 return OB_FRAME_CONTEXT_CLIENT
;
1213 else if (!g_ascii_strcasecmp("Titlebar", name
))
1214 return OB_FRAME_CONTEXT_TITLEBAR
;
1215 else if (!g_ascii_strcasecmp("Frame", name
))
1216 return OB_FRAME_CONTEXT_FRAME
;
1217 else if (!g_ascii_strcasecmp("TLCorner", name
))
1218 return OB_FRAME_CONTEXT_TLCORNER
;
1219 else if (!g_ascii_strcasecmp("TRCorner", name
))
1220 return OB_FRAME_CONTEXT_TRCORNER
;
1221 else if (!g_ascii_strcasecmp("BLCorner", name
))
1222 return OB_FRAME_CONTEXT_BLCORNER
;
1223 else if (!g_ascii_strcasecmp("BRCorner", name
))
1224 return OB_FRAME_CONTEXT_BRCORNER
;
1225 else if (!g_ascii_strcasecmp("Top", name
))
1226 return OB_FRAME_CONTEXT_TOP
;
1227 else if (!g_ascii_strcasecmp("Bottom", name
))
1228 return OB_FRAME_CONTEXT_BOTTOM
;
1229 else if (!g_ascii_strcasecmp("Left", name
))
1230 return OB_FRAME_CONTEXT_LEFT
;
1231 else if (!g_ascii_strcasecmp("Right", name
))
1232 return OB_FRAME_CONTEXT_RIGHT
;
1233 else if (!g_ascii_strcasecmp("Maximize", name
))
1234 return OB_FRAME_CONTEXT_MAXIMIZE
;
1235 else if (!g_ascii_strcasecmp("AllDesktops", name
))
1236 return OB_FRAME_CONTEXT_ALLDESKTOPS
;
1237 else if (!g_ascii_strcasecmp("Shade", name
))
1238 return OB_FRAME_CONTEXT_SHADE
;
1239 else if (!g_ascii_strcasecmp("Iconify", name
))
1240 return OB_FRAME_CONTEXT_ICONIFY
;
1241 else if (!g_ascii_strcasecmp("Icon", name
))
1242 return OB_FRAME_CONTEXT_ICON
;
1243 else if (!g_ascii_strcasecmp("Close", name
))
1244 return OB_FRAME_CONTEXT_CLOSE
;
1245 else if (!g_ascii_strcasecmp("MoveResize", name
))
1246 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
1247 return OB_FRAME_CONTEXT_NONE
;
1250 ObFrameContext
frame_context(ObClient
*client
, Window win
, gint x
, gint y
)
1254 if (moveresize_in_progress
)
1255 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
1257 if (win
== RootWindow(ob_display
, ob_screen
))
1258 return OB_FRAME_CONTEXT_ROOT
;
1259 if (client
== NULL
) return OB_FRAME_CONTEXT_NONE
;
1260 if (win
== client
->window
) {
1261 /* conceptually, this is the desktop, as far as users are
1263 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
1264 return OB_FRAME_CONTEXT_DESKTOP
;
1265 return OB_FRAME_CONTEXT_CLIENT
;
1268 self
= client
->frame
;
1270 /* when the user clicks in the corners of the titlebar and the client
1271 is fully maximized, then treat it like they clicked in the
1272 button that is there */
1273 if (self
->max_horz
&& self
->max_vert
&&
1274 (win
== self
->title
|| win
== self
->titletop
||
1275 win
== self
->titleleft
|| win
== self
->titletopleft
||
1276 win
== self
->titleright
|| win
== self
->titletopright
))
1278 /* get the mouse coords in reference to the whole frame */
1282 /* these windows are down a border width from the top of the frame */
1283 if (win
== self
->title
||
1284 win
== self
->titleleft
|| win
== self
->titleright
)
1287 /* title is a border width in from the edge */
1288 if (win
== self
->title
)
1290 /* titletop is a bit to the right */
1291 else if (win
== self
->titletop
)
1292 fx
+= ob_rr_theme
->grip_width
+ self
->bwidth
;
1293 /* titletopright is way to the right edge */
1294 else if (win
== self
->titletopright
)
1295 fx
+= self
->area
.width
- (ob_rr_theme
->grip_width
+ self
->bwidth
);
1296 /* titleright is even more way to the right edge */
1297 else if (win
== self
->titleright
)
1298 fx
+= self
->area
.width
- self
->bwidth
;
1300 /* figure out if we're over the area that should be considered a
1302 if (fy
< self
->bwidth
+ ob_rr_theme
->paddingy
+ 1 +
1303 ob_rr_theme
->button_size
)
1305 if (fx
< (self
->bwidth
+ ob_rr_theme
->paddingx
+ 1 +
1306 ob_rr_theme
->button_size
))
1308 if (self
->leftmost
!= OB_FRAME_CONTEXT_NONE
)
1309 return self
->leftmost
;
1311 else if (fx
>= (self
->area
.width
-
1312 (self
->bwidth
+ ob_rr_theme
->paddingx
+ 1 +
1313 ob_rr_theme
->button_size
)))
1315 if (self
->rightmost
!= OB_FRAME_CONTEXT_NONE
)
1316 return self
->rightmost
;
1320 /* there is no resizing maximized windows so make them the titlebar
1322 return OB_FRAME_CONTEXT_TITLEBAR
;
1324 else if (self
->max_vert
&&
1325 (win
== self
->titletop
|| win
== self
->topresize
))
1326 /* can't resize vertically when max vert */
1327 return OB_FRAME_CONTEXT_TITLEBAR
;
1329 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
1330 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
1331 if (win
== self
->handle
) return OB_FRAME_CONTEXT_BOTTOM
;
1332 if (win
== self
->handletop
) return OB_FRAME_CONTEXT_BOTTOM
;
1333 if (win
== self
->handlebottom
) return OB_FRAME_CONTEXT_BOTTOM
;
1334 if (win
== self
->handleleft
) return OB_FRAME_CONTEXT_BLCORNER
;
1335 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
1336 if (win
== self
->lgripleft
) return OB_FRAME_CONTEXT_BLCORNER
;
1337 if (win
== self
->lgriptop
) return OB_FRAME_CONTEXT_BLCORNER
;
1338 if (win
== self
->lgripbottom
) return OB_FRAME_CONTEXT_BLCORNER
;
1339 if (win
== self
->handleright
) return OB_FRAME_CONTEXT_BRCORNER
;
1340 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
1341 if (win
== self
->rgripright
) return OB_FRAME_CONTEXT_BLCORNER
;
1342 if (win
== self
->rgriptop
) return OB_FRAME_CONTEXT_BLCORNER
;
1343 if (win
== self
->rgripbottom
) return OB_FRAME_CONTEXT_BLCORNER
;
1344 if (win
== self
->title
) return OB_FRAME_CONTEXT_TITLEBAR
;
1345 if (win
== self
->titlebottom
) return OB_FRAME_CONTEXT_TITLEBAR
;
1346 if (win
== self
->titleleft
) return OB_FRAME_CONTEXT_TLCORNER
;
1347 if (win
== self
->titletopleft
) return OB_FRAME_CONTEXT_TLCORNER
;
1348 if (win
== self
->titleright
) return OB_FRAME_CONTEXT_TRCORNER
;
1349 if (win
== self
->titletopright
) return OB_FRAME_CONTEXT_TRCORNER
;
1350 if (win
== self
->titletop
) return OB_FRAME_CONTEXT_TOP
;
1351 if (win
== self
->topresize
) return OB_FRAME_CONTEXT_TOP
;
1352 if (win
== self
->tltresize
) return OB_FRAME_CONTEXT_TLCORNER
;
1353 if (win
== self
->tllresize
) return OB_FRAME_CONTEXT_TLCORNER
;
1354 if (win
== self
->trtresize
) return OB_FRAME_CONTEXT_TRCORNER
;
1355 if (win
== self
->trrresize
) return OB_FRAME_CONTEXT_TRCORNER
;
1356 if (win
== self
->left
) return OB_FRAME_CONTEXT_LEFT
;
1357 if (win
== self
->right
) return OB_FRAME_CONTEXT_RIGHT
;
1358 if (win
== self
->innertop
) return OB_FRAME_CONTEXT_TITLEBAR
;
1359 if (win
== self
->innerleft
) return OB_FRAME_CONTEXT_LEFT
;
1360 if (win
== self
->innerbottom
) return OB_FRAME_CONTEXT_BOTTOM
;
1361 if (win
== self
->innerright
) return OB_FRAME_CONTEXT_RIGHT
;
1362 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
1363 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
1364 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
1365 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
1366 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
1367 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
1369 return OB_FRAME_CONTEXT_NONE
;
1372 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
1375 switch (self
->client
->gravity
) {
1377 case NorthWestGravity
:
1378 case SouthWestGravity
:
1385 /* the middle of the client will be the middle of the frame */
1386 *x
-= (self
->size
.right
- self
->size
.left
) / 2;
1389 case NorthEastGravity
:
1390 case SouthEastGravity
:
1392 /* the right side of the client will be the right side of the frame */
1393 *x
-= self
->size
.right
+ self
->size
.left
-
1394 self
->client
->border_width
* 2;
1399 /* the client's position won't move */
1400 *x
-= self
->size
.left
- self
->client
->border_width
;
1405 switch (self
->client
->gravity
) {
1407 case NorthWestGravity
:
1408 case NorthEastGravity
:
1415 /* the middle of the client will be the middle of the frame */
1416 *y
-= (self
->size
.bottom
- self
->size
.top
) / 2;
1419 case SouthWestGravity
:
1420 case SouthEastGravity
:
1422 /* the bottom of the client will be the bottom of the frame */
1423 *y
-= self
->size
.bottom
+ self
->size
.top
-
1424 self
->client
->border_width
* 2;
1429 /* the client's position won't move */
1430 *y
-= self
->size
.top
- self
->client
->border_width
;
1435 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
1438 switch (self
->client
->gravity
) {
1440 case NorthWestGravity
:
1442 case SouthWestGravity
:
1447 /* the middle of the client will be the middle of the frame */
1448 *x
+= (self
->size
.right
- self
->size
.left
) / 2;
1450 case NorthEastGravity
:
1452 case SouthEastGravity
:
1453 /* the right side of the client will be the right side of the frame */
1454 *x
+= self
->size
.right
+ self
->size
.left
-
1455 self
->client
->border_width
* 2;
1459 /* the client's position won't move */
1460 *x
+= self
->size
.left
- self
->client
->border_width
;
1465 switch (self
->client
->gravity
) {
1467 case NorthWestGravity
:
1469 case NorthEastGravity
:
1474 /* the middle of the client will be the middle of the frame */
1475 *y
+= (self
->size
.bottom
- self
->size
.top
) / 2;
1477 case SouthWestGravity
:
1479 case SouthEastGravity
:
1480 /* the bottom of the client will be the bottom of the frame */
1481 *y
+= self
->size
.bottom
+ self
->size
.top
-
1482 self
->client
->border_width
* 2;
1486 /* the client's position won't move */
1487 *y
+= self
->size
.top
- self
->client
->border_width
;
1492 static void flash_done(gpointer data
)
1494 ObFrame
*self
= data
;
1496 if (self
->focused
!= self
->flash_on
)
1497 frame_adjust_focus(self
, self
->focused
);
1500 static gboolean
flash_timeout(gpointer data
)
1502 ObFrame
*self
= data
;
1505 g_get_current_time(&now
);
1506 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
1507 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
1508 now
.tv_usec
>= self
->flash_end
.tv_usec
))
1509 self
->flashing
= FALSE
;
1511 if (!self
->flashing
)
1512 return FALSE
; /* we are done */
1514 self
->flash_on
= !self
->flash_on
;
1515 if (!self
->focused
) {
1516 frame_adjust_focus(self
, self
->flash_on
);
1517 self
->focused
= FALSE
;
1520 return TRUE
; /* go again */
1523 void frame_flash_start(ObFrame
*self
)
1525 self
->flash_on
= self
->focused
;
1527 if (!self
->flashing
)
1528 ob_main_loop_timeout_add(ob_main_loop
,
1529 G_USEC_PER_SEC
* 0.6,
1534 g_get_current_time(&self
->flash_end
);
1535 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
1537 self
->flashing
= TRUE
;
1540 void frame_flash_stop(ObFrame
*self
)
1542 self
->flashing
= FALSE
;
1545 static gulong
frame_animate_iconify_time_left(ObFrame
*self
,
1546 const GTimeVal
*now
)
1549 sec
= self
->iconify_animation_end
.tv_sec
- now
->tv_sec
;
1550 usec
= self
->iconify_animation_end
.tv_usec
- now
->tv_usec
;
1552 usec
+= G_USEC_PER_SEC
;
1555 /* no negative values */
1556 return MAX(sec
* G_USEC_PER_SEC
+ usec
, 0);
1559 static gboolean
frame_animate_iconify(gpointer p
)
1563 gint iconx
, icony
, iconw
;
1566 gboolean iconifying
;
1568 if (self
->client
->icon_geometry
.width
== 0) {
1569 /* there is no icon geometry set so just go straight down */
1570 Rect
*a
= screen_physical_area();
1571 iconx
= self
->area
.x
+ self
->area
.width
/ 2 + 32;
1572 icony
= a
->y
+ a
->width
;
1575 iconx
= self
->client
->icon_geometry
.x
;
1576 icony
= self
->client
->icon_geometry
.y
;
1577 iconw
= self
->client
->icon_geometry
.width
;
1580 iconifying
= self
->iconify_animation_going
> 0;
1582 /* how far do we have left to go ? */
1583 g_get_current_time(&now
);
1584 time
= frame_animate_iconify_time_left(self
, &now
);
1586 if (time
== 0 || iconifying
) {
1587 /* start where the frame is supposed to be */
1590 w
= self
->area
.width
;
1591 h
= self
->area
.height
;
1593 /* start at the icon */
1597 h
= self
->size
.top
; /* just the titlebar */
1604 dx
= self
->area
.x
- iconx
;
1605 dy
= self
->area
.y
- icony
;
1606 dw
= self
->area
.width
- self
->bwidth
* 2 - iconw
;
1607 /* if restoring, we move in the opposite direction */
1608 if (!iconifying
) { dx
= -dx
; dy
= -dy
; dw
= -dw
; }
1610 elapsed
= FRAME_ANIMATE_ICONIFY_TIME
- time
;
1611 x
= x
- (dx
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1612 y
= y
- (dy
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1613 w
= w
- (dw
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1614 h
= self
->size
.top
; /* just the titlebar */
1618 frame_end_iconify_animation(self
);
1620 XMoveResizeWindow(ob_display
, self
->window
, x
, y
, w
, h
);
1624 return time
> 0; /* repeat until we're out of time */
1627 void frame_end_iconify_animation(ObFrame
*self
)
1629 /* see if there is an animation going */
1630 if (self
->iconify_animation_going
== 0) return;
1633 XUnmapWindow(ob_display
, self
->window
);
1635 /* Send a ConfigureNotify when the animation is done, this fixes
1636 KDE's pager showing the window in the wrong place. */
1637 client_reconfigure(self
->client
);
1639 /* we're not animating any more ! */
1640 self
->iconify_animation_going
= 0;
1642 XMoveResizeWindow(ob_display
, self
->window
,
1643 self
->area
.x
, self
->area
.y
,
1644 self
->area
.width
, self
->area
.height
);
1648 void frame_begin_iconify_animation(ObFrame
*self
, gboolean iconifying
)
1651 gboolean new_anim
= FALSE
;
1652 gboolean set_end
= TRUE
;
1655 /* if there is no titlebar, just don't animate for now
1656 XXX it would be nice tho.. */
1657 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1660 /* get the current time */
1661 g_get_current_time(&now
);
1663 /* get how long until the end */
1664 time
= FRAME_ANIMATE_ICONIFY_TIME
;
1665 if (self
->iconify_animation_going
) {
1666 if (!!iconifying
!= (self
->iconify_animation_going
> 0)) {
1667 /* animation was already going on in the opposite direction */
1668 time
= time
- frame_animate_iconify_time_left(self
, &now
);
1670 /* animation was already going in the same direction */
1674 self
->iconify_animation_going
= iconifying
? 1 : -1;
1676 /* set the ending time */
1678 self
->iconify_animation_end
.tv_sec
= now
.tv_sec
;
1679 self
->iconify_animation_end
.tv_usec
= now
.tv_usec
;
1680 g_time_val_add(&self
->iconify_animation_end
, time
);
1684 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
1686 ob_main_loop_timeout_add(ob_main_loop
,
1687 FRAME_ANIMATE_ICONIFY_STEP_TIME
,
1688 frame_animate_iconify
, self
,
1689 g_direct_equal
, NULL
);
1691 /* do the first step */
1692 frame_animate_iconify(self
);
1694 /* show it during the animation even if it is not "visible" */
1696 XMapWindow(ob_display
, self
->window
);