8 #include <X11/Xresource.h>
10 static XrmDatabase
loaddb(RrTheme
*theme
, char *name
);
11 static gboolean
read_int(XrmDatabase db
, char *rname
, int *value
);
12 static gboolean
read_string(XrmDatabase db
, char *rname
, char **value
);
13 static gboolean
read_color(XrmDatabase db
, const RrInstance
*inst
,
14 gchar
*rname
, RrColor
**value
);
15 static gboolean
read_mask(const RrInstance
*inst
,
16 gchar
*maskname
, RrTheme
*theme
,
17 RrPixmapMask
**value
);
18 static gboolean
read_appearance(XrmDatabase db
, const RrInstance
*inst
,
19 gchar
*rname
, RrAppearance
*value
);
20 static void set_default_appearance(RrAppearance
*a
);
22 RrTheme
* RrThemeNew(const RrInstance
*inst
, gchar
*name
)
24 XrmDatabase db
= NULL
;
25 RrJustify winjust
, mtitlejust
, mjust
;
30 theme
= g_new0(RrTheme
, 1);
34 theme
->a_disabled_focused_max
= RrAppearanceNew(inst
, 1);
35 theme
->a_disabled_unfocused_max
= RrAppearanceNew(inst
, 1);
36 theme
->a_focused_unpressed_max
= RrAppearanceNew(inst
, 1);
37 theme
->a_focused_pressed_max
= RrAppearanceNew(inst
, 1);
38 theme
->a_focused_pressed_set_max
= RrAppearanceNew(inst
, 1);
39 theme
->a_unfocused_unpressed_max
= RrAppearanceNew(inst
, 1);
40 theme
->a_unfocused_pressed_max
= RrAppearanceNew(inst
, 1);
41 theme
->a_unfocused_pressed_set_max
= RrAppearanceNew(inst
, 1);
42 theme
->a_focused_grip
= RrAppearanceNew(inst
, 0);
43 theme
->a_unfocused_grip
= RrAppearanceNew(inst
, 0);
44 theme
->a_focused_title
= RrAppearanceNew(inst
, 0);
45 theme
->a_unfocused_title
= RrAppearanceNew(inst
, 0);
46 theme
->a_focused_label
= RrAppearanceNew(inst
, 1);
47 theme
->a_unfocused_label
= RrAppearanceNew(inst
, 1);
48 theme
->a_icon
= RrAppearanceNew(inst
, 1);
49 theme
->a_focused_handle
= RrAppearanceNew(inst
, 0);
50 theme
->a_unfocused_handle
= RrAppearanceNew(inst
, 0);
51 theme
->a_menu
= RrAppearanceNew(inst
, 0);
52 theme
->a_menu_title
= RrAppearanceNew(inst
, 1);
53 theme
->a_menu_item
= RrAppearanceNew(inst
, 1);
54 theme
->a_menu_disabled
= RrAppearanceNew(inst
, 1);
55 theme
->a_menu_hilite
= RrAppearanceNew(inst
, 1);
57 theme
->app_hilite_bg
= RrAppearanceNew(inst
, 0);
58 theme
->app_unhilite_bg
= RrAppearanceNew(inst
, 0);
59 theme
->app_hilite_label
= RrAppearanceNew(inst
, 1);
60 theme
->app_unhilite_label
= RrAppearanceNew(inst
, 1);
61 theme
->app_icon
= RrAppearanceNew(inst
, 1);
64 db
= loaddb(theme
, name
);
66 g_warning("Failed to load the theme '%s'", name
);
67 g_message("Falling back to the default: '%s'", DEFAULT_THEME
);
69 theme
->name
= g_path_get_basename(name
);
72 db
= loaddb(theme
, DEFAULT_THEME
);
74 g_warning("Failed to load the theme '%s'.", DEFAULT_THEME
);
77 theme
->name
= g_path_get_basename(DEFAULT_THEME
);
80 /* load the font stuff */
81 if (!read_string(db
, "window.title.xftfont", &font_str
))
82 font_str
= "arial,sans:bold:pixelsize=10:shadow=y:shadowtint=50";
84 if (!(theme
->winfont
= RrFontOpen(inst
, font_str
))) {
88 theme
->winfont_height
= RrFontHeight(theme
->winfont
);
90 winjust
= RR_JUSTIFY_LEFT
;
91 if (read_string(db
, "window.justify", &str
)) {
92 if (!g_ascii_strcasecmp(str
, "right"))
93 winjust
= RR_JUSTIFY_RIGHT
;
94 else if (!g_ascii_strcasecmp(str
, "center"))
95 winjust
= RR_JUSTIFY_CENTER
;
98 if (!read_string(db
, "menu.title.xftfont", &font_str
))
99 font_str
= "arial,sans:bold:pixelsize=12:shadow=y";
101 if (!(theme
->mtitlefont
= RrFontOpen(inst
, font_str
))) {
105 theme
->mtitlefont_height
= RrFontHeight(theme
->mtitlefont
);
107 mtitlejust
= RR_JUSTIFY_LEFT
;
108 if (read_string(db
, "menu.title.justify", &str
)) {
109 if (!g_ascii_strcasecmp(str
, "right"))
110 mtitlejust
= RR_JUSTIFY_RIGHT
;
111 else if (!g_ascii_strcasecmp(str
, "center"))
112 mtitlejust
= RR_JUSTIFY_CENTER
;
115 if (!read_string(db
, "menu.frame.xftfont", &font_str
))
116 font_str
= "arial,sans:bold:pixelsize=11:shadow=y";
118 if (!(theme
->mfont
= RrFontOpen(inst
, font_str
))) {
122 theme
->mfont_height
= RrFontHeight(theme
->mfont
);
124 mjust
= RR_JUSTIFY_LEFT
;
125 if (read_string(db
, "menu.frame.justify", &str
)) {
126 if (!g_ascii_strcasecmp(str
, "right"))
127 mjust
= RR_JUSTIFY_RIGHT
;
128 else if (!g_ascii_strcasecmp(str
, "center"))
129 mjust
= RR_JUSTIFY_CENTER
;
132 /* load the title layout */
133 if (!read_string(db
, "window.title.layout", &font_str
))
135 theme
->title_layout
= g_strdup(font_str
);
137 /* load direct dimensions */
138 if (!read_int(db
, "menuOverlap", &theme
->menu_overlap
) ||
139 theme
->menu_overlap
< 0 || theme
->menu_overlap
> 20)
140 theme
->handle_height
= 0;
141 if (!read_int(db
, "handleWidth", &theme
->handle_height
) ||
142 theme
->handle_height
< 0 || theme
->handle_height
> 100)
143 theme
->handle_height
= 6;
144 if (!read_int(db
, "bevelWidth", &theme
->bevel
) ||
145 theme
->bevel
<= 0 || theme
->bevel
> 100) theme
->bevel
= 3;
146 if (!read_int(db
, "borderWidth", &theme
->bwidth
) ||
147 theme
->bwidth
< 0 || theme
->bwidth
> 100) theme
->bwidth
= 1;
148 if (!read_int(db
, "frameWidth", &theme
->cbwidth
) ||
149 theme
->cbwidth
< 0 || theme
->cbwidth
> 100)
150 theme
->cbwidth
= theme
->bevel
;
153 if (!read_color(db
, inst
,
154 "borderColor", &theme
->b_color
))
155 theme
->b_color
= RrColorNew(inst
, 0, 0, 0);
156 if (!read_color(db
, inst
,
157 "window.frame.focusColor", &theme
->cb_focused_color
))
158 theme
->cb_focused_color
= RrColorNew(inst
, 0xff, 0xff, 0xff);
159 if (!read_color(db
, inst
,
160 "window.frame.unfocusColor",&theme
->cb_unfocused_color
))
161 theme
->cb_unfocused_color
= RrColorNew(inst
, 0xff, 0xff, 0xff);
162 if (!read_color(db
, inst
,
163 "window.label.focus.textColor",
164 &theme
->title_focused_color
))
165 theme
->title_focused_color
= RrColorNew(inst
, 0x0, 0x0, 0x0);
166 if (!read_color(db
, inst
,
167 "window.label.unfocus.textColor",
168 &theme
->title_unfocused_color
))
169 theme
->title_unfocused_color
= RrColorNew(inst
, 0xff, 0xff, 0xff);
170 if (!read_color(db
, inst
,
171 "window.button.focus.picColor",
172 &theme
->titlebut_focused_color
))
173 theme
->titlebut_focused_color
= RrColorNew(inst
, 0, 0, 0);
174 if (!read_color(db
, inst
,
175 "window.button.unfocus.picColor",
176 &theme
->titlebut_unfocused_color
))
177 theme
->titlebut_unfocused_color
= RrColorNew(inst
, 0xff, 0xff, 0xff);
178 if (!read_color(db
, inst
,
179 "window.button.disabled.focus.picColor",
180 &theme
->titlebut_disabled_focused_color
))
181 theme
->titlebut_disabled_focused_color
=
182 RrColorNew(inst
, 0xff, 0xff, 0xff);
183 if (!read_color(db
, inst
,
184 "window.button.disabled.unfocus.picColor",
185 &theme
->titlebut_disabled_unfocused_color
))
186 theme
->titlebut_disabled_unfocused_color
= RrColorNew(inst
, 0, 0, 0);
187 if (!read_color(db
, inst
,
188 "menu.title.textColor", &theme
->menu_title_color
))
189 theme
->menu_title_color
= RrColorNew(inst
, 0, 0, 0);
190 if (!read_color(db
, inst
,
191 "menu.frame.textColor", &theme
->menu_color
))
192 theme
->menu_color
= RrColorNew(inst
, 0xff, 0xff, 0xff);
193 if (!read_color(db
, inst
,
194 "menu.frame.disableColor", &theme
->menu_disabled_color
))
195 theme
->menu_disabled_color
= RrColorNew(inst
, 0, 0, 0);
196 if (!read_color(db
, inst
,
197 "menu.hilite.textColor", &theme
->menu_hilite_color
))
198 theme
->menu_hilite_color
= RrColorNew(inst
, 0, 0, 0);
200 if (read_mask(inst
, "max.xbm", theme
, &theme
->max_unset_mask
)){
201 if (!read_mask(inst
, "max_t.xbm", theme
, &theme
->max_set_mask
)) {
202 theme
->max_set_mask
= RrPixmapMaskCopy(theme
->max_unset_mask
);
206 char data
[] = { 0x7f, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x7f };
207 theme
->max_unset_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
210 char data
[] = { 0x7c, 0x44, 0x47, 0x47, 0x7f, 0x1f, 0x1f };
211 theme
->max_set_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
215 if (!read_mask(inst
, "iconify.xbm", theme
, &theme
->iconify_mask
)) {
216 char data
[] = { 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x7f };
217 theme
->iconify_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
220 if (read_mask(inst
, "stick.xbm", theme
, &theme
->desk_unset_mask
)) {
221 if (!read_mask(inst
, "stick_t.xbm", theme
, &theme
->desk_set_mask
)) {
222 theme
->desk_set_mask
=
223 RrPixmapMaskCopy(theme
->desk_unset_mask
);
227 char data
[] = { 0x63, 0x63, 0x00, 0x00, 0x00, 0x63, 0x63 };
228 theme
->desk_unset_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
231 char data
[] = { 0x00, 0x36, 0x36, 0x08, 0x36, 0x36, 0x00 };
232 theme
->desk_set_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
236 if (read_mask(inst
, "shade.xbm", theme
, &theme
->shade_unset_mask
)) {
237 if (!read_mask(inst
, "shade_t.xbm", theme
, &theme
->shade_set_mask
)) {
238 theme
->shade_set_mask
=
239 RrPixmapMaskCopy(theme
->shade_unset_mask
);
243 char data
[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00 };
244 theme
->shade_unset_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
247 char data
[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x7f };
248 theme
->shade_set_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
252 if (!read_mask(inst
, "close.xbm", theme
, &theme
->close_mask
)) {
253 char data
[] = { 0x63, 0x77, 0x3e, 0x1c, 0x3e, 0x77, 0x63 };
254 theme
->close_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
257 /* read the decoration textures */
258 if (!read_appearance(db
, inst
,
259 "window.title.focus", theme
->a_focused_title
))
260 set_default_appearance(theme
->a_focused_title
);
261 if (!read_appearance(db
, inst
,
262 "window.title.unfocus", theme
->a_unfocused_title
))
263 set_default_appearance(theme
->a_unfocused_title
);
264 if (!read_appearance(db
, inst
,
265 "window.label.focus", theme
->a_focused_label
))
266 set_default_appearance(theme
->a_focused_label
);
267 if (!read_appearance(db
, inst
,
268 "window.label.unfocus", theme
->a_unfocused_label
))
269 set_default_appearance(theme
->a_unfocused_label
);
270 if (!read_appearance(db
, inst
,
271 "window.handle.focus", theme
->a_focused_handle
))
272 set_default_appearance(theme
->a_focused_handle
);
273 if (!read_appearance(db
, inst
,
274 "window.handle.unfocus",theme
->a_unfocused_handle
))
275 set_default_appearance(theme
->a_unfocused_handle
);
276 if (!read_appearance(db
, inst
,
277 "window.grip.focus", theme
->a_focused_grip
))
278 set_default_appearance(theme
->a_focused_grip
);
279 if (!read_appearance(db
, inst
,
280 "window.grip.unfocus", theme
->a_unfocused_grip
))
281 set_default_appearance(theme
->a_unfocused_grip
);
282 if (!read_appearance(db
, inst
,
283 "menu.frame", theme
->a_menu
))
284 set_default_appearance(theme
->a_menu
);
285 if (!read_appearance(db
, inst
,
286 "menu.title", theme
->a_menu_title
))
287 set_default_appearance(theme
->a_menu_title
);
288 if (!read_appearance(db
, inst
,
289 "menu.hilite", theme
->a_menu_hilite
))
290 set_default_appearance(theme
->a_menu_hilite
);
292 /* read the appearances for rendering non-decorations */
293 if (!read_appearance(db
, inst
,
294 "window.title.focus", theme
->app_hilite_bg
))
295 set_default_appearance(theme
->app_hilite_bg
);
296 if (!read_appearance(db
, inst
,
297 "window.label.focus", theme
->app_hilite_label
))
298 set_default_appearance(theme
->app_hilite_label
);
299 if (!read_appearance(db
, inst
,
300 "window.title.unfocus", theme
->app_unhilite_bg
))
301 set_default_appearance(theme
->app_unhilite_bg
);
302 if (!read_appearance(db
, inst
,
303 "window.label.unfocus", theme
->app_unhilite_label
))
304 set_default_appearance(theme
->app_unhilite_label
);
306 /* read buttons textures */
307 if (!read_appearance(db
, inst
,
308 "window.button.disabled.focus",
309 theme
->a_disabled_focused_max
))
310 set_default_appearance(theme
->a_disabled_focused_max
);
311 if (!read_appearance(db
, inst
,
312 "window.button.disabled.unfocus",
313 theme
->a_disabled_unfocused_max
))
314 set_default_appearance(theme
->a_disabled_unfocused_max
);
315 if (!read_appearance(db
, inst
,
316 "window.button.pressed.focus",
317 theme
->a_focused_pressed_max
))
318 if (!read_appearance(db
, inst
,
319 "window.button.pressed",
320 theme
->a_focused_pressed_max
))
321 set_default_appearance(theme
->a_focused_pressed_max
);
322 if (!read_appearance(db
, inst
,
323 "window.button.pressed.unfocus",
324 theme
->a_unfocused_pressed_max
))
325 if (!read_appearance(db
, inst
,
326 "window.button.pressed",
327 theme
->a_unfocused_pressed_max
))
328 set_default_appearance(theme
->a_unfocused_pressed_max
);
329 if (!read_appearance(db
, inst
,
330 "window.button.focus",
331 theme
->a_focused_unpressed_max
))
332 set_default_appearance(theme
->a_focused_unpressed_max
);
333 if (!read_appearance(db
, inst
,
334 "window.button.unfocus",
335 theme
->a_unfocused_unpressed_max
))
336 set_default_appearance(theme
->a_unfocused_unpressed_max
);
338 theme
->a_disabled_focused_close
=
339 RrAppearanceCopy(theme
->a_disabled_focused_max
);
340 theme
->a_disabled_unfocused_close
=
341 RrAppearanceCopy(theme
->a_disabled_unfocused_max
);
342 theme
->a_unfocused_unpressed_close
=
343 RrAppearanceCopy(theme
->a_unfocused_unpressed_max
);
344 theme
->a_unfocused_pressed_close
=
345 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
346 theme
->a_focused_unpressed_close
=
347 RrAppearanceCopy(theme
->a_focused_unpressed_max
);
348 theme
->a_focused_pressed_close
=
349 RrAppearanceCopy(theme
->a_focused_pressed_max
);
350 theme
->a_disabled_focused_desk
=
351 RrAppearanceCopy(theme
->a_disabled_focused_max
);
352 theme
->a_disabled_unfocused_desk
=
353 RrAppearanceCopy(theme
->a_disabled_unfocused_max
);
354 theme
->a_unfocused_unpressed_desk
=
355 RrAppearanceCopy(theme
->a_unfocused_unpressed_max
);
356 theme
->a_unfocused_pressed_desk
=
357 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
358 theme
->a_unfocused_pressed_set_desk
=
359 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
360 theme
->a_focused_unpressed_desk
=
361 RrAppearanceCopy(theme
->a_focused_unpressed_max
);
362 theme
->a_focused_pressed_desk
=
363 RrAppearanceCopy(theme
->a_focused_pressed_max
);
364 theme
->a_focused_pressed_set_desk
=
365 RrAppearanceCopy(theme
->a_focused_pressed_max
);
366 theme
->a_disabled_focused_shade
=
367 RrAppearanceCopy(theme
->a_disabled_focused_max
);
368 theme
->a_disabled_unfocused_shade
=
369 RrAppearanceCopy(theme
->a_disabled_unfocused_max
);
370 theme
->a_unfocused_unpressed_shade
=
371 RrAppearanceCopy(theme
->a_unfocused_unpressed_max
);
372 theme
->a_unfocused_pressed_shade
=
373 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
374 theme
->a_unfocused_pressed_set_shade
=
375 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
376 theme
->a_focused_unpressed_shade
=
377 RrAppearanceCopy(theme
->a_focused_unpressed_max
);
378 theme
->a_focused_pressed_shade
=
379 RrAppearanceCopy(theme
->a_focused_pressed_max
);
380 theme
->a_focused_pressed_set_shade
=
381 RrAppearanceCopy(theme
->a_focused_pressed_max
);
382 theme
->a_disabled_focused_iconify
=
383 RrAppearanceCopy(theme
->a_disabled_focused_max
);
384 theme
->a_disabled_unfocused_iconify
=
385 RrAppearanceCopy(theme
->a_disabled_focused_max
);
386 theme
->a_unfocused_unpressed_iconify
=
387 RrAppearanceCopy(theme
->a_unfocused_unpressed_max
);
388 theme
->a_unfocused_pressed_iconify
=
389 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
390 theme
->a_focused_unpressed_iconify
=
391 RrAppearanceCopy(theme
->a_focused_unpressed_max
);
392 theme
->a_focused_pressed_iconify
=
393 RrAppearanceCopy(theme
->a_focused_pressed_max
);
394 theme
->a_unfocused_pressed_set_max
=
395 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
396 theme
->a_focused_pressed_set_max
=
397 RrAppearanceCopy(theme
->a_focused_pressed_max
);
399 theme
->a_icon
->surface
.grad
= RR_SURFACE_PARENTREL
;
401 /* set up the textures */
402 theme
->a_focused_label
->texture
[0].type
=
403 theme
->app_hilite_label
->texture
[0].type
= RR_TEXTURE_TEXT
;
404 theme
->a_focused_label
->texture
[0].data
.text
.justify
= winjust
;
405 theme
->app_hilite_label
->texture
[0].data
.text
.justify
= RR_JUSTIFY_LEFT
;
406 theme
->a_focused_label
->texture
[0].data
.text
.font
=
407 theme
->app_hilite_label
->texture
[0].data
.text
.font
= theme
->winfont
;
408 theme
->a_focused_label
->texture
[0].data
.text
.color
=
409 theme
->app_hilite_label
->texture
[0].data
.text
.color
=
410 theme
->title_focused_color
;
412 theme
->a_unfocused_label
->texture
[0].type
=
413 theme
->app_unhilite_label
->texture
[0].type
= RR_TEXTURE_TEXT
;
414 theme
->a_unfocused_label
->texture
[0].data
.text
.justify
= winjust
;
415 theme
->app_unhilite_label
->texture
[0].data
.text
.justify
= RR_JUSTIFY_LEFT
;
416 theme
->a_unfocused_label
->texture
[0].data
.text
.font
=
417 theme
->app_unhilite_label
->texture
[0].data
.text
.font
= theme
->winfont
;
418 theme
->a_unfocused_label
->texture
[0].data
.text
.color
=
419 theme
->app_unhilite_label
->texture
[0].data
.text
.color
=
420 theme
->title_unfocused_color
;
422 theme
->a_menu_title
->texture
[0].type
= RR_TEXTURE_TEXT
;
423 theme
->a_menu_title
->texture
[0].data
.text
.justify
= mtitlejust
;
424 theme
->a_menu_title
->texture
[0].data
.text
.font
= theme
->mtitlefont
;
425 theme
->a_menu_title
->texture
[0].data
.text
.color
= theme
->menu_title_color
;
427 theme
->a_menu_item
->surface
.grad
=
428 theme
->a_menu_disabled
->surface
.grad
=
429 theme
->app_icon
->surface
.grad
= RR_SURFACE_PARENTREL
;
431 theme
->a_menu_item
->texture
[0].type
=
432 theme
->a_menu_disabled
->texture
[0].type
=
433 theme
->a_menu_hilite
->texture
[0].type
= RR_TEXTURE_TEXT
;
434 theme
->a_menu_item
->texture
[0].data
.text
.justify
=
435 theme
->a_menu_disabled
->texture
[0].data
.text
.justify
=
436 theme
->a_menu_hilite
->texture
[0].data
.text
.justify
= mjust
;
437 theme
->a_menu_item
->texture
[0].data
.text
.font
=
438 theme
->a_menu_disabled
->texture
[0].data
.text
.font
=
439 theme
->a_menu_hilite
->texture
[0].data
.text
.font
= theme
->mfont
;
440 theme
->a_menu_item
->texture
[0].data
.text
.color
= theme
->menu_color
;
441 theme
->a_menu_disabled
->texture
[0].data
.text
.color
=
442 theme
->menu_disabled_color
;
443 theme
->a_menu_hilite
->texture
[0].data
.text
.color
=
444 theme
->menu_hilite_color
;
446 theme
->a_disabled_focused_max
->texture
[0].type
=
447 theme
->a_disabled_unfocused_max
->texture
[0].type
=
448 theme
->a_focused_unpressed_max
->texture
[0].type
=
449 theme
->a_focused_pressed_max
->texture
[0].type
=
450 theme
->a_focused_pressed_set_max
->texture
[0].type
=
451 theme
->a_unfocused_unpressed_max
->texture
[0].type
=
452 theme
->a_unfocused_pressed_max
->texture
[0].type
=
453 theme
->a_unfocused_pressed_set_max
->texture
[0].type
=
454 theme
->a_disabled_focused_close
->texture
[0].type
=
455 theme
->a_disabled_unfocused_close
->texture
[0].type
=
456 theme
->a_focused_unpressed_close
->texture
[0].type
=
457 theme
->a_focused_pressed_close
->texture
[0].type
=
458 theme
->a_unfocused_unpressed_close
->texture
[0].type
=
459 theme
->a_unfocused_pressed_close
->texture
[0].type
=
460 theme
->a_disabled_focused_desk
->texture
[0].type
=
461 theme
->a_disabled_unfocused_desk
->texture
[0].type
=
462 theme
->a_focused_unpressed_desk
->texture
[0].type
=
463 theme
->a_focused_pressed_desk
->texture
[0].type
=
464 theme
->a_focused_pressed_set_desk
->texture
[0].type
=
465 theme
->a_unfocused_unpressed_desk
->texture
[0].type
=
466 theme
->a_unfocused_pressed_desk
->texture
[0].type
=
467 theme
->a_unfocused_pressed_set_desk
->texture
[0].type
=
468 theme
->a_disabled_focused_shade
->texture
[0].type
=
469 theme
->a_disabled_unfocused_shade
->texture
[0].type
=
470 theme
->a_focused_unpressed_shade
->texture
[0].type
=
471 theme
->a_focused_pressed_shade
->texture
[0].type
=
472 theme
->a_focused_pressed_set_shade
->texture
[0].type
=
473 theme
->a_unfocused_unpressed_shade
->texture
[0].type
=
474 theme
->a_unfocused_pressed_shade
->texture
[0].type
=
475 theme
->a_unfocused_pressed_set_shade
->texture
[0].type
=
476 theme
->a_disabled_focused_iconify
->texture
[0].type
=
477 theme
->a_disabled_unfocused_iconify
->texture
[0].type
=
478 theme
->a_focused_unpressed_iconify
->texture
[0].type
=
479 theme
->a_focused_pressed_iconify
->texture
[0].type
=
480 theme
->a_unfocused_unpressed_iconify
->texture
[0].type
=
481 theme
->a_unfocused_pressed_iconify
->texture
[0].type
= RR_TEXTURE_MASK
;
482 theme
->a_disabled_focused_max
->texture
[0].data
.mask
.mask
=
483 theme
->a_disabled_unfocused_max
->texture
[0].data
.mask
.mask
=
484 theme
->a_focused_unpressed_max
->texture
[0].data
.mask
.mask
=
485 theme
->a_unfocused_unpressed_max
->texture
[0].data
.mask
.mask
=
486 theme
->a_focused_pressed_max
->texture
[0].data
.mask
.mask
=
487 theme
->a_unfocused_pressed_max
->texture
[0].data
.mask
.mask
=
488 theme
->max_unset_mask
;
489 theme
->a_focused_pressed_set_max
->texture
[0].data
.mask
.mask
=
490 theme
->a_unfocused_pressed_set_max
->texture
[0].data
.mask
.mask
=
492 theme
->a_disabled_focused_close
->texture
[0].data
.mask
.mask
=
493 theme
->a_disabled_unfocused_close
->texture
[0].data
.mask
.mask
=
494 theme
->a_focused_pressed_close
->texture
[0].data
.mask
.mask
=
495 theme
->a_unfocused_pressed_close
->texture
[0].data
.mask
.mask
=
496 theme
->a_focused_unpressed_close
->texture
[0].data
.mask
.mask
=
497 theme
->a_unfocused_unpressed_close
->texture
[0].data
.mask
.mask
=
499 theme
->a_disabled_focused_desk
->texture
[0].data
.mask
.mask
=
500 theme
->a_disabled_unfocused_desk
->texture
[0].data
.mask
.mask
=
501 theme
->a_focused_unpressed_desk
->texture
[0].data
.mask
.mask
=
502 theme
->a_unfocused_unpressed_desk
->texture
[0].data
.mask
.mask
=
503 theme
->a_focused_pressed_desk
->texture
[0].data
.mask
.mask
=
504 theme
->a_unfocused_pressed_desk
->texture
[0].data
.mask
.mask
=
505 theme
->desk_unset_mask
;
506 theme
->a_focused_pressed_set_desk
->texture
[0].data
.mask
.mask
=
507 theme
->a_unfocused_pressed_set_desk
->texture
[0].data
.mask
.mask
=
508 theme
->desk_set_mask
;
509 theme
->a_disabled_focused_shade
->texture
[0].data
.mask
.mask
=
510 theme
->a_disabled_unfocused_shade
->texture
[0].data
.mask
.mask
=
511 theme
->a_focused_unpressed_shade
->texture
[0].data
.mask
.mask
=
512 theme
->a_unfocused_unpressed_shade
->texture
[0].data
.mask
.mask
=
513 theme
->a_focused_pressed_shade
->texture
[0].data
.mask
.mask
=
514 theme
->a_unfocused_pressed_shade
->texture
[0].data
.mask
.mask
=
515 theme
->shade_unset_mask
;
516 theme
->a_focused_pressed_set_shade
->texture
[0].data
.mask
.mask
=
517 theme
->a_unfocused_pressed_set_shade
->texture
[0].data
.mask
.mask
=
518 theme
->shade_set_mask
;
519 theme
->a_disabled_focused_iconify
->texture
[0].data
.mask
.mask
=
520 theme
->a_disabled_unfocused_iconify
->texture
[0].data
.mask
.mask
=
521 theme
->a_focused_unpressed_iconify
->texture
[0].data
.mask
.mask
=
522 theme
->a_unfocused_unpressed_iconify
->texture
[0].data
.mask
.mask
=
523 theme
->a_focused_pressed_iconify
->texture
[0].data
.mask
.mask
=
524 theme
->a_unfocused_pressed_iconify
->texture
[0].data
.mask
.mask
=
526 theme
->a_disabled_focused_max
->texture
[0].data
.mask
.color
=
527 theme
->a_disabled_focused_close
->texture
[0].data
.mask
.color
=
528 theme
->a_disabled_focused_desk
->texture
[0].data
.mask
.color
=
529 theme
->a_disabled_focused_shade
->texture
[0].data
.mask
.color
=
530 theme
->a_disabled_focused_iconify
->texture
[0].data
.mask
.color
=
531 theme
->titlebut_disabled_focused_color
;
532 theme
->a_disabled_unfocused_max
->texture
[0].data
.mask
.color
=
533 theme
->a_disabled_unfocused_close
->texture
[0].data
.mask
.color
=
534 theme
->a_disabled_unfocused_desk
->texture
[0].data
.mask
.color
=
535 theme
->a_disabled_unfocused_shade
->texture
[0].data
.mask
.color
=
536 theme
->a_disabled_unfocused_iconify
->texture
[0].data
.mask
.color
=
537 theme
->titlebut_disabled_unfocused_color
;
538 theme
->a_focused_unpressed_max
->texture
[0].data
.mask
.color
=
539 theme
->a_focused_pressed_max
->texture
[0].data
.mask
.color
=
540 theme
->a_focused_pressed_set_max
->texture
[0].data
.mask
.color
=
541 theme
->a_focused_unpressed_close
->texture
[0].data
.mask
.color
=
542 theme
->a_focused_pressed_close
->texture
[0].data
.mask
.color
=
543 theme
->a_focused_unpressed_desk
->texture
[0].data
.mask
.color
=
544 theme
->a_focused_pressed_desk
->texture
[0].data
.mask
.color
=
545 theme
->a_focused_pressed_set_desk
->texture
[0].data
.mask
.color
=
546 theme
->a_focused_unpressed_shade
->texture
[0].data
.mask
.color
=
547 theme
->a_focused_pressed_shade
->texture
[0].data
.mask
.color
=
548 theme
->a_focused_pressed_set_shade
->texture
[0].data
.mask
.color
=
549 theme
->a_focused_unpressed_iconify
->texture
[0].data
.mask
.color
=
550 theme
->a_focused_pressed_iconify
->texture
[0].data
.mask
.color
=
551 theme
->titlebut_focused_color
;
552 theme
->a_unfocused_unpressed_max
->texture
[0].data
.mask
.color
=
553 theme
->a_unfocused_pressed_max
->texture
[0].data
.mask
.color
=
554 theme
->a_unfocused_pressed_set_max
->texture
[0].data
.mask
.color
=
555 theme
->a_unfocused_unpressed_close
->texture
[0].data
.mask
.color
=
556 theme
->a_unfocused_pressed_close
->texture
[0].data
.mask
.color
=
557 theme
->a_unfocused_unpressed_desk
->texture
[0].data
.mask
.color
=
558 theme
->a_unfocused_pressed_desk
->texture
[0].data
.mask
.color
=
559 theme
->a_unfocused_pressed_set_desk
->texture
[0].data
.mask
.color
=
560 theme
->a_unfocused_unpressed_shade
->texture
[0].data
.mask
.color
=
561 theme
->a_unfocused_pressed_shade
->texture
[0].data
.mask
.color
=
562 theme
->a_unfocused_pressed_set_shade
->texture
[0].data
.mask
.color
=
563 theme
->a_unfocused_unpressed_iconify
->texture
[0].data
.mask
.color
=
564 theme
->a_unfocused_pressed_iconify
->texture
[0].data
.mask
.color
=
565 theme
->titlebut_unfocused_color
;
567 XrmDestroyDatabase(db
);
569 theme
->label_height
= theme
->winfont_height
;
570 theme
->title_height
= theme
->label_height
+ theme
->bevel
* 2;
571 theme
->button_size
= theme
->label_height
- 2;
572 theme
->grip_width
= theme
->button_size
* 2;
577 void RrThemeFree(RrTheme
*theme
)
582 RrColorFree(theme
->b_color
);
583 RrColorFree(theme
->cb_unfocused_color
);
584 RrColorFree(theme
->cb_focused_color
);
585 RrColorFree(theme
->title_unfocused_color
);
586 RrColorFree(theme
->title_focused_color
);
587 RrColorFree(theme
->titlebut_unfocused_color
);
588 RrColorFree(theme
->titlebut_focused_color
);
589 RrColorFree(theme
->menu_color
);
590 RrColorFree(theme
->menu_title_color
);
591 RrColorFree(theme
->menu_disabled_color
);
592 RrColorFree(theme
->menu_hilite_color
);
594 RrPixmapMaskFree(theme
->max_set_mask
);
595 RrPixmapMaskFree(theme
->max_unset_mask
);
596 RrPixmapMaskFree(theme
->desk_set_mask
);
597 RrPixmapMaskFree(theme
->desk_unset_mask
);
598 RrPixmapMaskFree(theme
->shade_set_mask
);
599 RrPixmapMaskFree(theme
->shade_unset_mask
);
600 RrPixmapMaskFree(theme
->iconify_mask
);
601 RrPixmapMaskFree(theme
->close_mask
);
603 RrFontClose(theme
->winfont
);
604 RrFontClose(theme
->mtitlefont
);
605 RrFontClose(theme
->mfont
);
607 g_free(theme
->title_layout
);
609 RrAppearanceFree(theme
->a_focused_unpressed_max
);
610 RrAppearanceFree(theme
->a_focused_pressed_max
);
611 RrAppearanceFree(theme
->a_focused_pressed_set_max
);
612 RrAppearanceFree(theme
->a_unfocused_unpressed_max
);
613 RrAppearanceFree(theme
->a_unfocused_pressed_max
);
614 RrAppearanceFree(theme
->a_unfocused_pressed_set_max
);
615 RrAppearanceFree(theme
->a_focused_unpressed_close
);
616 RrAppearanceFree(theme
->a_focused_pressed_close
);
617 RrAppearanceFree(theme
->a_unfocused_unpressed_close
);
618 RrAppearanceFree(theme
->a_unfocused_pressed_close
);
619 RrAppearanceFree(theme
->a_focused_unpressed_desk
);
620 RrAppearanceFree(theme
->a_focused_pressed_desk
);
621 RrAppearanceFree(theme
->a_unfocused_unpressed_desk
);
622 RrAppearanceFree(theme
->a_unfocused_pressed_desk
);
623 RrAppearanceFree(theme
->a_focused_unpressed_shade
);
624 RrAppearanceFree(theme
->a_focused_pressed_shade
);
625 RrAppearanceFree(theme
->a_unfocused_unpressed_shade
);
626 RrAppearanceFree(theme
->a_unfocused_pressed_shade
);
627 RrAppearanceFree(theme
->a_focused_unpressed_iconify
);
628 RrAppearanceFree(theme
->a_focused_pressed_iconify
);
629 RrAppearanceFree(theme
->a_unfocused_unpressed_iconify
);
630 RrAppearanceFree(theme
->a_unfocused_pressed_iconify
);
631 RrAppearanceFree(theme
->a_focused_grip
);
632 RrAppearanceFree(theme
->a_unfocused_grip
);
633 RrAppearanceFree(theme
->a_focused_title
);
634 RrAppearanceFree(theme
->a_unfocused_title
);
635 RrAppearanceFree(theme
->a_focused_label
);
636 RrAppearanceFree(theme
->a_unfocused_label
);
637 RrAppearanceFree(theme
->a_icon
);
638 RrAppearanceFree(theme
->a_focused_handle
);
639 RrAppearanceFree(theme
->a_unfocused_handle
);
640 RrAppearanceFree(theme
->a_menu
);
641 RrAppearanceFree(theme
->a_menu_title
);
642 RrAppearanceFree(theme
->a_menu_item
);
643 RrAppearanceFree(theme
->a_menu_disabled
);
644 RrAppearanceFree(theme
->a_menu_hilite
);
645 RrAppearanceFree(theme
->app_hilite_bg
);
646 RrAppearanceFree(theme
->app_unhilite_bg
);
647 RrAppearanceFree(theme
->app_hilite_label
);
648 RrAppearanceFree(theme
->app_unhilite_label
);
649 RrAppearanceFree(theme
->app_icon
);
653 static XrmDatabase
loaddb(RrTheme
*theme
, char *name
)
657 if ((db
= XrmGetFileDatabase(name
)))
658 theme
->path
= g_path_get_dirname(name
);
660 char *s
= g_build_filename(g_get_home_dir(), ".openbox", "themes",
662 if ((db
= XrmGetFileDatabase(s
)))
663 theme
->path
= g_path_get_dirname(s
);
667 char *s
= g_build_filename(THEMEDIR
, name
, NULL
);
668 if ((db
= XrmGetFileDatabase(s
)))
669 theme
->path
= g_path_get_dirname(s
);
676 static char *create_class_name(char *rname
)
678 char *rclass
= g_strdup(rname
);
683 p
= strchr(p
+1, '.');
684 if (p
== NULL
) break;
686 if (*p
== '\0') break;
691 static gboolean
read_int(XrmDatabase db
, char *rname
, int *value
)
693 gboolean ret
= FALSE
;
694 char *rclass
= create_class_name(rname
);
698 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
699 retvalue
.addr
!= NULL
) {
700 *value
= (int)strtol(retvalue
.addr
, &end
, 10);
701 if (end
!= retvalue
.addr
)
709 static gboolean
read_string(XrmDatabase db
, char *rname
, char **value
)
711 gboolean ret
= FALSE
;
712 char *rclass
= create_class_name(rname
);
716 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
717 retvalue
.addr
!= NULL
) {
718 *value
= retvalue
.addr
;
726 static gboolean
read_color(XrmDatabase db
, const RrInstance
*inst
,
727 gchar
*rname
, RrColor
**value
)
729 gboolean ret
= FALSE
;
730 char *rclass
= create_class_name(rname
);
734 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
735 retvalue
.addr
!= NULL
) {
736 RrColor
*c
= RrColorParse(inst
, retvalue
.addr
);
747 static gboolean
read_mask(const RrInstance
*inst
,
748 gchar
*maskname
, RrTheme
*theme
,
749 RrPixmapMask
**value
)
751 gboolean ret
= FALSE
;
754 int hx
, hy
; /* ignored */
758 data_dir
= g_strdup_printf("%s_data", theme
->name
);
760 s
= g_build_filename(g_get_home_dir(), ".openbox", "themes",
761 data_dir
, maskname
, NULL
);
762 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) == BitmapSuccess
)
766 s
= g_build_filename(THEMEDIR
, data_dir
, maskname
, NULL
);
767 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) == BitmapSuccess
)
771 s
= g_build_filename(theme
->path
, data_dir
, maskname
, NULL
);
772 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) == BitmapSuccess
)
778 *value
= RrPixmapMaskNew(inst
, w
, h
, (char*)b
);
788 static void parse_appearance(gchar
*tex
, RrSurfaceColorType
*grad
,
789 RrReliefType
*relief
, RrBevelType
*bevel
,
790 gboolean
*interlaced
, gboolean
*border
)
794 /* convert to all lowercase */
795 for (t
= tex
; *t
!= '\0'; ++t
)
796 *t
= g_ascii_tolower(*t
);
798 if (strstr(tex
, "parentrelative") != NULL
) {
799 *grad
= RR_SURFACE_PARENTREL
;
801 if (strstr(tex
, "gradient") != NULL
) {
802 if (strstr(tex
, "crossdiagonal") != NULL
)
803 *grad
= RR_SURFACE_CROSS_DIAGONAL
;
804 else if (strstr(tex
, "pyramid") != NULL
)
805 *grad
= RR_SURFACE_PYRAMID
;
806 else if (strstr(tex
, "horizontal") != NULL
)
807 *grad
= RR_SURFACE_HORIZONTAL
;
808 else if (strstr(tex
, "vertical") != NULL
)
809 *grad
= RR_SURFACE_VERTICAL
;
811 *grad
= RR_SURFACE_DIAGONAL
;
813 *grad
= RR_SURFACE_SOLID
;
816 if (strstr(tex
, "sunken") != NULL
)
817 *relief
= RR_RELIEF_SUNKEN
;
818 else if (strstr(tex
, "flat") != NULL
)
819 *relief
= RR_RELIEF_FLAT
;
821 *relief
= RR_RELIEF_RAISED
;
824 if (*relief
== RR_RELIEF_FLAT
) {
825 if (strstr(tex
, "border") != NULL
)
828 if (strstr(tex
, "bevel2") != NULL
)
834 if (strstr(tex
, "interlaced") != NULL
)
842 static gboolean
read_appearance(XrmDatabase db
, const RrInstance
*inst
,
843 gchar
*rname
, RrAppearance
*value
)
845 gboolean ret
= FALSE
;
846 char *rclass
= create_class_name(rname
), *cname
, *ctoname
, *bcname
;
850 cname
= g_strconcat(rname
, ".color", NULL
);
851 ctoname
= g_strconcat(rname
, ".colorTo", NULL
);
852 bcname
= g_strconcat(rname
, ".borderColor", NULL
);
854 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
855 retvalue
.addr
!= NULL
) {
856 parse_appearance(retvalue
.addr
,
857 &value
->surface
.grad
,
858 &value
->surface
.relief
,
859 &value
->surface
.bevel
,
860 &value
->surface
.interlaced
,
861 &value
->surface
.border
);
862 if (!read_color(db
, inst
, cname
, &value
->surface
.primary
))
863 value
->surface
.primary
= RrColorNew(inst
, 0, 0, 0);
864 if (!read_color(db
, inst
, ctoname
, &value
->surface
.secondary
))
865 value
->surface
.secondary
= RrColorNew(inst
, 0, 0, 0);
866 if (value
->surface
.border
)
867 if (!read_color(db
, inst
, bcname
,
868 &value
->surface
.border_color
))
869 value
->surface
.border_color
= RrColorNew(inst
, 0, 0, 0);
880 static void set_default_appearance(RrAppearance
*a
)
882 a
->surface
.grad
= RR_SURFACE_SOLID
;
883 a
->surface
.relief
= RR_RELIEF_FLAT
;
884 a
->surface
.bevel
= RR_BEVEL_1
;
885 a
->surface
.interlaced
= FALSE
;
886 a
->surface
.border
= FALSE
;
887 a
->surface
.primary
= RrColorNew(a
->inst
, 0, 0, 0);
888 a
->surface
.secondary
= RrColorNew(a
->inst
, 0, 0, 0);