1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 framerender.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.
24 #include "framerender.h"
25 #include "render/theme.h"
27 static void framerender_label(ObFrame
*self
, RrAppearance
*a
);
28 static void framerender_icon(ObFrame
*self
, RrAppearance
*a
);
29 static void framerender_max(ObFrame
*self
, RrAppearance
*a
);
30 static void framerender_iconify(ObFrame
*self
, RrAppearance
*a
);
31 static void framerender_desk(ObFrame
*self
, RrAppearance
*a
);
32 static void framerender_shade(ObFrame
*self
, RrAppearance
*a
);
33 static void framerender_close(ObFrame
*self
, RrAppearance
*a
);
35 void framerender_frame(ObFrame
*self
)
41 RrColorPixel(ob_rr_theme
->cb_focused_color
) :
42 RrColorPixel(ob_rr_theme
->cb_unfocused_color
));
43 XSetWindowBackground(ob_display
, self
->inner
, px
);
44 XClearWindow(ob_display
, self
->inner
);
47 RrColorPixel(ob_rr_theme
->frame_focused_border_color
) :
48 RrColorPixel(ob_rr_theme
->frame_unfocused_border_color
));
50 XSetWindowBackground(ob_display
, self
->left
, px
);
51 XClearWindow(ob_display
, self
->left
);
52 XSetWindowBackground(ob_display
, self
->right
, px
);
53 XClearWindow(ob_display
, self
->right
);
55 XSetWindowBackground(ob_display
, self
->titleleft
, px
);
56 XClearWindow(ob_display
, self
->titleleft
);
57 XSetWindowBackground(ob_display
, self
->titletop
, px
);
58 XClearWindow(ob_display
, self
->titletop
);
59 XSetWindowBackground(ob_display
, self
->titletopleft
, px
);
60 XClearWindow(ob_display
, self
->titletopleft
);
61 XSetWindowBackground(ob_display
, self
->titletopright
, px
);
62 XClearWindow(ob_display
, self
->titletopright
);
63 XSetWindowBackground(ob_display
, self
->titleright
, px
);
64 XClearWindow(ob_display
, self
->titleright
);
65 XSetWindowBackground(ob_display
, self
->titlebottom
, px
);
66 XClearWindow(ob_display
, self
->titlebottom
);
68 XSetWindowBackground(ob_display
, self
->handleleft
, px
);
69 XClearWindow(ob_display
, self
->handleleft
);
70 XSetWindowBackground(ob_display
, self
->handletop
, px
);
71 XClearWindow(ob_display
, self
->handletop
);
72 XSetWindowBackground(ob_display
, self
->handleright
, px
);
73 XClearWindow(ob_display
, self
->handleright
);
74 XSetWindowBackground(ob_display
, self
->handlebottom
, px
);
75 XClearWindow(ob_display
, self
->handlebottom
);
77 XSetWindowBackground(ob_display
, self
->lgripleft
, px
);
78 XClearWindow(ob_display
, self
->lgripleft
);
79 XSetWindowBackground(ob_display
, self
->lgriptop
, px
);
80 XClearWindow(ob_display
, self
->lgriptop
);
81 XSetWindowBackground(ob_display
, self
->lgripbottom
, px
);
82 XClearWindow(ob_display
, self
->lgripbottom
);
84 XSetWindowBackground(ob_display
, self
->rgripright
, px
);
85 XClearWindow(ob_display
, self
->rgripright
);
86 XSetWindowBackground(ob_display
, self
->rgriptop
, px
);
87 XClearWindow(ob_display
, self
->rgriptop
);
88 XSetWindowBackground(ob_display
, self
->rgripbottom
, px
);
89 XClearWindow(ob_display
, self
->rgripbottom
);
92 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
93 RrAppearance
*t
, *l
, *m
, *n
, *i
, *d
, *s
, *c
, *clear
;
96 t
= self
->a_focused_title
;
97 l
= self
->a_focused_label
;
99 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
100 ob_rr_theme
->a_disabled_focused_max
:
101 (self
->client
->max_vert
|| self
->client
->max_horz
?
103 ob_rr_theme
->a_toggled_focused_pressed_max
:
105 ob_rr_theme
->a_toggled_hover_focused_max
:
106 ob_rr_theme
->a_toggled_focused_unpressed_max
)) :
108 ob_rr_theme
->a_focused_pressed_max
:
110 ob_rr_theme
->a_hover_focused_max
:
111 ob_rr_theme
->a_focused_unpressed_max
))));
113 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
114 ob_rr_theme
->a_disabled_focused_iconify
:
115 (self
->iconify_press
?
116 ob_rr_theme
->a_focused_pressed_iconify
:
117 (self
->iconify_hover
?
118 ob_rr_theme
->a_hover_focused_iconify
:
119 ob_rr_theme
->a_focused_unpressed_iconify
)));
120 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
121 ob_rr_theme
->a_disabled_focused_desk
:
122 (self
->client
->desktop
== DESKTOP_ALL
?
124 ob_rr_theme
->a_toggled_focused_pressed_desk
:
126 ob_rr_theme
->a_toggled_hover_focused_desk
:
127 ob_rr_theme
->a_toggled_focused_unpressed_desk
)) :
129 ob_rr_theme
->a_focused_pressed_desk
:
131 ob_rr_theme
->a_hover_focused_desk
:
132 ob_rr_theme
->a_focused_unpressed_desk
))));
133 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
134 ob_rr_theme
->a_disabled_focused_shade
:
135 (self
->client
->shaded
?
137 ob_rr_theme
->a_toggled_focused_pressed_shade
:
139 ob_rr_theme
->a_toggled_hover_focused_shade
:
140 ob_rr_theme
->a_toggled_focused_unpressed_shade
)) :
142 ob_rr_theme
->a_focused_pressed_shade
:
144 ob_rr_theme
->a_hover_focused_shade
:
145 ob_rr_theme
->a_focused_unpressed_shade
))));
146 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
147 ob_rr_theme
->a_disabled_focused_close
:
149 ob_rr_theme
->a_focused_pressed_close
:
151 ob_rr_theme
->a_hover_focused_close
:
152 ob_rr_theme
->a_focused_unpressed_close
)));
154 t
= self
->a_unfocused_title
;
155 l
= self
->a_unfocused_label
;
156 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
157 ob_rr_theme
->a_disabled_unfocused_max
:
158 (self
->client
->max_vert
|| self
->client
->max_horz
?
160 ob_rr_theme
->a_toggled_unfocused_pressed_max
:
162 ob_rr_theme
->a_toggled_hover_unfocused_max
:
163 ob_rr_theme
->a_toggled_unfocused_unpressed_max
)) :
165 ob_rr_theme
->a_unfocused_pressed_max
:
167 ob_rr_theme
->a_hover_unfocused_max
:
168 ob_rr_theme
->a_unfocused_unpressed_max
))));
170 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
171 ob_rr_theme
->a_disabled_unfocused_iconify
:
172 (self
->iconify_press
?
173 ob_rr_theme
->a_unfocused_pressed_iconify
:
174 (self
->iconify_hover
?
175 ob_rr_theme
->a_hover_unfocused_iconify
:
176 ob_rr_theme
->a_unfocused_unpressed_iconify
)));
177 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
178 ob_rr_theme
->a_disabled_unfocused_desk
:
179 (self
->client
->desktop
== DESKTOP_ALL
?
181 ob_rr_theme
->a_toggled_unfocused_pressed_desk
:
183 ob_rr_theme
->a_toggled_hover_unfocused_desk
:
184 ob_rr_theme
->a_toggled_unfocused_unpressed_desk
)) :
186 ob_rr_theme
->a_unfocused_pressed_desk
:
188 ob_rr_theme
->a_hover_unfocused_desk
:
189 ob_rr_theme
->a_unfocused_unpressed_desk
))));
190 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
191 ob_rr_theme
->a_disabled_unfocused_shade
:
192 (self
->client
->shaded
?
194 ob_rr_theme
->a_toggled_unfocused_pressed_shade
:
196 ob_rr_theme
->a_toggled_hover_unfocused_shade
:
197 ob_rr_theme
->a_toggled_unfocused_unpressed_shade
)) :
199 ob_rr_theme
->a_unfocused_pressed_shade
:
201 ob_rr_theme
->a_hover_unfocused_shade
:
202 ob_rr_theme
->a_unfocused_unpressed_shade
))));
203 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
204 ob_rr_theme
->a_disabled_unfocused_close
:
206 ob_rr_theme
->a_unfocused_pressed_close
:
208 ob_rr_theme
->a_hover_unfocused_close
:
209 ob_rr_theme
->a_unfocused_unpressed_close
)));
211 clear
= ob_rr_theme
->a_clear
;
213 RrPaint(t
, self
->title
, self
->width
, ob_rr_theme
->title_height
);
215 clear
->surface
.parent
= t
;
216 clear
->surface
.parenty
= 0;
218 clear
->surface
.parentx
= ob_rr_theme
->grip_width
;
220 RrPaint(clear
, self
->topresize
,
221 self
->width
- ob_rr_theme
->grip_width
* 2,
222 ob_rr_theme
->paddingy
+ 1);
224 clear
->surface
.parentx
= 0;
226 if (ob_rr_theme
->grip_width
> 0)
227 RrPaint(clear
, self
->tltresize
,
228 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
229 if (ob_rr_theme
->title_height
> 0)
230 RrPaint(clear
, self
->tllresize
,
231 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
233 clear
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
235 if (ob_rr_theme
->grip_width
> 0)
236 RrPaint(clear
, self
->trtresize
,
237 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
239 clear
->surface
.parentx
= self
->width
- (ob_rr_theme
->paddingx
+ 1);
241 if (ob_rr_theme
->title_height
> 0)
242 RrPaint(clear
, self
->trrresize
,
243 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
245 /* set parents for any parent relative guys */
246 l
->surface
.parent
= t
;
247 l
->surface
.parentx
= self
->label_x
;
248 l
->surface
.parenty
= ob_rr_theme
->paddingy
;
250 m
->surface
.parent
= t
;
251 m
->surface
.parentx
= self
->max_x
;
252 m
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
254 n
->surface
.parent
= t
;
255 n
->surface
.parentx
= self
->icon_x
;
256 n
->surface
.parenty
= ob_rr_theme
->paddingy
;
258 i
->surface
.parent
= t
;
259 i
->surface
.parentx
= self
->iconify_x
;
260 i
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
262 d
->surface
.parent
= t
;
263 d
->surface
.parentx
= self
->desk_x
;
264 d
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
266 s
->surface
.parent
= t
;
267 s
->surface
.parentx
= self
->shade_x
;
268 s
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
270 c
->surface
.parent
= t
;
271 c
->surface
.parentx
= self
->close_x
;
272 c
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
274 framerender_label(self
, l
);
275 framerender_max(self
, m
);
276 framerender_icon(self
, n
);
277 framerender_iconify(self
, i
);
278 framerender_desk(self
, d
);
279 framerender_shade(self
, s
);
280 framerender_close(self
, c
);
283 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
284 ob_rr_theme
->handle_height
> 0)
289 self
->a_focused_handle
: self
->a_unfocused_handle
);
291 RrPaint(h
, self
->handle
, self
->width
, ob_rr_theme
->handle_height
);
293 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
295 ob_rr_theme
->a_focused_grip
: ob_rr_theme
->a_unfocused_grip
);
297 if (g
->surface
.grad
== RR_SURFACE_PARENTREL
)
298 g
->surface
.parent
= h
;
300 g
->surface
.parentx
= 0;
301 g
->surface
.parenty
= 0;
303 RrPaint(g
, self
->lgrip
,
304 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
306 g
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
307 g
->surface
.parenty
= 0;
309 RrPaint(g
, self
->rgrip
,
310 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
317 static void framerender_label(ObFrame
*self
, RrAppearance
*a
)
319 if (!self
->label_on
) return;
320 /* set the texture's text! */
321 a
->texture
[0].data
.text
.string
= self
->client
->title
;
322 RrPaint(a
, self
->label
, self
->label_width
, ob_rr_theme
->label_height
);
325 static void framerender_icon(ObFrame
*self
, RrAppearance
*a
)
327 const ObClientIcon
*icon
;
329 if (!self
->icon_on
) return;
331 icon
= client_icon(self
->client
,
332 ob_rr_theme
->button_size
+ 2,
333 ob_rr_theme
->button_size
+ 2);
335 a
->texture
[0].type
= RR_TEXTURE_RGBA
;
336 a
->texture
[0].data
.rgba
.width
= icon
->width
;
337 a
->texture
[0].data
.rgba
.height
= icon
->height
;
338 a
->texture
[0].data
.rgba
.data
= icon
->data
;
340 a
->texture
[0].type
= RR_TEXTURE_NONE
;
342 RrPaint(a
, self
->icon
,
343 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
346 static void framerender_max(ObFrame
*self
, RrAppearance
*a
)
348 if (!self
->max_on
) return;
349 RrPaint(a
, self
->max
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
352 static void framerender_iconify(ObFrame
*self
, RrAppearance
*a
)
354 if (!self
->iconify_on
) return;
355 RrPaint(a
, self
->iconify
,
356 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
359 static void framerender_desk(ObFrame
*self
, RrAppearance
*a
)
361 if (!self
->desk_on
) return;
362 RrPaint(a
, self
->desk
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
365 static void framerender_shade(ObFrame
*self
, RrAppearance
*a
)
367 if (!self
->shade_on
) return;
368 RrPaint(a
, self
->shade
,
369 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
372 static void framerender_close(ObFrame
*self
, RrAppearance
*a
)
374 if (!self
->close_on
) return;
375 RrPaint(a
, self
->close
,
376 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);