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 */
379 XMoveResizeWindow(ob_display
, self
->titletop
,
380 ob_rr_theme
->grip_width
+ self
->bwidth
, 0,
381 /* width + bwidth*2 - bwidth*2 - grips*2 */
382 self
->width
- ob_rr_theme
->grip_width
* 2,
384 XMoveResizeWindow(ob_display
, self
->titletopleft
,
386 ob_rr_theme
->grip_width
+ self
->bwidth
,
388 XMoveResizeWindow(ob_display
, self
->titletopright
,
389 self
->client
->area
.width
+
390 self
->size
.left
+ self
->size
.right
-
391 ob_rr_theme
->grip_width
- self
->bwidth
,
393 ob_rr_theme
->grip_width
+ self
->bwidth
,
396 XMoveResizeWindow(ob_display
, self
->titleleft
,
400 ob_rr_theme
->grip_width
:
401 self
->size
.top
- self
->bwidth
));
402 XMoveResizeWindow(ob_display
, self
->titleright
,
403 self
->client
->area
.width
+
404 self
->size
.left
+ self
->size
.right
-
409 ob_rr_theme
->grip_width
:
410 self
->size
.top
- self
->bwidth
));
412 XMapWindow(ob_display
, self
->titletop
);
413 XMapWindow(ob_display
, self
->titletopleft
);
414 XMapWindow(ob_display
, self
->titletopright
);
415 XMapWindow(ob_display
, self
->titleleft
);
416 XMapWindow(ob_display
, self
->titleright
);
418 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
&&
421 XMoveResizeWindow(ob_display
, self
->titlebottom
,
423 ob_rr_theme
->title_height
+ self
->bwidth
,
427 XMapWindow(ob_display
, self
->titlebottom
);
429 XUnmapWindow(ob_display
, self
->titlebottom
);
431 XUnmapWindow(ob_display
, self
->titlebottom
);
433 XUnmapWindow(ob_display
, self
->titletop
);
434 XUnmapWindow(ob_display
, self
->titletopleft
);
435 XUnmapWindow(ob_display
, self
->titletopright
);
436 XUnmapWindow(ob_display
, self
->titleleft
);
437 XUnmapWindow(ob_display
, self
->titleright
);
440 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
441 XMoveResizeWindow(ob_display
, self
->title
,
442 self
->bwidth
, self
->bwidth
,
443 self
->width
, ob_rr_theme
->title_height
);
445 XMapWindow(ob_display
, self
->title
);
447 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
448 XMoveResizeWindow(ob_display
, self
->topresize
,
449 ob_rr_theme
->grip_width
,
451 self
->width
- ob_rr_theme
->grip_width
*2,
452 ob_rr_theme
->paddingy
+ 1);
454 XMoveWindow(ob_display
, self
->tltresize
, 0, 0);
455 XMoveWindow(ob_display
, self
->tllresize
, 0, 0);
456 XMoveWindow(ob_display
, self
->trtresize
,
457 self
->width
- ob_rr_theme
->grip_width
, 0);
458 XMoveWindow(ob_display
, self
->trrresize
,
459 self
->width
- ob_rr_theme
->paddingx
- 1, 0);
461 XMapWindow(ob_display
, self
->topresize
);
462 XMapWindow(ob_display
, self
->tltresize
);
463 XMapWindow(ob_display
, self
->tllresize
);
464 XMapWindow(ob_display
, self
->trtresize
);
465 XMapWindow(ob_display
, self
->trrresize
);
467 XUnmapWindow(ob_display
, self
->topresize
);
468 XUnmapWindow(ob_display
, self
->tltresize
);
469 XUnmapWindow(ob_display
, self
->tllresize
);
470 XUnmapWindow(ob_display
, self
->trtresize
);
471 XUnmapWindow(ob_display
, self
->trrresize
);
474 XUnmapWindow(ob_display
, self
->title
);
477 if ((self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
478 /* layout the title bar elements */
483 XMoveResizeWindow(ob_display
, self
->handlebottom
,
484 ob_rr_theme
->grip_width
+
486 self
->size
.top
+ self
->client
->area
.height
+
487 self
->size
.bottom
- self
->bwidth
,
488 self
->width
- (ob_rr_theme
->grip_width
+
492 XMoveResizeWindow(ob_display
, self
->lgripleft
,
494 self
->size
.top
+ self
->client
->area
.height
+
497 ob_rr_theme
->grip_width
:
501 ob_rr_theme
->grip_width
:
503 XMoveResizeWindow(ob_display
, self
->rgripright
,
504 self
->size
.left
+ self
->client
->area
.width
+
505 self
->size
.right
- self
->bwidth
,
506 self
->size
.top
+ self
->client
->area
.height
+
509 ob_rr_theme
->grip_width
:
513 ob_rr_theme
->grip_width
:
516 XMoveResizeWindow(ob_display
, self
->lgripbottom
,
518 self
->size
.top
+ self
->client
->area
.height
+
519 self
->size
.bottom
- self
->bwidth
,
520 ob_rr_theme
->grip_width
+ self
->bwidth
,
522 XMoveResizeWindow(ob_display
, self
->rgripbottom
,
523 self
->size
.left
+ self
->client
->area
.width
+
524 self
->size
.right
- self
->bwidth
* 2 -
525 ob_rr_theme
->grip_width
,
526 self
->size
.top
+ self
->client
->area
.height
+
527 self
->size
.bottom
- self
->bwidth
,
528 ob_rr_theme
->grip_width
+ self
->bwidth
,
531 XMapWindow(ob_display
, self
->handlebottom
);
532 XMapWindow(ob_display
, self
->lgripleft
);
533 XMapWindow(ob_display
, self
->rgripright
);
534 XMapWindow(ob_display
, self
->lgripbottom
);
535 XMapWindow(ob_display
, self
->rgripbottom
);
537 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
538 ob_rr_theme
->handle_height
> 0)
540 XMoveResizeWindow(ob_display
, self
->handletop
,
541 ob_rr_theme
->grip_width
+
543 FRAME_HANDLE_Y(self
),
544 self
->width
- (ob_rr_theme
->grip_width
+
547 XMapWindow(ob_display
, self
->handletop
);
549 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
550 XMoveResizeWindow(ob_display
, self
->handleleft
,
551 ob_rr_theme
->grip_width
,
554 ob_rr_theme
->handle_height
);
555 XMoveResizeWindow(ob_display
, self
->handleright
,
557 ob_rr_theme
->grip_width
-
561 ob_rr_theme
->handle_height
);
563 XMoveResizeWindow(ob_display
, self
->lgriptop
,
565 FRAME_HANDLE_Y(self
),
566 ob_rr_theme
->grip_width
+
569 XMoveResizeWindow(ob_display
, self
->rgriptop
,
571 self
->client
->area
.width
+
572 self
->size
.right
- self
->bwidth
* 2 -
573 ob_rr_theme
->grip_width
,
574 FRAME_HANDLE_Y(self
),
575 ob_rr_theme
->grip_width
+
579 XMapWindow(ob_display
, self
->handleleft
);
580 XMapWindow(ob_display
, self
->handleright
);
581 XMapWindow(ob_display
, self
->lgriptop
);
582 XMapWindow(ob_display
, self
->rgriptop
);
584 XUnmapWindow(ob_display
, self
->handleleft
);
585 XUnmapWindow(ob_display
, self
->handleright
);
586 XUnmapWindow(ob_display
, self
->lgriptop
);
587 XUnmapWindow(ob_display
, self
->rgriptop
);
590 XUnmapWindow(ob_display
, self
->handleleft
);
591 XUnmapWindow(ob_display
, self
->handleright
);
592 XUnmapWindow(ob_display
, self
->lgriptop
);
593 XUnmapWindow(ob_display
, self
->rgriptop
);
595 XUnmapWindow(ob_display
, self
->handletop
);
598 XUnmapWindow(ob_display
, self
->handleleft
);
599 XUnmapWindow(ob_display
, self
->handleright
);
600 XUnmapWindow(ob_display
, self
->lgriptop
);
601 XUnmapWindow(ob_display
, self
->rgriptop
);
603 XUnmapWindow(ob_display
, self
->handletop
);
605 XUnmapWindow(ob_display
, self
->handlebottom
);
606 XUnmapWindow(ob_display
, self
->lgripleft
);
607 XUnmapWindow(ob_display
, self
->rgripright
);
608 XUnmapWindow(ob_display
, self
->lgripbottom
);
609 XUnmapWindow(ob_display
, self
->rgripbottom
);
612 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
613 ob_rr_theme
->handle_height
> 0)
615 XMoveResizeWindow(ob_display
, self
->handle
,
617 FRAME_HANDLE_Y(self
) + self
->bwidth
,
618 self
->width
, ob_rr_theme
->handle_height
);
619 XMapWindow(ob_display
, self
->handle
);
621 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
622 XMoveResizeWindow(ob_display
, self
->lgrip
,
624 ob_rr_theme
->grip_width
,
625 ob_rr_theme
->handle_height
);
626 XMoveResizeWindow(ob_display
, self
->rgrip
,
627 self
->width
- ob_rr_theme
->grip_width
,
629 ob_rr_theme
->grip_width
,
630 ob_rr_theme
->handle_height
);
632 XMapWindow(ob_display
, self
->lgrip
);
633 XMapWindow(ob_display
, self
->rgrip
);
635 XUnmapWindow(ob_display
, self
->lgrip
);
636 XUnmapWindow(ob_display
, self
->rgrip
);
639 XUnmapWindow(ob_display
, self
->lgrip
);
640 XUnmapWindow(ob_display
, self
->rgrip
);
642 XUnmapWindow(ob_display
, self
->handle
);
645 if (self
->bwidth
&& !self
->max_horz
) {
646 XMoveResizeWindow(ob_display
, self
->left
,
648 self
->bwidth
+ ob_rr_theme
->grip_width
,
650 self
->client
->area
.height
+
651 self
->size
.top
+ self
->size
.bottom
-
652 ob_rr_theme
->grip_width
* 2);
654 XMapWindow(ob_display
, self
->left
);
656 XUnmapWindow(ob_display
, self
->left
);
658 if (self
->bwidth
&& !self
->max_horz
) {
659 XMoveResizeWindow(ob_display
, self
->right
,
660 self
->client
->area
.width
+
661 self
->cbwidth_x
* 2 + self
->bwidth
,
662 self
->bwidth
+ ob_rr_theme
->grip_width
,
664 self
->client
->area
.height
+
665 self
->size
.top
+ self
->size
.bottom
-
666 ob_rr_theme
->grip_width
* 2);
668 XMapWindow(ob_display
, self
->right
);
670 XUnmapWindow(ob_display
, self
->right
);
672 /* move and resize the inner border window which contains the plate
674 XMoveResizeWindow(ob_display
, self
->inner
,
676 self
->size
.top
- self
->cbwidth_y
,
677 self
->client
->area
.width
+
678 self
->cbwidth_x
* 2 +
679 (!self
->max_horz
? self
->bwidth
* 2 : 0),
680 self
->client
->area
.height
+
681 self
->cbwidth_y
* 2);
684 XMoveWindow(ob_display
, self
->plate
,
685 (!self
->max_horz
? self
->bwidth
: 0) + self
->cbwidth_x
,
688 /* when the client has StaticGravity, it likes to move around. */
689 XMoveWindow(ob_display
, self
->client
->window
, 0, 0);
693 /* shading can change without being moved or resized */
694 RECT_SET_SIZE(self
->area
,
695 self
->client
->area
.width
+
696 self
->size
.left
+ self
->size
.right
,
697 (self
->client
->shaded
?
698 ob_rr_theme
->title_height
+ self
->bwidth
* 2:
699 self
->client
->area
.height
+
700 self
->size
.top
+ self
->size
.bottom
));
702 if ((moved
|| resized
) && !fake
) {
703 /* find the new coordinates, done after setting the frame.size, for
704 frame_client_gravity. */
705 self
->area
.x
= self
->client
->area
.x
;
706 self
->area
.y
= self
->client
->area
.y
;
707 frame_client_gravity(self
, &self
->area
.x
, &self
->area
.y
,
708 self
->client
->area
.width
,
709 self
->client
->area
.height
);
713 if (!frame_iconify_animating(self
))
714 /* move and resize the top level frame.
715 shading can change without being moved or resized.
717 but don't do this during an iconify animation. it will be
718 reflected afterwards.
720 XMoveResizeWindow(ob_display
, self
->window
,
727 framerender_frame(self
);
728 frame_adjust_shape(self
);
731 if (!STRUT_EQUAL(self
->size
, oldsize
)) {
733 vals
[0] = self
->size
.left
;
734 vals
[1] = self
->size
.right
;
735 vals
[2] = self
->size
.top
;
736 vals
[3] = self
->size
.bottom
;
737 PROP_SETA32(self
->client
->window
, net_frame_extents
,
739 PROP_SETA32(self
->client
->window
, kde_net_wm_frame_strut
,
743 /* if this occurs while we are focus cycling, the indicator needs to
745 if (focus_cycle_target
== self
->client
)
746 focus_cycle_draw_indicator(self
->client
);
748 if (resized
&& (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
749 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
750 ob_rr_theme
->label_height
);
754 static void frame_adjust_cursors(ObFrame
*self
)
756 if ((self
->functions
& OB_CLIENT_FUNC_RESIZE
) !=
757 (self
->client
->functions
& OB_CLIENT_FUNC_RESIZE
) ||
758 self
->max_horz
!= self
->client
->max_horz
||
759 self
->max_vert
!= self
->client
->max_vert
)
761 gboolean r
= (self
->client
->functions
& OB_CLIENT_FUNC_RESIZE
) &&
762 !(self
->client
->max_horz
&& self
->client
->max_vert
);
763 gboolean topbot
= !self
->client
->max_vert
;
764 XSetWindowAttributes a
;
766 /* these ones turn off when max vert */
767 a
.cursor
= ob_cursor(r
&& topbot
? OB_CURSOR_NORTH
: OB_CURSOR_NONE
);
768 XChangeWindowAttributes(ob_display
, self
->topresize
, CWCursor
, &a
);
769 XChangeWindowAttributes(ob_display
, self
->titletop
, CWCursor
, &a
);
770 a
.cursor
= ob_cursor(r
&& topbot
? OB_CURSOR_SOUTH
: OB_CURSOR_NONE
);
771 XChangeWindowAttributes(ob_display
, self
->handle
, CWCursor
, &a
);
772 XChangeWindowAttributes(ob_display
, self
->handletop
, CWCursor
, &a
);
773 XChangeWindowAttributes(ob_display
, self
->handlebottom
, CWCursor
, &a
);
775 /* these ones don't */
776 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTHWEST
: OB_CURSOR_NONE
);
777 XChangeWindowAttributes(ob_display
, self
->tltresize
, CWCursor
, &a
);
778 XChangeWindowAttributes(ob_display
, self
->tllresize
, CWCursor
, &a
);
779 XChangeWindowAttributes(ob_display
, self
->titletopleft
, CWCursor
, &a
);
780 XChangeWindowAttributes(ob_display
, self
->titleleft
, CWCursor
, &a
);
781 a
.cursor
= ob_cursor(r
? OB_CURSOR_NORTHEAST
: OB_CURSOR_NONE
);
782 XChangeWindowAttributes(ob_display
, self
->trtresize
, CWCursor
, &a
);
783 XChangeWindowAttributes(ob_display
, self
->trrresize
, CWCursor
, &a
);
784 XChangeWindowAttributes(ob_display
, self
->titletopright
, CWCursor
, &a
);
785 XChangeWindowAttributes(ob_display
, self
->titleright
, CWCursor
, &a
);
786 a
.cursor
= ob_cursor(r
? OB_CURSOR_WEST
: OB_CURSOR_NONE
);
787 XChangeWindowAttributes(ob_display
, self
->left
, CWCursor
, &a
);
788 a
.cursor
= ob_cursor(r
? OB_CURSOR_EAST
: OB_CURSOR_NONE
);
789 XChangeWindowAttributes(ob_display
, self
->right
, CWCursor
, &a
);
790 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTHWEST
: OB_CURSOR_NONE
);
791 XChangeWindowAttributes(ob_display
, self
->lgrip
, CWCursor
, &a
);
792 XChangeWindowAttributes(ob_display
, self
->handleleft
, CWCursor
, &a
);
793 XChangeWindowAttributes(ob_display
, self
->lgripleft
, CWCursor
, &a
);
794 XChangeWindowAttributes(ob_display
, self
->lgriptop
, CWCursor
, &a
);
795 XChangeWindowAttributes(ob_display
, self
->lgripbottom
, CWCursor
, &a
);
796 a
.cursor
= ob_cursor(r
? OB_CURSOR_SOUTHEAST
: OB_CURSOR_NONE
);
797 XChangeWindowAttributes(ob_display
, self
->rgrip
, CWCursor
, &a
);
798 XChangeWindowAttributes(ob_display
, self
->handleright
, CWCursor
, &a
);
799 XChangeWindowAttributes(ob_display
, self
->rgripright
, CWCursor
, &a
);
800 XChangeWindowAttributes(ob_display
, self
->rgriptop
, CWCursor
, &a
);
801 XChangeWindowAttributes(ob_display
, self
->rgripbottom
, CWCursor
, &a
);
805 void frame_adjust_client_area(ObFrame
*self
)
807 /* resize the plate */
808 XResizeWindow(ob_display
, self
->plate
,
809 self
->client
->area
.width
, self
->client
->area
.height
);
812 void frame_adjust_state(ObFrame
*self
)
814 framerender_frame(self
);
817 void frame_adjust_focus(ObFrame
*self
, gboolean hilite
)
819 self
->focused
= hilite
;
820 framerender_frame(self
);
824 void frame_adjust_title(ObFrame
*self
)
826 framerender_frame(self
);
829 void frame_adjust_icon(ObFrame
*self
)
831 framerender_frame(self
);
834 void frame_grab_client(ObFrame
*self
)
836 /* reparent the client to the frame */
837 XReparentWindow(ob_display
, self
->client
->window
, self
->plate
, 0, 0);
840 When reparenting the client window, it is usually not mapped yet, since
841 this occurs from a MapRequest. However, in the case where Openbox is
842 starting up, the window is already mapped, so we'll see unmap events for
843 it. There are 2 unmap events generated that we see, one with the 'event'
844 member set the root window, and one set to the client, but both get
845 handled and need to be ignored.
847 if (ob_state() == OB_STATE_STARTING
)
848 self
->client
->ignore_unmaps
+= 2;
850 /* select the event mask on the client's parent (to receive config/map
851 req's) the ButtonPress is to catch clicks on the client border */
852 XSelectInput(ob_display
, self
->plate
, PLATE_EVENTMASK
);
854 /* map the client so it maps when the frame does */
855 XMapWindow(ob_display
, self
->client
->window
);
857 /* set all the windows for the frame in the window_map */
858 g_hash_table_insert(window_map
, &self
->window
, self
->client
);
859 g_hash_table_insert(window_map
, &self
->plate
, self
->client
);
860 g_hash_table_insert(window_map
, &self
->inner
, self
->client
);
861 g_hash_table_insert(window_map
, &self
->title
, self
->client
);
862 g_hash_table_insert(window_map
, &self
->label
, self
->client
);
863 g_hash_table_insert(window_map
, &self
->max
, self
->client
);
864 g_hash_table_insert(window_map
, &self
->close
, self
->client
);
865 g_hash_table_insert(window_map
, &self
->desk
, self
->client
);
866 g_hash_table_insert(window_map
, &self
->shade
, self
->client
);
867 g_hash_table_insert(window_map
, &self
->icon
, self
->client
);
868 g_hash_table_insert(window_map
, &self
->iconify
, self
->client
);
869 g_hash_table_insert(window_map
, &self
->handle
, self
->client
);
870 g_hash_table_insert(window_map
, &self
->lgrip
, self
->client
);
871 g_hash_table_insert(window_map
, &self
->rgrip
, self
->client
);
872 g_hash_table_insert(window_map
, &self
->topresize
, self
->client
);
873 g_hash_table_insert(window_map
, &self
->tltresize
, self
->client
);
874 g_hash_table_insert(window_map
, &self
->tllresize
, self
->client
);
875 g_hash_table_insert(window_map
, &self
->trtresize
, self
->client
);
876 g_hash_table_insert(window_map
, &self
->trrresize
, self
->client
);
877 g_hash_table_insert(window_map
, &self
->left
, self
->client
);
878 g_hash_table_insert(window_map
, &self
->right
, self
->client
);
879 g_hash_table_insert(window_map
, &self
->titleleft
, self
->client
);
880 g_hash_table_insert(window_map
, &self
->titletop
, self
->client
);
881 g_hash_table_insert(window_map
, &self
->titletopleft
, self
->client
);
882 g_hash_table_insert(window_map
, &self
->titletopright
, self
->client
);
883 g_hash_table_insert(window_map
, &self
->titleright
, self
->client
);
884 g_hash_table_insert(window_map
, &self
->titlebottom
, self
->client
);
885 g_hash_table_insert(window_map
, &self
->handleleft
, self
->client
);
886 g_hash_table_insert(window_map
, &self
->handletop
, self
->client
);
887 g_hash_table_insert(window_map
, &self
->handleright
, self
->client
);
888 g_hash_table_insert(window_map
, &self
->handlebottom
, self
->client
);
889 g_hash_table_insert(window_map
, &self
->lgripleft
, self
->client
);
890 g_hash_table_insert(window_map
, &self
->lgriptop
, self
->client
);
891 g_hash_table_insert(window_map
, &self
->lgripbottom
, self
->client
);
892 g_hash_table_insert(window_map
, &self
->rgripright
, self
->client
);
893 g_hash_table_insert(window_map
, &self
->rgriptop
, self
->client
);
894 g_hash_table_insert(window_map
, &self
->rgripbottom
, self
->client
);
897 void frame_release_client(ObFrame
*self
)
900 gboolean reparent
= TRUE
;
902 /* if there was any animation going on, kill it */
903 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
906 /* check if the app has already reparented its window away */
907 while (XCheckTypedWindowEvent(ob_display
, self
->client
->window
,
908 ReparentNotify
, &ev
))
910 /* This check makes sure we don't catch our own reparent action to
911 our frame window. This doesn't count as the app reparenting itself
914 Reparent events that are generated by us are just discarded here.
915 They are of no consequence to us anyhow.
917 if (ev
.xreparent
.parent
!= self
->plate
) {
919 XPutBackEvent(ob_display
, &ev
);
925 /* according to the ICCCM - if the client doesn't reparent itself,
926 then we will reparent the window to root for them */
927 XReparentWindow(ob_display
, self
->client
->window
,
928 RootWindow(ob_display
, ob_screen
),
929 self
->client
->area
.x
,
930 self
->client
->area
.y
);
933 /* remove all the windows for the frame from the window_map */
934 g_hash_table_remove(window_map
, &self
->window
);
935 g_hash_table_remove(window_map
, &self
->plate
);
936 g_hash_table_remove(window_map
, &self
->inner
);
937 g_hash_table_remove(window_map
, &self
->title
);
938 g_hash_table_remove(window_map
, &self
->label
);
939 g_hash_table_remove(window_map
, &self
->max
);
940 g_hash_table_remove(window_map
, &self
->close
);
941 g_hash_table_remove(window_map
, &self
->desk
);
942 g_hash_table_remove(window_map
, &self
->shade
);
943 g_hash_table_remove(window_map
, &self
->icon
);
944 g_hash_table_remove(window_map
, &self
->iconify
);
945 g_hash_table_remove(window_map
, &self
->handle
);
946 g_hash_table_remove(window_map
, &self
->lgrip
);
947 g_hash_table_remove(window_map
, &self
->rgrip
);
948 g_hash_table_remove(window_map
, &self
->topresize
);
949 g_hash_table_remove(window_map
, &self
->tltresize
);
950 g_hash_table_remove(window_map
, &self
->tllresize
);
951 g_hash_table_remove(window_map
, &self
->trtresize
);
952 g_hash_table_remove(window_map
, &self
->trrresize
);
953 g_hash_table_remove(window_map
, &self
->left
);
954 g_hash_table_remove(window_map
, &self
->right
);
955 g_hash_table_remove(window_map
, &self
->titleleft
);
956 g_hash_table_remove(window_map
, &self
->titletop
);
957 g_hash_table_remove(window_map
, &self
->titletopleft
);
958 g_hash_table_remove(window_map
, &self
->titletopright
);
959 g_hash_table_remove(window_map
, &self
->titleright
);
960 g_hash_table_remove(window_map
, &self
->titlebottom
);
961 g_hash_table_remove(window_map
, &self
->handleleft
);
962 g_hash_table_remove(window_map
, &self
->handletop
);
963 g_hash_table_remove(window_map
, &self
->handleright
);
964 g_hash_table_remove(window_map
, &self
->handlebottom
);
965 g_hash_table_remove(window_map
, &self
->lgripleft
);
966 g_hash_table_remove(window_map
, &self
->lgriptop
);
967 g_hash_table_remove(window_map
, &self
->lgripbottom
);
968 g_hash_table_remove(window_map
, &self
->rgripright
);
969 g_hash_table_remove(window_map
, &self
->rgriptop
);
970 g_hash_table_remove(window_map
, &self
->rgripbottom
);
972 ob_main_loop_timeout_remove_data(ob_main_loop
, flash_timeout
, self
, TRUE
);
975 /* is there anything present between us and the label? */
976 static gboolean
is_button_present(ObFrame
*self
, const gchar
*lc
, gint dir
) {
977 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+= dir
) {
978 if (*lc
== ' ') continue; /* it was invalid */
979 if (*lc
== 'N' && self
->decorations
& OB_FRAME_DECOR_ICON
)
981 if (*lc
== 'D' && self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
)
983 if (*lc
== 'S' && self
->decorations
& OB_FRAME_DECOR_SHADE
)
985 if (*lc
== 'I' && self
->decorations
& OB_FRAME_DECOR_ICONIFY
)
987 if (*lc
== 'M' && self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
)
989 if (*lc
== 'C' && self
->decorations
& OB_FRAME_DECOR_CLOSE
)
991 if (*lc
== 'L') return FALSE
;
996 static void layout_title(ObFrame
*self
)
1001 const gint bwidth
= ob_rr_theme
->button_size
+ ob_rr_theme
->paddingx
+ 1;
1002 /* position of the left most button */
1003 const gint left
= ob_rr_theme
->paddingx
+ 1;
1004 /* position of the right most button */
1005 const gint right
= self
->width
- bwidth
;
1007 /* turn them all off */
1008 self
->icon_on
= self
->desk_on
= self
->shade_on
= self
->iconify_on
=
1009 self
->max_on
= self
->close_on
= self
->label_on
= FALSE
;
1010 self
->label_width
= self
->width
- (ob_rr_theme
->paddingx
+ 1) * 2;
1011 self
->leftmost
= self
->rightmost
= OB_FRAME_CONTEXT_NONE
;
1013 /* figure out what's being show, find each element's position, and the
1016 do the ones before the label, then after the label,
1017 i will be +1 the first time through when working to the left,
1018 and -1 the second time through when working to the right */
1019 for (i
= 1; i
>= -1; i
-=2) {
1021 ObFrameContext
*firstcon
;
1025 lc
= config_title_layout
;
1026 firstcon
= &self
->leftmost
;
1029 lc
= config_title_layout
+ strlen(config_title_layout
)-1;
1030 firstcon
= &self
->rightmost
;
1033 /* stop at the end of the string (or the label, which calls break) */
1034 for (; *lc
!= '\0' && lc
>= config_title_layout
; lc
+=i
) {
1037 self
->label_on
= TRUE
;
1040 break; /* break the for loop, do other side of label */
1041 } else if (*lc
== 'N') {
1042 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICON
;
1043 if ((self
->icon_on
= is_button_present(self
, lc
, i
))) {
1044 /* icon is bigger than buttons */
1045 self
->label_width
-= bwidth
+ 2;
1047 x
+= i
* (bwidth
+ 2);
1049 } else if (*lc
== 'D') {
1050 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ALLDESKTOPS
;
1051 if ((self
->desk_on
= is_button_present(self
, lc
, i
))) {
1052 self
->label_width
-= bwidth
;
1056 } else if (*lc
== 'S') {
1057 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_SHADE
;
1058 if ((self
->shade_on
= is_button_present(self
, lc
, i
))) {
1059 self
->label_width
-= bwidth
;
1063 } else if (*lc
== 'I') {
1064 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_ICONIFY
;
1065 if ((self
->iconify_on
= is_button_present(self
, lc
, i
))) {
1066 self
->label_width
-= bwidth
;
1067 self
->iconify_x
= x
;
1070 } else if (*lc
== 'M') {
1071 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_MAXIMIZE
;
1072 if ((self
->max_on
= is_button_present(self
, lc
, i
))) {
1073 self
->label_width
-= bwidth
;
1077 } else if (*lc
== 'C') {
1078 if (firstcon
) *firstcon
= OB_FRAME_CONTEXT_CLOSE
;
1079 if ((self
->close_on
= is_button_present(self
, lc
, i
))) {
1080 self
->label_width
-= bwidth
;
1085 continue; /* don't set firstcon */
1090 /* position and map the elements */
1091 if (self
->icon_on
) {
1092 XMapWindow(ob_display
, self
->icon
);
1093 XMoveWindow(ob_display
, self
->icon
, self
->icon_x
,
1094 ob_rr_theme
->paddingy
);
1096 XUnmapWindow(ob_display
, self
->icon
);
1098 if (self
->desk_on
) {
1099 XMapWindow(ob_display
, self
->desk
);
1100 XMoveWindow(ob_display
, self
->desk
, self
->desk_x
,
1101 ob_rr_theme
->paddingy
+ 1);
1103 XUnmapWindow(ob_display
, self
->desk
);
1105 if (self
->shade_on
) {
1106 XMapWindow(ob_display
, self
->shade
);
1107 XMoveWindow(ob_display
, self
->shade
, self
->shade_x
,
1108 ob_rr_theme
->paddingy
+ 1);
1110 XUnmapWindow(ob_display
, self
->shade
);
1112 if (self
->iconify_on
) {
1113 XMapWindow(ob_display
, self
->iconify
);
1114 XMoveWindow(ob_display
, self
->iconify
, self
->iconify_x
,
1115 ob_rr_theme
->paddingy
+ 1);
1117 XUnmapWindow(ob_display
, self
->iconify
);
1120 XMapWindow(ob_display
, self
->max
);
1121 XMoveWindow(ob_display
, self
->max
, self
->max_x
,
1122 ob_rr_theme
->paddingy
+ 1);
1124 XUnmapWindow(ob_display
, self
->max
);
1126 if (self
->close_on
) {
1127 XMapWindow(ob_display
, self
->close
);
1128 XMoveWindow(ob_display
, self
->close
, self
->close_x
,
1129 ob_rr_theme
->paddingy
+ 1);
1131 XUnmapWindow(ob_display
, self
->close
);
1133 if (self
->label_on
) {
1134 self
->label_width
= MAX(1, self
->label_width
); /* no lower than 1 */
1135 XMapWindow(ob_display
, self
->label
);
1136 XMoveWindow(ob_display
, self
->label
, self
->label_x
,
1137 ob_rr_theme
->paddingy
);
1139 XUnmapWindow(ob_display
, self
->label
);
1142 ObFrameContext
frame_context_from_string(const gchar
*name
)
1144 if (!g_ascii_strcasecmp("Desktop", name
))
1145 return OB_FRAME_CONTEXT_DESKTOP
;
1146 else if (!g_ascii_strcasecmp("Root", name
))
1147 return OB_FRAME_CONTEXT_ROOT
;
1148 else if (!g_ascii_strcasecmp("Client", name
))
1149 return OB_FRAME_CONTEXT_CLIENT
;
1150 else if (!g_ascii_strcasecmp("Titlebar", name
))
1151 return OB_FRAME_CONTEXT_TITLEBAR
;
1152 else if (!g_ascii_strcasecmp("Frame", name
))
1153 return OB_FRAME_CONTEXT_FRAME
;
1154 else if (!g_ascii_strcasecmp("TLCorner", name
))
1155 return OB_FRAME_CONTEXT_TLCORNER
;
1156 else if (!g_ascii_strcasecmp("TRCorner", name
))
1157 return OB_FRAME_CONTEXT_TRCORNER
;
1158 else if (!g_ascii_strcasecmp("BLCorner", name
))
1159 return OB_FRAME_CONTEXT_BLCORNER
;
1160 else if (!g_ascii_strcasecmp("BRCorner", name
))
1161 return OB_FRAME_CONTEXT_BRCORNER
;
1162 else if (!g_ascii_strcasecmp("Top", name
))
1163 return OB_FRAME_CONTEXT_TOP
;
1164 else if (!g_ascii_strcasecmp("Bottom", name
))
1165 return OB_FRAME_CONTEXT_BOTTOM
;
1166 else if (!g_ascii_strcasecmp("Left", name
))
1167 return OB_FRAME_CONTEXT_LEFT
;
1168 else if (!g_ascii_strcasecmp("Right", name
))
1169 return OB_FRAME_CONTEXT_RIGHT
;
1170 else if (!g_ascii_strcasecmp("Maximize", name
))
1171 return OB_FRAME_CONTEXT_MAXIMIZE
;
1172 else if (!g_ascii_strcasecmp("AllDesktops", name
))
1173 return OB_FRAME_CONTEXT_ALLDESKTOPS
;
1174 else if (!g_ascii_strcasecmp("Shade", name
))
1175 return OB_FRAME_CONTEXT_SHADE
;
1176 else if (!g_ascii_strcasecmp("Iconify", name
))
1177 return OB_FRAME_CONTEXT_ICONIFY
;
1178 else if (!g_ascii_strcasecmp("Icon", name
))
1179 return OB_FRAME_CONTEXT_ICON
;
1180 else if (!g_ascii_strcasecmp("Close", name
))
1181 return OB_FRAME_CONTEXT_CLOSE
;
1182 else if (!g_ascii_strcasecmp("MoveResize", name
))
1183 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
1184 return OB_FRAME_CONTEXT_NONE
;
1187 ObFrameContext
frame_context(ObClient
*client
, Window win
, gint x
, gint y
)
1191 if (moveresize_in_progress
)
1192 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
1194 if (win
== RootWindow(ob_display
, ob_screen
))
1195 return OB_FRAME_CONTEXT_ROOT
;
1196 if (client
== NULL
) return OB_FRAME_CONTEXT_NONE
;
1197 if (win
== client
->window
) {
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 self
= client
->frame
;
1206 if (win
== self
->inner
|| win
== self
->plate
) {
1207 /* conceptually, this is the desktop, as far as users are
1209 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
1210 return OB_FRAME_CONTEXT_DESKTOP
;
1211 return OB_FRAME_CONTEXT_CLIENT
;
1214 /* when the user clicks in the corners of the titlebar and the client
1215 is fully maximized, then treat it like they clicked in the
1216 button that is there */
1217 if (self
->max_horz
&& self
->max_vert
&&
1218 (win
== self
->title
|| win
== self
->titletop
||
1219 win
== self
->titleleft
|| win
== self
->titletopleft
||
1220 win
== self
->titleright
|| win
== self
->titletopright
))
1222 /* get the mouse coords in reference to the whole frame */
1226 /* these windows are down a border width from the top of the frame */
1227 if (win
== self
->title
||
1228 win
== self
->titleleft
|| win
== self
->titleright
)
1231 /* title is a border width in from the edge */
1232 if (win
== self
->title
)
1234 /* titletop is a bit to the right */
1235 else if (win
== self
->titletop
)
1236 fx
+= ob_rr_theme
->grip_width
+ self
->bwidth
;
1237 /* titletopright is way to the right edge */
1238 else if (win
== self
->titletopright
)
1239 fx
+= self
->area
.width
- (ob_rr_theme
->grip_width
+ self
->bwidth
);
1240 /* titleright is even more way to the right edge */
1241 else if (win
== self
->titleright
)
1242 fx
+= self
->area
.width
- self
->bwidth
;
1244 /* figure out if we're over the area that should be considered a
1246 if (fy
< self
->bwidth
+ ob_rr_theme
->paddingy
+ 1 +
1247 ob_rr_theme
->button_size
)
1249 if (fx
< (self
->bwidth
+ ob_rr_theme
->paddingx
+ 1 +
1250 ob_rr_theme
->button_size
))
1252 if (self
->leftmost
!= OB_FRAME_CONTEXT_NONE
)
1253 return self
->leftmost
;
1255 else if (fx
>= (self
->area
.width
-
1256 (self
->bwidth
+ ob_rr_theme
->paddingx
+ 1 +
1257 ob_rr_theme
->button_size
)))
1259 if (self
->rightmost
!= OB_FRAME_CONTEXT_NONE
)
1260 return self
->rightmost
;
1264 /* there is no resizing maximized windows so make them the titlebar
1266 return OB_FRAME_CONTEXT_TITLEBAR
;
1268 else if (self
->max_vert
&&
1269 (win
== self
->titletop
|| win
== self
->topresize
))
1270 /* can't resize vertically when max vert */
1271 return OB_FRAME_CONTEXT_TITLEBAR
;
1273 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
1274 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
1275 if (win
== self
->handle
) return OB_FRAME_CONTEXT_BOTTOM
;
1276 if (win
== self
->handletop
) return OB_FRAME_CONTEXT_BOTTOM
;
1277 if (win
== self
->handlebottom
) return OB_FRAME_CONTEXT_BOTTOM
;
1278 if (win
== self
->handleleft
) return OB_FRAME_CONTEXT_BLCORNER
;
1279 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
1280 if (win
== self
->lgripleft
) return OB_FRAME_CONTEXT_BLCORNER
;
1281 if (win
== self
->lgriptop
) return OB_FRAME_CONTEXT_BLCORNER
;
1282 if (win
== self
->lgripbottom
) return OB_FRAME_CONTEXT_BLCORNER
;
1283 if (win
== self
->handleright
) return OB_FRAME_CONTEXT_BRCORNER
;
1284 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
1285 if (win
== self
->rgripright
) return OB_FRAME_CONTEXT_BLCORNER
;
1286 if (win
== self
->rgriptop
) return OB_FRAME_CONTEXT_BLCORNER
;
1287 if (win
== self
->rgripbottom
) return OB_FRAME_CONTEXT_BLCORNER
;
1288 if (win
== self
->title
) return OB_FRAME_CONTEXT_TITLEBAR
;
1289 if (win
== self
->titleleft
) return OB_FRAME_CONTEXT_TLCORNER
;
1290 if (win
== self
->titletopleft
) return OB_FRAME_CONTEXT_TLCORNER
;
1291 if (win
== self
->titleright
) return OB_FRAME_CONTEXT_TRCORNER
;
1292 if (win
== self
->titletopright
) return OB_FRAME_CONTEXT_TRCORNER
;
1293 if (win
== self
->titletop
) return OB_FRAME_CONTEXT_TOP
;
1294 if (win
== self
->topresize
) return OB_FRAME_CONTEXT_TOP
;
1295 if (win
== self
->tltresize
) return OB_FRAME_CONTEXT_TLCORNER
;
1296 if (win
== self
->tllresize
) return OB_FRAME_CONTEXT_TLCORNER
;
1297 if (win
== self
->trtresize
) return OB_FRAME_CONTEXT_TRCORNER
;
1298 if (win
== self
->trrresize
) return OB_FRAME_CONTEXT_TRCORNER
;
1299 if (win
== self
->left
) return OB_FRAME_CONTEXT_LEFT
;
1300 if (win
== self
->right
) return OB_FRAME_CONTEXT_RIGHT
;
1301 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
1302 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
1303 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
1304 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
1305 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
1306 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
1308 return OB_FRAME_CONTEXT_NONE
;
1311 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
1314 switch (self
->client
->gravity
) {
1316 case NorthWestGravity
:
1317 case SouthWestGravity
:
1324 /* the middle of the client will be the middle of the frame */
1325 *x
-= (self
->size
.right
- self
->size
.left
) / 2;
1328 case NorthEastGravity
:
1329 case SouthEastGravity
:
1331 /* the right side of the client will be the right side of the frame */
1332 *x
-= self
->size
.right
+ self
->size
.left
;
1337 /* the client's position won't move */
1338 *x
-= self
->size
.left
;
1343 switch (self
->client
->gravity
) {
1345 case NorthWestGravity
:
1346 case NorthEastGravity
:
1353 /* the middle of the client will be the middle of the frame */
1354 *y
-= (self
->size
.bottom
- self
->size
.top
) / 2;
1357 case SouthWestGravity
:
1358 case SouthEastGravity
:
1360 /* the bottom of the client will be the bottom of the frame */
1361 *y
-= self
->size
.bottom
+ self
->size
.top
;
1366 /* the client's position won't move */
1367 *y
-= self
->size
.top
;
1372 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
, gint w
, gint h
)
1375 switch (self
->client
->gravity
) {
1377 case NorthWestGravity
:
1379 case SouthWestGravity
:
1384 /* the middle of the client will be the middle of the frame */
1385 *x
+= (self
->size
.right
- self
->size
.left
) / 2;
1387 case NorthEastGravity
:
1389 case SouthEastGravity
:
1390 /* the right side of the client will be the right side of the frame */
1391 *x
+= self
->size
.right
+ self
->size
.left
;
1395 /* the client's position won't move */
1396 *x
+= self
->size
.left
;
1401 switch (self
->client
->gravity
) {
1403 case NorthWestGravity
:
1405 case NorthEastGravity
:
1410 /* the middle of the client will be the middle of the frame */
1411 *y
+= (self
->size
.bottom
- self
->size
.top
) / 2;
1413 case SouthWestGravity
:
1415 case SouthEastGravity
:
1416 /* the bottom of the client will be the bottom of the frame */
1417 *y
+= self
->size
.bottom
+ self
->size
.top
;
1421 /* the client's position won't move */
1422 *y
+= self
->size
.top
;
1427 static void flash_done(gpointer data
)
1429 ObFrame
*self
= data
;
1431 if (self
->focused
!= self
->flash_on
)
1432 frame_adjust_focus(self
, self
->focused
);
1435 static gboolean
flash_timeout(gpointer data
)
1437 ObFrame
*self
= data
;
1440 g_get_current_time(&now
);
1441 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
1442 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
1443 now
.tv_usec
>= self
->flash_end
.tv_usec
))
1444 self
->flashing
= FALSE
;
1446 if (!self
->flashing
)
1447 return FALSE
; /* we are done */
1449 self
->flash_on
= !self
->flash_on
;
1450 if (!self
->focused
) {
1451 frame_adjust_focus(self
, self
->flash_on
);
1452 self
->focused
= FALSE
;
1455 return TRUE
; /* go again */
1458 void frame_flash_start(ObFrame
*self
)
1460 self
->flash_on
= self
->focused
;
1462 if (!self
->flashing
)
1463 ob_main_loop_timeout_add(ob_main_loop
,
1464 G_USEC_PER_SEC
* 0.6,
1469 g_get_current_time(&self
->flash_end
);
1470 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
1472 self
->flashing
= TRUE
;
1475 void frame_flash_stop(ObFrame
*self
)
1477 self
->flashing
= FALSE
;
1480 static gulong
frame_animate_iconify_time_left(ObFrame
*self
,
1481 const GTimeVal
*now
)
1484 sec
= self
->iconify_animation_end
.tv_sec
- now
->tv_sec
;
1485 usec
= self
->iconify_animation_end
.tv_usec
- now
->tv_usec
;
1487 usec
+= G_USEC_PER_SEC
;
1490 /* no negative values */
1491 return MAX(sec
* G_USEC_PER_SEC
+ usec
, 0);
1494 static gboolean
frame_animate_iconify(gpointer p
)
1498 gint iconx
, icony
, iconw
;
1501 gboolean iconifying
;
1503 if (self
->client
->icon_geometry
.width
== 0) {
1504 /* there is no icon geometry set so just go straight down */
1505 Rect
*a
= screen_physical_area();
1506 iconx
= self
->area
.x
+ self
->area
.width
/ 2 + 32;
1507 icony
= a
->y
+ a
->width
;
1510 iconx
= self
->client
->icon_geometry
.x
;
1511 icony
= self
->client
->icon_geometry
.y
;
1512 iconw
= self
->client
->icon_geometry
.width
;
1515 iconifying
= self
->iconify_animation_going
> 0;
1517 /* how far do we have left to go ? */
1518 g_get_current_time(&now
);
1519 time
= frame_animate_iconify_time_left(self
, &now
);
1521 if (time
== 0 || iconifying
) {
1522 /* start where the frame is supposed to be */
1525 w
= self
->area
.width
;
1526 h
= self
->area
.height
;
1528 /* start at the icon */
1532 h
= self
->size
.top
; /* just the titlebar */
1539 dx
= self
->area
.x
- iconx
;
1540 dy
= self
->area
.y
- icony
;
1541 dw
= self
->area
.width
- self
->bwidth
* 2 - iconw
;
1542 /* if restoring, we move in the opposite direction */
1543 if (!iconifying
) { dx
= -dx
; dy
= -dy
; dw
= -dw
; }
1545 elapsed
= FRAME_ANIMATE_ICONIFY_TIME
- time
;
1546 x
= x
- (dx
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1547 y
= y
- (dy
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1548 w
= w
- (dw
* elapsed
) / FRAME_ANIMATE_ICONIFY_TIME
;
1549 h
= self
->size
.top
; /* just the titlebar */
1553 frame_end_iconify_animation(self
);
1555 XMoveResizeWindow(ob_display
, self
->window
, x
, y
, w
, h
);
1559 return time
> 0; /* repeat until we're out of time */
1562 void frame_end_iconify_animation(ObFrame
*self
)
1564 /* see if there is an animation going */
1565 if (self
->iconify_animation_going
== 0) return;
1568 XUnmapWindow(ob_display
, self
->window
);
1570 /* Send a ConfigureNotify when the animation is done, this fixes
1571 KDE's pager showing the window in the wrong place. */
1572 client_reconfigure(self
->client
);
1574 /* we're not animating any more ! */
1575 self
->iconify_animation_going
= 0;
1577 XMoveResizeWindow(ob_display
, self
->window
,
1578 self
->area
.x
, self
->area
.y
,
1579 self
->area
.width
, self
->area
.height
);
1583 void frame_begin_iconify_animation(ObFrame
*self
, gboolean iconifying
)
1586 gboolean new_anim
= FALSE
;
1587 gboolean set_end
= TRUE
;
1590 /* if there is no titlebar, just don't animate for now
1591 XXX it would be nice tho.. */
1592 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1595 /* get the current time */
1596 g_get_current_time(&now
);
1598 /* get how long until the end */
1599 time
= FRAME_ANIMATE_ICONIFY_TIME
;
1600 if (self
->iconify_animation_going
) {
1601 if (!!iconifying
!= (self
->iconify_animation_going
> 0)) {
1602 /* animation was already going on in the opposite direction */
1603 time
= time
- frame_animate_iconify_time_left(self
, &now
);
1605 /* animation was already going in the same direction */
1609 self
->iconify_animation_going
= iconifying
? 1 : -1;
1611 /* set the ending time */
1613 self
->iconify_animation_end
.tv_sec
= now
.tv_sec
;
1614 self
->iconify_animation_end
.tv_usec
= now
.tv_usec
;
1615 g_time_val_add(&self
->iconify_animation_end
, time
);
1619 ob_main_loop_timeout_remove_data(ob_main_loop
, frame_animate_iconify
,
1621 ob_main_loop_timeout_add(ob_main_loop
,
1622 FRAME_ANIMATE_ICONIFY_STEP_TIME
,
1623 frame_animate_iconify
, self
,
1624 g_direct_equal
, NULL
);
1626 /* do the first step */
1627 frame_animate_iconify(self
);
1629 /* show it during the animation even if it is not "visible" */
1631 XMapWindow(ob_display
, self
->window
);