1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 frame.c for the Openbox window manager
4 Copyright (c) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
22 #include "extensions.h"
25 #include "framerender.h"
28 #include "moveresize.h"
29 #include "render/theme.h"
31 #define PLATE_EVENTMASK (SubstructureRedirectMask | ButtonPressMask)
32 #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
33 ButtonPressMask | ButtonReleaseMask | \
35 #define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \
36 ButtonMotionMask | ExposureMask | \
37 EnterWindowMask | LeaveWindowMask)
39 #define FRAME_HANDLE_Y(f) (f->innersize.top + f->client->area.height + \
42 static void layout_title(ObFrame
*self
);
43 static void flash_done(gpointer data
);
44 static gboolean
flash_timeout(gpointer data
);
46 static void set_theme_statics(ObFrame
*self
);
47 static void free_theme_statics(ObFrame
*self
);
49 static Window
createWindow(Window parent
, gulong mask
,
50 XSetWindowAttributes
*attrib
)
52 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
53 RrDepth(ob_rr_inst
), InputOutput
,
54 RrVisual(ob_rr_inst
), mask
, attrib
);
60 XSetWindowAttributes attrib
;
64 self
= g_new0(ObFrame
, 1);
66 self
->obscured
= TRUE
;
68 /* create all of the decor windows */
70 attrib
.event_mask
= FRAME_EVENTMASK
;
71 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
),
75 self
->plate
= createWindow(self
->window
, mask
, &attrib
);
78 attrib
.event_mask
= ELEMENT_EVENTMASK
;
79 self
->title
= createWindow(self
->window
, mask
, &attrib
);
82 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHWEST
);
83 self
->tlresize
= createWindow(self
->title
, mask
, &attrib
);
84 attrib
.cursor
= ob_cursor(OB_CURSOR_NORTHEAST
);
85 self
->trresize
= createWindow(self
->title
, mask
, &attrib
);
88 self
->label
= createWindow(self
->title
, mask
, &attrib
);
89 self
->max
= createWindow(self
->title
, mask
, &attrib
);
90 self
->close
= createWindow(self
->title
, mask
, &attrib
);
91 self
->desk
= createWindow(self
->title
, mask
, &attrib
);
92 self
->shade
= createWindow(self
->title
, mask
, &attrib
);
93 self
->icon
= createWindow(self
->title
, mask
, &attrib
);
94 self
->iconify
= createWindow(self
->title
, mask
, &attrib
);
95 self
->handle
= createWindow(self
->window
, mask
, &attrib
);
98 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHWEST
);
99 self
->lgrip
= createWindow(self
->handle
, mask
, &attrib
);
100 attrib
.cursor
= ob_cursor(OB_CURSOR_SOUTHEAST
);
101 self
->rgrip
= createWindow(self
->handle
, mask
, &attrib
);
103 self
->focused
= FALSE
;
105 /* the other stuff is shown based on decor settings */
106 XMapWindow(ob_display
, self
->plate
);
107 XMapWindow(ob_display
, self
->lgrip
);
108 XMapWindow(ob_display
, self
->rgrip
);
109 XMapWindow(ob_display
, self
->label
);
111 self
->max_press
= self
->close_press
= self
->desk_press
=
112 self
->iconify_press
= self
->shade_press
= FALSE
;
113 self
->max_hover
= self
->close_hover
= self
->desk_hover
=
114 self
->iconify_hover
= self
->shade_hover
= FALSE
;
116 set_theme_statics(self
);
118 return (ObFrame
*)self
;
121 static void set_theme_statics(ObFrame
*self
)
123 /* set colors/appearance/sizes for stuff that doesn't change */
124 XSetWindowBorder(ob_display
, self
->window
,
125 RrColorPixel(ob_rr_theme
->b_color
));
126 XSetWindowBorder(ob_display
, self
->title
,
127 RrColorPixel(ob_rr_theme
->b_color
));
128 XSetWindowBorder(ob_display
, self
->handle
,
129 RrColorPixel(ob_rr_theme
->b_color
));
130 XSetWindowBorder(ob_display
, self
->rgrip
,
131 RrColorPixel(ob_rr_theme
->b_color
));
132 XSetWindowBorder(ob_display
, self
->lgrip
,
133 RrColorPixel(ob_rr_theme
->b_color
));
135 XResizeWindow(ob_display
, self
->max
,
136 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
137 XResizeWindow(ob_display
, self
->iconify
,
138 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
139 XResizeWindow(ob_display
, self
->icon
,
140 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
141 XResizeWindow(ob_display
, self
->close
,
142 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
143 XResizeWindow(ob_display
, self
->desk
,
144 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
145 XResizeWindow(ob_display
, self
->shade
,
146 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
147 XResizeWindow(ob_display
, self
->lgrip
,
148 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
149 XResizeWindow(ob_display
, self
->rgrip
,
150 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
151 XResizeWindow(ob_display
, self
->tlresize
,
152 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
153 XResizeWindow(ob_display
, self
->trresize
,
154 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
156 /* set up the dynamic appearances */
157 self
->a_unfocused_title
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_title
);
158 self
->a_focused_title
= RrAppearanceCopy(ob_rr_theme
->a_focused_title
);
159 self
->a_unfocused_label
= RrAppearanceCopy(ob_rr_theme
->a_unfocused_label
);
160 self
->a_focused_label
= RrAppearanceCopy(ob_rr_theme
->a_focused_label
);
161 self
->a_unfocused_handle
=
162 RrAppearanceCopy(ob_rr_theme
->a_unfocused_handle
);
163 self
->a_focused_handle
= RrAppearanceCopy(ob_rr_theme
->a_focused_handle
);
164 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_icon
);
167 static void free_theme_statics(ObFrame
*self
)
169 RrAppearanceFree(self
->a_unfocused_title
);
170 RrAppearanceFree(self
->a_focused_title
);
171 RrAppearanceFree(self
->a_unfocused_label
);
172 RrAppearanceFree(self
->a_focused_label
);
173 RrAppearanceFree(self
->a_unfocused_handle
);
174 RrAppearanceFree(self
->a_focused_handle
);
175 RrAppearanceFree(self
->a_icon
);
178 static void frame_free(ObFrame
*self
)
180 free_theme_statics(self
);
182 XDestroyWindow(ob_display
, self
->window
);
187 void frame_show(ObFrame
*self
)
189 if (!self
->visible
) {
190 self
->visible
= TRUE
;
191 XMapWindow(ob_display
, self
->client
->window
);
192 XMapWindow(ob_display
, self
->window
);
196 void frame_hide(ObFrame
*self
)
199 self
->visible
= FALSE
;
200 self
->client
->ignore_unmaps
+= 2;
201 /* we unmap the client itself so that we can get MapRequest
202 events, and because the ICCCM tells us to! */
203 XUnmapWindow(ob_display
, self
->window
);
204 XUnmapWindow(ob_display
, self
->client
->window
);
208 void frame_adjust_theme(ObFrame
*self
)
210 free_theme_statics(self
);
211 set_theme_statics(self
);
214 void frame_adjust_shape(ObFrame
*self
)
220 if (!self
->client
->shaped
) {
221 /* clear the shape on the frame window */
222 XShapeCombineMask(ob_display
, self
->window
, ShapeBounding
,
223 self
->innersize
.left
,
227 /* make the frame's shape match the clients */
228 XShapeCombineShape(ob_display
, self
->window
, ShapeBounding
,
229 self
->innersize
.left
,
231 self
->client
->window
,
232 ShapeBounding
, ShapeSet
);
235 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
236 xrect
[0].x
= -ob_rr_theme
->bwidth
;
237 xrect
[0].y
= -ob_rr_theme
->bwidth
;
238 xrect
[0].width
= self
->width
+ self
->rbwidth
* 2;
239 xrect
[0].height
= ob_rr_theme
->title_height
+
244 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
) {
245 xrect
[1].x
= -ob_rr_theme
->bwidth
;
246 xrect
[1].y
= FRAME_HANDLE_Y(self
);
247 xrect
[1].width
= self
->width
+ self
->rbwidth
* 2;
248 xrect
[1].height
= ob_rr_theme
->handle_height
+
253 XShapeCombineRectangles(ob_display
, self
->window
,
254 ShapeBounding
, 0, 0, xrect
, num
,
255 ShapeUnion
, Unsorted
);
260 void frame_adjust_area(ObFrame
*self
, gboolean moved
,
261 gboolean resized
, gboolean fake
)
265 oldsize
= self
->size
;
268 self
->decorations
= self
->client
->decorations
;
269 self
->max_horz
= self
->client
->max_horz
;
271 if (self
->decorations
& OB_FRAME_DECOR_BORDER
) {
272 self
->bwidth
= ob_rr_theme
->bwidth
;
273 self
->cbwidth_x
= self
->cbwidth_y
= ob_rr_theme
->cbwidth
;
275 self
->bwidth
= self
->cbwidth_x
= self
->cbwidth_y
= 0;
277 self
->rbwidth
= self
->bwidth
;
280 self
->bwidth
= self
->cbwidth_x
= 0;
282 STRUT_SET(self
->innersize
,
287 self
->width
= self
->client
->area
.width
+ self
->cbwidth_x
* 2 -
288 (self
->max_horz
? self
->rbwidth
* 2 : 0);
289 self
->width
= MAX(self
->width
, 1); /* no lower than 1 */
291 /* set border widths */
293 XSetWindowBorderWidth(ob_display
, self
->window
, self
->bwidth
);
294 XSetWindowBorderWidth(ob_display
, self
->title
, self
->rbwidth
);
295 XSetWindowBorderWidth(ob_display
, self
->handle
, self
->rbwidth
);
296 XSetWindowBorderWidth(ob_display
, self
->lgrip
, self
->rbwidth
);
297 XSetWindowBorderWidth(ob_display
, self
->rgrip
, self
->rbwidth
);
300 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
301 self
->innersize
.top
+= ob_rr_theme
->title_height
+ self
->rbwidth
+
302 (self
->rbwidth
- self
->bwidth
);
303 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
304 ob_rr_theme
->show_handle
)
305 self
->innersize
.bottom
+= ob_rr_theme
->handle_height
+
306 self
->rbwidth
+ (self
->rbwidth
- self
->bwidth
);
308 /* they all default off, they're turned on in layout_title */
312 self
->iconify_x
= -1;
317 /* position/size and map/unmap all the windows */
320 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
321 XMoveResizeWindow(ob_display
, self
->title
,
322 -self
->bwidth
, -self
->bwidth
,
323 self
->width
, ob_rr_theme
->title_height
);
324 XMapWindow(ob_display
, self
->title
);
326 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
327 XMoveWindow(ob_display
, self
->tlresize
, 0, 0);
328 XMoveWindow(ob_display
, self
->trresize
,
329 self
->width
- ob_rr_theme
->grip_width
, 0);
330 XMapWindow(ob_display
, self
->tlresize
);
331 XMapWindow(ob_display
, self
->trresize
);
333 XUnmapWindow(ob_display
, self
->tlresize
);
334 XUnmapWindow(ob_display
, self
->trresize
);
337 XUnmapWindow(ob_display
, self
->title
);
340 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
)
341 /* layout the title bar elements */
345 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
346 ob_rr_theme
->show_handle
)
348 XMoveResizeWindow(ob_display
, self
->handle
,
349 -self
->bwidth
, FRAME_HANDLE_Y(self
),
350 self
->width
, ob_rr_theme
->handle_height
);
351 XMapWindow(ob_display
, self
->handle
);
353 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
354 XMoveWindow(ob_display
, self
->lgrip
,
355 -self
->rbwidth
, -self
->rbwidth
);
356 XMoveWindow(ob_display
, self
->rgrip
,
357 -self
->rbwidth
+ self
->width
-
358 ob_rr_theme
->grip_width
, -self
->rbwidth
);
359 XMapWindow(ob_display
, self
->lgrip
);
360 XMapWindow(ob_display
, self
->rgrip
);
362 XUnmapWindow(ob_display
, self
->lgrip
);
363 XUnmapWindow(ob_display
, self
->rgrip
);
366 /* XXX make a subwindow with these dimentions?
367 ob_rr_theme->grip_width + self->bwidth, 0,
368 self->width - (ob_rr_theme->grip_width + self->bwidth) * 2,
369 ob_rr_theme->handle_height);
372 XUnmapWindow(ob_display
, self
->handle
);
374 /* move and resize the plate */
375 XMoveResizeWindow(ob_display
, self
->plate
,
376 self
->innersize
.left
- self
->cbwidth_x
,
377 self
->innersize
.top
- self
->cbwidth_y
,
378 self
->client
->area
.width
+ self
->cbwidth_x
* 2,
379 self
->client
->area
.height
+ self
->cbwidth_y
* 2);
380 /* when the client has StaticGravity, it likes to move around. */
381 XMoveWindow(ob_display
, self
->client
->window
,
382 self
->cbwidth_x
, self
->cbwidth_y
);
385 STRUT_SET(self
->size
,
386 self
->innersize
.left
+ self
->bwidth
,
387 self
->innersize
.top
+ self
->bwidth
,
388 self
->innersize
.right
+ self
->bwidth
,
389 self
->innersize
.bottom
+ self
->bwidth
);
392 /* shading can change without being moved or resized */
393 RECT_SET_SIZE(self
->area
,
394 self
->client
->area
.width
+
395 self
->size
.left
+ self
->size
.right
,
396 (self
->client
->shaded
?
397 ob_rr_theme
->title_height
+ self
->rbwidth
* 2:
398 self
->client
->area
.height
+
399 self
->size
.top
+ self
->size
.bottom
));
402 /* find the new coordinates, done after setting the frame.size, for
403 frame_client_gravity. */
404 self
->area
.x
= self
->client
->area
.x
;
405 self
->area
.y
= self
->client
->area
.y
;
406 frame_client_gravity(self
, &self
->area
.x
, &self
->area
.y
);
410 /* move and resize the top level frame.
411 shading can change without being moved or resized */
412 XMoveResizeWindow(ob_display
, self
->window
,
413 self
->area
.x
, self
->area
.y
,
414 self
->area
.width
- self
->bwidth
* 2,
415 self
->area
.height
- self
->bwidth
* 2);
418 framerender_frame(self
);
420 frame_adjust_shape(self
);
423 if (!STRUT_EQUAL(self
->size
, oldsize
)) {
425 vals
[0] = self
->size
.left
;
426 vals
[1] = self
->size
.right
;
427 vals
[2] = self
->size
.top
;
428 vals
[3] = self
->size
.bottom
;
429 PROP_SETA32(self
->client
->window
, kde_net_wm_frame_strut
,
433 /* if this occurs while we are focus cycling, the indicator needs to
435 if (focus_cycle_target
== self
->client
)
436 focus_cycle_draw_indicator();
440 void frame_adjust_state(ObFrame
*self
)
442 framerender_frame(self
);
445 void frame_adjust_focus(ObFrame
*self
, gboolean hilite
)
447 self
->focused
= hilite
;
448 framerender_frame(self
);
451 void frame_adjust_title(ObFrame
*self
)
453 framerender_frame(self
);
456 void frame_adjust_icon(ObFrame
*self
)
458 framerender_frame(self
);
461 void frame_grab_client(ObFrame
*self
, ObClient
*client
)
463 self
->client
= client
;
465 /* reparent the client to the frame */
466 XReparentWindow(ob_display
, client
->window
, self
->plate
, 0, 0);
468 When reparenting the client window, it is usually not mapped yet, since
469 this occurs from a MapRequest. However, in the case where Openbox is
470 starting up, the window is already mapped, so we'll see unmap events for
471 it. There are 2 unmap events generated that we see, one with the 'event'
472 member set the root window, and one set to the client, but both get
473 handled and need to be ignored.
475 if (ob_state() == OB_STATE_STARTING
)
476 client
->ignore_unmaps
+= 2;
478 /* select the event mask on the client's parent (to receive config/map
479 req's) the ButtonPress is to catch clicks on the client border */
480 XSelectInput(ob_display
, self
->plate
, PLATE_EVENTMASK
);
482 /* map the client so it maps when the frame does */
483 XMapWindow(ob_display
, client
->window
);
485 frame_adjust_area(self
, TRUE
, TRUE
, FALSE
);
487 /* set all the windows for the frame in the window_map */
488 g_hash_table_insert(window_map
, &self
->window
, client
);
489 g_hash_table_insert(window_map
, &self
->plate
, client
);
490 g_hash_table_insert(window_map
, &self
->title
, client
);
491 g_hash_table_insert(window_map
, &self
->label
, client
);
492 g_hash_table_insert(window_map
, &self
->max
, client
);
493 g_hash_table_insert(window_map
, &self
->close
, client
);
494 g_hash_table_insert(window_map
, &self
->desk
, client
);
495 g_hash_table_insert(window_map
, &self
->shade
, client
);
496 g_hash_table_insert(window_map
, &self
->icon
, client
);
497 g_hash_table_insert(window_map
, &self
->iconify
, client
);
498 g_hash_table_insert(window_map
, &self
->handle
, client
);
499 g_hash_table_insert(window_map
, &self
->lgrip
, client
);
500 g_hash_table_insert(window_map
, &self
->rgrip
, client
);
501 g_hash_table_insert(window_map
, &self
->tlresize
, client
);
502 g_hash_table_insert(window_map
, &self
->trresize
, client
);
505 void frame_release_client(ObFrame
*self
, ObClient
*client
)
508 gboolean reparent
= TRUE
;
510 g_assert(self
->client
== client
);
512 /* check if the app has already reparented its window away */
513 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
514 ReparentNotify
, &ev
))
516 /* This check makes sure we don't catch our own reparent action to
517 our frame window. This doesn't count as the app reparenting itself
520 Reparent events that are generated by us are just discarded here.
521 They are of no consequence to us anyhow.
523 if (ev
.xreparent
.parent
!= self
->plate
) {
525 XPutBackEvent(ob_display
, &ev
);
531 /* according to the ICCCM - if the client doesn't reparent itself,
532 then we will reparent the window to root for them */
533 XReparentWindow(ob_display
, client
->window
,
534 RootWindow(ob_display
, ob_screen
),
539 /* remove all the windows for the frame from the window_map */
540 g_hash_table_remove(window_map
, &self
->window
);
541 g_hash_table_remove(window_map
, &self
->plate
);
542 g_hash_table_remove(window_map
, &self
->title
);
543 g_hash_table_remove(window_map
, &self
->label
);
544 g_hash_table_remove(window_map
, &self
->max
);
545 g_hash_table_remove(window_map
, &self
->close
);
546 g_hash_table_remove(window_map
, &self
->desk
);
547 g_hash_table_remove(window_map
, &self
->shade
);
548 g_hash_table_remove(window_map
, &self
->icon
);
549 g_hash_table_remove(window_map
, &self
->iconify
);
550 g_hash_table_remove(window_map
, &self
->handle
);
551 g_hash_table_remove(window_map
, &self
->lgrip
);
552 g_hash_table_remove(window_map
, &self
->rgrip
);
553 g_hash_table_remove(window_map
, &self
->tlresize
);
554 g_hash_table_remove(window_map
, &self
->trresize
);
556 ob_main_loop_timeout_remove_data(ob_main_loop
, flash_timeout
, self
);
561 static void layout_title(ObFrame
*self
)
565 gboolean n
, d
, i
, l
, m
, c
, s
;
567 n
= d
= i
= l
= m
= c
= s
= FALSE
;
569 /* figure out whats being shown, and the width of the label */
570 self
->label_width
= self
->width
- (ob_rr_theme
->padding
+ 1) * 2;
571 for (lc
= config_title_layout
; *lc
!= '\0'; ++lc
) {
574 if (n
) { *lc
= ' '; break; } /* rm duplicates */
576 self
->label_width
-= (ob_rr_theme
->button_size
+ 2 +
577 ob_rr_theme
->padding
+ 1);
580 if (d
) { *lc
= ' '; break; } /* rm duplicates */
582 self
->label_width
-= (ob_rr_theme
->button_size
+
583 ob_rr_theme
->padding
+ 1);
586 if (s
) { *lc
= ' '; break; } /* rm duplicates */
588 self
->label_width
-= (ob_rr_theme
->button_size
+
589 ob_rr_theme
->padding
+ 1);
592 if (i
) { *lc
= ' '; break; } /* rm duplicates */
594 self
->label_width
-= (ob_rr_theme
->button_size
+
595 ob_rr_theme
->padding
+ 1);
598 if (l
) { *lc
= ' '; break; } /* rm duplicates */
602 if (m
) { *lc
= ' '; break; } /* rm duplicates */
604 self
->label_width
-= (ob_rr_theme
->button_size
+
605 ob_rr_theme
->padding
+ 1);
608 if (c
) { *lc
= ' '; break; } /* rm duplicates */
610 self
->label_width
-= (ob_rr_theme
->button_size
+
611 ob_rr_theme
->padding
+ 1);
615 if (self
->label_width
< 1) self
->label_width
= 1;
617 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
618 ob_rr_theme
->label_height
);
620 if (!n
) XUnmapWindow(ob_display
, self
->icon
);
621 if (!d
) XUnmapWindow(ob_display
, self
->desk
);
622 if (!s
) XUnmapWindow(ob_display
, self
->shade
);
623 if (!i
) XUnmapWindow(ob_display
, self
->iconify
);
624 if (!l
) XUnmapWindow(ob_display
, self
->label
);
625 if (!m
) XUnmapWindow(ob_display
, self
->max
);
626 if (!c
) XUnmapWindow(ob_display
, self
->close
);
628 x
= ob_rr_theme
->padding
+ 1;
629 for (lc
= config_title_layout
; *lc
!= '\0'; ++lc
) {
634 XMapWindow(ob_display
, self
->icon
);
635 XMoveWindow(ob_display
, self
->icon
, x
, ob_rr_theme
->padding
);
636 x
+= ob_rr_theme
->button_size
+ 2 + ob_rr_theme
->padding
+ 1;
641 XMapWindow(ob_display
, self
->desk
);
642 XMoveWindow(ob_display
, self
->desk
, x
, ob_rr_theme
->padding
+ 1);
643 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->padding
+ 1;
648 XMapWindow(ob_display
, self
->shade
);
649 XMoveWindow(ob_display
, self
->shade
, x
, ob_rr_theme
->padding
+ 1);
650 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->padding
+ 1;
655 XMapWindow(ob_display
, self
->iconify
);
656 XMoveWindow(ob_display
,self
->iconify
, x
, ob_rr_theme
->padding
+ 1);
657 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->padding
+ 1;
662 XMapWindow(ob_display
, self
->label
);
663 XMoveWindow(ob_display
, self
->label
, x
, ob_rr_theme
->padding
);
664 x
+= self
->label_width
+ ob_rr_theme
->padding
+ 1;
669 XMapWindow(ob_display
, self
->max
);
670 XMoveWindow(ob_display
, self
->max
, x
, ob_rr_theme
->padding
+ 1);
671 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->padding
+ 1;
676 XMapWindow(ob_display
, self
->close
);
677 XMoveWindow(ob_display
, self
->close
, x
, ob_rr_theme
->padding
+ 1);
678 x
+= ob_rr_theme
->button_size
+ ob_rr_theme
->padding
+ 1;
684 ObFrameContext
frame_context_from_string(const gchar
*name
)
686 if (!g_ascii_strcasecmp("Desktop", name
))
687 return OB_FRAME_CONTEXT_DESKTOP
;
688 else if (!g_ascii_strcasecmp("Client", name
))
689 return OB_FRAME_CONTEXT_CLIENT
;
690 else if (!g_ascii_strcasecmp("Titlebar", name
))
691 return OB_FRAME_CONTEXT_TITLEBAR
;
692 else if (!g_ascii_strcasecmp("Handle", name
))
693 return OB_FRAME_CONTEXT_HANDLE
;
694 else if (!g_ascii_strcasecmp("Frame", name
))
695 return OB_FRAME_CONTEXT_FRAME
;
696 else if (!g_ascii_strcasecmp("TLCorner", name
))
697 return OB_FRAME_CONTEXT_TLCORNER
;
698 else if (!g_ascii_strcasecmp("TRCorner", name
))
699 return OB_FRAME_CONTEXT_TRCORNER
;
700 else if (!g_ascii_strcasecmp("BLCorner", name
))
701 return OB_FRAME_CONTEXT_BLCORNER
;
702 else if (!g_ascii_strcasecmp("BRCorner", name
))
703 return OB_FRAME_CONTEXT_BRCORNER
;
704 else if (!g_ascii_strcasecmp("Maximize", name
))
705 return OB_FRAME_CONTEXT_MAXIMIZE
;
706 else if (!g_ascii_strcasecmp("AllDesktops", name
))
707 return OB_FRAME_CONTEXT_ALLDESKTOPS
;
708 else if (!g_ascii_strcasecmp("Shade", name
))
709 return OB_FRAME_CONTEXT_SHADE
;
710 else if (!g_ascii_strcasecmp("Iconify", name
))
711 return OB_FRAME_CONTEXT_ICONIFY
;
712 else if (!g_ascii_strcasecmp("Icon", name
))
713 return OB_FRAME_CONTEXT_ICON
;
714 else if (!g_ascii_strcasecmp("Close", name
))
715 return OB_FRAME_CONTEXT_CLOSE
;
716 else if (!g_ascii_strcasecmp("MoveResize", name
))
717 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
718 return OB_FRAME_CONTEXT_NONE
;
721 ObFrameContext
frame_context(ObClient
*client
, Window win
)
725 if (moveresize_in_progress
)
726 return OB_FRAME_CONTEXT_MOVE_RESIZE
;
728 if (win
== RootWindow(ob_display
, ob_screen
))
729 return OB_FRAME_CONTEXT_DESKTOP
;
730 if (client
== NULL
) return OB_FRAME_CONTEXT_NONE
;
731 if (win
== client
->window
) {
732 /* conceptually, this is the desktop, as far as users are
734 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
735 return OB_FRAME_CONTEXT_DESKTOP
;
736 return OB_FRAME_CONTEXT_CLIENT
;
739 self
= client
->frame
;
740 if (win
== self
->plate
) {
741 /* conceptually, this is the desktop, as far as users are
743 if (client
->type
== OB_CLIENT_TYPE_DESKTOP
)
744 return OB_FRAME_CONTEXT_DESKTOP
;
745 return OB_FRAME_CONTEXT_CLIENT
;
748 if (win
== self
->window
) return OB_FRAME_CONTEXT_FRAME
;
749 if (win
== self
->title
) return OB_FRAME_CONTEXT_TITLEBAR
;
750 if (win
== self
->label
) return OB_FRAME_CONTEXT_TITLEBAR
;
751 if (win
== self
->handle
) return OB_FRAME_CONTEXT_HANDLE
;
752 if (win
== self
->lgrip
) return OB_FRAME_CONTEXT_BLCORNER
;
753 if (win
== self
->rgrip
) return OB_FRAME_CONTEXT_BRCORNER
;
754 if (win
== self
->tlresize
) return OB_FRAME_CONTEXT_TLCORNER
;
755 if (win
== self
->trresize
) return OB_FRAME_CONTEXT_TRCORNER
;
756 if (win
== self
->max
) return OB_FRAME_CONTEXT_MAXIMIZE
;
757 if (win
== self
->iconify
) return OB_FRAME_CONTEXT_ICONIFY
;
758 if (win
== self
->close
) return OB_FRAME_CONTEXT_CLOSE
;
759 if (win
== self
->icon
) return OB_FRAME_CONTEXT_ICON
;
760 if (win
== self
->desk
) return OB_FRAME_CONTEXT_ALLDESKTOPS
;
761 if (win
== self
->shade
) return OB_FRAME_CONTEXT_SHADE
;
763 return OB_FRAME_CONTEXT_NONE
;
766 void frame_client_gravity(ObFrame
*self
, gint
*x
, gint
*y
)
769 switch (self
->client
->gravity
) {
771 case NorthWestGravity
:
772 case SouthWestGravity
:
779 *x
-= (self
->size
.left
+ self
->size
.right
) / 2;
782 case NorthEastGravity
:
783 case SouthEastGravity
:
785 *x
-= self
->size
.left
+ self
->size
.right
;
790 *x
-= self
->size
.left
;
795 switch (self
->client
->gravity
) {
797 case NorthWestGravity
:
798 case NorthEastGravity
:
805 *y
-= (self
->size
.top
+ self
->size
.bottom
) / 2;
808 case SouthWestGravity
:
809 case SouthEastGravity
:
811 *y
-= self
->size
.top
+ self
->size
.bottom
;
816 *y
-= self
->size
.top
;
821 void frame_frame_gravity(ObFrame
*self
, gint
*x
, gint
*y
)
824 switch (self
->client
->gravity
) {
826 case NorthWestGravity
:
828 case SouthWestGravity
:
833 *x
+= (self
->size
.left
+ self
->size
.right
) / 2;
835 case NorthEastGravity
:
837 case SouthEastGravity
:
838 *x
+= self
->size
.left
+ self
->size
.right
;
842 *x
+= self
->size
.left
;
847 switch (self
->client
->gravity
) {
849 case NorthWestGravity
:
851 case NorthEastGravity
:
856 *y
+= (self
->size
.top
+ self
->size
.bottom
) / 2;
858 case SouthWestGravity
:
860 case SouthEastGravity
:
861 *y
+= self
->size
.top
+ self
->size
.bottom
;
865 *y
+= self
->size
.top
;
870 static void flash_done(gpointer data
)
872 ObFrame
*self
= data
;
874 if (self
->focused
!= self
->flash_on
)
875 frame_adjust_focus(self
, self
->focused
);
878 static gboolean
flash_timeout(gpointer data
)
880 ObFrame
*self
= data
;
883 g_get_current_time(&now
);
884 if (now
.tv_sec
> self
->flash_end
.tv_sec
||
885 (now
.tv_sec
== self
->flash_end
.tv_sec
&&
886 now
.tv_usec
>= self
->flash_end
.tv_usec
))
887 self
->flashing
= FALSE
;
890 return FALSE
; /* we are done */
892 self
->flash_on
= !self
->flash_on
;
893 if (!self
->focused
) {
894 frame_adjust_focus(self
, self
->flash_on
);
895 self
->focused
= FALSE
;
898 return TRUE
; /* go again */
901 void frame_flash_start(ObFrame
*self
)
903 self
->flash_on
= self
->focused
;
906 ob_main_loop_timeout_add(ob_main_loop
,
907 G_USEC_PER_SEC
* 0.6,
911 g_get_current_time(&self
->flash_end
);
912 g_time_val_add(&self
->flash_end
, G_USEC_PER_SEC
* 5);
914 self
->flashing
= TRUE
;
917 void frame_flash_stop(ObFrame
*self
)
919 self
->flashing
= FALSE
;