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