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