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