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