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 PLATE_EVENTMASK (SubstructureRedirectMask | FocusChangeMask)
35 #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
36 ButtonPressMask | ButtonReleaseMask)
37 #define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \
38 ButtonMotionMask | PointerMotionMask | \
39 EnterWindowMask | LeaveWindowMask)
40 /* The inner window does not need enter/leave events.
41 If it does get them, then it needs its own context for enter events
42 because sloppy focus will focus the window when you enter the inner window
44 #define INNER_EVENTMASK (ButtonPressMask)
46 #define FRAME_ANIMATE_ICONIFY_TIME 150000 /* .15 seconds */
47 #define FRAME_ANIMATE_ICONIFY_STEP_TIME (G_USEC_PER_SEC / 60) /* 60 Hz */
49 #define FRAME_HANDLE_Y(f) (f->size.top + f->client->area.height + f->cbwidth_y)
51 static void flash_done(gpointer data
);
52 static gboolean
flash_timeout(gpointer data
);
54 static void layout_title(ObFrame
*self
);
55 static void set_theme_statics(ObFrame
*self
);
56 static void free_theme_statics(ObFrame
*self
);
57 static gboolean
frame_animate_iconify(gpointer self
);
59 static Window
createWindow(Window parent
, Visual
*visual
,
60 gulong mask
, XSetWindowAttributes
*attrib
)
62 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
63 (visual
? 32 : RrDepth(ob_rr_inst
)), InputOutput
,
64 (visual
? visual
: RrVisual(ob_rr_inst
)),
69 static Visual
*check_32bit_client(ObClient
*c
)
71 XWindowAttributes wattrib
;
74 /* we're already running at 32 bit depth, yay. we don't need to use their
76 if (RrDepth(ob_rr_inst
) == 32)
79 ret
= XGetWindowAttributes(ob_display
, c
->window
, &wattrib
);
80 g_assert(ret
!= BadDrawable
);
81 g_assert(ret
!= BadWindow
);
83 if (wattrib
.depth
== 32)
84 return wattrib
.visual
;
88 ObFrame
*frame_new(ObClient
*client
)
90 XSetWindowAttributes attrib
;
95 self
= g_new0(ObFrame
, 1);
96 self
->client
= client
;
98 visual
= check_32bit_client(client
);
100 /* create the non-visible decor windows */
104 /* client has a 32-bit visual */
105 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
106 /* create a colormap with the visual */
107 self
->colormap
= attrib
.colormap
=
108 XCreateColormap(ob_display
,
109 RootWindow(ob_display
, ob_screen
),
111 attrib
.background_pixel
= BlackPixel(ob_display
, ob_screen
);
112 attrib
.border_pixel
= BlackPixel(ob_display
, ob_screen
);
114 attrib
.event_mask
= FRAME_EVENTMASK
;
115 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
), visual
,
118 attrib
.event_mask
= INNER_EVENTMASK
;
119 self
->inner
= createWindow(self
->window
, visual
, mask
, &attrib
);
121 mask
&= ~CWEventMask
;
122 self
->plate
= createWindow(self
->inner
, visual
, mask
, &attrib
);
124 /* create the visible decor windows */
128 /* client has a 32-bit visual */
129 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
130 attrib
.colormap
= RrColormap(ob_rr_inst
);
132 attrib
.event_mask
= ELEMENT_EVENTMASK
;
133 self
->title
= createWindow(self
->window
, NULL
, mask
, &attrib
);
134 self
->titleleft
= createWindow(self
->window
, NULL
, mask
, &attrib
);
135 self
->titletop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
136 self
->titletopleft
= createWindow(self
->window
, NULL
, mask
, &attrib
);
137 self
->titletopright
= createWindow(self
->window
, NULL
, mask
, &attrib
);
138 self
->titleright
= createWindow(self
->window
, NULL
, mask
, &attrib
);
139 self
->titlebottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
141 self
->topresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
142 self
->tltresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
143 self
->tllresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
144 self
->trtresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
145 self
->trrresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
147 self
->left
= createWindow(self
->window
, NULL
, mask
, &attrib
);
148 self
->right
= createWindow(self
->window
, 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
);
158 self
->handle
= createWindow(self
->window
, NULL
, mask
, &attrib
);
159 self
->lgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
160 self
->rgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
162 self
->handleleft
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
163 self
->handleright
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
165 self
->handletop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
166 self
->handlebottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
167 self
->lgripleft
= createWindow(self
->window
, NULL
, mask
, &attrib
);
168 self
->lgriptop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
169 self
->lgripbottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
170 self
->rgripright
= createWindow(self
->window
, NULL
, mask
, &attrib
);
171 self
->rgriptop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
172 self
->rgripbottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
174 self
->focused
= FALSE
;
176 /* the other stuff is shown based on decor settings */
177 XMapWindow(ob_display
, self
->plate
);
178 XMapWindow(ob_display
, self
->inner
);
179 XMapWindow(ob_display
, self
->label
);
181 self
->max_press
= self
->close_press
= self
->desk_press
=
182 self
->iconify_press
= self
->shade_press
= FALSE
;
183 self
->max_hover
= self
->close_hover
= self
->desk_hover
=
184 self
->iconify_hover
= self
->shade_hover
= FALSE
;
186 set_theme_statics(self
);
188 return (ObFrame
*)self
;
191 static void set_theme_statics(ObFrame
*self
)
193 /* set colors/appearance/sizes for stuff that doesn't change */
194 XResizeWindow(ob_display
, self
->max
,
195 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
196 XResizeWindow(ob_display
, self
->iconify
,
197 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
198 XResizeWindow(ob_display
, self
->icon
,
199 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
200 XResizeWindow(ob_display
, self
->close
,
201 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
202 XResizeWindow(ob_display
, self
->desk
,
203 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
204 XResizeWindow(ob_display
, self
->shade
,
205 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
206 XResizeWindow(ob_display
, self
->tltresize
,
207 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
208 XResizeWindow(ob_display
, self
->trtresize
,
209 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
210 XResizeWindow(ob_display
, self
->tllresize
,
211 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
212 XResizeWindow(ob_display
, self
->trrresize
,
213 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
215 /* set up the dynamic appearances */
216 self
->a_unfocused_title
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_title
);
217 self
->a_focused_title
= RrAppearanceCopy(ob_rr_theme
->a_focused_title
);
218 self
->a_unfocused_label
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_label
);
219 self
->a_focused_label
= RrAppearanceCopy(ob_rr_theme
->a_focused_label
);
220 self
->a_unfocused_handle
=
221 RrAppearanceCopy(ob_rr_theme
->a_unfocused_handle
);
222 self
->a_focused_handle
= RrAppearanceCopy(ob_rr_theme
->a_focused_handle
);
223 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_icon
);
226 static void free_theme_statics(ObFrame
*self
)
228 RrAppearanceFree(self
->a_unfocused_title
);
229 RrAppearanceFree(self
->a_focused_title
);
230 RrAppearanceFree(self
->a_unfocused_label
);
231 RrAppearanceFree(self
->a_focused_label
);
232 RrAppearanceFree(self
->a_unfocused_handle
);
233 RrAppearanceFree(self
->a_focused_handle
);
234 RrAppearanceFree(self
->a_icon
);
237 void frame_free(ObFrame
*self
)
239 free_theme_statics(self
);
241 XDestroyWindow(ob_display
, self
->window
);
243 XFreeColormap(ob_display
, self
->colormap
);
248 void frame_show(ObFrame
*self
)
250 if (!self
->visible
) {
251 self
->visible
= TRUE
;
252 XMapWindow(ob_display
, self
->client
->window
);
253 XMapWindow(ob_display
, self
->window
);
257 void frame_hide(ObFrame
*self
)
260 self
->visible
= FALSE
;
261 if (!frame_iconify_animating(self
))
262 XUnmapWindow(ob_display
, self
->window
);
263 /* we unmap the client itself so that we can get MapRequest
264 events, and because the ICCCM tells us to! */
265 XUnmapWindow(ob_display
, self
->client
->window
);
266 self
->client
->ignore_unmaps
+= 1;
270 void frame_adjust_theme(ObFrame
*self
)
272 free_theme_statics(self
);
273 set_theme_statics(self
);
276 void frame_adjust_shape(ObFrame
*self
)
282 if (!self
->client
->shaped
) {
283 /* clear the shape on the frame window */
284 XShapeCombineMask(ob_display
, self
->window
, ShapeBounding
,
289 /* make the frame's shape match the clients */
290 XShapeCombineShape(ob_display
, self
->window
, ShapeBounding
,
293 self
->client
->window
,
294 ShapeBounding
, ShapeSet
);
297 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
300 xrect
[0].width
= self
->area
.width
;
301 xrect
[0].height
= ob_rr_theme
->title_height
+
302 self
->bwidth
+ self
->rbwidth
;
306 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
307 ob_rr_theme
->handle_height
> 0)
310 xrect
[1].y
= FRAME_HANDLE_Y(self
);
311 xrect
[1].width
= self
->area
.width
;
312 xrect
[1].height
= ob_rr_theme
->handle_height
+
317 XShapeCombineRectangles(ob_display
, self
->window
,
318 ShapeBounding
, 0, 0, xrect
, num
,
319 ShapeUnion
, Unsorted
);
324 void frame_adjust_area(ObFrame
*self
, gboolean moved
,
325 gboolean resized
, gboolean fake
)
329 oldsize
= self
->size
;
332 self
->decorations
= self
->client
->decorations
;
333 self
->max_horz
= self
->client
->max_horz
;
335 if (self
->decorations
& OB_FRAME_DECOR_BORDER
) {
336 self
->bwidth
= ob_rr_theme
->fbwidth
;
337 self
->cbwidth_x
= ob_rr_theme
->cbwidthx
;
338 self
->cbwidth_y
= ob_rr_theme
->cbwidthy
;
340 self
->bwidth
= self
->cbwidth_x
= self
->cbwidth_y
= 0;
342 self
->rbwidth
= self
->bwidth
;
343 self
->leftb
= self
->rightb
= TRUE
;
345 if (self
->max_horz
) {
346 self
->leftb
= self
->rightb
= FALSE
;
350 self
->width
= self
->client
->area
.width
+ self
->cbwidth_x
* 2;
351 self
->width
= MAX(self
->width
, 1); /* no lower than 1 */
353 STRUT_SET(self
->size
,
354 self
->cbwidth_x
+ (self
->leftb
? self
->bwidth
: 0),
355 self
->cbwidth_y
+ self
->bwidth
,
356 self
->cbwidth_x
+ (self
->rightb
? self
->bwidth
: 0),
357 self
->cbwidth_y
+ self
->bwidth
);
359 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
360 self
->size
.top
+= ob_rr_theme
->title_height
+ self
->rbwidth
;
361 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
362 ob_rr_theme
->handle_height
> 0)
364 self
->size
.bottom
+= ob_rr_theme
->handle_height
+ self
->bwidth
;
367 /* position/size and map/unmap all the windows */
371 XMoveResizeWindow(ob_display
, self
->titletop
,
372 ob_rr_theme
->grip_width
+ self
->bwidth
, 0,
373 self
->client
->area
.width
+
374 self
->cbwidth_x
* 2 + self
->bwidth
* 2 -
375 (ob_rr_theme
->grip_width
+ self
->bwidth
) * 2,
377 XMoveResizeWindow(ob_display
, self
->titletopleft
,
379 ob_rr_theme
->grip_width
+ self
->bwidth
,
381 XMoveResizeWindow(ob_display
, self
->titletopright
,
382 self
->client
->area
.width
+
383 self
->cbwidth_x
* 2 + self
->bwidth
* 2 -
384 ob_rr_theme
->grip_width
- self
->bwidth
,
386 ob_rr_theme
->grip_width
+ self
->bwidth
,
389 XMoveResizeWindow(ob_display
, self
->titleleft
,
393 ob_rr_theme
->grip_width
:
394 self
->size
.top
- self
->bwidth
));
395 XMoveResizeWindow(ob_display
, self
->titleright
,
396 self
->client
->area
.width
+
397 self
->cbwidth_x
* 2 + self
->bwidth
,
401 ob_rr_theme
->grip_width
:
402 self
->size
.top
- self
->bwidth
));
404 XMapWindow(ob_display
, self
->titletop
);
405 XMapWindow(ob_display
, self
->titletopleft
);
406 XMapWindow(ob_display
, self
->titletopright
);
407 XMapWindow(ob_display
, self
->titleleft
);
408 XMapWindow(ob_display
, self
->titleright
);
410 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
&&
413 XMoveResizeWindow(ob_display
, self
->titlebottom
,
415 ob_rr_theme
->title_height
+ self
->bwidth
,
416 self
->client
->area
.width
+
420 XMapWindow(ob_display
, self
->titlebottom
);
422 XUnmapWindow(ob_display
, self
->titlebottom
);
424 XUnmapWindow(ob_display
, self
->titlebottom
);
426 XUnmapWindow(ob_display
, self
->titletop
);
427 XUnmapWindow(ob_display
, self
->titletopleft
);
428 XUnmapWindow(ob_display
, self
->titletopright
);
429 XUnmapWindow(ob_display
, self
->titleleft
);
430 XUnmapWindow(ob_display
, self
->titleright
);
433 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
434 XMoveResizeWindow(ob_display
, self
->title
,
435 self
->bwidth
, self
->bwidth
,
436 self
->width
, ob_rr_theme
->title_height
);
438 XMapWindow(ob_display
, self
->title
);
440 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
441 XMoveResizeWindow(ob_display
, self
->topresize
,
442 ob_rr_theme
->grip_width
+ self
->bwidth
,
444 self
->width
- (ob_rr_theme
->grip_width
+
446 ob_rr_theme
->paddingy
+ 1);
448 XMoveWindow(ob_display
, self
->tltresize
, 0, 0);
449 XMoveWindow(ob_display
, self
->tllresize
, 0, 0);
450 XMoveWindow(ob_display
, self
->trtresize
,
451 self
->width
- ob_rr_theme
->grip_width
, 0);
452 XMoveWindow(ob_display
, self
->trrresize
,
453 self
->width
- ob_rr_theme
->paddingx
- 1, 0);
455 XMapWindow(ob_display
, self
->topresize
);
456 XMapWindow(ob_display
, self
->tltresize
);
457 XMapWindow(ob_display
, self
->tllresize
);
458 XMapWindow(ob_display
, self
->trtresize
);
459 XMapWindow(ob_display
, self
->trrresize
);
461 XUnmapWindow(ob_display
, self
->topresize
);
462 XUnmapWindow(ob_display
, self
->tltresize
);
463 XUnmapWindow(ob_display
, self
->tllresize
);
464 XUnmapWindow(ob_display
, self
->trtresize
);
465 XUnmapWindow(ob_display
, self
->trrresize
);
468 XUnmapWindow(ob_display
, self
->title
);
471 if ((self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
472 /* layout the title bar elements */
477 XMoveResizeWindow(ob_display
, self
->handlebottom
,
478 ob_rr_theme
->grip_width
+
480 self
->size
.top
+ self
->client
->area
.height
+
481 self
->size
.bottom
- self
->bwidth
,
482 self
->width
- (ob_rr_theme
->grip_width
+
486 XMoveResizeWindow(ob_display
, self
->lgripleft
,
488 self
->size
.top
+ self
->client
->area
.height
+
491 ob_rr_theme
->grip_width
:
495 ob_rr_theme
->grip_width
:
497 XMoveResizeWindow(ob_display
, self
->rgripright
,
498 self
->size
.left
+ self
->client
->area
.width
+
499 self
->size
.right
- self
->bwidth
,
500 self
->size
.top
+ self
->client
->area
.height
+
503 ob_rr_theme
->grip_width
:
507 ob_rr_theme
->grip_width
:
510 XMoveResizeWindow(ob_display
, self
->lgripbottom
,
512 self
->size
.top
+ self
->client
->area
.height
+
513 self
->size
.bottom
- self
->bwidth
,
514 ob_rr_theme
->grip_width
+ self
->bwidth
,
516 XMoveResizeWindow(ob_display
, self
->rgripbottom
,
517 self
->size
.left
+ self
->client
->area
.width
+
518 self
->size
.right
- self
->bwidth
* 2 -
519 ob_rr_theme
->grip_width
,
520 self
->size
.top
+ self
->client
->area
.height
+
521 self
->size
.bottom
- self
->bwidth
,
522 ob_rr_theme
->grip_width
+ self
->bwidth
,
525 XMapWindow(ob_display
, self
->handlebottom
);
526 XMapWindow(ob_display
, self
->lgripleft
);
527 XMapWindow(ob_display
, self
->rgripright
);
528 XMapWindow(ob_display
, self
->lgripbottom
);
529 XMapWindow(ob_display
, self
->rgripbottom
);
531 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
532 ob_rr_theme
->handle_height
> 0)
534 XMoveResizeWindow(ob_display
, self
->handletop
,
535 ob_rr_theme
->grip_width
+
537 FRAME_HANDLE_Y(self
),
538 self
->width
- (ob_rr_theme
->grip_width
+
541 XMapWindow(ob_display
, self
->handletop
);
543 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
544 XMoveResizeWindow(ob_display
, self
->handleleft
,
545 ob_rr_theme
->grip_width
,
548 ob_rr_theme
->handle_height
);
549 XMoveResizeWindow(ob_display
, self
->handleright
,
551 ob_rr_theme
->grip_width
-
555 ob_rr_theme
->handle_height
);
557 XMoveResizeWindow(ob_display
, self
->lgriptop
,
559 FRAME_HANDLE_Y(self
),
560 ob_rr_theme
->grip_width
+
563 XMoveResizeWindow(ob_display
, self
->rgriptop
,
565 self
->client
->area
.width
+
566 self
->size
.right
- self
->bwidth
* 2 -
567 ob_rr_theme
->grip_width
,
568 FRAME_HANDLE_Y(self
),
569 ob_rr_theme
->grip_width
+
573 XMapWindow(ob_display
, self
->handleleft
);
574 XMapWindow(ob_display
, self
->handleright
);
575 XMapWindow(ob_display
, self
->lgriptop
);
576 XMapWindow(ob_display
, self
->rgriptop
);
578 XUnmapWindow(ob_display
, self
->handleleft
);
579 XUnmapWindow(ob_display
, self
->handleright
);
580 XUnmapWindow(ob_display
, self
->lgriptop
);
581 XUnmapWindow(ob_display
, self
->rgriptop
);
584 XUnmapWindow(ob_display
, self
->handleleft
);
585 XUnmapWindow(ob_display
, self
->handleright
);
586 XUnmapWindow(ob_display
, self
->lgriptop
);
587 XUnmapWindow(ob_display
, self
->rgriptop
);
589 XUnmapWindow(ob_display
, self
->handletop
);
592 XUnmapWindow(ob_display
, self
->handleleft
);
593 XUnmapWindow(ob_display
, self
->handleright
);
594 XUnmapWindow(ob_display
, self
->lgriptop
);
595 XUnmapWindow(ob_display
, self
->rgriptop
);
597 XUnmapWindow(ob_display
, self
->handletop
);
599 XUnmapWindow(ob_display
, self
->handlebottom
);
600 XUnmapWindow(ob_display
, self
->lgripleft
);
601 XUnmapWindow(ob_display
, self
->rgripright
);
602 XUnmapWindow(ob_display
, self
->lgripbottom
);
603 XUnmapWindow(ob_display
, self
->rgripbottom
);
606 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
607 ob_rr_theme
->handle_height
> 0)
609 XMoveResizeWindow(ob_display
, self
->handle
,
611 FRAME_HANDLE_Y(self
) + self
->bwidth
,
612 self
->width
, ob_rr_theme
->handle_height
);
613 XMapWindow(ob_display
, self
->handle
);
615 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
616 XMoveResizeWindow(ob_display
, self
->lgrip
,
618 ob_rr_theme
->grip_width
,
619 ob_rr_theme
->handle_height
);
620 XMoveResizeWindow(ob_display
, self
->rgrip
,
621 self
->width
- ob_rr_theme
->grip_width
,
623 ob_rr_theme
->grip_width
,
624 ob_rr_theme
->handle_height
);
626 XMapWindow(ob_display
, self
->lgrip
);
627 XMapWindow(ob_display
, self
->rgrip
);
629 XUnmapWindow(ob_display
, self
->lgrip
);
630 XUnmapWindow(ob_display
, self
->rgrip
);
633 XUnmapWindow(ob_display
, self
->lgrip
);
634 XUnmapWindow(ob_display
, self
->rgrip
);
636 XUnmapWindow(ob_display
, self
->handle
);
639 if (self
->bwidth
&& self
->leftb
) {
640 XMoveResizeWindow(ob_display
, self
->left
,
642 self
->bwidth
+ ob_rr_theme
->grip_width
,
644 self
->client
->area
.height
+
645 self
->size
.top
+ self
->size
.bottom
-
646 ob_rr_theme
->grip_width
* 2);
648 XMapWindow(ob_display
, self
->left
);
650 XUnmapWindow(ob_display
, self
->left
);
652 if (self
->bwidth
&& self
->rightb
) {
653 XMoveResizeWindow(ob_display
, self
->right
,
654 self
->client
->area
.width
+
655 self
->cbwidth_x
* 2 + self
->bwidth
,
656 self
->bwidth
+ ob_rr_theme
->grip_width
,
658 self
->client
->area
.height
+
659 self
->size
.top
+ self
->size
.bottom
-
660 ob_rr_theme
->grip_width
* 2);
662 XMapWindow(ob_display
, self
->right
);
664 XUnmapWindow(ob_display
, self
->right
);
666 /* move and resize the inner border window which contains the plate
668 XMoveResizeWindow(ob_display
, self
->inner
,
670 self
->size
.top
- self
->cbwidth_y
,
671 self
->client
->area
.width
+
672 self
->cbwidth_x
* 2 +
673 (self
->leftb
? self
->bwidth
: 0) +
674 (self
->rightb
? self
->bwidth
: 0),
675 self
->client
->area
.height
+
676 self
->cbwidth_y
* 2);
679 XMoveWindow(ob_display
, self
->plate
,
680 (self
->leftb
? self
->bwidth
: 0) + self
->cbwidth_x
,
683 /* when the client has StaticGravity, it likes to move around. */
684 XMoveWindow(ob_display
, self
->client
->window
, 0, 0);
688 /* shading can change without being moved or resized */
689 RECT_SET_SIZE(self
->area
,
690 self
->client
->area
.width
+
691 self
->size
.left
+ self
->size
.right
,
692 (self
->client
->shaded
?
693 ob_rr_theme
->title_height
+ self
->bwidth
* 2:
694 self
->client
->area
.height
+
695 self
->size
.top
+ self
->size
.bottom
));
697 if (moved
|| resized
) {
698 /* find the new coordinates, done after setting the frame.size, for
699 frame_client_gravity. */
700 self
->area
.x
= self
->client
->area
.x
;
701 self
->area
.y
= self
->client
->area
.y
;
702 frame_client_gravity(self
, &self
->area
.x
, &self
->area
.y
,
703 self
->client
->area
.width
,
704 self
->client
->area
.height
);
708 if (!frame_iconify_animating(self
))
709 /* move and resize the top level frame.
710 shading can change without being moved or resized.
712 but don't do this during an iconify animation. it will be
713 reflected afterwards.
715 XMoveResizeWindow(ob_display
, self
->window
,
722 framerender_frame(self
);
723 frame_adjust_shape(self
);
726 if (!STRUT_EQUAL(self
->size
, oldsize
)) {
728 vals
[0] = self
->size
.left
;
729 vals
[1] = self
->size
.right
;
730 vals
[2] = self
->size
.top
;
731 vals
[3] = self
->size
.bottom
;
732 PROP_SETA32(self
->client
->window
, net_frame_extents
,
734 PROP_SETA32(self
->client
->window
, kde_net_wm_frame_strut
,
738 /* if this occurs while we are focus cycling, the indicator needs to
740 if (focus_cycle_target
== self
->client
)
741 focus_cycle_draw_indicator(self
->client
);
743 if (resized
&& (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
744 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
745 ob_rr_theme
->label_height
);
749 (self
->functions
& OB_CLIENT_FUNC_RESIZE
) !=
750 (self
->client
->functions
& OB_CLIENT_FUNC_RESIZE
))
752 gboolean r
= self
->client
->functions
& OB_CLIENT_FUNC_RESIZE
;
753 XSetWindowAttributes a
;
755 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTH
: OB_CURSOR_NONE
);
756 XChangeWindowAttributes(ob_display
, self
->topresize
, CWCursor
, &a
);
757 XChangeWindowAttributes(ob_display
, self
->titletop
, CWCursor
, &a
);
758 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTHWEST
: OB_CURSOR_NONE
);
759 XChangeWindowAttributes(ob_display
, self
->tltresize
, CWCursor
, &a
);
760 XChangeWindowAttributes(ob_display
, self
->tllresize
, CWCursor
, &a
);
761 XChangeWindowAttributes(ob_display
, self
->titletopleft
, CWCursor
, &a
);
762 XChangeWindowAttributes(ob_display
, self
->titleleft
, CWCursor
, &a
);
763 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTHEAST
: OB_CURSOR_NONE
);
764 XChangeWindowAttributes(ob_display
, self
->trtresize
, CWCursor
, &a
);
765 XChangeWindowAttributes(ob_display
, self
->trrresize
, CWCursor
, &a
);
766 XChangeWindowAttributes(ob_display
, self
->titletopright
, CWCursor
, &a
);
767 XChangeWindowAttributes(ob_display
, self
->titleright
, CWCursor
, &a
);
768 a
.cursor
= ob_cursor(r
? OB_CURSOR_WEST
: OB_CURSOR_NONE
);
769 XChangeWindowAttributes(ob_display
, self
->left
, CWCursor
, &a
);
770 a
.cursor
= ob_cursor(r
? OB_CURSOR_EAST
: OB_CURSOR_NONE
);
771 XChangeWindowAttributes(ob_display
, self
->right
, CWCursor
, &a
);
772 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTH
: OB_CURSOR_NONE
);
773 XChangeWindowAttributes(ob_display
, self
->handle
, CWCursor
, &a
);
774 XChangeWindowAttributes(ob_display
, self
->handletop
, CWCursor
, &a
);
775 XChangeWindowAttributes(ob_display
, self
->handlebottom
, CWCursor
, &a
);
776 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTHWEST
: OB_CURSOR_NONE
);
777 XChangeWindowAttributes(ob_display
, self
->lgrip
, CWCursor
, &a
);
778 XChangeWindowAttributes(ob_display
, self
->handleleft
, CWCursor
, &a
);
779 XChangeWindowAttributes(ob_display
, self
->lgripleft
, CWCursor
, &a
);
780 XChangeWindowAttributes(ob_display
, self
->lgriptop
, CWCursor
, &a
);
781 XChangeWindowAttributes(ob_display
, self
->lgripbottom
, CWCursor
, &a
);
782 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTHEAST
: OB_CURSOR_NONE
);
783 XChangeWindowAttributes(ob_display
, self
->rgrip
, CWCursor
, &a
);
784 XChangeWindowAttributes(ob_display
, self
->handleright
, CWCursor
, &a
);
785 XChangeWindowAttributes(ob_display
, self
->rgripright
, CWCursor
, &a
);
786 XChangeWindowAttributes(ob_display
, self
->rgriptop
, CWCursor
, &a
);
787 XChangeWindowAttributes(ob_display
, self
->rgripbottom
, CWCursor
, &a
);
789 self
->functions
= self
->client
->functions
;
793 void frame_adjust_client_area(ObFrame
*self
)
795 /* resize the plate */
796 XResizeWindow(ob_display
, self
->plate
,
797 self
->client
->area
.width
, self
->client
->area
.height
);
800 void frame_adjust_state(ObFrame
*self
)
802 framerender_frame(self
);
805 void frame_adjust_focus(ObFrame
*self
, gboolean hilite
)
807 self
->focused
= hilite
;
808 framerender_frame(self
);
812 void frame_adjust_title(ObFrame
*self
)
814 framerender_frame(self
);
817 void frame_adjust_icon(ObFrame
*self
)
819 framerender_frame(self
);
822 void frame_grab_client(ObFrame
*self
)
824 /* reparent the client to the frame */
825 XReparentWindow(ob_display
, self
->client
->window
, self
->plate
, 0, 0);
828 When reparenting the client window, it is usually not mapped yet, since
829 this occurs from a MapRequest. However, in the case where Openbox is
830 starting up, the window is already mapped, so we'll see unmap events for
831 it. There are 2 unmap events generated that we see, one with the 'event'
832 member set the root window, and one set to the client, but both get
833 handled and need to be ignored.
835 if (ob_state() == OB_STATE_STARTING
)
836 self
->client
->ignore_unmaps
+= 2;
838 /* select the event mask on the client's parent (to receive config/map
839 req's) the ButtonPress is to catch clicks on the client border */
840 XSelectInput(ob_display
, self
->plate
, PLATE_EVENTMASK
);
842 /* map the client so it maps when the frame does */
843 XMapWindow(ob_display
, self
->client
->window
);
845 /* set all the windows for the frame in the window_map */
846 g_hash_table_insert(window_map
, &self
->window
, self
->client
);
847 g_hash_table_insert(window_map
, &self
->plate
, self
->client
);
848 g_hash_table_insert(window_map
, &self
->inner
, self
->client
);
849 g_hash_table_insert(window_map
, &self
->title
, self
->client
);
850 g_hash_table_insert(window_map
, &self
->label
, self
->client
);
851 g_hash_table_insert(window_map
, &self
->max
, self
->client
);
852 g_hash_table_insert(window_map
, &self
->close
, self
->client
);
853 g_hash_table_insert(window_map
, &self
->desk
, self
->client
);
854 g_hash_table_insert(window_map
, &self
->shade
, self
->client
);
855 g_hash_table_insert(window_map
, &self
->icon
, self
->client
);
856 g_hash_table_insert(window_map
, &self
->iconify
, self
->client
);
857 g_hash_table_insert(window_map
, &self
->handle
, self
->client
);
858 g_hash_table_insert(window_map
, &self
->lgrip
, self
->client
);
859 g_hash_table_insert(window_map
, &self
->rgrip
, self
->client
);
860 g_hash_table_insert(window_map
, &self
->topresize
, self
->client
);
861 g_hash_table_insert(window_map
, &self
->tltresize
, self
->client
);
862 g_hash_table_insert(window_map
, &self
->tllresize
, self
->client
);
863 g_hash_table_insert(window_map
, &self
->trtresize
, self
->client
);
864 g_hash_table_insert(window_map
, &self
->trrresize
, self
->client
);
865 g_hash_table_insert(window_map
, &self
->left
, self
->client
);
866 g_hash_table_insert(window_map
, &self
->right
, self
->client
);
867 g_hash_table_insert(window_map
, &self
->titleleft
, self
->client
);
868 g_hash_table_insert(window_map
, &self
->titletop
, self
->client
);
869 g_hash_table_insert(window_map
, &self
->titletopleft
, self
->client
);
870 g_hash_table_insert(window_map
, &self
->titletopright
, self
->client
);
871 g_hash_table_insert(window_map
, &self
->titleright
, self
->client
);
872 g_hash_table_insert(window_map
, &self
->titlebottom
, self
->client
);
873 g_hash_table_insert(window_map
, &self
->handleleft
, self
->client
);
874 g_hash_table_insert(window_map
, &self
->handletop
, self
->client
);
875 g_hash_table_insert(window_map
, &self
->handleright
, self
->client
);
876 g_hash_table_insert(window_map
, &self
->handlebottom
, self
->client
);
877 g_hash_table_insert(window_map
, &self
->lgripleft
, self
->client
);
878 g_hash_table_insert(window_map
, &self
->lgriptop
, self
->client
);
879 g_hash_table_insert(window_map
, &self
->lgripbottom
, self
->client
);
880 g_hash_table_insert(window_map
, &self
->rgripright
, self
->client
);
881 g_hash_table_insert(window_map
, &self
->rgriptop
, self
->client
);
882 g_hash_table_insert(window_map
, &self
->rgripbottom
, self
->client
);
885 void frame_release_client(ObFrame
*self
)
888 gboolean reparent
= TRUE
;
890 /* if there was any animation going on, kill it */
891 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
894 /* check if the app has already reparented its window away */
895 while (XCheckTypedWindowEvent(ob_display
, self
->client
->window
,
896 ReparentNotify
, &ev
))
898 /* This check makes sure we don't catch our own reparent action to
899 our frame window. This doesn't count as the app reparenting itself
902 Reparent events that are generated by us are just discarded here.
903 They are of no consequence to us anyhow.
905 if (ev
.xreparent
.parent
!= self
->plate
) {
907 XPutBackEvent(ob_display
, &ev
);
913 /* according to the ICCCM - if the client doesn't reparent itself,
914 then we will reparent the window to root for them */
915 XReparentWindow(ob_display
, self
->client
->window
,
916 RootWindow(ob_display
, ob_screen
),
917 self
->client
->area
.x
,
918 self
->client
->area
.y
);
921 /* remove all the windows for the frame from the window_map */
922 g_hash_table_remove(window_map
, &self
->window
);
923 g_hash_table_remove(window_map
, &self
->plate
);
924 g_hash_table_remove(window_map
, &self
->inner
);
925 g_hash_table_remove(window_map
, &self
->title
);
926 g_hash_table_remove(window_map
, &self
->label
);
927 g_hash_table_remove(window_map
, &self
->max
);
928 g_hash_table_remove(window_map
, &self
->close
);
929 g_hash_table_remove(window_map
, &self
->desk
);
930 g_hash_table_remove(window_map
, &self
->shade
);
931 g_hash_table_remove(window_map
, &self
->icon
);
932 g_hash_table_remove(window_map
, &self
->iconify
);
933 g_hash_table_remove(window_map
, &self
->handle
);
934 g_hash_table_remove(window_map
, &self
->lgrip
);
935 g_hash_table_remove(window_map
, &self
->rgrip
);
936 g_hash_table_remove(window_map
, &self
->topresize
);
937 g_hash_table_remove(window_map
, &self
->tltresize
);
938 g_hash_table_remove(window_map
, &self
->tllresize
);
939 g_hash_table_remove(window_map
, &self
->trtresize
);
940 g_hash_table_remove(window_map
, &self
->trrresize
);
941 g_hash_table_remove(window_map
, &self
->left
);
942 g_hash_table_remove(window_map
, &self
->right
);
943 g_hash_table_remove(window_map
, &self
->titleleft
);
944 g_hash_table_remove(window_map
, &self
->titletop
);
945 g_hash_table_remove(window_map
, &self
->titletopleft
);
946 g_hash_table_remove(window_map
, &self
->titletopright
);
947 g_hash_table_remove(window_map
, &self
->titleright
);
948 g_hash_table_remove(window_map
, &self
->titlebottom
);
949 g_hash_table_remove(window_map
, &self
->handleleft
);
950 g_hash_table_remove(window_map
, &self
->handletop
);
951 g_hash_table_remove(window_map
, &self
->handleright
);
952 g_hash_table_remove(window_map
, &self
->handlebottom
);
953 g_hash_table_remove(window_map
, &self
->lgripleft
);
954 g_hash_table_remove(window_map
, &self
->lgriptop
);
955 g_hash_table_remove(window_map
, &self
->lgripbottom
);
956 g_hash_table_remove(window_map
, &self
->rgripright
);
957 g_hash_table_remove(window_map
, &self
->rgriptop
);
958 g_hash_table_remove(window_map
, &self
->rgripbottom
);
960 ob_main_loop_timeout_remove_data(ob_main_loop
, flash_timeout
, self
, TRUE
);
963 /* is there anything present between us and the label? */
964 static gboolean
is_button_present(ObFrame
*self
, const gchar
*lc
, gint dir
) {
965 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+= dir
) {
966 if (*lc
== ' ') continue; /* it was invalid */
967 if (*lc
== 'N' && self
->decorations
& OB_FRAME_DECOR_ICON
)
969 if (*lc
== 'D' && self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
)
971 if (*lc
== 'S' && self
->decorations
& OB_FRAME_DECOR_SHADE
)
973 if (*lc
== 'I' && self
->decorations
& OB_FRAME_DECOR_ICONIFY
)
975 if (*lc
== 'M' && self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
)
977 if (*lc
== 'C' && self
->decorations
& OB_FRAME_DECOR_CLOSE
)
979 if (*lc
== 'L') return FALSE
;
984 static void layout_title(ObFrame
*self
)
989 const gint bwidth
= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
990 /* position of the left most button */
991 const gint left
= ob_rr_theme
->paddingx
+ 1;
992 /* position of the right most button */
993 const gint right
= self
->width
- bwidth
;
995 /* turn them all off */
996 self
->icon_on
= self
->desk_on
= self
->shade_on
= self
->iconify_on
=
997 self
->max_on
= self
->close_on
= self
->label_on
= FALSE
;
998 self
->label_width
= self
->width
- (ob_rr_theme
->paddingx
+ 1) * 2;
999 self
->leftmost
= self
->rightmost
= OB_FRAME_CONTEXT_NONE
;
1001 /* figure out what's being show, find each element's position, and the
1004 do the ones before the label, then after the label,
1005 i will be +1 the first time through when working to the left,
1006 and -1 the second time through when working to the right */
1007 for (i
= 1; i
>= -1; i
-=2) {
1009 ObFrameContext
*firstcon
;
1013 lc
= config_title_layout
;
1014 firstcon
= &self
->leftmost
;
1017 lc
= config_title_layout
+ strlen(config_title_layout
)-1;
1018 firstcon
= &self
->rightmost
;
1021 /* stop at the end of the string (or the label, which calls break) */
1022 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+=i
) {
1025 self
->label_on
= TRUE
;
1028 break; /* break the for loop, do other side of label */
1029 } else if (*lc
== 'N') {
1030 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICON
;
1031 if ((self
->icon_on
= is_button_present(self
, lc
, i
))) {
1032 /* icon is bigger than buttons */
1033 self
->label_width
-= bwidth
+ 2;
1035 x
+= i
* (bwidth
+ 2);
1037 } else if (*lc
== 'D') {
1038 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ALLDESKTOPS
;
1039 if ((self
->desk_on
= is_button_present(self
, lc
, i
))) {
1040 self
->label_width
-= bwidth
;
1044 } else if (*lc
== 'S') {
1045 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_SHADE
;
1046 if ((self
->shade_on
= is_button_present(self
, lc
, i
))) {
1047 self
->label_width
-= bwidth
;
1051 } else if (*lc
== 'I') {
1052 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICONIFY
;
1053 if ((self
->iconify_on
= is_button_present(self
, lc
, i
))) {
1054 self
->label_width
-= bwidth
;
1055 self
->iconify_x
= x
;
1058 } else if (*lc
== 'M') {
1059 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_MAXIMIZE
;
1060 if ((self
->max_on
= is_button_present(self
, lc
, i
))) {
1061 self
->label_width
-= bwidth
;
1065 } else if (*lc
== 'C') {
1066 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_CLOSE
;
1067 if ((self
->close_on
= is_button_present(self
, lc
, i
))) {
1068 self
->label_width
-= bwidth
;
1073 continue; /* don't set firstcon */
1078 /* position and map the elements */
1079 if (self
->icon_on
) {
1080 XMapWindow(ob_display
, self
->icon
);
1081 XMoveWindow(ob_display
, self
->icon
, self
->icon_x
,
1082 ob_rr_theme
->paddingy
);
1084 XUnmapWindow(ob_display
, self
->icon
);
1086 if (self
->desk_on
) {
1087 XMapWindow(ob_display
, self
->desk
);
1088 XMoveWindow(ob_display
, self
->desk
, self
->desk_x
,
1089 ob_rr_theme
->paddingy
+ 1);
1091 XUnmapWindow(ob_display
, self
->desk
);
1093 if (self
->shade_on
) {
1094 XMapWindow(ob_display
, self
->shade
);
1095 XMoveWindow(ob_display
, self
->shade
, self
->shade_x
,
1096 ob_rr_theme
->paddingy
+ 1);
1098 XUnmapWindow(ob_display
, self
->shade
);
1100 if (self
->iconify_on
) {
1101 XMapWindow(ob_display
, self
->iconify
);
1102 XMoveWindow(ob_display
, self
->iconify
, self
->iconify_x
,
1103 ob_rr_theme
->paddingy
+ 1);
1105 XUnmapWindow(ob_display
, self
->iconify
);
1108 XMapWindow(ob_display
, self
->max
);
1109 XMoveWindow(ob_display
, self
->max
, self
->max_x
,
1110 ob_rr_theme
->paddingy
+ 1);
1112 XUnmapWindow(ob_display
, self
->max
);
1114 if (self
->close_on
) {
1115 XMapWindow(ob_display
, self
->close
);
1116 XMoveWindow(ob_display
, self
->close
, self
->close_x
,
1117 ob_rr_theme
->paddingy
+ 1);
1119 XUnmapWindow(ob_display
, self
->close
);
1121 if (self
->label_on
) {
1122 self
->label_width
= MAX(1, self
->label_width
); /* no lower than 1 */
1123 XMapWindow(ob_display
, self
->label
);
1124 XMoveWindow(ob_display
, self
->label
, self
->label_x
,
1125 ob_rr_theme
->paddingy
);
1127 XUnmapWindow(ob_display
, self
->label
);
1130 ObFrameContext
frame_context_from_string(const gchar
*name
)
1132 if (!g_ascii_strcasecmp("Desktop", name
))
1133 return OB_FRAME_CONTEXT_DESKTOP
;
1134 else if (!g_ascii_strcasecmp("Root", name
))
1135 return OB_FRAME_CONTEXT_ROOT
;
1136 else if (!g_ascii_strcasecmp("Client", name
))
1137 return OB_FRAME_CONTEXT_CLIENT
;
1138 else if (!g_ascii_strcasecmp("Titlebar", name
))
1139 return OB_FRAME_CONTEXT_TITLEBAR
;
1140 else if (!g_ascii_strcasecmp("Frame", name
))
1141 return OB_FRAME_CONTEXT_FRAME
;
1142 else if (!g_ascii_strcasecmp("TLCorner", name
))
1143 return OB_FRAME_CONTEXT_TLCORNER
;
1144 else if (!g_ascii_strcasecmp("TRCorner", name
))
1145 return OB_FRAME_CONTEXT_TRCORNER
;
1146 else if (!g_ascii_strcasecmp("BLCorner", name
))
1147 return OB_FRAME_CONTEXT_BLCORNER
;
1148 else if (!g_ascii_strcasecmp("BRCorner", name
))
1149 return OB_FRAME_CONTEXT_BRCORNER
;
1150 else if (!g_ascii_strcasecmp("Top", name
))
1151 return OB_FRAME_CONTEXT_TOP
;
1152 else if (!g_ascii_strcasecmp("Bottom", name
))
1153 return OB_FRAME_CONTEXT_BOTTOM
;
1154 else if (!g_ascii_strcasecmp("Left", name
))
1155 return OB_FRAME_CONTEXT_LEFT
;
1156 else if (!g_ascii_strcasecmp("Right", name
))
1157 return OB_FRAME_CONTEXT_RIGHT
;
1158 else if (!g_ascii_strcasecmp("Maximize", name
))
1159 return OB_FRAME_CONTEXT_MAXIMIZE
;
1160 else if (!g_ascii_strcasecmp("AllDesktops", name
))
1161 return OB_FRAME_CONTEXT_ALLDESKTOPS
;
1162 else if (!g_ascii_strcasecmp("Shade", name
))
1163 return OB_FRAME_CONTEXT_SHADE
;
1164 else if (!g_ascii_strcasecmp("Iconify", name
))
1165 return OB_FRAME_CONTEXT_ICONIFY
;
1166 else if (!g_ascii_strcasecmp("Icon", name
))
1167 return OB_FRAME_CONTEXT_ICON
;
1168 else if (!g_ascii_strcasecmp("Close", name
))
1169 return OB_FRAME_CONTEXT_CLOSE
;
1170 else if (!g_ascii_strcasecmp("MoveResize", name
))
1171 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
1172 return OB_FRAME_CONTEXT_NONE
;
1175 ObFrameContext
frame_context(ObClient
*client
, Window win
, gint x
, gint y
)
1179 if (moveresize_in_progress
)
1180 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
1182 if (win
== RootWindow(ob_display
, ob_screen
))
1183 return OB_FRAME_CONTEXT_ROOT
;
1184 if (client
== NULL
) return OB_FRAME_CONTEXT_NONE
;
1185 if (win
== client
->window
) {
1186 /* conceptually, this is the desktop, as far as users are
1188 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
1189 return OB_FRAME_CONTEXT_DESKTOP
;
1190 return OB_FRAME_CONTEXT_CLIENT
;
1193 self
= client
->frame
;
1194 if (win
== self
->inner
|| win
== self
->plate
) {
1195 /* conceptually, this is the desktop, as far as users are
1197 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
1198 return OB_FRAME_CONTEXT_DESKTOP
;
1199 return OB_FRAME_CONTEXT_CLIENT
;
1202 if (win
== self
->title
) {
1203 /* when the user clicks in the corners of the titlebar and the client
1204 is fully maximized, then treat it like they clicked in the
1205 button that is there */
1206 if (self
->client
->max_horz
&& self
->client
->max_vert
&&
1207 y
< ob_rr_theme
->paddingy
+ 1 + ob_rr_theme
->button_size
)
1209 if (x
< ((ob_rr_theme
->paddingx
+ 1) * 2 +
1210 ob_rr_theme
->button_size
)) {
1211 if (self
->leftmost
!= OB_FRAME_CONTEXT_NONE
)
1212 return self
->leftmost
;
1214 else if (x
> (self
->width
-
1215 (ob_rr_theme
->paddingx
+ 1 +
1216 ob_rr_theme
->button_size
)))
1218 if (self
->rightmost
!= OB_FRAME_CONTEXT_NONE
)
1219 return self
->rightmost
;
1222 return OB_FRAME_CONTEXT_TITLEBAR
;
1225 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
1226 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
1227 if (win
== self
->handle
) return OB_FRAME_CONTEXT_BOTTOM
;
1228 if (win
== self
->handletop
) return OB_FRAME_CONTEXT_BOTTOM
;
1229 if (win
== self
->handlebottom
) return OB_FRAME_CONTEXT_BOTTOM
;
1230 if (win
== self
->handleleft
) return OB_FRAME_CONTEXT_BLCORNER
;
1231 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
1232 if (win
== self
->lgripleft
) return OB_FRAME_CONTEXT_BLCORNER
;
1233 if (win
== self
->lgriptop
) return OB_FRAME_CONTEXT_BLCORNER
;
1234 if (win
== self
->lgripbottom
) return OB_FRAME_CONTEXT_BLCORNER
;
1235 if (win
== self
->handleright
) return OB_FRAME_CONTEXT_BRCORNER
;
1236 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
1237 if (win
== self
->rgripright
) return OB_FRAME_CONTEXT_BLCORNER
;
1238 if (win
== self
->rgriptop
) return OB_FRAME_CONTEXT_BLCORNER
;
1239 if (win
== self
->rgripbottom
) return OB_FRAME_CONTEXT_BLCORNER
;
1240 if (win
== self
->titletop
) return OB_FRAME_CONTEXT_TOP
;
1241 if (win
== self
->topresize
) return OB_FRAME_CONTEXT_TOP
;
1242 if (win
== self
->tltresize
) return OB_FRAME_CONTEXT_TLCORNER
;
1243 if (win
== self
->tllresize
) return OB_FRAME_CONTEXT_TLCORNER
;
1244 if (win
== self
->titleleft
) return OB_FRAME_CONTEXT_TLCORNER
;
1245 if (win
== self
->titletopleft
) return OB_FRAME_CONTEXT_TLCORNER
;
1246 if (win
== self
->trtresize
) return OB_FRAME_CONTEXT_TRCORNER
;
1247 if (win
== self
->trrresize
) return OB_FRAME_CONTEXT_TRCORNER
;
1248 if (win
== self
->titleright
) return OB_FRAME_CONTEXT_TRCORNER
;
1249 if (win
== self
->titletopright
) return OB_FRAME_CONTEXT_TRCORNER
;
1250 if (win
== self
->left
) return OB_FRAME_CONTEXT_LEFT
;
1251 if (win
== self
->right
) return OB_FRAME_CONTEXT_RIGHT
;
1252 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
1253 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
1254 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
1255 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
1256 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
1257 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
1259 return OB_FRAME_CONTEXT_NONE
;
1262 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
1265 switch (self
->client
->gravity
) {
1267 case NorthWestGravity
:
1268 case SouthWestGravity
:
1275 *x
-= (self
->size
.left
+ w
) / 2;
1278 case NorthEastGravity
:
1279 case SouthEastGravity
:
1281 *x
-= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
1286 *x
-= self
->size
.left
;
1291 switch (self
->client
->gravity
) {
1293 case NorthWestGravity
:
1294 case NorthEastGravity
:
1301 *y
-= (self
->size
.top
+ h
) / 2;
1304 case SouthWestGravity
:
1305 case SouthEastGravity
:
1307 *y
-= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
1312 *y
-= self
->size
.top
;
1317 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
1320 switch (self
->client
->gravity
) {
1322 case NorthWestGravity
:
1324 case SouthWestGravity
:
1329 *x
+= (self
->size
.left
+ w
) / 2;
1331 case NorthEastGravity
:
1333 case SouthEastGravity
:
1334 *x
+= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
1338 *x
+= self
->size
.left
;
1343 switch (self
->client
->gravity
) {
1345 case NorthWestGravity
:
1347 case NorthEastGravity
:
1352 *y
+= (self
->size
.top
+ h
) / 2;
1354 case SouthWestGravity
:
1356 case SouthEastGravity
:
1357 *y
+= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
1361 *y
+= self
->size
.top
;
1366 static void flash_done(gpointer data
)
1368 ObFrame
*self
= data
;
1370 if (self
->focused
!= self
->flash_on
)
1371 frame_adjust_focus(self
, self
->focused
);
1374 static gboolean
flash_timeout(gpointer data
)
1376 ObFrame
*self
= data
;
1379 g_get_current_time(&now
);
1380 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
1381 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
1382 now
.tv_usec
>= self
->flash_end
.tv_usec
))
1383 self
->flashing
= FALSE
;
1385 if (!self
->flashing
)
1386 return FALSE
; /* we are done */
1388 self
->flash_on
= !self
->flash_on
;
1389 if (!self
->focused
) {
1390 frame_adjust_focus(self
, self
->flash_on
);
1391 self
->focused
= FALSE
;
1394 return TRUE
; /* go again */
1397 void frame_flash_start(ObFrame
*self
)
1399 self
->flash_on
= self
->focused
;
1401 if (!self
->flashing
)
1402 ob_main_loop_timeout_add(ob_main_loop
,
1403 G_USEC_PER_SEC
* 0.6,
1408 g_get_current_time(&self
->flash_end
);
1409 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
1411 self
->flashing
= TRUE
;
1414 void frame_flash_stop(ObFrame
*self
)
1416 self
->flashing
= FALSE
;
1419 static gulong
frame_animate_iconify_time_left(ObFrame
*self
,
1420 const GTimeVal
*now
)
1423 sec
= self
->iconify_animation_end
.tv_sec
- now
->tv_sec
;
1424 usec
= self
->iconify_animation_end
.tv_usec
- now
->tv_usec
;
1426 usec
+= G_USEC_PER_SEC
;
1429 /* no negative values */
1430 return MAX(sec
* G_USEC_PER_SEC
+ usec
, 0);
1433 static gboolean
frame_animate_iconify(gpointer p
)
1437 gint iconx
, icony
, iconw
;
1440 gboolean iconifying
;
1442 if (self
->client
->icon_geometry
.width
== 0) {
1443 /* there is no icon geometry set so just go straight down */
1444 Rect
*a
= screen_physical_area();
1445 iconx
= self
->area
.x
+ self
->area
.width
/ 2 + 32;
1446 icony
= a
->y
+ a
->width
;
1449 iconx
= self
->client
->icon_geometry
.x
;
1450 icony
= self
->client
->icon_geometry
.y
;
1451 iconw
= self
->client
->icon_geometry
.width
;
1454 iconifying
= self
->iconify_animation_going
> 0;
1456 /* how far do we have left to go ? */
1457 g_get_current_time(&now
);
1458 time
= frame_animate_iconify_time_left(self
, &now
);
1460 if (time
== 0 || iconifying
) {
1461 /* start where the frame is supposed to be */
1464 w
= self
->area
.width
;
1465 h
= self
->area
.height
;
1467 /* start at the icon */
1471 h
= self
->size
.top
; /* just the titlebar */
1478 dx
= self
->area
.x
- iconx
;
1479 dy
= self
->area
.y
- icony
;
1480 dw
= self
->area
.width
- self
->bwidth
* 2 - iconw
;
1481 /* if restoring, we move in the opposite direction */
1482 if (!iconifying
) { dx
= -dx
; dy
= -dy
; dw
= -dw
; }
1484 elapsed
= FRAME_ANIMATE_ICONIFY_TIME
- time
;
1485 x
= x
- (dx
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1486 y
= y
- (dy
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1487 w
= w
- (dw
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1488 h
= self
->size
.top
; /* just the titlebar */
1492 frame_end_iconify_animation(self
);
1494 XMoveResizeWindow(ob_display
, self
->window
, x
, y
, w
, h
);
1498 return time
> 0; /* repeat until we're out of time */
1501 void frame_end_iconify_animation(ObFrame
*self
)
1503 /* see if there is an animation going */
1504 if (self
->iconify_animation_going
== 0) return;
1507 XUnmapWindow(ob_display
, self
->window
);
1509 /* Send a ConfigureNotify when the animation is done, this fixes
1510 KDE's pager showing the window in the wrong place. */
1511 client_reconfigure(self
->client
);
1513 /* we're not animating any more ! */
1514 self
->iconify_animation_going
= 0;
1516 XMoveResizeWindow(ob_display
, self
->window
,
1517 self
->area
.x
, self
->area
.y
,
1518 self
->area
.width
, self
->area
.height
);
1522 void frame_begin_iconify_animation(ObFrame
*self
, gboolean iconifying
)
1525 gboolean new_anim
= FALSE
;
1526 gboolean set_end
= TRUE
;
1529 /* if there is no titlebar, just don't animate for now
1530 XXX it would be nice tho.. */
1531 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1534 /* get the current time */
1535 g_get_current_time(&now
);
1537 /* get how long until the end */
1538 time
= FRAME_ANIMATE_ICONIFY_TIME
;
1539 if (self
->iconify_animation_going
) {
1540 if (!!iconifying
!= (self
->iconify_animation_going
> 0)) {
1541 /* animation was already going on in the opposite direction */
1542 time
= time
- frame_animate_iconify_time_left(self
, &now
);
1544 /* animation was already going in the same direction */
1548 self
->iconify_animation_going
= iconifying
? 1 : -1;
1550 /* set the ending time */
1552 self
->iconify_animation_end
.tv_sec
= now
.tv_sec
;
1553 self
->iconify_animation_end
.tv_usec
= now
.tv_usec
;
1554 g_time_val_add(&self
->iconify_animation_end
, time
);
1558 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
1560 ob_main_loop_timeout_add(ob_main_loop
,
1561 FRAME_ANIMATE_ICONIFY_STEP_TIME
,
1562 frame_animate_iconify
, self
,
1563 g_direct_equal
, NULL
);
1565 /* do the first step */
1566 frame_animate_iconify(self
);
1568 /* show it during the animation even if it is not "visible" */
1570 XMapWindow(ob_display
, self
->window
);