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