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 Ben 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
->plate
, px
);
44 XClearWindow(ob_display
, self
->plate
);
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
;
53 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
54 ob_rr_theme
->a_disabled_focused_max
:
55 (self
->client
->max_vert
|| self
->client
->max_horz
?
56 ob_rr_theme
->a_toggled_focused_max
:
58 ob_rr_theme
->a_focused_pressed_max
:
60 ob_rr_theme
->a_hover_focused_max
:
61 ob_rr_theme
->a_focused_unpressed_max
))));
63 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
64 ob_rr_theme
->a_disabled_focused_iconify
:
65 (self
->iconify_press
?
66 ob_rr_theme
->a_focused_pressed_iconify
:
67 (self
->iconify_hover
?
68 ob_rr_theme
->a_hover_focused_iconify
:
69 ob_rr_theme
->a_focused_unpressed_iconify
)));
70 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
71 ob_rr_theme
->a_disabled_focused_desk
:
72 (self
->client
->desktop
== DESKTOP_ALL
?
73 ob_rr_theme
->a_toggled_focused_desk
:
75 ob_rr_theme
->a_focused_pressed_desk
:
77 ob_rr_theme
->a_hover_focused_desk
:
78 ob_rr_theme
->a_focused_unpressed_desk
))));
79 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
80 ob_rr_theme
->a_disabled_focused_shade
:
81 (self
->client
->shaded
?
82 ob_rr_theme
->a_toggled_focused_shade
:
84 ob_rr_theme
->a_focused_pressed_shade
:
86 ob_rr_theme
->a_hover_focused_shade
:
87 ob_rr_theme
->a_focused_unpressed_shade
))));
88 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
89 ob_rr_theme
->a_disabled_focused_close
:
91 ob_rr_theme
->a_focused_pressed_close
:
93 ob_rr_theme
->a_hover_focused_close
:
94 ob_rr_theme
->a_focused_unpressed_close
)));
97 t
= self
->a_unfocused_title
;
98 l
= self
->a_unfocused_label
;
99 m
= (!(self
->decorations
& OB_FRAME_DECOR_MAXIMIZE
) ?
100 ob_rr_theme
->a_disabled_unfocused_max
:
101 (self
->client
->max_vert
|| self
->client
->max_horz
?
102 ob_rr_theme
->a_toggled_unfocused_max
:
104 ob_rr_theme
->a_unfocused_pressed_max
:
106 ob_rr_theme
->a_hover_unfocused_max
:
107 ob_rr_theme
->a_unfocused_unpressed_max
))));
109 i
= (!(self
->decorations
& OB_FRAME_DECOR_ICONIFY
) ?
110 ob_rr_theme
->a_disabled_unfocused_iconify
:
111 (self
->iconify_press
?
112 ob_rr_theme
->a_unfocused_pressed_iconify
:
113 (self
->iconify_hover
?
114 ob_rr_theme
->a_hover_unfocused_iconify
:
115 ob_rr_theme
->a_unfocused_unpressed_iconify
)));
116 d
= (!(self
->decorations
& OB_FRAME_DECOR_ALLDESKTOPS
) ?
117 ob_rr_theme
->a_disabled_unfocused_desk
:
118 (self
->client
->desktop
== DESKTOP_ALL
?
119 ob_rr_theme
->a_toggled_unfocused_desk
:
121 ob_rr_theme
->a_unfocused_pressed_desk
:
123 ob_rr_theme
->a_hover_unfocused_desk
:
124 ob_rr_theme
->a_unfocused_unpressed_desk
))));
125 s
= (!(self
->decorations
& OB_FRAME_DECOR_SHADE
) ?
126 ob_rr_theme
->a_disabled_unfocused_shade
:
127 (self
->client
->shaded
?
128 ob_rr_theme
->a_toggled_unfocused_shade
:
130 ob_rr_theme
->a_unfocused_pressed_shade
:
132 ob_rr_theme
->a_hover_unfocused_shade
:
133 ob_rr_theme
->a_unfocused_unpressed_shade
))));
134 c
= (!(self
->decorations
& OB_FRAME_DECOR_CLOSE
) ?
135 ob_rr_theme
->a_disabled_unfocused_close
:
137 ob_rr_theme
->a_unfocused_pressed_close
:
139 ob_rr_theme
->a_hover_unfocused_close
:
140 ob_rr_theme
->a_unfocused_unpressed_close
)));
143 RrPaint(t
, self
->title
, self
->width
, ob_rr_theme
->title_height
);
145 ob_rr_theme
->a_clear
->surface
.parent
= t
;
146 ob_rr_theme
->a_clear
->surface
.parentx
= 0;
147 ob_rr_theme
->a_clear
->surface
.parenty
= 0;
149 if (ob_rr_theme
->grip_width
> 0)
150 RrPaint(ob_rr_theme
->a_clear
, self
->tltresize
,
151 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
152 if (ob_rr_theme
->title_height
> 0)
153 RrPaint(ob_rr_theme
->a_clear
, self
->tllresize
,
154 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
156 ob_rr_theme
->a_clear
->surface
.parentx
=
157 self
->width
- ob_rr_theme
->grip_width
;
159 if (ob_rr_theme
->grip_width
> 0)
160 RrPaint(ob_rr_theme
->a_clear
, self
->trtresize
,
161 ob_rr_theme
->grip_width
, ob_rr_theme
->paddingy
+ 1);
163 ob_rr_theme
->a_clear
->surface
.parentx
=
164 self
->width
- (ob_rr_theme
->paddingx
+ 1);
166 if (ob_rr_theme
->title_height
> 0)
167 RrPaint(ob_rr_theme
->a_clear
, self
->trrresize
,
168 ob_rr_theme
->paddingx
+ 1, ob_rr_theme
->title_height
);
170 /* set parents for any parent relative guys */
171 l
->surface
.parent
= t
;
172 l
->surface
.parentx
= self
->label_x
;
173 l
->surface
.parenty
= ob_rr_theme
->paddingy
;
175 m
->surface
.parent
= t
;
176 m
->surface
.parentx
= self
->max_x
;
177 m
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
179 n
->surface
.parent
= t
;
180 n
->surface
.parentx
= self
->icon_x
;
181 n
->surface
.parenty
= ob_rr_theme
->paddingy
;
183 i
->surface
.parent
= t
;
184 i
->surface
.parentx
= self
->iconify_x
;
185 i
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
187 d
->surface
.parent
= t
;
188 d
->surface
.parentx
= self
->desk_x
;
189 d
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
191 s
->surface
.parent
= t
;
192 s
->surface
.parentx
= self
->shade_x
;
193 s
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
195 c
->surface
.parent
= t
;
196 c
->surface
.parentx
= self
->close_x
;
197 c
->surface
.parenty
= ob_rr_theme
->paddingy
+ 1;
199 framerender_label(self
, l
);
200 framerender_max(self
, m
);
201 framerender_icon(self
, n
);
202 framerender_iconify(self
, i
);
203 framerender_desk(self
, d
);
204 framerender_shade(self
, s
);
205 framerender_close(self
, c
);
208 if (self
->decorations
& OB_FRAME_DECOR_HANDLE
&&
209 ob_rr_theme
->handle_height
> 0)
214 self
->a_focused_handle
: self
->a_unfocused_handle
);
216 RrPaint(h
, self
->handle
, self
->width
, ob_rr_theme
->handle_height
);
218 if (self
->decorations
& OB_FRAME_DECOR_GRIPS
) {
220 ob_rr_theme
->a_focused_grip
: ob_rr_theme
->a_unfocused_grip
);
222 if (g
->surface
.grad
== RR_SURFACE_PARENTREL
)
223 g
->surface
.parent
= h
;
225 g
->surface
.parentx
= 0;
226 g
->surface
.parenty
= 0;
228 RrPaint(g
, self
->lgrip
,
229 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
231 g
->surface
.parentx
= self
->width
- ob_rr_theme
->grip_width
;
232 g
->surface
.parenty
= 0;
234 RrPaint(g
, self
->rgrip
,
235 ob_rr_theme
->grip_width
, ob_rr_theme
->handle_height
);
242 static void framerender_label(ObFrame
*self
, RrAppearance
*a
)
244 if (self
->label_x
< 0) return;
245 /* set the texture's text! */
246 a
->texture
[0].data
.text
.string
= self
->client
->title
;
247 RrPaint(a
, self
->label
, self
->label_width
, ob_rr_theme
->label_height
);
250 static void framerender_icon(ObFrame
*self
, RrAppearance
*a
)
252 const ObClientIcon
*icon
;
254 if (self
->icon_x
< 0) return;
256 icon
= client_icon(self
->client
,
257 ob_rr_theme
->button_size
+ 2,
258 ob_rr_theme
->button_size
+ 2);
260 a
->texture
[0].type
= RR_TEXTURE_RGBA
;
261 a
->texture
[0].data
.rgba
.width
= icon
->width
;
262 a
->texture
[0].data
.rgba
.height
= icon
->height
;
263 a
->texture
[0].data
.rgba
.data
= icon
->data
;
265 a
->texture
[0].type
= RR_TEXTURE_NONE
;
267 RrPaint(a
, self
->icon
,
268 ob_rr_theme
->button_size
+ 2, ob_rr_theme
->button_size
+ 2);
271 static void framerender_max(ObFrame
*self
, RrAppearance
*a
)
273 if (self
->max_x
< 0) return;
274 RrPaint(a
, self
->max
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
277 static void framerender_iconify(ObFrame
*self
, RrAppearance
*a
)
279 if (self
->iconify_x
< 0) return;
280 RrPaint(a
, self
->iconify
,
281 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
284 static void framerender_desk(ObFrame
*self
, RrAppearance
*a
)
286 if (self
->desk_x
< 0) return;
287 RrPaint(a
, self
->desk
, ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
290 static void framerender_shade(ObFrame
*self
, RrAppearance
*a
)
292 if (self
->shade_x
< 0) return;
293 RrPaint(a
, self
->shade
,
294 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);
297 static void framerender_close(ObFrame
*self
, RrAppearance
*a
)
299 if (self
->close_x
< 0) return;
300 RrPaint(a
, self
->close
,
301 ob_rr_theme
->button_size
, ob_rr_theme
->button_size
);