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