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 /* some elements are sized based of the width, so don't let them have
358 self
->width
= MAX(self
->width
,
359 (ob_rr_theme
->grip_width
+ self
->bwidth
) * 2 + 1);
361 STRUT_SET(self
->size
,
362 self
->cbwidth_x
+ (!self
->max_horz
? self
->bwidth
: 0),
363 self
->cbwidth_y
+ self
->bwidth
,
364 self
->cbwidth_x
+ (!self
->max_horz
? self
->bwidth
: 0),
365 self
->cbwidth_y
+ self
->bwidth
);
367 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
368 self
->size
.top
+= ob_rr_theme
->title_height
+ self
->rbwidth
;
369 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
370 ob_rr_theme
->handle_height
> 0)
372 self
->size
.bottom
+= ob_rr_theme
->handle_height
+ self
->bwidth
;
375 /* position/size and map/unmap all the windows */
381 /* height of titleleft and titleright */
382 titlesides
= (!self
->max_horz
?
383 ob_rr_theme
->grip_width
:
384 self
->size
.top
- self
->bwidth
);
386 XMoveResizeWindow(ob_display
, self
->titletop
,
387 ob_rr_theme
->grip_width
+ self
->bwidth
, 0,
388 /* width + bwidth*2 - bwidth*2 - grips*2 */
389 self
->width
- ob_rr_theme
->grip_width
* 2,
391 XMoveResizeWindow(ob_display
, self
->titletopleft
,
393 ob_rr_theme
->grip_width
+ self
->bwidth
,
395 XMoveResizeWindow(ob_display
, self
->titletopright
,
396 self
->client
->area
.width
+
397 self
->size
.left
+ self
->size
.right
-
398 ob_rr_theme
->grip_width
- self
->bwidth
,
400 ob_rr_theme
->grip_width
+ self
->bwidth
,
403 if (titlesides
> 0) {
404 XMoveResizeWindow(ob_display
, self
->titleleft
,
408 XMoveResizeWindow(ob_display
, self
->titleright
,
409 self
->client
->area
.width
+
410 self
->size
.left
+ self
->size
.right
-
416 XMapWindow(ob_display
, self
->titleleft
);
417 XMapWindow(ob_display
, self
->titleright
);
419 XUnmapWindow(ob_display
, self
->titleleft
);
420 XUnmapWindow(ob_display
, self
->titleright
);
423 XMapWindow(ob_display
, self
->titletop
);
424 XMapWindow(ob_display
, self
->titletopleft
);
425 XMapWindow(ob_display
, self
->titletopright
);
427 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
&&
430 XMoveResizeWindow(ob_display
, self
->titlebottom
,
432 ob_rr_theme
->title_height
+ self
->bwidth
,
436 XMapWindow(ob_display
, self
->titlebottom
);
438 XUnmapWindow(ob_display
, self
->titlebottom
);
440 XUnmapWindow(ob_display
, self
->titlebottom
);
442 XUnmapWindow(ob_display
, self
->titletop
);
443 XUnmapWindow(ob_display
, self
->titletopleft
);
444 XUnmapWindow(ob_display
, self
->titletopright
);
445 XUnmapWindow(ob_display
, self
->titleleft
);
446 XUnmapWindow(ob_display
, self
->titleright
);
449 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
450 XMoveResizeWindow(ob_display
, self
->title
,
451 self
->bwidth
, self
->bwidth
,
452 self
->width
, ob_rr_theme
->title_height
);
454 XMapWindow(ob_display
, self
->title
);
456 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
457 XMoveResizeWindow(ob_display
, self
->topresize
,
458 ob_rr_theme
->grip_width
,
460 self
->width
- ob_rr_theme
->grip_width
*2,
461 ob_rr_theme
->paddingy
+ 1);
463 XMoveWindow(ob_display
, self
->tltresize
, 0, 0);
464 XMoveWindow(ob_display
, self
->tllresize
, 0, 0);
465 XMoveWindow(ob_display
, self
->trtresize
,
466 self
->width
- ob_rr_theme
->grip_width
, 0);
467 XMoveWindow(ob_display
, self
->trrresize
,
468 self
->width
- ob_rr_theme
->paddingx
- 1, 0);
470 XMapWindow(ob_display
, self
->topresize
);
471 XMapWindow(ob_display
, self
->tltresize
);
472 XMapWindow(ob_display
, self
->tllresize
);
473 XMapWindow(ob_display
, self
->trtresize
);
474 XMapWindow(ob_display
, self
->trrresize
);
476 XUnmapWindow(ob_display
, self
->topresize
);
477 XUnmapWindow(ob_display
, self
->tltresize
);
478 XUnmapWindow(ob_display
, self
->tllresize
);
479 XUnmapWindow(ob_display
, self
->trtresize
);
480 XUnmapWindow(ob_display
, self
->trrresize
);
483 XUnmapWindow(ob_display
, self
->title
);
486 if ((self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
487 /* layout the title bar elements */
492 XMoveResizeWindow(ob_display
, self
->handlebottom
,
493 ob_rr_theme
->grip_width
+
495 self
->size
.top
+ self
->client
->area
.height
+
496 self
->size
.bottom
- self
->bwidth
,
497 self
->width
- (ob_rr_theme
->grip_width
+
501 XMoveResizeWindow(ob_display
, self
->lgripleft
,
503 self
->size
.top
+ self
->client
->area
.height
+
506 ob_rr_theme
->grip_width
:
510 ob_rr_theme
->grip_width
:
512 XMoveResizeWindow(ob_display
, self
->rgripright
,
513 self
->size
.left
+ self
->client
->area
.width
+
514 self
->size
.right
- self
->bwidth
,
515 self
->size
.top
+ self
->client
->area
.height
+
518 ob_rr_theme
->grip_width
:
522 ob_rr_theme
->grip_width
:
525 XMoveResizeWindow(ob_display
, self
->lgripbottom
,
527 self
->size
.top
+ self
->client
->area
.height
+
528 self
->size
.bottom
- self
->bwidth
,
529 ob_rr_theme
->grip_width
+ self
->bwidth
,
531 XMoveResizeWindow(ob_display
, self
->rgripbottom
,
532 self
->size
.left
+ self
->client
->area
.width
+
533 self
->size
.right
- self
->bwidth
* 2 -
534 ob_rr_theme
->grip_width
,
535 self
->size
.top
+ self
->client
->area
.height
+
536 self
->size
.bottom
- self
->bwidth
,
537 ob_rr_theme
->grip_width
+ self
->bwidth
,
540 XMapWindow(ob_display
, self
->handlebottom
);
541 XMapWindow(ob_display
, self
->lgripleft
);
542 XMapWindow(ob_display
, self
->rgripright
);
543 XMapWindow(ob_display
, self
->lgripbottom
);
544 XMapWindow(ob_display
, self
->rgripbottom
);
546 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
547 ob_rr_theme
->handle_height
> 0)
549 XMoveResizeWindow(ob_display
, self
->handletop
,
550 ob_rr_theme
->grip_width
+
552 FRAME_HANDLE_Y(self
),
553 self
->width
- (ob_rr_theme
->grip_width
+
556 XMapWindow(ob_display
, self
->handletop
);
558 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
559 XMoveResizeWindow(ob_display
, self
->handleleft
,
560 ob_rr_theme
->grip_width
,
563 ob_rr_theme
->handle_height
);
564 XMoveResizeWindow(ob_display
, self
->handleright
,
566 ob_rr_theme
->grip_width
-
570 ob_rr_theme
->handle_height
);
572 XMoveResizeWindow(ob_display
, self
->lgriptop
,
574 FRAME_HANDLE_Y(self
),
575 ob_rr_theme
->grip_width
+
578 XMoveResizeWindow(ob_display
, self
->rgriptop
,
580 self
->client
->area
.width
+
581 self
->size
.right
- self
->bwidth
* 2 -
582 ob_rr_theme
->grip_width
,
583 FRAME_HANDLE_Y(self
),
584 ob_rr_theme
->grip_width
+
588 XMapWindow(ob_display
, self
->handleleft
);
589 XMapWindow(ob_display
, self
->handleright
);
590 XMapWindow(ob_display
, self
->lgriptop
);
591 XMapWindow(ob_display
, self
->rgriptop
);
593 XUnmapWindow(ob_display
, self
->handleleft
);
594 XUnmapWindow(ob_display
, self
->handleright
);
595 XUnmapWindow(ob_display
, self
->lgriptop
);
596 XUnmapWindow(ob_display
, self
->rgriptop
);
599 XUnmapWindow(ob_display
, self
->handleleft
);
600 XUnmapWindow(ob_display
, self
->handleright
);
601 XUnmapWindow(ob_display
, self
->lgriptop
);
602 XUnmapWindow(ob_display
, self
->rgriptop
);
604 XUnmapWindow(ob_display
, self
->handletop
);
607 XUnmapWindow(ob_display
, self
->handleleft
);
608 XUnmapWindow(ob_display
, self
->handleright
);
609 XUnmapWindow(ob_display
, self
->lgriptop
);
610 XUnmapWindow(ob_display
, self
->rgriptop
);
612 XUnmapWindow(ob_display
, self
->handletop
);
614 XUnmapWindow(ob_display
, self
->handlebottom
);
615 XUnmapWindow(ob_display
, self
->lgripleft
);
616 XUnmapWindow(ob_display
, self
->rgripright
);
617 XUnmapWindow(ob_display
, self
->lgripbottom
);
618 XUnmapWindow(ob_display
, self
->rgripbottom
);
621 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
622 ob_rr_theme
->handle_height
> 0)
624 XMoveResizeWindow(ob_display
, self
->handle
,
626 FRAME_HANDLE_Y(self
) + self
->bwidth
,
627 self
->width
, ob_rr_theme
->handle_height
);
628 XMapWindow(ob_display
, self
->handle
);
630 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
631 XMoveResizeWindow(ob_display
, self
->lgrip
,
633 ob_rr_theme
->grip_width
,
634 ob_rr_theme
->handle_height
);
635 XMoveResizeWindow(ob_display
, self
->rgrip
,
636 self
->width
- ob_rr_theme
->grip_width
,
638 ob_rr_theme
->grip_width
,
639 ob_rr_theme
->handle_height
);
641 XMapWindow(ob_display
, self
->lgrip
);
642 XMapWindow(ob_display
, self
->rgrip
);
644 XUnmapWindow(ob_display
, self
->lgrip
);
645 XUnmapWindow(ob_display
, self
->rgrip
);
648 XUnmapWindow(ob_display
, self
->lgrip
);
649 XUnmapWindow(ob_display
, self
->rgrip
);
651 XUnmapWindow(ob_display
, self
->handle
);
654 if (self
->bwidth
&& !self
->max_horz
) {
655 XMoveResizeWindow(ob_display
, self
->left
,
657 self
->bwidth
+ ob_rr_theme
->grip_width
,
659 self
->client
->area
.height
+
660 self
->size
.top
+ self
->size
.bottom
-
661 ob_rr_theme
->grip_width
* 2);
663 XMapWindow(ob_display
, self
->left
);
665 XUnmapWindow(ob_display
, self
->left
);
667 if (self
->bwidth
&& !self
->max_horz
) {
668 XMoveResizeWindow(ob_display
, self
->right
,
669 self
->client
->area
.width
+
670 self
->cbwidth_x
* 2 + self
->bwidth
,
671 self
->bwidth
+ ob_rr_theme
->grip_width
,
673 self
->client
->area
.height
+
674 self
->size
.top
+ self
->size
.bottom
-
675 ob_rr_theme
->grip_width
* 2);
677 XMapWindow(ob_display
, self
->right
);
679 XUnmapWindow(ob_display
, self
->right
);
681 /* move and resize the inner border window which contains the plate
683 XMoveResizeWindow(ob_display
, self
->inner
,
685 self
->size
.top
- self
->cbwidth_y
,
686 self
->client
->area
.width
+
687 self
->cbwidth_x
* 2 +
688 (!self
->max_horz
? self
->bwidth
* 2 : 0),
689 self
->client
->area
.height
+
690 self
->cbwidth_y
* 2);
693 XMoveWindow(ob_display
, self
->plate
,
694 (!self
->max_horz
? self
->bwidth
: 0) + self
->cbwidth_x
,
697 /* when the client has StaticGravity, it likes to move around. */
698 XMoveWindow(ob_display
, self
->client
->window
, 0, 0);
702 /* shading can change without being moved or resized */
703 RECT_SET_SIZE(self
->area
,
704 self
->client
->area
.width
+
705 self
->size
.left
+ self
->size
.right
,
706 (self
->client
->shaded
?
707 ob_rr_theme
->title_height
+ self
->bwidth
* 2:
708 self
->client
->area
.height
+
709 self
->size
.top
+ self
->size
.bottom
));
711 if ((moved
|| resized
) && !fake
) {
712 /* find the new coordinates, done after setting the frame.size, for
713 frame_client_gravity. */
714 self
->area
.x
= self
->client
->area
.x
;
715 self
->area
.y
= self
->client
->area
.y
;
716 frame_client_gravity(self
, &self
->area
.x
, &self
->area
.y
,
717 self
->client
->area
.width
,
718 self
->client
->area
.height
);
722 if (!frame_iconify_animating(self
))
723 /* move and resize the top level frame.
724 shading can change without being moved or resized.
726 but don't do this during an iconify animation. it will be
727 reflected afterwards.
729 XMoveResizeWindow(ob_display
, self
->window
,
736 framerender_frame(self
);
737 frame_adjust_shape(self
);
740 if (!STRUT_EQUAL(self
->size
, oldsize
)) {
742 vals
[0] = self
->size
.left
;
743 vals
[1] = self
->size
.right
;
744 vals
[2] = self
->size
.top
;
745 vals
[3] = self
->size
.bottom
;
746 PROP_SETA32(self
->client
->window
, net_frame_extents
,
748 PROP_SETA32(self
->client
->window
, kde_net_wm_frame_strut
,
752 /* if this occurs while we are focus cycling, the indicator needs to
754 if (focus_cycle_target
== self
->client
)
755 focus_cycle_draw_indicator(self
->client
);
757 if (resized
&& (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
758 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
759 ob_rr_theme
->label_height
);
763 static void frame_adjust_cursors(ObFrame
*self
)
765 if ((self
->functions
& OB_CLIENT_FUNC_RESIZE
) !=
766 (self
->client
->functions
& OB_CLIENT_FUNC_RESIZE
) ||
767 self
->max_horz
!= self
->client
->max_horz
||
768 self
->max_vert
!= self
->client
->max_vert
)
770 gboolean r
= (self
->client
->functions
& OB_CLIENT_FUNC_RESIZE
) &&
771 !(self
->client
->max_horz
&& self
->client
->max_vert
);
772 gboolean topbot
= !self
->client
->max_vert
;
773 XSetWindowAttributes a
;
775 /* these ones turn off when max vert */
776 a
.cursor
= ob_cursor(r
&& topbot
? OB_CURSOR_NORTH
: OB_CURSOR_NONE
);
777 XChangeWindowAttributes(ob_display
, self
->topresize
, CWCursor
, &a
);
778 XChangeWindowAttributes(ob_display
, self
->titletop
, CWCursor
, &a
);
779 a
.cursor
= ob_cursor(r
&& topbot
? OB_CURSOR_SOUTH
: OB_CURSOR_NONE
);
780 XChangeWindowAttributes(ob_display
, self
->handle
, CWCursor
, &a
);
781 XChangeWindowAttributes(ob_display
, self
->handletop
, CWCursor
, &a
);
782 XChangeWindowAttributes(ob_display
, self
->handlebottom
, CWCursor
, &a
);
784 /* these ones don't */
785 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTHWEST
: OB_CURSOR_NONE
);
786 XChangeWindowAttributes(ob_display
, self
->tltresize
, CWCursor
, &a
);
787 XChangeWindowAttributes(ob_display
, self
->tllresize
, CWCursor
, &a
);
788 XChangeWindowAttributes(ob_display
, self
->titletopleft
, CWCursor
, &a
);
789 XChangeWindowAttributes(ob_display
, self
->titleleft
, CWCursor
, &a
);
790 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTHEAST
: OB_CURSOR_NONE
);
791 XChangeWindowAttributes(ob_display
, self
->trtresize
, CWCursor
, &a
);
792 XChangeWindowAttributes(ob_display
, self
->trrresize
, CWCursor
, &a
);
793 XChangeWindowAttributes(ob_display
, self
->titletopright
, CWCursor
, &a
);
794 XChangeWindowAttributes(ob_display
, self
->titleright
, CWCursor
, &a
);
795 a
.cursor
= ob_cursor(r
? OB_CURSOR_WEST
: OB_CURSOR_NONE
);
796 XChangeWindowAttributes(ob_display
, self
->left
, CWCursor
, &a
);
797 a
.cursor
= ob_cursor(r
? OB_CURSOR_EAST
: OB_CURSOR_NONE
);
798 XChangeWindowAttributes(ob_display
, self
->right
, CWCursor
, &a
);
799 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTHWEST
: OB_CURSOR_NONE
);
800 XChangeWindowAttributes(ob_display
, self
->lgrip
, CWCursor
, &a
);
801 XChangeWindowAttributes(ob_display
, self
->handleleft
, CWCursor
, &a
);
802 XChangeWindowAttributes(ob_display
, self
->lgripleft
, CWCursor
, &a
);
803 XChangeWindowAttributes(ob_display
, self
->lgriptop
, CWCursor
, &a
);
804 XChangeWindowAttributes(ob_display
, self
->lgripbottom
, CWCursor
, &a
);
805 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTHEAST
: OB_CURSOR_NONE
);
806 XChangeWindowAttributes(ob_display
, self
->rgrip
, CWCursor
, &a
);
807 XChangeWindowAttributes(ob_display
, self
->handleright
, CWCursor
, &a
);
808 XChangeWindowAttributes(ob_display
, self
->rgripright
, CWCursor
, &a
);
809 XChangeWindowAttributes(ob_display
, self
->rgriptop
, CWCursor
, &a
);
810 XChangeWindowAttributes(ob_display
, self
->rgripbottom
, CWCursor
, &a
);
814 void frame_adjust_client_area(ObFrame
*self
)
816 /* resize the plate */
817 XResizeWindow(ob_display
, self
->plate
,
818 self
->client
->area
.width
, self
->client
->area
.height
);
821 void frame_adjust_state(ObFrame
*self
)
823 framerender_frame(self
);
826 void frame_adjust_focus(ObFrame
*self
, gboolean hilite
)
828 self
->focused
= hilite
;
829 framerender_frame(self
);
833 void frame_adjust_title(ObFrame
*self
)
835 framerender_frame(self
);
838 void frame_adjust_icon(ObFrame
*self
)
840 framerender_frame(self
);
843 void frame_grab_client(ObFrame
*self
)
845 /* reparent the client to the frame */
846 XReparentWindow(ob_display
, self
->client
->window
, self
->plate
, 0, 0);
849 When reparenting the client window, it is usually not mapped yet, since
850 this occurs from a MapRequest. However, in the case where Openbox is
851 starting up, the window is already mapped, so we'll see unmap events for
852 it. There are 2 unmap events generated that we see, one with the 'event'
853 member set the root window, and one set to the client, but both get
854 handled and need to be ignored.
856 if (ob_state() == OB_STATE_STARTING
)
857 self
->client
->ignore_unmaps
+= 2;
859 /* select the event mask on the client's parent (to receive config/map
860 req's) the ButtonPress is to catch clicks on the client border */
861 XSelectInput(ob_display
, self
->plate
, PLATE_EVENTMASK
);
863 /* set all the windows for the frame in the window_map */
864 g_hash_table_insert(window_map
, &self
->window
, self
->client
);
865 g_hash_table_insert(window_map
, &self
->plate
, self
->client
);
866 g_hash_table_insert(window_map
, &self
->inner
, self
->client
);
867 g_hash_table_insert(window_map
, &self
->title
, self
->client
);
868 g_hash_table_insert(window_map
, &self
->label
, self
->client
);
869 g_hash_table_insert(window_map
, &self
->max
, self
->client
);
870 g_hash_table_insert(window_map
, &self
->close
, self
->client
);
871 g_hash_table_insert(window_map
, &self
->desk
, self
->client
);
872 g_hash_table_insert(window_map
, &self
->shade
, self
->client
);
873 g_hash_table_insert(window_map
, &self
->icon
, self
->client
);
874 g_hash_table_insert(window_map
, &self
->iconify
, self
->client
);
875 g_hash_table_insert(window_map
, &self
->handle
, self
->client
);
876 g_hash_table_insert(window_map
, &self
->lgrip
, self
->client
);
877 g_hash_table_insert(window_map
, &self
->rgrip
, self
->client
);
878 g_hash_table_insert(window_map
, &self
->topresize
, self
->client
);
879 g_hash_table_insert(window_map
, &self
->tltresize
, self
->client
);
880 g_hash_table_insert(window_map
, &self
->tllresize
, self
->client
);
881 g_hash_table_insert(window_map
, &self
->trtresize
, self
->client
);
882 g_hash_table_insert(window_map
, &self
->trrresize
, self
->client
);
883 g_hash_table_insert(window_map
, &self
->left
, self
->client
);
884 g_hash_table_insert(window_map
, &self
->right
, self
->client
);
885 g_hash_table_insert(window_map
, &self
->titleleft
, self
->client
);
886 g_hash_table_insert(window_map
, &self
->titletop
, self
->client
);
887 g_hash_table_insert(window_map
, &self
->titletopleft
, self
->client
);
888 g_hash_table_insert(window_map
, &self
->titletopright
, self
->client
);
889 g_hash_table_insert(window_map
, &self
->titleright
, self
->client
);
890 g_hash_table_insert(window_map
, &self
->titlebottom
, self
->client
);
891 g_hash_table_insert(window_map
, &self
->handleleft
, self
->client
);
892 g_hash_table_insert(window_map
, &self
->handletop
, self
->client
);
893 g_hash_table_insert(window_map
, &self
->handleright
, self
->client
);
894 g_hash_table_insert(window_map
, &self
->handlebottom
, self
->client
);
895 g_hash_table_insert(window_map
, &self
->lgripleft
, self
->client
);
896 g_hash_table_insert(window_map
, &self
->lgriptop
, self
->client
);
897 g_hash_table_insert(window_map
, &self
->lgripbottom
, self
->client
);
898 g_hash_table_insert(window_map
, &self
->rgripright
, self
->client
);
899 g_hash_table_insert(window_map
, &self
->rgriptop
, self
->client
);
900 g_hash_table_insert(window_map
, &self
->rgripbottom
, self
->client
);
903 void frame_release_client(ObFrame
*self
)
906 gboolean reparent
= TRUE
;
908 /* if there was any animation going on, kill it */
909 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
912 /* check if the app has already reparented its window away */
913 while (XCheckTypedWindowEvent(ob_display
, self
->client
->window
,
914 ReparentNotify
, &ev
))
916 /* This check makes sure we don't catch our own reparent action to
917 our frame window. This doesn't count as the app reparenting itself
920 Reparent events that are generated by us are just discarded here.
921 They are of no consequence to us anyhow.
923 if (ev
.xreparent
.parent
!= self
->plate
) {
925 XPutBackEvent(ob_display
, &ev
);
931 /* according to the ICCCM - if the client doesn't reparent itself,
932 then we will reparent the window to root for them */
933 XReparentWindow(ob_display
, self
->client
->window
,
934 RootWindow(ob_display
, ob_screen
),
935 self
->client
->area
.x
,
936 self
->client
->area
.y
);
939 /* remove all the windows for the frame from the window_map */
940 g_hash_table_remove(window_map
, &self
->window
);
941 g_hash_table_remove(window_map
, &self
->plate
);
942 g_hash_table_remove(window_map
, &self
->inner
);
943 g_hash_table_remove(window_map
, &self
->title
);
944 g_hash_table_remove(window_map
, &self
->label
);
945 g_hash_table_remove(window_map
, &self
->max
);
946 g_hash_table_remove(window_map
, &self
->close
);
947 g_hash_table_remove(window_map
, &self
->desk
);
948 g_hash_table_remove(window_map
, &self
->shade
);
949 g_hash_table_remove(window_map
, &self
->icon
);
950 g_hash_table_remove(window_map
, &self
->iconify
);
951 g_hash_table_remove(window_map
, &self
->handle
);
952 g_hash_table_remove(window_map
, &self
->lgrip
);
953 g_hash_table_remove(window_map
, &self
->rgrip
);
954 g_hash_table_remove(window_map
, &self
->topresize
);
955 g_hash_table_remove(window_map
, &self
->tltresize
);
956 g_hash_table_remove(window_map
, &self
->tllresize
);
957 g_hash_table_remove(window_map
, &self
->trtresize
);
958 g_hash_table_remove(window_map
, &self
->trrresize
);
959 g_hash_table_remove(window_map
, &self
->left
);
960 g_hash_table_remove(window_map
, &self
->right
);
961 g_hash_table_remove(window_map
, &self
->titleleft
);
962 g_hash_table_remove(window_map
, &self
->titletop
);
963 g_hash_table_remove(window_map
, &self
->titletopleft
);
964 g_hash_table_remove(window_map
, &self
->titletopright
);
965 g_hash_table_remove(window_map
, &self
->titleright
);
966 g_hash_table_remove(window_map
, &self
->titlebottom
);
967 g_hash_table_remove(window_map
, &self
->handleleft
);
968 g_hash_table_remove(window_map
, &self
->handletop
);
969 g_hash_table_remove(window_map
, &self
->handleright
);
970 g_hash_table_remove(window_map
, &self
->handlebottom
);
971 g_hash_table_remove(window_map
, &self
->lgripleft
);
972 g_hash_table_remove(window_map
, &self
->lgriptop
);
973 g_hash_table_remove(window_map
, &self
->lgripbottom
);
974 g_hash_table_remove(window_map
, &self
->rgripright
);
975 g_hash_table_remove(window_map
, &self
->rgriptop
);
976 g_hash_table_remove(window_map
, &self
->rgripbottom
);
978 ob_main_loop_timeout_remove_data(ob_main_loop
, flash_timeout
, self
, TRUE
);
981 /* is there anything present between us and the label? */
982 static gboolean
is_button_present(ObFrame
*self
, const gchar
*lc
, gint dir
) {
983 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+= dir
) {
984 if (*lc
== ' ') continue; /* it was invalid */
985 if (*lc
== 'N' && self
->decorations
& OB_FRAME_DECOR_ICON
)
987 if (*lc
== 'D' && self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
)
989 if (*lc
== 'S' && self
->decorations
& OB_FRAME_DECOR_SHADE
)
991 if (*lc
== 'I' && self
->decorations
& OB_FRAME_DECOR_ICONIFY
)
993 if (*lc
== 'M' && self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
)
995 if (*lc
== 'C' && self
->decorations
& OB_FRAME_DECOR_CLOSE
)
997 if (*lc
== 'L') return FALSE
;
1002 static void layout_title(ObFrame
*self
)
1007 const gint bwidth
= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
1008 /* position of the left most button */
1009 const gint left
= ob_rr_theme
->paddingx
+ 1;
1010 /* position of the right most button */
1011 const gint right
= self
->width
- bwidth
;
1013 /* turn them all off */
1014 self
->icon_on
= self
->desk_on
= self
->shade_on
= self
->iconify_on
=
1015 self
->max_on
= self
->close_on
= self
->label_on
= FALSE
;
1016 self
->label_width
= self
->width
- (ob_rr_theme
->paddingx
+ 1) * 2;
1017 self
->leftmost
= self
->rightmost
= OB_FRAME_CONTEXT_NONE
;
1019 /* figure out what's being show, find each element's position, and the
1022 do the ones before the label, then after the label,
1023 i will be +1 the first time through when working to the left,
1024 and -1 the second time through when working to the right */
1025 for (i
= 1; i
>= -1; i
-=2) {
1027 ObFrameContext
*firstcon
;
1031 lc
= config_title_layout
;
1032 firstcon
= &self
->leftmost
;
1035 lc
= config_title_layout
+ strlen(config_title_layout
)-1;
1036 firstcon
= &self
->rightmost
;
1039 /* stop at the end of the string (or the label, which calls break) */
1040 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+=i
) {
1043 self
->label_on
= TRUE
;
1046 break; /* break the for loop, do other side of label */
1047 } else if (*lc
== 'N') {
1048 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICON
;
1049 if ((self
->icon_on
= is_button_present(self
, lc
, i
))) {
1050 /* icon is bigger than buttons */
1051 self
->label_width
-= bwidth
+ 2;
1053 x
+= i
* (bwidth
+ 2);
1055 } else if (*lc
== 'D') {
1056 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ALLDESKTOPS
;
1057 if ((self
->desk_on
= is_button_present(self
, lc
, i
))) {
1058 self
->label_width
-= bwidth
;
1062 } else if (*lc
== 'S') {
1063 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_SHADE
;
1064 if ((self
->shade_on
= is_button_present(self
, lc
, i
))) {
1065 self
->label_width
-= bwidth
;
1069 } else if (*lc
== 'I') {
1070 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICONIFY
;
1071 if ((self
->iconify_on
= is_button_present(self
, lc
, i
))) {
1072 self
->label_width
-= bwidth
;
1073 self
->iconify_x
= x
;
1076 } else if (*lc
== 'M') {
1077 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_MAXIMIZE
;
1078 if ((self
->max_on
= is_button_present(self
, lc
, i
))) {
1079 self
->label_width
-= bwidth
;
1083 } else if (*lc
== 'C') {
1084 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_CLOSE
;
1085 if ((self
->close_on
= is_button_present(self
, lc
, i
))) {
1086 self
->label_width
-= bwidth
;
1091 continue; /* don't set firstcon */
1096 /* position and map the elements */
1097 if (self
->icon_on
) {
1098 XMapWindow(ob_display
, self
->icon
);
1099 XMoveWindow(ob_display
, self
->icon
, self
->icon_x
,
1100 ob_rr_theme
->paddingy
);
1102 XUnmapWindow(ob_display
, self
->icon
);
1104 if (self
->desk_on
) {
1105 XMapWindow(ob_display
, self
->desk
);
1106 XMoveWindow(ob_display
, self
->desk
, self
->desk_x
,
1107 ob_rr_theme
->paddingy
+ 1);
1109 XUnmapWindow(ob_display
, self
->desk
);
1111 if (self
->shade_on
) {
1112 XMapWindow(ob_display
, self
->shade
);
1113 XMoveWindow(ob_display
, self
->shade
, self
->shade_x
,
1114 ob_rr_theme
->paddingy
+ 1);
1116 XUnmapWindow(ob_display
, self
->shade
);
1118 if (self
->iconify_on
) {
1119 XMapWindow(ob_display
, self
->iconify
);
1120 XMoveWindow(ob_display
, self
->iconify
, self
->iconify_x
,
1121 ob_rr_theme
->paddingy
+ 1);
1123 XUnmapWindow(ob_display
, self
->iconify
);
1126 XMapWindow(ob_display
, self
->max
);
1127 XMoveWindow(ob_display
, self
->max
, self
->max_x
,
1128 ob_rr_theme
->paddingy
+ 1);
1130 XUnmapWindow(ob_display
, self
->max
);
1132 if (self
->close_on
) {
1133 XMapWindow(ob_display
, self
->close
);
1134 XMoveWindow(ob_display
, self
->close
, self
->close_x
,
1135 ob_rr_theme
->paddingy
+ 1);
1137 XUnmapWindow(ob_display
, self
->close
);
1139 if (self
->label_on
) {
1140 self
->label_width
= MAX(1, self
->label_width
); /* no lower than 1 */
1141 XMapWindow(ob_display
, self
->label
);
1142 XMoveWindow(ob_display
, self
->label
, self
->label_x
,
1143 ob_rr_theme
->paddingy
);
1145 XUnmapWindow(ob_display
, self
->label
);
1148 ObFrameContext
frame_context_from_string(const gchar
*name
)
1150 if (!g_ascii_strcasecmp("Desktop", name
))
1151 return OB_FRAME_CONTEXT_DESKTOP
;
1152 else if (!g_ascii_strcasecmp("Root", name
))
1153 return OB_FRAME_CONTEXT_ROOT
;
1154 else if (!g_ascii_strcasecmp("Client", name
))
1155 return OB_FRAME_CONTEXT_CLIENT
;
1156 else if (!g_ascii_strcasecmp("Titlebar", name
))
1157 return OB_FRAME_CONTEXT_TITLEBAR
;
1158 else if (!g_ascii_strcasecmp("Frame", name
))
1159 return OB_FRAME_CONTEXT_FRAME
;
1160 else if (!g_ascii_strcasecmp("TLCorner", name
))
1161 return OB_FRAME_CONTEXT_TLCORNER
;
1162 else if (!g_ascii_strcasecmp("TRCorner", name
))
1163 return OB_FRAME_CONTEXT_TRCORNER
;
1164 else if (!g_ascii_strcasecmp("BLCorner", name
))
1165 return OB_FRAME_CONTEXT_BLCORNER
;
1166 else if (!g_ascii_strcasecmp("BRCorner", name
))
1167 return OB_FRAME_CONTEXT_BRCORNER
;
1168 else if (!g_ascii_strcasecmp("Top", name
))
1169 return OB_FRAME_CONTEXT_TOP
;
1170 else if (!g_ascii_strcasecmp("Bottom", name
))
1171 return OB_FRAME_CONTEXT_BOTTOM
;
1172 else if (!g_ascii_strcasecmp("Left", name
))
1173 return OB_FRAME_CONTEXT_LEFT
;
1174 else if (!g_ascii_strcasecmp("Right", name
))
1175 return OB_FRAME_CONTEXT_RIGHT
;
1176 else if (!g_ascii_strcasecmp("Maximize", name
))
1177 return OB_FRAME_CONTEXT_MAXIMIZE
;
1178 else if (!g_ascii_strcasecmp("AllDesktops", name
))
1179 return OB_FRAME_CONTEXT_ALLDESKTOPS
;
1180 else if (!g_ascii_strcasecmp("Shade", name
))
1181 return OB_FRAME_CONTEXT_SHADE
;
1182 else if (!g_ascii_strcasecmp("Iconify", name
))
1183 return OB_FRAME_CONTEXT_ICONIFY
;
1184 else if (!g_ascii_strcasecmp("Icon", name
))
1185 return OB_FRAME_CONTEXT_ICON
;
1186 else if (!g_ascii_strcasecmp("Close", name
))
1187 return OB_FRAME_CONTEXT_CLOSE
;
1188 else if (!g_ascii_strcasecmp("MoveResize", name
))
1189 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
1190 return OB_FRAME_CONTEXT_NONE
;
1193 ObFrameContext
frame_context(ObClient
*client
, Window win
, gint x
, gint y
)
1197 if (moveresize_in_progress
)
1198 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
1200 if (win
== RootWindow(ob_display
, ob_screen
))
1201 return OB_FRAME_CONTEXT_ROOT
;
1202 if (client
== NULL
) return OB_FRAME_CONTEXT_NONE
;
1203 if (win
== client
->window
) {
1204 /* conceptually, this is the desktop, as far as users are
1206 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
1207 return OB_FRAME_CONTEXT_DESKTOP
;
1208 return OB_FRAME_CONTEXT_CLIENT
;
1211 self
= client
->frame
;
1212 if (win
== self
->inner
|| win
== self
->plate
) {
1213 /* conceptually, this is the desktop, as far as users are
1215 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
1216 return OB_FRAME_CONTEXT_DESKTOP
;
1217 return OB_FRAME_CONTEXT_CLIENT
;
1220 /* when the user clicks in the corners of the titlebar and the client
1221 is fully maximized, then treat it like they clicked in the
1222 button that is there */
1223 if (self
->max_horz
&& self
->max_vert
&&
1224 (win
== self
->title
|| win
== self
->titletop
||
1225 win
== self
->titleleft
|| win
== self
->titletopleft
||
1226 win
== self
->titleright
|| win
== self
->titletopright
))
1228 /* get the mouse coords in reference to the whole frame */
1232 /* these windows are down a border width from the top of the frame */
1233 if (win
== self
->title
||
1234 win
== self
->titleleft
|| win
== self
->titleright
)
1237 /* title is a border width in from the edge */
1238 if (win
== self
->title
)
1240 /* titletop is a bit to the right */
1241 else if (win
== self
->titletop
)
1242 fx
+= ob_rr_theme
->grip_width
+ self
->bwidth
;
1243 /* titletopright is way to the right edge */
1244 else if (win
== self
->titletopright
)
1245 fx
+= self
->area
.width
- (ob_rr_theme
->grip_width
+ self
->bwidth
);
1246 /* titleright is even more way to the right edge */
1247 else if (win
== self
->titleright
)
1248 fx
+= self
->area
.width
- self
->bwidth
;
1250 /* figure out if we're over the area that should be considered a
1252 if (fy
< self
->bwidth
+ ob_rr_theme
->paddingy
+ 1 +
1253 ob_rr_theme
->button_size
)
1255 if (fx
< (self
->bwidth
+ ob_rr_theme
->paddingx
+ 1 +
1256 ob_rr_theme
->button_size
))
1258 if (self
->leftmost
!= OB_FRAME_CONTEXT_NONE
)
1259 return self
->leftmost
;
1261 else if (fx
>= (self
->area
.width
-
1262 (self
->bwidth
+ ob_rr_theme
->paddingx
+ 1 +
1263 ob_rr_theme
->button_size
)))
1265 if (self
->rightmost
!= OB_FRAME_CONTEXT_NONE
)
1266 return self
->rightmost
;
1270 /* there is no resizing maximized windows so make them the titlebar
1272 return OB_FRAME_CONTEXT_TITLEBAR
;
1274 else if (self
->max_vert
&&
1275 (win
== self
->titletop
|| win
== self
->topresize
))
1276 /* can't resize vertically when max vert */
1277 return OB_FRAME_CONTEXT_TITLEBAR
;
1279 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
1280 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
1281 if (win
== self
->handle
) return OB_FRAME_CONTEXT_BOTTOM
;
1282 if (win
== self
->handletop
) return OB_FRAME_CONTEXT_BOTTOM
;
1283 if (win
== self
->handlebottom
) return OB_FRAME_CONTEXT_BOTTOM
;
1284 if (win
== self
->handleleft
) return OB_FRAME_CONTEXT_BLCORNER
;
1285 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
1286 if (win
== self
->lgripleft
) return OB_FRAME_CONTEXT_BLCORNER
;
1287 if (win
== self
->lgriptop
) return OB_FRAME_CONTEXT_BLCORNER
;
1288 if (win
== self
->lgripbottom
) return OB_FRAME_CONTEXT_BLCORNER
;
1289 if (win
== self
->handleright
) return OB_FRAME_CONTEXT_BRCORNER
;
1290 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
1291 if (win
== self
->rgripright
) return OB_FRAME_CONTEXT_BLCORNER
;
1292 if (win
== self
->rgriptop
) return OB_FRAME_CONTEXT_BLCORNER
;
1293 if (win
== self
->rgripbottom
) return OB_FRAME_CONTEXT_BLCORNER
;
1294 if (win
== self
->title
) return OB_FRAME_CONTEXT_TITLEBAR
;
1295 if (win
== self
->titleleft
) return OB_FRAME_CONTEXT_TLCORNER
;
1296 if (win
== self
->titletopleft
) return OB_FRAME_CONTEXT_TLCORNER
;
1297 if (win
== self
->titleright
) return OB_FRAME_CONTEXT_TRCORNER
;
1298 if (win
== self
->titletopright
) return OB_FRAME_CONTEXT_TRCORNER
;
1299 if (win
== self
->titletop
) return OB_FRAME_CONTEXT_TOP
;
1300 if (win
== self
->topresize
) return OB_FRAME_CONTEXT_TOP
;
1301 if (win
== self
->tltresize
) return OB_FRAME_CONTEXT_TLCORNER
;
1302 if (win
== self
->tllresize
) return OB_FRAME_CONTEXT_TLCORNER
;
1303 if (win
== self
->trtresize
) return OB_FRAME_CONTEXT_TRCORNER
;
1304 if (win
== self
->trrresize
) return OB_FRAME_CONTEXT_TRCORNER
;
1305 if (win
== self
->left
) return OB_FRAME_CONTEXT_LEFT
;
1306 if (win
== self
->right
) return OB_FRAME_CONTEXT_RIGHT
;
1307 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
1308 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
1309 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
1310 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
1311 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
1312 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
1314 return OB_FRAME_CONTEXT_NONE
;
1317 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
1320 switch (self
->client
->gravity
) {
1322 case NorthWestGravity
:
1323 case SouthWestGravity
:
1330 /* the middle of the client will be the middle of the frame */
1331 *x
-= (self
->size
.right
- self
->size
.left
) / 2;
1334 case NorthEastGravity
:
1335 case SouthEastGravity
:
1337 /* the right side of the client will be the right side of the frame */
1338 *x
-= self
->size
.right
+ self
->size
.left
;
1343 /* the client's position won't move */
1344 *x
-= self
->size
.left
;
1349 switch (self
->client
->gravity
) {
1351 case NorthWestGravity
:
1352 case NorthEastGravity
:
1359 /* the middle of the client will be the middle of the frame */
1360 *y
-= (self
->size
.bottom
- self
->size
.top
) / 2;
1363 case SouthWestGravity
:
1364 case SouthEastGravity
:
1366 /* the bottom of the client will be the bottom of the frame */
1367 *y
-= self
->size
.bottom
+ self
->size
.top
;
1372 /* the client's position won't move */
1373 *y
-= self
->size
.top
;
1378 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
1381 switch (self
->client
->gravity
) {
1383 case NorthWestGravity
:
1385 case SouthWestGravity
:
1390 /* the middle of the client will be the middle of the frame */
1391 *x
+= (self
->size
.right
- self
->size
.left
) / 2;
1393 case NorthEastGravity
:
1395 case SouthEastGravity
:
1396 /* the right side of the client will be the right side of the frame */
1397 *x
+= self
->size
.right
+ self
->size
.left
;
1401 /* the client's position won't move */
1402 *x
+= self
->size
.left
;
1407 switch (self
->client
->gravity
) {
1409 case NorthWestGravity
:
1411 case NorthEastGravity
:
1416 /* the middle of the client will be the middle of the frame */
1417 *y
+= (self
->size
.bottom
- self
->size
.top
) / 2;
1419 case SouthWestGravity
:
1421 case SouthEastGravity
:
1422 /* the bottom of the client will be the bottom of the frame */
1423 *y
+= self
->size
.bottom
+ self
->size
.top
;
1427 /* the client's position won't move */
1428 *y
+= self
->size
.top
;
1433 static void flash_done(gpointer data
)
1435 ObFrame
*self
= data
;
1437 if (self
->focused
!= self
->flash_on
)
1438 frame_adjust_focus(self
, self
->focused
);
1441 static gboolean
flash_timeout(gpointer data
)
1443 ObFrame
*self
= data
;
1446 g_get_current_time(&now
);
1447 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
1448 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
1449 now
.tv_usec
>= self
->flash_end
.tv_usec
))
1450 self
->flashing
= FALSE
;
1452 if (!self
->flashing
)
1453 return FALSE
; /* we are done */
1455 self
->flash_on
= !self
->flash_on
;
1456 if (!self
->focused
) {
1457 frame_adjust_focus(self
, self
->flash_on
);
1458 self
->focused
= FALSE
;
1461 return TRUE
; /* go again */
1464 void frame_flash_start(ObFrame
*self
)
1466 self
->flash_on
= self
->focused
;
1468 if (!self
->flashing
)
1469 ob_main_loop_timeout_add(ob_main_loop
,
1470 G_USEC_PER_SEC
* 0.6,
1475 g_get_current_time(&self
->flash_end
);
1476 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
1478 self
->flashing
= TRUE
;
1481 void frame_flash_stop(ObFrame
*self
)
1483 self
->flashing
= FALSE
;
1486 static gulong
frame_animate_iconify_time_left(ObFrame
*self
,
1487 const GTimeVal
*now
)
1490 sec
= self
->iconify_animation_end
.tv_sec
- now
->tv_sec
;
1491 usec
= self
->iconify_animation_end
.tv_usec
- now
->tv_usec
;
1493 usec
+= G_USEC_PER_SEC
;
1496 /* no negative values */
1497 return MAX(sec
* G_USEC_PER_SEC
+ usec
, 0);
1500 static gboolean
frame_animate_iconify(gpointer p
)
1504 gint iconx
, icony
, iconw
;
1507 gboolean iconifying
;
1509 if (self
->client
->icon_geometry
.width
== 0) {
1510 /* there is no icon geometry set so just go straight down */
1511 Rect
*a
= screen_physical_area();
1512 iconx
= self
->area
.x
+ self
->area
.width
/ 2 + 32;
1513 icony
= a
->y
+ a
->width
;
1516 iconx
= self
->client
->icon_geometry
.x
;
1517 icony
= self
->client
->icon_geometry
.y
;
1518 iconw
= self
->client
->icon_geometry
.width
;
1521 iconifying
= self
->iconify_animation_going
> 0;
1523 /* how far do we have left to go ? */
1524 g_get_current_time(&now
);
1525 time
= frame_animate_iconify_time_left(self
, &now
);
1527 if (time
== 0 || iconifying
) {
1528 /* start where the frame is supposed to be */
1531 w
= self
->area
.width
;
1532 h
= self
->area
.height
;
1534 /* start at the icon */
1538 h
= self
->size
.top
; /* just the titlebar */
1545 dx
= self
->area
.x
- iconx
;
1546 dy
= self
->area
.y
- icony
;
1547 dw
= self
->area
.width
- self
->bwidth
* 2 - iconw
;
1548 /* if restoring, we move in the opposite direction */
1549 if (!iconifying
) { dx
= -dx
; dy
= -dy
; dw
= -dw
; }
1551 elapsed
= FRAME_ANIMATE_ICONIFY_TIME
- time
;
1552 x
= x
- (dx
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1553 y
= y
- (dy
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1554 w
= w
- (dw
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1555 h
= self
->size
.top
; /* just the titlebar */
1559 frame_end_iconify_animation(self
);
1561 XMoveResizeWindow(ob_display
, self
->window
, x
, y
, w
, h
);
1565 return time
> 0; /* repeat until we're out of time */
1568 void frame_end_iconify_animation(ObFrame
*self
)
1570 /* see if there is an animation going */
1571 if (self
->iconify_animation_going
== 0) return;
1574 XUnmapWindow(ob_display
, self
->window
);
1576 /* Send a ConfigureNotify when the animation is done, this fixes
1577 KDE's pager showing the window in the wrong place. */
1578 client_reconfigure(self
->client
);
1580 /* we're not animating any more ! */
1581 self
->iconify_animation_going
= 0;
1583 XMoveResizeWindow(ob_display
, self
->window
,
1584 self
->area
.x
, self
->area
.y
,
1585 self
->area
.width
, self
->area
.height
);
1589 void frame_begin_iconify_animation(ObFrame
*self
, gboolean iconifying
)
1592 gboolean new_anim
= FALSE
;
1593 gboolean set_end
= TRUE
;
1596 /* if there is no titlebar, just don't animate for now
1597 XXX it would be nice tho.. */
1598 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1601 /* get the current time */
1602 g_get_current_time(&now
);
1604 /* get how long until the end */
1605 time
= FRAME_ANIMATE_ICONIFY_TIME
;
1606 if (self
->iconify_animation_going
) {
1607 if (!!iconifying
!= (self
->iconify_animation_going
> 0)) {
1608 /* animation was already going on in the opposite direction */
1609 time
= time
- frame_animate_iconify_time_left(self
, &now
);
1611 /* animation was already going in the same direction */
1615 self
->iconify_animation_going
= iconifying
? 1 : -1;
1617 /* set the ending time */
1619 self
->iconify_animation_end
.tv_sec
= now
.tv_sec
;
1620 self
->iconify_animation_end
.tv_usec
= now
.tv_usec
;
1621 g_time_val_add(&self
->iconify_animation_end
, time
);
1625 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
1627 ob_main_loop_timeout_add(ob_main_loop
,
1628 FRAME_ANIMATE_ICONIFY_STEP_TIME
,
1629 frame_animate_iconify
, self
,
1630 g_direct_equal
, NULL
);
1632 /* do the first step */
1633 frame_animate_iconify(self
);
1635 /* show it during the animation even if it is not "visible" */
1637 XMapWindow(ob_display
, self
->window
);