move the titlebar layout from the theme to the rc file
[dana/openbox.git] / render / theme.c
1 #include "render.h"
2 #include "color.h"
3 #include "font.h"
4 #include "mask.h"
5 #include "theme.h"
6
7 #include <X11/Xlib.h>
8 #include <X11/Xresource.h>
9
10 static XrmDatabase loaddb(RrTheme *theme, char *name);
11 static gboolean read_int(XrmDatabase db, char *rname, int *value);
12 static gboolean read_string(XrmDatabase db, char *rname, char **value);
13 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
14                            gchar *rname, RrColor **value);
15 static gboolean read_mask(const RrInstance *inst,
16                           gchar *maskname, RrTheme *theme,
17                           RrPixmapMask **value);
18 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
19                                 gchar *rname, RrAppearance *value,
20                                 gboolean allow_trans);
21 static void set_default_appearance(RrAppearance *a);
22
23 RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
24 {
25     XrmDatabase db = NULL;
26     RrJustify winjust, mtitlejust, mjust;
27     gchar *str;
28     gchar *font_str;
29     RrTheme *theme;
30
31     theme = g_new0(RrTheme, 1);
32
33     theme->inst = inst;
34
35     theme->a_disabled_focused_max = RrAppearanceNew(inst, 1);
36     theme->a_disabled_unfocused_max = RrAppearanceNew(inst, 1);
37     theme->a_hover_focused_max = RrAppearanceNew(inst, 1);
38     theme->a_hover_unfocused_max = RrAppearanceNew(inst, 1);
39     theme->a_focused_unpressed_max = RrAppearanceNew(inst, 1);
40     theme->a_focused_pressed_max = RrAppearanceNew(inst, 1);
41     theme->a_focused_pressed_set_max = RrAppearanceNew(inst, 1);
42     theme->a_unfocused_unpressed_max = RrAppearanceNew(inst, 1);
43     theme->a_unfocused_pressed_max = RrAppearanceNew(inst, 1);
44     theme->a_unfocused_pressed_set_max = RrAppearanceNew(inst, 1);
45     theme->a_focused_grip = RrAppearanceNew(inst, 0);
46     theme->a_unfocused_grip = RrAppearanceNew(inst, 0);
47     theme->a_focused_title = RrAppearanceNew(inst, 0);
48     theme->a_unfocused_title = RrAppearanceNew(inst, 0);
49     theme->a_focused_label = RrAppearanceNew(inst, 1);
50     theme->a_unfocused_label = RrAppearanceNew(inst, 1);
51     theme->a_icon = RrAppearanceNew(inst, 1);
52     theme->a_focused_handle = RrAppearanceNew(inst, 0);
53     theme->a_unfocused_handle = RrAppearanceNew(inst, 0);
54     theme->a_menu = RrAppearanceNew(inst, 0);
55     theme->a_menu_title = RrAppearanceNew(inst, 1);
56     theme->a_menu_item = RrAppearanceNew(inst, 1);
57     theme->a_menu_disabled = RrAppearanceNew(inst, 1);
58     theme->a_menu_hilite = RrAppearanceNew(inst, 1);
59
60     theme->app_hilite_bg = RrAppearanceNew(inst, 0);
61     theme->app_unhilite_bg = RrAppearanceNew(inst, 0);
62     theme->app_hilite_label = RrAppearanceNew(inst, 1);
63     theme->app_unhilite_label = RrAppearanceNew(inst, 1);
64     theme->app_icon = RrAppearanceNew(inst, 1);
65
66     if (name) {
67         db = loaddb(theme, name);
68         if (db == NULL) {
69             g_warning("Failed to load the theme '%s'\n"
70                       "Falling back to the default: '%s'",
71                       name, DEFAULT_THEME);
72         } else
73             theme->name = g_path_get_basename(name);
74     }
75     if (db == NULL) {
76         db = loaddb(theme, DEFAULT_THEME);
77         if (db == NULL) {
78             g_warning("Failed to load the theme '%s'.", DEFAULT_THEME);
79             return NULL;
80         } else
81             theme->name = g_path_get_basename(DEFAULT_THEME);
82     }
83
84     /* load the font stuff */
85     if (!read_string(db, "window.title.xftfont", &font_str))
86         font_str = "arial,sans:bold:pixelsize=10:shadow=y:shadowtint=50";
87
88     if (!(theme->winfont = RrFontOpen(inst, font_str))) {
89         RrThemeFree(theme);
90         return NULL;
91     }
92     theme->winfont_height = RrFontHeight(theme->winfont);
93
94     winjust = RR_JUSTIFY_LEFT;
95     if (read_string(db, "window.justify", &str)) {
96         if (!g_ascii_strcasecmp(str, "right"))
97             winjust = RR_JUSTIFY_RIGHT;
98         else if (!g_ascii_strcasecmp(str, "center"))
99             winjust = RR_JUSTIFY_CENTER;
100     }
101
102     if (!read_string(db, "menu.title.xftfont", &font_str))
103         font_str = "arial,sans:bold:pixelsize=12:shadow=y";
104
105     if (!(theme->mtitlefont = RrFontOpen(inst, font_str))) {
106         RrThemeFree(theme);
107         return NULL;
108     }
109     theme->mtitlefont_height = RrFontHeight(theme->mtitlefont);
110
111     mtitlejust = RR_JUSTIFY_LEFT;
112     if (read_string(db, "menu.title.justify", &str)) {
113         if (!g_ascii_strcasecmp(str, "right"))
114             mtitlejust = RR_JUSTIFY_RIGHT;
115         else if (!g_ascii_strcasecmp(str, "center"))
116             mtitlejust = RR_JUSTIFY_CENTER;
117     }
118
119     if (!read_string(db, "menu.frame.xftfont", &font_str))
120         font_str = "arial,sans:bold:pixelsize=11:shadow=y";
121
122     if (!(theme->mfont = RrFontOpen(inst, font_str))) {
123         RrThemeFree(theme);
124         return NULL;
125     }
126     theme->mfont_height = RrFontHeight(theme->mfont);
127
128     mjust = RR_JUSTIFY_LEFT;
129     if (read_string(db, "menu.frame.justify", &str)) {
130         if (!g_ascii_strcasecmp(str, "right"))
131             mjust = RR_JUSTIFY_RIGHT;
132         else if (!g_ascii_strcasecmp(str, "center"))
133             mjust = RR_JUSTIFY_CENTER;
134     }
135
136     /* load direct dimensions */
137     if (!read_int(db, "menuOverlap", &theme->menu_overlap) ||
138         theme->menu_overlap < 0 || theme->menu_overlap > 20)
139         theme->handle_height = 0;
140     if (!read_int(db, "handleWidth", &theme->handle_height) ||
141         theme->handle_height < 0 || theme->handle_height > 100)
142         theme->handle_height = 6;
143     if (!read_int(db, "bevelWidth", &theme->bevel) ||
144         theme->bevel <= 0 || theme->bevel > 100) theme->bevel = 3;
145     if (!read_int(db, "borderWidth", &theme->bwidth) ||
146         theme->bwidth < 0 || theme->bwidth > 100) theme->bwidth = 1;
147     if (!read_int(db, "frameWidth", &theme->cbwidth) ||
148         theme->cbwidth < 0 || theme->cbwidth > 100)
149         theme->cbwidth = theme->bevel;
150
151     /* load colors */
152     if (!read_color(db, inst,
153                     "borderColor", &theme->b_color))
154         theme->b_color = RrColorNew(inst, 0, 0, 0);
155     if (!read_color(db, inst,
156                     "window.frame.focusColor", &theme->cb_focused_color))
157         theme->cb_focused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
158     if (!read_color(db, inst,
159                     "window.frame.unfocusColor",&theme->cb_unfocused_color))
160         theme->cb_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
161     if (!read_color(db, inst,
162                     "window.label.focus.textColor",
163                     &theme->title_focused_color))
164         theme->title_focused_color = RrColorNew(inst, 0x0, 0x0, 0x0);
165     if (!read_color(db, inst,
166                     "window.label.unfocus.textColor",
167                     &theme->title_unfocused_color))
168         theme->title_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
169     if (!read_color(db, inst,
170                     "window.button.focus.picColor",
171                     &theme->titlebut_focused_unpressed_color))
172         theme->titlebut_focused_unpressed_color = RrColorNew(inst, 0, 0, 0);
173     if (!read_color(db, inst,
174                     "window.button.unfocus.picColor",
175                     &theme->titlebut_unfocused_unpressed_color))
176         theme->titlebut_unfocused_unpressed_color =
177             RrColorNew(inst, 0xff, 0xff, 0xff);
178     if (!read_color(db, inst,
179                     "window.button.pressed.focus.picColor",
180                     &theme->titlebut_focused_pressed_color))
181         theme->titlebut_focused_pressed_color =
182             RrColorNew(inst,
183                        theme->titlebut_focused_unpressed_color->r,
184                        theme->titlebut_focused_unpressed_color->g,
185                        theme->titlebut_focused_unpressed_color->b);
186     if (!read_color(db, inst,
187                     "window.button.pressed.unfocus.picColor",
188                     &theme->titlebut_unfocused_pressed_color))
189         theme->titlebut_unfocused_pressed_color =
190             RrColorNew(inst,
191                        theme->titlebut_unfocused_unpressed_color->r,
192                        theme->titlebut_unfocused_unpressed_color->g,
193                        theme->titlebut_unfocused_unpressed_color->b);
194     if (!read_color(db, inst,
195                     "window.button.disabled.focus.picColor",
196                     &theme->titlebut_disabled_focused_color))
197         theme->titlebut_disabled_focused_color =
198             RrColorNew(inst, 0xff, 0xff, 0xff);
199     if (!read_color(db, inst,
200                     "window.button.disabled.unfocus.picColor",
201                     &theme->titlebut_disabled_unfocused_color))
202         theme->titlebut_disabled_unfocused_color = RrColorNew(inst, 0, 0, 0);
203     if (!read_color(db, inst,
204                     "window.button.hover.focus.picColor",
205                     &theme->titlebut_hover_focused_color))
206         theme->titlebut_hover_focused_color =
207             RrColorNew(inst,
208                        theme->titlebut_focused_unpressed_color->r,
209                        theme->titlebut_focused_unpressed_color->g,
210                        theme->titlebut_focused_unpressed_color->b);
211     if (!read_color(db, inst,
212                     "window.button.hover.unfocus.picColor",
213                     &theme->titlebut_hover_unfocused_color))
214         theme->titlebut_hover_unfocused_color =
215             RrColorNew(inst,
216                        theme->titlebut_unfocused_unpressed_color->r,
217                        theme->titlebut_unfocused_unpressed_color->g,
218                        theme->titlebut_unfocused_unpressed_color->b);
219     if (!read_color(db, inst,
220                     "menu.title.textColor", &theme->menu_title_color))
221         theme->menu_title_color = RrColorNew(inst, 0, 0, 0);
222     if (!read_color(db, inst,
223                     "menu.frame.textColor", &theme->menu_color))
224         theme->menu_color = RrColorNew(inst, 0xff, 0xff, 0xff);
225     if (!read_color(db, inst,
226                     "menu.frame.disableColor", &theme->menu_disabled_color))
227         theme->menu_disabled_color = RrColorNew(inst, 0, 0, 0);
228     if (!read_color(db, inst,
229                     "menu.hilite.textColor", &theme->menu_hilite_color))
230         theme->menu_hilite_color = RrColorNew(inst, 0, 0, 0);
231
232     if (read_mask(inst, "max.xbm", theme, &theme->max_unset_mask)){
233         if (!read_mask(inst, "max_t.xbm", theme, &theme->max_set_mask)) {
234             theme->max_set_mask = RrPixmapMaskCopy(theme->max_unset_mask);
235         }
236     } else {
237         {
238             char data[] = { 0x7f, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x7f };
239             theme->max_unset_mask = RrPixmapMaskNew(inst, 7, 7, data);
240         }
241         {
242             char data[] = { 0x7c, 0x44, 0x47, 0x47, 0x7f, 0x1f, 0x1f };
243             theme->max_set_mask = RrPixmapMaskNew(inst, 7, 7, data);
244         }
245     }
246
247     if (!read_mask(inst, "iconify.xbm", theme, &theme->iconify_mask)) {
248         char data[] = { 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x7f };
249         theme->iconify_mask = RrPixmapMaskNew(inst, 7, 7, data);
250     }
251
252     if (read_mask(inst, "stick.xbm", theme, &theme->desk_unset_mask)) {
253         if (!read_mask(inst, "stick_t.xbm", theme, &theme->desk_set_mask)) {
254             theme->desk_set_mask =
255                 RrPixmapMaskCopy(theme->desk_unset_mask);
256         }
257     } else {
258         {
259             char data[] = { 0x63, 0x63, 0x00, 0x00, 0x00, 0x63, 0x63 };
260             theme->desk_unset_mask = RrPixmapMaskNew(inst, 7, 7, data);
261         }
262         {
263             char data[] = { 0x00, 0x36, 0x36, 0x08, 0x36, 0x36, 0x00 };
264             theme->desk_set_mask = RrPixmapMaskNew(inst, 7, 7, data);
265         }
266     }
267
268     if (read_mask(inst, "shade.xbm", theme, &theme->shade_unset_mask)) {
269         if (!read_mask(inst, "shade_t.xbm", theme, &theme->shade_set_mask)) {
270             theme->shade_set_mask =
271                 RrPixmapMaskCopy(theme->shade_unset_mask);
272         }
273     } else {
274         {
275             char data[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00 };
276             theme->shade_unset_mask = RrPixmapMaskNew(inst, 7, 7, data);
277         }
278         {
279             char data[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x7f };
280             theme->shade_set_mask = RrPixmapMaskNew(inst, 7, 7, data);
281         }
282     }
283
284     if (!read_mask(inst, "close.xbm", theme, &theme->close_mask)) {
285         char data[] = { 0x63, 0x77, 0x3e, 0x1c, 0x3e, 0x77, 0x63 };
286         theme->close_mask = RrPixmapMaskNew(inst, 7, 7, data);
287     }        
288
289     /* read the decoration textures */
290     if (!read_appearance(db, inst,
291                          "window.title.focus", theme->a_focused_title,
292                          FALSE))
293         set_default_appearance(theme->a_focused_title);
294     if (!read_appearance(db, inst,
295                          "window.title.unfocus", theme->a_unfocused_title,
296                          FALSE))
297         set_default_appearance(theme->a_unfocused_title);
298     if (!read_appearance(db, inst,
299                          "window.label.focus", theme->a_focused_label,
300                          TRUE))
301         set_default_appearance(theme->a_focused_label);
302     if (!read_appearance(db, inst,
303                          "window.label.unfocus", theme->a_unfocused_label,
304                          TRUE))
305         set_default_appearance(theme->a_unfocused_label);
306     if (!read_appearance(db, inst,
307                          "window.handle.focus", theme->a_focused_handle,
308                          FALSE))
309         set_default_appearance(theme->a_focused_handle);
310     if (!read_appearance(db, inst,
311                          "window.handle.unfocus",theme->a_unfocused_handle,
312                          FALSE))
313         set_default_appearance(theme->a_unfocused_handle);
314     if (!read_appearance(db, inst,
315                          "window.grip.focus", theme->a_focused_grip,
316                          TRUE))
317         set_default_appearance(theme->a_focused_grip);
318     if (!read_appearance(db, inst,
319                          "window.grip.unfocus", theme->a_unfocused_grip,
320                          TRUE))
321         set_default_appearance(theme->a_unfocused_grip);
322     if (!read_appearance(db, inst,
323                          "menu.frame", theme->a_menu,
324                          FALSE))
325         set_default_appearance(theme->a_menu);
326     if (!read_appearance(db, inst,
327                          "menu.title", theme->a_menu_title,
328                          FALSE))
329         set_default_appearance(theme->a_menu_title);
330     if (!read_appearance(db, inst,
331                          "menu.hilite", theme->a_menu_hilite,
332                          TRUE))
333         set_default_appearance(theme->a_menu_hilite);
334
335     /* read the appearances for rendering non-decorations */
336     if (!read_appearance(db, inst,
337                          "window.title.focus", theme->app_hilite_bg,
338                          FALSE))
339         set_default_appearance(theme->app_hilite_bg);
340     if (!read_appearance(db, inst,
341                          "window.label.focus", theme->app_hilite_label,
342                          TRUE))
343         set_default_appearance(theme->app_hilite_label);
344     if (!read_appearance(db, inst,
345                          "window.title.unfocus", theme->app_unhilite_bg,
346                          FALSE))
347         set_default_appearance(theme->app_unhilite_bg);
348     if (!read_appearance(db, inst,
349                          "window.label.unfocus", theme->app_unhilite_label,
350                          TRUE))
351         set_default_appearance(theme->app_unhilite_label);
352
353     /* read buttons textures */
354     if (!read_appearance(db, inst,
355                          "window.button.disabled.focus",
356                          theme->a_disabled_focused_max,
357                          TRUE))
358         set_default_appearance(theme->a_disabled_focused_max);
359     if (!read_appearance(db, inst,
360                          "window.button.disabled.unfocus",
361                          theme->a_disabled_unfocused_max,
362                          TRUE))
363         set_default_appearance(theme->a_disabled_unfocused_max);
364     if (!read_appearance(db, inst,
365                          "window.button.pressed.focus",
366                          theme->a_focused_pressed_max,
367                          TRUE))
368         if (!read_appearance(db, inst,
369                              "window.button.pressed",
370                              theme->a_focused_pressed_max,
371                          TRUE))
372             set_default_appearance(theme->a_focused_pressed_max);
373     if (!read_appearance(db, inst,
374                          "window.button.pressed.unfocus",
375                          theme->a_unfocused_pressed_max,
376                          TRUE))
377         if (!read_appearance(db, inst,
378                              "window.button.pressed",
379                              theme->a_unfocused_pressed_max,
380                              TRUE))
381             set_default_appearance(theme->a_unfocused_pressed_max);
382     if (!read_appearance(db, inst,
383                          "window.button.focus",
384                          theme->a_focused_unpressed_max,
385                          TRUE))
386         set_default_appearance(theme->a_focused_unpressed_max);
387     if (!read_appearance(db, inst,
388                          "window.button.unfocus",
389                          theme->a_unfocused_unpressed_max,
390                          TRUE))
391         set_default_appearance(theme->a_unfocused_unpressed_max);
392     if (!read_appearance(db, inst,
393                          "window.button.hover.focus",
394                          theme->a_hover_focused_max,
395                          TRUE))
396         theme->a_hover_focused_max =
397             RrAppearanceCopy(theme->a_focused_unpressed_max);
398     if (!read_appearance(db, inst,
399                          "window.button.hover.unfocus",
400                          theme->a_hover_unfocused_max,
401                          TRUE))
402         theme->a_hover_unfocused_max =
403             RrAppearanceCopy(theme->a_unfocused_unpressed_max);
404
405     theme->a_disabled_focused_close =
406         RrAppearanceCopy(theme->a_disabled_focused_max);
407     theme->a_disabled_unfocused_close =
408         RrAppearanceCopy(theme->a_disabled_unfocused_max);
409     theme->a_hover_focused_close =
410         RrAppearanceCopy(theme->a_hover_focused_max);
411     theme->a_hover_unfocused_close =
412         RrAppearanceCopy(theme->a_hover_unfocused_max);
413     theme->a_unfocused_unpressed_close =
414         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
415     theme->a_unfocused_pressed_close =
416         RrAppearanceCopy(theme->a_unfocused_pressed_max);
417     theme->a_focused_unpressed_close =
418         RrAppearanceCopy(theme->a_focused_unpressed_max);
419     theme->a_focused_pressed_close =
420         RrAppearanceCopy(theme->a_focused_pressed_max);
421     theme->a_disabled_focused_desk =
422         RrAppearanceCopy(theme->a_disabled_focused_max);
423     theme->a_disabled_unfocused_desk =
424         RrAppearanceCopy(theme->a_disabled_unfocused_max);
425     theme->a_hover_focused_desk =
426         RrAppearanceCopy(theme->a_hover_focused_max);
427     theme->a_hover_unfocused_desk =
428         RrAppearanceCopy(theme->a_hover_unfocused_max);
429     theme->a_unfocused_unpressed_desk =
430         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
431     theme->a_unfocused_pressed_desk =
432         RrAppearanceCopy(theme->a_unfocused_pressed_max);
433     theme->a_unfocused_pressed_set_desk =
434         RrAppearanceCopy(theme->a_unfocused_pressed_max);
435     theme->a_focused_unpressed_desk =
436         RrAppearanceCopy(theme->a_focused_unpressed_max);
437     theme->a_focused_pressed_desk =
438         RrAppearanceCopy(theme->a_focused_pressed_max);
439     theme->a_focused_pressed_set_desk =
440         RrAppearanceCopy(theme->a_focused_pressed_max);
441     theme->a_disabled_focused_shade =
442         RrAppearanceCopy(theme->a_disabled_focused_max);
443     theme->a_disabled_unfocused_shade =
444         RrAppearanceCopy(theme->a_disabled_unfocused_max);
445     theme->a_hover_focused_shade =
446         RrAppearanceCopy(theme->a_hover_focused_max);
447     theme->a_hover_unfocused_shade =
448         RrAppearanceCopy(theme->a_hover_unfocused_max);
449     theme->a_unfocused_unpressed_shade =
450         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
451     theme->a_unfocused_pressed_shade =
452         RrAppearanceCopy(theme->a_unfocused_pressed_max);
453     theme->a_unfocused_pressed_set_shade =
454         RrAppearanceCopy(theme->a_unfocused_pressed_max);
455     theme->a_focused_unpressed_shade =
456         RrAppearanceCopy(theme->a_focused_unpressed_max);
457     theme->a_focused_pressed_shade =
458         RrAppearanceCopy(theme->a_focused_pressed_max);
459     theme->a_focused_pressed_set_shade =
460         RrAppearanceCopy(theme->a_focused_pressed_max);
461     theme->a_disabled_focused_iconify =
462         RrAppearanceCopy(theme->a_disabled_focused_max);
463     theme->a_disabled_unfocused_iconify =
464         RrAppearanceCopy(theme->a_disabled_focused_max);
465     theme->a_hover_focused_iconify =
466         RrAppearanceCopy(theme->a_hover_focused_max);
467     theme->a_hover_unfocused_iconify =
468         RrAppearanceCopy(theme->a_hover_unfocused_max);
469     theme->a_unfocused_unpressed_iconify =
470         RrAppearanceCopy(theme->a_unfocused_unpressed_max);
471     theme->a_unfocused_pressed_iconify =
472         RrAppearanceCopy(theme->a_unfocused_pressed_max);
473     theme->a_focused_unpressed_iconify =
474         RrAppearanceCopy(theme->a_focused_unpressed_max);
475     theme->a_focused_pressed_iconify =
476         RrAppearanceCopy(theme->a_focused_pressed_max);
477     theme->a_unfocused_pressed_set_max =
478         RrAppearanceCopy(theme->a_unfocused_pressed_max);
479     theme->a_focused_pressed_set_max =
480         RrAppearanceCopy(theme->a_focused_pressed_max);
481
482     theme->a_icon->surface.grad = RR_SURFACE_PARENTREL;
483
484     /* set up the textures */
485     theme->a_focused_label->texture[0].type = 
486         theme->app_hilite_label->texture[0].type = RR_TEXTURE_TEXT;
487     theme->a_focused_label->texture[0].data.text.justify = winjust;
488     theme->app_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
489     theme->a_focused_label->texture[0].data.text.font =
490         theme->app_hilite_label->texture[0].data.text.font = theme->winfont;
491     theme->a_focused_label->texture[0].data.text.color =
492         theme->app_hilite_label->texture[0].data.text.color =
493         theme->title_focused_color;
494
495     theme->a_unfocused_label->texture[0].type =
496         theme->app_unhilite_label->texture[0].type = RR_TEXTURE_TEXT;
497     theme->a_unfocused_label->texture[0].data.text.justify = winjust;
498     theme->app_unhilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
499     theme->a_unfocused_label->texture[0].data.text.font =
500         theme->app_unhilite_label->texture[0].data.text.font = theme->winfont;
501     theme->a_unfocused_label->texture[0].data.text.color =
502         theme->app_unhilite_label->texture[0].data.text.color =
503         theme->title_unfocused_color;
504
505     theme->a_menu_title->texture[0].type = RR_TEXTURE_TEXT;
506     theme->a_menu_title->texture[0].data.text.justify = mtitlejust;
507     theme->a_menu_title->texture[0].data.text.font = theme->mtitlefont;
508     theme->a_menu_title->texture[0].data.text.color = theme->menu_title_color;
509
510     theme->a_menu_item->surface.grad = 
511         theme->a_menu_disabled->surface.grad =
512         theme->app_icon->surface.grad = RR_SURFACE_PARENTREL;
513
514     theme->a_menu_item->texture[0].type =
515         theme->a_menu_disabled->texture[0].type = 
516         theme->a_menu_hilite->texture[0].type = RR_TEXTURE_TEXT;
517     theme->a_menu_item->texture[0].data.text.justify = 
518         theme->a_menu_disabled->texture[0].data.text.justify = 
519         theme->a_menu_hilite->texture[0].data.text.justify = mjust;
520     theme->a_menu_item->texture[0].data.text.font =
521         theme->a_menu_disabled->texture[0].data.text.font =
522         theme->a_menu_hilite->texture[0].data.text.font = theme->mfont;
523     theme->a_menu_item->texture[0].data.text.color = theme->menu_color;
524     theme->a_menu_disabled->texture[0].data.text.color =
525         theme->menu_disabled_color;
526     theme->a_menu_hilite->texture[0].data.text.color =
527         theme->menu_hilite_color;
528
529     theme->a_disabled_focused_max->texture[0].type = 
530         theme->a_disabled_unfocused_max->texture[0].type = 
531         theme->a_hover_focused_max->texture[0].type = 
532         theme->a_hover_unfocused_max->texture[0].type = 
533         theme->a_focused_unpressed_max->texture[0].type = 
534         theme->a_focused_pressed_max->texture[0].type = 
535         theme->a_focused_pressed_set_max->texture[0].type =  
536         theme->a_unfocused_unpressed_max->texture[0].type = 
537         theme->a_unfocused_pressed_max->texture[0].type = 
538         theme->a_unfocused_pressed_set_max->texture[0].type = 
539         theme->a_disabled_focused_close->texture[0].type = 
540         theme->a_disabled_unfocused_close->texture[0].type = 
541         theme->a_hover_focused_close->texture[0].type = 
542         theme->a_hover_unfocused_close->texture[0].type = 
543         theme->a_focused_unpressed_close->texture[0].type = 
544         theme->a_focused_pressed_close->texture[0].type = 
545         theme->a_unfocused_unpressed_close->texture[0].type = 
546         theme->a_unfocused_pressed_close->texture[0].type = 
547         theme->a_disabled_focused_desk->texture[0].type = 
548         theme->a_disabled_unfocused_desk->texture[0].type = 
549         theme->a_hover_focused_desk->texture[0].type = 
550         theme->a_hover_unfocused_desk->texture[0].type = 
551         theme->a_focused_unpressed_desk->texture[0].type = 
552         theme->a_focused_pressed_desk->texture[0].type = 
553         theme->a_focused_pressed_set_desk->texture[0].type = 
554         theme->a_unfocused_unpressed_desk->texture[0].type = 
555         theme->a_unfocused_pressed_desk->texture[0].type = 
556         theme->a_unfocused_pressed_set_desk->texture[0].type = 
557         theme->a_disabled_focused_shade->texture[0].type = 
558         theme->a_disabled_unfocused_shade->texture[0].type = 
559         theme->a_hover_focused_shade->texture[0].type = 
560         theme->a_hover_unfocused_shade->texture[0].type = 
561         theme->a_focused_unpressed_shade->texture[0].type = 
562         theme->a_focused_pressed_shade->texture[0].type = 
563         theme->a_focused_pressed_set_shade->texture[0].type = 
564         theme->a_unfocused_unpressed_shade->texture[0].type = 
565         theme->a_unfocused_pressed_shade->texture[0].type = 
566         theme->a_unfocused_pressed_set_shade->texture[0].type = 
567         theme->a_disabled_focused_iconify->texture[0].type = 
568         theme->a_disabled_unfocused_iconify->texture[0].type = 
569         theme->a_hover_focused_iconify->texture[0].type = 
570         theme->a_hover_unfocused_iconify->texture[0].type = 
571         theme->a_focused_unpressed_iconify->texture[0].type = 
572         theme->a_focused_pressed_iconify->texture[0].type = 
573         theme->a_unfocused_unpressed_iconify->texture[0].type = 
574         theme->a_unfocused_pressed_iconify->texture[0].type = RR_TEXTURE_MASK;
575     theme->a_disabled_focused_max->texture[0].data.mask.mask = 
576         theme->a_disabled_unfocused_max->texture[0].data.mask.mask = 
577         theme->a_hover_focused_max->texture[0].data.mask.mask = 
578         theme->a_hover_unfocused_max->texture[0].data.mask.mask = 
579         theme->a_focused_unpressed_max->texture[0].data.mask.mask = 
580         theme->a_unfocused_unpressed_max->texture[0].data.mask.mask = 
581         theme->a_focused_pressed_max->texture[0].data.mask.mask = 
582         theme->a_unfocused_pressed_max->texture[0].data.mask.mask =
583         theme->max_unset_mask;
584     theme->a_focused_pressed_set_max->texture[0].data.mask.mask = 
585         theme->a_unfocused_pressed_set_max->texture[0].data.mask.mask =
586         theme->max_set_mask;
587     theme->a_disabled_focused_close->texture[0].data.mask.mask = 
588         theme->a_disabled_unfocused_close->texture[0].data.mask.mask = 
589         theme->a_hover_focused_close->texture[0].data.mask.mask = 
590         theme->a_hover_unfocused_close->texture[0].data.mask.mask = 
591         theme->a_focused_pressed_close->texture[0].data.mask.mask = 
592         theme->a_unfocused_pressed_close->texture[0].data.mask.mask =
593         theme->a_focused_unpressed_close->texture[0].data.mask.mask = 
594         theme->a_unfocused_unpressed_close->texture[0].data.mask.mask =
595         theme->close_mask;
596     theme->a_disabled_focused_desk->texture[0].data.mask.mask = 
597         theme->a_disabled_unfocused_desk->texture[0].data.mask.mask = 
598         theme->a_hover_focused_desk->texture[0].data.mask.mask = 
599         theme->a_hover_unfocused_desk->texture[0].data.mask.mask = 
600         theme->a_focused_unpressed_desk->texture[0].data.mask.mask = 
601         theme->a_unfocused_unpressed_desk->texture[0].data.mask.mask = 
602         theme->a_focused_pressed_desk->texture[0].data.mask.mask = 
603         theme->a_unfocused_pressed_desk->texture[0].data.mask.mask =
604         theme->desk_unset_mask;
605     theme->a_focused_pressed_set_desk->texture[0].data.mask.mask = 
606         theme->a_unfocused_pressed_set_desk->texture[0].data.mask.mask =
607         theme->desk_set_mask;
608     theme->a_disabled_focused_shade->texture[0].data.mask.mask = 
609         theme->a_disabled_unfocused_shade->texture[0].data.mask.mask = 
610         theme->a_hover_focused_shade->texture[0].data.mask.mask = 
611         theme->a_hover_unfocused_shade->texture[0].data.mask.mask = 
612         theme->a_focused_unpressed_shade->texture[0].data.mask.mask = 
613         theme->a_unfocused_unpressed_shade->texture[0].data.mask.mask = 
614         theme->a_focused_pressed_shade->texture[0].data.mask.mask = 
615         theme->a_unfocused_pressed_shade->texture[0].data.mask.mask =
616         theme->shade_unset_mask;
617     theme->a_focused_pressed_set_shade->texture[0].data.mask.mask = 
618         theme->a_unfocused_pressed_set_shade->texture[0].data.mask.mask =
619         theme->shade_set_mask;
620     theme->a_disabled_focused_iconify->texture[0].data.mask.mask = 
621         theme->a_disabled_unfocused_iconify->texture[0].data.mask.mask = 
622         theme->a_hover_focused_iconify->texture[0].data.mask.mask = 
623         theme->a_hover_unfocused_iconify->texture[0].data.mask.mask = 
624         theme->a_focused_unpressed_iconify->texture[0].data.mask.mask = 
625         theme->a_unfocused_unpressed_iconify->texture[0].data.mask.mask = 
626         theme->a_focused_pressed_iconify->texture[0].data.mask.mask = 
627         theme->a_unfocused_pressed_iconify->texture[0].data.mask.mask =
628         theme->iconify_mask;
629     theme->a_disabled_focused_max->texture[0].data.mask.color = 
630         theme->a_disabled_focused_close->texture[0].data.mask.color = 
631         theme->a_disabled_focused_desk->texture[0].data.mask.color = 
632         theme->a_disabled_focused_shade->texture[0].data.mask.color = 
633         theme->a_disabled_focused_iconify->texture[0].data.mask.color = 
634         theme->titlebut_disabled_focused_color;
635     theme->a_disabled_unfocused_max->texture[0].data.mask.color = 
636         theme->a_disabled_unfocused_close->texture[0].data.mask.color = 
637         theme->a_disabled_unfocused_desk->texture[0].data.mask.color = 
638         theme->a_disabled_unfocused_shade->texture[0].data.mask.color = 
639         theme->a_disabled_unfocused_iconify->texture[0].data.mask.color = 
640         theme->titlebut_disabled_unfocused_color;
641     theme->a_hover_focused_max->texture[0].data.mask.color = 
642         theme->a_hover_focused_close->texture[0].data.mask.color = 
643         theme->a_hover_focused_desk->texture[0].data.mask.color = 
644         theme->a_hover_focused_shade->texture[0].data.mask.color = 
645         theme->a_hover_focused_iconify->texture[0].data.mask.color = 
646         theme->titlebut_hover_focused_color;
647     theme->a_hover_unfocused_max->texture[0].data.mask.color = 
648         theme->a_hover_unfocused_close->texture[0].data.mask.color = 
649         theme->a_hover_unfocused_desk->texture[0].data.mask.color = 
650         theme->a_hover_unfocused_shade->texture[0].data.mask.color = 
651         theme->a_hover_unfocused_iconify->texture[0].data.mask.color = 
652         theme->titlebut_hover_unfocused_color;
653     theme->a_focused_unpressed_max->texture[0].data.mask.color = 
654         theme->a_focused_unpressed_close->texture[0].data.mask.color = 
655         theme->a_focused_unpressed_desk->texture[0].data.mask.color = 
656         theme->a_focused_unpressed_shade->texture[0].data.mask.color = 
657         theme->a_focused_unpressed_iconify->texture[0].data.mask.color = 
658         theme->titlebut_focused_unpressed_color;
659     theme->a_focused_pressed_max->texture[0].data.mask.color = 
660         theme->a_focused_pressed_set_max->texture[0].data.mask.color = 
661         theme->a_focused_pressed_close->texture[0].data.mask.color = 
662         theme->a_focused_pressed_desk->texture[0].data.mask.color = 
663         theme->a_focused_pressed_set_desk->texture[0].data.mask.color = 
664         theme->a_focused_pressed_shade->texture[0].data.mask.color = 
665         theme->a_focused_pressed_set_shade->texture[0].data.mask.color = 
666         theme->a_focused_pressed_iconify->texture[0].data.mask.color =
667         theme->titlebut_focused_pressed_color;
668     theme->a_unfocused_unpressed_max->texture[0].data.mask.color = 
669         theme->a_unfocused_unpressed_close->texture[0].data.mask.color = 
670         theme->a_unfocused_unpressed_desk->texture[0].data.mask.color = 
671         theme->a_unfocused_unpressed_shade->texture[0].data.mask.color = 
672         theme->a_unfocused_unpressed_iconify->texture[0].data.mask.color = 
673         theme->titlebut_unfocused_unpressed_color;
674         theme->a_unfocused_pressed_max->texture[0].data.mask.color = 
675         theme->a_unfocused_pressed_set_max->texture[0].data.mask.color = 
676         theme->a_unfocused_pressed_close->texture[0].data.mask.color = 
677         theme->a_unfocused_pressed_desk->texture[0].data.mask.color = 
678         theme->a_unfocused_pressed_set_desk->texture[0].data.mask.color = 
679         theme->a_unfocused_pressed_shade->texture[0].data.mask.color = 
680         theme->a_unfocused_pressed_set_shade->texture[0].data.mask.color = 
681         theme->a_unfocused_pressed_iconify->texture[0].data.mask.color =
682         theme->titlebut_unfocused_pressed_color;
683
684     XrmDestroyDatabase(db);
685
686     theme->label_height = theme->winfont_height;
687     theme->title_height = theme->label_height + theme->bevel * 2;
688     theme->button_size = theme->label_height - 2;
689     theme->grip_width = theme->button_size * 2;
690
691     return theme;
692 }
693
694 void RrThemeFree(RrTheme *theme)
695 {
696     if (theme) {
697         g_free(theme->name);
698
699         RrColorFree(theme->b_color);
700         RrColorFree(theme->cb_unfocused_color);
701         RrColorFree(theme->cb_focused_color);
702         RrColorFree(theme->title_unfocused_color);
703         RrColorFree(theme->title_focused_color);
704         RrColorFree(theme->titlebut_disabled_focused_color);
705         RrColorFree(theme->titlebut_disabled_unfocused_color);
706         RrColorFree(theme->titlebut_hover_focused_color);
707         RrColorFree(theme->titlebut_hover_unfocused_color);
708         RrColorFree(theme->titlebut_unfocused_pressed_color);
709         RrColorFree(theme->titlebut_focused_pressed_color);
710         RrColorFree(theme->titlebut_unfocused_unpressed_color);
711         RrColorFree(theme->titlebut_focused_unpressed_color);
712         RrColorFree(theme->menu_color);
713         RrColorFree(theme->menu_title_color);
714         RrColorFree(theme->menu_disabled_color);
715         RrColorFree(theme->menu_hilite_color);
716
717         RrPixmapMaskFree(theme->max_set_mask);
718         RrPixmapMaskFree(theme->max_unset_mask);
719         RrPixmapMaskFree(theme->desk_set_mask);
720         RrPixmapMaskFree(theme->desk_unset_mask);
721         RrPixmapMaskFree(theme->shade_set_mask);
722         RrPixmapMaskFree(theme->shade_unset_mask);
723         RrPixmapMaskFree(theme->iconify_mask);
724         RrPixmapMaskFree(theme->close_mask);
725
726         RrFontClose(theme->winfont);
727         RrFontClose(theme->mtitlefont);
728         RrFontClose(theme->mfont);
729
730         RrAppearanceFree(theme->a_disabled_focused_max);
731         RrAppearanceFree(theme->a_disabled_unfocused_max);
732         RrAppearanceFree(theme->a_hover_focused_max);
733         RrAppearanceFree(theme->a_hover_unfocused_max);
734         RrAppearanceFree(theme->a_focused_unpressed_max);
735         RrAppearanceFree(theme->a_focused_pressed_max);
736         RrAppearanceFree(theme->a_focused_pressed_set_max);
737         RrAppearanceFree(theme->a_unfocused_unpressed_max);
738         RrAppearanceFree(theme->a_unfocused_pressed_max);
739         RrAppearanceFree(theme->a_unfocused_pressed_set_max);
740         RrAppearanceFree(theme->a_disabled_focused_close);
741         RrAppearanceFree(theme->a_disabled_unfocused_close);
742         RrAppearanceFree(theme->a_hover_focused_close);
743         RrAppearanceFree(theme->a_hover_unfocused_close);
744         RrAppearanceFree(theme->a_focused_unpressed_close);
745         RrAppearanceFree(theme->a_focused_pressed_close);
746         RrAppearanceFree(theme->a_unfocused_unpressed_close);
747         RrAppearanceFree(theme->a_unfocused_pressed_close);
748         RrAppearanceFree(theme->a_disabled_focused_desk);
749         RrAppearanceFree(theme->a_disabled_unfocused_desk);
750         RrAppearanceFree(theme->a_hover_focused_desk);
751         RrAppearanceFree(theme->a_hover_unfocused_desk);
752         RrAppearanceFree(theme->a_focused_unpressed_desk);
753         RrAppearanceFree(theme->a_focused_pressed_desk);
754         RrAppearanceFree(theme->a_unfocused_unpressed_desk);
755         RrAppearanceFree(theme->a_unfocused_pressed_desk);
756         RrAppearanceFree(theme->a_disabled_focused_shade);
757         RrAppearanceFree(theme->a_disabled_unfocused_shade);
758         RrAppearanceFree(theme->a_hover_focused_shade);
759         RrAppearanceFree(theme->a_hover_unfocused_shade);
760         RrAppearanceFree(theme->a_focused_unpressed_shade);
761         RrAppearanceFree(theme->a_focused_pressed_shade);
762         RrAppearanceFree(theme->a_unfocused_unpressed_shade);
763         RrAppearanceFree(theme->a_unfocused_pressed_shade);
764         RrAppearanceFree(theme->a_disabled_focused_iconify);
765         RrAppearanceFree(theme->a_disabled_unfocused_iconify);
766         RrAppearanceFree(theme->a_hover_focused_iconify);
767         RrAppearanceFree(theme->a_hover_unfocused_iconify);
768         RrAppearanceFree(theme->a_focused_unpressed_iconify);
769         RrAppearanceFree(theme->a_focused_pressed_iconify);
770         RrAppearanceFree(theme->a_unfocused_unpressed_iconify);
771         RrAppearanceFree(theme->a_unfocused_pressed_iconify);
772         RrAppearanceFree(theme->a_focused_grip);
773         RrAppearanceFree(theme->a_unfocused_grip);
774         RrAppearanceFree(theme->a_focused_title);
775         RrAppearanceFree(theme->a_unfocused_title);
776         RrAppearanceFree(theme->a_focused_label);
777         RrAppearanceFree(theme->a_unfocused_label);
778         RrAppearanceFree(theme->a_icon);
779         RrAppearanceFree(theme->a_focused_handle);
780         RrAppearanceFree(theme->a_unfocused_handle);
781         RrAppearanceFree(theme->a_menu);
782         RrAppearanceFree(theme->a_menu_title);
783         RrAppearanceFree(theme->a_menu_item);
784         RrAppearanceFree(theme->a_menu_disabled);
785         RrAppearanceFree(theme->a_menu_hilite);
786         RrAppearanceFree(theme->app_hilite_bg);
787         RrAppearanceFree(theme->app_unhilite_bg);
788         RrAppearanceFree(theme->app_hilite_label);
789         RrAppearanceFree(theme->app_unhilite_label);
790         RrAppearanceFree(theme->app_icon);
791     }
792 }
793
794 static XrmDatabase loaddb(RrTheme *theme, char *name)
795 {
796     XrmDatabase db;
797
798     if ((db = XrmGetFileDatabase(name)))
799         theme->path = g_path_get_dirname(name);
800     if (db == NULL) {
801         char *s = g_build_filename(g_get_home_dir(), ".openbox", "themes",
802                                    name, NULL);
803         if ((db = XrmGetFileDatabase(s)))
804             theme->path = g_path_get_dirname(s);
805         g_free(s);
806     }
807     if (db == NULL) {
808         char *s = g_build_filename(THEMEDIR, name, NULL);
809         if ((db = XrmGetFileDatabase(s)))
810             theme->path = g_path_get_dirname(s);
811         g_free(s);
812     }
813
814     return db;
815 }
816
817 static char *create_class_name(char *rname)
818 {
819     char *rclass = g_strdup(rname);
820     char *p = rclass;
821
822     while (TRUE) {
823         *p = toupper(*p);
824         p = strchr(p+1, '.');
825         if (p == NULL) break;
826         ++p;
827         if (*p == '\0') break;
828     }
829     return rclass;
830 }
831
832 static gboolean read_int(XrmDatabase db, char *rname, int *value)
833 {
834     gboolean ret = FALSE;
835     char *rclass = create_class_name(rname);
836     char *rettype, *end;
837     XrmValue retvalue;
838   
839     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
840         retvalue.addr != NULL) {
841         *value = (int)strtol(retvalue.addr, &end, 10);
842         if (end != retvalue.addr)
843             ret = TRUE;
844     }
845
846     g_free(rclass);
847     return ret;
848 }
849
850 static gboolean read_string(XrmDatabase db, char *rname, char **value)
851 {
852     gboolean ret = FALSE;
853     char *rclass = create_class_name(rname);
854     char *rettype;
855     XrmValue retvalue;
856   
857     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
858         retvalue.addr != NULL) {
859         *value = retvalue.addr;
860         ret = TRUE;
861     }
862
863     g_free(rclass);
864     return ret;
865 }
866
867 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
868                            gchar *rname, RrColor **value)
869 {
870     gboolean ret = FALSE;
871     char *rclass = create_class_name(rname);
872     char *rettype;
873     XrmValue retvalue;
874   
875     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
876         retvalue.addr != NULL) {
877         RrColor *c = RrColorParse(inst, retvalue.addr);
878         if (c != NULL) {
879             *value = c;
880             ret = TRUE;
881         }
882     }
883
884     g_free(rclass);
885     return ret;
886 }
887
888 static gboolean read_mask(const RrInstance *inst,
889                           gchar *maskname, RrTheme *theme,
890                           RrPixmapMask **value)
891 {
892     gboolean ret = FALSE;
893     char *s;
894     char *data_dir;
895     int hx, hy; /* ignored */
896     unsigned int w, h;
897     unsigned char *b;
898
899     data_dir = g_strdup_printf("%s_data", theme->name);
900
901     s = g_build_filename(g_get_home_dir(), ".openbox", "themes",
902                          data_dir, maskname, NULL);
903     if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess)
904         ret = TRUE;
905     else {
906         g_free(s);
907         s = g_build_filename(THEMEDIR, data_dir, maskname, NULL);
908         if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess) 
909             ret = TRUE;
910         else {
911             g_free(s);
912             s = g_build_filename(theme->path, data_dir, maskname, NULL);
913             if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess) 
914                 ret = TRUE;
915         }
916     }
917
918     if (ret) {
919         *value = RrPixmapMaskNew(inst, w, h, (char*)b);
920         XFree(b);
921     }
922       
923     g_free(s);
924     g_free(data_dir);
925
926     return ret;
927 }
928
929 static void parse_appearance(gchar *tex, RrSurfaceColorType *grad,
930                              RrReliefType *relief, RrBevelType *bevel,
931                              gboolean *interlaced, gboolean *border,
932                              gboolean allow_trans)
933 {
934     char *t;
935
936     /* convert to all lowercase */
937     for (t = tex; *t != '\0'; ++t)
938         *t = g_ascii_tolower(*t);
939
940     if (allow_trans && strstr(tex, "parentrelative") != NULL) {
941         *grad = RR_SURFACE_PARENTREL;
942     } else {
943         if (strstr(tex, "gradient") != NULL) {
944             if (strstr(tex, "crossdiagonal") != NULL)
945                 *grad = RR_SURFACE_CROSS_DIAGONAL;
946             else if (strstr(tex, "pyramid") != NULL)
947                 *grad = RR_SURFACE_PYRAMID;
948             else if (strstr(tex, "horizontal") != NULL)
949                 *grad = RR_SURFACE_HORIZONTAL;
950             else if (strstr(tex, "vertical") != NULL)
951                 *grad = RR_SURFACE_VERTICAL;
952             else
953                 *grad = RR_SURFACE_DIAGONAL;
954         } else {
955             *grad = RR_SURFACE_SOLID;
956         }
957
958         if (strstr(tex, "sunken") != NULL)
959             *relief = RR_RELIEF_SUNKEN;
960         else if (strstr(tex, "flat") != NULL)
961             *relief = RR_RELIEF_FLAT;
962         else
963             *relief = RR_RELIEF_RAISED;
964         
965         *border = FALSE;
966         if (*relief == RR_RELIEF_FLAT) {
967             if (strstr(tex, "border") != NULL)
968                 *border = TRUE;
969         } else {
970             if (strstr(tex, "bevel2") != NULL)
971                 *bevel = RR_BEVEL_2;
972             else
973                 *bevel = RR_BEVEL_1;
974         }
975
976         if (strstr(tex, "interlaced") != NULL)
977             *interlaced = TRUE;
978         else
979             *interlaced = FALSE;
980     }
981 }
982
983
984 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
985                                 gchar *rname, RrAppearance *value,
986                                 gboolean allow_trans)
987 {
988     gboolean ret = FALSE;
989     char *rclass = create_class_name(rname), *cname, *ctoname, *bcname;
990     char *rettype;
991     XrmValue retvalue;
992
993     cname = g_strconcat(rname, ".color", NULL);
994     ctoname = g_strconcat(rname, ".colorTo", NULL);
995     bcname = g_strconcat(rname, ".borderColor", NULL);
996
997     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
998         retvalue.addr != NULL) {
999         parse_appearance(retvalue.addr,
1000                          &value->surface.grad,
1001                          &value->surface.relief,
1002                          &value->surface.bevel,
1003                          &value->surface.interlaced,
1004                          &value->surface.border,
1005                          allow_trans);
1006         if (!read_color(db, inst, cname, &value->surface.primary))
1007             value->surface.primary = RrColorNew(inst, 0, 0, 0);
1008         if (!read_color(db, inst, ctoname, &value->surface.secondary))
1009             value->surface.secondary = RrColorNew(inst, 0, 0, 0);
1010         if (value->surface.border)
1011             if (!read_color(db, inst, bcname,
1012                             &value->surface.border_color))
1013                 value->surface.border_color = RrColorNew(inst, 0, 0, 0);
1014         ret = TRUE;
1015     }
1016
1017     g_free(bcname);
1018     g_free(ctoname);
1019     g_free(cname);
1020     g_free(rclass);
1021     return ret;
1022 }
1023
1024 static void set_default_appearance(RrAppearance *a)
1025 {
1026     a->surface.grad = RR_SURFACE_SOLID;
1027     a->surface.relief = RR_RELIEF_FLAT;
1028     a->surface.bevel = RR_BEVEL_1;
1029     a->surface.interlaced = FALSE;
1030     a->surface.border = FALSE;
1031     a->surface.primary = RrColorNew(a->inst, 0, 0, 0);
1032     a->surface.secondary = RrColorNew(a->inst, 0, 0, 0);
1033 }