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
;
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
)));
212 RrPaint(t
, self
->title
, self
->width
, ob_rr_theme
->title_height
);
214 ob_rr_theme
->a_clear
->surface
.parent
= t
;
215 ob_rr_theme
->a_clear
->surface
.parenty
= 0;
217 ob_rr_theme
->a_clear
->surface
.parentx
= ob_rr_theme
->grip_width
+
219 RrPaint(ob_rr_theme
->a_clear
, self
->topresize
,
220 self
->width
- ob_rr_theme
->grip_width
* 2,
221 ob_rr_theme
->paddingy
+ 1);
223 ob_rr_theme
->a_clear
->surface
.parentx
= 0;
225 if (ob_rr_theme
->grip_width
> 0)
226 RrPaint(ob_rr_theme
->a_clear
, self
->tltresize
,
227 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
228 if (ob_rr_theme
->title_height
> 0)
229 RrPaint(ob_rr_theme
->a_clear
, self
->tllresize
,
230 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
232 ob_rr_theme
->a_clear
->surface
.parentx
=
233 self
->width
- ob_rr_theme
->grip_width
;
235 if (ob_rr_theme
->grip_width
> 0)
236 RrPaint(ob_rr_theme
->a_clear
, self
->trtresize
,
237 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
239 ob_rr_theme
->a_clear
->surface
.parentx
=
240 self
->width
- (ob_rr_theme
->paddingx
+ 1);
242 if (ob_rr_theme
->title_height
> 0)
243 RrPaint(ob_rr_theme
->a_clear
, self
->trrresize
,
244 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
246 /* set parents for any parent relative guys */
247 l
->surface
.parent
= t
;
248 l
->surface
.parentx
= self
->label_x
;
249 l
->surface
.parenty
= ob_rr_theme
->paddingy
;
251 m
->surface
.parent
= t
;
252 m
->surface
.parentx
= self
->max_x
;
253 m
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
255 n
->surface
.parent
= t
;
256 n
->surface
.parentx
= self
->icon_x
;
257 n
->surface
.parenty
= ob_rr_theme
->paddingy
;
259 i
->surface
.parent
= t
;
260 i
->surface
.parentx
= self
->iconify_x
;
261 i
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
263 d
->surface
.parent
= t
;
264 d
->surface
.parentx
= self
->desk_x
;
265 d
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
267 s
->surface
.parent
= t
;
268 s
->surface
.parentx
= self
->shade_x
;
269 s
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
271 c
->surface
.parent
= t
;
272 c
->surface
.parentx
= self
->close_x
;
273 c
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
275 framerender_label(self
, l
);
276 framerender_max(self
, m
);
277 framerender_icon(self
, n
);
278 framerender_iconify(self
, i
);
279 framerender_desk(self
, d
);
280 framerender_shade(self
, s
);
281 framerender_close(self
, c
);
284 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
285 ob_rr_theme
->handle_height
> 0)
290 self
->a_focused_handle
: self
->a_unfocused_handle
);
292 RrPaint(h
, self
->handle
, self
->width
, ob_rr_theme
->handle_height
);
294 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
296 ob_rr_theme
->a_focused_grip
: ob_rr_theme
->a_unfocused_grip
);
298 if (g
->surface
.grad
== RR_SURFACE_PARENTREL
)
299 g
->surface
.parent
= h
;
301 g
->surface
.parentx
= 0;
302 g
->surface
.parenty
= 0;
304 RrPaint(g
, self
->lgrip
,
305 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
307 g
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
308 g
->surface
.parenty
= 0;
310 RrPaint(g
, self
->rgrip
,
311 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
318 static void framerender_label(ObFrame
*self
, RrAppearance
*a
)
320 if (!self
->label_on
) return;
321 /* set the texture's text! */
322 a
->texture
[0].data
.text
.string
= self
->client
->title
;
323 RrPaint(a
, self
->label
, self
->label_width
, ob_rr_theme
->label_height
);
326 static void framerender_icon(ObFrame
*self
, RrAppearance
*a
)
328 const ObClientIcon
*icon
;
330 if (!self
->icon_on
) return;
332 icon
= client_icon(self
->client
,
333 ob_rr_theme
->button_size
+ 2,
334 ob_rr_theme
->button_size
+ 2);
336 a
->texture
[0].type
= RR_TEXTURE_RGBA
;
337 a
->texture
[0].data
.rgba
.width
= icon
->width
;
338 a
->texture
[0].data
.rgba
.height
= icon
->height
;
339 a
->texture
[0].data
.rgba
.data
= icon
->data
;
341 a
->texture
[0].type
= RR_TEXTURE_NONE
;
343 RrPaint(a
, self
->icon
,
344 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
347 static void framerender_max(ObFrame
*self
, RrAppearance
*a
)
349 if (!self
->max_on
) return;
350 RrPaint(a
, self
->max
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
353 static void framerender_iconify(ObFrame
*self
, RrAppearance
*a
)
355 if (!self
->iconify_on
) return;
356 RrPaint(a
, self
->iconify
,
357 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
360 static void framerender_desk(ObFrame
*self
, RrAppearance
*a
)
362 if (!self
->desk_on
) return;
363 RrPaint(a
, self
->desk
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
366 static void framerender_shade(ObFrame
*self
, RrAppearance
*a
)
368 if (!self
->shade_on
) return;
369 RrPaint(a
, self
->shade
,
370 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
373 static void framerender_close(ObFrame
*self
, RrAppearance
*a
)
375 if (!self
->close_on
) return;
376 RrPaint(a
, self
->close
,
377 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);