]> icculus.org git repositories - mikachu/openbox.git/blob - obrender/theme.c
Make theme.c indentation more locally consistent
[mikachu/openbox.git] / obrender / 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 "obt/paths.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 static void read_button_colors(XrmDatabase db, const RrInstance *inst, 
49                                const RrTheme *theme, RrButton *btn, 
50                                const gchar *btnname);
51
52 static RrFont *get_font(RrFont *target, RrFont **default_font,
53                         const RrInstance *inst)
54 {
55     if (target) {
56         RrFontRef(target);
57         return target;
58     } else {
59         /* Only load the default font once */
60         if (*default_font) {
61             RrFontRef(*default_font);
62         } else {
63             *default_font = RrFontOpenDefault(inst);
64         }
65         return *default_font;
66     }
67 }
68
69 #define READ_INT(x_resstr, x_var, x_min, x_max, x_def) \
70     if (!read_int(db, x_resstr, & x_var) || \
71             x_var < x_min || x_var > x_max) \
72         x_var = x_def;
73
74 #define READ_COLOR(x_resstr, x_var, x_def) \
75     if (!read_color(db, inst, x_resstr, & x_var)) \
76         x_var = x_def;
77
78 #define READ_COLOR_(x_res1, x_res2, x_var, x_def) \
79     if (!read_color(db, inst, x_res1, & x_var) && \
80         !read_color(db, inst, x_res2, & x_var)) \
81         x_var = x_def;
82
83 #define READ_MASK_COPY(x_file, x_var, x_copysrc) \
84     if (!read_mask(inst, path, theme, x_file, & x_var)) \
85         x_var = RrPixmapMaskCopy(x_copysrc);
86
87 #define READ_APPEARANCE(x_resstr, x_var, x_parrel) \
88     if (!read_appearance(db, inst, x_resstr, x_var, x_parrel)) \
89         set_default_appearance(x_var);
90
91 #define READ_APPEARANCE_COPY(x_resstr, x_var, x_parrel, x_defval) \
92     if (!read_appearance(db, inst, x_resstr, x_var, x_parrel)) {\
93         RrAppearanceFree(x_var); \
94         x_var = RrAppearanceCopy(x_defval); }
95
96 #define READ_APPEARANCE_COPY_TEXTURES(x_resstr, x_var, x_parrel, x_defval, n_tex) \
97     if (!read_appearance(db, inst, x_resstr, x_var, x_parrel)) {\
98         RrAppearanceFree(x_var); \
99         x_var = RrAppearanceCopy(x_defval); \
100         RrAppearanceRemoveTextures(x_var); \
101         RrAppearanceAddTextures(x_var, 5); }
102
103 #define READ_APPEARANCE_(x_res1, x_res2, x_var, x_parrel, x_defval) \
104     if (!read_appearance(db, inst, x_res1, x_var, x_parrel) && \
105         !read_appearance(db, inst, x_res2, x_var, x_parrel)) {\
106         RrAppearanceFree(x_var); \
107         x_var = RrAppearanceCopy(x_defval); }
108
109 RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
110                     gboolean allow_fallback,
111                     RrFont *active_window_font, RrFont *inactive_window_font,
112                     RrFont *menu_title_font, RrFont *menu_item_font,
113                     RrFont *active_osd_font, RrFont *inactive_osd_font)
114 {
115     XrmDatabase db = NULL;
116     RrJustify winjust, mtitlejust;
117     gchar *str;
118     RrTheme *theme;
119     RrFont *default_font = NULL;
120     gchar *path;
121     gboolean userdef;
122     gint menu_overlap = 0;
123     RrAppearance *a_disabled_focused_tmp;
124     RrAppearance *a_disabled_unfocused_tmp;
125     RrAppearance *a_hover_focused_tmp;
126     RrAppearance *a_hover_unfocused_tmp;
127     RrAppearance *a_focused_unpressed_tmp;
128     RrAppearance *a_focused_pressed_tmp;
129     RrAppearance *a_unfocused_unpressed_tmp;
130     RrAppearance *a_unfocused_pressed_tmp;
131     RrAppearance *a_toggled_hover_focused_tmp;
132     RrAppearance *a_toggled_hover_unfocused_tmp;
133     RrAppearance *a_toggled_focused_unpressed_tmp;
134     RrAppearance *a_toggled_focused_pressed_tmp;
135     RrAppearance *a_toggled_unfocused_unpressed_tmp;
136     RrAppearance *a_toggled_unfocused_pressed_tmp;
137
138     if (name) {
139         db = loaddb(name, &path);
140         if (db == NULL) {
141             g_message("Unable to load the theme '%s'", name);
142             if (allow_fallback)
143                 g_message("Falling back to the default theme '%s'",
144                           DEFAULT_THEME);
145             /* fallback to the default theme */
146             name = NULL;
147         }
148     }
149     if (name == NULL) {
150         if (allow_fallback) {
151             db = loaddb(DEFAULT_THEME, &path);
152             if (db == NULL) {
153                 g_message("Unable to load the theme '%s'", DEFAULT_THEME);
154                 return NULL;
155             }
156         } else
157             return NULL;
158     }
159
160     /* initialize temp reading textures */
161     a_disabled_focused_tmp = RrAppearanceNew(inst, 1);
162     a_disabled_unfocused_tmp = RrAppearanceNew(inst, 1);
163     a_hover_focused_tmp = RrAppearanceNew(inst, 1);
164     a_hover_unfocused_tmp = RrAppearanceNew(inst, 1);
165     a_toggled_focused_unpressed_tmp = RrAppearanceNew(inst, 1);
166     a_toggled_unfocused_unpressed_tmp = RrAppearanceNew(inst, 1);
167     a_toggled_hover_focused_tmp = RrAppearanceNew(inst, 1);
168     a_toggled_hover_unfocused_tmp = RrAppearanceNew(inst, 1);
169     a_toggled_focused_pressed_tmp = RrAppearanceNew(inst, 1);
170     a_toggled_unfocused_pressed_tmp = RrAppearanceNew(inst, 1);
171     a_focused_unpressed_tmp = RrAppearanceNew(inst, 1);
172     a_focused_pressed_tmp = RrAppearanceNew(inst, 1);
173     a_unfocused_unpressed_tmp = RrAppearanceNew(inst, 1);
174     a_unfocused_pressed_tmp = RrAppearanceNew(inst, 1);
175
176     /* initialize theme */
177     theme = g_slice_new0(RrTheme);
178
179     theme->inst = inst;
180     theme->name = g_strdup(name ? name : DEFAULT_THEME);
181
182     /* init buttons */
183     theme->btn_max = RrButtonNew(inst);
184     theme->btn_close = RrButtonNew(inst);
185     theme->btn_desk = RrButtonNew(inst);
186     theme->btn_shade = RrButtonNew(inst);
187     theme->btn_iconify = RrButtonNew(inst);
188
189     /* init appearances */
190     theme->a_focused_grip = RrAppearanceNew(inst, 0);
191     theme->a_unfocused_grip = RrAppearanceNew(inst, 0);
192     theme->a_focused_title = RrAppearanceNew(inst, 0);
193     theme->a_unfocused_title = RrAppearanceNew(inst, 0);
194     theme->a_focused_label = RrAppearanceNew(inst, 1);
195     theme->a_unfocused_label = RrAppearanceNew(inst, 1);
196     theme->a_icon = RrAppearanceNew(inst, 1);
197     theme->a_focused_handle = RrAppearanceNew(inst, 0);
198     theme->a_unfocused_handle = RrAppearanceNew(inst, 0);
199     theme->a_menu = RrAppearanceNew(inst, 0);
200     theme->a_menu_title = RrAppearanceNew(inst, 0);
201     theme->a_menu_text_title = RrAppearanceNew(inst, 1);
202     theme->a_menu_normal = RrAppearanceNew(inst, 0);
203     theme->a_menu_selected = RrAppearanceNew(inst, 0);
204     theme->a_menu_disabled = RrAppearanceNew(inst, 0);
205     /* a_menu_disabled_selected is copied from a_menu_selected */
206     theme->a_menu_text_normal = RrAppearanceNew(inst, 1);
207     theme->a_menu_text_selected = RrAppearanceNew(inst, 1);
208     theme->a_menu_text_disabled = RrAppearanceNew(inst, 1);
209     theme->a_menu_text_disabled_selected = RrAppearanceNew(inst, 1);
210     theme->a_menu_bullet_normal = RrAppearanceNew(inst, 1);
211     theme->a_menu_bullet_selected = RrAppearanceNew(inst, 1);
212     theme->a_clear = RrAppearanceNew(inst, 0);
213     theme->a_clear_tex = RrAppearanceNew(inst, 1);
214     theme->osd_bg = RrAppearanceNew(inst, 0);
215     theme->osd_hilite_label = RrAppearanceNew(inst, 1);
216     theme->osd_hilite_bg = RrAppearanceNew(inst, 0);
217     theme->osd_unhilite_label = RrAppearanceNew(inst, 1);
218     theme->osd_unhilite_bg = RrAppearanceNew(inst, 0);
219     theme->osd_unpressed_button = RrAppearanceNew(inst, 1);
220     theme->osd_pressed_button = RrAppearanceNew(inst, 5);
221     theme->osd_focused_button = RrAppearanceNew(inst, 5);
222
223     /* load the font stuff */
224     theme->win_font_focused = get_font(active_window_font,
225                                        &default_font, inst);
226     theme->win_font_unfocused = get_font(inactive_window_font,
227                                          &default_font, inst);
228
229     winjust = RR_JUSTIFY_LEFT;
230     if (read_string(db, "window.label.text.justify", &str)) {
231         if (!g_ascii_strcasecmp(str, "right"))
232             winjust = RR_JUSTIFY_RIGHT;
233         else if (!g_ascii_strcasecmp(str, "center"))
234             winjust = RR_JUSTIFY_CENTER;
235     }
236
237     theme->menu_title_font = get_font(menu_title_font, &default_font, inst);
238
239     mtitlejust = RR_JUSTIFY_LEFT;
240     if (read_string(db, "menu.title.text.justify", &str)) {
241         if (!g_ascii_strcasecmp(str, "right"))
242             mtitlejust = RR_JUSTIFY_RIGHT;
243         else if (!g_ascii_strcasecmp(str, "center"))
244             mtitlejust = RR_JUSTIFY_CENTER;
245     }
246
247     theme->menu_font = get_font(menu_item_font, &default_font, inst);
248
249     theme->osd_font_hilite = get_font(active_osd_font, &default_font, inst);
250     theme->osd_font_unhilite = get_font(inactive_osd_font, &default_font,inst);
251
252     /* load direct dimensions */
253     READ_INT("menu.overlap", menu_overlap, -100, 100, 0);
254     READ_INT("menu.overlap.x", theme->menu_overlap_x, -100, 100, menu_overlap);
255     READ_INT("menu.overlap.y", theme->menu_overlap_y, -100, 100, menu_overlap);
256     READ_INT("window.handle.width", theme->handle_height, 0, 100, 6);
257     READ_INT("padding.width", theme->paddingx, 0, 100, 3);
258     READ_INT("padding.height", theme->paddingy, 0, 100, theme->paddingx);
259     READ_INT("border.width", theme->fbwidth, 0, 100, 1);
260     READ_INT("menu.border.width", theme->mbwidth, 0, 100, theme->fbwidth);
261     READ_INT("osd.border.width", theme->obwidth, 0, 100, theme->fbwidth);
262     READ_INT("undecorated.border.width", theme->ubwidth, 0, 100, theme->fbwidth);
263     READ_INT("menu.separator.width", theme->menu_sep_width, 1, 100, 1);
264     READ_INT("menu.separator.padding.width", theme->menu_sep_paddingx, 0, 100, 6);
265     READ_INT("menu.separator.padding.height", theme->menu_sep_paddingy, 0, 100, 3);
266     READ_INT("window.client.padding.width", theme->cbwidthx, 0, 100, theme->paddingx);
267     READ_INT("window.client.padding.height", theme->cbwidthy, 0, 100, theme->cbwidthx);
268
269     /* load colors */
270     READ_COLOR_("window.active.border.color",
271                 "border.color",
272                 theme->frame_focused_border_color,
273                 RrColorNew(inst, 0, 0, 0));
274     READ_COLOR("window.undecorated.active.border.color",
275                theme->frame_undecorated_focused_border_color,
276                RrColorCopy(theme->frame_focused_border_color));
277     READ_COLOR("window.active.title.separator.color",
278                theme->title_separator_focused_color,
279                RrColorCopy(theme->frame_focused_border_color));
280
281     READ_COLOR("window.inactive.border.color",
282                theme->frame_unfocused_border_color,
283                RrColorCopy(theme->frame_focused_border_color));
284
285     READ_COLOR("window.undecorated.inactive.border.color",
286                theme->frame_undecorated_unfocused_border_color,
287                RrColorCopy(theme->frame_unfocused_border_color));
288
289     READ_COLOR("window.inactive.title.separator.color",
290                theme->title_separator_unfocused_color,
291                RrColorCopy(theme->frame_unfocused_border_color));
292
293     READ_COLOR("menu.border.color",
294                theme->menu_border_color,
295                RrColorCopy(theme->frame_focused_border_color));
296
297     READ_COLOR("osd.border.color", 
298                theme->osd_border_color,
299                RrColorCopy(theme->frame_focused_border_color));
300
301     READ_COLOR("window.active.client.color",
302                theme->cb_focused_color,
303                RrColorNew(inst, 0xff, 0xff, 0xff));
304
305     READ_COLOR("window.inactive.client.color",
306                theme->cb_unfocused_color,
307                RrColorNew(inst, 0xff, 0xff, 0xff));
308
309     READ_COLOR("window.active.label.text.color",
310                theme->title_focused_color,
311                RrColorNew(inst, 0x0, 0x0, 0x0));
312
313     READ_COLOR("window.inactive.label.text.color",
314                theme->title_unfocused_color,
315                RrColorNew(inst, 0xff, 0xff, 0xff));
316
317     READ_COLOR_("osd.active.label.text.color",
318                 "osd.label.text.color",
319                 theme->osd_text_active_color,
320                 RrColorCopy(theme->title_focused_color));
321
322     READ_COLOR_("osd.inactive.label.text.color",
323                 "osd.label.text.color",
324                 theme->osd_text_inactive_color,
325                 RrColorCopy(theme->title_unfocused_color));
326
327     READ_COLOR("window.active.button.unpressed.image.color",
328                theme->titlebut_focused_unpressed_color,
329                RrColorNew(inst, 0, 0, 0));
330
331     READ_COLOR("window.inactive.button.unpressed.image.color",
332                theme->titlebut_unfocused_unpressed_color,
333                RrColorNew(inst, 0xff, 0xff, 0xff));
334
335     READ_COLOR("window.active.button.pressed.image.color",
336                theme->titlebut_focused_pressed_color,
337                RrColorCopy(theme->titlebut_focused_unpressed_color));
338
339     READ_COLOR("window.inactive.button.pressed.image.color",
340                theme->titlebut_unfocused_pressed_color,
341                RrColorCopy(theme->titlebut_unfocused_unpressed_color));
342
343     READ_COLOR("window.active.button.disabled.image.color",
344                theme->titlebut_disabled_focused_color,
345                RrColorNew(inst, 0xff, 0xff, 0xff));
346
347     READ_COLOR("window.inactive.button.disabled.image.color",
348                theme->titlebut_disabled_unfocused_color,
349                RrColorNew(inst, 0, 0, 0));
350
351     READ_COLOR("window.active.button.hover.image.color",
352                theme->titlebut_hover_focused_color,
353                RrColorCopy(theme->titlebut_focused_unpressed_color));
354
355     READ_COLOR("window.inactive.button.hover.image.color",
356                theme->titlebut_hover_unfocused_color,
357                RrColorCopy(theme->titlebut_unfocused_unpressed_color));
358
359     READ_COLOR_("window.active.button.toggled.unpressed.image.color",
360                 "window.active.button.toggled.image.color",
361                 theme->titlebut_toggled_focused_unpressed_color,
362                 RrColorCopy(theme->titlebut_focused_pressed_color));
363
364     READ_COLOR_("window.inactive.button.toggled.unpressed.image.color",
365                 "window.inactive.button.toggled.image.color",
366                 theme->titlebut_toggled_unfocused_unpressed_color,
367                 RrColorCopy(theme->titlebut_unfocused_pressed_color));
368
369     READ_COLOR("window.active.button.toggled.hover.image.color",
370                theme->titlebut_toggled_hover_focused_color,
371                RrColorCopy(theme->titlebut_toggled_focused_unpressed_color));
372
373     READ_COLOR("window.inactive.button.toggled.hover.image.color",
374                theme->titlebut_toggled_hover_unfocused_color,
375                RrColorCopy(theme->titlebut_toggled_unfocused_unpressed_color));
376
377     READ_COLOR("window.active.button.toggled.pressed.image.color",
378                theme->titlebut_toggled_focused_pressed_color,
379                RrColorCopy(theme->titlebut_focused_pressed_color));
380
381     READ_COLOR("window.inactive.button.toggled.pressed.image.color",
382                theme->titlebut_toggled_unfocused_pressed_color,
383                RrColorCopy(theme->titlebut_unfocused_pressed_color));
384
385     READ_COLOR("menu.title.text.color",
386                theme->menu_title_color,
387                RrColorNew(inst, 0, 0, 0));
388
389     READ_COLOR("menu.items.text.color",
390                theme->menu_color,
391                RrColorNew(inst, 0xff, 0xff, 0xff));
392
393     READ_COLOR("menu.bullet.image.color",
394                theme->menu_bullet_color,
395                RrColorCopy(theme->menu_color));
396    
397     READ_COLOR("menu.items.disabled.text.color",
398                theme->menu_disabled_color,
399                RrColorNew(inst, 0, 0, 0));
400
401     READ_COLOR("menu.items.active.disabled.text.color",
402                theme->menu_disabled_selected_color,
403                RrColorCopy(theme->menu_disabled_color));
404
405     READ_COLOR("menu.items.active.text.color",
406                theme->menu_selected_color,
407                RrColorNew(inst, 0, 0, 0));
408
409     READ_COLOR("menu.separator.color",
410                theme->menu_sep_color,
411                RrColorCopy(theme->menu_color));
412     
413     READ_COLOR("menu.bullet.selected.image.color", 
414                theme->menu_bullet_selected_color,
415                RrColorCopy(theme->menu_selected_color));
416
417     READ_COLOR("osd.button.unpressed.text.color",
418                theme->osd_unpressed_color,
419                RrColorCopy(theme->osd_text_active_color));
420     READ_COLOR("osd.button.pressed.text.color",
421                theme->osd_pressed_color,
422                RrColorCopy(theme->osd_text_active_color));
423     READ_COLOR("osd.button.focused.text.color",
424                theme->osd_focused_color,
425                RrColorCopy(theme->osd_text_active_color));
426     READ_COLOR("osd.button.pressed.box.color",
427                theme->osd_pressed_lineart,
428                RrColorCopy(theme->titlebut_focused_pressed_color));
429     READ_COLOR("osd.button.focused.box.color",
430                theme->osd_focused_lineart,
431                RrColorCopy(theme->titlebut_hover_focused_color));
432  
433     /* load the image masks */
434
435     /* maximize button masks */
436     userdef = TRUE;
437     if (!read_mask(inst, path, theme, "max.xbm", &theme->btn_max->mask))
438     {
439             guchar data[] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f };
440             theme->btn_max->mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
441             userdef = FALSE;
442     }
443     if (!read_mask(inst, path, theme, "max_toggled.xbm",
444                    &theme->btn_max->toggled_mask))
445     {
446         if (userdef)
447             theme->btn_max->toggled_mask = RrPixmapMaskCopy(theme->btn_max->mask);
448         else
449         {
450             guchar data[] = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f };
451             theme->btn_max->toggled_mask = RrPixmapMaskNew(inst, 6, 6,(gchar*)data);
452         }
453     }
454     READ_MASK_COPY("max_pressed.xbm",
455                    theme->btn_max->pressed_mask,
456                    theme->btn_max->mask);
457     READ_MASK_COPY("max_disabled.xbm",
458                    theme->btn_max->disabled_mask,
459                    theme->btn_max->mask);
460     READ_MASK_COPY("max_hover.xbm",
461                    theme->btn_max->hover_mask, 
462                    theme->btn_max->mask);
463     READ_MASK_COPY("max_toggled_pressed.xbm", 
464                    theme->btn_max->toggled_pressed_mask, 
465                    theme->btn_max->toggled_mask);
466     READ_MASK_COPY("max_toggled_hover.xbm", 
467                    theme->btn_max->toggled_hover_mask,
468                    theme->btn_max->toggled_mask);
469
470     /* all desktops button masks */
471     userdef = TRUE;
472     if (!read_mask(inst, path, theme, "desk.xbm", &theme->btn_desk->mask))
473     {
474         guchar data[] = { 0x33, 0x33, 0x00, 0x00, 0x33, 0x33 };
475         theme->btn_desk->mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
476         userdef = FALSE;
477     }
478     if (!read_mask(inst, path, theme, "desk_toggled.xbm",
479                    &theme->btn_desk->toggled_mask))
480     {
481         if (userdef)
482             theme->btn_desk->toggled_mask = RrPixmapMaskCopy(theme->btn_desk->mask);
483         else
484         {
485             guchar data[] = { 0x00, 0x1e, 0x1a, 0x16, 0x1e, 0x00 };
486             theme->btn_desk->toggled_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
487         }
488     }
489     READ_MASK_COPY("desk_pressed.xbm",
490                    theme->btn_desk->pressed_mask,
491                    theme->btn_desk->mask);
492     READ_MASK_COPY("desk_disabled.xbm",
493                    theme->btn_desk->disabled_mask,
494                    theme->btn_desk->mask);
495     READ_MASK_COPY("desk_hover.xbm",
496                    theme->btn_desk->hover_mask,
497                    theme->btn_desk->mask);
498     READ_MASK_COPY("desk_toggled_pressed.xbm",
499                    theme->btn_desk->toggled_pressed_mask,
500                    theme->btn_desk->toggled_mask);
501     READ_MASK_COPY("desk_toggled_hover.xbm",
502                    theme->btn_desk->toggled_hover_mask,
503                    theme->btn_desk->toggled_mask);
504
505     /* shade button masks */
506     if (!read_mask(inst, path, theme, "shade.xbm", &theme->btn_shade->mask))
507     {
508         guchar data[] = { 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00 };
509         theme->btn_shade->mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
510     }
511     READ_MASK_COPY("shade_toggled.xbm",
512                    theme->btn_shade->toggled_mask,
513                    theme->btn_shade->mask);
514     READ_MASK_COPY("shade_pressed.xbm",
515                    theme->btn_shade->pressed_mask,
516                    theme->btn_shade->mask);
517     READ_MASK_COPY("shade_disabled.xbm",
518                    theme->btn_shade->disabled_mask,
519                    theme->btn_shade->mask);
520     READ_MASK_COPY("shade_hover.xbm",
521                    theme->btn_shade->hover_mask,
522                    theme->btn_shade->mask);
523     READ_MASK_COPY("shade_toggled_pressed.xbm",
524                    theme->btn_shade->toggled_pressed_mask,
525                    theme->btn_shade->toggled_mask);
526     READ_MASK_COPY("shade_toggled_hover.xbm",
527                    theme->btn_shade->toggled_hover_mask, 
528                    theme->btn_shade->toggled_mask);
529
530     /* iconify button masks */
531     if (!read_mask(inst, path, theme, "iconify.xbm", &theme->btn_iconify->mask))
532     {
533         guchar data[] = { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f };
534         theme->btn_iconify->mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
535     }
536     READ_MASK_COPY("iconify_pressed.xbm",
537                    theme->btn_iconify->pressed_mask,
538                    theme->btn_iconify->mask);
539     READ_MASK_COPY("iconify_disabled.xbm",
540                    theme->btn_iconify->disabled_mask,
541                    theme->btn_iconify->mask);
542     READ_MASK_COPY("iconify_hover.xbm",
543                    theme->btn_iconify->hover_mask,
544                    theme->btn_iconify->mask);
545
546     /* close button masks */
547     if (!read_mask(inst, path, theme, "close.xbm", &theme->btn_close->mask))
548     {
549         guchar data[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 };
550         theme->btn_close->mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
551     }
552     READ_MASK_COPY("close_pressed.xbm",
553                    theme->btn_close->pressed_mask,
554                    theme->btn_close->mask);
555     READ_MASK_COPY("close_disabled.xbm",
556                    theme->btn_close->disabled_mask,
557                    theme->btn_close->mask);
558     READ_MASK_COPY("close_hover.xbm",
559                    theme->btn_close->hover_mask,
560                    theme->btn_close->mask);
561
562     /* submenu bullet mask */
563     if (!read_mask(inst, path, theme, "bullet.xbm", &theme->menu_bullet_mask))
564     {
565         guchar data[] = { 0x01, 0x03, 0x07, 0x0f, 0x07, 0x03, 0x01 };
566         theme->menu_bullet_mask = RrPixmapMaskNew(inst, 4, 7, (gchar*)data);
567     }
568
569     /* up and down arrows */
570     {
571         guchar data[] = { 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00 };
572         theme->down_arrow_mask = RrPixmapMaskNew(inst, 9, 4, (gchar*)data);
573     }
574     {
575         guchar data[] = { 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00 };
576         theme->up_arrow_mask = RrPixmapMaskNew(inst, 9, 4, (gchar*)data);
577     }
578
579     /* setup the default window icon */
580     theme->def_win_icon = read_c_image(OB_DEFAULT_ICON_WIDTH,
581                                        OB_DEFAULT_ICON_HEIGHT,
582                                        OB_DEFAULT_ICON_pixel_data);
583     theme->def_win_icon_w = OB_DEFAULT_ICON_WIDTH;
584     theme->def_win_icon_h = OB_DEFAULT_ICON_HEIGHT;
585
586     /* read the decoration textures */
587     READ_APPEARANCE("window.active.title.bg", theme->a_focused_title, FALSE);
588     READ_APPEARANCE("window.inactive.title.bg", theme->a_unfocused_title, FALSE);
589     READ_APPEARANCE("window.active.label.bg", theme->a_focused_label, TRUE);
590     READ_APPEARANCE("window.inactive.label.bg", theme->a_unfocused_label, TRUE);
591     READ_APPEARANCE("window.active.handle.bg", theme->a_focused_handle, FALSE);
592     READ_APPEARANCE("window.inactive.handle.bg",theme->a_unfocused_handle, FALSE);
593     READ_APPEARANCE("window.active.grip.bg", theme->a_focused_grip, TRUE);
594     READ_APPEARANCE("window.inactive.grip.bg", theme->a_unfocused_grip, TRUE);
595     READ_APPEARANCE("menu.items.bg", theme->a_menu, FALSE);
596     READ_APPEARANCE("menu.title.bg", theme->a_menu_title, TRUE);
597     READ_APPEARANCE("menu.items.active.bg", theme->a_menu_selected, TRUE);
598
599     theme->a_menu_disabled_selected =
600         RrAppearanceCopy(theme->a_menu_selected);
601
602     /* read appearances for non-decorations (on-screen-display) */
603     if (!read_appearance(db, inst, "osd.bg", theme->osd_bg, FALSE))
604     {
605         RrAppearanceFree(theme->osd_bg);
606         theme->osd_bg = RrAppearanceCopy(theme->a_focused_title);
607     }
608     if (!read_appearance(db, inst, "osd.active.label.bg",
609                          theme->osd_hilite_label, TRUE) &&
610         !read_appearance(db, inst, "osd.label.bg",
611                          theme->osd_hilite_label, TRUE))
612     {
613         RrAppearanceFree(theme->osd_hilite_label);
614         theme->osd_hilite_label = RrAppearanceCopy(theme->a_focused_label);
615     }
616     if (!read_appearance(db, inst, "osd.inactive.label.bg",
617                          theme->osd_unhilite_label, TRUE))
618     {
619         RrAppearanceFree(theme->osd_unhilite_label);
620         theme->osd_unhilite_label = RrAppearanceCopy(theme->a_unfocused_label);
621     }
622     /* osd_hilite_fg can't be parentrel */
623     if (!read_appearance(db, inst, "osd.hilight.bg",
624                          theme->osd_hilite_bg, FALSE))
625     {
626         RrAppearanceFree(theme->osd_hilite_bg);
627         if (theme->a_focused_label->surface.grad != RR_SURFACE_PARENTREL)
628             theme->osd_hilite_bg = RrAppearanceCopy(theme->a_focused_label);
629         else
630             theme->osd_hilite_bg = RrAppearanceCopy(theme->a_focused_title);
631     }
632     /* osd_unhilite_fg can't be parentrel either */
633     if (!read_appearance(db, inst, "osd.unhilight.bg",
634                          theme->osd_unhilite_bg, FALSE))
635     {
636         RrAppearanceFree(theme->osd_unhilite_bg);
637         if (theme->a_unfocused_label->surface.grad != RR_SURFACE_PARENTREL)
638             theme->osd_unhilite_bg=RrAppearanceCopy(theme->a_unfocused_label);
639         else
640             theme->osd_unhilite_bg=RrAppearanceCopy(theme->a_unfocused_title);
641     }
642
643     /* read buttons textures */
644
645     /* bases: unpressed, pressed, disabled */
646     READ_APPEARANCE("window.active.button.unpressed.bg", a_focused_unpressed_tmp, TRUE);
647     READ_APPEARANCE("window.inactive.button.unpressed.bg", a_unfocused_unpressed_tmp, TRUE);
648     READ_APPEARANCE("window.active.button.pressed.bg", a_focused_pressed_tmp, TRUE);
649     READ_APPEARANCE("window.inactive.button.pressed.bg", a_unfocused_pressed_tmp, TRUE);
650     READ_APPEARANCE("window.active.button.disabled.bg", a_disabled_focused_tmp, TRUE);
651     READ_APPEARANCE("window.inactive.button.disabled.bg", a_disabled_unfocused_tmp, TRUE);
652
653     /* hover */
654     READ_APPEARANCE_COPY("window.active.button.hover.bg",
655                          a_hover_focused_tmp, TRUE,
656                          a_focused_unpressed_tmp);
657     READ_APPEARANCE_COPY("window.inactive.button.hover.bg",
658                          a_hover_unfocused_tmp, TRUE,
659                          a_unfocused_unpressed_tmp);
660
661     /* toggled unpressed */
662     READ_APPEARANCE_("window.active.button.toggled.unpressed.bg",
663                      "window.active.button.toggled.bg",
664                      a_toggled_focused_unpressed_tmp, TRUE,
665                      a_focused_pressed_tmp);
666     READ_APPEARANCE_("window.inactive.button.toggled.unpressed.bg",
667                      "window.inactive.button.toggled.bg",
668                      a_toggled_unfocused_unpressed_tmp, TRUE,
669                      a_unfocused_pressed_tmp);
670
671     /* toggled pressed */
672     READ_APPEARANCE_COPY("window.active.button.toggled.pressed.bg",
673                          a_toggled_focused_pressed_tmp, TRUE,
674                          a_focused_pressed_tmp);
675     READ_APPEARANCE_COPY("window.inactive.button.toggled.pressed.bg",
676                          a_toggled_unfocused_pressed_tmp, TRUE,
677                          a_unfocused_pressed_tmp);
678
679     /* toggled hover */
680     READ_APPEARANCE_COPY("window.active.button.toggled.hover.bg",
681                          a_toggled_hover_focused_tmp, TRUE,
682                          a_toggled_focused_unpressed_tmp);
683     READ_APPEARANCE_COPY("window.inactive.button.toggled.hover.bg",
684                          a_toggled_hover_unfocused_tmp, TRUE,
685                          a_toggled_unfocused_unpressed_tmp);
686
687
688     /* now do individual buttons, if specified */
689
690     /* max button */
691     read_button_colors(db, inst, theme, theme->btn_max, "max");
692
693     /* bases:  unpressed, pressed, disabled */
694     READ_APPEARANCE_COPY("window.active.button.max.unpressed.bg",
695                          theme->btn_max->a_focused_unpressed, TRUE,
696                          a_focused_unpressed_tmp);
697     READ_APPEARANCE_COPY("window.inactive.button.max.unpressed.bg",
698                          theme->btn_max->a_unfocused_unpressed, TRUE,
699                          a_unfocused_unpressed_tmp);
700     READ_APPEARANCE_COPY("window.active.button.max.pressed.bg",
701                          theme->btn_max->a_focused_pressed, TRUE,
702                          a_focused_pressed_tmp);
703     READ_APPEARANCE_COPY("window.inactive.button.max.pressed.bg",
704                          theme->btn_max->a_unfocused_pressed, TRUE,
705                          a_unfocused_pressed_tmp);
706     READ_APPEARANCE_COPY("window.active.button.max.disabled.bg",
707                          theme->btn_max->a_disabled_focused, TRUE,
708                          a_disabled_focused_tmp);
709     READ_APPEARANCE_COPY("window.inactive.button.max.disabled.bg",
710                          theme->btn_max->a_disabled_unfocused, TRUE,
711                          a_disabled_unfocused_tmp);
712
713     /* hover */
714     READ_APPEARANCE_COPY("window.active.button.max.hover.bg",
715                          theme->btn_max->a_hover_focused, TRUE,
716                          a_hover_focused_tmp);
717     READ_APPEARANCE_COPY("window.inactive.button.max.hover.bg",
718                          theme->btn_max->a_hover_unfocused, TRUE,
719                          a_hover_unfocused_tmp);
720
721     /* toggled unpressed */
722     READ_APPEARANCE_("window.active.button.max.toggled.unpressed.bg",
723                      "window.active.button.max.toggled.bg",
724                      theme->btn_max->a_toggled_focused_unpressed, TRUE,
725                      a_toggled_focused_unpressed_tmp);
726     READ_APPEARANCE_("window.inactive.button.max.toggled.unpressed.bg",
727                      "window.inactive.button.max.toggled.bg",
728                      theme->btn_max->a_toggled_unfocused_unpressed, TRUE,
729                      a_toggled_unfocused_unpressed_tmp);
730
731     /* toggled pressed */
732     READ_APPEARANCE_COPY("window.active.button.max.toggled.pressed.bg",
733                          theme->btn_max->a_toggled_focused_pressed, TRUE,
734                          a_toggled_focused_pressed_tmp);
735     READ_APPEARANCE_COPY("window.inactive.button.max.toggled.pressed.bg",
736                          theme->btn_max->a_toggled_unfocused_pressed, TRUE,
737                          a_toggled_unfocused_pressed_tmp);
738
739     /* toggled hover */
740     READ_APPEARANCE_COPY("window.active.button.max.toggled.hover.bg",
741                          theme->btn_max->a_toggled_hover_focused, TRUE,
742                          a_toggled_hover_focused_tmp);
743     READ_APPEARANCE_COPY("window.inactive.button.max.toggled.hover.bg",
744                          theme->btn_max->a_toggled_hover_unfocused, TRUE,
745                          a_toggled_hover_unfocused_tmp);
746
747     /* close button */
748     read_button_colors(db, inst, theme, theme->btn_close, "close");
749
750     READ_APPEARANCE_COPY("window.active.button.close.unpressed.bg",
751                          theme->btn_close->a_focused_unpressed, TRUE,
752                          a_focused_unpressed_tmp);
753     READ_APPEARANCE_COPY("window.inactive.button.close.unpressed.bg",
754                          theme->btn_close->a_unfocused_unpressed, TRUE,
755                          a_unfocused_unpressed_tmp);
756     READ_APPEARANCE_COPY("window.active.button.close.pressed.bg",
757                          theme->btn_close->a_focused_pressed, TRUE,
758                          a_focused_pressed_tmp);
759     READ_APPEARANCE_COPY("window.inactive.button.close.pressed.bg",
760                          theme->btn_close->a_unfocused_pressed, TRUE,
761                          a_unfocused_pressed_tmp);
762     READ_APPEARANCE_COPY("window.active.button.close.disabled.bg",
763                          theme->btn_close->a_disabled_focused, TRUE,
764                          a_disabled_focused_tmp);
765     READ_APPEARANCE_COPY("window.inactive.button.close.disabled.bg",
766                          theme->btn_close->a_disabled_unfocused, TRUE,
767                          a_disabled_unfocused_tmp);
768     READ_APPEARANCE_COPY("window.active.button.close.hover.bg",
769                          theme->btn_close->a_hover_focused, TRUE,
770                          a_hover_focused_tmp);
771     READ_APPEARANCE_COPY("window.inactive.button.close.hover.bg",
772                          theme->btn_close->a_hover_unfocused, TRUE,
773                          a_hover_unfocused_tmp);
774
775     /* desk button */
776     read_button_colors(db, inst, theme, theme->btn_desk, "desk");
777
778     /* bases:  unpressed, pressed, disabled */
779     READ_APPEARANCE_COPY("window.active.button.desk.unpressed.bg",
780                          theme->btn_desk->a_focused_unpressed, TRUE,
781                          a_focused_unpressed_tmp);
782     READ_APPEARANCE_COPY("window.inactive.button.desk.unpressed.bg",
783                          theme->btn_desk->a_unfocused_unpressed, TRUE,
784                          a_unfocused_unpressed_tmp);
785     READ_APPEARANCE_COPY("window.active.button.desk.pressed.bg",
786                          theme->btn_desk->a_focused_pressed, TRUE,
787                          a_focused_pressed_tmp);
788     READ_APPEARANCE_COPY("window.inactive.button.desk.pressed.bg",
789                          theme->btn_desk->a_unfocused_pressed, TRUE,
790                          a_unfocused_pressed_tmp);
791     READ_APPEARANCE_COPY("window.active.button.desk.disabled.bg",
792                          theme->btn_desk->a_disabled_focused, TRUE,
793                          a_disabled_focused_tmp);
794     READ_APPEARANCE_COPY("window.inactive.button.desk.disabled.bg",
795                          theme->btn_desk->a_disabled_unfocused, TRUE,
796                          a_disabled_unfocused_tmp);
797
798     /* hover */
799     READ_APPEARANCE_COPY("window.active.button.desk.hover.bg",
800                          theme->btn_desk->a_hover_focused, TRUE,
801                          a_hover_focused_tmp);
802     READ_APPEARANCE_COPY("window.inactive.button.desk.hover.bg",
803                          theme->btn_desk->a_hover_unfocused, TRUE,
804                          a_hover_unfocused_tmp);
805
806     /* toggled unpressed */
807     READ_APPEARANCE_("window.active.button.desk.toggled.unpressed.bg",
808                      "window.active.button.desk.toggled.bg",
809                      theme->btn_desk->a_toggled_focused_unpressed, TRUE,
810                      a_toggled_focused_unpressed_tmp);
811     READ_APPEARANCE_("window.inactive.button.desk.toggled.unpressed.bg",
812                      "window.inactive.button.desk.toggled.bg",
813                      theme->btn_desk->a_toggled_unfocused_unpressed, TRUE,
814                      a_toggled_unfocused_unpressed_tmp);
815
816     /* toggled pressed */
817     READ_APPEARANCE_COPY("window.active.button.desk.toggled.pressed.bg",
818                          theme->btn_desk->a_toggled_focused_pressed, TRUE,
819                          a_toggled_focused_pressed_tmp);
820     READ_APPEARANCE_COPY("window.inactive.button.desk.toggled.pressed.bg",
821                          theme->btn_desk->a_toggled_unfocused_pressed, TRUE,
822                          a_toggled_unfocused_pressed_tmp);
823
824     /* toggled hover */
825     READ_APPEARANCE_COPY("window.active.button.desk.toggled.hover.bg",
826                          theme->btn_desk->a_toggled_hover_focused, TRUE,
827                          a_toggled_hover_focused_tmp);
828     READ_APPEARANCE_COPY("window.inactive.button.desk.toggled.hover.bg",
829                          theme->btn_desk->a_toggled_hover_unfocused, TRUE,
830                          a_toggled_hover_unfocused_tmp);
831
832     /* shade button */
833     read_button_colors(db, inst, theme, theme->btn_shade, "shade");
834
835     /* bases:  unpressed, pressed, disabled */
836     READ_APPEARANCE_COPY("window.active.button.shade.unpressed.bg",
837                          theme->btn_shade->a_focused_unpressed, TRUE,
838                          a_focused_unpressed_tmp);
839     READ_APPEARANCE_COPY("window.inactive.button.shade.unpressed.bg",
840                          theme->btn_shade->a_unfocused_unpressed, TRUE,
841                          a_unfocused_unpressed_tmp);
842     READ_APPEARANCE_COPY("window.active.button.shade.pressed.bg",
843                          theme->btn_shade->a_focused_pressed, TRUE,
844                          a_focused_pressed_tmp);
845     READ_APPEARANCE_COPY("window.inactive.button.shade.pressed.bg",
846                          theme->btn_shade->a_unfocused_pressed, TRUE,
847                          a_unfocused_pressed_tmp);
848     READ_APPEARANCE_COPY("window.active.button.shade.disabled.bg",
849                          theme->btn_shade->a_disabled_focused, TRUE,
850                          a_disabled_focused_tmp);
851     READ_APPEARANCE_COPY("window.inactive.button.shade.disabled.bg",
852                          theme->btn_shade->a_disabled_unfocused, TRUE,
853                          a_disabled_unfocused_tmp);
854
855     /* hover */
856     READ_APPEARANCE_COPY("window.active.button.shade.hover.bg",
857                          theme->btn_shade->a_hover_focused, TRUE,
858                          a_hover_focused_tmp);
859     READ_APPEARANCE_COPY("window.inactive.button.shade.hover.bg",
860                          theme->btn_shade->a_hover_unfocused, TRUE,
861                          a_hover_unfocused_tmp);
862
863     /* toggled unpressed */
864     READ_APPEARANCE_("window.active.button.shade.toggled.unpressed.bg",
865                      "window.active.button.shade.toggled.bg",
866                      theme->btn_shade->a_toggled_focused_unpressed, TRUE,
867                      a_toggled_focused_unpressed_tmp);
868     READ_APPEARANCE_("window.inactive.button.shade.toggled.unpressed.bg",
869                      "window.inactive.button.shade.toggled.bg",
870                      theme->btn_shade->a_toggled_unfocused_unpressed, TRUE,
871                      a_toggled_unfocused_unpressed_tmp);
872
873     /* toggled pressed */
874     READ_APPEARANCE_COPY("window.active.button.shade.toggled.pressed.bg",
875                          theme->btn_shade->a_toggled_focused_pressed, TRUE,
876                          a_toggled_focused_pressed_tmp);
877     READ_APPEARANCE_COPY("window.inactive.button.shade.toggled.pressed.bg",
878                          theme->btn_shade->a_toggled_unfocused_pressed, TRUE,
879                          a_toggled_unfocused_pressed_tmp);
880
881     /* toggled hover */
882     READ_APPEARANCE_COPY("window.active.button.shade.toggled.hover.bg",
883                          theme->btn_shade->a_toggled_hover_focused, TRUE,
884                          a_toggled_hover_focused_tmp);
885     READ_APPEARANCE_COPY("window.inactive.button.shade.toggled.hover.bg",
886                          theme->btn_shade->a_toggled_hover_unfocused, TRUE,
887                          a_toggled_hover_unfocused_tmp);
888
889     /* iconify button */
890     read_button_colors(db, inst, theme, theme->btn_iconify, "iconify");
891
892     READ_APPEARANCE_COPY("window.active.button.iconify.unpressed.bg",
893                          theme->btn_iconify->a_focused_unpressed, TRUE,
894                          a_focused_unpressed_tmp);
895     READ_APPEARANCE_COPY("window.inactive.button.iconify.unpressed.bg",
896                          theme->btn_iconify->a_unfocused_unpressed, TRUE,
897                          a_unfocused_unpressed_tmp);
898     READ_APPEARANCE_COPY("window.active.button.iconify.pressed.bg",
899                          theme->btn_iconify->a_focused_pressed, TRUE,
900                          a_focused_pressed_tmp);
901     READ_APPEARANCE_COPY("window.inactive.button.iconify.pressed.bg",
902                          theme->btn_iconify->a_unfocused_pressed, TRUE,
903                          a_unfocused_pressed_tmp);
904     READ_APPEARANCE_COPY("window.active.button.iconify.disabled.bg",
905                          theme->btn_iconify->a_disabled_focused, TRUE,
906                          a_disabled_focused_tmp);
907     READ_APPEARANCE_COPY("window.inactive.button.iconify.disabled.bg",
908                          theme->btn_iconify->a_disabled_unfocused, TRUE,
909                          a_disabled_unfocused_tmp);
910     READ_APPEARANCE_COPY("window.active.button.iconify.hover.bg",
911                          theme->btn_iconify->a_hover_focused, TRUE,
912                          a_hover_focused_tmp);
913     READ_APPEARANCE_COPY("window.inactive.button.iconify.hover.bg",
914                          theme->btn_iconify->a_hover_unfocused, TRUE,
915                          a_hover_unfocused_tmp);
916
917     /* osd buttons */
918     READ_APPEARANCE_COPY("osd.button.unpressed.bg", theme->osd_unpressed_button, TRUE, a_focused_unpressed_tmp);
919     READ_APPEARANCE_COPY_TEXTURES("osd.button.pressed.bg", theme->osd_pressed_button, TRUE, a_focused_pressed_tmp, 5);
920     READ_APPEARANCE_COPY_TEXTURES("osd.button.focused.bg", theme->osd_focused_button, TRUE, a_focused_unpressed_tmp, 5);
921
922     theme->a_icon->surface.grad =
923         theme->a_clear->surface.grad =
924         theme->a_clear_tex->surface.grad =
925         theme->a_menu_text_title->surface.grad =
926         theme->a_menu_normal->surface.grad =
927         theme->a_menu_disabled->surface.grad =
928         theme->a_menu_text_normal->surface.grad =
929         theme->a_menu_text_selected->surface.grad =
930         theme->a_menu_text_disabled->surface.grad =
931         theme->a_menu_text_disabled_selected->surface.grad =
932         theme->a_menu_bullet_normal->surface.grad =
933         theme->a_menu_bullet_selected->surface.grad = RR_SURFACE_PARENTREL;
934
935     /* set up the textures */
936     theme->a_focused_label->texture[0].type = RR_TEXTURE_TEXT;
937     theme->a_focused_label->texture[0].data.text.justify = winjust;
938     theme->a_focused_label->texture[0].data.text.font=theme->win_font_focused;
939     theme->a_focused_label->texture[0].data.text.color =
940         theme->title_focused_color;
941
942     if (read_string(db, "window.active.label.text.font", &str)) {
943         char *p;
944         gint i = 0;
945         gint j;
946         if (strstr(str, "shadow=y")) {
947             if ((p = strstr(str, "shadowoffset=")))
948                 i = parse_inline_number(p + strlen("shadowoffset="));
949             else
950                 i = 1;
951             theme->a_focused_label->texture[0].data.text.shadow_offset_x = i;
952             theme->a_focused_label->texture[0].data.text.shadow_offset_y = i;
953         }
954         if ((p = strstr(str, "shadowtint="))) {
955             i = parse_inline_number(p + strlen("shadowtint="));
956             j = (i > 0 ? 0 : 255);
957             i = ABS(i*255/100);
958
959             theme->title_focused_shadow_color = RrColorNew(inst, j, j, j);
960             theme->title_focused_shadow_alpha = i;
961         } else {
962             theme->title_focused_shadow_color = RrColorNew(inst, 0, 0, 0);
963             theme->title_focused_shadow_alpha = 50;
964         }
965     }
966
967     theme->a_focused_label->texture[0].data.text.shadow_color = theme->title_focused_shadow_color;
968     theme->a_focused_label->texture[0].data.text.shadow_alpha = theme->title_focused_shadow_alpha;
969
970     theme->osd_hilite_label->texture[0].type = RR_TEXTURE_TEXT;
971     theme->osd_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
972     theme->osd_hilite_label->texture[0].data.text.font = theme->osd_font_hilite;
973     theme->osd_hilite_label->texture[0].data.text.color = theme->osd_text_active_color;
974
975     if (read_string(db, "osd.active.label.text.font", &str) ||
976         read_string(db, "osd.label.text.font", &str))
977     {
978         char *p;
979         gint i = 0;
980         gint j;
981         if (strstr(str, "shadow=y")) {
982             if ((p = strstr(str, "shadowoffset=")))
983                 i = parse_inline_number(p + strlen("shadowoffset="));
984             else
985                 i = 1;
986             theme->osd_hilite_label->texture[0].data.text.shadow_offset_x = i;
987             theme->osd_hilite_label->texture[0].data.text.shadow_offset_y = i;
988         }
989         if ((p = strstr(str, "shadowtint="))) {
990             i = parse_inline_number(p + strlen("shadowtint="));
991             j = (i > 0 ? 0 : 255);
992             i = ABS(i*255/100);
993
994             theme->osd_text_active_shadow_color = RrColorNew(inst, j, j, j);
995             theme->osd_text_active_shadow_alpha = i;
996         } else {
997             theme->osd_text_active_shadow_color = RrColorNew(inst, 0, 0, 0);
998             theme->osd_text_active_shadow_alpha = 50;
999         }
1000     } else {
1001         /* inherit the font settings from the focused label */
1002         theme->osd_hilite_label->texture[0].data.text.shadow_offset_x =
1003             theme->a_focused_label->texture[0].data.text.shadow_offset_x;
1004         theme->osd_hilite_label->texture[0].data.text.shadow_offset_y =
1005             theme->a_focused_label->texture[0].data.text.shadow_offset_y;
1006         if (theme->title_focused_shadow_color)
1007             theme->osd_text_active_shadow_color =
1008                 RrColorCopy(theme->title_focused_shadow_color);
1009         else
1010             theme->osd_text_active_shadow_color = RrColorNew(inst, 0, 0, 0);
1011         theme->osd_text_active_shadow_alpha =
1012             theme->title_focused_shadow_alpha;
1013     }
1014
1015     theme->osd_hilite_label->texture[0].data.text.shadow_color =
1016         theme->osd_text_active_shadow_color;
1017     theme->osd_hilite_label->texture[0].data.text.shadow_alpha =
1018         theme->osd_text_active_shadow_alpha;
1019
1020     theme->osd_unpressed_button->texture[0].type =
1021         theme->osd_pressed_button->texture[0].type =
1022         theme->osd_focused_button->texture[0].type =
1023         RR_TEXTURE_TEXT;
1024
1025     theme->osd_unpressed_button->texture[0].data.text.justify =
1026         theme->osd_pressed_button->texture[0].data.text.justify =
1027         theme->osd_focused_button->texture[0].data.text.justify =
1028         RR_JUSTIFY_CENTER;
1029
1030     theme->osd_unpressed_button->texture[0].data.text.font =
1031         theme->osd_pressed_button->texture[0].data.text.font =
1032         theme->osd_focused_button->texture[0].data.text.font =
1033         theme->osd_font_hilite;
1034
1035     theme->osd_unpressed_button->texture[0].data.text.color =
1036         theme->osd_unpressed_color;
1037     theme->osd_pressed_button->texture[0].data.text.color =
1038         theme->osd_pressed_color;
1039     theme->osd_focused_button->texture[0].data.text.color =
1040         theme->osd_focused_color;
1041
1042     theme->osd_pressed_button->texture[1].data.lineart.color =
1043         theme->osd_pressed_button->texture[2].data.lineart.color =
1044         theme->osd_pressed_button->texture[3].data.lineart.color =
1045         theme->osd_pressed_button->texture[4].data.lineart.color =
1046         theme->osd_pressed_lineart;
1047
1048     theme->osd_focused_button->texture[1].data.lineart.color =
1049         theme->osd_focused_button->texture[2].data.lineart.color =
1050         theme->osd_focused_button->texture[3].data.lineart.color =
1051         theme->osd_focused_button->texture[4].data.lineart.color =
1052         theme->osd_focused_lineart;
1053
1054     theme->a_unfocused_label->texture[0].type = RR_TEXTURE_TEXT;
1055     theme->a_unfocused_label->texture[0].data.text.justify = winjust;
1056     theme->a_unfocused_label->texture[0].data.text.font = theme->win_font_unfocused;
1057     theme->a_unfocused_label->texture[0].data.text.color = theme->title_unfocused_color;
1058
1059     if (read_string(db, "window.inactive.label.text.font", &str)) {
1060         char *p;
1061         gint i = 0;
1062         gint j;
1063         if (strstr(str, "shadow=y")) {
1064             if ((p = strstr(str, "shadowoffset=")))
1065                 i = parse_inline_number(p + strlen("shadowoffset="));
1066             else
1067                 i = 1;
1068             theme->a_unfocused_label->texture[0].data.text.shadow_offset_x = i;
1069             theme->a_unfocused_label->texture[0].data.text.shadow_offset_y = i;
1070         }
1071         if ((p = strstr(str, "shadowtint="))) {
1072             i = parse_inline_number(p + strlen("shadowtint="));
1073             j = (i > 0 ? 0 : 255);
1074             i = ABS(i*255/100);
1075
1076             theme->title_unfocused_shadow_color = RrColorNew(inst, j, j, j);
1077             theme->title_unfocused_shadow_alpha = i;
1078         } else {
1079             theme->title_unfocused_shadow_color = RrColorNew(inst, 0, 0, 0);
1080             theme->title_unfocused_shadow_alpha = 50;
1081         }
1082     }
1083
1084     theme->a_unfocused_label->texture[0].data.text.shadow_color =
1085         theme->title_unfocused_shadow_color;
1086     theme->a_unfocused_label->texture[0].data.text.shadow_alpha =
1087         theme->title_unfocused_shadow_alpha;
1088
1089     theme->osd_unhilite_label->texture[0].type = RR_TEXTURE_TEXT;
1090     theme->osd_unhilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
1091     theme->osd_unhilite_label->texture[0].data.text.font =
1092         theme->osd_font_unhilite;
1093     theme->osd_unhilite_label->texture[0].data.text.color =
1094         theme->osd_text_inactive_color;
1095
1096     if (read_string(db, "osd.inactive.label.text.font", &str)) {
1097         char *p;
1098         gint i = 0;
1099         gint j;
1100         if (strstr(str, "shadow=y")) {
1101             if ((p = strstr(str, "shadowoffset=")))
1102                 i = parse_inline_number(p + strlen("shadowoffset="));
1103             else
1104                 i = 1;
1105             theme->osd_unhilite_label->texture[0].data.text.shadow_offset_x=i;
1106             theme->osd_unhilite_label->texture[0].data.text.shadow_offset_y=i;
1107         }
1108         if ((p = strstr(str, "shadowtint="))) {
1109             i = parse_inline_number(p + strlen("shadowtint="));
1110             j = (i > 0 ? 0 : 255);
1111             i = ABS(i*255/100);
1112
1113             theme->osd_text_inactive_shadow_color = RrColorNew(inst, j, j, j);
1114             theme->osd_text_inactive_shadow_alpha = i;
1115         } else {
1116             theme->osd_text_inactive_shadow_color = RrColorNew(inst, 0, 0, 0);
1117             theme->osd_text_inactive_shadow_alpha = 50;
1118         }
1119     } else {
1120         /* inherit the font settings from the unfocused label */
1121         theme->osd_unhilite_label->texture[0].data.text.shadow_offset_x =
1122             theme->a_unfocused_label->texture[0].data.text.shadow_offset_x;
1123         theme->osd_unhilite_label->texture[0].data.text.shadow_offset_y =
1124             theme->a_unfocused_label->texture[0].data.text.shadow_offset_y;
1125         if (theme->title_unfocused_shadow_color)
1126             theme->osd_text_inactive_shadow_color =
1127                 RrColorCopy(theme->title_unfocused_shadow_color);
1128         else
1129             theme->osd_text_inactive_shadow_color = RrColorNew(inst, 0, 0, 0);
1130         theme->osd_text_inactive_shadow_alpha =
1131             theme->title_unfocused_shadow_alpha;
1132     }
1133
1134     theme->osd_unhilite_label->texture[0].data.text.shadow_color =
1135         theme->osd_text_inactive_shadow_color;
1136     theme->osd_unhilite_label->texture[0].data.text.shadow_alpha =
1137         theme->osd_text_inactive_shadow_alpha;
1138
1139     theme->a_menu_text_title->texture[0].type = RR_TEXTURE_TEXT;
1140     theme->a_menu_text_title->texture[0].data.text.justify = mtitlejust;
1141     theme->a_menu_text_title->texture[0].data.text.font = theme->menu_title_font;
1142     theme->a_menu_text_title->texture[0].data.text.color = theme->menu_title_color;
1143
1144     if (read_string(db, "menu.title.text.font", &str)) {
1145         char *p;
1146         gint i = 0;
1147         gint j;
1148         if (strstr(str, "shadow=y")) {
1149             if ((p = strstr(str, "shadowoffset=")))
1150                 i = parse_inline_number(p + strlen("shadowoffset="));
1151             else
1152                 i = 1;
1153             theme->a_menu_text_title->texture[0].data.text.shadow_offset_x = i;
1154             theme->a_menu_text_title->texture[0].data.text.shadow_offset_y = i;
1155         }
1156         if ((p = strstr(str, "shadowtint="))) {
1157             i = parse_inline_number(p + strlen("shadowtint="));
1158             j = (i > 0 ? 0 : 255);
1159             i = ABS(i*255/100);
1160
1161             theme->menu_title_shadow_color = RrColorNew(inst, j, j, j);
1162             theme->menu_title_shadow_alpha = i;
1163         } else {
1164             theme->menu_title_shadow_color = RrColorNew(inst, 0, 0, 0);
1165             theme->menu_title_shadow_alpha = 50;
1166         }
1167     }
1168
1169     theme->a_menu_text_title->texture[0].data.text.shadow_color =
1170         theme->menu_title_shadow_color;
1171     theme->a_menu_text_title->texture[0].data.text.shadow_alpha =
1172         theme->menu_title_shadow_alpha;
1173
1174     theme->a_menu_text_normal->texture[0].type =
1175         theme->a_menu_text_selected->texture[0].type =
1176         theme->a_menu_text_disabled->texture[0].type =
1177         theme->a_menu_text_disabled_selected->texture[0].type =
1178         RR_TEXTURE_TEXT;
1179     theme->a_menu_text_normal->texture[0].data.text.justify =
1180         theme->a_menu_text_selected->texture[0].data.text.justify =
1181         theme->a_menu_text_disabled->texture[0].data.text.justify =
1182         theme->a_menu_text_disabled_selected->texture[0].data.text.justify =
1183         RR_JUSTIFY_LEFT;
1184     theme->a_menu_text_normal->texture[0].data.text.font =
1185         theme->a_menu_text_selected->texture[0].data.text.font =
1186         theme->a_menu_text_disabled->texture[0].data.text.font =
1187         theme->a_menu_text_disabled_selected->texture[0].data.text.font =
1188         theme->menu_font;
1189     theme->a_menu_text_normal->texture[0].data.text.color = theme->menu_color;
1190     theme->a_menu_text_selected->texture[0].data.text.color =
1191         theme->menu_selected_color;
1192     theme->a_menu_text_disabled->texture[0].data.text.color =
1193         theme->menu_disabled_color;
1194     theme->a_menu_text_disabled_selected->texture[0].data.text.color =
1195         theme->menu_disabled_selected_color;
1196
1197     if (read_string(db, "menu.items.font", &str)) {
1198         char *p;
1199         gint i = 0;
1200         gint j;
1201         if (strstr(str, "shadow=y")) {
1202             if ((p = strstr(str, "shadowoffset=")))
1203                 i = parse_inline_number(p + strlen("shadowoffset="));
1204             else
1205                 i = 1;
1206             theme->a_menu_text_normal->
1207                 texture[0].data.text.shadow_offset_x = i;
1208             theme->a_menu_text_normal->
1209                 texture[0].data.text.shadow_offset_y = i;
1210             theme->a_menu_text_selected->
1211                 texture[0].data.text.shadow_offset_x = i;
1212             theme->a_menu_text_selected->
1213                 texture[0].data.text.shadow_offset_y = i;
1214             theme->a_menu_text_disabled->
1215                 texture[0].data.text.shadow_offset_x = i;
1216             theme->a_menu_text_disabled->
1217                 texture[0].data.text.shadow_offset_y = i;
1218             theme->a_menu_text_disabled_selected->
1219                 texture[0].data.text.shadow_offset_x = i;
1220             theme->a_menu_text_disabled_selected->
1221                 texture[0].data.text.shadow_offset_y = i;
1222         }
1223         if ((p = strstr(str, "shadowtint="))) {
1224             i = parse_inline_number(p + strlen("shadowtint="));
1225             j = (i > 0 ? 0 : 255);
1226             i = ABS(i*255/100);
1227
1228             theme->menu_text_normal_shadow_color = RrColorNew(inst, j, j, j);
1229             theme->menu_text_selected_shadow_color = RrColorNew(inst, j, j, j);
1230             theme->menu_text_disabled_shadow_color = RrColorNew(inst, j, j, j);
1231             theme->menu_text_normal_shadow_alpha = i;
1232             theme->menu_text_selected_shadow_alpha = i;
1233             theme->menu_text_disabled_shadow_alpha = i;
1234             theme->menu_text_disabled_selected_shadow_alpha = i;
1235         } else {
1236             theme->menu_text_normal_shadow_color = RrColorNew(inst, 0, 0, 0);
1237             theme->menu_text_selected_shadow_color = RrColorNew(inst, 0, 0, 0);
1238             theme->menu_text_disabled_shadow_color = RrColorNew(inst, 0, 0, 0);
1239             theme->menu_text_normal_shadow_alpha = 50;
1240             theme->menu_text_selected_shadow_alpha = 50;
1241             theme->menu_text_disabled_selected_shadow_alpha = 50;
1242         }
1243     }
1244
1245     theme->a_menu_text_normal->texture[0].data.text.shadow_color =
1246         theme->menu_text_normal_shadow_color;
1247     theme->a_menu_text_normal->texture[0].data.text.shadow_alpha =
1248         theme->menu_text_normal_shadow_alpha;
1249     theme->a_menu_text_selected->texture[0].data.text.shadow_color =
1250         theme->menu_text_selected_shadow_color;
1251     theme->a_menu_text_selected->texture[0].data.text.shadow_alpha =
1252         theme->menu_text_selected_shadow_alpha;
1253     theme->a_menu_text_disabled->texture[0].data.text.shadow_color =
1254         theme->menu_text_disabled_shadow_color;
1255     theme->a_menu_text_disabled->texture[0].data.text.shadow_alpha =
1256         theme->menu_text_disabled_shadow_alpha;
1257     theme->a_menu_text_disabled_selected->texture[0].data.text.shadow_color =
1258         theme->menu_text_disabled_shadow_color;
1259     theme->a_menu_text_disabled_selected->texture[0].data.text.shadow_alpha =
1260         theme->menu_text_disabled_shadow_alpha;
1261
1262     theme->btn_max->a_disabled_focused->texture[0].type =
1263         theme->btn_max->a_disabled_unfocused->texture[0].type =
1264         theme->btn_max->a_hover_focused->texture[0].type =
1265         theme->btn_max->a_hover_unfocused->texture[0].type =
1266         theme->btn_max->a_toggled_hover_focused->texture[0].type =
1267         theme->btn_max->a_toggled_hover_unfocused->texture[0].type =
1268         theme->btn_max->a_toggled_focused_unpressed->texture[0].type =
1269         theme->btn_max->a_toggled_unfocused_unpressed->texture[0].type =
1270         theme->btn_max->a_toggled_focused_pressed->texture[0].type =
1271         theme->btn_max->a_toggled_unfocused_pressed->texture[0].type =
1272         theme->btn_max->a_focused_unpressed->texture[0].type =
1273         theme->btn_max->a_focused_pressed->texture[0].type =
1274         theme->btn_max->a_unfocused_unpressed->texture[0].type =
1275         theme->btn_max->a_unfocused_pressed->texture[0].type =
1276         theme->btn_close->a_disabled_focused->texture[0].type =
1277         theme->btn_close->a_disabled_unfocused->texture[0].type =
1278         theme->btn_close->a_hover_focused->texture[0].type =
1279         theme->btn_close->a_hover_unfocused->texture[0].type =
1280         theme->btn_close->a_focused_unpressed->texture[0].type =
1281         theme->btn_close->a_focused_pressed->texture[0].type =
1282         theme->btn_close->a_unfocused_unpressed->texture[0].type =
1283         theme->btn_close->a_unfocused_pressed->texture[0].type =
1284         theme->btn_desk->a_disabled_focused->texture[0].type =
1285         theme->btn_desk->a_disabled_unfocused->texture[0].type =
1286         theme->btn_desk->a_hover_focused->texture[0].type =
1287         theme->btn_desk->a_hover_unfocused->texture[0].type =
1288         theme->btn_desk->a_toggled_hover_focused->texture[0].type =
1289         theme->btn_desk->a_toggled_hover_unfocused->texture[0].type =
1290         theme->btn_desk->a_toggled_focused_unpressed->texture[0].type =
1291         theme->btn_desk->a_toggled_unfocused_unpressed->texture[0].type =
1292         theme->btn_desk->a_toggled_focused_pressed->texture[0].type =
1293         theme->btn_desk->a_toggled_unfocused_pressed->texture[0].type =
1294         theme->btn_desk->a_focused_unpressed->texture[0].type =
1295         theme->btn_desk->a_focused_pressed->texture[0].type =
1296         theme->btn_desk->a_unfocused_unpressed->texture[0].type =
1297         theme->btn_desk->a_unfocused_pressed->texture[0].type =
1298         theme->btn_shade->a_disabled_focused->texture[0].type =
1299         theme->btn_shade->a_disabled_unfocused->texture[0].type =
1300         theme->btn_shade->a_hover_focused->texture[0].type =
1301         theme->btn_shade->a_hover_unfocused->texture[0].type =
1302         theme->btn_shade->a_toggled_hover_focused->texture[0].type =
1303         theme->btn_shade->a_toggled_hover_unfocused->texture[0].type =
1304         theme->btn_shade->a_toggled_focused_unpressed->texture[0].type =
1305         theme->btn_shade->a_toggled_unfocused_unpressed->texture[0].type =
1306         theme->btn_shade->a_toggled_focused_pressed->texture[0].type =
1307         theme->btn_shade->a_toggled_unfocused_pressed->texture[0].type =
1308         theme->btn_shade->a_focused_unpressed->texture[0].type =
1309         theme->btn_shade->a_focused_pressed->texture[0].type =
1310         theme->btn_shade->a_unfocused_unpressed->texture[0].type =
1311         theme->btn_shade->a_unfocused_pressed->texture[0].type =
1312         theme->btn_iconify->a_disabled_focused->texture[0].type =
1313         theme->btn_iconify->a_disabled_unfocused->texture[0].type =
1314         theme->btn_iconify->a_hover_focused->texture[0].type =
1315         theme->btn_iconify->a_hover_unfocused->texture[0].type =
1316         theme->btn_iconify->a_focused_unpressed->texture[0].type =
1317         theme->btn_iconify->a_focused_pressed->texture[0].type =
1318         theme->btn_iconify->a_unfocused_unpressed->texture[0].type =
1319         theme->btn_iconify->a_unfocused_pressed->texture[0].type =
1320         theme->a_menu_bullet_normal->texture[0].type =
1321         theme->a_menu_bullet_selected->texture[0].type = RR_TEXTURE_MASK;
1322
1323     theme->btn_max->a_disabled_focused->texture[0].data.mask.mask =
1324         theme->btn_max->a_disabled_unfocused->texture[0].data.mask.mask =
1325         theme->btn_max->disabled_mask;
1326     theme->btn_max->a_hover_focused->texture[0].data.mask.mask =
1327         theme->btn_max->a_hover_unfocused->texture[0].data.mask.mask =
1328         theme->btn_max->hover_mask;
1329     theme->btn_max->a_focused_pressed->texture[0].data.mask.mask =
1330         theme->btn_max->a_unfocused_pressed->texture[0].data.mask.mask =
1331         theme->btn_max->pressed_mask;
1332     theme->btn_max->a_focused_unpressed->texture[0].data.mask.mask =
1333         theme->btn_max->a_unfocused_unpressed->texture[0].data.mask.mask =
1334         theme->btn_max->mask;
1335     theme->btn_max->a_toggled_hover_focused->texture[0].data.mask.mask =
1336         theme->btn_max->a_toggled_hover_unfocused->texture[0].data.mask.mask =
1337         theme->btn_max->toggled_hover_mask;
1338     theme->btn_max->a_toggled_focused_unpressed->texture[0].data.mask.mask =
1339         theme->btn_max->a_toggled_unfocused_unpressed->
1340         texture[0].data.mask.mask = theme->btn_max->toggled_mask;
1341     theme->btn_max->a_toggled_focused_pressed->texture[0].data.mask.mask =
1342         theme->btn_max->a_toggled_unfocused_pressed->texture[0].data.mask.mask
1343         = theme->btn_max->toggled_pressed_mask;
1344     theme->btn_close->a_disabled_focused->texture[0].data.mask.mask =
1345         theme->btn_close->a_disabled_unfocused->texture[0].data.mask.mask =
1346         theme->btn_close->disabled_mask;
1347     theme->btn_close->a_hover_focused->texture[0].data.mask.mask =
1348         theme->btn_close->a_hover_unfocused->texture[0].data.mask.mask =
1349         theme->btn_close->hover_mask;
1350     theme->btn_close->a_focused_pressed->texture[0].data.mask.mask =
1351         theme->btn_close->a_unfocused_pressed->texture[0].data.mask.mask =
1352         theme->btn_close->pressed_mask;
1353     theme->btn_close->a_focused_unpressed->texture[0].data.mask.mask =
1354         theme->btn_close->a_unfocused_unpressed->texture[0].data.mask.mask =
1355         theme->btn_close->mask;
1356     theme->btn_desk->a_disabled_focused->texture[0].data.mask.mask =
1357         theme->btn_desk->a_disabled_unfocused->texture[0].data.mask.mask =
1358         theme->btn_desk->disabled_mask;
1359     theme->btn_desk->a_hover_focused->texture[0].data.mask.mask =
1360         theme->btn_desk->a_hover_unfocused->texture[0].data.mask.mask =
1361         theme->btn_desk->hover_mask;
1362     theme->btn_desk->a_focused_pressed->texture[0].data.mask.mask =
1363         theme->btn_desk->a_unfocused_pressed->texture[0].data.mask.mask =
1364         theme->btn_desk->pressed_mask;
1365     theme->btn_desk->a_focused_unpressed->texture[0].data.mask.mask =
1366         theme->btn_desk->a_unfocused_unpressed->texture[0].data.mask.mask =
1367         theme->btn_desk->mask;
1368     theme->btn_desk->a_toggled_hover_focused->texture[0].data.mask.mask =
1369         theme->btn_desk->a_toggled_hover_unfocused->texture[0].data.mask.mask =
1370         theme->btn_desk->toggled_hover_mask;
1371     theme->btn_desk->a_toggled_focused_unpressed->texture[0].data.mask.mask =
1372         theme->btn_desk->a_toggled_unfocused_unpressed->
1373         texture[0].data.mask.mask = theme->btn_desk->toggled_mask;
1374     theme->btn_desk->a_toggled_focused_pressed->texture[0].data.mask.mask =
1375         theme->btn_desk->a_toggled_unfocused_pressed->texture[0].data.mask.mask
1376         = theme->btn_desk->toggled_pressed_mask;
1377     theme->btn_shade->a_disabled_focused->texture[0].data.mask.mask =
1378         theme->btn_shade->a_disabled_unfocused->texture[0].data.mask.mask =
1379         theme->btn_shade->disabled_mask;
1380     theme->btn_shade->a_hover_focused->texture[0].data.mask.mask =
1381         theme->btn_shade->a_hover_unfocused->texture[0].data.mask.mask =
1382         theme->btn_shade->hover_mask;
1383     theme->btn_shade->a_focused_pressed->texture[0].data.mask.mask =
1384         theme->btn_shade->a_unfocused_pressed->texture[0].data.mask.mask =
1385         theme->btn_shade->pressed_mask;
1386     theme->btn_shade->a_focused_unpressed->texture[0].data.mask.mask =
1387         theme->btn_shade->a_unfocused_unpressed->texture[0].data.mask.mask =
1388         theme->btn_shade->mask;
1389     theme->btn_shade->a_toggled_hover_focused->texture[0].data.mask.mask =
1390         theme->btn_shade->a_toggled_hover_unfocused->texture[0].data.mask.mask
1391         = theme->btn_shade->toggled_hover_mask;
1392     theme->btn_shade->a_toggled_focused_unpressed->texture[0].data.mask.mask =
1393         theme->btn_shade->a_toggled_unfocused_unpressed->
1394         texture[0].data.mask.mask = theme->btn_shade->toggled_mask;
1395     theme->btn_shade->a_toggled_focused_pressed->texture[0].data.mask.mask =
1396         theme->btn_shade->a_toggled_unfocused_pressed->
1397         texture[0].data.mask.mask = theme->btn_shade->toggled_pressed_mask;
1398     theme->btn_iconify->a_disabled_focused->texture[0].data.mask.mask =
1399         theme->btn_iconify->a_disabled_unfocused->texture[0].data.mask.mask =
1400         theme->btn_iconify->disabled_mask;
1401     theme->btn_iconify->a_hover_focused->texture[0].data.mask.mask =
1402         theme->btn_iconify->a_hover_unfocused->texture[0].data.mask.mask =
1403         theme->btn_iconify->hover_mask;
1404     theme->btn_iconify->a_focused_pressed->texture[0].data.mask.mask =
1405         theme->btn_iconify->a_unfocused_pressed->texture[0].data.mask.mask =
1406         theme->btn_iconify->pressed_mask;
1407     theme->btn_iconify->a_focused_unpressed->texture[0].data.mask.mask =
1408         theme->btn_iconify->a_unfocused_unpressed->texture[0].data.mask.mask =
1409         theme->btn_iconify->mask;
1410     theme->a_menu_bullet_normal->texture[0].data.mask.mask =
1411     theme->a_menu_bullet_selected->texture[0].data.mask.mask =
1412         theme->menu_bullet_mask;
1413     theme->btn_max->a_disabled_focused->texture[0].data.mask.color = 
1414         theme->btn_max->disabled_focused_color;
1415     theme->btn_close->a_disabled_focused->texture[0].data.mask.color = 
1416         theme->btn_close->disabled_focused_color;
1417     theme->btn_desk->a_disabled_focused->texture[0].data.mask.color = 
1418         theme->btn_desk->disabled_focused_color;
1419     theme->btn_shade->a_disabled_focused->texture[0].data.mask.color = 
1420         theme->btn_shade->disabled_focused_color;
1421     theme->btn_iconify->a_disabled_focused->texture[0].data.mask.color = 
1422         theme->btn_iconify->disabled_focused_color;
1423     theme->btn_max->a_disabled_unfocused->texture[0].data.mask.color = 
1424         theme->btn_max->disabled_unfocused_color;
1425     theme->btn_close->a_disabled_unfocused->texture[0].data.mask.color = 
1426         theme->btn_close->disabled_unfocused_color;
1427     theme->btn_desk->a_disabled_unfocused->texture[0].data.mask.color = 
1428         theme->btn_desk->disabled_unfocused_color;
1429     theme->btn_shade->a_disabled_unfocused->texture[0].data.mask.color = 
1430         theme->btn_shade->disabled_unfocused_color;
1431     theme->btn_iconify->a_disabled_unfocused->texture[0].data.mask.color = 
1432         theme->btn_iconify->disabled_unfocused_color;
1433     theme->btn_max->a_hover_focused->texture[0].data.mask.color = 
1434         theme->btn_max->hover_focused_color;
1435     theme->btn_close->a_hover_focused->texture[0].data.mask.color = 
1436         theme->btn_close->hover_focused_color;
1437     theme->btn_desk->a_hover_focused->texture[0].data.mask.color = 
1438         theme->btn_desk->hover_focused_color;
1439     theme->btn_shade->a_hover_focused->texture[0].data.mask.color = 
1440         theme->btn_shade->hover_focused_color;
1441     theme->btn_iconify->a_hover_focused->texture[0].data.mask.color = 
1442         theme->btn_iconify->hover_focused_color;
1443     theme->btn_max->a_hover_unfocused->texture[0].data.mask.color = 
1444         theme->btn_max->hover_unfocused_color;
1445     theme->btn_close->a_hover_unfocused->texture[0].data.mask.color = 
1446         theme->btn_close->hover_unfocused_color;
1447     theme->btn_desk->a_hover_unfocused->texture[0].data.mask.color = 
1448         theme->btn_desk->hover_unfocused_color;
1449     theme->btn_shade->a_hover_unfocused->texture[0].data.mask.color = 
1450         theme->btn_shade->hover_unfocused_color;
1451     theme->btn_iconify->a_hover_unfocused->texture[0].data.mask.color = 
1452         theme->btn_iconify->hover_unfocused_color;
1453     theme->btn_max->a_toggled_hover_focused->texture[0].data.mask.color = 
1454         theme->btn_max->toggled_hover_focused_color;
1455     theme->btn_desk->a_toggled_hover_focused->texture[0].data.mask.color = 
1456         theme->btn_desk->toggled_hover_focused_color;
1457     theme->btn_shade->a_toggled_hover_focused->texture[0].data.mask.color = 
1458         theme->btn_shade->toggled_hover_focused_color;
1459     theme->btn_max->a_toggled_hover_unfocused->texture[0].data.mask.color = 
1460         theme->btn_max->toggled_hover_unfocused_color;
1461     theme->btn_desk->a_toggled_hover_unfocused->texture[0].data.mask.color = 
1462         theme->btn_desk->toggled_hover_unfocused_color;
1463     theme->btn_shade->a_toggled_hover_unfocused->texture[0].data.mask.color = 
1464         theme->btn_shade->toggled_hover_unfocused_color;
1465     theme->btn_max->a_toggled_focused_unpressed->texture[0].data.mask.color = 
1466         theme->btn_max->toggled_focused_unpressed_color;
1467     theme->btn_desk->a_toggled_focused_unpressed->texture[0].data.mask.color = 
1468         theme->btn_desk->toggled_focused_unpressed_color;
1469     theme->btn_shade->a_toggled_focused_unpressed->texture[0].data.mask.color = 
1470         theme->btn_shade->toggled_focused_unpressed_color;
1471     theme->btn_max->a_toggled_unfocused_unpressed->texture[0].data.mask.color = 
1472         theme->btn_max->toggled_unfocused_unpressed_color;
1473     theme->btn_desk->a_toggled_unfocused_unpressed->texture[0].data.mask.color
1474         = theme->btn_desk->toggled_unfocused_unpressed_color;
1475     theme->btn_shade->a_toggled_unfocused_unpressed->texture[0].data.mask.color
1476         = theme->btn_shade->toggled_unfocused_unpressed_color;
1477     theme->btn_max->a_toggled_focused_pressed->texture[0].data.mask.color = 
1478         theme->btn_max->toggled_focused_pressed_color;
1479     theme->btn_desk->a_toggled_focused_pressed->texture[0].data.mask.color = 
1480         theme->btn_desk->toggled_focused_pressed_color;
1481     theme->btn_shade->a_toggled_focused_pressed->texture[0].data.mask.color = 
1482         theme->btn_shade->toggled_focused_pressed_color;
1483     theme->btn_max->a_toggled_unfocused_pressed->texture[0].data.mask.color = 
1484         theme->btn_max->toggled_unfocused_pressed_color;
1485     theme->btn_desk->a_toggled_unfocused_pressed->texture[0].data.mask.color = 
1486         theme->btn_desk->toggled_unfocused_pressed_color;
1487     theme->btn_shade->a_toggled_unfocused_pressed->texture[0].data.mask.color = 
1488         theme->btn_shade->toggled_unfocused_pressed_color;
1489     theme->btn_max->a_focused_unpressed->texture[0].data.mask.color = 
1490         theme->btn_max->focused_unpressed_color;
1491     theme->btn_close->a_focused_unpressed->texture[0].data.mask.color = 
1492         theme->btn_close->focused_unpressed_color;
1493     theme->btn_desk->a_focused_unpressed->texture[0].data.mask.color = 
1494         theme->btn_desk->focused_unpressed_color;
1495     theme->btn_shade->a_focused_unpressed->texture[0].data.mask.color = 
1496         theme->btn_shade->focused_unpressed_color;
1497     theme->btn_iconify->a_focused_unpressed->texture[0].data.mask.color = 
1498         theme->btn_iconify->focused_unpressed_color;
1499     theme->btn_max->a_focused_pressed->texture[0].data.mask.color = 
1500         theme->btn_max->focused_pressed_color;
1501     theme->btn_close->a_focused_pressed->texture[0].data.mask.color = 
1502         theme->btn_close->focused_pressed_color;
1503     theme->btn_desk->a_focused_pressed->texture[0].data.mask.color = 
1504         theme->btn_desk->focused_pressed_color;
1505     theme->btn_shade->a_focused_pressed->texture[0].data.mask.color = 
1506         theme->btn_shade->focused_pressed_color;
1507     theme->btn_iconify->a_focused_pressed->texture[0].data.mask.color = 
1508         theme->btn_iconify->focused_pressed_color;
1509     theme->btn_max->a_unfocused_unpressed->texture[0].data.mask.color = 
1510         theme->btn_max->unfocused_unpressed_color;
1511     theme->btn_close->a_unfocused_unpressed->texture[0].data.mask.color = 
1512         theme->btn_close->unfocused_unpressed_color;
1513     theme->btn_desk->a_unfocused_unpressed->texture[0].data.mask.color = 
1514         theme->btn_desk->unfocused_unpressed_color;
1515     theme->btn_shade->a_unfocused_unpressed->texture[0].data.mask.color = 
1516         theme->btn_shade->unfocused_unpressed_color;
1517     theme->btn_iconify->a_unfocused_unpressed->texture[0].data.mask.color = 
1518         theme->btn_iconify->unfocused_unpressed_color;
1519     theme->btn_max->a_unfocused_pressed->texture[0].data.mask.color = 
1520         theme->btn_max->unfocused_pressed_color;
1521     theme->btn_close->a_unfocused_pressed->texture[0].data.mask.color = 
1522         theme->btn_close->unfocused_pressed_color;
1523     theme->btn_desk->a_unfocused_pressed->texture[0].data.mask.color = 
1524         theme->btn_desk->unfocused_pressed_color;
1525     theme->btn_shade->a_unfocused_pressed->texture[0].data.mask.color = 
1526         theme->btn_shade->unfocused_pressed_color;
1527     theme->btn_iconify->a_unfocused_pressed->texture[0].data.mask.color = 
1528         theme->btn_iconify->unfocused_pressed_color;
1529     theme->a_menu_bullet_normal->texture[0].data.mask.color =
1530         theme->menu_bullet_color;
1531     theme->a_menu_bullet_selected->texture[0].data.mask.color =
1532         theme->menu_bullet_selected_color;
1533
1534     g_free(path);
1535     XrmDestroyDatabase(db);
1536
1537     /* set the font heights */
1538     theme->win_font_height = RrFontHeight(theme->win_font_focused,
1539         theme->a_focused_label->texture[0].data.text.shadow_offset_y);
1540     theme->win_font_height =
1541         MAX(theme->win_font_height,
1542             RrFontHeight(theme->win_font_focused,
1543                 theme->a_unfocused_label->texture[0].data.text.shadow_offset_y));
1544     theme->menu_title_font_height = RrFontHeight(theme->menu_title_font,
1545         theme->a_menu_text_title->texture[0].data.text.shadow_offset_y);
1546     theme->menu_font_height = RrFontHeight(theme->menu_font,
1547         theme->a_menu_text_normal->texture[0].data.text.shadow_offset_y);
1548
1549     /* calculate some last extents */
1550     {
1551         gint ft, fb, fl, fr, ut, ub, ul, ur;
1552
1553         RrMargins(theme->a_focused_label, &fl, &ft, &fr, &fb);
1554         RrMargins(theme->a_unfocused_label, &ul, &ut, &ur, &ub);
1555         theme->label_height = theme->win_font_height + MAX(ft + fb, ut + ub);
1556         theme->label_height += theme->label_height % 2;
1557
1558         /* this would be nice I think, since padding.width can now be 0,
1559            but it breaks frame.c horribly and I don't feel like fixing that
1560            right now, so if anyone complains, here is how to keep text from
1561            going over the title's bevel/border with a padding.width of 0 and a
1562            bevelless/borderless label
1563            RrMargins(theme->a_focused_title, &fl, &ft, &fr, &fb);
1564            RrMargins(theme->a_unfocused_title, &ul, &ut, &ur, &ub);
1565            theme->title_height = theme->label_height +
1566            MAX(MAX(theme->padding * 2, ft + fb),
1567            MAX(theme->padding * 2, ut + ub));
1568         */
1569         theme->title_height = theme->label_height + theme->paddingy * 2;
1570
1571         RrMargins(theme->a_menu_title, &ul, &ut, &ur, &ub);
1572         theme->menu_title_label_height = theme->menu_title_font_height+ut+ub;
1573         theme->menu_title_height = theme->menu_title_label_height +
1574             theme->paddingy * 2;
1575     }
1576     theme->button_size = theme->label_height - 2;
1577     theme->grip_width = 25;
1578
1579     RrAppearanceFree(a_disabled_focused_tmp);
1580     RrAppearanceFree(a_disabled_unfocused_tmp);
1581     RrAppearanceFree(a_hover_focused_tmp);
1582     RrAppearanceFree(a_hover_unfocused_tmp);
1583     RrAppearanceFree(a_focused_unpressed_tmp);
1584     RrAppearanceFree(a_focused_pressed_tmp);
1585     RrAppearanceFree(a_unfocused_unpressed_tmp);
1586     RrAppearanceFree(a_unfocused_pressed_tmp);
1587     RrAppearanceFree(a_toggled_hover_focused_tmp);
1588     RrAppearanceFree(a_toggled_hover_unfocused_tmp);
1589     RrAppearanceFree(a_toggled_focused_unpressed_tmp);
1590     RrAppearanceFree(a_toggled_focused_pressed_tmp);
1591     RrAppearanceFree(a_toggled_unfocused_unpressed_tmp);
1592     RrAppearanceFree(a_toggled_unfocused_pressed_tmp);
1593
1594     return theme;
1595 }
1596
1597 void RrThemeFree(RrTheme *theme)
1598 {
1599     if (theme) {
1600         g_free(theme->name);
1601
1602         RrButtonFree(theme->btn_max);
1603         RrButtonFree(theme->btn_close);
1604         RrButtonFree(theme->btn_desk);
1605         RrButtonFree(theme->btn_shade);
1606         RrButtonFree(theme->btn_iconify);
1607
1608         RrColorFree(theme->menu_border_color);
1609         RrColorFree(theme->osd_border_color);
1610         RrColorFree(theme->frame_focused_border_color);
1611         RrColorFree(theme->frame_undecorated_focused_border_color);
1612         RrColorFree(theme->frame_unfocused_border_color);
1613         RrColorFree(theme->frame_undecorated_unfocused_border_color);
1614         RrColorFree(theme->title_separator_focused_color);
1615         RrColorFree(theme->title_separator_unfocused_color);
1616         RrColorFree(theme->cb_unfocused_color);
1617         RrColorFree(theme->cb_focused_color);
1618         RrColorFree(theme->title_focused_color);
1619         RrColorFree(theme->title_unfocused_color);
1620         RrColorFree(theme->titlebut_disabled_focused_color);
1621         RrColorFree(theme->titlebut_disabled_unfocused_color);
1622         RrColorFree(theme->titlebut_hover_focused_color);
1623         RrColorFree(theme->titlebut_hover_unfocused_color);
1624         RrColorFree(theme->titlebut_toggled_hover_focused_color);
1625         RrColorFree(theme->titlebut_toggled_hover_unfocused_color);
1626         RrColorFree(theme->titlebut_toggled_focused_pressed_color);
1627         RrColorFree(theme->titlebut_toggled_unfocused_pressed_color);
1628         RrColorFree(theme->titlebut_toggled_focused_unpressed_color);
1629         RrColorFree(theme->titlebut_toggled_unfocused_unpressed_color);
1630         RrColorFree(theme->titlebut_focused_pressed_color);
1631         RrColorFree(theme->titlebut_unfocused_pressed_color);
1632         RrColorFree(theme->titlebut_focused_unpressed_color);
1633         RrColorFree(theme->titlebut_unfocused_unpressed_color);
1634         RrColorFree(theme->menu_title_color);
1635         RrColorFree(theme->menu_sep_color);
1636         RrColorFree(theme->menu_color);
1637         RrColorFree(theme->menu_bullet_color);
1638         RrColorFree(theme->menu_bullet_selected_color);
1639         RrColorFree(theme->menu_selected_color);
1640         RrColorFree(theme->menu_disabled_color);
1641         RrColorFree(theme->menu_disabled_selected_color);
1642         RrColorFree(theme->title_focused_shadow_color);
1643         RrColorFree(theme->title_unfocused_shadow_color);
1644         RrColorFree(theme->osd_text_active_color);
1645         RrColorFree(theme->osd_text_inactive_color);
1646         RrColorFree(theme->osd_text_active_shadow_color);
1647         RrColorFree(theme->osd_text_inactive_shadow_color);
1648         RrColorFree(theme->osd_pressed_color);
1649         RrColorFree(theme->osd_unpressed_color);
1650         RrColorFree(theme->osd_focused_color);
1651         RrColorFree(theme->osd_pressed_lineart);
1652         RrColorFree(theme->osd_focused_lineart);
1653         RrColorFree(theme->menu_title_shadow_color);
1654         RrColorFree(theme->menu_text_normal_shadow_color);
1655         RrColorFree(theme->menu_text_selected_shadow_color);
1656         RrColorFree(theme->menu_text_disabled_shadow_color);
1657         RrColorFree(theme->menu_text_disabled_selected_shadow_color);
1658
1659         g_free(theme->def_win_icon);
1660         
1661         RrPixmapMaskFree(theme->menu_bullet_mask);
1662         RrPixmapMaskFree(theme->down_arrow_mask);
1663         RrPixmapMaskFree(theme->up_arrow_mask);
1664
1665         RrFontClose(theme->win_font_focused);
1666         RrFontClose(theme->win_font_unfocused);
1667         RrFontClose(theme->menu_title_font);
1668         RrFontClose(theme->menu_font);
1669         RrFontClose(theme->osd_font_hilite);
1670         RrFontClose(theme->osd_font_unhilite);
1671
1672         RrAppearanceFree(theme->a_focused_grip);
1673         RrAppearanceFree(theme->a_unfocused_grip);
1674         RrAppearanceFree(theme->a_focused_title);
1675         RrAppearanceFree(theme->a_unfocused_title);
1676         RrAppearanceFree(theme->a_focused_label);
1677         RrAppearanceFree(theme->a_unfocused_label);
1678         RrAppearanceFree(theme->a_icon);
1679         RrAppearanceFree(theme->a_focused_handle);
1680         RrAppearanceFree(theme->a_unfocused_handle);
1681         RrAppearanceFree(theme->a_menu);
1682         RrAppearanceFree(theme->a_menu_title);
1683         RrAppearanceFree(theme->a_menu_text_title);
1684         RrAppearanceFree(theme->a_menu_normal);
1685         RrAppearanceFree(theme->a_menu_selected);
1686         RrAppearanceFree(theme->a_menu_disabled);
1687         RrAppearanceFree(theme->a_menu_disabled_selected);
1688         RrAppearanceFree(theme->a_menu_text_normal);
1689         RrAppearanceFree(theme->a_menu_text_selected);
1690         RrAppearanceFree(theme->a_menu_text_disabled);
1691         RrAppearanceFree(theme->a_menu_text_disabled_selected);
1692         RrAppearanceFree(theme->a_menu_bullet_normal);
1693         RrAppearanceFree(theme->a_menu_bullet_selected);
1694         RrAppearanceFree(theme->a_clear);
1695         RrAppearanceFree(theme->a_clear_tex);
1696         RrAppearanceFree(theme->osd_bg);
1697         RrAppearanceFree(theme->osd_hilite_bg);
1698         RrAppearanceFree(theme->osd_hilite_label);
1699         RrAppearanceFree(theme->osd_unhilite_bg);
1700         RrAppearanceFree(theme->osd_unhilite_label);
1701         RrAppearanceFree(theme->osd_pressed_button);
1702         RrAppearanceFree(theme->osd_unpressed_button);
1703         RrAppearanceFree(theme->osd_focused_button);
1704
1705         g_slice_free(RrTheme, theme);
1706     }
1707 }
1708
1709 static XrmDatabase loaddb(const gchar *name, gchar **path)
1710 {
1711     GSList *it;
1712     XrmDatabase db = NULL;
1713     gchar *s;
1714
1715     if (name[0] == '/') {
1716         s = g_build_filename(name, "openbox-3", "themerc", NULL);
1717         if ((db = XrmGetFileDatabase(s)))
1718             *path = g_path_get_dirname(s);
1719         g_free(s);
1720     } else {
1721         ObtPaths *p;
1722
1723         p = obt_paths_new();
1724
1725         /* XXX backwards compatibility, remove me sometime later */
1726         s = g_build_filename(g_get_home_dir(), ".themes", name,
1727                              "openbox-3", "themerc", NULL);
1728         if ((db = XrmGetFileDatabase(s)))
1729             *path = g_path_get_dirname(s);
1730         g_free(s);
1731
1732         for (it = obt_paths_data_dirs(p); !db && it; it = g_slist_next(it))
1733         {
1734             s = g_build_filename(it->data, "themes", name,
1735                                  "openbox-3", "themerc", NULL);
1736             if ((db = XrmGetFileDatabase(s)))
1737                 *path = g_path_get_dirname(s);
1738             g_free(s);
1739         }
1740
1741         obt_paths_unref(p);
1742     }
1743
1744     if (db == NULL) {
1745         s = g_build_filename(name, "themerc", NULL);
1746         if ((db = XrmGetFileDatabase(s)))
1747             *path = g_path_get_dirname(s);
1748         g_free(s);
1749     }
1750
1751     return db;
1752 }
1753
1754 static gchar *create_class_name(const gchar *rname)
1755 {
1756     gchar *rclass = g_strdup(rname);
1757     gchar *p = rclass;
1758
1759     while (TRUE) {
1760         *p = toupper(*p);
1761         p = strchr(p+1, '.');
1762         if (p == NULL) break;
1763         ++p;
1764         if (*p == '\0') break;
1765     }
1766     return rclass;
1767 }
1768
1769 static gboolean read_int(XrmDatabase db, const gchar *rname, gint *value)
1770 {
1771     gboolean ret = FALSE;
1772     gchar *rclass = create_class_name(rname);
1773     gchar *rettype, *end;
1774     XrmValue retvalue;
1775
1776     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1777         retvalue.addr != NULL) {
1778         *value = (gint)strtol(retvalue.addr, &end, 10);
1779         if (end != retvalue.addr)
1780             ret = TRUE;
1781     }
1782
1783     g_free(rclass);
1784     return ret;
1785 }
1786
1787 static gboolean read_string(XrmDatabase db, const gchar *rname, gchar **value)
1788 {
1789     gboolean ret = FALSE;
1790     gchar *rclass = create_class_name(rname);
1791     gchar *rettype;
1792     XrmValue retvalue;
1793
1794     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1795         retvalue.addr != NULL) {
1796         g_strstrip(retvalue.addr);
1797         *value = retvalue.addr;
1798         ret = TRUE;
1799     }
1800
1801     g_free(rclass);
1802     return ret;
1803 }
1804
1805 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
1806                            const gchar *rname, RrColor **value)
1807 {
1808     gboolean ret = FALSE;
1809     gchar *rclass = create_class_name(rname);
1810     gchar *rettype;
1811     XrmValue retvalue;
1812
1813     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1814         retvalue.addr != NULL) {
1815         RrColor *c;
1816
1817         /* retvalue.addr is inside the xrdb database so we can't destroy it
1818            but we can edit it in place, as g_strstrip does. */
1819         g_strstrip(retvalue.addr);
1820         c = RrColorParse(inst, retvalue.addr);
1821         if (c != NULL) {
1822             *value = c;
1823             ret = TRUE;
1824         }
1825     }
1826
1827     g_free(rclass);
1828     return ret;
1829 }
1830
1831 static gboolean read_mask(const RrInstance *inst, const gchar *path,
1832                           RrTheme *theme, const gchar *maskname,
1833                           RrPixmapMask **value)
1834 {
1835     gboolean ret = FALSE;
1836     gchar *s;
1837     gint hx, hy; /* ignored */
1838     guint w, h;
1839     guchar *b;
1840
1841     s = g_build_filename(path, maskname, NULL);
1842     if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess) {
1843         ret = TRUE;
1844         *value = RrPixmapMaskNew(inst, w, h, (gchar*)b);
1845         XFree(b);
1846     }
1847     g_free(s);
1848
1849     return ret;
1850 }
1851
1852 static void parse_appearance(gchar *tex, RrSurfaceColorType *grad,
1853                              RrReliefType *relief, RrBevelType *bevel,
1854                              gboolean *interlaced, gboolean *border,
1855                              gboolean allow_trans)
1856 {
1857     gchar *t;
1858
1859     /* convert to all lowercase */
1860     for (t = tex; *t != '\0'; ++t)
1861         *t = g_ascii_tolower(*t);
1862
1863     if (allow_trans && strstr(tex, "parentrelative") != NULL) {
1864         *grad = RR_SURFACE_PARENTREL;
1865     } else {
1866         if (strstr(tex, "gradient") != NULL) {
1867             if (strstr(tex, "crossdiagonal") != NULL)
1868                 *grad = RR_SURFACE_CROSS_DIAGONAL;
1869             else if (strstr(tex, "pyramid") != NULL)
1870                 *grad = RR_SURFACE_PYRAMID;
1871             else if (strstr(tex, "mirrorhorizontal") != NULL)
1872                 *grad = RR_SURFACE_MIRROR_HORIZONTAL;
1873             else if (strstr(tex, "horizontal") != NULL)
1874                 *grad = RR_SURFACE_HORIZONTAL;
1875             else if (strstr(tex, "splitvertical") != NULL)
1876                 *grad = RR_SURFACE_SPLIT_VERTICAL;
1877             else if (strstr(tex, "vertical") != NULL)
1878                 *grad = RR_SURFACE_VERTICAL;
1879             else
1880                 *grad = RR_SURFACE_DIAGONAL;
1881         } else {
1882             *grad = RR_SURFACE_SOLID;
1883         }
1884     }
1885
1886     if (strstr(tex, "sunken") != NULL)
1887         *relief = RR_RELIEF_SUNKEN;
1888     else if (strstr(tex, "flat") != NULL)
1889         *relief = RR_RELIEF_FLAT;
1890     else if (strstr(tex, "raised") != NULL)
1891         *relief = RR_RELIEF_RAISED;
1892     else
1893         *relief = (*grad == RR_SURFACE_PARENTREL) ?
1894                   RR_RELIEF_FLAT : RR_RELIEF_RAISED;
1895
1896     *border = FALSE;
1897     if (*relief == RR_RELIEF_FLAT) {
1898         if (strstr(tex, "border") != NULL)
1899             *border = TRUE;
1900     } else {
1901         if (strstr(tex, "bevel2") != NULL)
1902             *bevel = RR_BEVEL_2;
1903         else
1904             *bevel = RR_BEVEL_1;
1905     }
1906
1907     if (strstr(tex, "interlaced") != NULL)
1908         *interlaced = TRUE;
1909     else
1910         *interlaced = FALSE;
1911 }
1912
1913 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
1914                                 const gchar *rname, RrAppearance *value,
1915                                 gboolean allow_trans)
1916 {
1917     gboolean ret = FALSE;
1918     gchar *rclass = create_class_name(rname);
1919     gchar *cname, *ctoname, *bcname, *icname, *hname, *sname;
1920     gchar *csplitname, *ctosplitname;
1921     gchar *rettype;
1922     XrmValue retvalue;
1923     gint i;
1924
1925     cname = g_strconcat(rname, ".color", NULL);
1926     ctoname = g_strconcat(rname, ".colorTo", NULL);
1927     bcname = g_strconcat(rname, ".border.color", NULL);
1928     icname = g_strconcat(rname, ".interlace.color", NULL);
1929     hname = g_strconcat(rname, ".highlight", NULL);
1930     sname = g_strconcat(rname, ".shadow", NULL);
1931     csplitname = g_strconcat(rname, ".color.splitTo", NULL);
1932     ctosplitname = g_strconcat(rname, ".colorTo.splitTo", NULL);
1933
1934     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1935         retvalue.addr != NULL) {
1936         parse_appearance(retvalue.addr,
1937                          &value->surface.grad,
1938                          &value->surface.relief,
1939                          &value->surface.bevel,
1940                          &value->surface.interlaced,
1941                          &value->surface.border,
1942                          allow_trans);
1943         if (!read_color(db, inst, cname, &value->surface.primary))
1944             value->surface.primary = RrColorNew(inst, 0, 0, 0);
1945         if (!read_color(db, inst, ctoname, &value->surface.secondary))
1946             value->surface.secondary = RrColorNew(inst, 0, 0, 0);
1947         if (value->surface.border)
1948             if (!read_color(db, inst, bcname,
1949                             &value->surface.border_color))
1950                 value->surface.border_color = RrColorNew(inst, 0, 0, 0);
1951         if (value->surface.interlaced)
1952             if (!read_color(db, inst, icname,
1953                             &value->surface.interlace_color))
1954                 value->surface.interlace_color = RrColorNew(inst, 0, 0, 0);
1955         if (read_int(db, hname, &i) && i >= 0)
1956             value->surface.bevel_light_adjust = i;
1957         if (read_int(db, sname, &i) && i >= 0 && i <= 256)
1958             value->surface.bevel_dark_adjust = i;
1959
1960         if (value->surface.grad == RR_SURFACE_SPLIT_VERTICAL) {
1961             gint r, g, b;
1962
1963             if (!read_color(db, inst, csplitname,
1964                             &value->surface.split_primary))
1965             {
1966                 r = value->surface.primary->r;
1967                 r += r >> 2;
1968                 g = value->surface.primary->g;
1969                 g += g >> 2;
1970                 b = value->surface.primary->b;
1971                 b += b >> 2;
1972                 if (r > 0xFF) r = 0xFF;
1973                 if (g > 0xFF) g = 0xFF;
1974                 if (b > 0xFF) b = 0xFF;
1975                 value->surface.split_primary = RrColorNew(inst, r, g, b);
1976             }
1977
1978             if (!read_color(db, inst, ctosplitname,
1979                             &value->surface.split_secondary))
1980             {
1981                 r = value->surface.secondary->r;
1982                 r += r >> 4;
1983                 g = value->surface.secondary->g;
1984                 g += g >> 4;
1985                 b = value->surface.secondary->b;
1986                 b += b >> 4;
1987                 if (r > 0xFF) r = 0xFF;
1988                 if (g > 0xFF) g = 0xFF;
1989                 if (b > 0xFF) b = 0xFF;
1990                 value->surface.split_secondary = RrColorNew(inst, r, g, b);
1991             }
1992         }
1993
1994         ret = TRUE;
1995     }
1996
1997     g_free(ctosplitname);
1998     g_free(csplitname);
1999     g_free(sname);
2000     g_free(hname);
2001     g_free(icname);
2002     g_free(bcname);
2003     g_free(ctoname);
2004     g_free(cname);
2005     g_free(rclass);
2006     return ret;
2007 }
2008
2009 static int parse_inline_number(const char *p)
2010 {
2011     int neg = 1;
2012     int res = 0;
2013     if (*p == '-') {
2014         neg = -1;
2015         ++p;
2016     }
2017     for (; isdigit(*p); ++p)
2018         res = res * 10 + *p - '0';
2019     res *= neg;
2020     return res;
2021 }
2022
2023 static void set_default_appearance(RrAppearance *a)
2024 {
2025     a->surface.grad = RR_SURFACE_SOLID;
2026     a->surface.relief = RR_RELIEF_FLAT;
2027     a->surface.bevel = RR_BEVEL_1;
2028     a->surface.interlaced = FALSE;
2029     a->surface.border = FALSE;
2030     a->surface.primary = RrColorNew(a->inst, 0, 0, 0);
2031     a->surface.secondary = RrColorNew(a->inst, 0, 0, 0);
2032 }
2033
2034 /* Reads the output from gimp's C-Source file format into valid RGBA data for
2035    an RrTextureRGBA. */
2036 static RrPixel32* read_c_image(gint width, gint height, const guint8 *data)
2037 {
2038     RrPixel32 *im, *p;
2039     gint i;
2040
2041     p = im = g_memdup(data, width * height * sizeof(RrPixel32));
2042
2043     for (i = 0; i < width * height; ++i) {
2044         guchar a = ((*p >> 24) & 0xff);
2045         guchar b = ((*p >> 16) & 0xff);
2046         guchar g = ((*p >>  8) & 0xff);
2047         guchar r = ((*p >>  0) & 0xff);
2048
2049         *p = ((r << RrDefaultRedOffset) +
2050               (g << RrDefaultGreenOffset) +
2051               (b << RrDefaultBlueOffset) +
2052               (a << RrDefaultAlphaOffset));
2053         p++;
2054     }
2055
2056     return im;
2057 }
2058
2059 static void read_button_colors(XrmDatabase db, const RrInstance *inst, 
2060                                const RrTheme *theme, RrButton *btn, 
2061                                const gchar *btnname)
2062 {
2063     gchar *name;
2064
2065     /* active unpressed */
2066     name = g_strdup_printf("window.active.button.%s.unpressed.image.color", btnname);
2067     READ_COLOR(name, btn->focused_unpressed_color,
2068                RrColorCopy(theme->titlebut_focused_unpressed_color));
2069     g_free(name);
2070
2071     /* inactive unpressed */
2072     name = g_strdup_printf("window.inactive.button.%s.unpressed.image.color", btnname);
2073     READ_COLOR(name, btn->unfocused_unpressed_color,
2074                RrColorCopy(theme->titlebut_unfocused_unpressed_color));
2075     g_free(name);
2076
2077     /* active pressed */
2078     name = g_strdup_printf("window.active.button.%s.pressed.image.color", btnname);
2079     READ_COLOR(name, btn->focused_pressed_color,
2080                RrColorCopy(theme->titlebut_focused_pressed_color));
2081     g_free(name);
2082
2083     /* inactive pressed */
2084     name = g_strdup_printf("window.inactive.button.%s.pressed.image.color", btnname);
2085     READ_COLOR(name, btn->unfocused_pressed_color,
2086                RrColorCopy(theme->titlebut_unfocused_pressed_color));
2087     g_free(name);
2088
2089     /* active disabled */
2090     name = g_strdup_printf("window.active.button.%s.disabled.image.color", btnname);
2091     READ_COLOR(name, btn->disabled_focused_color,
2092                RrColorCopy(theme->titlebut_disabled_focused_color));
2093     g_free(name);
2094
2095     /* inactive disabled */
2096     name = g_strdup_printf("window.inactive.button.%s.disabled.image.color", btnname);
2097     READ_COLOR(name, btn->disabled_unfocused_color,
2098                RrColorCopy(theme->titlebut_disabled_unfocused_color));
2099     g_free(name);
2100
2101     /* active hover */
2102     name = g_strdup_printf("window.active.button.%s.hover.image.color", btnname);
2103     READ_COLOR(name, btn->hover_focused_color, 
2104                RrColorCopy(theme->titlebut_hover_focused_color));
2105     g_free(name);
2106
2107     /* inactive hover */
2108     name = g_strdup_printf("window.inactive.button.%s.hover.image.color", btnname);
2109     READ_COLOR(name, btn->hover_unfocused_color,
2110                RrColorCopy(theme->titlebut_hover_unfocused_color));
2111     g_free(name);
2112
2113     /* active toggled unpressed */
2114     name = g_strdup_printf("window.active.button.%s.toggled.unpressed.image.color", btnname);
2115     READ_COLOR(name, btn->toggled_focused_unpressed_color,
2116                RrColorCopy(theme->titlebut_toggled_focused_unpressed_color));
2117     g_free(name);
2118
2119     /* inactive toggled unpressed */
2120     name = g_strdup_printf("window.inactive.button.%s.toggled.unpressed.image.color", btnname);
2121     READ_COLOR(name, btn->toggled_unfocused_unpressed_color,
2122                RrColorCopy(theme->titlebut_toggled_unfocused_unpressed_color));
2123     g_free(name);
2124
2125     /* active toggled hover */
2126     name = g_strdup_printf("window.active.button.%s.toggled.hover.image.color", btnname);
2127     READ_COLOR(name, btn->toggled_hover_focused_color,
2128                RrColorCopy(theme->titlebut_toggled_hover_focused_color));
2129
2130     g_free(name);
2131
2132     /* inactive toggled hover */
2133     name = g_strdup_printf("window.inactive.button.%s.toggled.hover.image.color", btnname);
2134     READ_COLOR(name, btn->toggled_hover_unfocused_color,
2135                RrColorCopy(theme->titlebut_toggled_hover_unfocused_color));
2136     g_free(name);
2137
2138     /* active toggled pressed */
2139     name = g_strdup_printf("window.active.button.%s.toggled.pressed.image.color", btnname);
2140     READ_COLOR(name, btn->toggled_focused_pressed_color, 
2141                RrColorCopy(theme->titlebut_toggled_focused_pressed_color));
2142     g_free(name);
2143    
2144     /* inactive toggled pressed */
2145     name = g_strdup_printf("window.inactive.button.%s.toggled.pressed.image.color", btnname);
2146     READ_COLOR(name, btn->toggled_unfocused_pressed_color,
2147                RrColorCopy(theme->titlebut_toggled_unfocused_pressed_color));
2148     g_free(name);
2149 }
2150
2151