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
));
44 XSetWindowBackground(ob_display
, self
->backback
, px
);
45 XClearWindow(ob_display
, self
->backback
);
46 XSetWindowBackground(ob_display
, self
->innerleft
, px
);
47 XClearWindow(ob_display
, self
->innerleft
);
48 XSetWindowBackground(ob_display
, self
->innertop
, px
);
49 XClearWindow(ob_display
, self
->innertop
);
50 XSetWindowBackground(ob_display
, self
->innerright
, px
);
51 XClearWindow(ob_display
, self
->innerright
);
52 XSetWindowBackground(ob_display
, self
->innerbottom
, px
);
53 XClearWindow(ob_display
, self
->innerbottom
);
56 RrColorPixel(ob_rr_theme
->frame_focused_border_color
) :
57 RrColorPixel(ob_rr_theme
->frame_unfocused_border_color
));
59 XSetWindowBackground(ob_display
, self
->left
, px
);
60 XClearWindow(ob_display
, self
->left
);
61 XSetWindowBackground(ob_display
, self
->right
, px
);
62 XClearWindow(ob_display
, self
->right
);
64 XSetWindowBackground(ob_display
, self
->titleleft
, px
);
65 XClearWindow(ob_display
, self
->titleleft
);
66 XSetWindowBackground(ob_display
, self
->titletop
, px
);
67 XClearWindow(ob_display
, self
->titletop
);
68 XSetWindowBackground(ob_display
, self
->titletopleft
, px
);
69 XClearWindow(ob_display
, self
->titletopleft
);
70 XSetWindowBackground(ob_display
, self
->titletopright
, px
);
71 XClearWindow(ob_display
, self
->titletopright
);
72 XSetWindowBackground(ob_display
, self
->titleright
, px
);
73 XClearWindow(ob_display
, self
->titleright
);
75 XSetWindowBackground(ob_display
, self
->handleleft
, px
);
76 XClearWindow(ob_display
, self
->handleleft
);
77 XSetWindowBackground(ob_display
, self
->handletop
, px
);
78 XClearWindow(ob_display
, self
->handletop
);
79 XSetWindowBackground(ob_display
, self
->handleright
, px
);
80 XClearWindow(ob_display
, self
->handleright
);
81 XSetWindowBackground(ob_display
, self
->handlebottom
, px
);
82 XClearWindow(ob_display
, self
->handlebottom
);
84 XSetWindowBackground(ob_display
, self
->lgripleft
, px
);
85 XClearWindow(ob_display
, self
->lgripleft
);
86 XSetWindowBackground(ob_display
, self
->lgriptop
, px
);
87 XClearWindow(ob_display
, self
->lgriptop
);
88 XSetWindowBackground(ob_display
, self
->lgripbottom
, px
);
89 XClearWindow(ob_display
, self
->lgripbottom
);
91 XSetWindowBackground(ob_display
, self
->rgripright
, px
);
92 XClearWindow(ob_display
, self
->rgripright
);
93 XSetWindowBackground(ob_display
, self
->rgriptop
, px
);
94 XClearWindow(ob_display
, self
->rgriptop
);
95 XSetWindowBackground(ob_display
, self
->rgripbottom
, px
);
96 XClearWindow(ob_display
, self
->rgripbottom
);
98 /* don't use the separator color for shaded windows */
99 if (!self
->client
->shaded
)
100 px
= (self
->focused
?
101 RrColorPixel(ob_rr_theme
->title_separator_focused_color
) :
102 RrColorPixel(ob_rr_theme
->title_separator_unfocused_color
));
104 XSetWindowBackground(ob_display
, self
->titlebottom
, px
);
105 XClearWindow(ob_display
, self
->titlebottom
);
108 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
109 RrAppearance
*t
, *l
, *m
, *n
, *i
, *d
, *s
, *c
, *clear
;
112 t
= self
->a_focused_title
;
113 l
= self
->a_focused_label
;
115 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
116 ob_rr_theme
->a_disabled_focused_max
:
117 (self
->client
->max_vert
|| self
->client
->max_horz
?
119 ob_rr_theme
->a_toggled_focused_pressed_max
:
121 ob_rr_theme
->a_toggled_hover_focused_max
:
122 ob_rr_theme
->a_toggled_focused_unpressed_max
)) :
124 ob_rr_theme
->a_focused_pressed_max
:
126 ob_rr_theme
->a_hover_focused_max
:
127 ob_rr_theme
->a_focused_unpressed_max
))));
129 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
130 ob_rr_theme
->a_disabled_focused_iconify
:
131 (self
->iconify_press
?
132 ob_rr_theme
->a_focused_pressed_iconify
:
133 (self
->iconify_hover
?
134 ob_rr_theme
->a_hover_focused_iconify
:
135 ob_rr_theme
->a_focused_unpressed_iconify
)));
136 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
137 ob_rr_theme
->a_disabled_focused_desk
:
138 (self
->client
->desktop
== DESKTOP_ALL
?
140 ob_rr_theme
->a_toggled_focused_pressed_desk
:
142 ob_rr_theme
->a_toggled_hover_focused_desk
:
143 ob_rr_theme
->a_toggled_focused_unpressed_desk
)) :
145 ob_rr_theme
->a_focused_pressed_desk
:
147 ob_rr_theme
->a_hover_focused_desk
:
148 ob_rr_theme
->a_focused_unpressed_desk
))));
149 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
150 ob_rr_theme
->a_disabled_focused_shade
:
151 (self
->client
->shaded
?
153 ob_rr_theme
->a_toggled_focused_pressed_shade
:
155 ob_rr_theme
->a_toggled_hover_focused_shade
:
156 ob_rr_theme
->a_toggled_focused_unpressed_shade
)) :
158 ob_rr_theme
->a_focused_pressed_shade
:
160 ob_rr_theme
->a_hover_focused_shade
:
161 ob_rr_theme
->a_focused_unpressed_shade
))));
162 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
163 ob_rr_theme
->a_disabled_focused_close
:
165 ob_rr_theme
->a_focused_pressed_close
:
167 ob_rr_theme
->a_hover_focused_close
:
168 ob_rr_theme
->a_focused_unpressed_close
)));
170 t
= self
->a_unfocused_title
;
171 l
= self
->a_unfocused_label
;
172 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
173 ob_rr_theme
->a_disabled_unfocused_max
:
174 (self
->client
->max_vert
|| self
->client
->max_horz
?
176 ob_rr_theme
->a_toggled_unfocused_pressed_max
:
178 ob_rr_theme
->a_toggled_hover_unfocused_max
:
179 ob_rr_theme
->a_toggled_unfocused_unpressed_max
)) :
181 ob_rr_theme
->a_unfocused_pressed_max
:
183 ob_rr_theme
->a_hover_unfocused_max
:
184 ob_rr_theme
->a_unfocused_unpressed_max
))));
186 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
187 ob_rr_theme
->a_disabled_unfocused_iconify
:
188 (self
->iconify_press
?
189 ob_rr_theme
->a_unfocused_pressed_iconify
:
190 (self
->iconify_hover
?
191 ob_rr_theme
->a_hover_unfocused_iconify
:
192 ob_rr_theme
->a_unfocused_unpressed_iconify
)));
193 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
194 ob_rr_theme
->a_disabled_unfocused_desk
:
195 (self
->client
->desktop
== DESKTOP_ALL
?
197 ob_rr_theme
->a_toggled_unfocused_pressed_desk
:
199 ob_rr_theme
->a_toggled_hover_unfocused_desk
:
200 ob_rr_theme
->a_toggled_unfocused_unpressed_desk
)) :
202 ob_rr_theme
->a_unfocused_pressed_desk
:
204 ob_rr_theme
->a_hover_unfocused_desk
:
205 ob_rr_theme
->a_unfocused_unpressed_desk
))));
206 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
207 ob_rr_theme
->a_disabled_unfocused_shade
:
208 (self
->client
->shaded
?
210 ob_rr_theme
->a_toggled_unfocused_pressed_shade
:
212 ob_rr_theme
->a_toggled_hover_unfocused_shade
:
213 ob_rr_theme
->a_toggled_unfocused_unpressed_shade
)) :
215 ob_rr_theme
->a_unfocused_pressed_shade
:
217 ob_rr_theme
->a_hover_unfocused_shade
:
218 ob_rr_theme
->a_unfocused_unpressed_shade
))));
219 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
220 ob_rr_theme
->a_disabled_unfocused_close
:
222 ob_rr_theme
->a_unfocused_pressed_close
:
224 ob_rr_theme
->a_hover_unfocused_close
:
225 ob_rr_theme
->a_unfocused_unpressed_close
)));
227 clear
= ob_rr_theme
->a_clear
;
229 RrPaint(t
, self
->title
, self
->width
, ob_rr_theme
->title_height
);
231 clear
->surface
.parent
= t
;
232 clear
->surface
.parenty
= 0;
234 clear
->surface
.parentx
= ob_rr_theme
->grip_width
;
236 RrPaint(clear
, self
->topresize
,
237 self
->width
- ob_rr_theme
->grip_width
* 2,
238 ob_rr_theme
->paddingy
+ 1);
240 clear
->surface
.parentx
= 0;
242 if (ob_rr_theme
->grip_width
> 0)
243 RrPaint(clear
, self
->tltresize
,
244 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
245 if (ob_rr_theme
->title_height
> 0)
246 RrPaint(clear
, self
->tllresize
,
247 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
249 clear
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
251 if (ob_rr_theme
->grip_width
> 0)
252 RrPaint(clear
, self
->trtresize
,
253 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
255 clear
->surface
.parentx
= self
->width
- (ob_rr_theme
->paddingx
+ 1);
257 if (ob_rr_theme
->title_height
> 0)
258 RrPaint(clear
, self
->trrresize
,
259 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
261 /* set parents for any parent relative guys */
262 l
->surface
.parent
= t
;
263 l
->surface
.parentx
= self
->label_x
;
264 l
->surface
.parenty
= ob_rr_theme
->paddingy
;
266 m
->surface
.parent
= t
;
267 m
->surface
.parentx
= self
->max_x
;
268 m
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
270 n
->surface
.parent
= t
;
271 n
->surface
.parentx
= self
->icon_x
;
272 n
->surface
.parenty
= ob_rr_theme
->paddingy
;
274 i
->surface
.parent
= t
;
275 i
->surface
.parentx
= self
->iconify_x
;
276 i
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
278 d
->surface
.parent
= t
;
279 d
->surface
.parentx
= self
->desk_x
;
280 d
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
282 s
->surface
.parent
= t
;
283 s
->surface
.parentx
= self
->shade_x
;
284 s
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
286 c
->surface
.parent
= t
;
287 c
->surface
.parentx
= self
->close_x
;
288 c
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
290 framerender_label(self
, l
);
291 framerender_max(self
, m
);
292 framerender_icon(self
, n
);
293 framerender_iconify(self
, i
);
294 framerender_desk(self
, d
);
295 framerender_shade(self
, s
);
296 framerender_close(self
, c
);
299 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
300 ob_rr_theme
->handle_height
> 0)
305 self
->a_focused_handle
: self
->a_unfocused_handle
);
307 RrPaint(h
, self
->handle
, self
->width
, ob_rr_theme
->handle_height
);
309 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
311 ob_rr_theme
->a_focused_grip
: ob_rr_theme
->a_unfocused_grip
);
313 if (g
->surface
.grad
== RR_SURFACE_PARENTREL
)
314 g
->surface
.parent
= h
;
316 g
->surface
.parentx
= 0;
317 g
->surface
.parenty
= 0;
319 RrPaint(g
, self
->lgrip
,
320 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
322 g
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
323 g
->surface
.parenty
= 0;
325 RrPaint(g
, self
->rgrip
,
326 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
333 static void framerender_label(ObFrame
*self
, RrAppearance
*a
)
335 if (!self
->label_on
) return;
336 /* set the texture's text! */
337 a
->texture
[0].data
.text
.string
= self
->client
->title
;
338 RrPaint(a
, self
->label
, self
->label_width
, ob_rr_theme
->label_height
);
341 static void framerender_icon(ObFrame
*self
, RrAppearance
*a
)
343 const ObClientIcon
*icon
;
345 if (!self
->icon_on
) return;
347 icon
= client_icon(self
->client
,
348 ob_rr_theme
->button_size
+ 2,
349 ob_rr_theme
->button_size
+ 2);
351 a
->texture
[0].type
= RR_TEXTURE_RGBA
;
352 a
->texture
[0].data
.rgba
.width
= icon
->width
;
353 a
->texture
[0].data
.rgba
.height
= icon
->height
;
354 a
->texture
[0].data
.rgba
.alpha
= 0xff;
355 a
->texture
[0].data
.rgba
.data
= icon
->data
;
357 a
->texture
[0].type
= RR_TEXTURE_NONE
;
359 RrPaint(a
, self
->icon
,
360 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
363 static void framerender_max(ObFrame
*self
, RrAppearance
*a
)
365 if (!self
->max_on
) return;
366 RrPaint(a
, self
->max
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
369 static void framerender_iconify(ObFrame
*self
, RrAppearance
*a
)
371 if (!self
->iconify_on
) return;
372 RrPaint(a
, self
->iconify
,
373 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
376 static void framerender_desk(ObFrame
*self
, RrAppearance
*a
)
378 if (!self
->desk_on
) return;
379 RrPaint(a
, self
->desk
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
382 static void framerender_shade(ObFrame
*self
, RrAppearance
*a
)
384 if (!self
->shade_on
) return;
385 RrPaint(a
, self
->shade
,
386 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
389 static void framerender_close(ObFrame
*self
, RrAppearance
*a
)
391 if (!self
->close_on
) return;
392 RrPaint(a
, self
->close
,
393 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);