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