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