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