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
)
37 if (frame_iconify_animating(self
))
38 return; /* delay redrawing until the animation is done */
39 if (!self
->need_render
)
43 self
->need_render
= FALSE
;
49 RrColorPixel(ob_rr_theme
->cb_focused_color
) :
50 RrColorPixel(ob_rr_theme
->cb_unfocused_color
));
52 XSetWindowBackground(ob_display
, self
->backback
, px
);
53 XClearWindow(ob_display
, self
->backback
);
54 XSetWindowBackground(ob_display
, self
->innerleft
, px
);
55 XClearWindow(ob_display
, self
->innerleft
);
56 XSetWindowBackground(ob_display
, self
->innertop
, px
);
57 XClearWindow(ob_display
, self
->innertop
);
58 XSetWindowBackground(ob_display
, self
->innerright
, px
);
59 XClearWindow(ob_display
, self
->innerright
);
60 XSetWindowBackground(ob_display
, self
->innerbottom
, px
);
61 XClearWindow(ob_display
, self
->innerbottom
);
62 XSetWindowBackground(ob_display
, self
->innerbll
, px
);
63 XClearWindow(ob_display
, self
->innerbll
);
64 XSetWindowBackground(ob_display
, self
->innerbrr
, px
);
65 XClearWindow(ob_display
, self
->innerbrr
);
66 XSetWindowBackground(ob_display
, self
->innerblb
, px
);
67 XClearWindow(ob_display
, self
->innerblb
);
68 XSetWindowBackground(ob_display
, self
->innerbrb
, px
);
69 XClearWindow(ob_display
, self
->innerbrb
);
72 RrColorPixel(ob_rr_theme
->frame_focused_border_color
) :
73 RrColorPixel(ob_rr_theme
->frame_unfocused_border_color
));
75 XSetWindowBackground(ob_display
, self
->left
, px
);
76 XClearWindow(ob_display
, self
->left
);
77 XSetWindowBackground(ob_display
, self
->right
, px
);
78 XClearWindow(ob_display
, self
->right
);
80 XSetWindowBackground(ob_display
, self
->titleleft
, px
);
81 XClearWindow(ob_display
, self
->titleleft
);
82 XSetWindowBackground(ob_display
, self
->titletop
, px
);
83 XClearWindow(ob_display
, self
->titletop
);
84 XSetWindowBackground(ob_display
, self
->titletopleft
, px
);
85 XClearWindow(ob_display
, self
->titletopleft
);
86 XSetWindowBackground(ob_display
, self
->titletopright
, px
);
87 XClearWindow(ob_display
, self
->titletopright
);
88 XSetWindowBackground(ob_display
, self
->titleright
, px
);
89 XClearWindow(ob_display
, self
->titleright
);
91 XSetWindowBackground(ob_display
, self
->handleleft
, px
);
92 XClearWindow(ob_display
, self
->handleleft
);
93 XSetWindowBackground(ob_display
, self
->handletop
, px
);
94 XClearWindow(ob_display
, self
->handletop
);
95 XSetWindowBackground(ob_display
, self
->handleright
, px
);
96 XClearWindow(ob_display
, self
->handleright
);
97 XSetWindowBackground(ob_display
, self
->handlebottom
, px
);
98 XClearWindow(ob_display
, self
->handlebottom
);
100 XSetWindowBackground(ob_display
, self
->lgripleft
, px
);
101 XClearWindow(ob_display
, self
->lgripleft
);
102 XSetWindowBackground(ob_display
, self
->lgriptop
, px
);
103 XClearWindow(ob_display
, self
->lgriptop
);
104 XSetWindowBackground(ob_display
, self
->lgripbottom
, px
);
105 XClearWindow(ob_display
, self
->lgripbottom
);
107 XSetWindowBackground(ob_display
, self
->rgripright
, px
);
108 XClearWindow(ob_display
, self
->rgripright
);
109 XSetWindowBackground(ob_display
, self
->rgriptop
, px
);
110 XClearWindow(ob_display
, self
->rgriptop
);
111 XSetWindowBackground(ob_display
, self
->rgripbottom
, px
);
112 XClearWindow(ob_display
, self
->rgripbottom
);
114 /* don't use the separator color for shaded windows */
115 if (!self
->client
->shaded
)
116 px
= (self
->focused
?
117 RrColorPixel(ob_rr_theme
->title_separator_focused_color
) :
118 RrColorPixel(ob_rr_theme
->title_separator_unfocused_color
));
120 XSetWindowBackground(ob_display
, self
->titlebottom
, px
);
121 XClearWindow(ob_display
, self
->titlebottom
);
124 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
125 RrAppearance
*t
, *l
, *m
, *n
, *i
, *d
, *s
, *c
, *clear
;
127 t
= ob_rr_theme
->a_focused_title
;
128 l
= ob_rr_theme
->a_focused_label
;
129 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
130 ob_rr_theme
->a_disabled_focused_max
:
131 (self
->client
->max_vert
|| self
->client
->max_horz
?
133 ob_rr_theme
->a_toggled_focused_pressed_max
:
135 ob_rr_theme
->a_toggled_hover_focused_max
:
136 ob_rr_theme
->a_toggled_focused_unpressed_max
)) :
138 ob_rr_theme
->a_focused_pressed_max
:
140 ob_rr_theme
->a_hover_focused_max
:
141 ob_rr_theme
->a_focused_unpressed_max
))));
142 n
= ob_rr_theme
->a_icon
;
143 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
144 ob_rr_theme
->a_disabled_focused_iconify
:
145 (self
->iconify_press
?
146 ob_rr_theme
->a_focused_pressed_iconify
:
147 (self
->iconify_hover
?
148 ob_rr_theme
->a_hover_focused_iconify
:
149 ob_rr_theme
->a_focused_unpressed_iconify
)));
150 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
151 ob_rr_theme
->a_disabled_focused_desk
:
152 (self
->client
->desktop
== DESKTOP_ALL
?
154 ob_rr_theme
->a_toggled_focused_pressed_desk
:
156 ob_rr_theme
->a_toggled_hover_focused_desk
:
157 ob_rr_theme
->a_toggled_focused_unpressed_desk
)) :
159 ob_rr_theme
->a_focused_pressed_desk
:
161 ob_rr_theme
->a_hover_focused_desk
:
162 ob_rr_theme
->a_focused_unpressed_desk
))));
163 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
164 ob_rr_theme
->a_disabled_focused_shade
:
165 (self
->client
->shaded
?
167 ob_rr_theme
->a_toggled_focused_pressed_shade
:
169 ob_rr_theme
->a_toggled_hover_focused_shade
:
170 ob_rr_theme
->a_toggled_focused_unpressed_shade
)) :
172 ob_rr_theme
->a_focused_pressed_shade
:
174 ob_rr_theme
->a_hover_focused_shade
:
175 ob_rr_theme
->a_focused_unpressed_shade
))));
176 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
177 ob_rr_theme
->a_disabled_focused_close
:
179 ob_rr_theme
->a_focused_pressed_close
:
181 ob_rr_theme
->a_hover_focused_close
:
182 ob_rr_theme
->a_focused_unpressed_close
)));
184 t
= ob_rr_theme
->a_unfocused_title
;
185 l
= ob_rr_theme
->a_unfocused_label
;
186 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
187 ob_rr_theme
->a_disabled_unfocused_max
:
188 (self
->client
->max_vert
|| self
->client
->max_horz
?
190 ob_rr_theme
->a_toggled_unfocused_pressed_max
:
192 ob_rr_theme
->a_toggled_hover_unfocused_max
:
193 ob_rr_theme
->a_toggled_unfocused_unpressed_max
)) :
195 ob_rr_theme
->a_unfocused_pressed_max
:
197 ob_rr_theme
->a_hover_unfocused_max
:
198 ob_rr_theme
->a_unfocused_unpressed_max
))));
199 n
= ob_rr_theme
->a_icon
;
200 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
201 ob_rr_theme
->a_disabled_unfocused_iconify
:
202 (self
->iconify_press
?
203 ob_rr_theme
->a_unfocused_pressed_iconify
:
204 (self
->iconify_hover
?
205 ob_rr_theme
->a_hover_unfocused_iconify
:
206 ob_rr_theme
->a_unfocused_unpressed_iconify
)));
207 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
208 ob_rr_theme
->a_disabled_unfocused_desk
:
209 (self
->client
->desktop
== DESKTOP_ALL
?
211 ob_rr_theme
->a_toggled_unfocused_pressed_desk
:
213 ob_rr_theme
->a_toggled_hover_unfocused_desk
:
214 ob_rr_theme
->a_toggled_unfocused_unpressed_desk
)) :
216 ob_rr_theme
->a_unfocused_pressed_desk
:
218 ob_rr_theme
->a_hover_unfocused_desk
:
219 ob_rr_theme
->a_unfocused_unpressed_desk
))));
220 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
221 ob_rr_theme
->a_disabled_unfocused_shade
:
222 (self
->client
->shaded
?
224 ob_rr_theme
->a_toggled_unfocused_pressed_shade
:
226 ob_rr_theme
->a_toggled_hover_unfocused_shade
:
227 ob_rr_theme
->a_toggled_unfocused_unpressed_shade
)) :
229 ob_rr_theme
->a_unfocused_pressed_shade
:
231 ob_rr_theme
->a_hover_unfocused_shade
:
232 ob_rr_theme
->a_unfocused_unpressed_shade
))));
233 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
234 ob_rr_theme
->a_disabled_unfocused_close
:
236 ob_rr_theme
->a_unfocused_pressed_close
:
238 ob_rr_theme
->a_hover_unfocused_close
:
239 ob_rr_theme
->a_unfocused_unpressed_close
)));
241 clear
= ob_rr_theme
->a_clear
;
243 RrPaint(t
, self
->title
, self
->width
, ob_rr_theme
->title_height
);
245 clear
->surface
.parent
= t
;
246 clear
->surface
.parenty
= 0;
248 clear
->surface
.parentx
= ob_rr_theme
->grip_width
;
250 RrPaint(clear
, self
->topresize
,
251 self
->width
- ob_rr_theme
->grip_width
* 2,
252 ob_rr_theme
->paddingy
+ 1);
254 clear
->surface
.parentx
= 0;
256 if (ob_rr_theme
->grip_width
> 0)
257 RrPaint(clear
, self
->tltresize
,
258 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
259 if (ob_rr_theme
->title_height
> 0)
260 RrPaint(clear
, self
->tllresize
,
261 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
263 clear
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
265 if (ob_rr_theme
->grip_width
> 0)
266 RrPaint(clear
, self
->trtresize
,
267 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
269 clear
->surface
.parentx
= self
->width
- (ob_rr_theme
->paddingx
+ 1);
271 if (ob_rr_theme
->title_height
> 0)
272 RrPaint(clear
, self
->trrresize
,
273 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
275 /* set parents for any parent relative guys */
276 l
->surface
.parent
= t
;
277 l
->surface
.parentx
= self
->label_x
;
278 l
->surface
.parenty
= ob_rr_theme
->paddingy
;
280 m
->surface
.parent
= t
;
281 m
->surface
.parentx
= self
->max_x
;
282 m
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
284 n
->surface
.parent
= t
;
285 n
->surface
.parentx
= self
->icon_x
;
286 n
->surface
.parenty
= ob_rr_theme
->paddingy
;
288 i
->surface
.parent
= t
;
289 i
->surface
.parentx
= self
->iconify_x
;
290 i
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
292 d
->surface
.parent
= t
;
293 d
->surface
.parentx
= self
->desk_x
;
294 d
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
296 s
->surface
.parent
= t
;
297 s
->surface
.parentx
= self
->shade_x
;
298 s
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
300 c
->surface
.parent
= t
;
301 c
->surface
.parentx
= self
->close_x
;
302 c
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
304 framerender_label(self
, l
);
305 framerender_max(self
, m
);
306 framerender_icon(self
, n
);
307 framerender_iconify(self
, i
);
308 framerender_desk(self
, d
);
309 framerender_shade(self
, s
);
310 framerender_close(self
, c
);
313 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
314 ob_rr_theme
->handle_height
> 0)
319 ob_rr_theme
->a_focused_handle
: ob_rr_theme
->a_unfocused_handle
);
321 RrPaint(h
, self
->handle
, self
->width
, ob_rr_theme
->handle_height
);
323 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
325 ob_rr_theme
->a_focused_grip
: ob_rr_theme
->a_unfocused_grip
);
327 if (g
->surface
.grad
== RR_SURFACE_PARENTREL
)
328 g
->surface
.parent
= h
;
330 g
->surface
.parentx
= 0;
331 g
->surface
.parenty
= 0;
333 RrPaint(g
, self
->lgrip
,
334 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
336 g
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
337 g
->surface
.parenty
= 0;
339 RrPaint(g
, self
->rgrip
,
340 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
347 static void framerender_label(ObFrame
*self
, RrAppearance
*a
)
349 if (!self
->label_on
) return;
350 /* set the texture's text! */
351 a
->texture
[0].data
.text
.string
= self
->client
->title
;
352 RrPaint(a
, self
->label
, self
->label_width
, ob_rr_theme
->label_height
);
355 static void framerender_icon(ObFrame
*self
, RrAppearance
*a
)
359 if (!self
->icon_on
) return;
361 icon
= client_icon(self
->client
);
364 RrAppearanceClearTextures(a
);
365 a
->texture
[0].type
= RR_TEXTURE_IMAGE
;
366 a
->texture
[0].data
.image
.alpha
= 0xff;
367 a
->texture
[0].data
.image
.image
= icon
;
369 RrAppearanceClearTextures(a
);
370 a
->texture
[0].type
= RR_TEXTURE_NONE
;
373 RrPaint(a
, self
->icon
,
374 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
377 static void framerender_max(ObFrame
*self
, RrAppearance
*a
)
379 if (!self
->max_on
) return;
380 RrPaint(a
, self
->max
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
383 static void framerender_iconify(ObFrame
*self
, RrAppearance
*a
)
385 if (!self
->iconify_on
) return;
386 RrPaint(a
, self
->iconify
,
387 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
390 static void framerender_desk(ObFrame
*self
, RrAppearance
*a
)
392 if (!self
->desk_on
) return;
393 RrPaint(a
, self
->desk
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
396 static void framerender_shade(ObFrame
*self
, RrAppearance
*a
)
398 if (!self
->shade_on
) return;
399 RrPaint(a
, self
->shade
,
400 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
403 static void framerender_close(ObFrame
*self
, RrAppearance
*a
)
405 if (!self
->close_on
) return;
406 RrPaint(a
, self
->close
,
407 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);