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
);
58 static void frame_adjust_cursors(ObFrame
*self
);
60 static Window
createWindow(Window parent
, Visual
*visual
,
61 gulong mask
, XSetWindowAttributes
*attrib
)
63 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
64 (visual
? 32 : RrDepth(ob_rr_inst
)), InputOutput
,
65 (visual
? visual
: RrVisual(ob_rr_inst
)),
70 static Visual
*check_32bit_client(ObClient
*c
)
72 XWindowAttributes wattrib
;
75 /* we're already running at 32 bit depth, yay. we don't need to use their
77 if (RrDepth(ob_rr_inst
) == 32)
80 ret
= XGetWindowAttributes(ob_display
, c
->window
, &wattrib
);
81 g_assert(ret
!= BadDrawable
);
82 g_assert(ret
!= BadWindow
);
84 if (wattrib
.depth
== 32)
85 return wattrib
.visual
;
89 ObFrame
*frame_new(ObClient
*client
)
91 XSetWindowAttributes attrib
;
96 self
= g_new0(ObFrame
, 1);
97 self
->client
= client
;
99 visual
= check_32bit_client(client
);
101 /* create the non-visible decor windows */
105 /* client has a 32-bit visual */
106 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
107 /* create a colormap with the visual */
108 self
->colormap
= attrib
.colormap
=
109 XCreateColormap(ob_display
,
110 RootWindow(ob_display
, ob_screen
),
112 attrib
.background_pixel
= BlackPixel(ob_display
, ob_screen
);
113 attrib
.border_pixel
= BlackPixel(ob_display
, ob_screen
);
115 attrib
.event_mask
= FRAME_EVENTMASK
;
116 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
), visual
,
119 attrib
.event_mask
= INNER_EVENTMASK
;
120 self
->inner
= createWindow(self
->window
, visual
, mask
, &attrib
);
122 mask
&= ~CWEventMask
;
123 self
->plate
= createWindow(self
->inner
, visual
, mask
, &attrib
);
125 /* create the visible decor windows */
129 /* client has a 32-bit visual */
130 mask
|= CWColormap
| CWBackPixel
| CWBorderPixel
;
131 attrib
.colormap
= RrColormap(ob_rr_inst
);
133 attrib
.event_mask
= ELEMENT_EVENTMASK
;
134 self
->title
= createWindow(self
->window
, NULL
, mask
, &attrib
);
135 self
->titleleft
= createWindow(self
->window
, NULL
, mask
, &attrib
);
136 self
->titletop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
137 self
->titletopleft
= createWindow(self
->window
, NULL
, mask
, &attrib
);
138 self
->titletopright
= createWindow(self
->window
, NULL
, mask
, &attrib
);
139 self
->titleright
= createWindow(self
->window
, NULL
, mask
, &attrib
);
140 self
->titlebottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
142 self
->topresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
143 self
->tltresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
144 self
->tllresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
145 self
->trtresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
146 self
->trrresize
= createWindow(self
->title
, NULL
, mask
, &attrib
);
148 self
->left
= createWindow(self
->window
, NULL
, mask
, &attrib
);
149 self
->right
= createWindow(self
->window
, NULL
, mask
, &attrib
);
151 self
->label
= createWindow(self
->title
, NULL
, mask
, &attrib
);
152 self
->max
= createWindow(self
->title
, NULL
, mask
, &attrib
);
153 self
->close
= createWindow(self
->title
, NULL
, mask
, &attrib
);
154 self
->desk
= createWindow(self
->title
, NULL
, mask
, &attrib
);
155 self
->shade
= createWindow(self
->title
, NULL
, mask
, &attrib
);
156 self
->icon
= createWindow(self
->title
, NULL
, mask
, &attrib
);
157 self
->iconify
= createWindow(self
->title
, NULL
, mask
, &attrib
);
159 self
->handle
= createWindow(self
->window
, NULL
, mask
, &attrib
);
160 self
->lgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
161 self
->rgrip
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
163 self
->handleleft
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
164 self
->handleright
= createWindow(self
->handle
, NULL
, mask
, &attrib
);
166 self
->handletop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
167 self
->handlebottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
168 self
->lgripleft
= createWindow(self
->window
, NULL
, mask
, &attrib
);
169 self
->lgriptop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
170 self
->lgripbottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
171 self
->rgripright
= createWindow(self
->window
, NULL
, mask
, &attrib
);
172 self
->rgriptop
= createWindow(self
->window
, NULL
, mask
, &attrib
);
173 self
->rgripbottom
= createWindow(self
->window
, NULL
, mask
, &attrib
);
175 self
->focused
= FALSE
;
177 /* the other stuff is shown based on decor settings */
178 XMapWindow(ob_display
, self
->plate
);
179 XMapWindow(ob_display
, self
->inner
);
180 XMapWindow(ob_display
, self
->label
);
182 self
->max_press
= self
->close_press
= self
->desk_press
=
183 self
->iconify_press
= self
->shade_press
= FALSE
;
184 self
->max_hover
= self
->close_hover
= self
->desk_hover
=
185 self
->iconify_hover
= self
->shade_hover
= FALSE
;
187 set_theme_statics(self
);
189 return (ObFrame
*)self
;
192 static void set_theme_statics(ObFrame
*self
)
194 /* set colors/appearance/sizes for stuff that doesn't change */
195 XResizeWindow(ob_display
, self
->max
,
196 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
197 XResizeWindow(ob_display
, self
->iconify
,
198 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
199 XResizeWindow(ob_display
, self
->icon
,
200 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
201 XResizeWindow(ob_display
, self
->close
,
202 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
203 XResizeWindow(ob_display
, self
->desk
,
204 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
205 XResizeWindow(ob_display
, self
->shade
,
206 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
207 XResizeWindow(ob_display
, self
->tltresize
,
208 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
209 XResizeWindow(ob_display
, self
->trtresize
,
210 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
211 XResizeWindow(ob_display
, self
->tllresize
,
212 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
213 XResizeWindow(ob_display
, self
->trrresize
,
214 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
216 /* set up the dynamic appearances */
217 self
->a_unfocused_title
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_title
);
218 self
->a_focused_title
= RrAppearanceCopy(ob_rr_theme
->a_focused_title
);
219 self
->a_unfocused_label
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_label
);
220 self
->a_focused_label
= RrAppearanceCopy(ob_rr_theme
->a_focused_label
);
221 self
->a_unfocused_handle
=
222 RrAppearanceCopy(ob_rr_theme
->a_unfocused_handle
);
223 self
->a_focused_handle
= RrAppearanceCopy(ob_rr_theme
->a_focused_handle
);
224 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_icon
);
227 static void free_theme_statics(ObFrame
*self
)
229 RrAppearanceFree(self
->a_unfocused_title
);
230 RrAppearanceFree(self
->a_focused_title
);
231 RrAppearanceFree(self
->a_unfocused_label
);
232 RrAppearanceFree(self
->a_focused_label
);
233 RrAppearanceFree(self
->a_unfocused_handle
);
234 RrAppearanceFree(self
->a_focused_handle
);
235 RrAppearanceFree(self
->a_icon
);
238 void frame_free(ObFrame
*self
)
240 free_theme_statics(self
);
242 XDestroyWindow(ob_display
, self
->window
);
244 XFreeColormap(ob_display
, self
->colormap
);
249 void frame_show(ObFrame
*self
)
251 if (!self
->visible
) {
252 self
->visible
= TRUE
;
253 XMapWindow(ob_display
, self
->client
->window
);
254 XMapWindow(ob_display
, self
->window
);
258 void frame_hide(ObFrame
*self
)
261 self
->visible
= FALSE
;
262 if (!frame_iconify_animating(self
))
263 XUnmapWindow(ob_display
, self
->window
);
264 /* we unmap the client itself so that we can get MapRequest
265 events, and because the ICCCM tells us to! */
266 XUnmapWindow(ob_display
, self
->client
->window
);
267 self
->client
->ignore_unmaps
+= 1;
271 void frame_adjust_theme(ObFrame
*self
)
273 free_theme_statics(self
);
274 set_theme_statics(self
);
277 void frame_adjust_shape(ObFrame
*self
)
283 if (!self
->client
->shaped
) {
284 /* clear the shape on the frame window */
285 XShapeCombineMask(ob_display
, self
->window
, ShapeBounding
,
290 /* make the frame's shape match the clients */
291 XShapeCombineShape(ob_display
, self
->window
, ShapeBounding
,
294 self
->client
->window
,
295 ShapeBounding
, ShapeSet
);
298 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
301 xrect
[0].width
= self
->area
.width
;
302 xrect
[0].height
= ob_rr_theme
->title_height
+
303 self
->bwidth
+ self
->rbwidth
;
307 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
308 ob_rr_theme
->handle_height
> 0)
311 xrect
[1].y
= FRAME_HANDLE_Y(self
);
312 xrect
[1].width
= self
->area
.width
;
313 xrect
[1].height
= ob_rr_theme
->handle_height
+
318 XShapeCombineRectangles(ob_display
, self
->window
,
319 ShapeBounding
, 0, 0, xrect
, num
,
320 ShapeUnion
, Unsorted
);
325 void frame_adjust_area(ObFrame
*self
, gboolean moved
,
326 gboolean resized
, gboolean fake
)
330 oldsize
= self
->size
;
333 /* do this before changing the frame's status like max_horz max_vert */
334 frame_adjust_cursors(self
);
336 self
->functions
= self
->client
->functions
;
337 self
->decorations
= self
->client
->decorations
;
338 self
->max_horz
= self
->client
->max_horz
;
339 self
->max_vert
= self
->client
->max_vert
;
341 if (self
->decorations
& OB_FRAME_DECOR_BORDER
) {
342 self
->bwidth
= ob_rr_theme
->fbwidth
;
343 self
->cbwidth_x
= ob_rr_theme
->cbwidthx
;
344 self
->cbwidth_y
= ob_rr_theme
->cbwidthy
;
346 self
->bwidth
= self
->cbwidth_x
= self
->cbwidth_y
= 0;
348 self
->rbwidth
= self
->bwidth
;
350 if (self
->max_horz
) {
352 self
->width
= self
->client
->area
.width
- self
->bwidth
* 2;
354 self
->width
= self
->client
->area
.width
+ self
->cbwidth_x
* 2;
356 STRUT_SET(self
->size
,
357 self
->cbwidth_x
+ (!self
->max_horz
? self
->bwidth
: 0),
358 self
->cbwidth_y
+ self
->bwidth
,
359 self
->cbwidth_x
+ (!self
->max_horz
? self
->bwidth
: 0),
360 self
->cbwidth_y
+ self
->bwidth
);
362 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
363 self
->size
.top
+= ob_rr_theme
->title_height
+ self
->rbwidth
;
364 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
365 ob_rr_theme
->handle_height
> 0)
367 self
->size
.bottom
+= ob_rr_theme
->handle_height
+ self
->bwidth
;
370 /* position/size and map/unmap all the windows */
374 XMoveResizeWindow(ob_display
, self
->titletop
,
375 ob_rr_theme
->grip_width
+ self
->bwidth
, 0,
376 /* width + bwidth*2 - bwidth*2 - grips*2 */
377 self
->width
+ ob_rr_theme
->grip_width
* 2,
379 XMoveResizeWindow(ob_display
, self
->titletopleft
,
381 ob_rr_theme
->grip_width
+ self
->bwidth
,
383 XMoveResizeWindow(ob_display
, self
->titletopright
,
384 self
->client
->area
.width
+
385 self
->size
.left
+ self
->size
.right
-
386 ob_rr_theme
->grip_width
- self
->bwidth
,
388 ob_rr_theme
->grip_width
+ self
->bwidth
,
391 XMoveResizeWindow(ob_display
, self
->titleleft
,
395 ob_rr_theme
->grip_width
:
396 self
->size
.top
- self
->bwidth
));
397 XMoveResizeWindow(ob_display
, self
->titleright
,
398 self
->client
->area
.width
+
399 self
->size
.left
+ self
->size
.right
-
404 ob_rr_theme
->grip_width
:
405 self
->size
.top
- self
->bwidth
));
407 XMapWindow(ob_display
, self
->titletop
);
408 XMapWindow(ob_display
, self
->titletopleft
);
409 XMapWindow(ob_display
, self
->titletopright
);
410 XMapWindow(ob_display
, self
->titleleft
);
411 XMapWindow(ob_display
, self
->titleright
);
413 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
&&
416 XMoveResizeWindow(ob_display
, self
->titlebottom
,
418 ob_rr_theme
->title_height
+ self
->bwidth
,
422 XMapWindow(ob_display
, self
->titlebottom
);
424 XUnmapWindow(ob_display
, self
->titlebottom
);
426 XUnmapWindow(ob_display
, self
->titlebottom
);
428 XUnmapWindow(ob_display
, self
->titletop
);
429 XUnmapWindow(ob_display
, self
->titletopleft
);
430 XUnmapWindow(ob_display
, self
->titletopright
);
431 XUnmapWindow(ob_display
, self
->titleleft
);
432 XUnmapWindow(ob_display
, self
->titleright
);
435 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
436 XMoveResizeWindow(ob_display
, self
->title
,
437 self
->bwidth
, self
->bwidth
,
438 self
->width
, ob_rr_theme
->title_height
);
440 XMapWindow(ob_display
, self
->title
);
442 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
443 XMoveResizeWindow(ob_display
, self
->topresize
,
444 ob_rr_theme
->grip_width
+ self
->bwidth
,
446 self
->width
- (ob_rr_theme
->grip_width
+
448 ob_rr_theme
->paddingy
+ 1);
450 XMoveWindow(ob_display
, self
->tltresize
, 0, 0);
451 XMoveWindow(ob_display
, self
->tllresize
, 0, 0);
452 XMoveWindow(ob_display
, self
->trtresize
,
453 self
->width
- ob_rr_theme
->grip_width
, 0);
454 XMoveWindow(ob_display
, self
->trrresize
,
455 self
->width
- ob_rr_theme
->paddingx
- 1, 0);
457 XMapWindow(ob_display
, self
->topresize
);
458 XMapWindow(ob_display
, self
->tltresize
);
459 XMapWindow(ob_display
, self
->tllresize
);
460 XMapWindow(ob_display
, self
->trtresize
);
461 XMapWindow(ob_display
, self
->trrresize
);
463 XUnmapWindow(ob_display
, self
->topresize
);
464 XUnmapWindow(ob_display
, self
->tltresize
);
465 XUnmapWindow(ob_display
, self
->tllresize
);
466 XUnmapWindow(ob_display
, self
->trtresize
);
467 XUnmapWindow(ob_display
, self
->trrresize
);
470 XUnmapWindow(ob_display
, self
->title
);
473 if ((self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
474 /* layout the title bar elements */
479 XMoveResizeWindow(ob_display
, self
->handlebottom
,
480 ob_rr_theme
->grip_width
+
482 self
->size
.top
+ self
->client
->area
.height
+
483 self
->size
.bottom
- self
->bwidth
,
484 self
->width
- (ob_rr_theme
->grip_width
+
488 XMoveResizeWindow(ob_display
, self
->lgripleft
,
490 self
->size
.top
+ self
->client
->area
.height
+
493 ob_rr_theme
->grip_width
:
497 ob_rr_theme
->grip_width
:
499 XMoveResizeWindow(ob_display
, self
->rgripright
,
500 self
->size
.left
+ self
->client
->area
.width
+
501 self
->size
.right
- self
->bwidth
,
502 self
->size
.top
+ self
->client
->area
.height
+
505 ob_rr_theme
->grip_width
:
509 ob_rr_theme
->grip_width
:
512 XMoveResizeWindow(ob_display
, self
->lgripbottom
,
514 self
->size
.top
+ self
->client
->area
.height
+
515 self
->size
.bottom
- self
->bwidth
,
516 ob_rr_theme
->grip_width
+ self
->bwidth
,
518 XMoveResizeWindow(ob_display
, self
->rgripbottom
,
519 self
->size
.left
+ self
->client
->area
.width
+
520 self
->size
.right
- self
->bwidth
* 2 -
521 ob_rr_theme
->grip_width
,
522 self
->size
.top
+ self
->client
->area
.height
+
523 self
->size
.bottom
- self
->bwidth
,
524 ob_rr_theme
->grip_width
+ self
->bwidth
,
527 XMapWindow(ob_display
, self
->handlebottom
);
528 XMapWindow(ob_display
, self
->lgripleft
);
529 XMapWindow(ob_display
, self
->rgripright
);
530 XMapWindow(ob_display
, self
->lgripbottom
);
531 XMapWindow(ob_display
, self
->rgripbottom
);
533 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
534 ob_rr_theme
->handle_height
> 0)
536 XMoveResizeWindow(ob_display
, self
->handletop
,
537 ob_rr_theme
->grip_width
+
539 FRAME_HANDLE_Y(self
),
540 self
->width
- (ob_rr_theme
->grip_width
+
543 XMapWindow(ob_display
, self
->handletop
);
545 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
546 XMoveResizeWindow(ob_display
, self
->handleleft
,
547 ob_rr_theme
->grip_width
,
550 ob_rr_theme
->handle_height
);
551 XMoveResizeWindow(ob_display
, self
->handleright
,
553 ob_rr_theme
->grip_width
-
557 ob_rr_theme
->handle_height
);
559 XMoveResizeWindow(ob_display
, self
->lgriptop
,
561 FRAME_HANDLE_Y(self
),
562 ob_rr_theme
->grip_width
+
565 XMoveResizeWindow(ob_display
, self
->rgriptop
,
567 self
->client
->area
.width
+
568 self
->size
.right
- self
->bwidth
* 2 -
569 ob_rr_theme
->grip_width
,
570 FRAME_HANDLE_Y(self
),
571 ob_rr_theme
->grip_width
+
575 XMapWindow(ob_display
, self
->handleleft
);
576 XMapWindow(ob_display
, self
->handleright
);
577 XMapWindow(ob_display
, self
->lgriptop
);
578 XMapWindow(ob_display
, self
->rgriptop
);
580 XUnmapWindow(ob_display
, self
->handleleft
);
581 XUnmapWindow(ob_display
, self
->handleright
);
582 XUnmapWindow(ob_display
, self
->lgriptop
);
583 XUnmapWindow(ob_display
, self
->rgriptop
);
586 XUnmapWindow(ob_display
, self
->handleleft
);
587 XUnmapWindow(ob_display
, self
->handleright
);
588 XUnmapWindow(ob_display
, self
->lgriptop
);
589 XUnmapWindow(ob_display
, self
->rgriptop
);
591 XUnmapWindow(ob_display
, self
->handletop
);
594 XUnmapWindow(ob_display
, self
->handleleft
);
595 XUnmapWindow(ob_display
, self
->handleright
);
596 XUnmapWindow(ob_display
, self
->lgriptop
);
597 XUnmapWindow(ob_display
, self
->rgriptop
);
599 XUnmapWindow(ob_display
, self
->handletop
);
601 XUnmapWindow(ob_display
, self
->handlebottom
);
602 XUnmapWindow(ob_display
, self
->lgripleft
);
603 XUnmapWindow(ob_display
, self
->rgripright
);
604 XUnmapWindow(ob_display
, self
->lgripbottom
);
605 XUnmapWindow(ob_display
, self
->rgripbottom
);
608 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
609 ob_rr_theme
->handle_height
> 0)
611 XMoveResizeWindow(ob_display
, self
->handle
,
613 FRAME_HANDLE_Y(self
) + self
->bwidth
,
614 self
->width
, ob_rr_theme
->handle_height
);
615 XMapWindow(ob_display
, self
->handle
);
617 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
618 XMoveResizeWindow(ob_display
, self
->lgrip
,
620 ob_rr_theme
->grip_width
,
621 ob_rr_theme
->handle_height
);
622 XMoveResizeWindow(ob_display
, self
->rgrip
,
623 self
->width
- ob_rr_theme
->grip_width
,
625 ob_rr_theme
->grip_width
,
626 ob_rr_theme
->handle_height
);
628 XMapWindow(ob_display
, self
->lgrip
);
629 XMapWindow(ob_display
, self
->rgrip
);
631 XUnmapWindow(ob_display
, self
->lgrip
);
632 XUnmapWindow(ob_display
, self
->rgrip
);
635 XUnmapWindow(ob_display
, self
->lgrip
);
636 XUnmapWindow(ob_display
, self
->rgrip
);
638 XUnmapWindow(ob_display
, self
->handle
);
641 if (self
->bwidth
&& !self
->max_horz
) {
642 XMoveResizeWindow(ob_display
, self
->left
,
644 self
->bwidth
+ ob_rr_theme
->grip_width
,
646 self
->client
->area
.height
+
647 self
->size
.top
+ self
->size
.bottom
-
648 ob_rr_theme
->grip_width
* 2);
650 XMapWindow(ob_display
, self
->left
);
652 XUnmapWindow(ob_display
, self
->left
);
654 if (self
->bwidth
&& !self
->max_horz
) {
655 XMoveResizeWindow(ob_display
, self
->right
,
656 self
->client
->area
.width
+
657 self
->cbwidth_x
* 2 + self
->bwidth
,
658 self
->bwidth
+ ob_rr_theme
->grip_width
,
660 self
->client
->area
.height
+
661 self
->size
.top
+ self
->size
.bottom
-
662 ob_rr_theme
->grip_width
* 2);
664 XMapWindow(ob_display
, self
->right
);
666 XUnmapWindow(ob_display
, self
->right
);
668 /* move and resize the inner border window which contains the plate
670 XMoveResizeWindow(ob_display
, self
->inner
,
672 self
->size
.top
- self
->cbwidth_y
,
673 self
->client
->area
.width
+
674 self
->cbwidth_x
* 2 +
675 (!self
->max_horz
? self
->bwidth
* 2 : 0),
676 self
->client
->area
.height
+
677 self
->cbwidth_y
* 2);
680 XMoveWindow(ob_display
, self
->plate
,
681 (!self
->max_horz
? self
->bwidth
: 0) + self
->cbwidth_x
,
684 /* when the client has StaticGravity, it likes to move around. */
685 XMoveWindow(ob_display
, self
->client
->window
, 0, 0);
689 /* shading can change without being moved or resized */
690 RECT_SET_SIZE(self
->area
,
691 self
->client
->area
.width
+
692 self
->size
.left
+ self
->size
.right
,
693 (self
->client
->shaded
?
694 ob_rr_theme
->title_height
+ self
->bwidth
* 2:
695 self
->client
->area
.height
+
696 self
->size
.top
+ self
->size
.bottom
));
698 if (moved
|| resized
) {
699 /* find the new coordinates, done after setting the frame.size, for
700 frame_client_gravity. */
701 self
->area
.x
= self
->client
->area
.x
;
702 self
->area
.y
= self
->client
->area
.y
;
703 frame_client_gravity(self
, &self
->area
.x
, &self
->area
.y
,
704 self
->client
->area
.width
,
705 self
->client
->area
.height
);
709 if (!frame_iconify_animating(self
))
710 /* move and resize the top level frame.
711 shading can change without being moved or resized.
713 but don't do this during an iconify animation. it will be
714 reflected afterwards.
716 XMoveResizeWindow(ob_display
, self
->window
,
723 framerender_frame(self
);
724 frame_adjust_shape(self
);
727 if (!STRUT_EQUAL(self
->size
, oldsize
)) {
729 vals
[0] = self
->size
.left
;
730 vals
[1] = self
->size
.right
;
731 vals
[2] = self
->size
.top
;
732 vals
[3] = self
->size
.bottom
;
733 PROP_SETA32(self
->client
->window
, net_frame_extents
,
735 PROP_SETA32(self
->client
->window
, kde_net_wm_frame_strut
,
739 /* if this occurs while we are focus cycling, the indicator needs to
741 if (focus_cycle_target
== self
->client
)
742 focus_cycle_draw_indicator(self
->client
);
744 if (resized
&& (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
745 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
746 ob_rr_theme
->label_height
);
749 static void frame_adjust_cursors(ObFrame
*self
)
751 if ((self
->functions
& OB_CLIENT_FUNC_RESIZE
) !=
752 (self
->client
->functions
& OB_CLIENT_FUNC_RESIZE
) ||
753 ((self
->max_horz
&& self
->max_vert
) !=
754 (self
->client
->max_horz
&& self
->client
->max_vert
)))
756 gboolean r
= (self
->client
->functions
& OB_CLIENT_FUNC_RESIZE
) &&
757 !(self
->client
->max_horz
&& self
->client
->max_vert
);
758 XSetWindowAttributes a
;
760 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTH
: OB_CURSOR_NONE
);
761 XChangeWindowAttributes(ob_display
, self
->topresize
, CWCursor
, &a
);
762 XChangeWindowAttributes(ob_display
, self
->titletop
, CWCursor
, &a
);
763 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTHWEST
: OB_CURSOR_NONE
);
764 XChangeWindowAttributes(ob_display
, self
->tltresize
, CWCursor
, &a
);
765 XChangeWindowAttributes(ob_display
, self
->tllresize
, CWCursor
, &a
);
766 XChangeWindowAttributes(ob_display
, self
->titletopleft
, CWCursor
, &a
);
767 XChangeWindowAttributes(ob_display
, self
->titleleft
, CWCursor
, &a
);
768 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTHEAST
: OB_CURSOR_NONE
);
769 XChangeWindowAttributes(ob_display
, self
->trtresize
, CWCursor
, &a
);
770 XChangeWindowAttributes(ob_display
, self
->trrresize
, CWCursor
, &a
);
771 XChangeWindowAttributes(ob_display
, self
->titletopright
, CWCursor
, &a
);
772 XChangeWindowAttributes(ob_display
, self
->titleright
, CWCursor
, &a
);
773 a
.cursor
= ob_cursor(r
? OB_CURSOR_WEST
: OB_CURSOR_NONE
);
774 XChangeWindowAttributes(ob_display
, self
->left
, CWCursor
, &a
);
775 a
.cursor
= ob_cursor(r
? OB_CURSOR_EAST
: OB_CURSOR_NONE
);
776 XChangeWindowAttributes(ob_display
, self
->right
, CWCursor
, &a
);
777 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTH
: OB_CURSOR_NONE
);
778 XChangeWindowAttributes(ob_display
, self
->handle
, CWCursor
, &a
);
779 XChangeWindowAttributes(ob_display
, self
->handletop
, CWCursor
, &a
);
780 XChangeWindowAttributes(ob_display
, self
->handlebottom
, CWCursor
, &a
);
781 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTHWEST
: OB_CURSOR_NONE
);
782 XChangeWindowAttributes(ob_display
, self
->lgrip
, CWCursor
, &a
);
783 XChangeWindowAttributes(ob_display
, self
->handleleft
, CWCursor
, &a
);
784 XChangeWindowAttributes(ob_display
, self
->lgripleft
, CWCursor
, &a
);
785 XChangeWindowAttributes(ob_display
, self
->lgriptop
, CWCursor
, &a
);
786 XChangeWindowAttributes(ob_display
, self
->lgripbottom
, CWCursor
, &a
);
787 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTHEAST
: OB_CURSOR_NONE
);
788 XChangeWindowAttributes(ob_display
, self
->rgrip
, CWCursor
, &a
);
789 XChangeWindowAttributes(ob_display
, self
->handleright
, CWCursor
, &a
);
790 XChangeWindowAttributes(ob_display
, self
->rgripright
, CWCursor
, &a
);
791 XChangeWindowAttributes(ob_display
, self
->rgriptop
, CWCursor
, &a
);
792 XChangeWindowAttributes(ob_display
, self
->rgripbottom
, CWCursor
, &a
);
796 void frame_adjust_client_area(ObFrame
*self
)
798 /* resize the plate */
799 XResizeWindow(ob_display
, self
->plate
,
800 self
->client
->area
.width
, self
->client
->area
.height
);
803 void frame_adjust_state(ObFrame
*self
)
805 framerender_frame(self
);
808 void frame_adjust_focus(ObFrame
*self
, gboolean hilite
)
810 self
->focused
= hilite
;
811 framerender_frame(self
);
815 void frame_adjust_title(ObFrame
*self
)
817 framerender_frame(self
);
820 void frame_adjust_icon(ObFrame
*self
)
822 framerender_frame(self
);
825 void frame_grab_client(ObFrame
*self
)
827 /* reparent the client to the frame */
828 XReparentWindow(ob_display
, self
->client
->window
, self
->plate
, 0, 0);
831 When reparenting the client window, it is usually not mapped yet, since
832 this occurs from a MapRequest. However, in the case where Openbox is
833 starting up, the window is already mapped, so we'll see unmap events for
834 it. There are 2 unmap events generated that we see, one with the 'event'
835 member set the root window, and one set to the client, but both get
836 handled and need to be ignored.
838 if (ob_state() == OB_STATE_STARTING
)
839 self
->client
->ignore_unmaps
+= 2;
841 /* select the event mask on the client's parent (to receive config/map
842 req's) the ButtonPress is to catch clicks on the client border */
843 XSelectInput(ob_display
, self
->plate
, PLATE_EVENTMASK
);
845 /* map the client so it maps when the frame does */
846 XMapWindow(ob_display
, self
->client
->window
);
848 /* set all the windows for the frame in the window_map */
849 g_hash_table_insert(window_map
, &self
->window
, self
->client
);
850 g_hash_table_insert(window_map
, &self
->plate
, self
->client
);
851 g_hash_table_insert(window_map
, &self
->inner
, self
->client
);
852 g_hash_table_insert(window_map
, &self
->title
, self
->client
);
853 g_hash_table_insert(window_map
, &self
->label
, self
->client
);
854 g_hash_table_insert(window_map
, &self
->max
, self
->client
);
855 g_hash_table_insert(window_map
, &self
->close
, self
->client
);
856 g_hash_table_insert(window_map
, &self
->desk
, self
->client
);
857 g_hash_table_insert(window_map
, &self
->shade
, self
->client
);
858 g_hash_table_insert(window_map
, &self
->icon
, self
->client
);
859 g_hash_table_insert(window_map
, &self
->iconify
, self
->client
);
860 g_hash_table_insert(window_map
, &self
->handle
, self
->client
);
861 g_hash_table_insert(window_map
, &self
->lgrip
, self
->client
);
862 g_hash_table_insert(window_map
, &self
->rgrip
, self
->client
);
863 g_hash_table_insert(window_map
, &self
->topresize
, self
->client
);
864 g_hash_table_insert(window_map
, &self
->tltresize
, self
->client
);
865 g_hash_table_insert(window_map
, &self
->tllresize
, self
->client
);
866 g_hash_table_insert(window_map
, &self
->trtresize
, self
->client
);
867 g_hash_table_insert(window_map
, &self
->trrresize
, self
->client
);
868 g_hash_table_insert(window_map
, &self
->left
, self
->client
);
869 g_hash_table_insert(window_map
, &self
->right
, self
->client
);
870 g_hash_table_insert(window_map
, &self
->titleleft
, self
->client
);
871 g_hash_table_insert(window_map
, &self
->titletop
, self
->client
);
872 g_hash_table_insert(window_map
, &self
->titletopleft
, self
->client
);
873 g_hash_table_insert(window_map
, &self
->titletopright
, self
->client
);
874 g_hash_table_insert(window_map
, &self
->titleright
, self
->client
);
875 g_hash_table_insert(window_map
, &self
->titlebottom
, self
->client
);
876 g_hash_table_insert(window_map
, &self
->handleleft
, self
->client
);
877 g_hash_table_insert(window_map
, &self
->handletop
, self
->client
);
878 g_hash_table_insert(window_map
, &self
->handleright
, self
->client
);
879 g_hash_table_insert(window_map
, &self
->handlebottom
, self
->client
);
880 g_hash_table_insert(window_map
, &self
->lgripleft
, self
->client
);
881 g_hash_table_insert(window_map
, &self
->lgriptop
, self
->client
);
882 g_hash_table_insert(window_map
, &self
->lgripbottom
, self
->client
);
883 g_hash_table_insert(window_map
, &self
->rgripright
, self
->client
);
884 g_hash_table_insert(window_map
, &self
->rgriptop
, self
->client
);
885 g_hash_table_insert(window_map
, &self
->rgripbottom
, self
->client
);
888 void frame_release_client(ObFrame
*self
)
891 gboolean reparent
= TRUE
;
893 /* if there was any animation going on, kill it */
894 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
897 /* check if the app has already reparented its window away */
898 while (XCheckTypedWindowEvent(ob_display
, self
->client
->window
,
899 ReparentNotify
, &ev
))
901 /* This check makes sure we don't catch our own reparent action to
902 our frame window. This doesn't count as the app reparenting itself
905 Reparent events that are generated by us are just discarded here.
906 They are of no consequence to us anyhow.
908 if (ev
.xreparent
.parent
!= self
->plate
) {
910 XPutBackEvent(ob_display
, &ev
);
916 /* according to the ICCCM - if the client doesn't reparent itself,
917 then we will reparent the window to root for them */
918 XReparentWindow(ob_display
, self
->client
->window
,
919 RootWindow(ob_display
, ob_screen
),
920 self
->client
->area
.x
,
921 self
->client
->area
.y
);
924 /* remove all the windows for the frame from the window_map */
925 g_hash_table_remove(window_map
, &self
->window
);
926 g_hash_table_remove(window_map
, &self
->plate
);
927 g_hash_table_remove(window_map
, &self
->inner
);
928 g_hash_table_remove(window_map
, &self
->title
);
929 g_hash_table_remove(window_map
, &self
->label
);
930 g_hash_table_remove(window_map
, &self
->max
);
931 g_hash_table_remove(window_map
, &self
->close
);
932 g_hash_table_remove(window_map
, &self
->desk
);
933 g_hash_table_remove(window_map
, &self
->shade
);
934 g_hash_table_remove(window_map
, &self
->icon
);
935 g_hash_table_remove(window_map
, &self
->iconify
);
936 g_hash_table_remove(window_map
, &self
->handle
);
937 g_hash_table_remove(window_map
, &self
->lgrip
);
938 g_hash_table_remove(window_map
, &self
->rgrip
);
939 g_hash_table_remove(window_map
, &self
->topresize
);
940 g_hash_table_remove(window_map
, &self
->tltresize
);
941 g_hash_table_remove(window_map
, &self
->tllresize
);
942 g_hash_table_remove(window_map
, &self
->trtresize
);
943 g_hash_table_remove(window_map
, &self
->trrresize
);
944 g_hash_table_remove(window_map
, &self
->left
);
945 g_hash_table_remove(window_map
, &self
->right
);
946 g_hash_table_remove(window_map
, &self
->titleleft
);
947 g_hash_table_remove(window_map
, &self
->titletop
);
948 g_hash_table_remove(window_map
, &self
->titletopleft
);
949 g_hash_table_remove(window_map
, &self
->titletopright
);
950 g_hash_table_remove(window_map
, &self
->titleright
);
951 g_hash_table_remove(window_map
, &self
->titlebottom
);
952 g_hash_table_remove(window_map
, &self
->handleleft
);
953 g_hash_table_remove(window_map
, &self
->handletop
);
954 g_hash_table_remove(window_map
, &self
->handleright
);
955 g_hash_table_remove(window_map
, &self
->handlebottom
);
956 g_hash_table_remove(window_map
, &self
->lgripleft
);
957 g_hash_table_remove(window_map
, &self
->lgriptop
);
958 g_hash_table_remove(window_map
, &self
->lgripbottom
);
959 g_hash_table_remove(window_map
, &self
->rgripright
);
960 g_hash_table_remove(window_map
, &self
->rgriptop
);
961 g_hash_table_remove(window_map
, &self
->rgripbottom
);
963 ob_main_loop_timeout_remove_data(ob_main_loop
, flash_timeout
, self
, TRUE
);
966 /* is there anything present between us and the label? */
967 static gboolean
is_button_present(ObFrame
*self
, const gchar
*lc
, gint dir
) {
968 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+= dir
) {
969 if (*lc
== ' ') continue; /* it was invalid */
970 if (*lc
== 'N' && self
->decorations
& OB_FRAME_DECOR_ICON
)
972 if (*lc
== 'D' && self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
)
974 if (*lc
== 'S' && self
->decorations
& OB_FRAME_DECOR_SHADE
)
976 if (*lc
== 'I' && self
->decorations
& OB_FRAME_DECOR_ICONIFY
)
978 if (*lc
== 'M' && self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
)
980 if (*lc
== 'C' && self
->decorations
& OB_FRAME_DECOR_CLOSE
)
982 if (*lc
== 'L') return FALSE
;
987 static void layout_title(ObFrame
*self
)
992 const gint bwidth
= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
993 /* position of the left most button */
994 const gint left
= ob_rr_theme
->paddingx
+ 1;
995 /* position of the right most button */
996 const gint right
= self
->width
- bwidth
;
998 /* turn them all off */
999 self
->icon_on
= self
->desk_on
= self
->shade_on
= self
->iconify_on
=
1000 self
->max_on
= self
->close_on
= self
->label_on
= FALSE
;
1001 self
->label_width
= self
->width
- (ob_rr_theme
->paddingx
+ 1) * 2;
1002 self
->leftmost
= self
->rightmost
= OB_FRAME_CONTEXT_NONE
;
1004 /* figure out what's being show, find each element's position, and the
1007 do the ones before the label, then after the label,
1008 i will be +1 the first time through when working to the left,
1009 and -1 the second time through when working to the right */
1010 for (i
= 1; i
>= -1; i
-=2) {
1012 ObFrameContext
*firstcon
;
1016 lc
= config_title_layout
;
1017 firstcon
= &self
->leftmost
;
1020 lc
= config_title_layout
+ strlen(config_title_layout
)-1;
1021 firstcon
= &self
->rightmost
;
1024 /* stop at the end of the string (or the label, which calls break) */
1025 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+=i
) {
1028 self
->label_on
= TRUE
;
1031 break; /* break the for loop, do other side of label */
1032 } else if (*lc
== 'N') {
1033 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICON
;
1034 if ((self
->icon_on
= is_button_present(self
, lc
, i
))) {
1035 /* icon is bigger than buttons */
1036 self
->label_width
-= bwidth
+ 2;
1038 x
+= i
* (bwidth
+ 2);
1040 } else if (*lc
== 'D') {
1041 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ALLDESKTOPS
;
1042 if ((self
->desk_on
= is_button_present(self
, lc
, i
))) {
1043 self
->label_width
-= bwidth
;
1047 } else if (*lc
== 'S') {
1048 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_SHADE
;
1049 if ((self
->shade_on
= is_button_present(self
, lc
, i
))) {
1050 self
->label_width
-= bwidth
;
1054 } else if (*lc
== 'I') {
1055 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICONIFY
;
1056 if ((self
->iconify_on
= is_button_present(self
, lc
, i
))) {
1057 self
->label_width
-= bwidth
;
1058 self
->iconify_x
= x
;
1061 } else if (*lc
== 'M') {
1062 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_MAXIMIZE
;
1063 if ((self
->max_on
= is_button_present(self
, lc
, i
))) {
1064 self
->label_width
-= bwidth
;
1068 } else if (*lc
== 'C') {
1069 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_CLOSE
;
1070 if ((self
->close_on
= is_button_present(self
, lc
, i
))) {
1071 self
->label_width
-= bwidth
;
1076 continue; /* don't set firstcon */
1081 /* position and map the elements */
1082 if (self
->icon_on
) {
1083 XMapWindow(ob_display
, self
->icon
);
1084 XMoveWindow(ob_display
, self
->icon
, self
->icon_x
,
1085 ob_rr_theme
->paddingy
);
1087 XUnmapWindow(ob_display
, self
->icon
);
1089 if (self
->desk_on
) {
1090 XMapWindow(ob_display
, self
->desk
);
1091 XMoveWindow(ob_display
, self
->desk
, self
->desk_x
,
1092 ob_rr_theme
->paddingy
+ 1);
1094 XUnmapWindow(ob_display
, self
->desk
);
1096 if (self
->shade_on
) {
1097 XMapWindow(ob_display
, self
->shade
);
1098 XMoveWindow(ob_display
, self
->shade
, self
->shade_x
,
1099 ob_rr_theme
->paddingy
+ 1);
1101 XUnmapWindow(ob_display
, self
->shade
);
1103 if (self
->iconify_on
) {
1104 XMapWindow(ob_display
, self
->iconify
);
1105 XMoveWindow(ob_display
, self
->iconify
, self
->iconify_x
,
1106 ob_rr_theme
->paddingy
+ 1);
1108 XUnmapWindow(ob_display
, self
->iconify
);
1111 XMapWindow(ob_display
, self
->max
);
1112 XMoveWindow(ob_display
, self
->max
, self
->max_x
,
1113 ob_rr_theme
->paddingy
+ 1);
1115 XUnmapWindow(ob_display
, self
->max
);
1117 if (self
->close_on
) {
1118 XMapWindow(ob_display
, self
->close
);
1119 XMoveWindow(ob_display
, self
->close
, self
->close_x
,
1120 ob_rr_theme
->paddingy
+ 1);
1122 XUnmapWindow(ob_display
, self
->close
);
1124 if (self
->label_on
) {
1125 self
->label_width
= MAX(1, self
->label_width
); /* no lower than 1 */
1126 XMapWindow(ob_display
, self
->label
);
1127 XMoveWindow(ob_display
, self
->label
, self
->label_x
,
1128 ob_rr_theme
->paddingy
);
1130 XUnmapWindow(ob_display
, self
->label
);
1133 ObFrameContext
frame_context_from_string(const gchar
*name
)
1135 if (!g_ascii_strcasecmp("Desktop", name
))
1136 return OB_FRAME_CONTEXT_DESKTOP
;
1137 else if (!g_ascii_strcasecmp("Root", name
))
1138 return OB_FRAME_CONTEXT_ROOT
;
1139 else if (!g_ascii_strcasecmp("Client", name
))
1140 return OB_FRAME_CONTEXT_CLIENT
;
1141 else if (!g_ascii_strcasecmp("Titlebar", name
))
1142 return OB_FRAME_CONTEXT_TITLEBAR
;
1143 else if (!g_ascii_strcasecmp("Frame", name
))
1144 return OB_FRAME_CONTEXT_FRAME
;
1145 else if (!g_ascii_strcasecmp("TLCorner", name
))
1146 return OB_FRAME_CONTEXT_TLCORNER
;
1147 else if (!g_ascii_strcasecmp("TRCorner", name
))
1148 return OB_FRAME_CONTEXT_TRCORNER
;
1149 else if (!g_ascii_strcasecmp("BLCorner", name
))
1150 return OB_FRAME_CONTEXT_BLCORNER
;
1151 else if (!g_ascii_strcasecmp("BRCorner", name
))
1152 return OB_FRAME_CONTEXT_BRCORNER
;
1153 else if (!g_ascii_strcasecmp("Top", name
))
1154 return OB_FRAME_CONTEXT_TOP
;
1155 else if (!g_ascii_strcasecmp("Bottom", name
))
1156 return OB_FRAME_CONTEXT_BOTTOM
;
1157 else if (!g_ascii_strcasecmp("Left", name
))
1158 return OB_FRAME_CONTEXT_LEFT
;
1159 else if (!g_ascii_strcasecmp("Right", name
))
1160 return OB_FRAME_CONTEXT_RIGHT
;
1161 else if (!g_ascii_strcasecmp("Maximize", name
))
1162 return OB_FRAME_CONTEXT_MAXIMIZE
;
1163 else if (!g_ascii_strcasecmp("AllDesktops", name
))
1164 return OB_FRAME_CONTEXT_ALLDESKTOPS
;
1165 else if (!g_ascii_strcasecmp("Shade", name
))
1166 return OB_FRAME_CONTEXT_SHADE
;
1167 else if (!g_ascii_strcasecmp("Iconify", name
))
1168 return OB_FRAME_CONTEXT_ICONIFY
;
1169 else if (!g_ascii_strcasecmp("Icon", name
))
1170 return OB_FRAME_CONTEXT_ICON
;
1171 else if (!g_ascii_strcasecmp("Close", name
))
1172 return OB_FRAME_CONTEXT_CLOSE
;
1173 else if (!g_ascii_strcasecmp("MoveResize", name
))
1174 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
1175 return OB_FRAME_CONTEXT_NONE
;
1178 ObFrameContext
frame_context(ObClient
*client
, Window win
, gint x
, gint y
)
1182 if (moveresize_in_progress
)
1183 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
1185 if (win
== RootWindow(ob_display
, ob_screen
))
1186 return OB_FRAME_CONTEXT_ROOT
;
1187 if (client
== NULL
) return OB_FRAME_CONTEXT_NONE
;
1188 if (win
== client
->window
) {
1189 /* conceptually, this is the desktop, as far as users are
1191 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
1192 return OB_FRAME_CONTEXT_DESKTOP
;
1193 return OB_FRAME_CONTEXT_CLIENT
;
1196 self
= client
->frame
;
1197 if (win
== self
->inner
|| win
== self
->plate
) {
1198 /* conceptually, this is the desktop, as far as users are
1200 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
1201 return OB_FRAME_CONTEXT_DESKTOP
;
1202 return OB_FRAME_CONTEXT_CLIENT
;
1205 /* when the user clicks in the corners of the titlebar and the client
1206 is fully maximized, then treat it like they clicked in the
1207 button that is there */
1208 if (self
->max_horz
&& self
->max_vert
&&
1209 (win
== self
->title
||
1210 win
== self
->titleleft
|| win
== self
->titletopleft
||
1211 win
== self
->titleright
|| win
== self
->titletopright
))
1213 /* get the mouse coords in reference to the whole frame */
1217 /* these windows are down a border width from the top of the frame */
1218 if (win
== self
->title
||
1219 win
== self
->titleleft
|| win
== self
->titleright
)
1222 /* title is a border width in from the edge */
1223 if (win
== self
->title
)
1225 /* titletopright is way to the right edge */
1226 else if (win
== self
->titletopright
)
1227 fx
+= self
->area
.width
- (ob_rr_theme
->grip_width
+ self
->bwidth
);
1228 /* titleright is even more way to the right edge */
1229 else if (win
== self
->titleright
)
1230 fx
+= self
->area
.width
- self
->bwidth
;
1232 /* figure out if we're over the area that should be considered a
1234 if (fy
< self
->bwidth
+ ob_rr_theme
->paddingy
+ 1 +
1235 ob_rr_theme
->button_size
)
1237 if (fx
< (self
->bwidth
+ ob_rr_theme
->paddingx
+ 1 +
1238 ob_rr_theme
->button_size
))
1240 if (self
->leftmost
!= OB_FRAME_CONTEXT_NONE
)
1241 return self
->leftmost
;
1243 else if (fx
>= (self
->area
.width
-
1244 (self
->bwidth
+ ob_rr_theme
->paddingx
+ 1 +
1245 ob_rr_theme
->button_size
)))
1247 if (self
->rightmost
!= OB_FRAME_CONTEXT_NONE
)
1248 return self
->rightmost
;
1253 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
1254 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
1255 if (win
== self
->handle
) return OB_FRAME_CONTEXT_BOTTOM
;
1256 if (win
== self
->handletop
) return OB_FRAME_CONTEXT_BOTTOM
;
1257 if (win
== self
->handlebottom
) return OB_FRAME_CONTEXT_BOTTOM
;
1258 if (win
== self
->handleleft
) return OB_FRAME_CONTEXT_BLCORNER
;
1259 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
1260 if (win
== self
->lgripleft
) return OB_FRAME_CONTEXT_BLCORNER
;
1261 if (win
== self
->lgriptop
) return OB_FRAME_CONTEXT_BLCORNER
;
1262 if (win
== self
->lgripbottom
) return OB_FRAME_CONTEXT_BLCORNER
;
1263 if (win
== self
->handleright
) return OB_FRAME_CONTEXT_BRCORNER
;
1264 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
1265 if (win
== self
->rgripright
) return OB_FRAME_CONTEXT_BLCORNER
;
1266 if (win
== self
->rgriptop
) return OB_FRAME_CONTEXT_BLCORNER
;
1267 if (win
== self
->rgripbottom
) return OB_FRAME_CONTEXT_BLCORNER
;
1268 if (win
== self
->title
) return OB_FRAME_CONTEXT_TITLEBAR
;
1269 if (win
== self
->titleleft
) return OB_FRAME_CONTEXT_TLCORNER
;
1270 if (win
== self
->titletopleft
) return OB_FRAME_CONTEXT_TLCORNER
;
1271 if (win
== self
->titleright
) return OB_FRAME_CONTEXT_TRCORNER
;
1272 if (win
== self
->titletopright
) return OB_FRAME_CONTEXT_TRCORNER
;
1273 if (win
== self
->titletop
) return OB_FRAME_CONTEXT_TOP
;
1274 if (win
== self
->topresize
) return OB_FRAME_CONTEXT_TOP
;
1275 if (win
== self
->tltresize
) return OB_FRAME_CONTEXT_TLCORNER
;
1276 if (win
== self
->tllresize
) return OB_FRAME_CONTEXT_TLCORNER
;
1277 if (win
== self
->trtresize
) return OB_FRAME_CONTEXT_TRCORNER
;
1278 if (win
== self
->trrresize
) return OB_FRAME_CONTEXT_TRCORNER
;
1279 if (win
== self
->left
) return OB_FRAME_CONTEXT_LEFT
;
1280 if (win
== self
->right
) return OB_FRAME_CONTEXT_RIGHT
;
1281 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
1282 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
1283 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
1284 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
1285 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
1286 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
1288 return OB_FRAME_CONTEXT_NONE
;
1291 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
1294 switch (self
->client
->gravity
) {
1296 case NorthWestGravity
:
1297 case SouthWestGravity
:
1304 *x
-= (self
->size
.left
+ w
) / 2;
1307 case NorthEastGravity
:
1308 case SouthEastGravity
:
1310 *x
-= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
1315 *x
-= self
->size
.left
;
1320 switch (self
->client
->gravity
) {
1322 case NorthWestGravity
:
1323 case NorthEastGravity
:
1330 *y
-= (self
->size
.top
+ h
) / 2;
1333 case SouthWestGravity
:
1334 case SouthEastGravity
:
1336 *y
-= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
1341 *y
-= self
->size
.top
;
1346 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
1349 switch (self
->client
->gravity
) {
1351 case NorthWestGravity
:
1353 case SouthWestGravity
:
1358 *x
+= (self
->size
.left
+ w
) / 2;
1360 case NorthEastGravity
:
1362 case SouthEastGravity
:
1363 *x
+= (self
->size
.left
+ self
->size
.right
+ w
) - 1;
1367 *x
+= self
->size
.left
;
1372 switch (self
->client
->gravity
) {
1374 case NorthWestGravity
:
1376 case NorthEastGravity
:
1381 *y
+= (self
->size
.top
+ h
) / 2;
1383 case SouthWestGravity
:
1385 case SouthEastGravity
:
1386 *y
+= (self
->size
.top
+ self
->size
.bottom
+ h
) - 1;
1390 *y
+= self
->size
.top
;
1395 static void flash_done(gpointer data
)
1397 ObFrame
*self
= data
;
1399 if (self
->focused
!= self
->flash_on
)
1400 frame_adjust_focus(self
, self
->focused
);
1403 static gboolean
flash_timeout(gpointer data
)
1405 ObFrame
*self
= data
;
1408 g_get_current_time(&now
);
1409 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
1410 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
1411 now
.tv_usec
>= self
->flash_end
.tv_usec
))
1412 self
->flashing
= FALSE
;
1414 if (!self
->flashing
)
1415 return FALSE
; /* we are done */
1417 self
->flash_on
= !self
->flash_on
;
1418 if (!self
->focused
) {
1419 frame_adjust_focus(self
, self
->flash_on
);
1420 self
->focused
= FALSE
;
1423 return TRUE
; /* go again */
1426 void frame_flash_start(ObFrame
*self
)
1428 self
->flash_on
= self
->focused
;
1430 if (!self
->flashing
)
1431 ob_main_loop_timeout_add(ob_main_loop
,
1432 G_USEC_PER_SEC
* 0.6,
1437 g_get_current_time(&self
->flash_end
);
1438 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
1440 self
->flashing
= TRUE
;
1443 void frame_flash_stop(ObFrame
*self
)
1445 self
->flashing
= FALSE
;
1448 static gulong
frame_animate_iconify_time_left(ObFrame
*self
,
1449 const GTimeVal
*now
)
1452 sec
= self
->iconify_animation_end
.tv_sec
- now
->tv_sec
;
1453 usec
= self
->iconify_animation_end
.tv_usec
- now
->tv_usec
;
1455 usec
+= G_USEC_PER_SEC
;
1458 /* no negative values */
1459 return MAX(sec
* G_USEC_PER_SEC
+ usec
, 0);
1462 static gboolean
frame_animate_iconify(gpointer p
)
1466 gint iconx
, icony
, iconw
;
1469 gboolean iconifying
;
1471 if (self
->client
->icon_geometry
.width
== 0) {
1472 /* there is no icon geometry set so just go straight down */
1473 Rect
*a
= screen_physical_area();
1474 iconx
= self
->area
.x
+ self
->area
.width
/ 2 + 32;
1475 icony
= a
->y
+ a
->width
;
1478 iconx
= self
->client
->icon_geometry
.x
;
1479 icony
= self
->client
->icon_geometry
.y
;
1480 iconw
= self
->client
->icon_geometry
.width
;
1483 iconifying
= self
->iconify_animation_going
> 0;
1485 /* how far do we have left to go ? */
1486 g_get_current_time(&now
);
1487 time
= frame_animate_iconify_time_left(self
, &now
);
1489 if (time
== 0 || iconifying
) {
1490 /* start where the frame is supposed to be */
1493 w
= self
->area
.width
;
1494 h
= self
->area
.height
;
1496 /* start at the icon */
1500 h
= self
->size
.top
; /* just the titlebar */
1507 dx
= self
->area
.x
- iconx
;
1508 dy
= self
->area
.y
- icony
;
1509 dw
= self
->area
.width
- self
->bwidth
* 2 - iconw
;
1510 /* if restoring, we move in the opposite direction */
1511 if (!iconifying
) { dx
= -dx
; dy
= -dy
; dw
= -dw
; }
1513 elapsed
= FRAME_ANIMATE_ICONIFY_TIME
- time
;
1514 x
= x
- (dx
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1515 y
= y
- (dy
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1516 w
= w
- (dw
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1517 h
= self
->size
.top
; /* just the titlebar */
1521 frame_end_iconify_animation(self
);
1523 XMoveResizeWindow(ob_display
, self
->window
, x
, y
, w
, h
);
1527 return time
> 0; /* repeat until we're out of time */
1530 void frame_end_iconify_animation(ObFrame
*self
)
1532 /* see if there is an animation going */
1533 if (self
->iconify_animation_going
== 0) return;
1536 XUnmapWindow(ob_display
, self
->window
);
1538 /* Send a ConfigureNotify when the animation is done, this fixes
1539 KDE's pager showing the window in the wrong place. */
1540 client_reconfigure(self
->client
);
1542 /* we're not animating any more ! */
1543 self
->iconify_animation_going
= 0;
1545 XMoveResizeWindow(ob_display
, self
->window
,
1546 self
->area
.x
, self
->area
.y
,
1547 self
->area
.width
, self
->area
.height
);
1551 void frame_begin_iconify_animation(ObFrame
*self
, gboolean iconifying
)
1554 gboolean new_anim
= FALSE
;
1555 gboolean set_end
= TRUE
;
1558 /* if there is no titlebar, just don't animate for now
1559 XXX it would be nice tho.. */
1560 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1563 /* get the current time */
1564 g_get_current_time(&now
);
1566 /* get how long until the end */
1567 time
= FRAME_ANIMATE_ICONIFY_TIME
;
1568 if (self
->iconify_animation_going
) {
1569 if (!!iconifying
!= (self
->iconify_animation_going
> 0)) {
1570 /* animation was already going on in the opposite direction */
1571 time
= time
- frame_animate_iconify_time_left(self
, &now
);
1573 /* animation was already going in the same direction */
1577 self
->iconify_animation_going
= iconifying
? 1 : -1;
1579 /* set the ending time */
1581 self
->iconify_animation_end
.tv_sec
= now
.tv_sec
;
1582 self
->iconify_animation_end
.tv_usec
= now
.tv_usec
;
1583 g_time_val_add(&self
->iconify_animation_end
, time
);
1587 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
1589 ob_main_loop_timeout_add(ob_main_loop
,
1590 FRAME_ANIMATE_ICONIFY_STEP_TIME
,
1591 frame_animate_iconify
, self
,
1592 g_direct_equal
, NULL
);
1594 /* do the first step */
1595 frame_animate_iconify(self
);
1597 /* show it during the animation even if it is not "visible" */
1599 XMapWindow(ob_display
, self
->window
);