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