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