]> icculus.org git repositories - mikachu/openbox.git/blob - render/theme.c
Removed trailing spaces and fixed to 80 column width.
[mikachu/openbox.git] / render / theme.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    theme.c for the Openbox window manager
4    Copyright (c) 2006        Mikael Magnusson
5    Copyright (c) 2003-2007   Dana Jansens
6
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.
11
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.
16
17    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "render.h"
21 #include "color.h"
22 #include "font.h"
23 #include "mask.h"
24 #include "theme.h"
25 #include "icon.h"
26 #include "parser/parse.h"
27
28 #include <X11/Xlib.h>
29 #include <X11/Xresource.h>
30 #include <ctype.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 static XrmDatabase loaddb(const gchar *name, gchar **path);
35 static gboolean read_int(XrmDatabase db, const gchar *rname, gint *value);
36 static gboolean read_string(XrmDatabase db, const gchar *rname, gchar **value);
37 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
38                            const gchar *rname, RrColor **value);
39 static gboolean read_mask(const RrInstance *inst, const gchar *path,
40                           RrTheme *theme, const gchar *maskname,
41                           RrPixmapMask **value);
42 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
43                                 const gchar *rname, RrAppearance *value,
44                                 gboolean allow_trans);
45 static int parse_inline_number(const char *p);
46 static RrPixel32* read_c_image(gint width, gint height, const guint8 *data);
47 static void set_default_appearance(RrAppearance *a);
48
49 #define READ_INT(x_resstr, x_var, x_min, x_max, x_def) \
50     if (!read_int(db, x_resstr, & x_var) || \
51             x_var < x_min || x_var > x_max) \
52         x_var = x_def;
53
54 #define READ_COLOR(x_resstr, x_var, x_def) \
55     if (!read_color(db, inst, x_resstr, & x_var)) \
56         x_var = x_def;
57
58 #define READ_COLOR_(x_res1, x_res2, x_var, x_def) \
59     if (!read_color(db, inst, x_res1, & x_var) && \
60         !read_color(db, inst, x_res2, & x_var)) \
61         x_var = x_def;
62
63 #define READ_MASK_COPY(x_file, x_var, x_copysrc) \
64     if (!read_mask(inst, path, theme, x_file, & x_var)) \
65         x_var = RrPixmapMaskCopy(x_copysrc);
66
67 #define READ_APPEARANCE(x_resstr, x_var, x_parrel) \
68     if (!read_appearance(db, inst, x_resstr, x_var, x_parrel)) \
69         set_default_appearance(x_var);
70
71 #define READ_APPEARANCE_COPY(x_resstr, x_var, x_parrel, x_defval) \
72     if (!read_appearance(db, inst, x_resstr, x_var, x_parrel)) {\
73         RrAppearanceFree(x_var); \
74         x_var = RrAppearanceCopy(x_defval); }
75
76 #define READ_APPEARANCE_(x_res1, x_res2, x_var, x_parrel, x_defval) \
77     if (!read_appearance(db, inst, x_res1, x_var, x_parrel) && \
78         !read_appearance(db, inst, x_res2, x_var, x_parrel)) {\
79         RrAppearanceFree(x_var); \
80         x_var = RrAppearanceCopy(x_defval); }
81
82 RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
83                     gboolean allow_fallback,
84                     RrFont *active_window_font, RrFont *inactive_window_font,
85                     RrFont *menu_title_font, RrFont *menu_item_font,
86                     RrFont *osd_font)
87 {
88     XrmDatabase db = NULL;
89     RrJustify winjust, mtitlejust;
90     gchar *str;
91     RrTheme *theme;
92     gchar *path;
93     gboolean userdef;
94
95     if (name) {
96         db = loaddb(name, &path);
97         if (db == NULL) {
98             g_message("Unable to load the theme '%s'", name);
99             if (allow_fallback)
100                 g_message("Falling back to the default theme '%s'",
101                           DEFAULT_THEME);
102             /* fallback to the default theme */
103             name = NULL;
104         }
105     }
106     if (name == NULL) {
107         if (allow_fallback) {
108             db = loaddb(DEFAULT_THEME, &path);
109             if (db == NULL) {
110                 g_message("Unable to load the theme '%s'", DEFAULT_THEME);
111                 return NULL;
112             }
113         } else
114             return NULL;
115     }
116
117     theme = g_new0(RrTheme, 1);
118
119     theme->inst = inst;
120     theme->name = g_strdup(name ? name : DEFAULT_THEME);
121
122     theme->a_disabled_focused_max = RrAppearanceNew(inst, 1);
123     theme->a_disabled_unfocused_max = RrAppearanceNew(inst, 1);
124     theme->a_hover_focused_max = RrAppearanceNew(inst, 1);
125     theme->a_hover_unfocused_max = RrAppearanceNew(inst, 1);
126     theme->a_toggled_focused_unpressed_max = RrAppearanceNew(inst, 1);
127     theme->a_toggled_unfocused_unpressed_max = RrAppearanceNew(inst, 1);
128     theme->a_toggled_hover_focused_max = RrAppearanceNew(inst, 1);
129     theme->a_toggled_hover_unfocused_max = RrAppearanceNew(inst, 1);
130     theme->a_toggled_focused_pressed_max = RrAppearanceNew(inst, 1);
131     theme->a_toggled_unfocused_pressed_max = RrAppearanceNew(inst, 1);
132     theme->a_focused_unpressed_max = RrAppearanceNew(inst, 1);
133     theme->a_focused_pressed_max = RrAppearanceNew(inst, 1);
134     theme->a_unfocused_unpressed_max = RrAppearanceNew(inst, 1);
135     theme->a_unfocused_pressed_max = RrAppearanceNew(inst, 1);
136     theme->a_focused_grip = RrAppearanceNew(inst, 0);
137     theme->a_unfocused_grip = RrAppearanceNew(inst, 0);
138     theme->a_focused_title = RrAppearanceNew(inst, 0);
139     theme->a_unfocused_title = RrAppearanceNew(inst, 0);
140     theme->a_focused_label = RrAppearanceNew(inst, 1);
141     theme->a_unfocused_label = RrAppearanceNew(inst, 1);
142     theme->a_icon = RrAppearanceNew(inst, 1);
143     theme->a_focused_handle = RrAppearanceNew(inst, 0);
144     theme->a_unfocused_handle = RrAppearanceNew(inst, 0);
145     theme->a_menu = RrAppearanceNew(inst, 0);
146     theme->a_menu_title = RrAppearanceNew(inst, 0);
147     theme->a_menu_text_title = RrAppearanceNew(inst, 1);
148     theme->a_menu_normal = RrAppearanceNew(inst, 0);
149     theme->a_menu_selected = RrAppearanceNew(inst, 0);
150     theme->a_menu_disabled = RrAppearanceNew(inst, 0);
151     /* a_menu_disabled_selected is copied from a_menu_selected */
152     theme->a_menu_text_normal = RrAppearanceNew(inst, 1);
153     theme->a_menu_text_selected = RrAppearanceNew(inst, 1);
154     theme->a_menu_text_disabled = RrAppearanceNew(inst, 1);
155     theme->a_menu_text_disabled_selected = RrAppearanceNew(inst, 1);
156     theme->a_menu_bullet_normal = RrAppearanceNew(inst, 1);
157     theme->a_menu_bullet_selected = RrAppearanceNew(inst, 1);
158     theme->a_clear = RrAppearanceNew(inst, 0);
159     theme->a_clear_tex = RrAppearanceNew(inst, 1);
160     theme->osd_hilite_bg = RrAppearanceNew(inst, 0);
161     theme->osd_hilite_label = RrAppearanceNew(inst, 1);
162     theme->osd_hilite_fg = RrAppearanceNew(inst, 0);
163     theme->osd_unhilite_fg = RrAppearanceNew(inst, 0);
164
165     /* load the font stuff */
166     if (active_window_font) {
167         theme->win_font_focused = active_window_font;
168         RrFontRef(active_window_font);
169     } else
170         theme->win_font_focused = RrFontOpenDefault(inst);
171
172     if (inactive_window_font) {
173         theme->win_font_unfocused = inactive_window_font;
174         RrFontRef(inactive_window_font);
175     } else
176         theme->win_font_unfocused = RrFontOpenDefault(inst);
177
178     winjust = RR_JUSTIFY_LEFT;
179     if (read_string(db, "window.label.text.justify", &str)) {
180         if (!g_ascii_strcasecmp(str, "right"))
181             winjust = RR_JUSTIFY_RIGHT;
182         else if (!g_ascii_strcasecmp(str, "center"))
183             winjust = RR_JUSTIFY_CENTER;
184     }
185
186     if (menu_title_font) {
187         theme->menu_title_font = menu_title_font;
188         RrFontRef(menu_title_font);
189     } else
190         theme->menu_title_font = RrFontOpenDefault(inst);
191
192     mtitlejust = RR_JUSTIFY_LEFT;
193     if (read_string(db, "menu.title.text.justify", &str)) {
194         if (!g_ascii_strcasecmp(str, "right"))
195             mtitlejust = RR_JUSTIFY_RIGHT;
196         else if (!g_ascii_strcasecmp(str, "center"))
197             mtitlejust = RR_JUSTIFY_CENTER;
198     }
199
200     if (menu_item_font) {
201         theme->menu_font = menu_item_font;
202         RrFontRef(menu_item_font);
203     } else
204         theme->menu_font = RrFontOpenDefault(inst);
205
206     if (osd_font) {
207         theme->osd_font = osd_font;
208         RrFontRef(osd_font);
209     } else
210         theme->osd_font = RrFontOpenDefault(inst);
211
212     /* load direct dimensions */
213     READ_INT("menu.overlap", theme->menu_overlap, -100, 100, 0);
214     READ_INT("window.handle.width", theme->handle_height, 0, 100, 6);
215     READ_INT("padding.width", theme->paddingx, 0, 100, 3);
216     READ_INT("padding.height", theme->paddingy, 0, 100, theme->paddingx);
217     READ_INT("border.width", theme->fbwidth, 0, 100, 1);
218     READ_INT("menu.border.width", theme->mbwidth, 0, 100, theme->fbwidth);
219     READ_INT("osd.border.width", theme->obwidth, 0, 100, theme->fbwidth);
220     READ_INT("window.client.padding.width", theme->cbwidthx, 0, 100,
221              theme->paddingx);
222     READ_INT("window.client.padding.height", theme->cbwidthy, 0, 100,
223              theme->cbwidthx);
224
225     /* load colors */
226     READ_COLOR_("window.active.border.color", "border.color",
227                 theme->frame_focused_border_color, RrColorNew(inst, 0, 0, 0));
228
229     /* title separator focused color inherits from focused boder color */
230     READ_COLOR("window.active.title.separator.color",
231                theme->title_separator_focused_color,
232                RrColorCopy(theme->frame_focused_border_color));
233
234     /* unfocused border color inherits from frame focused border color */
235     READ_COLOR("window.inactive.border.color",
236                theme->frame_unfocused_border_color,
237                RrColorCopy(theme->frame_focused_border_color));
238
239     /* title separator unfocused color inherits from unfocused boder color */
240     READ_COLOR("window.inactive.title.separator.color",
241                theme->title_separator_unfocused_color,
242                RrColorCopy(theme->frame_unfocused_border_color));
243
244     /* menu border color inherits from frame focused border color */
245     READ_COLOR("menu.border.color", theme->menu_border_color,
246                RrColorCopy(theme->frame_focused_border_color));
247
248     /* osd border color inherits from frame focused border color */
249     READ_COLOR("osd.border.color", theme->osd_border_color,
250                RrColorCopy(theme->frame_focused_border_color));
251
252     READ_COLOR("window.active.client.color", theme->cb_focused_color,
253                RrColorNew(inst, 0xff, 0xff, 0xff));
254
255     READ_COLOR("window.inactive.client.color", theme->cb_unfocused_color,
256                RrColorNew(inst, 0xff, 0xff, 0xff));
257
258     READ_COLOR("window.active.label.text.color", theme->title_focused_color,
259                RrColorNew(inst, 0x0, 0x0, 0x0));
260
261     READ_COLOR("osd.label.text.color", theme->osd_color,
262                RrColorCopy(theme->title_focused_color));
263
264     READ_COLOR("window.inactive.label.text.color",
265                theme->title_unfocused_color,
266                RrColorNew(inst, 0xff, 0xff, 0xff));
267
268     READ_COLOR("window.active.button.unpressed.image.color",
269                theme->titlebut_focused_unpressed_color,
270                RrColorNew(inst, 0, 0, 0));
271
272     READ_COLOR("window.inactive.button.unpressed.image.color",
273                theme->titlebut_unfocused_unpressed_color,
274                RrColorNew(inst, 0xff, 0xff, 0xff));
275
276     READ_COLOR("window.active.button.pressed.image.color",
277                theme->titlebut_focused_pressed_color,
278                RrColorCopy(theme->titlebut_focused_unpressed_color));
279
280     READ_COLOR("window.inactive.button.pressed.image.color",
281                theme->titlebut_unfocused_pressed_color,
282                RrColorCopy(theme->titlebut_unfocused_unpressed_color));
283
284     READ_COLOR("window.active.button.disabled.image.color",
285                theme->titlebut_disabled_focused_color,
286                RrColorNew(inst, 0xff, 0xff, 0xff));
287
288     READ_COLOR("window.inactive.button.disabled.image.color",
289                theme->titlebut_disabled_unfocused_color,
290                RrColorNew(inst, 0, 0, 0));
291
292     READ_COLOR("window.active.button.hover.image.color",
293                theme->titlebut_hover_focused_color,
294                RrColorCopy(theme->titlebut_focused_unpressed_color));
295
296     READ_COLOR("window.inactive.button.hover.image.color",
297                theme->titlebut_hover_unfocused_color,
298                RrColorCopy(theme->titlebut_unfocused_unpressed_color));
299
300     READ_COLOR_("window.active.button.toggled.unpressed.image.color",
301                 "window.active.button.toggled.image.color",
302                 theme->titlebut_toggled_focused_unpressed_color,
303                 RrColorCopy(theme->titlebut_focused_pressed_color));
304
305     READ_COLOR_("window.inactive.button.toggled.unpressed.image.color",
306                 "window.inactive.button.toggled.image.color",
307                 theme->titlebut_toggled_unfocused_unpressed_color,
308                 RrColorCopy(theme->titlebut_unfocused_pressed_color));
309
310     READ_COLOR("window.active.button.toggled.hover.image.color",
311                theme->titlebut_toggled_hover_focused_color,
312                RrColorCopy(theme->titlebut_toggled_focused_unpressed_color));
313
314     READ_COLOR("window.inactive.button.toggled.hover.image.color",
315                theme->titlebut_toggled_hover_unfocused_color,
316                RrColorCopy(theme->titlebut_toggled_unfocused_unpressed_color));
317
318     READ_COLOR("window.active.button.toggled.pressed.image.color",
319                theme->titlebut_toggled_focused_pressed_color,
320                RrColorCopy(theme->titlebut_focused_pressed_color));
321
322     READ_COLOR("window.inactive.button.toggled.pressed.image.color",
323                theme->titlebut_toggled_unfocused_pressed_color,
324                RrColorCopy(theme->titlebut_unfocused_pressed_color));
325
326     READ_COLOR("menu.title.text.color", theme->menu_title_color,
327                RrColorNew(inst, 0, 0, 0));
328
329     READ_COLOR("menu.items.text.color", theme->menu_color,
330                RrColorNew(inst, 0xff, 0xff, 0xff));
331
332     READ_COLOR("menu.items.disabled.text.color", theme->menu_disabled_color,
333                RrColorNew(inst, 0, 0, 0));
334
335     READ_COLOR("menu.items.active.disabled.text.color",
336                theme->menu_disabled_selected_color,
337                RrColorCopy(theme->menu_disabled_color));
338
339     READ_COLOR("menu.items.active.text.color", theme->menu_selected_color,
340                RrColorNew(inst, 0, 0, 0));
341
342
343     /* load the image masks */
344
345     /* maximize button masks */
346     userdef = TRUE;
347     if (!read_mask(inst, path, theme, "max.xbm", &theme->max_mask)) {
348             guchar data[] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f };
349             theme->max_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
350             userdef = FALSE;
351     }
352     if (!read_mask(inst, path, theme, "max_toggled.xbm",
353                    &theme->max_toggled_mask))
354     {
355         if (userdef)
356             theme->max_toggled_mask = RrPixmapMaskCopy(theme->max_mask);
357         else {
358             guchar data[] = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f };
359             theme->max_toggled_mask = RrPixmapMaskNew(inst, 6, 6,(gchar*)data);
360         }
361     }
362     READ_MASK_COPY("max_pressed.xbm", theme->max_pressed_mask,
363                    theme->max_mask);
364     READ_MASK_COPY("max_disabled.xbm", theme->max_disabled_mask,
365                    theme->max_mask);
366     READ_MASK_COPY("max_hover.xbm", theme->max_hover_mask, theme->max_mask);
367     READ_MASK_COPY("max_toggled_pressed.xbm", theme->max_toggled_pressed_mask,
368                    theme->max_toggled_mask);
369     READ_MASK_COPY("max_toggled_hover.xbm", theme->max_toggled_hover_mask,
370                    theme->max_toggled_mask);
371
372     /* iconify button masks */
373     if (!read_mask(inst, path, theme, "iconify.xbm", &theme->iconify_mask)) {
374         guchar data[] = { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f };
375         theme->iconify_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
376     }
377     READ_MASK_COPY("iconify_pressed.xbm", theme->iconify_pressed_mask,
378                    theme->iconify_mask);
379     READ_MASK_COPY("iconify_disabled.xbm", theme->iconify_disabled_mask,
380                    theme->iconify_mask);
381     READ_MASK_COPY("iconify_hover.xbm", theme->iconify_hover_mask,
382                    theme->iconify_mask);
383
384     /* all desktops button masks */
385     userdef = TRUE;
386     if (!read_mask(inst, path, theme, "desk.xbm", &theme->desk_mask)) {
387         guchar data[] = { 0x33, 0x33, 0x00, 0x00, 0x33, 0x33 };
388         theme->desk_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
389         userdef = FALSE;
390     }
391     if (!read_mask(inst, path, theme, "desk_toggled.xbm",
392                    &theme->desk_toggled_mask)) {
393         if (userdef)
394             theme->desk_toggled_mask = RrPixmapMaskCopy(theme->desk_mask);
395         else {
396             guchar data[] = { 0x00, 0x1e, 0x1a, 0x16, 0x1e, 0x00 };
397             theme->desk_toggled_mask =
398                 RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
399         }
400     }
401     READ_MASK_COPY("desk_pressed.xbm", theme->desk_pressed_mask,
402                    theme->desk_mask);
403     READ_MASK_COPY("desk_disabled.xbm", theme->desk_disabled_mask,
404                    theme->desk_mask);
405     READ_MASK_COPY("desk_hover.xbm", theme->desk_hover_mask, theme->desk_mask);
406     READ_MASK_COPY("desk_toggled_pressed.xbm",
407                    theme->desk_toggled_pressed_mask, theme->desk_toggled_mask);
408     READ_MASK_COPY("desk_toggled_hover.xbm", theme->desk_toggled_hover_mask,
409                    theme->desk_toggled_mask);
410
411     /* shade button masks */
412     if (!read_mask(inst, path, theme, "shade.xbm", &theme->shade_mask)) {
413         guchar data[] = { 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00 };
414         theme->shade_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
415     }
416     READ_MASK_COPY("shade_toggled.xbm", theme->shade_toggled_mask,
417                    theme->shade_mask);
418     READ_MASK_COPY("shade_pressed.xbm", theme->shade_pressed_mask,
419                    theme->shade_mask);
420     READ_MASK_COPY("shade_disabled.xbm", theme->shade_disabled_mask,
421                    theme->shade_mask);
422     READ_MASK_COPY("shade_hover.xbm", theme->shade_hover_mask,
423                    theme->shade_mask);
424     READ_MASK_COPY("shade_toggled_pressed.xbm",
425                    theme->shade_toggled_pressed_mask,
426                    theme->shade_toggled_mask);
427     READ_MASK_COPY("shade_toggled_hover.xbm",
428                    theme->shade_toggled_hover_mask, theme->shade_toggled_mask);
429
430     /* close button masks */
431     if (!read_mask(inst, path, theme, "close.xbm", &theme->close_mask)) {
432         guchar data[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 };
433         theme->close_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
434     }
435     READ_MASK_COPY("close_pressed.xbm", theme->close_pressed_mask,
436                    theme->close_mask);
437     READ_MASK_COPY("close_disabled.xbm", theme->close_disabled_mask,
438                    theme->close_mask);
439     READ_MASK_COPY("close_hover.xbm", theme->close_hover_mask,
440                    theme->close_mask);
441
442     /* submenu bullet mask */
443     if (!read_mask(inst, path, theme, "bullet.xbm", &theme->menu_bullet_mask))
444     {
445         guchar data[] = { 0x01, 0x03, 0x07, 0x0f, 0x07, 0x03, 0x01 };
446         theme->menu_bullet_mask = RrPixmapMaskNew(inst, 4, 7, (gchar*)data);
447     }
448
449     /* setup the default window icon */
450     theme->def_win_icon = read_c_image(OB_DEFAULT_ICON_WIDTH,
451                                        OB_DEFAULT_ICON_HEIGHT,
452                                        OB_DEFAULT_ICON_pixel_data);
453
454     /* read the decoration textures */
455     READ_APPEARANCE("window.active.title.bg", theme->a_focused_title, FALSE);
456     READ_APPEARANCE("window.inactive.title.bg", theme->a_unfocused_title,
457                     FALSE);
458     READ_APPEARANCE("window.active.label.bg", theme->a_focused_label, TRUE);
459     READ_APPEARANCE("window.inactive.label.bg", theme->a_unfocused_label,
460                     TRUE);
461     READ_APPEARANCE("window.active.handle.bg", theme->a_focused_handle, FALSE);
462     READ_APPEARANCE("window.inactive.handle.bg",theme->a_unfocused_handle,
463                     FALSE);
464     READ_APPEARANCE("window.active.grip.bg", theme->a_focused_grip, TRUE);
465     READ_APPEARANCE("window.inactive.grip.bg", theme->a_unfocused_grip, TRUE);
466     READ_APPEARANCE("menu.items.bg", theme->a_menu, FALSE);
467     READ_APPEARANCE("menu.title.bg", theme->a_menu_title, TRUE);
468     READ_APPEARANCE("menu.items.active.bg", theme->a_menu_selected, TRUE);
469
470     theme->a_menu_disabled_selected =
471         RrAppearanceCopy(theme->a_menu_selected);
472
473     /* read appearances for non-decorations (on-screen-display) */
474     if (!read_appearance(db, inst, "osd.bg", theme->osd_hilite_bg, FALSE)) {
475         RrAppearanceFree(theme->osd_hilite_bg);
476         theme->osd_hilite_bg = RrAppearanceCopy(theme->a_focused_title);
477     }
478     if (!read_appearance(db, inst, "osd.label.bg",
479                          theme->osd_hilite_label, TRUE)) {
480         RrAppearanceFree(theme->osd_hilite_label);
481         theme->osd_hilite_label = RrAppearanceCopy(theme->a_focused_label);
482     }
483     /* osd_hilite_fg can't be parentrel */
484     if (!read_appearance(db, inst, "osd.hilight.bg",
485                          theme->osd_hilite_fg, FALSE)) {
486         RrAppearanceFree(theme->osd_hilite_fg);
487         if (theme->a_focused_label->surface.grad != RR_SURFACE_PARENTREL)
488             theme->osd_hilite_fg = RrAppearanceCopy(theme->a_focused_label);
489         else
490             theme->osd_hilite_fg = RrAppearanceCopy(theme->a_focused_title);
491     }
492     /* osd_unhilite_fg can't be parentrel either */
493     if (!read_appearance(db, inst, "osd.unhilight.bg",
494                          theme->osd_unhilite_fg, FALSE)) {
495         RrAppearanceFree(theme->osd_unhilite_fg);
496         if (theme->a_unfocused_label->surface.grad != RR_SURFACE_PARENTREL)
497             theme->osd_unhilite_fg=RrAppearanceCopy(theme->a_unfocused_label);
498         else
499             theme->osd_unhilite_fg=RrAppearanceCopy(theme->a_unfocused_title);
500     }
501
502     /* read buttons textures */
503     READ_APPEARANCE("window.active.button.disabled.bg",
504                     theme->a_disabled_focused_max, TRUE);
505     READ_APPEARANCE("window.inactive.button.disabled.bg",
506                     theme->a_disabled_unfocused_max, TRUE);
507     READ_APPEARANCE("window.active.button.pressed.bg",
508                     theme->a_focused_pressed_max, TRUE);
509     READ_APPEARANCE("window.inactive.button.pressed.bg",
510                     theme->a_unfocused_pressed_max, TRUE);
511
512     READ_APPEARANCE_("window.active.button.toggled.unpressed.bg",
513                      "window.active.button.toggled.bg",
514                      theme->a_toggled_focused_unpressed_max, TRUE,
515                      theme->a_focused_pressed_max);
516     READ_APPEARANCE_("window.inactive.button.toggled.unpressed.bg",
517                      "window.inactive.button.toggled.bg",
518                      theme->a_toggled_unfocused_unpressed_max, TRUE,
519                      theme->a_unfocused_pressed_max);
520
521     READ_APPEARANCE_COPY("window.active.button.toggled.hover.bg",
522                          theme->a_toggled_hover_focused_max, TRUE,
523                          theme->a_toggled_focused_unpressed_max);
524     READ_APPEARANCE_COPY("window.inactive.button.toggled.hover.bg",
525                          theme->a_toggled_hover_unfocused_max, TRUE,
526                          theme->a_toggled_unfocused_unpressed_max);
527
528     READ_APPEARANCE_COPY("window.active.button.toggled.pressed.bg",
529                          theme->a_toggled_focused_pressed_max, TRUE,
530                          theme->a_focused_pressed_max);
531     READ_APPEARANCE_COPY("window.inactive.button.toggled.pressed.bg",
532                          theme->a_toggled_unfocused_pressed_max, TRUE,
533                          theme->a_unfocused_pressed_max);
534
535     READ_APPEARANCE("window.active.button.unpressed.bg",
536                     theme->a_focused_unpressed_max, TRUE);
537     READ_APPEARANCE("window.inactive.button.unpressed.bg",
538                     theme->a_unfocused_unpressed_max, TRUE);
539
540     READ_APPEARANCE_COPY("window.active.button.hover.bg",
541                          theme->a_hover_focused_max, TRUE,
542                          theme->a_focused_unpressed_max);
543     READ_APPEARANCE_COPY("window.inactive.button.hover.bg",
544                          theme->a_hover_unfocused_max, TRUE,
545                          theme->a_unfocused_unpressed_max);
546
547     theme->a_disabled_focused_close =
548         RrAppearanceCopy(theme->a_disabled_focused_max);
549     theme->a_disabled_unfocused_close =
550         RrAppearanceCopy(theme->a_disabled_unfocused_max);
551     theme->a_hover_focused_close =
552         RrAppearanceCopy(theme->a_hover_focused_max);
553     theme->a_hover_unfocused_close =
554         RrAppearanceCopy(theme->a_hover_unfocused_max);
555     theme->a_unfocused_unpressed_close =
556         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
557     theme->a_unfocused_pressed_close =
558         RrAppearanceCopy(theme->a_unfocused_pressed_max);
559     theme->a_focused_unpressed_close =
560         RrAppearanceCopy(theme->a_focused_unpressed_max);
561     theme->a_focused_pressed_close =
562         RrAppearanceCopy(theme->a_focused_pressed_max);
563     theme->a_disabled_focused_desk =
564         RrAppearanceCopy(theme->a_disabled_focused_max);
565     theme->a_disabled_unfocused_desk =
566         RrAppearanceCopy(theme->a_disabled_unfocused_max);
567     theme->a_hover_focused_desk =
568         RrAppearanceCopy(theme->a_hover_focused_max);
569     theme->a_hover_unfocused_desk =
570         RrAppearanceCopy(theme->a_hover_unfocused_max);
571     theme->a_toggled_hover_focused_desk =
572         RrAppearanceCopy(theme->a_toggled_hover_focused_max);
573     theme->a_toggled_hover_unfocused_desk =
574         RrAppearanceCopy(theme->a_toggled_hover_unfocused_max);
575     theme->a_toggled_focused_unpressed_desk =
576         RrAppearanceCopy(theme->a_toggled_focused_unpressed_max);
577     theme->a_toggled_unfocused_unpressed_desk =
578         RrAppearanceCopy(theme->a_toggled_unfocused_unpressed_max);
579     theme->a_toggled_focused_pressed_desk =
580         RrAppearanceCopy(theme->a_toggled_focused_pressed_max);
581     theme->a_toggled_unfocused_pressed_desk =
582         RrAppearanceCopy(theme->a_toggled_unfocused_pressed_max);
583     theme->a_unfocused_unpressed_desk =
584         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
585     theme->a_unfocused_pressed_desk =
586         RrAppearanceCopy(theme->a_unfocused_pressed_max);
587     theme->a_focused_unpressed_desk =
588         RrAppearanceCopy(theme->a_focused_unpressed_max);
589     theme->a_focused_pressed_desk =
590         RrAppearanceCopy(theme->a_focused_pressed_max);
591     theme->a_disabled_focused_shade =
592         RrAppearanceCopy(theme->a_disabled_focused_max);
593     theme->a_disabled_unfocused_shade =
594         RrAppearanceCopy(theme->a_disabled_unfocused_max);
595     theme->a_hover_focused_shade =
596         RrAppearanceCopy(theme->a_hover_focused_max);
597     theme->a_hover_unfocused_shade =
598         RrAppearanceCopy(theme->a_hover_unfocused_max);
599     theme->a_toggled_hover_focused_shade =
600         RrAppearanceCopy(theme->a_toggled_hover_focused_max);
601     theme->a_toggled_hover_unfocused_shade =
602         RrAppearanceCopy(theme->a_toggled_hover_unfocused_max);
603     theme->a_toggled_focused_unpressed_shade =
604         RrAppearanceCopy(theme->a_toggled_focused_unpressed_max);
605     theme->a_toggled_unfocused_unpressed_shade =
606         RrAppearanceCopy(theme->a_toggled_unfocused_unpressed_max);
607     theme->a_toggled_focused_pressed_shade =
608         RrAppearanceCopy(theme->a_toggled_focused_pressed_max);
609     theme->a_toggled_unfocused_pressed_shade =
610         RrAppearanceCopy(theme->a_toggled_unfocused_pressed_max);
611     theme->a_unfocused_unpressed_shade =
612         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
613     theme->a_unfocused_pressed_shade =
614         RrAppearanceCopy(theme->a_unfocused_pressed_max);
615     theme->a_focused_unpressed_shade =
616         RrAppearanceCopy(theme->a_focused_unpressed_max);
617     theme->a_focused_pressed_shade =
618         RrAppearanceCopy(theme->a_focused_pressed_max);
619     theme->a_disabled_focused_iconify =
620         RrAppearanceCopy(theme->a_disabled_focused_max);
621     theme->a_disabled_unfocused_iconify =
622         RrAppearanceCopy(theme->a_disabled_focused_max);
623     theme->a_hover_focused_iconify =
624         RrAppearanceCopy(theme->a_hover_focused_max);
625     theme->a_hover_unfocused_iconify =
626         RrAppearanceCopy(theme->a_hover_unfocused_max);
627     theme->a_unfocused_unpressed_iconify =
628         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
629     theme->a_unfocused_pressed_iconify =
630         RrAppearanceCopy(theme->a_unfocused_pressed_max);
631     theme->a_focused_unpressed_iconify =
632         RrAppearanceCopy(theme->a_focused_unpressed_max);
633     theme->a_focused_pressed_iconify =
634         RrAppearanceCopy(theme->a_focused_pressed_max);
635
636     theme->a_icon->surface.grad =
637         theme->a_clear->surface.grad =
638         theme->a_clear_tex->surface.grad =
639         theme->a_menu_text_title->surface.grad =
640         theme->a_menu_normal->surface.grad =
641         theme->a_menu_disabled->surface.grad =
642         theme->a_menu_text_normal->surface.grad =
643         theme->a_menu_text_selected->surface.grad =
644         theme->a_menu_text_disabled->surface.grad =
645         theme->a_menu_text_disabled_selected->surface.grad =
646         theme->a_menu_bullet_normal->surface.grad =
647         theme->a_menu_bullet_selected->surface.grad = RR_SURFACE_PARENTREL;
648
649     /* set up the textures */
650     theme->a_focused_label->texture[0].type = RR_TEXTURE_TEXT;
651     theme->a_focused_label->texture[0].data.text.justify = winjust;
652     theme->a_focused_label->texture[0].data.text.font=theme->win_font_focused;
653     theme->a_focused_label->texture[0].data.text.color =
654         theme->title_focused_color;
655
656     if (read_string(db, "window.active.label.text.font", &str)) {
657         char *p;
658         gint i = 0;
659         gint j;
660         if (strstr(str, "shadow=y")) {
661             if ((p = strstr(str, "shadowoffset=")))
662                 i = parse_inline_number(p + strlen("shadowoffset="));
663             else
664                 i = 1;
665             theme->a_focused_label->texture[0].data.text.shadow_offset_x = i;
666             theme->a_focused_label->texture[0].data.text.shadow_offset_y = i;
667         }
668         if ((p = strstr(str, "shadowtint=")))
669         {
670             i = parse_inline_number(p + strlen("shadowtint="));
671             j = (i > 0 ? 0 : 255);
672             i = ABS(i*255/100);
673
674             theme->title_focused_shadow_color = RrColorNew(inst, j, j, j);
675             theme->title_focused_shadow_alpha = i;
676         } else {
677             theme->title_focused_shadow_color = RrColorNew(inst, 0, 0, 0);
678             theme->title_focused_shadow_alpha = 50;
679         }
680     }
681
682     theme->a_focused_label->texture[0].data.text.shadow_color =
683         theme->title_focused_shadow_color;
684     theme->a_focused_label->texture[0].data.text.shadow_alpha =
685         theme->title_focused_shadow_alpha;
686
687     theme->osd_hilite_label->texture[0].type = RR_TEXTURE_TEXT;
688     theme->osd_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
689     theme->osd_hilite_label->texture[0].data.text.font = theme->osd_font;
690     theme->osd_hilite_label->texture[0].data.text.color = theme->osd_color;
691
692     if (read_string(db, "osd.label.text.font", &str)) {
693         char *p;
694         gint i = 0;
695         gint j;
696         if (strstr(str, "shadow=y")) {
697             if ((p = strstr(str, "shadowoffset=")))
698                 i = parse_inline_number(p + strlen("shadowoffset="));
699             else
700                 i = 1;
701             theme->a_focused_label->texture[0].data.text.shadow_offset_x = i;
702             theme->a_focused_label->texture[0].data.text.shadow_offset_y = i;
703             theme->osd_hilite_label->texture[0].data.text.shadow_offset_x = i;
704             theme->osd_hilite_label->texture[0].data.text.shadow_offset_y = i;
705         }
706         if ((p = strstr(str, "shadowtint=")))
707         {
708             i = parse_inline_number(p + strlen("shadowtint="));
709             j = (i > 0 ? 0 : 255);
710             i = ABS(i*255/100);
711
712             theme->title_focused_shadow_color = RrColorNew(inst, j, j, j);
713             theme->title_focused_shadow_alpha = i;
714             theme->osd_shadow_color = RrColorNew(inst, j, j, j);
715             theme->osd_shadow_alpha = i;
716         } else {
717             theme->title_focused_shadow_color = RrColorNew(inst, 0, 0, 0);
718             theme->title_focused_shadow_alpha = 50;
719             theme->osd_shadow_color = RrColorNew(inst, 0, 0, 0);
720             theme->osd_shadow_alpha = 50;
721         }
722     } else {
723         /* inherit the font settings from the focused label */
724         theme->osd_hilite_label->texture[0].data.text.shadow_offset_x =
725             theme->a_focused_label->texture[0].data.text.shadow_offset_x;
726         theme->osd_hilite_label->texture[0].data.text.shadow_offset_y =
727             theme->a_focused_label->texture[0].data.text.shadow_offset_y;
728         if (theme->title_focused_shadow_color)
729             theme->osd_shadow_color =
730                 RrColorNew(inst,
731                            theme->title_focused_shadow_color->r,
732                            theme->title_focused_shadow_color->g,
733                            theme->title_focused_shadow_color->b);
734         else
735             theme->osd_shadow_color = RrColorNew(inst, 0, 0, 0);
736         theme->osd_shadow_alpha = theme->title_focused_shadow_alpha;
737     }
738
739     theme->osd_hilite_label->texture[0].data.text.shadow_color =
740         theme->osd_shadow_color;
741     theme->osd_hilite_label->texture[0].data.text.shadow_alpha =
742         theme->osd_shadow_alpha;
743
744     theme->a_unfocused_label->texture[0].type = RR_TEXTURE_TEXT;
745     theme->a_unfocused_label->texture[0].data.text.justify = winjust;
746     theme->a_unfocused_label->texture[0].data.text.font =
747         theme->win_font_unfocused;
748     theme->a_unfocused_label->texture[0].data.text.color =
749         theme->title_unfocused_color;
750
751     if (read_string(db, "window.inactive.label.text.font", &str)) {
752         char *p;
753         gint i = 0;
754         gint j;
755         if (strstr(str, "shadow=y")) {
756             if ((p = strstr(str, "shadowoffset=")))
757                 i = parse_inline_number(p + strlen("shadowoffset="));
758             else
759                 i = 1;
760             theme->a_unfocused_label->texture[0].data.text.shadow_offset_x = i;
761             theme->a_unfocused_label->texture[0].data.text.shadow_offset_y = i;
762         }
763         if ((p = strstr(str, "shadowtint=")))
764         {
765             i = parse_inline_number(p + strlen("shadowtint="));
766             j = (i > 0 ? 0 : 255);
767             i = ABS(i*255/100);
768
769             theme->title_unfocused_shadow_color = RrColorNew(inst, j, j, j);
770             theme->title_unfocused_shadow_alpha = i;
771         } else {
772             theme->title_unfocused_shadow_color = RrColorNew(inst, 0, 0, 0);
773             theme->title_unfocused_shadow_alpha = 50;
774         }
775     }
776
777     theme->a_unfocused_label->texture[0].data.text.shadow_color =
778         theme->title_unfocused_shadow_color;
779     theme->a_unfocused_label->texture[0].data.text.shadow_alpha =
780         theme->title_unfocused_shadow_alpha;
781
782     theme->a_menu_text_title->texture[0].type = RR_TEXTURE_TEXT;
783     theme->a_menu_text_title->texture[0].data.text.justify = mtitlejust;
784     theme->a_menu_text_title->texture[0].data.text.font =
785         theme->menu_title_font;
786     theme->a_menu_text_title->texture[0].data.text.color =
787         theme->menu_title_color;
788
789     if (read_string(db, "menu.title.text.font", &str)) {
790         char *p;
791         gint i = 0;
792         gint j;
793         if (strstr(str, "shadow=y")) {
794             if ((p = strstr(str, "shadowoffset=")))
795                 i = parse_inline_number(p + strlen("shadowoffset="));
796             else
797                 i = 1;
798             theme->a_menu_text_title->texture[0].data.text.shadow_offset_x = i;
799             theme->a_menu_text_title->texture[0].data.text.shadow_offset_y = i;
800         }
801         if ((p = strstr(str, "shadowtint=")))
802         {
803             i = parse_inline_number(p + strlen("shadowtint="));
804             j = (i > 0 ? 0 : 255);
805             i = ABS(i*255/100);
806
807             theme->menu_title_shadow_color = RrColorNew(inst, j, j, j);
808             theme->menu_title_shadow_alpha = i;
809         } else {
810             theme->menu_title_shadow_color = RrColorNew(inst, 0, 0, 0);
811             theme->menu_title_shadow_alpha = 50;
812         }
813     }
814
815     theme->a_menu_text_title->texture[0].data.text.shadow_color =
816         theme->menu_title_shadow_color;
817     theme->a_menu_text_title->texture[0].data.text.shadow_alpha =
818         theme->menu_title_shadow_alpha;
819
820     theme->a_menu_text_normal->texture[0].type =
821         theme->a_menu_text_selected->texture[0].type =
822         theme->a_menu_text_disabled->texture[0].type =
823         theme->a_menu_text_disabled_selected->texture[0].type =
824         RR_TEXTURE_TEXT;
825     theme->a_menu_text_normal->texture[0].data.text.justify =
826         theme->a_menu_text_selected->texture[0].data.text.justify =
827         theme->a_menu_text_disabled->texture[0].data.text.justify =
828         theme->a_menu_text_disabled_selected->texture[0].data.text.justify =
829         RR_JUSTIFY_LEFT;
830     theme->a_menu_text_normal->texture[0].data.text.font =
831         theme->a_menu_text_selected->texture[0].data.text.font =
832         theme->a_menu_text_disabled->texture[0].data.text.font =
833         theme->a_menu_text_disabled_selected->texture[0].data.text.font =
834         theme->menu_font;
835     theme->a_menu_text_normal->texture[0].data.text.color = theme->menu_color;
836     theme->a_menu_text_selected->texture[0].data.text.color =
837         theme->menu_selected_color;
838     theme->a_menu_text_disabled->texture[0].data.text.color =
839         theme->menu_disabled_color;
840     theme->a_menu_text_disabled_selected->texture[0].data.text.color =
841         theme->menu_disabled_selected_color;
842
843     if (read_string(db, "menu.items.font", &str)) {
844         char *p;
845         gint i = 0;
846         gint j;
847         if (strstr(str, "shadow=y")) {
848             if ((p = strstr(str, "shadowoffset=")))
849                 i = parse_inline_number(p + strlen("shadowoffset="));
850             else
851                 i = 1;
852             theme->a_menu_text_normal->
853                 texture[0].data.text.shadow_offset_x = i;
854             theme->a_menu_text_normal->
855                 texture[0].data.text.shadow_offset_y = i;
856             theme->a_menu_text_selected->
857                 texture[0].data.text.shadow_offset_x = i;
858             theme->a_menu_text_selected->
859                 texture[0].data.text.shadow_offset_y = i;
860             theme->a_menu_text_disabled->
861                 texture[0].data.text.shadow_offset_x = i;
862             theme->a_menu_text_disabled->
863                 texture[0].data.text.shadow_offset_y = i;
864             theme->a_menu_text_disabled_selected->
865                 texture[0].data.text.shadow_offset_x = i;
866             theme->a_menu_text_disabled_selected->
867                 texture[0].data.text.shadow_offset_y = i;
868         }
869         if ((p = strstr(str, "shadowtint=")))
870         {
871             i = parse_inline_number(p + strlen("shadowtint="));
872             j = (i > 0 ? 0 : 255);
873             i = ABS(i*255/100);
874
875             theme->menu_text_normal_shadow_color = RrColorNew(inst, j, j, j);
876             theme->menu_text_selected_shadow_color = RrColorNew(inst, j, j, j);
877             theme->menu_text_disabled_shadow_color = RrColorNew(inst, j, j, j);
878             theme->menu_text_normal_shadow_alpha = i;
879             theme->menu_text_selected_shadow_alpha = i;
880             theme->menu_text_disabled_shadow_alpha = i;
881             theme->menu_text_disabled_selected_shadow_alpha = i;
882         } else {
883             theme->menu_text_normal_shadow_color = RrColorNew(inst, 0, 0, 0);
884             theme->menu_text_selected_shadow_color = RrColorNew(inst, 0, 0, 0);
885             theme->menu_text_disabled_shadow_color = RrColorNew(inst, 0, 0, 0);
886             theme->menu_text_normal_shadow_alpha = 50;
887             theme->menu_text_selected_shadow_alpha = 50;
888             theme->menu_text_disabled_selected_shadow_alpha = 50;
889         }
890     }
891
892     theme->a_menu_text_normal->texture[0].data.text.shadow_color =
893         theme->menu_text_normal_shadow_color;
894     theme->a_menu_text_normal->texture[0].data.text.shadow_alpha =
895         theme->menu_text_normal_shadow_alpha;
896     theme->a_menu_text_selected->texture[0].data.text.shadow_color =
897         theme->menu_text_selected_shadow_color;
898     theme->a_menu_text_selected->texture[0].data.text.shadow_alpha =
899         theme->menu_text_selected_shadow_alpha;
900     theme->a_menu_text_disabled->texture[0].data.text.shadow_color =
901         theme->menu_text_disabled_shadow_color;
902     theme->a_menu_text_disabled->texture[0].data.text.shadow_alpha =
903         theme->menu_text_disabled_shadow_alpha;
904     theme->a_menu_text_disabled_selected->texture[0].data.text.shadow_color =
905         theme->menu_text_disabled_shadow_color;
906     theme->a_menu_text_disabled_selected->texture[0].data.text.shadow_alpha =
907         theme->menu_text_disabled_shadow_alpha;
908
909     theme->a_disabled_focused_max->texture[0].type =
910         theme->a_disabled_unfocused_max->texture[0].type =
911         theme->a_hover_focused_max->texture[0].type =
912         theme->a_hover_unfocused_max->texture[0].type =
913         theme->a_toggled_hover_focused_max->texture[0].type =
914         theme->a_toggled_hover_unfocused_max->texture[0].type =
915         theme->a_toggled_focused_unpressed_max->texture[0].type =
916         theme->a_toggled_unfocused_unpressed_max->texture[0].type =
917         theme->a_toggled_focused_pressed_max->texture[0].type =
918         theme->a_toggled_unfocused_pressed_max->texture[0].type =
919         theme->a_focused_unpressed_max->texture[0].type =
920         theme->a_focused_pressed_max->texture[0].type =
921         theme->a_unfocused_unpressed_max->texture[0].type =
922         theme->a_unfocused_pressed_max->texture[0].type =
923         theme->a_disabled_focused_close->texture[0].type =
924         theme->a_disabled_unfocused_close->texture[0].type =
925         theme->a_hover_focused_close->texture[0].type =
926         theme->a_hover_unfocused_close->texture[0].type =
927         theme->a_focused_unpressed_close->texture[0].type =
928         theme->a_focused_pressed_close->texture[0].type =
929         theme->a_unfocused_unpressed_close->texture[0].type =
930         theme->a_unfocused_pressed_close->texture[0].type =
931         theme->a_disabled_focused_desk->texture[0].type =
932         theme->a_disabled_unfocused_desk->texture[0].type =
933         theme->a_hover_focused_desk->texture[0].type =
934         theme->a_hover_unfocused_desk->texture[0].type =
935         theme->a_toggled_hover_focused_desk->texture[0].type =
936         theme->a_toggled_hover_unfocused_desk->texture[0].type =
937         theme->a_toggled_focused_unpressed_desk->texture[0].type =
938         theme->a_toggled_unfocused_unpressed_desk->texture[0].type =
939         theme->a_toggled_focused_pressed_desk->texture[0].type =
940         theme->a_toggled_unfocused_pressed_desk->texture[0].type =
941         theme->a_focused_unpressed_desk->texture[0].type =
942         theme->a_focused_pressed_desk->texture[0].type =
943         theme->a_unfocused_unpressed_desk->texture[0].type =
944         theme->a_unfocused_pressed_desk->texture[0].type =
945         theme->a_disabled_focused_shade->texture[0].type =
946         theme->a_disabled_unfocused_shade->texture[0].type =
947         theme->a_hover_focused_shade->texture[0].type =
948         theme->a_hover_unfocused_shade->texture[0].type =
949         theme->a_toggled_hover_focused_shade->texture[0].type =
950         theme->a_toggled_hover_unfocused_shade->texture[0].type =
951         theme->a_toggled_focused_unpressed_shade->texture[0].type =
952         theme->a_toggled_unfocused_unpressed_shade->texture[0].type =
953         theme->a_toggled_focused_pressed_shade->texture[0].type =
954         theme->a_toggled_unfocused_pressed_shade->texture[0].type =
955         theme->a_focused_unpressed_shade->texture[0].type =
956         theme->a_focused_pressed_shade->texture[0].type =
957         theme->a_unfocused_unpressed_shade->texture[0].type =
958         theme->a_unfocused_pressed_shade->texture[0].type =
959         theme->a_disabled_focused_iconify->texture[0].type =
960         theme->a_disabled_unfocused_iconify->texture[0].type =
961         theme->a_hover_focused_iconify->texture[0].type =
962         theme->a_hover_unfocused_iconify->texture[0].type =
963         theme->a_focused_unpressed_iconify->texture[0].type =
964         theme->a_focused_pressed_iconify->texture[0].type =
965         theme->a_unfocused_unpressed_iconify->texture[0].type =
966         theme->a_unfocused_pressed_iconify->texture[0].type =
967         theme->a_menu_bullet_normal->texture[0].type =
968         theme->a_menu_bullet_selected->texture[0].type = RR_TEXTURE_MASK;
969
970     theme->a_disabled_focused_max->texture[0].data.mask.mask =
971         theme->a_disabled_unfocused_max->texture[0].data.mask.mask =
972         theme->max_disabled_mask;
973     theme->a_hover_focused_max->texture[0].data.mask.mask =
974         theme->a_hover_unfocused_max->texture[0].data.mask.mask =
975         theme->max_hover_mask;
976     theme->a_focused_pressed_max->texture[0].data.mask.mask =
977         theme->a_unfocused_pressed_max->texture[0].data.mask.mask =
978         theme->max_pressed_mask;
979     theme->a_focused_unpressed_max->texture[0].data.mask.mask =
980         theme->a_unfocused_unpressed_max->texture[0].data.mask.mask =
981         theme->max_mask;
982     theme->a_toggled_hover_focused_max->texture[0].data.mask.mask =
983         theme->a_toggled_hover_unfocused_max->texture[0].data.mask.mask =
984         theme->max_toggled_hover_mask;
985     theme->a_toggled_focused_unpressed_max->texture[0].data.mask.mask =
986         theme->a_toggled_unfocused_unpressed_max->texture[0].data.mask.mask =
987         theme->max_toggled_mask;
988     theme->a_toggled_focused_pressed_max->texture[0].data.mask.mask =
989         theme->a_toggled_unfocused_pressed_max->texture[0].data.mask.mask =
990         theme->max_toggled_pressed_mask;
991     theme->a_disabled_focused_close->texture[0].data.mask.mask =
992         theme->a_disabled_unfocused_close->texture[0].data.mask.mask =
993         theme->close_disabled_mask;
994     theme->a_hover_focused_close->texture[0].data.mask.mask =
995         theme->a_hover_unfocused_close->texture[0].data.mask.mask =
996         theme->close_hover_mask;
997     theme->a_focused_pressed_close->texture[0].data.mask.mask =
998         theme->a_unfocused_pressed_close->texture[0].data.mask.mask =
999         theme->close_pressed_mask;
1000     theme->a_focused_unpressed_close->texture[0].data.mask.mask =
1001         theme->a_unfocused_unpressed_close->texture[0].data.mask.mask =
1002         theme->close_mask;
1003     theme->a_disabled_focused_desk->texture[0].data.mask.mask =
1004         theme->a_disabled_unfocused_desk->texture[0].data.mask.mask =
1005         theme->desk_disabled_mask;
1006     theme->a_hover_focused_desk->texture[0].data.mask.mask =
1007         theme->a_hover_unfocused_desk->texture[0].data.mask.mask =
1008         theme->desk_hover_mask;
1009     theme->a_focused_pressed_desk->texture[0].data.mask.mask =
1010         theme->a_unfocused_pressed_desk->texture[0].data.mask.mask =
1011         theme->desk_pressed_mask;
1012     theme->a_focused_unpressed_desk->texture[0].data.mask.mask =
1013         theme->a_unfocused_unpressed_desk->texture[0].data.mask.mask =
1014         theme->desk_mask;
1015     theme->a_toggled_hover_focused_desk->texture[0].data.mask.mask =
1016         theme->a_toggled_hover_unfocused_desk->texture[0].data.mask.mask =
1017         theme->desk_toggled_hover_mask;
1018     theme->a_toggled_focused_unpressed_desk->texture[0].data.mask.mask =
1019         theme->a_toggled_unfocused_unpressed_desk->texture[0].data.mask.mask =
1020         theme->desk_toggled_mask;
1021     theme->a_toggled_focused_pressed_desk->texture[0].data.mask.mask =
1022         theme->a_toggled_unfocused_pressed_desk->texture[0].data.mask.mask =
1023         theme->desk_toggled_pressed_mask;
1024     theme->a_disabled_focused_shade->texture[0].data.mask.mask =
1025         theme->a_disabled_unfocused_shade->texture[0].data.mask.mask =
1026         theme->shade_disabled_mask;
1027     theme->a_hover_focused_shade->texture[0].data.mask.mask =
1028         theme->a_hover_unfocused_shade->texture[0].data.mask.mask =
1029         theme->shade_hover_mask;
1030     theme->a_focused_pressed_shade->texture[0].data.mask.mask =
1031         theme->a_unfocused_pressed_shade->texture[0].data.mask.mask =
1032         theme->shade_pressed_mask;
1033     theme->a_focused_unpressed_shade->texture[0].data.mask.mask =
1034         theme->a_unfocused_unpressed_shade->texture[0].data.mask.mask =
1035         theme->shade_mask;
1036     theme->a_toggled_hover_focused_shade->texture[0].data.mask.mask =
1037         theme->a_toggled_hover_unfocused_shade->texture[0].data.mask.mask =
1038         theme->shade_toggled_hover_mask;
1039     theme->a_toggled_focused_unpressed_shade->texture[0].data.mask.mask =
1040         theme->a_toggled_unfocused_unpressed_shade->texture[0].data.mask.mask =
1041         theme->shade_toggled_mask;
1042     theme->a_toggled_focused_pressed_shade->texture[0].data.mask.mask =
1043         theme->a_toggled_unfocused_pressed_shade->texture[0].data.mask.mask =
1044         theme->shade_toggled_pressed_mask;
1045     theme->a_disabled_focused_iconify->texture[0].data.mask.mask =
1046         theme->a_disabled_unfocused_iconify->texture[0].data.mask.mask =
1047         theme->iconify_disabled_mask;
1048     theme->a_hover_focused_iconify->texture[0].data.mask.mask =
1049         theme->a_hover_unfocused_iconify->texture[0].data.mask.mask =
1050         theme->iconify_hover_mask;
1051     theme->a_focused_pressed_iconify->texture[0].data.mask.mask =
1052         theme->a_unfocused_pressed_iconify->texture[0].data.mask.mask =
1053         theme->iconify_pressed_mask;
1054     theme->a_focused_unpressed_iconify->texture[0].data.mask.mask =
1055         theme->a_unfocused_unpressed_iconify->texture[0].data.mask.mask =
1056         theme->iconify_mask;
1057     theme->a_menu_bullet_normal->texture[0].data.mask.mask =
1058     theme->a_menu_bullet_selected->texture[0].data.mask.mask =
1059         theme->menu_bullet_mask;
1060     theme->a_disabled_focused_max->texture[0].data.mask.color =
1061         theme->a_disabled_focused_close->texture[0].data.mask.color =
1062         theme->a_disabled_focused_desk->texture[0].data.mask.color =
1063         theme->a_disabled_focused_shade->texture[0].data.mask.color =
1064         theme->a_disabled_focused_iconify->texture[0].data.mask.color =
1065         theme->titlebut_disabled_focused_color;
1066     theme->a_disabled_unfocused_max->texture[0].data.mask.color =
1067         theme->a_disabled_unfocused_close->texture[0].data.mask.color =
1068         theme->a_disabled_unfocused_desk->texture[0].data.mask.color =
1069         theme->a_disabled_unfocused_shade->texture[0].data.mask.color =
1070         theme->a_disabled_unfocused_iconify->texture[0].data.mask.color =
1071         theme->titlebut_disabled_unfocused_color;
1072     theme->a_hover_focused_max->texture[0].data.mask.color =
1073         theme->a_hover_focused_close->texture[0].data.mask.color =
1074         theme->a_hover_focused_desk->texture[0].data.mask.color =
1075         theme->a_hover_focused_shade->texture[0].data.mask.color =
1076         theme->a_hover_focused_iconify->texture[0].data.mask.color =
1077         theme->titlebut_hover_focused_color;
1078     theme->a_hover_unfocused_max->texture[0].data.mask.color =
1079         theme->a_hover_unfocused_close->texture[0].data.mask.color =
1080         theme->a_hover_unfocused_desk->texture[0].data.mask.color =
1081         theme->a_hover_unfocused_shade->texture[0].data.mask.color =
1082         theme->a_hover_unfocused_iconify->texture[0].data.mask.color =
1083         theme->titlebut_hover_unfocused_color;
1084     theme->a_toggled_hover_focused_max->texture[0].data.mask.color =
1085         theme->a_toggled_hover_focused_desk->texture[0].data.mask.color =
1086         theme->a_toggled_hover_focused_shade->texture[0].data.mask.color =
1087         theme->titlebut_toggled_hover_focused_color;
1088     theme->a_toggled_hover_unfocused_max->texture[0].data.mask.color =
1089         theme->a_toggled_hover_unfocused_desk->texture[0].data.mask.color =
1090         theme->a_toggled_hover_unfocused_shade->texture[0].data.mask.color =
1091         theme->titlebut_toggled_hover_unfocused_color;
1092     theme->a_toggled_focused_unpressed_max->texture[0].data.mask.color =
1093         theme->a_toggled_focused_unpressed_desk->texture[0].data.mask.color =
1094         theme->a_toggled_focused_unpressed_shade->texture[0].data.mask.color =
1095         theme->titlebut_toggled_focused_unpressed_color;
1096     theme->a_toggled_unfocused_unpressed_max->texture[0].data.mask.color =
1097         theme->a_toggled_unfocused_unpressed_desk->texture[0].data.mask.color =
1098         theme->a_toggled_unfocused_unpressed_shade->texture[0].data.mask.color=
1099         theme->titlebut_toggled_unfocused_unpressed_color;
1100     theme->a_toggled_focused_pressed_max->texture[0].data.mask.color =
1101         theme->a_toggled_focused_pressed_desk->texture[0].data.mask.color =
1102         theme->a_toggled_focused_pressed_shade->texture[0].data.mask.color =
1103         theme->titlebut_toggled_focused_pressed_color;
1104     theme->a_toggled_unfocused_pressed_max->texture[0].data.mask.color =
1105         theme->a_toggled_unfocused_pressed_desk->texture[0].data.mask.color =
1106         theme->a_toggled_unfocused_pressed_shade->texture[0].data.mask.color =
1107         theme->titlebut_toggled_unfocused_pressed_color;
1108     theme->a_focused_unpressed_max->texture[0].data.mask.color =
1109         theme->a_focused_unpressed_close->texture[0].data.mask.color =
1110         theme->a_focused_unpressed_desk->texture[0].data.mask.color =
1111         theme->a_focused_unpressed_shade->texture[0].data.mask.color =
1112         theme->a_focused_unpressed_iconify->texture[0].data.mask.color =
1113         theme->titlebut_focused_unpressed_color;
1114     theme->a_focused_pressed_max->texture[0].data.mask.color =
1115         theme->a_focused_pressed_close->texture[0].data.mask.color =
1116         theme->a_focused_pressed_desk->texture[0].data.mask.color =
1117         theme->a_focused_pressed_shade->texture[0].data.mask.color =
1118         theme->a_focused_pressed_iconify->texture[0].data.mask.color =
1119         theme->titlebut_focused_pressed_color;
1120     theme->a_unfocused_unpressed_max->texture[0].data.mask.color =
1121         theme->a_unfocused_unpressed_close->texture[0].data.mask.color =
1122         theme->a_unfocused_unpressed_desk->texture[0].data.mask.color =
1123         theme->a_unfocused_unpressed_shade->texture[0].data.mask.color =
1124         theme->a_unfocused_unpressed_iconify->texture[0].data.mask.color =
1125         theme->titlebut_unfocused_unpressed_color;
1126     theme->a_unfocused_pressed_max->texture[0].data.mask.color =
1127         theme->a_unfocused_pressed_close->texture[0].data.mask.color =
1128         theme->a_unfocused_pressed_desk->texture[0].data.mask.color =
1129         theme->a_unfocused_pressed_shade->texture[0].data.mask.color =
1130         theme->a_unfocused_pressed_iconify->texture[0].data.mask.color =
1131         theme->titlebut_unfocused_pressed_color;
1132     theme->a_menu_bullet_normal->texture[0].data.mask.color =
1133         theme->menu_color;
1134     theme->a_menu_bullet_selected->texture[0].data.mask.color =
1135         theme->menu_selected_color;
1136
1137     g_free(path);
1138     XrmDestroyDatabase(db);
1139
1140     /* set the font heights */
1141     theme->win_font_height = RrFontHeight
1142         (theme->win_font_focused,
1143          theme->a_focused_label->texture[0].data.text.shadow_offset_y);
1144     theme->win_font_height =
1145         MAX(theme->win_font_height,
1146             RrFontHeight
1147             (theme->win_font_focused,
1148              theme->a_unfocused_label->texture[0].data.text.shadow_offset_y));
1149     theme->menu_title_font_height = RrFontHeight
1150         (theme->menu_title_font,
1151          theme->a_menu_text_title->texture[0].data.text.shadow_offset_y);
1152     theme->menu_font_height = RrFontHeight
1153         (theme->menu_font,
1154          theme->a_menu_text_normal->texture[0].data.text.shadow_offset_y);
1155
1156     /* calculate some last extents */
1157     {
1158         gint ft, fb, fl, fr, ut, ub, ul, ur;
1159
1160         RrMargins(theme->a_focused_label, &fl, &ft, &fr, &fb);
1161         RrMargins(theme->a_unfocused_label, &ul, &ut, &ur, &ub);
1162         theme->label_height = theme->win_font_height + MAX(ft + fb, ut + ub);
1163         theme->label_height += theme->label_height % 2;
1164
1165         /* this would be nice I think, since padding.width can now be 0,
1166            but it breaks frame.c horribly and I don't feel like fixing that
1167            right now, so if anyone complains, here is how to keep text from
1168            going over the title's bevel/border with a padding.width of 0 and a
1169            bevelless/borderless label
1170            RrMargins(theme->a_focused_title, &fl, &ft, &fr, &fb);
1171            RrMargins(theme->a_unfocused_title, &ul, &ut, &ur, &ub);
1172            theme->title_height = theme->label_height +
1173            MAX(MAX(theme->padding * 2, ft + fb),
1174            MAX(theme->padding * 2, ut + ub));
1175         */
1176         theme->title_height = theme->label_height + theme->paddingy * 2;
1177
1178         RrMargins(theme->a_menu_title, &ul, &ut, &ur, &ub);
1179         theme->menu_title_label_height = theme->menu_title_font_height+ut+ub;
1180         theme->menu_title_height = theme->menu_title_label_height +
1181             theme->paddingy * 2;
1182     }
1183     theme->button_size = theme->label_height - 2;
1184     theme->grip_width = 25;
1185
1186     return theme;
1187 }
1188
1189 void RrThemeFree(RrTheme *theme)
1190 {
1191     if (theme) {
1192         g_free(theme->name);
1193
1194         RrColorFree(theme->menu_border_color);
1195         RrColorFree(theme->osd_border_color);
1196         RrColorFree(theme->frame_focused_border_color);
1197         RrColorFree(theme->frame_unfocused_border_color);
1198         RrColorFree(theme->title_separator_focused_color);
1199         RrColorFree(theme->title_separator_unfocused_color);
1200         RrColorFree(theme->cb_unfocused_color);
1201         RrColorFree(theme->cb_focused_color);
1202         RrColorFree(theme->title_focused_color);
1203         RrColorFree(theme->title_unfocused_color);
1204         RrColorFree(theme->titlebut_disabled_focused_color);
1205         RrColorFree(theme->titlebut_disabled_unfocused_color);
1206         RrColorFree(theme->titlebut_hover_focused_color);
1207         RrColorFree(theme->titlebut_hover_unfocused_color);
1208         RrColorFree(theme->titlebut_toggled_hover_focused_color);
1209         RrColorFree(theme->titlebut_toggled_hover_unfocused_color);
1210         RrColorFree(theme->titlebut_toggled_focused_pressed_color);
1211         RrColorFree(theme->titlebut_toggled_unfocused_pressed_color);
1212         RrColorFree(theme->titlebut_toggled_focused_unpressed_color);
1213         RrColorFree(theme->titlebut_toggled_unfocused_unpressed_color);
1214         RrColorFree(theme->titlebut_focused_pressed_color);
1215         RrColorFree(theme->titlebut_unfocused_pressed_color);
1216         RrColorFree(theme->titlebut_focused_unpressed_color);
1217         RrColorFree(theme->titlebut_unfocused_unpressed_color);
1218         RrColorFree(theme->menu_title_color);
1219         RrColorFree(theme->menu_color);
1220         RrColorFree(theme->menu_selected_color);
1221         RrColorFree(theme->menu_disabled_color);
1222         RrColorFree(theme->menu_disabled_selected_color);
1223         RrColorFree(theme->title_focused_shadow_color);
1224         RrColorFree(theme->title_unfocused_shadow_color);
1225         RrColorFree(theme->osd_color);
1226         RrColorFree(theme->osd_shadow_color);
1227         RrColorFree(theme->menu_title_shadow_color);
1228         RrColorFree(theme->menu_text_normal_shadow_color);
1229         RrColorFree(theme->menu_text_selected_shadow_color);
1230         RrColorFree(theme->menu_text_disabled_shadow_color);
1231         RrColorFree(theme->menu_text_disabled_selected_shadow_color);
1232
1233         g_free(theme->def_win_icon);
1234
1235         RrPixmapMaskFree(theme->max_mask);
1236         RrPixmapMaskFree(theme->max_toggled_mask);
1237         RrPixmapMaskFree(theme->max_toggled_hover_mask);
1238         RrPixmapMaskFree(theme->max_toggled_pressed_mask);
1239         RrPixmapMaskFree(theme->max_disabled_mask);
1240         RrPixmapMaskFree(theme->max_hover_mask);
1241         RrPixmapMaskFree(theme->max_pressed_mask);
1242         RrPixmapMaskFree(theme->desk_mask);
1243         RrPixmapMaskFree(theme->desk_toggled_mask);
1244         RrPixmapMaskFree(theme->desk_toggled_hover_mask);
1245         RrPixmapMaskFree(theme->desk_toggled_pressed_mask);
1246         RrPixmapMaskFree(theme->desk_disabled_mask);
1247         RrPixmapMaskFree(theme->desk_hover_mask);
1248         RrPixmapMaskFree(theme->desk_pressed_mask);
1249         RrPixmapMaskFree(theme->shade_mask);
1250         RrPixmapMaskFree(theme->shade_toggled_mask);
1251         RrPixmapMaskFree(theme->shade_toggled_hover_mask);
1252         RrPixmapMaskFree(theme->shade_toggled_pressed_mask);
1253         RrPixmapMaskFree(theme->shade_disabled_mask);
1254         RrPixmapMaskFree(theme->shade_hover_mask);
1255         RrPixmapMaskFree(theme->shade_pressed_mask);
1256         RrPixmapMaskFree(theme->iconify_mask);
1257         RrPixmapMaskFree(theme->iconify_disabled_mask);
1258         RrPixmapMaskFree(theme->iconify_hover_mask);
1259         RrPixmapMaskFree(theme->iconify_pressed_mask);
1260         RrPixmapMaskFree(theme->close_mask);
1261         RrPixmapMaskFree(theme->close_disabled_mask);
1262         RrPixmapMaskFree(theme->close_hover_mask);
1263         RrPixmapMaskFree(theme->close_pressed_mask);
1264         RrPixmapMaskFree(theme->menu_bullet_mask);
1265
1266         RrFontClose(theme->win_font_focused);
1267         RrFontClose(theme->win_font_unfocused);
1268         RrFontClose(theme->menu_title_font);
1269         RrFontClose(theme->menu_font);
1270
1271         RrAppearanceFree(theme->a_disabled_focused_max);
1272         RrAppearanceFree(theme->a_disabled_unfocused_max);
1273         RrAppearanceFree(theme->a_hover_focused_max);
1274         RrAppearanceFree(theme->a_hover_unfocused_max);
1275         RrAppearanceFree(theme->a_toggled_hover_focused_max);
1276         RrAppearanceFree(theme->a_toggled_hover_unfocused_max);
1277         RrAppearanceFree(theme->a_toggled_focused_unpressed_max);
1278         RrAppearanceFree(theme->a_toggled_focused_pressed_max);
1279         RrAppearanceFree(theme->a_toggled_unfocused_unpressed_max);
1280         RrAppearanceFree(theme->a_toggled_unfocused_pressed_max);
1281         RrAppearanceFree(theme->a_focused_unpressed_max);
1282         RrAppearanceFree(theme->a_focused_pressed_max);
1283         RrAppearanceFree(theme->a_unfocused_unpressed_max);
1284         RrAppearanceFree(theme->a_unfocused_pressed_max);
1285         RrAppearanceFree(theme->a_disabled_focused_close);
1286         RrAppearanceFree(theme->a_disabled_unfocused_close);
1287         RrAppearanceFree(theme->a_hover_focused_close);
1288         RrAppearanceFree(theme->a_hover_unfocused_close);
1289         RrAppearanceFree(theme->a_focused_unpressed_close);
1290         RrAppearanceFree(theme->a_focused_pressed_close);
1291         RrAppearanceFree(theme->a_unfocused_unpressed_close);
1292         RrAppearanceFree(theme->a_unfocused_pressed_close);
1293         RrAppearanceFree(theme->a_disabled_focused_desk);
1294         RrAppearanceFree(theme->a_disabled_unfocused_desk);
1295         RrAppearanceFree(theme->a_hover_focused_desk);
1296         RrAppearanceFree(theme->a_hover_unfocused_desk);
1297         RrAppearanceFree(theme->a_toggled_hover_focused_desk);
1298         RrAppearanceFree(theme->a_toggled_hover_unfocused_desk);
1299         RrAppearanceFree(theme->a_toggled_focused_unpressed_desk);
1300         RrAppearanceFree(theme->a_toggled_focused_pressed_desk);
1301         RrAppearanceFree(theme->a_toggled_unfocused_unpressed_desk);
1302         RrAppearanceFree(theme->a_toggled_unfocused_pressed_desk);
1303         RrAppearanceFree(theme->a_focused_unpressed_desk);
1304         RrAppearanceFree(theme->a_focused_pressed_desk);
1305         RrAppearanceFree(theme->a_unfocused_unpressed_desk);
1306         RrAppearanceFree(theme->a_unfocused_pressed_desk);
1307         RrAppearanceFree(theme->a_disabled_focused_shade);
1308         RrAppearanceFree(theme->a_disabled_unfocused_shade);
1309         RrAppearanceFree(theme->a_hover_focused_shade);
1310         RrAppearanceFree(theme->a_hover_unfocused_shade);
1311         RrAppearanceFree(theme->a_toggled_hover_focused_shade);
1312         RrAppearanceFree(theme->a_toggled_hover_unfocused_shade);
1313         RrAppearanceFree(theme->a_toggled_focused_unpressed_shade);
1314         RrAppearanceFree(theme->a_toggled_focused_pressed_shade);
1315         RrAppearanceFree(theme->a_toggled_unfocused_unpressed_shade);
1316         RrAppearanceFree(theme->a_toggled_unfocused_pressed_shade);
1317         RrAppearanceFree(theme->a_focused_unpressed_shade);
1318         RrAppearanceFree(theme->a_focused_pressed_shade);
1319         RrAppearanceFree(theme->a_unfocused_unpressed_shade);
1320         RrAppearanceFree(theme->a_unfocused_pressed_shade);
1321         RrAppearanceFree(theme->a_disabled_focused_iconify);
1322         RrAppearanceFree(theme->a_disabled_unfocused_iconify);
1323         RrAppearanceFree(theme->a_hover_focused_iconify);
1324         RrAppearanceFree(theme->a_hover_unfocused_iconify);
1325         RrAppearanceFree(theme->a_focused_unpressed_iconify);
1326         RrAppearanceFree(theme->a_focused_pressed_iconify);
1327         RrAppearanceFree(theme->a_unfocused_unpressed_iconify);
1328         RrAppearanceFree(theme->a_unfocused_pressed_iconify);
1329         RrAppearanceFree(theme->a_focused_grip);
1330         RrAppearanceFree(theme->a_unfocused_grip);
1331         RrAppearanceFree(theme->a_focused_title);
1332         RrAppearanceFree(theme->a_unfocused_title);
1333         RrAppearanceFree(theme->a_focused_label);
1334         RrAppearanceFree(theme->a_unfocused_label);
1335         RrAppearanceFree(theme->a_icon);
1336         RrAppearanceFree(theme->a_focused_handle);
1337         RrAppearanceFree(theme->a_unfocused_handle);
1338         RrAppearanceFree(theme->a_menu);
1339         RrAppearanceFree(theme->a_menu_title);
1340         RrAppearanceFree(theme->a_menu_text_title);
1341         RrAppearanceFree(theme->a_menu_normal);
1342         RrAppearanceFree(theme->a_menu_selected);
1343         RrAppearanceFree(theme->a_menu_disabled);
1344         RrAppearanceFree(theme->a_menu_disabled_selected);
1345         RrAppearanceFree(theme->a_menu_text_normal);
1346         RrAppearanceFree(theme->a_menu_text_selected);
1347         RrAppearanceFree(theme->a_menu_text_disabled);
1348         RrAppearanceFree(theme->a_menu_text_disabled_selected);
1349         RrAppearanceFree(theme->a_menu_bullet_normal);
1350         RrAppearanceFree(theme->a_menu_bullet_selected);
1351         RrAppearanceFree(theme->a_clear);
1352         RrAppearanceFree(theme->a_clear_tex);
1353         RrAppearanceFree(theme->osd_hilite_bg);
1354         RrAppearanceFree(theme->osd_hilite_fg);
1355         RrAppearanceFree(theme->osd_hilite_label);
1356         RrAppearanceFree(theme->osd_unhilite_fg);
1357
1358         g_free(theme);
1359     }
1360 }
1361
1362 static XrmDatabase loaddb(const gchar *name, gchar **path)
1363 {
1364     GSList *it;
1365     XrmDatabase db = NULL;
1366     gchar *s;
1367
1368     if (name[0] == '/') {
1369         s = g_build_filename(name, "openbox-3", "themerc", NULL);
1370         if ((db = XrmGetFileDatabase(s)))
1371             *path = g_path_get_dirname(s);
1372         g_free(s);
1373     } else {
1374         /* XXX backwards compatibility, remove me sometime later */
1375         s = g_build_filename(g_get_home_dir(), ".themes", name,
1376                              "openbox-3", "themerc", NULL);
1377         if ((db = XrmGetFileDatabase(s)))
1378             *path = g_path_get_dirname(s);
1379         g_free(s);
1380
1381         for (it = parse_xdg_data_dir_paths(); !db && it;
1382              it = g_slist_next(it))
1383         {
1384             s = g_build_filename(it->data, "themes", name,
1385                                  "openbox-3", "themerc", NULL);
1386             if ((db = XrmGetFileDatabase(s)))
1387                 *path = g_path_get_dirname(s);
1388             g_free(s);
1389         }
1390     }
1391
1392     if (db == NULL) {
1393         s = g_build_filename(name, "themerc", NULL);
1394         if ((db = XrmGetFileDatabase(s)))
1395             *path = g_path_get_dirname(s);
1396         g_free(s);
1397     }
1398
1399     return db;
1400 }
1401
1402 static gchar *create_class_name(const gchar *rname)
1403 {
1404     gchar *rclass = g_strdup(rname);
1405     gchar *p = rclass;
1406
1407     while (TRUE) {
1408         *p = toupper(*p);
1409         p = strchr(p+1, '.');
1410         if (p == NULL) break;
1411         ++p;
1412         if (*p == '\0') break;
1413     }
1414     return rclass;
1415 }
1416
1417 static gboolean read_int(XrmDatabase db, const gchar *rname, gint *value)
1418 {
1419     gboolean ret = FALSE;
1420     gchar *rclass = create_class_name(rname);
1421     gchar *rettype, *end;
1422     XrmValue retvalue;
1423
1424     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1425         retvalue.addr != NULL) {
1426         *value = (gint)strtol(retvalue.addr, &end, 10);
1427         if (end != retvalue.addr)
1428             ret = TRUE;
1429     }
1430
1431     g_free(rclass);
1432     return ret;
1433 }
1434
1435 static gboolean read_string(XrmDatabase db, const gchar *rname, gchar **value)
1436 {
1437     gboolean ret = FALSE;
1438     gchar *rclass = create_class_name(rname);
1439     gchar *rettype;
1440     XrmValue retvalue;
1441
1442     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1443         retvalue.addr != NULL) {
1444         *value = retvalue.addr;
1445         ret = TRUE;
1446     }
1447
1448     g_free(rclass);
1449     return ret;
1450 }
1451
1452 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
1453                            const gchar *rname, RrColor **value)
1454 {
1455     gboolean ret = FALSE;
1456     gchar *rclass = create_class_name(rname);
1457     gchar *rettype;
1458     XrmValue retvalue;
1459
1460     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1461         retvalue.addr != NULL) {
1462         RrColor *c = RrColorParse(inst, retvalue.addr);
1463         if (c != NULL) {
1464             *value = c;
1465             ret = TRUE;
1466         }
1467     }
1468
1469     g_free(rclass);
1470     return ret;
1471 }
1472
1473 static gboolean read_mask(const RrInstance *inst, const gchar *path,
1474                           RrTheme *theme, const gchar *maskname,
1475                           RrPixmapMask **value)
1476 {
1477     gboolean ret = FALSE;
1478     gchar *s;
1479     gint hx, hy; /* ignored */
1480     guint w, h;
1481     guchar *b;
1482
1483     s = g_build_filename(path, maskname, NULL);
1484     if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess) {
1485         ret = TRUE;
1486         *value = RrPixmapMaskNew(inst, w, h, (gchar*)b);
1487         XFree(b);
1488     }
1489     g_free(s);
1490
1491     return ret;
1492 }
1493
1494 static void parse_appearance(gchar *tex, RrSurfaceColorType *grad,
1495                              RrReliefType *relief, RrBevelType *bevel,
1496                              gboolean *interlaced, gboolean *border,
1497                              gboolean allow_trans)
1498 {
1499     gchar *t;
1500
1501     /* convert to all lowercase */
1502     for (t = tex; *t != '\0'; ++t)
1503         *t = g_ascii_tolower(*t);
1504
1505     if (allow_trans && strstr(tex, "parentrelative") != NULL) {
1506         *grad = RR_SURFACE_PARENTREL;
1507     } else {
1508         if (strstr(tex, "gradient") != NULL) {
1509             if (strstr(tex, "crossdiagonal") != NULL)
1510                 *grad = RR_SURFACE_CROSS_DIAGONAL;
1511             else if (strstr(tex, "pyramid") != NULL)
1512                 *grad = RR_SURFACE_PYRAMID;
1513             else if (strstr(tex, "mirrorhorizontal") != NULL)
1514                 *grad = RR_SURFACE_MIRROR_HORIZONTAL;
1515             else if (strstr(tex, "horizontal") != NULL)
1516                 *grad = RR_SURFACE_HORIZONTAL;
1517             else if (strstr(tex, "splitvertical") != NULL)
1518                 *grad = RR_SURFACE_SPLIT_VERTICAL;
1519             else if (strstr(tex, "vertical") != NULL)
1520                 *grad = RR_SURFACE_VERTICAL;
1521             else
1522                 *grad = RR_SURFACE_DIAGONAL;
1523         } else {
1524             *grad = RR_SURFACE_SOLID;
1525         }
1526     }
1527
1528     if (strstr(tex, "sunken") != NULL)
1529         *relief = RR_RELIEF_SUNKEN;
1530     else if (strstr(tex, "flat") != NULL)
1531         *relief = RR_RELIEF_FLAT;
1532     else if (strstr(tex, "raised") != NULL)
1533         *relief = RR_RELIEF_RAISED;
1534     else
1535         *relief = (*grad == RR_SURFACE_PARENTREL) ?
1536                   RR_RELIEF_FLAT : RR_RELIEF_RAISED;
1537
1538     *border = FALSE;
1539     if (*relief == RR_RELIEF_FLAT) {
1540         if (strstr(tex, "border") != NULL)
1541             *border = TRUE;
1542     } else {
1543         if (strstr(tex, "bevel2") != NULL)
1544             *bevel = RR_BEVEL_2;
1545         else
1546             *bevel = RR_BEVEL_1;
1547     }
1548
1549     if (strstr(tex, "interlaced") != NULL)
1550         *interlaced = TRUE;
1551     else
1552         *interlaced = FALSE;
1553 }
1554
1555
1556 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
1557                                 const gchar *rname, RrAppearance *value,
1558                                 gboolean allow_trans)
1559 {
1560     gboolean ret = FALSE;
1561     gchar *rclass = create_class_name(rname);
1562     gchar *cname, *ctoname, *bcname, *icname, *hname, *sname;
1563     gchar *csplitname, *ctosplitname;
1564     gchar *rettype;
1565     XrmValue retvalue;
1566     gint i;
1567
1568     cname = g_strconcat(rname, ".color", NULL);
1569     ctoname = g_strconcat(rname, ".colorTo", NULL);
1570     bcname = g_strconcat(rname, ".border.color", NULL);
1571     icname = g_strconcat(rname, ".interlace.color", NULL);
1572     hname = g_strconcat(rname, ".highlight", NULL);
1573     sname = g_strconcat(rname, ".shadow", NULL);
1574     csplitname = g_strconcat(rname, ".color.splitTo", NULL);
1575     ctosplitname = g_strconcat(rname, ".colorTo.splitTo", NULL);
1576
1577     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1578         retvalue.addr != NULL) {
1579         parse_appearance(retvalue.addr,
1580                          &value->surface.grad,
1581                          &value->surface.relief,
1582                          &value->surface.bevel,
1583                          &value->surface.interlaced,
1584                          &value->surface.border,
1585                          allow_trans);
1586         if (!read_color(db, inst, cname, &value->surface.primary))
1587             value->surface.primary = RrColorNew(inst, 0, 0, 0);
1588         if (!read_color(db, inst, ctoname, &value->surface.secondary))
1589             value->surface.secondary = RrColorNew(inst, 0, 0, 0);
1590         if (value->surface.border)
1591             if (!read_color(db, inst, bcname,
1592                             &value->surface.border_color))
1593                 value->surface.border_color = RrColorNew(inst, 0, 0, 0);
1594         if (value->surface.interlaced)
1595             if (!read_color(db, inst, icname,
1596                             &value->surface.interlace_color))
1597                 value->surface.interlace_color = RrColorNew(inst, 0, 0, 0);
1598         if (read_int(db, hname, &i) && i >= 0)
1599             value->surface.bevel_light_adjust = i;
1600         if (read_int(db, sname, &i) && i >= 0 && i <= 256)
1601             value->surface.bevel_dark_adjust = i;
1602
1603         if (value->surface.grad == RR_SURFACE_SPLIT_VERTICAL) {
1604             gint r, g, b;
1605
1606             if (!read_color(db, inst, csplitname,
1607                             &value->surface.split_primary))
1608             {
1609                 r = value->surface.primary->r;
1610                 r += r >> 2;
1611                 g = value->surface.primary->g;
1612                 g += g >> 2;
1613                 b = value->surface.primary->b;
1614                 b += b >> 2;
1615                 if (r > 0xFF) r = 0xFF;
1616                 if (g > 0xFF) g = 0xFF;
1617                 if (b > 0xFF) b = 0xFF;
1618                 value->surface.split_primary = RrColorNew(inst, r, g, b);
1619             }
1620
1621             if (!read_color(db, inst, ctosplitname,
1622                             &value->surface.split_secondary))
1623             {
1624                 r = value->surface.secondary->r;
1625                 r += r >> 4;
1626                 g = value->surface.secondary->g;
1627                 g += g >> 4;
1628                 b = value->surface.secondary->b;
1629                 b += b >> 4;
1630                 if (r > 0xFF) r = 0xFF;
1631                 if (g > 0xFF) g = 0xFF;
1632                 if (b > 0xFF) b = 0xFF;
1633                 value->surface.split_secondary = RrColorNew(inst, r, g, b);
1634             }
1635         }
1636
1637         ret = TRUE;
1638     }
1639
1640     g_free(ctosplitname);
1641     g_free(csplitname);
1642     g_free(sname);
1643     g_free(hname);
1644     g_free(icname);
1645     g_free(bcname);
1646     g_free(ctoname);
1647     g_free(cname);
1648     g_free(rclass);
1649     return ret;
1650 }
1651
1652 static int parse_inline_number(const char *p)
1653 {
1654     int neg = 1;
1655     int res = 0;
1656     if (*p == '-') {
1657         neg = -1;
1658         ++p;
1659     }
1660     for (; isdigit(*p); ++p)
1661         res = res * 10 + *p - '0';
1662     res *= neg;
1663     return res;
1664 }
1665
1666 static void set_default_appearance(RrAppearance *a)
1667 {
1668     a->surface.grad = RR_SURFACE_SOLID;
1669     a->surface.relief = RR_RELIEF_FLAT;
1670     a->surface.bevel = RR_BEVEL_1;
1671     a->surface.interlaced = FALSE;
1672     a->surface.border = FALSE;
1673     a->surface.primary = RrColorNew(a->inst, 0, 0, 0);
1674     a->surface.secondary = RrColorNew(a->inst, 0, 0, 0);
1675 }
1676
1677 /* Reads the output from gimp's C-Source file format into valid RGBA data for
1678    an RrTextureRGBA. */
1679 static RrPixel32* read_c_image(gint width, gint height, const guint8 *data)
1680 {
1681     RrPixel32 *im, *p;
1682     gint i;
1683
1684     p = im = g_memdup(data, width * height * sizeof(RrPixel32));
1685
1686     for (i = 0; i < width * height; ++i) {
1687         guchar a = ((*p >> 24) & 0xff);
1688         guchar b = ((*p >> 16) & 0xff);
1689         guchar g = ((*p >>  8) & 0xff);
1690         guchar r = ((*p >>  0) & 0xff);
1691
1692         *p = ((r << RrDefaultRedOffset) +
1693               (g << RrDefaultGreenOffset) +
1694               (b << RrDefaultBlueOffset) +
1695               (a << RrDefaultAlphaOffset));
1696         p++;
1697     }
1698
1699     return im;
1700 }