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
);
74 XSetWindowBackground(ob_display
, self
->titlebottom
, px
);
75 XClearWindow(ob_display
, self
->titlebottom
);
77 XSetWindowBackground(ob_display
, self
->handleleft
, px
);
78 XClearWindow(ob_display
, self
->handleleft
);
79 XSetWindowBackground(ob_display
, self
->handletop
, px
);
80 XClearWindow(ob_display
, self
->handletop
);
81 XSetWindowBackground(ob_display
, self
->handleright
, px
);
82 XClearWindow(ob_display
, self
->handleright
);
83 XSetWindowBackground(ob_display
, self
->handlebottom
, px
);
84 XClearWindow(ob_display
, self
->handlebottom
);
86 XSetWindowBackground(ob_display
, self
->lgripleft
, px
);
87 XClearWindow(ob_display
, self
->lgripleft
);
88 XSetWindowBackground(ob_display
, self
->lgriptop
, px
);
89 XClearWindow(ob_display
, self
->lgriptop
);
90 XSetWindowBackground(ob_display
, self
->lgripbottom
, px
);
91 XClearWindow(ob_display
, self
->lgripbottom
);
93 XSetWindowBackground(ob_display
, self
->rgripright
, px
);
94 XClearWindow(ob_display
, self
->rgripright
);
95 XSetWindowBackground(ob_display
, self
->rgriptop
, px
);
96 XClearWindow(ob_display
, self
->rgriptop
);
97 XSetWindowBackground(ob_display
, self
->rgripbottom
, px
);
98 XClearWindow(ob_display
, self
->rgripbottom
);
101 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
102 RrAppearance
*t
, *l
, *m
, *n
, *i
, *d
, *s
, *c
, *clear
;
105 t
= self
->a_focused_title
;
106 l
= self
->a_focused_label
;
108 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
109 ob_rr_theme
->a_disabled_focused_max
:
110 (self
->client
->max_vert
|| self
->client
->max_horz
?
112 ob_rr_theme
->a_toggled_focused_pressed_max
:
114 ob_rr_theme
->a_toggled_hover_focused_max
:
115 ob_rr_theme
->a_toggled_focused_unpressed_max
)) :
117 ob_rr_theme
->a_focused_pressed_max
:
119 ob_rr_theme
->a_hover_focused_max
:
120 ob_rr_theme
->a_focused_unpressed_max
))));
122 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
123 ob_rr_theme
->a_disabled_focused_iconify
:
124 (self
->iconify_press
?
125 ob_rr_theme
->a_focused_pressed_iconify
:
126 (self
->iconify_hover
?
127 ob_rr_theme
->a_hover_focused_iconify
:
128 ob_rr_theme
->a_focused_unpressed_iconify
)));
129 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
130 ob_rr_theme
->a_disabled_focused_desk
:
131 (self
->client
->desktop
== DESKTOP_ALL
?
133 ob_rr_theme
->a_toggled_focused_pressed_desk
:
135 ob_rr_theme
->a_toggled_hover_focused_desk
:
136 ob_rr_theme
->a_toggled_focused_unpressed_desk
)) :
138 ob_rr_theme
->a_focused_pressed_desk
:
140 ob_rr_theme
->a_hover_focused_desk
:
141 ob_rr_theme
->a_focused_unpressed_desk
))));
142 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
143 ob_rr_theme
->a_disabled_focused_shade
:
144 (self
->client
->shaded
?
146 ob_rr_theme
->a_toggled_focused_pressed_shade
:
148 ob_rr_theme
->a_toggled_hover_focused_shade
:
149 ob_rr_theme
->a_toggled_focused_unpressed_shade
)) :
151 ob_rr_theme
->a_focused_pressed_shade
:
153 ob_rr_theme
->a_hover_focused_shade
:
154 ob_rr_theme
->a_focused_unpressed_shade
))));
155 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
156 ob_rr_theme
->a_disabled_focused_close
:
158 ob_rr_theme
->a_focused_pressed_close
:
160 ob_rr_theme
->a_hover_focused_close
:
161 ob_rr_theme
->a_focused_unpressed_close
)));
163 t
= self
->a_unfocused_title
;
164 l
= self
->a_unfocused_label
;
165 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
166 ob_rr_theme
->a_disabled_unfocused_max
:
167 (self
->client
->max_vert
|| self
->client
->max_horz
?
169 ob_rr_theme
->a_toggled_unfocused_pressed_max
:
171 ob_rr_theme
->a_toggled_hover_unfocused_max
:
172 ob_rr_theme
->a_toggled_unfocused_unpressed_max
)) :
174 ob_rr_theme
->a_unfocused_pressed_max
:
176 ob_rr_theme
->a_hover_unfocused_max
:
177 ob_rr_theme
->a_unfocused_unpressed_max
))));
179 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
180 ob_rr_theme
->a_disabled_unfocused_iconify
:
181 (self
->iconify_press
?
182 ob_rr_theme
->a_unfocused_pressed_iconify
:
183 (self
->iconify_hover
?
184 ob_rr_theme
->a_hover_unfocused_iconify
:
185 ob_rr_theme
->a_unfocused_unpressed_iconify
)));
186 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
187 ob_rr_theme
->a_disabled_unfocused_desk
:
188 (self
->client
->desktop
== DESKTOP_ALL
?
190 ob_rr_theme
->a_toggled_unfocused_pressed_desk
:
192 ob_rr_theme
->a_toggled_hover_unfocused_desk
:
193 ob_rr_theme
->a_toggled_unfocused_unpressed_desk
)) :
195 ob_rr_theme
->a_unfocused_pressed_desk
:
197 ob_rr_theme
->a_hover_unfocused_desk
:
198 ob_rr_theme
->a_unfocused_unpressed_desk
))));
199 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
200 ob_rr_theme
->a_disabled_unfocused_shade
:
201 (self
->client
->shaded
?
203 ob_rr_theme
->a_toggled_unfocused_pressed_shade
:
205 ob_rr_theme
->a_toggled_hover_unfocused_shade
:
206 ob_rr_theme
->a_toggled_unfocused_unpressed_shade
)) :
208 ob_rr_theme
->a_unfocused_pressed_shade
:
210 ob_rr_theme
->a_hover_unfocused_shade
:
211 ob_rr_theme
->a_unfocused_unpressed_shade
))));
212 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
213 ob_rr_theme
->a_disabled_unfocused_close
:
215 ob_rr_theme
->a_unfocused_pressed_close
:
217 ob_rr_theme
->a_hover_unfocused_close
:
218 ob_rr_theme
->a_unfocused_unpressed_close
)));
220 clear
= ob_rr_theme
->a_clear
;
222 RrPaint(t
, self
->title
, self
->width
, ob_rr_theme
->title_height
);
224 clear
->surface
.parent
= t
;
225 clear
->surface
.parenty
= 0;
227 clear
->surface
.parentx
= ob_rr_theme
->grip_width
;
229 RrPaint(clear
, self
->topresize
,
230 self
->width
- ob_rr_theme
->grip_width
* 2,
231 ob_rr_theme
->paddingy
+ 1);
233 clear
->surface
.parentx
= 0;
235 if (ob_rr_theme
->grip_width
> 0)
236 RrPaint(clear
, self
->tltresize
,
237 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
238 if (ob_rr_theme
->title_height
> 0)
239 RrPaint(clear
, self
->tllresize
,
240 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
242 clear
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
244 if (ob_rr_theme
->grip_width
> 0)
245 RrPaint(clear
, self
->trtresize
,
246 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
248 clear
->surface
.parentx
= self
->width
- (ob_rr_theme
->paddingx
+ 1);
250 if (ob_rr_theme
->title_height
> 0)
251 RrPaint(clear
, self
->trrresize
,
252 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
254 /* set parents for any parent relative guys */
255 l
->surface
.parent
= t
;
256 l
->surface
.parentx
= self
->label_x
;
257 l
->surface
.parenty
= ob_rr_theme
->paddingy
;
259 m
->surface
.parent
= t
;
260 m
->surface
.parentx
= self
->max_x
;
261 m
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
263 n
->surface
.parent
= t
;
264 n
->surface
.parentx
= self
->icon_x
;
265 n
->surface
.parenty
= ob_rr_theme
->paddingy
;
267 i
->surface
.parent
= t
;
268 i
->surface
.parentx
= self
->iconify_x
;
269 i
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
271 d
->surface
.parent
= t
;
272 d
->surface
.parentx
= self
->desk_x
;
273 d
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
275 s
->surface
.parent
= t
;
276 s
->surface
.parentx
= self
->shade_x
;
277 s
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
279 c
->surface
.parent
= t
;
280 c
->surface
.parentx
= self
->close_x
;
281 c
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
283 framerender_label(self
, l
);
284 framerender_max(self
, m
);
285 framerender_icon(self
, n
);
286 framerender_iconify(self
, i
);
287 framerender_desk(self
, d
);
288 framerender_shade(self
, s
);
289 framerender_close(self
, c
);
292 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
293 ob_rr_theme
->handle_height
> 0)
298 self
->a_focused_handle
: self
->a_unfocused_handle
);
300 RrPaint(h
, self
->handle
, self
->width
, ob_rr_theme
->handle_height
);
302 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
304 ob_rr_theme
->a_focused_grip
: ob_rr_theme
->a_unfocused_grip
);
306 if (g
->surface
.grad
== RR_SURFACE_PARENTREL
)
307 g
->surface
.parent
= h
;
309 g
->surface
.parentx
= 0;
310 g
->surface
.parenty
= 0;
312 RrPaint(g
, self
->lgrip
,
313 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
315 g
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
316 g
->surface
.parenty
= 0;
318 RrPaint(g
, self
->rgrip
,
319 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
326 static void framerender_label(ObFrame
*self
, RrAppearance
*a
)
328 if (!self
->label_on
) return;
329 /* set the texture's text! */
330 a
->texture
[0].data
.text
.string
= self
->client
->title
;
331 RrPaint(a
, self
->label
, self
->label_width
, ob_rr_theme
->label_height
);
334 static void framerender_icon(ObFrame
*self
, RrAppearance
*a
)
336 const ObClientIcon
*icon
;
338 if (!self
->icon_on
) return;
340 icon
= client_icon(self
->client
,
341 ob_rr_theme
->button_size
+ 2,
342 ob_rr_theme
->button_size
+ 2);
344 a
->texture
[0].type
= RR_TEXTURE_RGBA
;
345 a
->texture
[0].data
.rgba
.width
= icon
->width
;
346 a
->texture
[0].data
.rgba
.height
= icon
->height
;
347 a
->texture
[0].data
.rgba
.alpha
= 0xff;
348 a
->texture
[0].data
.rgba
.data
= icon
->data
;
350 a
->texture
[0].type
= RR_TEXTURE_NONE
;
352 RrPaint(a
, self
->icon
,
353 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
356 static void framerender_max(ObFrame
*self
, RrAppearance
*a
)
358 if (!self
->max_on
) return;
359 RrPaint(a
, self
->max
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
362 static void framerender_iconify(ObFrame
*self
, RrAppearance
*a
)
364 if (!self
->iconify_on
) return;
365 RrPaint(a
, self
->iconify
,
366 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
369 static void framerender_desk(ObFrame
*self
, RrAppearance
*a
)
371 if (!self
->desk_on
) return;
372 RrPaint(a
, self
->desk
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
375 static void framerender_shade(ObFrame
*self
, RrAppearance
*a
)
377 if (!self
->shade_on
) return;
378 RrPaint(a
, self
->shade
,
379 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
382 static void framerender_close(ObFrame
*self
, RrAppearance
*a
)
384 if (!self
->close_on
) return;
385 RrPaint(a
, self
->close
,
386 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);