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