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
));
49 XSetWindowBorder(ob_display
, self
->window
, px
);
50 XSetWindowBorder(ob_display
, self
->inner
, px
);
51 XSetWindowBorder(ob_display
, self
->title
, px
);
52 XSetWindowBorder(ob_display
, self
->handle
, px
);
53 XSetWindowBorder(ob_display
, self
->rgrip
, px
);
54 XSetWindowBorder(ob_display
, self
->lgrip
, px
);
57 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
58 RrAppearance
*t
, *l
, *m
, *n
, *i
, *d
, *s
, *c
;
61 t
= self
->a_focused_title
;
62 l
= self
->a_focused_label
;
64 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
65 ob_rr_theme
->a_disabled_focused_max
:
66 (self
->client
->max_vert
|| self
->client
->max_horz
?
68 ob_rr_theme
->a_toggled_focused_pressed_max
:
70 ob_rr_theme
->a_toggled_hover_focused_max
:
71 ob_rr_theme
->a_toggled_focused_unpressed_max
)) :
73 ob_rr_theme
->a_focused_pressed_max
:
75 ob_rr_theme
->a_hover_focused_max
:
76 ob_rr_theme
->a_focused_unpressed_max
))));
78 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
79 ob_rr_theme
->a_disabled_focused_iconify
:
80 (self
->iconify_press
?
81 ob_rr_theme
->a_focused_pressed_iconify
:
82 (self
->iconify_hover
?
83 ob_rr_theme
->a_hover_focused_iconify
:
84 ob_rr_theme
->a_focused_unpressed_iconify
)));
85 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
86 ob_rr_theme
->a_disabled_focused_desk
:
87 (self
->client
->desktop
== DESKTOP_ALL
?
89 ob_rr_theme
->a_toggled_focused_pressed_desk
:
91 ob_rr_theme
->a_toggled_hover_focused_desk
:
92 ob_rr_theme
->a_toggled_focused_unpressed_desk
)) :
94 ob_rr_theme
->a_focused_pressed_desk
:
96 ob_rr_theme
->a_hover_focused_desk
:
97 ob_rr_theme
->a_focused_unpressed_desk
))));
98 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
99 ob_rr_theme
->a_disabled_focused_shade
:
100 (self
->client
->shaded
?
102 ob_rr_theme
->a_toggled_focused_pressed_shade
:
104 ob_rr_theme
->a_toggled_hover_focused_shade
:
105 ob_rr_theme
->a_toggled_focused_unpressed_shade
)) :
107 ob_rr_theme
->a_focused_pressed_shade
:
109 ob_rr_theme
->a_hover_focused_shade
:
110 ob_rr_theme
->a_focused_unpressed_shade
))));
111 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
112 ob_rr_theme
->a_disabled_focused_close
:
114 ob_rr_theme
->a_focused_pressed_close
:
116 ob_rr_theme
->a_hover_focused_close
:
117 ob_rr_theme
->a_focused_unpressed_close
)));
119 t
= self
->a_unfocused_title
;
120 l
= self
->a_unfocused_label
;
121 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
122 ob_rr_theme
->a_disabled_unfocused_max
:
123 (self
->client
->max_vert
|| self
->client
->max_horz
?
125 ob_rr_theme
->a_toggled_unfocused_pressed_max
:
127 ob_rr_theme
->a_toggled_hover_unfocused_max
:
128 ob_rr_theme
->a_toggled_unfocused_unpressed_max
)) :
130 ob_rr_theme
->a_unfocused_pressed_max
:
132 ob_rr_theme
->a_hover_unfocused_max
:
133 ob_rr_theme
->a_unfocused_unpressed_max
))));
135 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
136 ob_rr_theme
->a_disabled_unfocused_iconify
:
137 (self
->iconify_press
?
138 ob_rr_theme
->a_unfocused_pressed_iconify
:
139 (self
->iconify_hover
?
140 ob_rr_theme
->a_hover_unfocused_iconify
:
141 ob_rr_theme
->a_unfocused_unpressed_iconify
)));
142 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
143 ob_rr_theme
->a_disabled_unfocused_desk
:
144 (self
->client
->desktop
== DESKTOP_ALL
?
146 ob_rr_theme
->a_toggled_unfocused_pressed_desk
:
148 ob_rr_theme
->a_toggled_hover_unfocused_desk
:
149 ob_rr_theme
->a_toggled_unfocused_unpressed_desk
)) :
151 ob_rr_theme
->a_unfocused_pressed_desk
:
153 ob_rr_theme
->a_hover_unfocused_desk
:
154 ob_rr_theme
->a_unfocused_unpressed_desk
))));
155 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
156 ob_rr_theme
->a_disabled_unfocused_shade
:
157 (self
->client
->shaded
?
159 ob_rr_theme
->a_toggled_unfocused_pressed_shade
:
161 ob_rr_theme
->a_toggled_hover_unfocused_shade
:
162 ob_rr_theme
->a_toggled_unfocused_unpressed_shade
)) :
164 ob_rr_theme
->a_unfocused_pressed_shade
:
166 ob_rr_theme
->a_hover_unfocused_shade
:
167 ob_rr_theme
->a_unfocused_unpressed_shade
))));
168 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
169 ob_rr_theme
->a_disabled_unfocused_close
:
171 ob_rr_theme
->a_unfocused_pressed_close
:
173 ob_rr_theme
->a_hover_unfocused_close
:
174 ob_rr_theme
->a_unfocused_unpressed_close
)));
177 RrPaint(t
, self
->title
, self
->width
, ob_rr_theme
->title_height
);
179 ob_rr_theme
->a_clear
->surface
.parent
= t
;
180 ob_rr_theme
->a_clear
->surface
.parenty
= 0;
182 ob_rr_theme
->a_clear
->surface
.parentx
= ob_rr_theme
->grip_width
+
184 RrPaint(ob_rr_theme
->a_clear
, self
->topresize
,
185 self
->width
- (ob_rr_theme
->grip_width
+ self
->bwidth
) * 2,
186 ob_rr_theme
->paddingy
+ 1);
188 ob_rr_theme
->a_clear
->surface
.parentx
= 0;
190 if (ob_rr_theme
->grip_width
> 0)
191 RrPaint(ob_rr_theme
->a_clear
, self
->tltresize
,
192 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
193 if (ob_rr_theme
->title_height
> 0)
194 RrPaint(ob_rr_theme
->a_clear
, self
->tllresize
,
195 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
197 ob_rr_theme
->a_clear
->surface
.parentx
=
198 self
->width
- ob_rr_theme
->grip_width
;
200 if (ob_rr_theme
->grip_width
> 0)
201 RrPaint(ob_rr_theme
->a_clear
, self
->trtresize
,
202 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
204 ob_rr_theme
->a_clear
->surface
.parentx
=
205 self
->width
- (ob_rr_theme
->paddingx
+ 1);
207 if (ob_rr_theme
->title_height
> 0)
208 RrPaint(ob_rr_theme
->a_clear
, self
->trrresize
,
209 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
211 /* set parents for any parent relative guys */
212 l
->surface
.parent
= t
;
213 l
->surface
.parentx
= self
->label_x
;
214 l
->surface
.parenty
= ob_rr_theme
->paddingy
;
216 m
->surface
.parent
= t
;
217 m
->surface
.parentx
= self
->max_x
;
218 m
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
220 n
->surface
.parent
= t
;
221 n
->surface
.parentx
= self
->icon_x
;
222 n
->surface
.parenty
= ob_rr_theme
->paddingy
;
224 i
->surface
.parent
= t
;
225 i
->surface
.parentx
= self
->iconify_x
;
226 i
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
228 d
->surface
.parent
= t
;
229 d
->surface
.parentx
= self
->desk_x
;
230 d
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
232 s
->surface
.parent
= t
;
233 s
->surface
.parentx
= self
->shade_x
;
234 s
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
236 c
->surface
.parent
= t
;
237 c
->surface
.parentx
= self
->close_x
;
238 c
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
240 framerender_label(self
, l
);
241 framerender_max(self
, m
);
242 framerender_icon(self
, n
);
243 framerender_iconify(self
, i
);
244 framerender_desk(self
, d
);
245 framerender_shade(self
, s
);
246 framerender_close(self
, c
);
249 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
250 ob_rr_theme
->handle_height
> 0)
255 self
->a_focused_handle
: self
->a_unfocused_handle
);
257 RrPaint(h
, self
->handle
, self
->width
, ob_rr_theme
->handle_height
);
259 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
261 ob_rr_theme
->a_focused_grip
: ob_rr_theme
->a_unfocused_grip
);
263 if (g
->surface
.grad
== RR_SURFACE_PARENTREL
)
264 g
->surface
.parent
= h
;
266 g
->surface
.parentx
= 0;
267 g
->surface
.parenty
= 0;
269 RrPaint(g
, self
->lgrip
,
270 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
272 g
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
273 g
->surface
.parenty
= 0;
275 RrPaint(g
, self
->rgrip
,
276 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
283 static void framerender_label(ObFrame
*self
, RrAppearance
*a
)
285 if (!self
->label_on
) return;
286 /* set the texture's text! */
287 a
->texture
[0].data
.text
.string
= self
->client
->title
;
288 RrPaint(a
, self
->label
, self
->label_width
, ob_rr_theme
->label_height
);
291 static void framerender_icon(ObFrame
*self
, RrAppearance
*a
)
293 const ObClientIcon
*icon
;
295 if (!self
->icon_on
) return;
297 icon
= client_icon(self
->client
,
298 ob_rr_theme
->button_size
+ 2,
299 ob_rr_theme
->button_size
+ 2);
301 a
->texture
[0].type
= RR_TEXTURE_RGBA
;
302 a
->texture
[0].data
.rgba
.width
= icon
->width
;
303 a
->texture
[0].data
.rgba
.height
= icon
->height
;
304 a
->texture
[0].data
.rgba
.data
= icon
->data
;
306 a
->texture
[0].type
= RR_TEXTURE_NONE
;
308 RrPaint(a
, self
->icon
,
309 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
312 static void framerender_max(ObFrame
*self
, RrAppearance
*a
)
314 if (!self
->max_on
) return;
315 RrPaint(a
, self
->max
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
318 static void framerender_iconify(ObFrame
*self
, RrAppearance
*a
)
320 if (!self
->iconify_on
) return;
321 RrPaint(a
, self
->iconify
,
322 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
325 static void framerender_desk(ObFrame
*self
, RrAppearance
*a
)
327 if (!self
->desk_on
) return;
328 RrPaint(a
, self
->desk
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
331 static void framerender_shade(ObFrame
*self
, RrAppearance
*a
)
333 if (!self
->shade_on
) return;
334 RrPaint(a
, self
->shade
,
335 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
338 static void framerender_close(ObFrame
*self
, RrAppearance
*a
)
340 if (!self
->close_on
) return;
341 RrPaint(a
, self
->close
,
342 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);