]> icculus.org git repositories - mikachu/openbox.git/blob - render/theme.c
Only open the default font once, then ref it.
[mikachu/openbox.git] / render / theme.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    theme.c for the Openbox window manager
4    Copyright (c) 2006        Mikael Magnusson
5    Copyright (c) 2003-2007   Dana Jansens
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "render.h"
21 #include "color.h"
22 #include "font.h"
23 #include "mask.h"
24 #include "theme.h"
25 #include "icon.h"
26 #include "parser/parse.h"
27
28 #include <X11/Xlib.h>
29 #include <X11/Xresource.h>
30 #include <ctype.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 static XrmDatabase loaddb(const gchar *name, gchar **path);
35 static gboolean read_int(XrmDatabase db, const gchar *rname, gint *value);
36 static gboolean read_string(XrmDatabase db, const gchar *rname, gchar **value);
37 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
38                            const gchar *rname, RrColor **value);
39 static gboolean read_mask(const RrInstance *inst, const gchar *path,
40                           RrTheme *theme, const gchar *maskname,
41                           RrPixmapMask **value);
42 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
43                                 const gchar *rname, RrAppearance *value,
44                                 gboolean allow_trans);
45 static int parse_inline_number(const char *p);
46 static RrPixel32* read_c_image(gint width, gint height, const guint8 *data);
47 static void set_default_appearance(RrAppearance *a);
48
49 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     /* setup the default window icon */
560     theme->def_win_icon = read_c_image(OB_DEFAULT_ICON_WIDTH,
561                                        OB_DEFAULT_ICON_HEIGHT,
562                                        OB_DEFAULT_ICON_pixel_data);
563     theme->def_win_icon_w = OB_DEFAULT_ICON_WIDTH;
564     theme->def_win_icon_h = OB_DEFAULT_ICON_HEIGHT;
565
566     /* read the decoration textures */
567     if (!read_appearance(db, inst,
568                          "window.active.title.bg", theme->a_focused_title,
569                          FALSE))
570         set_default_appearance(theme->a_focused_title);
571     if (!read_appearance(db, inst,
572                          "window.inactive.title.bg", theme->a_unfocused_title,
573                          FALSE))
574         set_default_appearance(theme->a_unfocused_title);
575     if (!read_appearance(db, inst,
576                          "window.active.label.bg", theme->a_focused_label,
577                          TRUE))
578         set_default_appearance(theme->a_focused_label);
579     if (!read_appearance(db, inst,
580                          "window.inactive.label.bg", theme->a_unfocused_label,
581                          TRUE))
582         set_default_appearance(theme->a_unfocused_label);
583     if (!read_appearance(db, inst,
584                          "window.active.handle.bg", theme->a_focused_handle,
585                          FALSE))
586         set_default_appearance(theme->a_focused_handle);
587     if (!read_appearance(db, inst,
588                          "window.inactive.handle.bg",theme->a_unfocused_handle,
589                          FALSE))
590         set_default_appearance(theme->a_unfocused_handle);
591     if (!read_appearance(db, inst,
592                          "window.active.grip.bg", theme->a_focused_grip,
593                          TRUE))
594         set_default_appearance(theme->a_focused_grip);
595     if (!read_appearance(db, inst,
596                          "window.inactive.grip.bg", theme->a_unfocused_grip,
597                          TRUE))
598         set_default_appearance(theme->a_unfocused_grip);
599     if (!read_appearance(db, inst,
600                          "menu.items.bg", theme->a_menu,
601                          FALSE))
602         set_default_appearance(theme->a_menu);
603     if (!read_appearance(db, inst,
604                          "menu.title.bg", theme->a_menu_title,
605                          TRUE))
606         set_default_appearance(theme->a_menu_title);
607     if (!read_appearance(db, inst,
608                          "menu.items.active.bg", theme->a_menu_selected,
609                          TRUE))
610         set_default_appearance(theme->a_menu_selected);
611     theme->a_menu_disabled_selected =
612         RrAppearanceCopy(theme->a_menu_selected);
613
614     /* read appearances for non-decorations (on-screen-display) */
615     if (!read_appearance(db, inst, "osd.bg", theme->osd_hilite_bg, FALSE)) {
616         RrAppearanceFree(theme->osd_hilite_bg);
617         theme->osd_hilite_bg = RrAppearanceCopy(theme->a_focused_title);
618     }
619     if (!read_appearance(db, inst, "osd.label.bg",
620                          theme->osd_hilite_label, TRUE)) {
621         RrAppearanceFree(theme->osd_hilite_label);
622         theme->osd_hilite_label = RrAppearanceCopy(theme->a_focused_label);
623     }
624     /* osd_hilite_fg can't be parentrel */
625     if (!read_appearance(db, inst, "osd.hilight.bg",
626                          theme->osd_hilite_fg, FALSE)) {
627         RrAppearanceFree(theme->osd_hilite_fg);
628         if (theme->a_focused_label->surface.grad != RR_SURFACE_PARENTREL)
629             theme->osd_hilite_fg = RrAppearanceCopy(theme->a_focused_label);
630         else
631             theme->osd_hilite_fg = RrAppearanceCopy(theme->a_focused_title);
632     }
633     /* osd_unhilite_fg can't be parentrel either */
634     if (!read_appearance(db, inst, "osd.unhilight.bg",
635                          theme->osd_unhilite_fg, FALSE)) {
636         RrAppearanceFree(theme->osd_unhilite_fg);
637         if (theme->a_unfocused_label->surface.grad != RR_SURFACE_PARENTREL)
638             theme->osd_unhilite_fg=RrAppearanceCopy(theme->a_unfocused_label);
639         else
640             theme->osd_unhilite_fg=RrAppearanceCopy(theme->a_unfocused_title);
641     }
642
643     /* read buttons textures */
644     if (!read_appearance(db, inst,
645                          "window.active.button.disabled.bg",
646                          theme->a_disabled_focused_max,
647                          TRUE))
648         set_default_appearance(theme->a_disabled_focused_max);
649     if (!read_appearance(db, inst,
650                          "window.inactive.button.disabled.bg",
651                          theme->a_disabled_unfocused_max,
652                          TRUE))
653         set_default_appearance(theme->a_disabled_unfocused_max);
654     if (!read_appearance(db, inst,
655                          "window.active.button.pressed.bg",
656                          theme->a_focused_pressed_max,
657                          TRUE))
658         set_default_appearance(theme->a_focused_pressed_max);
659     if (!read_appearance(db, inst,
660                          "window.inactive.button.pressed.bg",
661                          theme->a_unfocused_pressed_max,
662                          TRUE))
663         set_default_appearance(theme->a_unfocused_pressed_max);
664     if (!read_appearance(db, inst,
665                          "window.active.button.toggled.unpressed.bg",
666                          theme->a_toggled_focused_unpressed_max,
667                          TRUE) &&
668         !read_appearance(db, inst,
669                          "window.active.button.toggled.bg",
670                          theme->a_toggled_focused_unpressed_max,
671                          TRUE))
672     {
673         RrAppearanceFree(theme->a_toggled_focused_unpressed_max);
674         theme->a_toggled_focused_unpressed_max =
675             RrAppearanceCopy(theme->a_focused_pressed_max);
676     }
677     if (!read_appearance(db, inst,
678                          "window.inactive.button.toggled.unpressed.bg",
679                          theme->a_toggled_unfocused_unpressed_max,
680                          TRUE) &&
681         !read_appearance(db, inst,
682                          "window.inactive.button.toggled.bg",
683                          theme->a_toggled_unfocused_unpressed_max,
684                          TRUE))
685     {
686         RrAppearanceFree(theme->a_toggled_unfocused_unpressed_max);
687         theme->a_toggled_unfocused_unpressed_max =
688             RrAppearanceCopy(theme->a_unfocused_pressed_max);
689     }
690     if (!read_appearance(db, inst,
691                          "window.active.button.toggled.hover.bg",
692                          theme->a_toggled_hover_focused_max,
693                          TRUE))
694     {
695         RrAppearanceFree(theme->a_toggled_hover_focused_max);
696         theme->a_toggled_hover_focused_max =
697             RrAppearanceCopy(theme->a_toggled_focused_unpressed_max);
698     }
699     if (!read_appearance(db, inst,
700                          "window.inactive.button.toggled.hover.bg",
701                          theme->a_toggled_hover_unfocused_max,
702                          TRUE))
703     {
704         RrAppearanceFree(theme->a_toggled_hover_unfocused_max);
705         theme->a_toggled_hover_unfocused_max =
706             RrAppearanceCopy(theme->a_toggled_unfocused_unpressed_max);
707     }
708     if (!read_appearance(db, inst,
709                          "window.active.button.toggled.pressed.bg",
710                          theme->a_toggled_focused_pressed_max,
711                          TRUE))
712     {
713         RrAppearanceFree(theme->a_toggled_focused_pressed_max);
714         theme->a_toggled_focused_pressed_max =
715             RrAppearanceCopy(theme->a_focused_pressed_max);
716     }
717     if (!read_appearance(db, inst,
718                          "window.inactive.button.toggled.pressed.bg",
719                          theme->a_toggled_unfocused_pressed_max,
720                          TRUE))
721     {
722         RrAppearanceFree(theme->a_toggled_unfocused_pressed_max);
723         theme->a_toggled_unfocused_pressed_max =
724             RrAppearanceCopy(theme->a_unfocused_pressed_max);
725     }
726     if (!read_appearance(db, inst,
727                          "window.active.button.unpressed.bg",
728                          theme->a_focused_unpressed_max,
729                          TRUE))
730         set_default_appearance(theme->a_focused_unpressed_max);
731     if (!read_appearance(db, inst,
732                          "window.inactive.button.unpressed.bg",
733                          theme->a_unfocused_unpressed_max,
734                          TRUE))
735         set_default_appearance(theme->a_unfocused_unpressed_max);
736     if (!read_appearance(db, inst,
737                          "window.active.button.hover.bg",
738                          theme->a_hover_focused_max,
739                          TRUE))
740     {
741         RrAppearanceFree(theme->a_hover_focused_max);
742         theme->a_hover_focused_max =
743             RrAppearanceCopy(theme->a_focused_unpressed_max);
744     }
745     if (!read_appearance(db, inst,
746                          "window.inactive.button.hover.bg",
747                          theme->a_hover_unfocused_max,
748                          TRUE))
749     {
750         RrAppearanceFree(theme->a_hover_unfocused_max);
751         theme->a_hover_unfocused_max =
752             RrAppearanceCopy(theme->a_unfocused_unpressed_max);
753     }
754
755     theme->a_disabled_focused_close =
756         RrAppearanceCopy(theme->a_disabled_focused_max);
757     theme->a_disabled_unfocused_close =
758         RrAppearanceCopy(theme->a_disabled_unfocused_max);
759     theme->a_hover_focused_close =
760         RrAppearanceCopy(theme->a_hover_focused_max);
761     theme->a_hover_unfocused_close =
762         RrAppearanceCopy(theme->a_hover_unfocused_max);
763     theme->a_unfocused_unpressed_close =
764         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
765     theme->a_unfocused_pressed_close =
766         RrAppearanceCopy(theme->a_unfocused_pressed_max);
767     theme->a_focused_unpressed_close =
768         RrAppearanceCopy(theme->a_focused_unpressed_max);
769     theme->a_focused_pressed_close =
770         RrAppearanceCopy(theme->a_focused_pressed_max);
771     theme->a_disabled_focused_desk =
772         RrAppearanceCopy(theme->a_disabled_focused_max);
773     theme->a_disabled_unfocused_desk =
774         RrAppearanceCopy(theme->a_disabled_unfocused_max);
775     theme->a_hover_focused_desk =
776         RrAppearanceCopy(theme->a_hover_focused_max);
777     theme->a_hover_unfocused_desk =
778         RrAppearanceCopy(theme->a_hover_unfocused_max);
779     theme->a_toggled_hover_focused_desk =
780         RrAppearanceCopy(theme->a_toggled_hover_focused_max);
781     theme->a_toggled_hover_unfocused_desk =
782         RrAppearanceCopy(theme->a_toggled_hover_unfocused_max);
783     theme->a_toggled_focused_unpressed_desk =
784         RrAppearanceCopy(theme->a_toggled_focused_unpressed_max);
785     theme->a_toggled_unfocused_unpressed_desk =
786         RrAppearanceCopy(theme->a_toggled_unfocused_unpressed_max);
787     theme->a_toggled_focused_pressed_desk =
788         RrAppearanceCopy(theme->a_toggled_focused_pressed_max);
789     theme->a_toggled_unfocused_pressed_desk =
790         RrAppearanceCopy(theme->a_toggled_unfocused_pressed_max);
791     theme->a_unfocused_unpressed_desk =
792         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
793     theme->a_unfocused_pressed_desk =
794         RrAppearanceCopy(theme->a_unfocused_pressed_max);
795     theme->a_focused_unpressed_desk =
796         RrAppearanceCopy(theme->a_focused_unpressed_max);
797     theme->a_focused_pressed_desk =
798         RrAppearanceCopy(theme->a_focused_pressed_max);
799     theme->a_disabled_focused_shade =
800         RrAppearanceCopy(theme->a_disabled_focused_max);
801     theme->a_disabled_unfocused_shade =
802         RrAppearanceCopy(theme->a_disabled_unfocused_max);
803     theme->a_hover_focused_shade =
804         RrAppearanceCopy(theme->a_hover_focused_max);
805     theme->a_hover_unfocused_shade =
806         RrAppearanceCopy(theme->a_hover_unfocused_max);
807     theme->a_toggled_hover_focused_shade =
808         RrAppearanceCopy(theme->a_toggled_hover_focused_max);
809     theme->a_toggled_hover_unfocused_shade =
810         RrAppearanceCopy(theme->a_toggled_hover_unfocused_max);
811     theme->a_toggled_focused_unpressed_shade =
812         RrAppearanceCopy(theme->a_toggled_focused_unpressed_max);
813     theme->a_toggled_unfocused_unpressed_shade =
814         RrAppearanceCopy(theme->a_toggled_unfocused_unpressed_max);
815     theme->a_toggled_focused_pressed_shade =
816         RrAppearanceCopy(theme->a_toggled_focused_pressed_max);
817     theme->a_toggled_unfocused_pressed_shade =
818         RrAppearanceCopy(theme->a_toggled_unfocused_pressed_max);
819     theme->a_unfocused_unpressed_shade =
820         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
821     theme->a_unfocused_pressed_shade =
822         RrAppearanceCopy(theme->a_unfocused_pressed_max);
823     theme->a_focused_unpressed_shade =
824         RrAppearanceCopy(theme->a_focused_unpressed_max);
825     theme->a_focused_pressed_shade =
826         RrAppearanceCopy(theme->a_focused_pressed_max);
827     theme->a_disabled_focused_iconify =
828         RrAppearanceCopy(theme->a_disabled_focused_max);
829     theme->a_disabled_unfocused_iconify =
830         RrAppearanceCopy(theme->a_disabled_focused_max);
831     theme->a_hover_focused_iconify =
832         RrAppearanceCopy(theme->a_hover_focused_max);
833     theme->a_hover_unfocused_iconify =
834         RrAppearanceCopy(theme->a_hover_unfocused_max);
835     theme->a_unfocused_unpressed_iconify =
836         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
837     theme->a_unfocused_pressed_iconify =
838         RrAppearanceCopy(theme->a_unfocused_pressed_max);
839     theme->a_focused_unpressed_iconify =
840         RrAppearanceCopy(theme->a_focused_unpressed_max);
841     theme->a_focused_pressed_iconify =
842         RrAppearanceCopy(theme->a_focused_pressed_max);
843
844     theme->a_icon->surface.grad =
845         theme->a_clear->surface.grad =
846         theme->a_clear_tex->surface.grad =
847         theme->a_menu_text_title->surface.grad =
848         theme->a_menu_normal->surface.grad =
849         theme->a_menu_disabled->surface.grad =
850         theme->a_menu_text_normal->surface.grad =
851         theme->a_menu_text_selected->surface.grad =
852         theme->a_menu_text_disabled->surface.grad =
853         theme->a_menu_text_disabled_selected->surface.grad =
854         theme->a_menu_bullet_normal->surface.grad =
855         theme->a_menu_bullet_selected->surface.grad = RR_SURFACE_PARENTREL;
856
857     /* set up the textures */
858     theme->a_focused_label->texture[0].type = RR_TEXTURE_TEXT;
859     theme->a_focused_label->texture[0].data.text.justify = winjust;
860     theme->a_focused_label->texture[0].data.text.font=theme->win_font_focused;
861     theme->a_focused_label->texture[0].data.text.color =
862         theme->title_focused_color;
863
864     if (read_string(db, "window.active.label.text.font", &str)) {
865         char *p;
866         gint i = 0;
867         gint j;
868         if (strstr(str, "shadow=y")) {
869             if ((p = strstr(str, "shadowoffset=")))
870                 i = parse_inline_number(p + strlen("shadowoffset="));
871             else
872                 i = 1;
873             theme->a_focused_label->texture[0].data.text.shadow_offset_x = i;
874             theme->a_focused_label->texture[0].data.text.shadow_offset_y = i;
875         }
876         if ((p = strstr(str, "shadowtint=")))
877         {
878             i = parse_inline_number(p + strlen("shadowtint="));
879             j = (i > 0 ? 0 : 255);
880             i = ABS(i*255/100);
881
882             theme->title_focused_shadow_color = RrColorNew(inst, j, j, j);
883             theme->title_focused_shadow_alpha = i;
884         } else {
885             theme->title_focused_shadow_color = RrColorNew(inst, 0, 0, 0);
886             theme->title_focused_shadow_alpha = 50;
887         }
888     }
889
890     theme->a_focused_label->texture[0].data.text.shadow_color =
891         theme->title_focused_shadow_color;
892     theme->a_focused_label->texture[0].data.text.shadow_alpha =
893         theme->title_focused_shadow_alpha;
894
895     theme->osd_hilite_label->texture[0].type = RR_TEXTURE_TEXT;
896     theme->osd_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
897     theme->osd_hilite_label->texture[0].data.text.font = theme->osd_font;
898     theme->osd_hilite_label->texture[0].data.text.color = theme->osd_color;
899
900     if (read_string(db, "osd.label.text.font", &str)) {
901         char *p;
902         gint i = 0;
903         gint j;
904         if (strstr(str, "shadow=y")) {
905             if ((p = strstr(str, "shadowoffset=")))
906                 i = parse_inline_number(p + strlen("shadowoffset="));
907             else
908                 i = 1;
909             theme->a_focused_label->texture[0].data.text.shadow_offset_x = i;
910             theme->a_focused_label->texture[0].data.text.shadow_offset_y = i;
911             theme->osd_hilite_label->texture[0].data.text.shadow_offset_x = i;
912             theme->osd_hilite_label->texture[0].data.text.shadow_offset_y = i;
913         }
914         if ((p = strstr(str, "shadowtint=")))
915         {
916             i = parse_inline_number(p + strlen("shadowtint="));
917             j = (i > 0 ? 0 : 255);
918             i = ABS(i*255/100);
919
920             theme->osd_shadow_color = RrColorNew(inst, j, j, j);
921             theme->osd_shadow_alpha = i;
922         } else {
923             theme->osd_shadow_color = RrColorNew(inst, 0, 0, 0);
924             theme->osd_shadow_alpha = 50;
925         }
926     } else {
927         /* inherit the font settings from the focused label */
928         theme->osd_hilite_label->texture[0].data.text.shadow_offset_x =
929             theme->a_focused_label->texture[0].data.text.shadow_offset_x;
930         theme->osd_hilite_label->texture[0].data.text.shadow_offset_y =
931             theme->a_focused_label->texture[0].data.text.shadow_offset_y;
932         if (theme->title_focused_shadow_color)
933             theme->osd_shadow_color =
934                 RrColorNew(inst,
935                            theme->title_focused_shadow_color->r,
936                            theme->title_focused_shadow_color->g,
937                            theme->title_focused_shadow_color->b);
938         else
939             theme->osd_shadow_color = RrColorNew(inst, 0, 0, 0);
940         theme->osd_shadow_alpha = theme->title_focused_shadow_alpha;
941     }
942
943     theme->osd_hilite_label->texture[0].data.text.shadow_color =
944         theme->osd_shadow_color;
945     theme->osd_hilite_label->texture[0].data.text.shadow_alpha =
946         theme->osd_shadow_alpha;
947
948     theme->a_unfocused_label->texture[0].type = RR_TEXTURE_TEXT;
949     theme->a_unfocused_label->texture[0].data.text.justify = winjust;
950     theme->a_unfocused_label->texture[0].data.text.font =
951         theme->win_font_unfocused;
952     theme->a_unfocused_label->texture[0].data.text.color =
953         theme->title_unfocused_color;
954
955     if (read_string(db, "window.inactive.label.text.font", &str)) {
956         char *p;
957         gint i = 0;
958         gint j;
959         if (strstr(str, "shadow=y")) {
960             if ((p = strstr(str, "shadowoffset=")))
961                 i = parse_inline_number(p + strlen("shadowoffset="));
962             else
963                 i = 1;
964             theme->a_unfocused_label->texture[0].data.text.shadow_offset_x = i;
965             theme->a_unfocused_label->texture[0].data.text.shadow_offset_y = i;
966         }
967         if ((p = strstr(str, "shadowtint=")))
968         {
969             i = parse_inline_number(p + strlen("shadowtint="));
970             j = (i > 0 ? 0 : 255);
971             i = ABS(i*255/100);
972
973             theme->title_unfocused_shadow_color = RrColorNew(inst, j, j, j);
974             theme->title_unfocused_shadow_alpha = i;
975         } else {
976             theme->title_unfocused_shadow_color = RrColorNew(inst, 0, 0, 0);
977             theme->title_unfocused_shadow_alpha = 50;
978         }
979     }
980
981     theme->a_unfocused_label->texture[0].data.text.shadow_color =
982         theme->title_unfocused_shadow_color;
983     theme->a_unfocused_label->texture[0].data.text.shadow_alpha =
984         theme->title_unfocused_shadow_alpha;
985
986     theme->a_menu_text_title->texture[0].type = RR_TEXTURE_TEXT;
987     theme->a_menu_text_title->texture[0].data.text.justify = mtitlejust;
988     theme->a_menu_text_title->texture[0].data.text.font =
989         theme->menu_title_font;
990     theme->a_menu_text_title->texture[0].data.text.color =
991         theme->menu_title_color;
992
993     if (read_string(db, "menu.title.text.font", &str)) {
994         char *p;
995         gint i = 0;
996         gint j;
997         if (strstr(str, "shadow=y")) {
998             if ((p = strstr(str, "shadowoffset=")))
999                 i = parse_inline_number(p + strlen("shadowoffset="));
1000             else
1001                 i = 1;
1002             theme->a_menu_text_title->texture[0].data.text.shadow_offset_x = i;
1003             theme->a_menu_text_title->texture[0].data.text.shadow_offset_y = i;
1004         }
1005         if ((p = strstr(str, "shadowtint=")))
1006         {
1007             i = parse_inline_number(p + strlen("shadowtint="));
1008             j = (i > 0 ? 0 : 255);
1009             i = ABS(i*255/100);
1010
1011             theme->menu_title_shadow_color = RrColorNew(inst, j, j, j);
1012             theme->menu_title_shadow_alpha = i;
1013         } else {
1014             theme->menu_title_shadow_color = RrColorNew(inst, 0, 0, 0);
1015             theme->menu_title_shadow_alpha = 50;
1016         }
1017     }
1018
1019     theme->a_menu_text_title->texture[0].data.text.shadow_color =
1020         theme->menu_title_shadow_color;
1021     theme->a_menu_text_title->texture[0].data.text.shadow_alpha =
1022         theme->menu_title_shadow_alpha;
1023
1024     theme->a_menu_text_normal->texture[0].type =
1025         theme->a_menu_text_selected->texture[0].type =
1026         theme->a_menu_text_disabled->texture[0].type =
1027         theme->a_menu_text_disabled_selected->texture[0].type =
1028         RR_TEXTURE_TEXT;
1029     theme->a_menu_text_normal->texture[0].data.text.justify =
1030         theme->a_menu_text_selected->texture[0].data.text.justify =
1031         theme->a_menu_text_disabled->texture[0].data.text.justify =
1032         theme->a_menu_text_disabled_selected->texture[0].data.text.justify =
1033         RR_JUSTIFY_LEFT;
1034     theme->a_menu_text_normal->texture[0].data.text.font =
1035         theme->a_menu_text_selected->texture[0].data.text.font =
1036         theme->a_menu_text_disabled->texture[0].data.text.font =
1037         theme->a_menu_text_disabled_selected->texture[0].data.text.font =
1038         theme->menu_font;
1039     theme->a_menu_text_normal->texture[0].data.text.color = theme->menu_color;
1040     theme->a_menu_text_selected->texture[0].data.text.color =
1041         theme->menu_selected_color;
1042     theme->a_menu_text_disabled->texture[0].data.text.color =
1043         theme->menu_disabled_color;
1044     theme->a_menu_text_disabled_selected->texture[0].data.text.color =
1045         theme->menu_disabled_selected_color;
1046
1047     if (read_string(db, "menu.items.font", &str)) {
1048         char *p;
1049         gint i = 0;
1050         gint j;
1051         if (strstr(str, "shadow=y")) {
1052             if ((p = strstr(str, "shadowoffset=")))
1053                 i = parse_inline_number(p + strlen("shadowoffset="));
1054             else
1055                 i = 1;
1056             theme->a_menu_text_normal->
1057                 texture[0].data.text.shadow_offset_x = i;
1058             theme->a_menu_text_normal->
1059                 texture[0].data.text.shadow_offset_y = i;
1060             theme->a_menu_text_selected->
1061                 texture[0].data.text.shadow_offset_x = i;
1062             theme->a_menu_text_selected->
1063                 texture[0].data.text.shadow_offset_y = i;
1064             theme->a_menu_text_disabled->
1065                 texture[0].data.text.shadow_offset_x = i;
1066             theme->a_menu_text_disabled->
1067                 texture[0].data.text.shadow_offset_y = i;
1068             theme->a_menu_text_disabled_selected->
1069                 texture[0].data.text.shadow_offset_x = i;
1070             theme->a_menu_text_disabled_selected->
1071                 texture[0].data.text.shadow_offset_y = i;
1072         }
1073         if ((p = strstr(str, "shadowtint=")))
1074         {
1075             i = parse_inline_number(p + strlen("shadowtint="));
1076             j = (i > 0 ? 0 : 255);
1077             i = ABS(i*255/100);
1078
1079             theme->menu_text_normal_shadow_color = RrColorNew(inst, j, j, j);
1080             theme->menu_text_selected_shadow_color = RrColorNew(inst, j, j, j);
1081             theme->menu_text_disabled_shadow_color = RrColorNew(inst, j, j, j);
1082             theme->menu_text_normal_shadow_alpha = i;
1083             theme->menu_text_selected_shadow_alpha = i;
1084             theme->menu_text_disabled_shadow_alpha = i;
1085             theme->menu_text_disabled_selected_shadow_alpha = i;
1086         } else {
1087             theme->menu_text_normal_shadow_color = RrColorNew(inst, 0, 0, 0);
1088             theme->menu_text_selected_shadow_color = RrColorNew(inst, 0, 0, 0);
1089             theme->menu_text_disabled_shadow_color = RrColorNew(inst, 0, 0, 0);
1090             theme->menu_text_normal_shadow_alpha = 50;
1091             theme->menu_text_selected_shadow_alpha = 50;
1092             theme->menu_text_disabled_selected_shadow_alpha = 50;
1093         }
1094     }
1095
1096     theme->a_menu_text_normal->texture[0].data.text.shadow_color =
1097         theme->menu_text_normal_shadow_color;
1098     theme->a_menu_text_normal->texture[0].data.text.shadow_alpha =
1099         theme->menu_text_normal_shadow_alpha;
1100     theme->a_menu_text_selected->texture[0].data.text.shadow_color =
1101         theme->menu_text_selected_shadow_color;
1102     theme->a_menu_text_selected->texture[0].data.text.shadow_alpha =
1103         theme->menu_text_selected_shadow_alpha;
1104     theme->a_menu_text_disabled->texture[0].data.text.shadow_color =
1105         theme->menu_text_disabled_shadow_color;
1106     theme->a_menu_text_disabled->texture[0].data.text.shadow_alpha =
1107         theme->menu_text_disabled_shadow_alpha;
1108     theme->a_menu_text_disabled_selected->texture[0].data.text.shadow_color =
1109         theme->menu_text_disabled_shadow_color;
1110     theme->a_menu_text_disabled_selected->texture[0].data.text.shadow_alpha =
1111         theme->menu_text_disabled_shadow_alpha;
1112
1113     theme->a_disabled_focused_max->texture[0].type =
1114         theme->a_disabled_unfocused_max->texture[0].type =
1115         theme->a_hover_focused_max->texture[0].type =
1116         theme->a_hover_unfocused_max->texture[0].type =
1117         theme->a_toggled_hover_focused_max->texture[0].type =
1118         theme->a_toggled_hover_unfocused_max->texture[0].type =
1119         theme->a_toggled_focused_unpressed_max->texture[0].type =
1120         theme->a_toggled_unfocused_unpressed_max->texture[0].type =
1121         theme->a_toggled_focused_pressed_max->texture[0].type =
1122         theme->a_toggled_unfocused_pressed_max->texture[0].type =
1123         theme->a_focused_unpressed_max->texture[0].type =
1124         theme->a_focused_pressed_max->texture[0].type =
1125         theme->a_unfocused_unpressed_max->texture[0].type =
1126         theme->a_unfocused_pressed_max->texture[0].type =
1127         theme->a_disabled_focused_close->texture[0].type =
1128         theme->a_disabled_unfocused_close->texture[0].type =
1129         theme->a_hover_focused_close->texture[0].type =
1130         theme->a_hover_unfocused_close->texture[0].type =
1131         theme->a_focused_unpressed_close->texture[0].type =
1132         theme->a_focused_pressed_close->texture[0].type =
1133         theme->a_unfocused_unpressed_close->texture[0].type =
1134         theme->a_unfocused_pressed_close->texture[0].type =
1135         theme->a_disabled_focused_desk->texture[0].type =
1136         theme->a_disabled_unfocused_desk->texture[0].type =
1137         theme->a_hover_focused_desk->texture[0].type =
1138         theme->a_hover_unfocused_desk->texture[0].type =
1139         theme->a_toggled_hover_focused_desk->texture[0].type =
1140         theme->a_toggled_hover_unfocused_desk->texture[0].type =
1141         theme->a_toggled_focused_unpressed_desk->texture[0].type =
1142         theme->a_toggled_unfocused_unpressed_desk->texture[0].type =
1143         theme->a_toggled_focused_pressed_desk->texture[0].type =
1144         theme->a_toggled_unfocused_pressed_desk->texture[0].type =
1145         theme->a_focused_unpressed_desk->texture[0].type =
1146         theme->a_focused_pressed_desk->texture[0].type =
1147         theme->a_unfocused_unpressed_desk->texture[0].type =
1148         theme->a_unfocused_pressed_desk->texture[0].type =
1149         theme->a_disabled_focused_shade->texture[0].type =
1150         theme->a_disabled_unfocused_shade->texture[0].type =
1151         theme->a_hover_focused_shade->texture[0].type =
1152         theme->a_hover_unfocused_shade->texture[0].type =
1153         theme->a_toggled_hover_focused_shade->texture[0].type =
1154         theme->a_toggled_hover_unfocused_shade->texture[0].type =
1155         theme->a_toggled_focused_unpressed_shade->texture[0].type =
1156         theme->a_toggled_unfocused_unpressed_shade->texture[0].type =
1157         theme->a_toggled_focused_pressed_shade->texture[0].type =
1158         theme->a_toggled_unfocused_pressed_shade->texture[0].type =
1159         theme->a_focused_unpressed_shade->texture[0].type =
1160         theme->a_focused_pressed_shade->texture[0].type =
1161         theme->a_unfocused_unpressed_shade->texture[0].type =
1162         theme->a_unfocused_pressed_shade->texture[0].type =
1163         theme->a_disabled_focused_iconify->texture[0].type =
1164         theme->a_disabled_unfocused_iconify->texture[0].type =
1165         theme->a_hover_focused_iconify->texture[0].type =
1166         theme->a_hover_unfocused_iconify->texture[0].type =
1167         theme->a_focused_unpressed_iconify->texture[0].type =
1168         theme->a_focused_pressed_iconify->texture[0].type =
1169         theme->a_unfocused_unpressed_iconify->texture[0].type =
1170         theme->a_unfocused_pressed_iconify->texture[0].type =
1171         theme->a_menu_bullet_normal->texture[0].type =
1172         theme->a_menu_bullet_selected->texture[0].type = RR_TEXTURE_MASK;
1173
1174     theme->a_disabled_focused_max->texture[0].data.mask.mask =
1175         theme->a_disabled_unfocused_max->texture[0].data.mask.mask =
1176         theme->max_disabled_mask;
1177     theme->a_hover_focused_max->texture[0].data.mask.mask =
1178         theme->a_hover_unfocused_max->texture[0].data.mask.mask =
1179         theme->max_hover_mask;
1180     theme->a_focused_pressed_max->texture[0].data.mask.mask =
1181         theme->a_unfocused_pressed_max->texture[0].data.mask.mask =
1182         theme->max_pressed_mask;
1183     theme->a_focused_unpressed_max->texture[0].data.mask.mask =
1184         theme->a_unfocused_unpressed_max->texture[0].data.mask.mask =
1185         theme->max_mask;
1186     theme->a_toggled_hover_focused_max->texture[0].data.mask.mask =
1187         theme->a_toggled_hover_unfocused_max->texture[0].data.mask.mask =
1188         theme->max_toggled_hover_mask;
1189     theme->a_toggled_focused_unpressed_max->texture[0].data.mask.mask =
1190         theme->a_toggled_unfocused_unpressed_max->texture[0].data.mask.mask =
1191         theme->max_toggled_mask;
1192     theme->a_toggled_focused_pressed_max->texture[0].data.mask.mask =
1193         theme->a_toggled_unfocused_pressed_max->texture[0].data.mask.mask =
1194         theme->max_toggled_pressed_mask;
1195     theme->a_disabled_focused_close->texture[0].data.mask.mask =
1196         theme->a_disabled_unfocused_close->texture[0].data.mask.mask =
1197         theme->close_disabled_mask;
1198     theme->a_hover_focused_close->texture[0].data.mask.mask =
1199         theme->a_hover_unfocused_close->texture[0].data.mask.mask =
1200         theme->close_hover_mask;
1201     theme->a_focused_pressed_close->texture[0].data.mask.mask =
1202         theme->a_unfocused_pressed_close->texture[0].data.mask.mask =
1203         theme->close_pressed_mask;
1204     theme->a_focused_unpressed_close->texture[0].data.mask.mask =
1205         theme->a_unfocused_unpressed_close->texture[0].data.mask.mask =
1206         theme->close_mask;
1207     theme->a_disabled_focused_desk->texture[0].data.mask.mask =
1208         theme->a_disabled_unfocused_desk->texture[0].data.mask.mask =
1209         theme->desk_disabled_mask;
1210     theme->a_hover_focused_desk->texture[0].data.mask.mask =
1211         theme->a_hover_unfocused_desk->texture[0].data.mask.mask =
1212         theme->desk_hover_mask;
1213     theme->a_focused_pressed_desk->texture[0].data.mask.mask =
1214         theme->a_unfocused_pressed_desk->texture[0].data.mask.mask =
1215         theme->desk_pressed_mask;
1216     theme->a_focused_unpressed_desk->texture[0].data.mask.mask =
1217         theme->a_unfocused_unpressed_desk->texture[0].data.mask.mask =
1218         theme->desk_mask;
1219     theme->a_toggled_hover_focused_desk->texture[0].data.mask.mask =
1220         theme->a_toggled_hover_unfocused_desk->texture[0].data.mask.mask =
1221         theme->desk_toggled_hover_mask;
1222     theme->a_toggled_focused_unpressed_desk->texture[0].data.mask.mask =
1223         theme->a_toggled_unfocused_unpressed_desk->texture[0].data.mask.mask =
1224         theme->desk_toggled_mask;
1225     theme->a_toggled_focused_pressed_desk->texture[0].data.mask.mask =
1226         theme->a_toggled_unfocused_pressed_desk->texture[0].data.mask.mask =
1227         theme->desk_toggled_pressed_mask;
1228     theme->a_disabled_focused_shade->texture[0].data.mask.mask =
1229         theme->a_disabled_unfocused_shade->texture[0].data.mask.mask =
1230         theme->shade_disabled_mask;
1231     theme->a_hover_focused_shade->texture[0].data.mask.mask =
1232         theme->a_hover_unfocused_shade->texture[0].data.mask.mask =
1233         theme->shade_hover_mask;
1234     theme->a_focused_pressed_shade->texture[0].data.mask.mask =
1235         theme->a_unfocused_pressed_shade->texture[0].data.mask.mask =
1236         theme->shade_pressed_mask;
1237     theme->a_focused_unpressed_shade->texture[0].data.mask.mask =
1238         theme->a_unfocused_unpressed_shade->texture[0].data.mask.mask =
1239         theme->shade_mask;
1240     theme->a_toggled_hover_focused_shade->texture[0].data.mask.mask =
1241         theme->a_toggled_hover_unfocused_shade->texture[0].data.mask.mask =
1242         theme->shade_toggled_hover_mask;
1243     theme->a_toggled_focused_unpressed_shade->texture[0].data.mask.mask =
1244         theme->a_toggled_unfocused_unpressed_shade->texture[0].data.mask.mask =
1245         theme->shade_toggled_mask;
1246     theme->a_toggled_focused_pressed_shade->texture[0].data.mask.mask =
1247         theme->a_toggled_unfocused_pressed_shade->texture[0].data.mask.mask =
1248         theme->shade_toggled_pressed_mask;
1249     theme->a_disabled_focused_iconify->texture[0].data.mask.mask =
1250         theme->a_disabled_unfocused_iconify->texture[0].data.mask.mask =
1251         theme->iconify_disabled_mask;
1252     theme->a_hover_focused_iconify->texture[0].data.mask.mask =
1253         theme->a_hover_unfocused_iconify->texture[0].data.mask.mask =
1254         theme->iconify_hover_mask;
1255     theme->a_focused_pressed_iconify->texture[0].data.mask.mask =
1256         theme->a_unfocused_pressed_iconify->texture[0].data.mask.mask =
1257         theme->iconify_pressed_mask;
1258     theme->a_focused_unpressed_iconify->texture[0].data.mask.mask =
1259         theme->a_unfocused_unpressed_iconify->texture[0].data.mask.mask =
1260         theme->iconify_mask;
1261     theme->a_menu_bullet_normal->texture[0].data.mask.mask =
1262     theme->a_menu_bullet_selected->texture[0].data.mask.mask =
1263         theme->menu_bullet_mask;
1264     theme->a_disabled_focused_max->texture[0].data.mask.color =
1265         theme->a_disabled_focused_close->texture[0].data.mask.color =
1266         theme->a_disabled_focused_desk->texture[0].data.mask.color =
1267         theme->a_disabled_focused_shade->texture[0].data.mask.color =
1268         theme->a_disabled_focused_iconify->texture[0].data.mask.color =
1269         theme->titlebut_disabled_focused_color;
1270     theme->a_disabled_unfocused_max->texture[0].data.mask.color =
1271         theme->a_disabled_unfocused_close->texture[0].data.mask.color =
1272         theme->a_disabled_unfocused_desk->texture[0].data.mask.color =
1273         theme->a_disabled_unfocused_shade->texture[0].data.mask.color =
1274         theme->a_disabled_unfocused_iconify->texture[0].data.mask.color =
1275         theme->titlebut_disabled_unfocused_color;
1276     theme->a_hover_focused_max->texture[0].data.mask.color =
1277         theme->a_hover_focused_close->texture[0].data.mask.color =
1278         theme->a_hover_focused_desk->texture[0].data.mask.color =
1279         theme->a_hover_focused_shade->texture[0].data.mask.color =
1280         theme->a_hover_focused_iconify->texture[0].data.mask.color =
1281         theme->titlebut_hover_focused_color;
1282     theme->a_hover_unfocused_max->texture[0].data.mask.color =
1283         theme->a_hover_unfocused_close->texture[0].data.mask.color =
1284         theme->a_hover_unfocused_desk->texture[0].data.mask.color =
1285         theme->a_hover_unfocused_shade->texture[0].data.mask.color =
1286         theme->a_hover_unfocused_iconify->texture[0].data.mask.color =
1287         theme->titlebut_hover_unfocused_color;
1288     theme->a_toggled_hover_focused_max->texture[0].data.mask.color =
1289         theme->a_toggled_hover_focused_desk->texture[0].data.mask.color =
1290         theme->a_toggled_hover_focused_shade->texture[0].data.mask.color =
1291         theme->titlebut_toggled_hover_focused_color;
1292     theme->a_toggled_hover_unfocused_max->texture[0].data.mask.color =
1293         theme->a_toggled_hover_unfocused_desk->texture[0].data.mask.color =
1294         theme->a_toggled_hover_unfocused_shade->texture[0].data.mask.color =
1295         theme->titlebut_toggled_hover_unfocused_color;
1296     theme->a_toggled_focused_unpressed_max->texture[0].data.mask.color =
1297         theme->a_toggled_focused_unpressed_desk->texture[0].data.mask.color =
1298         theme->a_toggled_focused_unpressed_shade->texture[0].data.mask.color =
1299         theme->titlebut_toggled_focused_unpressed_color;
1300     theme->a_toggled_unfocused_unpressed_max->texture[0].data.mask.color =
1301         theme->a_toggled_unfocused_unpressed_desk->texture[0].data.mask.color =
1302         theme->a_toggled_unfocused_unpressed_shade->texture[0].data.mask.color=
1303         theme->titlebut_toggled_unfocused_unpressed_color;
1304     theme->a_toggled_focused_pressed_max->texture[0].data.mask.color =
1305         theme->a_toggled_focused_pressed_desk->texture[0].data.mask.color =
1306         theme->a_toggled_focused_pressed_shade->texture[0].data.mask.color =
1307         theme->titlebut_toggled_focused_pressed_color;
1308     theme->a_toggled_unfocused_pressed_max->texture[0].data.mask.color =
1309         theme->a_toggled_unfocused_pressed_desk->texture[0].data.mask.color =
1310         theme->a_toggled_unfocused_pressed_shade->texture[0].data.mask.color =
1311         theme->titlebut_toggled_unfocused_pressed_color;
1312     theme->a_focused_unpressed_max->texture[0].data.mask.color =
1313         theme->a_focused_unpressed_close->texture[0].data.mask.color =
1314         theme->a_focused_unpressed_desk->texture[0].data.mask.color =
1315         theme->a_focused_unpressed_shade->texture[0].data.mask.color =
1316         theme->a_focused_unpressed_iconify->texture[0].data.mask.color =
1317         theme->titlebut_focused_unpressed_color;
1318     theme->a_focused_pressed_max->texture[0].data.mask.color =
1319         theme->a_focused_pressed_close->texture[0].data.mask.color =
1320         theme->a_focused_pressed_desk->texture[0].data.mask.color =
1321         theme->a_focused_pressed_shade->texture[0].data.mask.color =
1322         theme->a_focused_pressed_iconify->texture[0].data.mask.color =
1323         theme->titlebut_focused_pressed_color;
1324     theme->a_unfocused_unpressed_max->texture[0].data.mask.color =
1325         theme->a_unfocused_unpressed_close->texture[0].data.mask.color =
1326         theme->a_unfocused_unpressed_desk->texture[0].data.mask.color =
1327         theme->a_unfocused_unpressed_shade->texture[0].data.mask.color =
1328         theme->a_unfocused_unpressed_iconify->texture[0].data.mask.color =
1329         theme->titlebut_unfocused_unpressed_color;
1330     theme->a_unfocused_pressed_max->texture[0].data.mask.color =
1331         theme->a_unfocused_pressed_close->texture[0].data.mask.color =
1332         theme->a_unfocused_pressed_desk->texture[0].data.mask.color =
1333         theme->a_unfocused_pressed_shade->texture[0].data.mask.color =
1334         theme->a_unfocused_pressed_iconify->texture[0].data.mask.color =
1335         theme->titlebut_unfocused_pressed_color;
1336     theme->a_menu_bullet_normal->texture[0].data.mask.color =
1337         theme->menu_color;
1338     theme->a_menu_bullet_selected->texture[0].data.mask.color =
1339         theme->menu_selected_color;
1340
1341     g_free(path);
1342     XrmDestroyDatabase(db);
1343
1344     /* set the font heights */
1345     theme->win_font_height = RrFontHeight
1346         (theme->win_font_focused,
1347          theme->a_focused_label->texture[0].data.text.shadow_offset_y);
1348     theme->win_font_height =
1349         MAX(theme->win_font_height,
1350             RrFontHeight
1351             (theme->win_font_focused,
1352              theme->a_unfocused_label->texture[0].data.text.shadow_offset_y));
1353     theme->menu_title_font_height = RrFontHeight
1354         (theme->menu_title_font,
1355          theme->a_menu_text_title->texture[0].data.text.shadow_offset_y);
1356     theme->menu_font_height = RrFontHeight
1357         (theme->menu_font,
1358          theme->a_menu_text_normal->texture[0].data.text.shadow_offset_y);
1359
1360     /* calculate some last extents */
1361     {
1362         gint ft, fb, fl, fr, ut, ub, ul, ur;
1363
1364         RrMargins(theme->a_focused_label, &fl, &ft, &fr, &fb);
1365         RrMargins(theme->a_unfocused_label, &ul, &ut, &ur, &ub);
1366         theme->label_height = theme->win_font_height + MAX(ft + fb, ut + ub);
1367         theme->label_height += theme->label_height % 2;
1368
1369         /* this would be nice I think, since padding.width can now be 0,
1370            but it breaks frame.c horribly and I don't feel like fixing that
1371            right now, so if anyone complains, here is how to keep text from
1372            going over the title's bevel/border with a padding.width of 0 and a
1373            bevelless/borderless label
1374            RrMargins(theme->a_focused_title, &fl, &ft, &fr, &fb);
1375            RrMargins(theme->a_unfocused_title, &ul, &ut, &ur, &ub);
1376            theme->title_height = theme->label_height +
1377            MAX(MAX(theme->padding * 2, ft + fb),
1378            MAX(theme->padding * 2, ut + ub));
1379         */
1380         theme->title_height = theme->label_height + theme->paddingy * 2;
1381
1382         RrMargins(theme->a_menu_title, &ul, &ut, &ur, &ub);
1383         theme->menu_title_label_height = theme->menu_title_font_height+ut+ub;
1384         theme->menu_title_height = theme->menu_title_label_height +
1385             theme->paddingy * 2;
1386     }
1387     theme->button_size = theme->label_height - 2;
1388     theme->grip_width = 25;
1389
1390     return theme;
1391 }
1392
1393 void RrThemeFree(RrTheme *theme)
1394 {
1395     if (theme) {
1396         g_free(theme->name);
1397
1398         RrColorFree(theme->menu_border_color);
1399         RrColorFree(theme->osd_border_color);
1400         RrColorFree(theme->frame_focused_border_color);
1401         RrColorFree(theme->frame_unfocused_border_color);
1402         RrColorFree(theme->title_separator_focused_color);
1403         RrColorFree(theme->title_separator_unfocused_color);
1404         RrColorFree(theme->cb_unfocused_color);
1405         RrColorFree(theme->cb_focused_color);
1406         RrColorFree(theme->title_focused_color);
1407         RrColorFree(theme->title_unfocused_color);
1408         RrColorFree(theme->titlebut_disabled_focused_color);
1409         RrColorFree(theme->titlebut_disabled_unfocused_color);
1410         RrColorFree(theme->titlebut_hover_focused_color);
1411         RrColorFree(theme->titlebut_hover_unfocused_color);
1412         RrColorFree(theme->titlebut_toggled_hover_focused_color);
1413         RrColorFree(theme->titlebut_toggled_hover_unfocused_color);
1414         RrColorFree(theme->titlebut_toggled_focused_pressed_color);
1415         RrColorFree(theme->titlebut_toggled_unfocused_pressed_color);
1416         RrColorFree(theme->titlebut_toggled_focused_unpressed_color);
1417         RrColorFree(theme->titlebut_toggled_unfocused_unpressed_color);
1418         RrColorFree(theme->titlebut_focused_pressed_color);
1419         RrColorFree(theme->titlebut_unfocused_pressed_color);
1420         RrColorFree(theme->titlebut_focused_unpressed_color);
1421         RrColorFree(theme->titlebut_unfocused_unpressed_color);
1422         RrColorFree(theme->menu_title_color);
1423         RrColorFree(theme->menu_sep_color);
1424         RrColorFree(theme->menu_color);
1425         RrColorFree(theme->menu_selected_color);
1426         RrColorFree(theme->menu_disabled_color);
1427         RrColorFree(theme->menu_disabled_selected_color);
1428         RrColorFree(theme->title_focused_shadow_color);
1429         RrColorFree(theme->title_unfocused_shadow_color);
1430         RrColorFree(theme->osd_color);
1431         RrColorFree(theme->osd_shadow_color);
1432         RrColorFree(theme->menu_title_shadow_color);
1433         RrColorFree(theme->menu_text_normal_shadow_color);
1434         RrColorFree(theme->menu_text_selected_shadow_color);
1435         RrColorFree(theme->menu_text_disabled_shadow_color);
1436         RrColorFree(theme->menu_text_disabled_selected_shadow_color);
1437
1438         g_free(theme->def_win_icon);
1439
1440         RrPixmapMaskFree(theme->max_mask);
1441         RrPixmapMaskFree(theme->max_toggled_mask);
1442         RrPixmapMaskFree(theme->max_toggled_hover_mask);
1443         RrPixmapMaskFree(theme->max_toggled_pressed_mask);
1444         RrPixmapMaskFree(theme->max_disabled_mask);
1445         RrPixmapMaskFree(theme->max_hover_mask);
1446         RrPixmapMaskFree(theme->max_pressed_mask);
1447         RrPixmapMaskFree(theme->desk_mask);
1448         RrPixmapMaskFree(theme->desk_toggled_mask);
1449         RrPixmapMaskFree(theme->desk_toggled_hover_mask);
1450         RrPixmapMaskFree(theme->desk_toggled_pressed_mask);
1451         RrPixmapMaskFree(theme->desk_disabled_mask);
1452         RrPixmapMaskFree(theme->desk_hover_mask);
1453         RrPixmapMaskFree(theme->desk_pressed_mask);
1454         RrPixmapMaskFree(theme->shade_mask);
1455         RrPixmapMaskFree(theme->shade_toggled_mask);
1456         RrPixmapMaskFree(theme->shade_toggled_hover_mask);
1457         RrPixmapMaskFree(theme->shade_toggled_pressed_mask);
1458         RrPixmapMaskFree(theme->shade_disabled_mask);
1459         RrPixmapMaskFree(theme->shade_hover_mask);
1460         RrPixmapMaskFree(theme->shade_pressed_mask);
1461         RrPixmapMaskFree(theme->iconify_mask);
1462         RrPixmapMaskFree(theme->iconify_disabled_mask);
1463         RrPixmapMaskFree(theme->iconify_hover_mask);
1464         RrPixmapMaskFree(theme->iconify_pressed_mask);
1465         RrPixmapMaskFree(theme->close_mask);
1466         RrPixmapMaskFree(theme->close_disabled_mask);
1467         RrPixmapMaskFree(theme->close_hover_mask);
1468         RrPixmapMaskFree(theme->close_pressed_mask);
1469         RrPixmapMaskFree(theme->menu_bullet_mask);
1470
1471         RrFontClose(theme->win_font_focused);
1472         RrFontClose(theme->win_font_unfocused);
1473         RrFontClose(theme->menu_title_font);
1474         RrFontClose(theme->menu_font);
1475         RrFontClose(theme->osd_font);
1476
1477         RrAppearanceFree(theme->a_disabled_focused_max);
1478         RrAppearanceFree(theme->a_disabled_unfocused_max);
1479         RrAppearanceFree(theme->a_hover_focused_max);
1480         RrAppearanceFree(theme->a_hover_unfocused_max);
1481         RrAppearanceFree(theme->a_toggled_hover_focused_max);
1482         RrAppearanceFree(theme->a_toggled_hover_unfocused_max);
1483         RrAppearanceFree(theme->a_toggled_focused_unpressed_max);
1484         RrAppearanceFree(theme->a_toggled_focused_pressed_max);
1485         RrAppearanceFree(theme->a_toggled_unfocused_unpressed_max);
1486         RrAppearanceFree(theme->a_toggled_unfocused_pressed_max);
1487         RrAppearanceFree(theme->a_focused_unpressed_max);
1488         RrAppearanceFree(theme->a_focused_pressed_max);
1489         RrAppearanceFree(theme->a_unfocused_unpressed_max);
1490         RrAppearanceFree(theme->a_unfocused_pressed_max);
1491         RrAppearanceFree(theme->a_disabled_focused_close);
1492         RrAppearanceFree(theme->a_disabled_unfocused_close);
1493         RrAppearanceFree(theme->a_hover_focused_close);
1494         RrAppearanceFree(theme->a_hover_unfocused_close);
1495         RrAppearanceFree(theme->a_focused_unpressed_close);
1496         RrAppearanceFree(theme->a_focused_pressed_close);
1497         RrAppearanceFree(theme->a_unfocused_unpressed_close);
1498         RrAppearanceFree(theme->a_unfocused_pressed_close);
1499         RrAppearanceFree(theme->a_disabled_focused_desk);
1500         RrAppearanceFree(theme->a_disabled_unfocused_desk);
1501         RrAppearanceFree(theme->a_hover_focused_desk);
1502         RrAppearanceFree(theme->a_hover_unfocused_desk);
1503         RrAppearanceFree(theme->a_toggled_hover_focused_desk);
1504         RrAppearanceFree(theme->a_toggled_hover_unfocused_desk);
1505         RrAppearanceFree(theme->a_toggled_focused_unpressed_desk);
1506         RrAppearanceFree(theme->a_toggled_focused_pressed_desk);
1507         RrAppearanceFree(theme->a_toggled_unfocused_unpressed_desk);
1508         RrAppearanceFree(theme->a_toggled_unfocused_pressed_desk);
1509         RrAppearanceFree(theme->a_focused_unpressed_desk);
1510         RrAppearanceFree(theme->a_focused_pressed_desk);
1511         RrAppearanceFree(theme->a_unfocused_unpressed_desk);
1512         RrAppearanceFree(theme->a_unfocused_pressed_desk);
1513         RrAppearanceFree(theme->a_disabled_focused_shade);
1514         RrAppearanceFree(theme->a_disabled_unfocused_shade);
1515         RrAppearanceFree(theme->a_hover_focused_shade);
1516         RrAppearanceFree(theme->a_hover_unfocused_shade);
1517         RrAppearanceFree(theme->a_toggled_hover_focused_shade);
1518         RrAppearanceFree(theme->a_toggled_hover_unfocused_shade);
1519         RrAppearanceFree(theme->a_toggled_focused_unpressed_shade);
1520         RrAppearanceFree(theme->a_toggled_focused_pressed_shade);
1521         RrAppearanceFree(theme->a_toggled_unfocused_unpressed_shade);
1522         RrAppearanceFree(theme->a_toggled_unfocused_pressed_shade);
1523         RrAppearanceFree(theme->a_focused_unpressed_shade);
1524         RrAppearanceFree(theme->a_focused_pressed_shade);
1525         RrAppearanceFree(theme->a_unfocused_unpressed_shade);
1526         RrAppearanceFree(theme->a_unfocused_pressed_shade);
1527         RrAppearanceFree(theme->a_disabled_focused_iconify);
1528         RrAppearanceFree(theme->a_disabled_unfocused_iconify);
1529         RrAppearanceFree(theme->a_hover_focused_iconify);
1530         RrAppearanceFree(theme->a_hover_unfocused_iconify);
1531         RrAppearanceFree(theme->a_focused_unpressed_iconify);
1532         RrAppearanceFree(theme->a_focused_pressed_iconify);
1533         RrAppearanceFree(theme->a_unfocused_unpressed_iconify);
1534         RrAppearanceFree(theme->a_unfocused_pressed_iconify);
1535         RrAppearanceFree(theme->a_focused_grip);
1536         RrAppearanceFree(theme->a_unfocused_grip);
1537         RrAppearanceFree(theme->a_focused_title);
1538         RrAppearanceFree(theme->a_unfocused_title);
1539         RrAppearanceFree(theme->a_focused_label);
1540         RrAppearanceFree(theme->a_unfocused_label);
1541         RrAppearanceFree(theme->a_icon);
1542         RrAppearanceFree(theme->a_focused_handle);
1543         RrAppearanceFree(theme->a_unfocused_handle);
1544         RrAppearanceFree(theme->a_menu);
1545         RrAppearanceFree(theme->a_menu_title);
1546         RrAppearanceFree(theme->a_menu_text_title);
1547         RrAppearanceFree(theme->a_menu_normal);
1548         RrAppearanceFree(theme->a_menu_selected);
1549         RrAppearanceFree(theme->a_menu_disabled);
1550         RrAppearanceFree(theme->a_menu_disabled_selected);
1551         RrAppearanceFree(theme->a_menu_text_normal);
1552         RrAppearanceFree(theme->a_menu_text_selected);
1553         RrAppearanceFree(theme->a_menu_text_disabled);
1554         RrAppearanceFree(theme->a_menu_text_disabled_selected);
1555         RrAppearanceFree(theme->a_menu_bullet_normal);
1556         RrAppearanceFree(theme->a_menu_bullet_selected);
1557         RrAppearanceFree(theme->a_clear);
1558         RrAppearanceFree(theme->a_clear_tex);
1559         RrAppearanceFree(theme->osd_hilite_bg);
1560         RrAppearanceFree(theme->osd_hilite_fg);
1561         RrAppearanceFree(theme->osd_hilite_label);
1562         RrAppearanceFree(theme->osd_unhilite_fg);
1563
1564         g_free(theme);
1565     }
1566 }
1567
1568 static XrmDatabase loaddb(const gchar *name, gchar **path)
1569 {
1570     GSList *it;
1571     XrmDatabase db = NULL;
1572     gchar *s;
1573
1574     if (name[0] == '/') {
1575         s = g_build_filename(name, "openbox-3", "themerc", NULL);
1576         if ((db = XrmGetFileDatabase(s)))
1577             *path = g_path_get_dirname(s);
1578         g_free(s);
1579     } else {
1580         /* XXX backwards compatibility, remove me sometime later */
1581         s = g_build_filename(g_get_home_dir(), ".themes", name,
1582                              "openbox-3", "themerc", NULL);
1583         if ((db = XrmGetFileDatabase(s)))
1584             *path = g_path_get_dirname(s);
1585         g_free(s);
1586
1587         for (it = parse_xdg_data_dir_paths(); !db && it;
1588              it = g_slist_next(it))
1589         {
1590             s = g_build_filename(it->data, "themes", name,
1591                                  "openbox-3", "themerc", NULL);
1592             if ((db = XrmGetFileDatabase(s)))
1593                 *path = g_path_get_dirname(s);
1594             g_free(s);
1595         }
1596     }
1597
1598     if (db == NULL) {
1599         s = g_build_filename(name, "themerc", NULL);
1600         if ((db = XrmGetFileDatabase(s)))
1601             *path = g_path_get_dirname(s);
1602         g_free(s);
1603     }
1604
1605     return db;
1606 }
1607
1608 static gchar *create_class_name(const gchar *rname)
1609 {
1610     gchar *rclass = g_strdup(rname);
1611     gchar *p = rclass;
1612
1613     while (TRUE) {
1614         *p = toupper(*p);
1615         p = strchr(p+1, '.');
1616         if (p == NULL) break;
1617         ++p;
1618         if (*p == '\0') break;
1619     }
1620     return rclass;
1621 }
1622
1623 static gboolean read_int(XrmDatabase db, const gchar *rname, gint *value)
1624 {
1625     gboolean ret = FALSE;
1626     gchar *rclass = create_class_name(rname);
1627     gchar *rettype, *end;
1628     XrmValue retvalue;
1629
1630     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1631         retvalue.addr != NULL) {
1632         *value = (gint)strtol(retvalue.addr, &end, 10);
1633         if (end != retvalue.addr)
1634             ret = TRUE;
1635     }
1636
1637     g_free(rclass);
1638     return ret;
1639 }
1640
1641 static gboolean read_string(XrmDatabase db, const gchar *rname, gchar **value)
1642 {
1643     gboolean ret = FALSE;
1644     gchar *rclass = create_class_name(rname);
1645     gchar *rettype;
1646     XrmValue retvalue;
1647
1648     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1649         retvalue.addr != NULL) {
1650         *value = retvalue.addr;
1651         ret = TRUE;
1652     }
1653
1654     g_free(rclass);
1655     return ret;
1656 }
1657
1658 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
1659                            const gchar *rname, RrColor **value)
1660 {
1661     gboolean ret = FALSE;
1662     gchar *rclass = create_class_name(rname);
1663     gchar *rettype;
1664     XrmValue retvalue;
1665
1666     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1667         retvalue.addr != NULL) {
1668         RrColor *c = RrColorParse(inst, retvalue.addr);
1669         if (c != NULL) {
1670             *value = c;
1671             ret = TRUE;
1672         }
1673     }
1674
1675     g_free(rclass);
1676     return ret;
1677 }
1678
1679 static gboolean read_mask(const RrInstance *inst, const gchar *path,
1680                           RrTheme *theme, const gchar *maskname,
1681                           RrPixmapMask **value)
1682 {
1683     gboolean ret = FALSE;
1684     gchar *s;
1685     gint hx, hy; /* ignored */
1686     guint w, h;
1687     guchar *b;
1688
1689     s = g_build_filename(path, maskname, NULL);
1690     if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess) {
1691         ret = TRUE;
1692         *value = RrPixmapMaskNew(inst, w, h, (gchar*)b);
1693         XFree(b);
1694     }
1695     g_free(s);
1696
1697     return ret;
1698 }
1699
1700 static void parse_appearance(gchar *tex, RrSurfaceColorType *grad,
1701                              RrReliefType *relief, RrBevelType *bevel,
1702                              gboolean *interlaced, gboolean *border,
1703                              gboolean allow_trans)
1704 {
1705     gchar *t;
1706
1707     /* convert to all lowercase */
1708     for (t = tex; *t != '\0'; ++t)
1709         *t = g_ascii_tolower(*t);
1710
1711     if (allow_trans && strstr(tex, "parentrelative") != NULL) {
1712         *grad = RR_SURFACE_PARENTREL;
1713     } else {
1714         if (strstr(tex, "gradient") != NULL) {
1715             if (strstr(tex, "crossdiagonal") != NULL)
1716                 *grad = RR_SURFACE_CROSS_DIAGONAL;
1717             else if (strstr(tex, "pyramid") != NULL)
1718                 *grad = RR_SURFACE_PYRAMID;
1719             else if (strstr(tex, "mirrorhorizontal") != NULL)
1720                 *grad = RR_SURFACE_MIRROR_HORIZONTAL;
1721             else if (strstr(tex, "horizontal") != NULL)
1722                 *grad = RR_SURFACE_HORIZONTAL;
1723             else if (strstr(tex, "splitvertical") != NULL)
1724                 *grad = RR_SURFACE_SPLIT_VERTICAL;
1725             else if (strstr(tex, "vertical") != NULL)
1726                 *grad = RR_SURFACE_VERTICAL;
1727             else
1728                 *grad = RR_SURFACE_DIAGONAL;
1729         } else {
1730             *grad = RR_SURFACE_SOLID;
1731         }
1732     }
1733
1734     if (strstr(tex, "sunken") != NULL)
1735         *relief = RR_RELIEF_SUNKEN;
1736     else if (strstr(tex, "flat") != NULL)
1737         *relief = RR_RELIEF_FLAT;
1738     else if (strstr(tex, "raised") != NULL)
1739         *relief = RR_RELIEF_RAISED;
1740     else
1741         *relief = (*grad == RR_SURFACE_PARENTREL) ?
1742                   RR_RELIEF_FLAT : RR_RELIEF_RAISED;
1743
1744     *border = FALSE;
1745     if (*relief == RR_RELIEF_FLAT) {
1746         if (strstr(tex, "border") != NULL)
1747             *border = TRUE;
1748     } else {
1749         if (strstr(tex, "bevel2") != NULL)
1750             *bevel = RR_BEVEL_2;
1751         else
1752             *bevel = RR_BEVEL_1;
1753     }
1754
1755     if (strstr(tex, "interlaced") != NULL)
1756         *interlaced = TRUE;
1757     else
1758         *interlaced = FALSE;
1759 }
1760
1761 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
1762                                 const gchar *rname, RrAppearance *value,
1763                                 gboolean allow_trans)
1764 {
1765     gboolean ret = FALSE;
1766     gchar *rclass = create_class_name(rname);
1767     gchar *cname, *ctoname, *bcname, *icname, *hname, *sname;
1768     gchar *csplitname, *ctosplitname;
1769     gchar *rettype;
1770     XrmValue retvalue;
1771     gint i;
1772
1773     cname = g_strconcat(rname, ".color", NULL);
1774     ctoname = g_strconcat(rname, ".colorTo", NULL);
1775     bcname = g_strconcat(rname, ".border.color", NULL);
1776     icname = g_strconcat(rname, ".interlace.color", NULL);
1777     hname = g_strconcat(rname, ".highlight", NULL);
1778     sname = g_strconcat(rname, ".shadow", NULL);
1779     csplitname = g_strconcat(rname, ".color.splitTo", NULL);
1780     ctosplitname = g_strconcat(rname, ".colorTo.splitTo", NULL);
1781
1782     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1783         retvalue.addr != NULL) {
1784         parse_appearance(retvalue.addr,
1785                          &value->surface.grad,
1786                          &value->surface.relief,
1787                          &value->surface.bevel,
1788                          &value->surface.interlaced,
1789                          &value->surface.border,
1790                          allow_trans);
1791         if (!read_color(db, inst, cname, &value->surface.primary))
1792             value->surface.primary = RrColorNew(inst, 0, 0, 0);
1793         if (!read_color(db, inst, ctoname, &value->surface.secondary))
1794             value->surface.secondary = RrColorNew(inst, 0, 0, 0);
1795         if (value->surface.border)
1796             if (!read_color(db, inst, bcname,
1797                             &value->surface.border_color))
1798                 value->surface.border_color = RrColorNew(inst, 0, 0, 0);
1799         if (value->surface.interlaced)
1800             if (!read_color(db, inst, icname,
1801                             &value->surface.interlace_color))
1802                 value->surface.interlace_color = RrColorNew(inst, 0, 0, 0);
1803         if (read_int(db, hname, &i) && i >= 0)
1804             value->surface.bevel_light_adjust = i;
1805         if (read_int(db, sname, &i) && i >= 0 && i <= 256)
1806             value->surface.bevel_dark_adjust = i;
1807
1808         if (value->surface.grad == RR_SURFACE_SPLIT_VERTICAL) {
1809             gint r, g, b;
1810
1811             if (!read_color(db, inst, csplitname,
1812                             &value->surface.split_primary))
1813             {
1814                 r = value->surface.primary->r;
1815                 r += r >> 2;
1816                 g = value->surface.primary->g;
1817                 g += g >> 2;
1818                 b = value->surface.primary->b;
1819                 b += b >> 2;
1820                 if (r > 0xFF) r = 0xFF;
1821                 if (g > 0xFF) g = 0xFF;
1822                 if (b > 0xFF) b = 0xFF;
1823                 value->surface.split_primary = RrColorNew(inst, r, g, b);
1824             }
1825
1826             if (!read_color(db, inst, ctosplitname,
1827                             &value->surface.split_secondary))
1828             {
1829                 r = value->surface.secondary->r;
1830                 r += r >> 4;
1831                 g = value->surface.secondary->g;
1832                 g += g >> 4;
1833                 b = value->surface.secondary->b;
1834                 b += b >> 4;
1835                 if (r > 0xFF) r = 0xFF;
1836                 if (g > 0xFF) g = 0xFF;
1837                 if (b > 0xFF) b = 0xFF;
1838                 value->surface.split_secondary = RrColorNew(inst, r, g, b);
1839             }
1840         }
1841
1842         ret = TRUE;
1843     }
1844
1845     g_free(ctosplitname);
1846     g_free(csplitname);
1847     g_free(sname);
1848     g_free(hname);
1849     g_free(icname);
1850     g_free(bcname);
1851     g_free(ctoname);
1852     g_free(cname);
1853     g_free(rclass);
1854     return ret;
1855 }
1856
1857 static int parse_inline_number(const char *p)
1858 {
1859     int neg = 1;
1860     int res = 0;
1861     if (*p == '-') {
1862         neg = -1;
1863         ++p;
1864     }
1865     for (; isdigit(*p); ++p)
1866         res = res * 10 + *p - '0';
1867     res *= neg;
1868     return res;
1869 }
1870
1871 static void set_default_appearance(RrAppearance *a)
1872 {
1873     a->surface.grad = RR_SURFACE_SOLID;
1874     a->surface.relief = RR_RELIEF_FLAT;
1875     a->surface.bevel = RR_BEVEL_1;
1876     a->surface.interlaced = FALSE;
1877     a->surface.border = FALSE;
1878     a->surface.primary = RrColorNew(a->inst, 0, 0, 0);
1879     a->surface.secondary = RrColorNew(a->inst, 0, 0, 0);
1880 }
1881
1882 /* Reads the output from gimp's C-Source file format into valid RGBA data for
1883    an RrTextureRGBA. */
1884 static RrPixel32* read_c_image(gint width, gint height, const guint8 *data)
1885 {
1886     RrPixel32 *im, *p;
1887     gint i;
1888
1889     p = im = g_memdup(data, width * height * sizeof(RrPixel32));
1890
1891     for (i = 0; i < width * height; ++i) {
1892         guchar a = ((*p >> 24) & 0xff);
1893         guchar b = ((*p >> 16) & 0xff);
1894         guchar g = ((*p >>  8) & 0xff);
1895         guchar r = ((*p >>  0) & 0xff);
1896
1897         *p = ((r << RrDefaultRedOffset) +
1898               (g << RrDefaultGreenOffset) +
1899               (b << RrDefaultBlueOffset) +
1900               (a << RrDefaultAlphaOffset));
1901         p++;
1902     }
1903
1904     return im;
1905 }