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