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