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