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