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