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 */
44 RrColorPixel(ob_rr_theme
->cb_focused_color
) :
45 RrColorPixel(ob_rr_theme
->cb_unfocused_color
));
47 XSetWindowBackground(ob_display
, self
->backback
, px
);
48 XClearWindow(ob_display
, self
->backback
);
49 XSetWindowBackground(ob_display
, self
->innerleft
, px
);
50 XClearWindow(ob_display
, self
->innerleft
);
51 XSetWindowBackground(ob_display
, self
->innertop
, px
);
52 XClearWindow(ob_display
, self
->innertop
);
53 XSetWindowBackground(ob_display
, self
->innerright
, px
);
54 XClearWindow(ob_display
, self
->innerright
);
55 XSetWindowBackground(ob_display
, self
->innerbottom
, px
);
56 XClearWindow(ob_display
, self
->innerbottom
);
59 RrColorPixel(ob_rr_theme
->frame_focused_border_color
) :
60 RrColorPixel(ob_rr_theme
->frame_unfocused_border_color
));
62 XSetWindowBackground(ob_display
, self
->left
, px
);
63 XClearWindow(ob_display
, self
->left
);
64 XSetWindowBackground(ob_display
, self
->right
, px
);
65 XClearWindow(ob_display
, self
->right
);
67 XSetWindowBackground(ob_display
, self
->titleleft
, px
);
68 XClearWindow(ob_display
, self
->titleleft
);
69 XSetWindowBackground(ob_display
, self
->titletop
, px
);
70 XClearWindow(ob_display
, self
->titletop
);
71 XSetWindowBackground(ob_display
, self
->titletopleft
, px
);
72 XClearWindow(ob_display
, self
->titletopleft
);
73 XSetWindowBackground(ob_display
, self
->titletopright
, px
);
74 XClearWindow(ob_display
, self
->titletopright
);
75 XSetWindowBackground(ob_display
, self
->titleright
, px
);
76 XClearWindow(ob_display
, self
->titleright
);
78 XSetWindowBackground(ob_display
, self
->handleleft
, px
);
79 XClearWindow(ob_display
, self
->handleleft
);
80 XSetWindowBackground(ob_display
, self
->handletop
, px
);
81 XClearWindow(ob_display
, self
->handletop
);
82 XSetWindowBackground(ob_display
, self
->handleright
, px
);
83 XClearWindow(ob_display
, self
->handleright
);
84 XSetWindowBackground(ob_display
, self
->handlebottom
, px
);
85 XClearWindow(ob_display
, self
->handlebottom
);
87 XSetWindowBackground(ob_display
, self
->lgripleft
, px
);
88 XClearWindow(ob_display
, self
->lgripleft
);
89 XSetWindowBackground(ob_display
, self
->lgriptop
, px
);
90 XClearWindow(ob_display
, self
->lgriptop
);
91 XSetWindowBackground(ob_display
, self
->lgripbottom
, px
);
92 XClearWindow(ob_display
, self
->lgripbottom
);
94 XSetWindowBackground(ob_display
, self
->rgripright
, px
);
95 XClearWindow(ob_display
, self
->rgripright
);
96 XSetWindowBackground(ob_display
, self
->rgriptop
, px
);
97 XClearWindow(ob_display
, self
->rgriptop
);
98 XSetWindowBackground(ob_display
, self
->rgripbottom
, px
);
99 XClearWindow(ob_display
, self
->rgripbottom
);
101 /* don't use the separator color for shaded windows */
102 if (!self
->client
->shaded
)
103 px
= (self
->focused
?
104 RrColorPixel(ob_rr_theme
->title_separator_focused_color
) :
105 RrColorPixel(ob_rr_theme
->title_separator_unfocused_color
));
107 XSetWindowBackground(ob_display
, self
->titlebottom
, px
);
108 XClearWindow(ob_display
, self
->titlebottom
);
111 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
112 RrAppearance
*t
, *l
, *m
, *n
, *i
, *d
, *s
, *c
, *clear
;
115 t
= self
->a_focused_title
;
116 l
= self
->a_focused_label
;
118 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
119 ob_rr_theme
->a_disabled_focused_max
:
120 (self
->client
->max_vert
|| self
->client
->max_horz
?
122 ob_rr_theme
->a_toggled_focused_pressed_max
:
124 ob_rr_theme
->a_toggled_hover_focused_max
:
125 ob_rr_theme
->a_toggled_focused_unpressed_max
)) :
127 ob_rr_theme
->a_focused_pressed_max
:
129 ob_rr_theme
->a_hover_focused_max
:
130 ob_rr_theme
->a_focused_unpressed_max
))));
132 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
133 ob_rr_theme
->a_disabled_focused_iconify
:
134 (self
->iconify_press
?
135 ob_rr_theme
->a_focused_pressed_iconify
:
136 (self
->iconify_hover
?
137 ob_rr_theme
->a_hover_focused_iconify
:
138 ob_rr_theme
->a_focused_unpressed_iconify
)));
139 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
140 ob_rr_theme
->a_disabled_focused_desk
:
141 (self
->client
->desktop
== DESKTOP_ALL
?
143 ob_rr_theme
->a_toggled_focused_pressed_desk
:
145 ob_rr_theme
->a_toggled_hover_focused_desk
:
146 ob_rr_theme
->a_toggled_focused_unpressed_desk
)) :
148 ob_rr_theme
->a_focused_pressed_desk
:
150 ob_rr_theme
->a_hover_focused_desk
:
151 ob_rr_theme
->a_focused_unpressed_desk
))));
152 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
153 ob_rr_theme
->a_disabled_focused_shade
:
154 (self
->client
->shaded
?
156 ob_rr_theme
->a_toggled_focused_pressed_shade
:
158 ob_rr_theme
->a_toggled_hover_focused_shade
:
159 ob_rr_theme
->a_toggled_focused_unpressed_shade
)) :
161 ob_rr_theme
->a_focused_pressed_shade
:
163 ob_rr_theme
->a_hover_focused_shade
:
164 ob_rr_theme
->a_focused_unpressed_shade
))));
165 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
166 ob_rr_theme
->a_disabled_focused_close
:
168 ob_rr_theme
->a_focused_pressed_close
:
170 ob_rr_theme
->a_hover_focused_close
:
171 ob_rr_theme
->a_focused_unpressed_close
)));
173 t
= self
->a_unfocused_title
;
174 l
= self
->a_unfocused_label
;
175 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
176 ob_rr_theme
->a_disabled_unfocused_max
:
177 (self
->client
->max_vert
|| self
->client
->max_horz
?
179 ob_rr_theme
->a_toggled_unfocused_pressed_max
:
181 ob_rr_theme
->a_toggled_hover_unfocused_max
:
182 ob_rr_theme
->a_toggled_unfocused_unpressed_max
)) :
184 ob_rr_theme
->a_unfocused_pressed_max
:
186 ob_rr_theme
->a_hover_unfocused_max
:
187 ob_rr_theme
->a_unfocused_unpressed_max
))));
189 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
190 ob_rr_theme
->a_disabled_unfocused_iconify
:
191 (self
->iconify_press
?
192 ob_rr_theme
->a_unfocused_pressed_iconify
:
193 (self
->iconify_hover
?
194 ob_rr_theme
->a_hover_unfocused_iconify
:
195 ob_rr_theme
->a_unfocused_unpressed_iconify
)));
196 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
197 ob_rr_theme
->a_disabled_unfocused_desk
:
198 (self
->client
->desktop
== DESKTOP_ALL
?
200 ob_rr_theme
->a_toggled_unfocused_pressed_desk
:
202 ob_rr_theme
->a_toggled_hover_unfocused_desk
:
203 ob_rr_theme
->a_toggled_unfocused_unpressed_desk
)) :
205 ob_rr_theme
->a_unfocused_pressed_desk
:
207 ob_rr_theme
->a_hover_unfocused_desk
:
208 ob_rr_theme
->a_unfocused_unpressed_desk
))));
209 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
210 ob_rr_theme
->a_disabled_unfocused_shade
:
211 (self
->client
->shaded
?
213 ob_rr_theme
->a_toggled_unfocused_pressed_shade
:
215 ob_rr_theme
->a_toggled_hover_unfocused_shade
:
216 ob_rr_theme
->a_toggled_unfocused_unpressed_shade
)) :
218 ob_rr_theme
->a_unfocused_pressed_shade
:
220 ob_rr_theme
->a_hover_unfocused_shade
:
221 ob_rr_theme
->a_unfocused_unpressed_shade
))));
222 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
223 ob_rr_theme
->a_disabled_unfocused_close
:
225 ob_rr_theme
->a_unfocused_pressed_close
:
227 ob_rr_theme
->a_hover_unfocused_close
:
228 ob_rr_theme
->a_unfocused_unpressed_close
)));
230 clear
= ob_rr_theme
->a_clear
;
232 RrPaint(t
, self
->title
, self
->width
, ob_rr_theme
->title_height
);
234 clear
->surface
.parent
= t
;
235 clear
->surface
.parenty
= 0;
237 clear
->surface
.parentx
= ob_rr_theme
->grip_width
;
239 RrPaint(clear
, self
->topresize
,
240 self
->width
- ob_rr_theme
->grip_width
* 2,
241 ob_rr_theme
->paddingy
+ 1);
243 clear
->surface
.parentx
= 0;
245 if (ob_rr_theme
->grip_width
> 0)
246 RrPaint(clear
, self
->tltresize
,
247 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
248 if (ob_rr_theme
->title_height
> 0)
249 RrPaint(clear
, self
->tllresize
,
250 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
252 clear
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
254 if (ob_rr_theme
->grip_width
> 0)
255 RrPaint(clear
, self
->trtresize
,
256 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
258 clear
->surface
.parentx
= self
->width
- (ob_rr_theme
->paddingx
+ 1);
260 if (ob_rr_theme
->title_height
> 0)
261 RrPaint(clear
, self
->trrresize
,
262 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
264 /* set parents for any parent relative guys */
265 l
->surface
.parent
= t
;
266 l
->surface
.parentx
= self
->label_x
;
267 l
->surface
.parenty
= ob_rr_theme
->paddingy
;
269 m
->surface
.parent
= t
;
270 m
->surface
.parentx
= self
->max_x
;
271 m
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
273 n
->surface
.parent
= t
;
274 n
->surface
.parentx
= self
->icon_x
;
275 n
->surface
.parenty
= ob_rr_theme
->paddingy
;
277 i
->surface
.parent
= t
;
278 i
->surface
.parentx
= self
->iconify_x
;
279 i
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
281 d
->surface
.parent
= t
;
282 d
->surface
.parentx
= self
->desk_x
;
283 d
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
285 s
->surface
.parent
= t
;
286 s
->surface
.parentx
= self
->shade_x
;
287 s
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
289 c
->surface
.parent
= t
;
290 c
->surface
.parentx
= self
->close_x
;
291 c
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
293 framerender_label(self
, l
);
294 framerender_max(self
, m
);
295 framerender_icon(self
, n
);
296 framerender_iconify(self
, i
);
297 framerender_desk(self
, d
);
298 framerender_shade(self
, s
);
299 framerender_close(self
, c
);
302 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
303 ob_rr_theme
->handle_height
> 0)
308 self
->a_focused_handle
: self
->a_unfocused_handle
);
310 RrPaint(h
, self
->handle
, self
->width
, ob_rr_theme
->handle_height
);
312 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
314 ob_rr_theme
->a_focused_grip
: ob_rr_theme
->a_unfocused_grip
);
316 if (g
->surface
.grad
== RR_SURFACE_PARENTREL
)
317 g
->surface
.parent
= h
;
319 g
->surface
.parentx
= 0;
320 g
->surface
.parenty
= 0;
322 RrPaint(g
, self
->lgrip
,
323 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
325 g
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
326 g
->surface
.parenty
= 0;
328 RrPaint(g
, self
->rgrip
,
329 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
336 static void framerender_label(ObFrame
*self
, RrAppearance
*a
)
338 if (!self
->label_on
) return;
339 /* set the texture's text! */
340 a
->texture
[0].data
.text
.string
= self
->client
->title
;
341 RrPaint(a
, self
->label
, self
->label_width
, ob_rr_theme
->label_height
);
344 static void framerender_icon(ObFrame
*self
, RrAppearance
*a
)
346 const ObClientIcon
*icon
;
348 if (!self
->icon_on
) return;
350 icon
= client_icon(self
->client
,
351 ob_rr_theme
->button_size
+ 2,
352 ob_rr_theme
->button_size
+ 2);
354 a
->texture
[0].type
= RR_TEXTURE_RGBA
;
355 a
->texture
[0].data
.rgba
.width
= icon
->width
;
356 a
->texture
[0].data
.rgba
.height
= icon
->height
;
357 a
->texture
[0].data
.rgba
.alpha
= 0xff;
358 a
->texture
[0].data
.rgba
.data
= icon
->data
;
360 a
->texture
[0].type
= RR_TEXTURE_NONE
;
362 RrPaint(a
, self
->icon
,
363 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
366 static void framerender_max(ObFrame
*self
, RrAppearance
*a
)
368 if (!self
->max_on
) return;
369 RrPaint(a
, self
->max
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
372 static void framerender_iconify(ObFrame
*self
, RrAppearance
*a
)
374 if (!self
->iconify_on
) return;
375 RrPaint(a
, self
->iconify
,
376 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
379 static void framerender_desk(ObFrame
*self
, RrAppearance
*a
)
381 if (!self
->desk_on
) return;
382 RrPaint(a
, self
->desk
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
385 static void framerender_shade(ObFrame
*self
, RrAppearance
*a
)
387 if (!self
->shade_on
) return;
388 RrPaint(a
, self
->shade
,
389 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
392 static void framerender_close(ObFrame
*self
, RrAppearance
*a
)
394 if (!self
->close_on
) return;
395 RrPaint(a
, self
->close
,
396 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);