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