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