2 #include "../../kernel/openbox.h"
3 #include "../../kernel/screen.h"
4 #include "../../kernel/extensions.h"
5 #include "../../kernel/themerc.h"
6 #include "../../kernel/frame.h"
7 #include "../../render/render.h"
8 #include "../../render/color.h"
9 #include "../../render/font.h"
14 #define TITLE_HEIGHT (s_winfont_height + s_bevel * 2)
15 #define LABEL_HEIGHT (s_winfont_height)
16 #define HANDLE_Y(f) (f->innersize.top + f->frame.client->area.height + \
18 #define BUTTON_SIZE (LABEL_HEIGHT - 2)
19 #define GRIP_WIDTH (BUTTON_SIZE * 2)
20 #define HANDLE_WIDTH(f) (f->width - (GRIP_WIDTH + f->bwidth) * 2)
22 #define PLATE_EVENTMASK (SubstructureRedirectMask | ButtonPressMask)
23 #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask)
25 /* style settings - geometry */
30 /* style settings - colors */
32 color_rgb
*s_cb_focused_color
;
33 color_rgb
*s_cb_unfocused_color
;
34 color_rgb
*s_title_focused_color
;
35 color_rgb
*s_title_unfocused_color
;
36 /* style settings - fonts */
39 int s_winfont_shadow_offset
;
42 /* global appearances */
43 Appearance
*a_focused_unpressed_max
;
44 Appearance
*a_focused_pressed_max
;
45 Appearance
*a_unfocused_unpressed_max
;
46 Appearance
*a_unfocused_pressed_max
;
47 Appearance
*a_focused_unpressed_close
;
48 Appearance
*a_focused_pressed_close
;
49 Appearance
*a_unfocused_unpressed_close
;
50 Appearance
*a_unfocused_pressed_close
;
51 Appearance
*a_focused_unpressed_desk
;
52 Appearance
*a_focused_pressed_desk
;
53 Appearance
*a_unfocused_unpressed_desk
;
54 Appearance
*a_unfocused_pressed_desk
;
55 Appearance
*a_focused_unpressed_iconify
;
56 Appearance
*a_focused_pressed_iconify
;
57 Appearance
*a_unfocused_unpressed_iconify
;
58 Appearance
*a_unfocused_pressed_iconify
;
59 Appearance
*a_focused_grip
;
60 Appearance
*a_unfocused_grip
;
61 Appearance
*a_focused_title
;
62 Appearance
*a_unfocused_title
;
63 Appearance
*a_focused_label
;
64 Appearance
*a_unfocused_label
;
65 Appearance
*a_icon
; /* always parentrelative, so no focused/unfocused */
66 Appearance
*a_focused_handle
;
67 Appearance
*a_unfocused_handle
;
69 typedef struct ObFrame
{
83 Appearance
*a_unfocused_title
;
84 Appearance
*a_focused_title
;
85 Appearance
*a_unfocused_label
;
86 Appearance
*a_focused_label
;
88 Appearance
*a_unfocused_handle
;
89 Appearance
*a_focused_handle
;
95 int width
; /* title and handle */
97 int icon_x
; /* x-position of the window icon button */
98 int label_x
; /* x-position of the window title */
99 int iconify_x
; /* x-position of the window iconify button */
100 int desk_x
; /* x-position of the window all-desktops button */
101 int max_x
; /* x-position of the window maximize button */
102 int close_x
; /* x-position of the window close button */
103 int bwidth
; /* border width */
104 int cbwidth
; /* client border width */
107 gboolean close_press
;
109 gboolean iconify_press
;
112 static void layout_title(ObFrame
*self
);
113 static void render(ObFrame
*self
);
114 static void render_label(ObFrame
*self
);
115 static void render_max(ObFrame
*self
);
116 static void render_icon(ObFrame
*self
);
117 static void render_iconify(ObFrame
*self
);
118 static void render_desk(ObFrame
*self
);
119 static void render_close(ObFrame
*self
);
123 g_quark_from_string("none");
124 g_quark_from_string("root");
125 g_quark_from_string("client");
126 g_quark_from_string("titlebar");
127 g_quark_from_string("handle");
128 g_quark_from_string("frame");
129 g_quark_from_string("blcorner");
130 g_quark_from_string("brcorner");
131 g_quark_from_string("maximize");
132 g_quark_from_string("alldesktops");
133 g_quark_from_string("iconify");
134 g_quark_from_string("icon");
135 g_quark_from_string("close");
137 s_b_color
= s_cb_unfocused_color
= s_cb_focused_color
= NULL
;
140 a_focused_unpressed_max
= appearance_new(Surface_Planar
, 0);//1);
141 a_focused_pressed_max
= appearance_new(Surface_Planar
, 0);//1);
142 a_unfocused_unpressed_max
= appearance_new(Surface_Planar
, 0);//1);
143 a_unfocused_pressed_max
= appearance_new(Surface_Planar
, 0);//1);
144 a_focused_unpressed_close
= NULL
;
145 a_focused_pressed_close
= NULL
;
146 a_unfocused_unpressed_close
= NULL
;
147 a_unfocused_pressed_close
= NULL
;
148 a_focused_unpressed_desk
= NULL
;
149 a_focused_pressed_desk
= NULL
;
150 a_unfocused_unpressed_desk
= NULL
;
151 a_unfocused_pressed_desk
= NULL
;
152 a_focused_unpressed_iconify
= NULL
;
153 a_focused_pressed_iconify
= NULL
;
154 a_unfocused_unpressed_iconify
= NULL
;
155 a_unfocused_pressed_iconify
= NULL
;
156 a_focused_grip
= appearance_new(Surface_Planar
, 0);
157 a_unfocused_grip
= appearance_new(Surface_Planar
, 0);
158 a_focused_title
= appearance_new(Surface_Planar
, 0);
159 a_unfocused_title
= appearance_new(Surface_Planar
, 0);
160 a_focused_label
= appearance_new(Surface_Planar
, 1);
161 a_unfocused_label
= appearance_new(Surface_Planar
, 1);
162 a_icon
= appearance_new(Surface_Planar
, 0);//1);
163 a_focused_handle
= appearance_new(Surface_Planar
, 0);
164 a_unfocused_handle
= appearance_new(Surface_Planar
, 0);
166 a_focused_label
->texture
[0].type
= Text
;
167 a_focused_label
->texture
[0].data
.text
.font
= s_winfont
;
168 a_focused_label
->texture
[0].data
.text
.shadow
= s_winfont_shadow
;
169 a_focused_label
->texture
[0].data
.text
.offset
= s_winfont_shadow_offset
;
170 a_focused_label
->texture
[0].data
.text
.color
= s_title_focused_color
;
172 a_unfocused_label
->texture
[0].type
= Text
;
173 a_unfocused_label
->texture
[0].data
.text
.font
= s_winfont
;
174 a_unfocused_label
->texture
[0].data
.text
.shadow
= s_winfont_shadow
;
175 a_unfocused_label
->texture
[0].data
.text
.offset
= s_winfont_shadow_offset
;
176 a_unfocused_label
->texture
[0].data
.text
.color
= s_title_unfocused_color
;
183 if (s_b_color
!= NULL
) color_free(s_b_color
);
184 if (s_cb_unfocused_color
!= NULL
) color_free(s_cb_unfocused_color
);
185 if (s_cb_focused_color
!= NULL
) color_free(s_cb_focused_color
);
187 if (s_winfont
!= NULL
) font_close(s_winfont
);
189 appearance_free(a_focused_unpressed_max
);
190 appearance_free(a_focused_pressed_max
);
191 appearance_free(a_unfocused_unpressed_max
);
192 appearance_free(a_unfocused_pressed_max
);
193 if (a_focused_unpressed_close
!= NULL
)
194 appearance_free(a_focused_unpressed_close
);
195 if (a_focused_pressed_close
!= NULL
)
196 appearance_free(a_focused_pressed_close
);
197 if (a_unfocused_unpressed_close
!= NULL
)
198 appearance_free(a_unfocused_unpressed_close
);
199 if (a_unfocused_pressed_close
!= NULL
)
200 appearance_free(a_unfocused_pressed_close
);
201 if (a_focused_unpressed_desk
!= NULL
)
202 appearance_free(a_focused_unpressed_desk
);
203 if (a_focused_pressed_desk
!= NULL
)
204 appearance_free(a_focused_pressed_desk
);
205 if (a_unfocused_unpressed_desk
!= NULL
)
206 appearance_free(a_unfocused_unpressed_desk
);
207 if (a_unfocused_pressed_desk
!= NULL
)
208 appearance_free(a_unfocused_pressed_desk
);
209 if (a_focused_unpressed_iconify
!= NULL
)
210 appearance_free(a_focused_unpressed_iconify
);
211 if (a_focused_pressed_iconify
!= NULL
)
212 appearance_free(a_focused_pressed_iconify
);
213 if (a_unfocused_unpressed_iconify
!= NULL
)
214 appearance_free(a_unfocused_unpressed_iconify
);
215 if (a_unfocused_pressed_iconify
!= NULL
)
216 appearance_free(a_unfocused_pressed_iconify
);
217 appearance_free(a_focused_grip
);
218 appearance_free(a_unfocused_grip
);
219 appearance_free(a_focused_title
);
220 appearance_free(a_unfocused_title
);
221 appearance_free(a_focused_label
);
222 appearance_free(a_unfocused_label
);
223 appearance_free(a_icon
);
224 appearance_free(a_focused_handle
);
225 appearance_free(a_unfocused_handle
);
228 static Window
createWindow(Window parent
, unsigned long mask
,
229 XSetWindowAttributes
*attrib
)
231 /* XXX DONT USE THE DEFAULT SHIT */
232 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
233 DefaultDepth(ob_display
, ob_screen
), InputOutput
,
234 DefaultVisual(ob_display
, ob_screen
),
241 XSetWindowAttributes attrib
;
245 self
= g_new(ObFrame
, 1);
247 self
->frame
.visible
= FALSE
;
249 /* create all of the decor windows */
250 mask
= CWOverrideRedirect
| CWEventMask
;
251 attrib
.event_mask
= FRAME_EVENTMASK
;
252 attrib
.override_redirect
= TRUE
;
253 self
->frame
.window
= createWindow(ob_root
, mask
, &attrib
);
256 self
->frame
.plate
= createWindow(self
->frame
.window
, mask
, &attrib
);
259 attrib
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
|
260 ButtonMotionMask
| ExposureMask
);
261 self
->title
= createWindow(self
->frame
.window
, mask
, &attrib
);
262 self
->label
= createWindow(self
->title
, mask
, &attrib
);
263 self
->max
= createWindow(self
->title
, mask
, &attrib
);
264 self
->close
= createWindow(self
->title
, mask
, &attrib
);
265 self
->desk
= createWindow(self
->title
, mask
, &attrib
);
266 self
->icon
= createWindow(self
->title
, mask
, &attrib
);
267 self
->iconify
= createWindow(self
->title
, mask
, &attrib
);
268 self
->handle
= createWindow(self
->frame
.window
, mask
, &attrib
);
270 attrib
.cursor
= ob_cursors
.ll_angle
;
271 self
->lgrip
= createWindow(self
->handle
, mask
, &attrib
);
272 attrib
.cursor
= ob_cursors
.lr_angle
;
273 self
->rgrip
= createWindow(self
->handle
, mask
, &attrib
);
275 /* the other stuff is shown based on decor settings */
276 XMapWindow(ob_display
, self
->frame
.plate
);
277 XMapWindow(ob_display
, self
->lgrip
);
278 XMapWindow(ob_display
, self
->rgrip
);
279 XMapWindow(ob_display
, self
->label
);
281 /* set colors/appearance/sizes for stuff that doesn't change */
282 XSetWindowBorder(ob_display
, self
->frame
.window
, s_b_color
->pixel
);
283 XSetWindowBorder(ob_display
, self
->label
, s_b_color
->pixel
);
284 XSetWindowBorder(ob_display
, self
->rgrip
, s_b_color
->pixel
);
285 XSetWindowBorder(ob_display
, self
->lgrip
, s_b_color
->pixel
);
287 XResizeWindow(ob_display
, self
->max
, BUTTON_SIZE
, BUTTON_SIZE
);
288 XResizeWindow(ob_display
, self
->iconify
, BUTTON_SIZE
, BUTTON_SIZE
);
289 XResizeWindow(ob_display
, self
->icon
, BUTTON_SIZE
, BUTTON_SIZE
);
290 XResizeWindow(ob_display
, self
->close
, BUTTON_SIZE
, BUTTON_SIZE
);
291 XResizeWindow(ob_display
, self
->desk
, BUTTON_SIZE
, BUTTON_SIZE
);
292 XResizeWindow(ob_display
, self
->lgrip
, GRIP_WIDTH
, s_handle_height
);
293 XResizeWindow(ob_display
, self
->rgrip
, GRIP_WIDTH
, s_handle_height
);
295 /* set up the dynamic appearances */
296 self
->a_unfocused_title
= appearance_copy(a_unfocused_title
);
297 self
->a_focused_title
= appearance_copy(a_focused_title
);
298 self
->a_unfocused_label
= appearance_copy(a_unfocused_label
);
299 self
->a_focused_label
= appearance_copy(a_focused_label
);
300 self
->a_unfocused_handle
= appearance_copy(a_unfocused_handle
);
301 self
->a_focused_handle
= appearance_copy(a_focused_handle
);
302 self
->a_icon
= appearance_copy(a_icon
);
304 self
->max_press
= self
->close_press
= self
->desk_press
=
305 self
->iconify_press
= FALSE
;
310 static void frame_free(ObFrame
*self
)
312 appearance_free(self
->a_unfocused_title
);
313 appearance_free(self
->a_focused_title
);
314 appearance_free(self
->a_unfocused_label
);
315 appearance_free(self
->a_focused_label
);
316 appearance_free(self
->a_unfocused_handle
);
317 appearance_free(self
->a_focused_handle
);
318 appearance_free(self
->a_icon
);
320 XDestroyWindow(ob_display
, self
->frame
.window
);
325 void frame_show(ObFrame
*self
)
327 if (!self
->frame
.visible
) {
328 self
->frame
.visible
= TRUE
;
329 XMapWindow(ob_display
, self
->frame
.window
);
333 void frame_hide(ObFrame
*self
)
335 if (self
->frame
.visible
) {
336 self
->frame
.visible
= FALSE
;
337 self
->frame
.client
->ignore_unmaps
++;
338 XUnmapWindow(ob_display
, self
->frame
.window
);
342 void frame_adjust_shape(ObFrame
*self
)
348 if (!self
->frame
.client
->shaped
) {
349 /* clear the shape on the frame window */
350 XShapeCombineMask(ob_display
, self
->frame
.window
, ShapeBounding
,
351 self
->innersize
.left
,
355 /* make the frame's shape match the clients */
356 XShapeCombineShape(ob_display
, self
->frame
.window
, ShapeBounding
,
357 self
->innersize
.left
,
359 self
->frame
.client
->window
,
360 ShapeBounding
, ShapeSet
);
363 if (self
->frame
.client
->decorations
& Decor_Titlebar
) {
364 xrect
[0].x
= -s_bevel
;
365 xrect
[0].y
= -s_bevel
;
366 xrect
[0].width
= self
->width
+ self
->bwidth
* 2;
367 xrect
[0].height
= TITLE_HEIGHT
+
372 if (self
->frame
.client
->decorations
& Decor_Handle
) {
373 xrect
[1].x
= -s_bevel
;
374 xrect
[1].y
= HANDLE_Y(self
);
375 xrect
[1].width
= self
->width
+ self
->bwidth
* 2;
376 xrect
[1].height
= s_handle_height
+
381 XShapeCombineRectangles(ob_display
, self
->frame
.window
,
382 ShapeBounding
, 0, 0, xrect
, num
,
383 ShapeUnion
, Unsorted
);
388 void frame_adjust_size(ObFrame
*self
)
390 if (self
->frame
.client
->decorations
& Decor_Border
) {
391 self
->bwidth
= s_bwidth
;
392 self
->cbwidth
= s_cbwidth
;
394 self
->bwidth
= self
->cbwidth
= 0;
396 STRUT_SET(self
->innersize
, self
->cbwidth
, self
->cbwidth
,
397 self
->cbwidth
, self
->cbwidth
);
398 self
->width
= self
->frame
.client
->area
.width
+ self
->cbwidth
* 2;
399 g_assert(self
->width
> 0);
401 /* set border widths */
402 XSetWindowBorderWidth(ob_display
, self
->frame
.plate
, self
->cbwidth
);
403 XSetWindowBorderWidth(ob_display
, self
->frame
.window
, self
->bwidth
);
404 XSetWindowBorderWidth(ob_display
, self
->title
, self
->bwidth
);
405 XSetWindowBorderWidth(ob_display
, self
->handle
, self
->bwidth
);
406 XSetWindowBorderWidth(ob_display
, self
->lgrip
, self
->bwidth
);
407 XSetWindowBorderWidth(ob_display
, self
->rgrip
, self
->bwidth
);
409 /* position/size and map/unmap all the windows */
411 if (self
->frame
.client
->decorations
& Decor_Titlebar
) {
412 XMoveResizeWindow(ob_display
, self
->title
,
413 -self
->bwidth
, -self
->bwidth
,
414 self
->width
, TITLE_HEIGHT
);
415 self
->innersize
.top
+= TITLE_HEIGHT
+ self
->bwidth
;
416 XMapWindow(ob_display
, self
->title
);
418 /* layout the title bar elements */
421 XUnmapWindow(ob_display
, self
->title
);
422 /* make all the titlebar stuff not render */
423 self
->frame
.client
->decorations
&= ~(Decor_Icon
| Decor_Iconify
|
424 Decor_Maximize
| Decor_Close
|
428 if (self
->frame
.client
->decorations
& Decor_Handle
) {
429 XMoveResizeWindow(ob_display
, self
->handle
,
430 -self
->bwidth
, HANDLE_Y(self
),
431 self
->width
, s_handle_height
);
432 XMoveWindow(ob_display
, self
->lgrip
,
433 -self
->bwidth
, -self
->bwidth
);
434 XMoveWindow(ob_display
, self
->rgrip
,
435 -self
->bwidth
+ self
->width
-
436 GRIP_WIDTH
, -self
->bwidth
);
437 self
->innersize
.bottom
+= s_handle_height
+
439 XMapWindow(ob_display
, self
->handle
);
441 XUnmapWindow(ob_display
, self
->handle
);
443 XResizeWindow(ob_display
, self
->frame
.window
, self
->width
,
444 (self
->frame
.client
->shaded
? TITLE_HEIGHT
:
445 self
->innersize
.top
+ self
->innersize
.bottom
+
446 self
->frame
.client
->area
.height
));
448 /* do this in two steps because clients whose gravity is set to
449 'Static' don't end up getting moved at all with an XMoveResizeWindow */
450 XMoveWindow(ob_display
, self
->frame
.plate
,
451 self
->innersize
.left
- self
->cbwidth
,
452 self
->innersize
.top
- self
->cbwidth
);
453 XResizeWindow(ob_display
, self
->frame
.plate
,
454 self
->frame
.client
->area
.width
,
455 self
->frame
.client
->area
.height
);
457 STRUT_SET(self
->frame
.size
,
458 self
->innersize
.left
+ self
->bwidth
,
459 self
->innersize
.top
+ self
->bwidth
,
460 self
->innersize
.right
+ self
->bwidth
,
461 self
->innersize
.bottom
+ self
->bwidth
);
463 RECT_SET_SIZE(self
->frame
.area
,
464 self
->frame
.client
->area
.width
+
465 self
->frame
.size
.left
+ self
->frame
.size
.right
,
466 self
->frame
.client
->area
.height
+
467 self
->frame
.size
.top
+ self
->frame
.size
.bottom
);
471 frame_adjust_shape(self
);
474 void frame_adjust_position(ObFrame
*self
)
476 self
->frame
.area
.x
= self
->frame
.client
->area
.x
;
477 self
->frame
.area
.y
= self
->frame
.client
->area
.y
;
478 frame_client_gravity((Frame
*)self
,
479 &self
->frame
.area
.x
, &self
->frame
.area
.y
);
480 XMoveWindow(ob_display
, self
->frame
.window
,
481 self
->frame
.area
.x
, self
->frame
.area
.y
);
484 void frame_adjust_state(ObFrame
*self
)
490 void frame_adjust_focus(ObFrame
*self
)
495 void frame_adjust_title(ObFrame
*self
)
500 void frame_adjust_icon(ObFrame
*self
)
505 void frame_grab_client(ObFrame
*self
, Client
*client
)
507 self
->frame
.client
= client
;
509 /* reparent the client to the frame */
510 XReparentWindow(ob_display
, client
->window
, self
->frame
.plate
, 0, 0);
512 When reparenting the client window, it is usually not mapped yet, since
513 this occurs from a MapRequest. However, in the case where Openbox is
514 starting up, the window is already mapped, so we'll see unmap events for
515 it. There are 2 unmap events generated that we see, one with the 'event'
516 member set the root window, and one set to the client, but both get
517 handled and need to be ignored.
519 if (ob_state
== State_Starting
)
520 client
->ignore_unmaps
+= 2;
522 /* select the event mask on the client's parent (to receive config/map
523 req's) the ButtonPress is to catch clicks on the client border */
524 XSelectInput(ob_display
, self
->frame
.plate
, PLATE_EVENTMASK
);
526 /* map the client so it maps when the frame does */
527 XMapWindow(ob_display
, client
->window
);
529 frame_adjust_size(self
);
530 frame_adjust_position(self
);
532 /* set all the windows for the frame in the client_map */
533 g_hash_table_insert(client_map
, (gpointer
)self
->frame
.window
, client
);
534 g_hash_table_insert(client_map
, (gpointer
)self
->frame
.plate
, client
);
535 g_hash_table_insert(client_map
, (gpointer
)self
->title
, client
);
536 g_hash_table_insert(client_map
, (gpointer
)self
->label
, client
);
537 g_hash_table_insert(client_map
, (gpointer
)self
->max
, client
);
538 g_hash_table_insert(client_map
, (gpointer
)self
->close
, client
);
539 g_hash_table_insert(client_map
, (gpointer
)self
->desk
, client
);
540 g_hash_table_insert(client_map
, (gpointer
)self
->icon
, client
);
541 g_hash_table_insert(client_map
, (gpointer
)self
->iconify
, client
);
542 g_hash_table_insert(client_map
, (gpointer
)self
->handle
, client
);
543 g_hash_table_insert(client_map
, (gpointer
)self
->lgrip
, client
);
544 g_hash_table_insert(client_map
, (gpointer
)self
->rgrip
, client
);
547 void frame_release_client(ObFrame
*self
, Client
*client
)
551 g_assert(self
->frame
.client
== client
);
553 /* check if the app has already reparented its window away */
554 if (XCheckTypedWindowEvent(ob_display
, client
->window
,
555 ReparentNotify
, &ev
)) {
556 XPutBackEvent(ob_display
, &ev
);
557 /* re-map the window since the unmanaging process unmaps it */
558 XMapWindow(ob_display
, client
->window
);
560 /* according to the ICCCM - if the client doesn't reparent itself,
561 then we will reparent the window to root for them */
562 XReparentWindow(ob_display
, client
->window
, ob_root
,
567 /* remove all the windows for the frame from the client_map */
568 g_hash_table_remove(client_map
, (gpointer
)self
->frame
.window
);
569 g_hash_table_remove(client_map
, (gpointer
)self
->frame
.plate
);
570 g_hash_table_remove(client_map
, (gpointer
)self
->title
);
571 g_hash_table_remove(client_map
, (gpointer
)self
->label
);
572 g_hash_table_remove(client_map
, (gpointer
)self
->max
);
573 g_hash_table_remove(client_map
, (gpointer
)self
->close
);
574 g_hash_table_remove(client_map
, (gpointer
)self
->desk
);
575 g_hash_table_remove(client_map
, (gpointer
)self
->icon
);
576 g_hash_table_remove(client_map
, (gpointer
)self
->iconify
);
577 g_hash_table_remove(client_map
, (gpointer
)self
->handle
);
578 g_hash_table_remove(client_map
, (gpointer
)self
->lgrip
);
579 g_hash_table_remove(client_map
, (gpointer
)self
->rgrip
);
584 static void layout_title(ObFrame
*self
)
588 gboolean n
, d
, i
, l
, m
,c
;
589 n
= d
= i
= l
= m
= c
= FALSE
;
591 /* figure out whats being shown, and the width of the label */
592 self
->label_width
= self
->width
- s_bevel
* 2;
593 for (lc
= themerc_titlebar_layout
; *lc
!= '\0'; ++lc
) {
596 if (!(self
->frame
.client
->decorations
& Decor_Icon
)) break;
598 self
->label_width
-= BUTTON_SIZE
+ s_bevel
;
601 if (!(self
->frame
.client
->decorations
& Decor_AllDesktops
)) break;
603 self
->label_width
-= BUTTON_SIZE
+ s_bevel
;
606 if (!(self
->frame
.client
->decorations
& Decor_Iconify
)) break;
608 self
->label_width
-= BUTTON_SIZE
+ s_bevel
;
614 if (!(self
->frame
.client
->decorations
& Decor_Maximize
)) break;
616 self
->label_width
-= BUTTON_SIZE
+ s_bevel
;
619 if (!(self
->frame
.client
->decorations
& Decor_Close
)) break;
621 self
->label_width
-= BUTTON_SIZE
+ s_bevel
;
625 if (self
->label_width
< 1) self
->label_width
= 1;
627 XResizeWindow(ob_display
, self
->label
, self
->label_width
,
631 self
->frame
.client
->decorations
&= ~Decor_Icon
;
632 XUnmapWindow(ob_display
, self
->icon
);
636 self
->frame
.client
->decorations
&= ~Decor_AllDesktops
;
637 XUnmapWindow(ob_display
, self
->desk
);
641 self
->frame
.client
->decorations
&= ~Decor_Iconify
;
642 XUnmapWindow(ob_display
, self
->iconify
);
646 XUnmapWindow(ob_display
, self
->label
);
650 self
->frame
.client
->decorations
&= ~Decor_Maximize
;
651 XUnmapWindow(ob_display
, self
->max
);
655 self
->frame
.client
->decorations
&= ~Decor_Close
;
656 XUnmapWindow(ob_display
, self
->close
);
661 for (lc
= themerc_titlebar_layout
; *lc
!= '\0'; ++lc
) {
666 XMapWindow(ob_display
, self
->icon
);
667 XMoveWindow(ob_display
, self
->icon
, x
, s_bevel
+ 1);
668 x
+= BUTTON_SIZE
+ s_bevel
;
673 XMapWindow(ob_display
, self
->desk
);
674 XMoveWindow(ob_display
, self
->desk
, x
, s_bevel
+ 1);
675 x
+= BUTTON_SIZE
+ s_bevel
;
680 XMapWindow(ob_display
, self
->iconify
);
681 XMoveWindow(ob_display
, self
->iconify
, x
, s_bevel
+ 1);
682 x
+= BUTTON_SIZE
+ s_bevel
;
687 XMapWindow(ob_display
, self
->label
);
688 XMoveWindow(ob_display
, self
->label
, x
, s_bevel
);
689 x
+= self
->label_width
+ s_bevel
;
694 XMapWindow(ob_display
, self
->max
);
695 XMoveWindow(ob_display
, self
->max
, x
, s_bevel
+ 1);
696 x
+= BUTTON_SIZE
+ s_bevel
;
701 XMapWindow(ob_display
, self
->close
);
702 XMoveWindow(ob_display
, self
->close
, x
, s_bevel
+ 1);
703 x
+= BUTTON_SIZE
+ s_bevel
;
709 static void render(ObFrame
*self
)
711 if (self
->frame
.client
->focused
) {
712 XSetWindowBorder(ob_display
, self
->frame
.plate
,
713 s_cb_focused_color
->pixel
);
715 XSetWindowBorder(ob_display
, self
->frame
.plate
,
716 s_cb_unfocused_color
->pixel
);
719 if (self
->frame
.client
->decorations
& Decor_Titlebar
) {
720 paint(self
->title
, (self
->frame
.client
->focused
?
721 self
->a_focused_title
:
722 self
->a_unfocused_title
),
723 self
->width
, TITLE_HEIGHT
);
727 render_iconify(self
);
732 if (self
->frame
.client
->decorations
& Decor_Handle
) {
733 paint(self
->handle
, (self
->frame
.client
->focused
?
734 self
->a_focused_handle
:
735 self
->a_unfocused_handle
),
736 HANDLE_WIDTH(self
), s_handle_height
);
737 paint(self
->lgrip
, (self
->frame
.client
->focused
?
740 GRIP_WIDTH
, s_handle_height
);
741 paint(self
->rgrip
, (self
->frame
.client
->focused
?
744 GRIP_WIDTH
, s_handle_height
);
748 static void render_label(ObFrame
*self
)
750 if (self
->label_x
< 0) return;
752 /* set the texture's text! */
753 self
->a_focused_label
->texture
[0].data
.text
.string
=
754 self
->frame
.client
->title
;
756 paint(self
->label
, (self
->frame
.client
->focused
?
757 self
->a_focused_label
:
758 self
->a_unfocused_label
),
759 self
->label_width
, LABEL_HEIGHT
);
762 static void render_icon(ObFrame
*self
)
764 if (self
->icon_x
< 0) return;
766 /* XXX set the texture's icon picture! */
767 paint(self
->icon
, self
->a_icon
, BUTTON_SIZE
, BUTTON_SIZE
);
770 static void render_max(ObFrame
*self
)
772 gboolean press
= self
->max_press
||
773 self
->frame
.client
->max_vert
|| self
->frame
.client
->max_horz
;
775 if (self
->max_x
< 0) return;
777 paint(self
->max
, (self
->frame
.client
->focused
?
779 a_focused_pressed_max
:
780 a_focused_unpressed_max
) :
782 a_unfocused_pressed_max
:
783 a_unfocused_unpressed_max
)),
784 BUTTON_SIZE
, BUTTON_SIZE
);
787 static void render_iconify(ObFrame
*self
)
789 if (self
->iconify_x
< 0) return;
791 paint(self
->iconify
, (self
->frame
.client
->focused
?
792 (self
->iconify_press
?
793 a_focused_pressed_iconify
:
794 a_focused_unpressed_iconify
) :
795 (self
->iconify_press
?
796 a_unfocused_pressed_iconify
:
797 a_unfocused_unpressed_iconify
)),
798 BUTTON_SIZE
, BUTTON_SIZE
);
801 static void render_desk(ObFrame
*self
)
803 gboolean press
= self
->desk_press
||
804 self
->frame
.client
->desktop
== DESKTOP_ALL
;
806 if (self
->desk_x
< 0) return;
808 paint(self
->desk
, (self
->frame
.client
->focused
?
810 a_focused_pressed_desk
:
811 a_focused_unpressed_desk
) :
813 a_unfocused_pressed_desk
:
814 a_unfocused_unpressed_desk
)),
815 BUTTON_SIZE
, BUTTON_SIZE
);
818 static void render_close(ObFrame
*self
)
820 if (self
->close_x
< 0) return;
822 paint(self
->close
, (self
->frame
.client
->focused
?
824 a_focused_pressed_close
:
825 a_focused_unpressed_close
) :
827 a_unfocused_pressed_close
:
828 a_unfocused_unpressed_close
)),
829 BUTTON_SIZE
, BUTTON_SIZE
);
832 GQuark
get_context(Client
*client
, Window win
)
836 if (win
== ob_root
) return g_quark_try_string("root");
837 if (client
== NULL
) return g_quark_try_string("none");
838 if (win
== client
->window
) return g_quark_try_string("client");
840 self
= (ObFrame
*) client
->frame
;
841 if (win
== self
->frame
.window
) return g_quark_try_string("frame");
842 if (win
== self
->frame
.plate
) return g_quark_try_string("client");
843 if (win
== self
->title
) return g_quark_try_string("titlebar");
844 if (win
== self
->label
) return g_quark_try_string("titlebar");
845 if (win
== self
->handle
) return g_quark_try_string("handle");
846 if (win
== self
->lgrip
) return g_quark_try_string("blcorner");
847 if (win
== self
->rgrip
) return g_quark_try_string("brcorner");
848 if (win
== self
->max
) return g_quark_try_string("maximize");
849 if (win
== self
->iconify
) return g_quark_try_string("iconify");
850 if (win
== self
->close
) return g_quark_try_string("close");
851 if (win
== self
->icon
) return g_quark_try_string("icon");
852 if (win
== self
->desk
) return g_quark_try_string("alldesktops");
854 return g_quark_try_string("none");