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