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