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