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