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 if (self
->decorations
& OB_FRAME_DECOR_TITLEBAR
) {
48 RrAppearance
*t
, *l
, *m
, *n
, *i
, *d
, *s
, *c
;
51 t
= self
->a_focused_title
;
52 l
= self
->a_focused_label
;
54 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
55 ob_rr_theme
->a_disabled_focused_max
:
56 (self
->client
->max_vert
|| self
->client
->max_horz
?
58 ob_rr_theme
->a_toggled_focused_pressed_max
:
60 ob_rr_theme
->a_toggled_hover_focused_max
:
61 ob_rr_theme
->a_toggled_focused_unpressed_max
)) :
63 ob_rr_theme
->a_focused_pressed_max
:
65 ob_rr_theme
->a_hover_focused_max
:
66 ob_rr_theme
->a_focused_unpressed_max
))));
68 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
69 ob_rr_theme
->a_disabled_focused_iconify
:
70 (self
->iconify_press
?
71 ob_rr_theme
->a_focused_pressed_iconify
:
72 (self
->iconify_hover
?
73 ob_rr_theme
->a_hover_focused_iconify
:
74 ob_rr_theme
->a_focused_unpressed_iconify
)));
75 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
76 ob_rr_theme
->a_disabled_focused_desk
:
77 (self
->client
->desktop
== DESKTOP_ALL
?
79 ob_rr_theme
->a_toggled_focused_pressed_desk
:
81 ob_rr_theme
->a_toggled_hover_focused_desk
:
82 ob_rr_theme
->a_toggled_focused_unpressed_desk
)) :
84 ob_rr_theme
->a_focused_pressed_desk
:
86 ob_rr_theme
->a_hover_focused_desk
:
87 ob_rr_theme
->a_focused_unpressed_desk
))));
88 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
89 ob_rr_theme
->a_disabled_focused_shade
:
90 (self
->client
->shaded
?
92 ob_rr_theme
->a_toggled_focused_pressed_shade
:
94 ob_rr_theme
->a_toggled_hover_focused_shade
:
95 ob_rr_theme
->a_toggled_focused_unpressed_shade
)) :
97 ob_rr_theme
->a_focused_pressed_shade
:
99 ob_rr_theme
->a_hover_focused_shade
:
100 ob_rr_theme
->a_focused_unpressed_shade
))));
101 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
102 ob_rr_theme
->a_disabled_focused_close
:
104 ob_rr_theme
->a_focused_pressed_close
:
106 ob_rr_theme
->a_hover_focused_close
:
107 ob_rr_theme
->a_focused_unpressed_close
)));
109 t
= self
->a_unfocused_title
;
110 l
= self
->a_unfocused_label
;
111 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
112 ob_rr_theme
->a_disabled_unfocused_max
:
113 (self
->client
->max_vert
|| self
->client
->max_horz
?
115 ob_rr_theme
->a_toggled_unfocused_pressed_max
:
117 ob_rr_theme
->a_toggled_hover_unfocused_max
:
118 ob_rr_theme
->a_toggled_unfocused_unpressed_max
)) :
120 ob_rr_theme
->a_unfocused_pressed_max
:
122 ob_rr_theme
->a_hover_unfocused_max
:
123 ob_rr_theme
->a_unfocused_unpressed_max
))));
125 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
126 ob_rr_theme
->a_disabled_unfocused_iconify
:
127 (self
->iconify_press
?
128 ob_rr_theme
->a_unfocused_pressed_iconify
:
129 (self
->iconify_hover
?
130 ob_rr_theme
->a_hover_unfocused_iconify
:
131 ob_rr_theme
->a_unfocused_unpressed_iconify
)));
132 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
133 ob_rr_theme
->a_disabled_unfocused_desk
:
134 (self
->client
->desktop
== DESKTOP_ALL
?
136 ob_rr_theme
->a_toggled_unfocused_pressed_desk
:
138 ob_rr_theme
->a_toggled_hover_unfocused_desk
:
139 ob_rr_theme
->a_toggled_unfocused_unpressed_desk
)) :
141 ob_rr_theme
->a_unfocused_pressed_desk
:
143 ob_rr_theme
->a_hover_unfocused_desk
:
144 ob_rr_theme
->a_unfocused_unpressed_desk
))));
145 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
146 ob_rr_theme
->a_disabled_unfocused_shade
:
147 (self
->client
->shaded
?
149 ob_rr_theme
->a_toggled_unfocused_pressed_shade
:
151 ob_rr_theme
->a_toggled_hover_unfocused_shade
:
152 ob_rr_theme
->a_toggled_unfocused_unpressed_shade
)) :
154 ob_rr_theme
->a_unfocused_pressed_shade
:
156 ob_rr_theme
->a_hover_unfocused_shade
:
157 ob_rr_theme
->a_unfocused_unpressed_shade
))));
158 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
159 ob_rr_theme
->a_disabled_unfocused_close
:
161 ob_rr_theme
->a_unfocused_pressed_close
:
163 ob_rr_theme
->a_hover_unfocused_close
:
164 ob_rr_theme
->a_unfocused_unpressed_close
)));
167 RrPaint(t
, self
->title
, self
->width
, ob_rr_theme
->title_height
);
169 ob_rr_theme
->a_clear
->surface
.parent
= t
;
170 ob_rr_theme
->a_clear
->surface
.parentx
= 0;
171 ob_rr_theme
->a_clear
->surface
.parenty
= 0;
173 if (ob_rr_theme
->grip_width
> 0)
174 RrPaint(ob_rr_theme
->a_clear
, self
->tltresize
,
175 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
176 if (ob_rr_theme
->title_height
> 0)
177 RrPaint(ob_rr_theme
->a_clear
, self
->tllresize
,
178 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
180 ob_rr_theme
->a_clear
->surface
.parentx
=
181 self
->width
- ob_rr_theme
->grip_width
;
183 if (ob_rr_theme
->grip_width
> 0)
184 RrPaint(ob_rr_theme
->a_clear
, self
->trtresize
,
185 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
187 ob_rr_theme
->a_clear
->surface
.parentx
=
188 self
->width
- (ob_rr_theme
->paddingx
+ 1);
190 if (ob_rr_theme
->title_height
> 0)
191 RrPaint(ob_rr_theme
->a_clear
, self
->trrresize
,
192 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
194 /* set parents for any parent relative guys */
195 l
->surface
.parent
= t
;
196 l
->surface
.parentx
= self
->label_x
;
197 l
->surface
.parenty
= ob_rr_theme
->paddingy
;
199 m
->surface
.parent
= t
;
200 m
->surface
.parentx
= self
->max_x
;
201 m
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
203 n
->surface
.parent
= t
;
204 n
->surface
.parentx
= self
->icon_x
;
205 n
->surface
.parenty
= ob_rr_theme
->paddingy
;
207 i
->surface
.parent
= t
;
208 i
->surface
.parentx
= self
->iconify_x
;
209 i
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
211 d
->surface
.parent
= t
;
212 d
->surface
.parentx
= self
->desk_x
;
213 d
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
215 s
->surface
.parent
= t
;
216 s
->surface
.parentx
= self
->shade_x
;
217 s
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
219 c
->surface
.parent
= t
;
220 c
->surface
.parentx
= self
->close_x
;
221 c
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
223 framerender_label(self
, l
);
224 framerender_max(self
, m
);
225 framerender_icon(self
, n
);
226 framerender_iconify(self
, i
);
227 framerender_desk(self
, d
);
228 framerender_shade(self
, s
);
229 framerender_close(self
, c
);
232 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
233 ob_rr_theme
->handle_height
> 0)
238 self
->a_focused_handle
: self
->a_unfocused_handle
);
240 RrPaint(h
, self
->handle
, self
->width
, ob_rr_theme
->handle_height
);
242 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
244 ob_rr_theme
->a_focused_grip
: ob_rr_theme
->a_unfocused_grip
);
246 if (g
->surface
.grad
== RR_SURFACE_PARENTREL
)
247 g
->surface
.parent
= h
;
249 g
->surface
.parentx
= 0;
250 g
->surface
.parenty
= 0;
252 RrPaint(g
, self
->lgrip
,
253 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
255 g
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
256 g
->surface
.parenty
= 0;
258 RrPaint(g
, self
->rgrip
,
259 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
266 static void framerender_label(ObFrame
*self
, RrAppearance
*a
)
268 if (self
->label_x
< 0) return;
269 /* set the texture's text! */
270 a
->texture
[0].data
.text
.string
= self
->client
->title
;
271 RrPaint(a
, self
->label
, self
->label_width
, ob_rr_theme
->label_height
);
274 static void framerender_icon(ObFrame
*self
, RrAppearance
*a
)
276 const ObClientIcon
*icon
;
278 if (self
->icon_x
< 0) return;
280 icon
= client_icon(self
->client
,
281 ob_rr_theme
->button_size
+ 2,
282 ob_rr_theme
->button_size
+ 2);
284 a
->texture
[0].type
= RR_TEXTURE_RGBA
;
285 a
->texture
[0].data
.rgba
.width
= icon
->width
;
286 a
->texture
[0].data
.rgba
.height
= icon
->height
;
287 a
->texture
[0].data
.rgba
.data
= icon
->data
;
289 a
->texture
[0].type
= RR_TEXTURE_NONE
;
291 RrPaint(a
, self
->icon
,
292 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
295 static void framerender_max(ObFrame
*self
, RrAppearance
*a
)
297 if (self
->max_x
< 0) return;
298 RrPaint(a
, self
->max
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
301 static void framerender_iconify(ObFrame
*self
, RrAppearance
*a
)
303 if (self
->iconify_x
< 0) return;
304 RrPaint(a
, self
->iconify
,
305 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
308 static void framerender_desk(ObFrame
*self
, RrAppearance
*a
)
310 if (self
->desk_x
< 0) return;
311 RrPaint(a
, self
->desk
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
314 static void framerender_shade(ObFrame
*self
, RrAppearance
*a
)
316 if (self
->shade_x
< 0) return;
317 RrPaint(a
, self
->shade
,
318 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
321 static void framerender_close(ObFrame
*self
, RrAppearance
*a
)
323 if (self
->close_x
< 0) return;
324 RrPaint(a
, self
->close
,
325 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);