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