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