]> icculus.org git repositories - mikachu/openbox.git/blob - render/theme.c
optimize it a bit
[mikachu/openbox.git] / render / theme.c
1 #include "render.h"
2 #include "color.h"
3 #include "font.h"
4 #include "mask.h"
5
6 #include <X11/Xlib.h>
7 #include <X11/Xresource.h>
8
9 /* style settings - geometry */
10 int theme_bevel;
11 int theme_handle_height;
12 int theme_bwidth;
13 int theme_cbwidth;
14 /* style settings - colors */
15 color_rgb *theme_b_color;
16 color_rgb *theme_cb_focused_color;
17 color_rgb *theme_cb_unfocused_color;
18 color_rgb *theme_title_focused_color;
19 color_rgb *theme_title_unfocused_color;
20 color_rgb *theme_titlebut_focused_color;
21 color_rgb *theme_titlebut_unfocused_color;
22 color_rgb *theme_menu_title_color;
23 color_rgb *theme_menu_color;
24 color_rgb *theme_menu_disabled_color;
25 color_rgb *theme_menu_hilite_color;
26 /* style settings - fonts */
27 int theme_winfont_height;
28 ObFont *theme_winfont;
29 gboolean theme_winfont_shadow;
30 int theme_winfont_shadow_offset;
31 int theme_winfont_shadow_tint;
32 int theme_mtitlefont_height;
33 ObFont *theme_mtitlefont;
34 gboolean theme_mtitlefont_shadow;
35 int theme_mtitlefont_shadow_offset;
36 int theme_mtitlefont_shadow_tint;
37 int theme_mfont_height;
38 ObFont *theme_mfont;
39 gboolean theme_mfont_shadow;
40 int theme_mfont_shadow_offset;
41 int theme_mfont_shadow_tint;
42 /* style settings - title layout */
43 char *theme_title_layout;
44 /* style settings - masks */
45 pixmap_mask *theme_max_set_mask;
46 pixmap_mask *theme_max_unset_mask;
47 pixmap_mask *theme_iconify_mask;
48 pixmap_mask *theme_desk_set_mask;
49 pixmap_mask *theme_desk_unset_mask;
50 pixmap_mask *theme_shade_set_mask;
51 pixmap_mask *theme_shade_unset_mask;
52 pixmap_mask *theme_close_mask;
53
54 /* global appearances */
55 Appearance *theme_a_focused_unpressed_max;
56 Appearance *theme_a_focused_pressed_max;
57 Appearance *theme_a_focused_pressed_set_max;
58 Appearance *theme_a_unfocused_unpressed_max;
59 Appearance *theme_a_unfocused_pressed_max;
60 Appearance *theme_a_unfocused_pressed_set_max;
61 Appearance *theme_a_focused_unpressed_close;
62 Appearance *theme_a_focused_pressed_close;
63 Appearance *theme_a_unfocused_unpressed_close;
64 Appearance *theme_a_unfocused_pressed_close;
65 Appearance *theme_a_focused_unpressed_desk;
66 Appearance *theme_a_focused_pressed_desk;
67 Appearance *theme_a_focused_pressed_set_desk;
68 Appearance *theme_a_unfocused_unpressed_desk;
69 Appearance *theme_a_unfocused_pressed_desk;
70 Appearance *theme_a_unfocused_pressed_set_desk;
71 Appearance *theme_a_focused_unpressed_shade;
72 Appearance *theme_a_focused_pressed_shade;
73 Appearance *theme_a_focused_pressed_set_shade;
74 Appearance *theme_a_unfocused_unpressed_shade;
75 Appearance *theme_a_unfocused_pressed_shade;
76 Appearance *theme_a_unfocused_pressed_set_shade;
77 Appearance *theme_a_focused_unpressed_iconify;
78 Appearance *theme_a_focused_pressed_iconify;
79 Appearance *theme_a_unfocused_unpressed_iconify;
80 Appearance *theme_a_unfocused_pressed_iconify;
81 Appearance *theme_a_focused_grip;
82 Appearance *theme_a_unfocused_grip;
83 Appearance *theme_a_focused_title;
84 Appearance *theme_a_unfocused_title;
85 Appearance *theme_a_focused_label;
86 Appearance *theme_a_unfocused_label;
87 Appearance *theme_a_icon; /* always parentrelative, so no focused/unfocused */
88 Appearance *theme_a_focused_handle;
89 Appearance *theme_a_unfocused_handle;
90 Appearance *theme_a_menu_title;
91 Appearance *theme_a_menu;
92 Appearance *theme_a_menu_item;
93 Appearance *theme_a_menu_disabled;
94 Appearance *theme_a_menu_hilite;
95
96 Appearance *theme_app_hilite_bg;
97 Appearance *theme_app_unhilite_bg;
98 Appearance *theme_app_hilite_label;
99 Appearance *theme_app_unhilite_label;
100 Appearance *theme_app_icon;
101
102 void theme_startup()
103 {
104     theme_b_color = theme_cb_unfocused_color = theme_cb_focused_color = 
105         theme_title_unfocused_color = theme_title_focused_color = 
106         theme_titlebut_unfocused_color = theme_titlebut_focused_color = 
107         theme_menu_color = theme_menu_title_color = theme_menu_disabled_color =
108         theme_menu_hilite_color = NULL;
109     theme_winfont = theme_mtitlefont = theme_mfont = NULL;
110     theme_title_layout = NULL;
111     theme_max_set_mask = theme_max_unset_mask = NULL;
112     theme_desk_set_mask = theme_desk_unset_mask = NULL;
113     theme_shade_set_mask = theme_shade_unset_mask = NULL;
114     theme_iconify_mask = theme_close_mask = NULL;
115
116     theme_a_focused_unpressed_max = appearance_new(Surface_Planar, 1);
117     theme_a_focused_pressed_max = appearance_new(Surface_Planar, 1);
118     theme_a_focused_pressed_set_max = appearance_new(Surface_Planar, 1);
119     theme_a_unfocused_unpressed_max = appearance_new(Surface_Planar, 1);
120     theme_a_unfocused_pressed_max = appearance_new(Surface_Planar, 1);
121     theme_a_unfocused_pressed_set_max = appearance_new(Surface_Planar, 1);
122     theme_a_focused_unpressed_close = NULL;
123     theme_a_focused_pressed_close = NULL;
124     theme_a_unfocused_unpressed_close = NULL;
125     theme_a_unfocused_pressed_close = NULL;
126     theme_a_focused_unpressed_desk = NULL;
127     theme_a_focused_pressed_desk = NULL;
128     theme_a_focused_pressed_set_desk = NULL;
129     theme_a_unfocused_unpressed_desk = NULL;
130     theme_a_unfocused_pressed_desk = NULL;
131     theme_a_unfocused_pressed_set_desk = NULL;
132     theme_a_focused_unpressed_shade = NULL;
133     theme_a_focused_pressed_shade = NULL;
134     theme_a_focused_pressed_set_shade = NULL;
135     theme_a_unfocused_unpressed_shade = NULL;
136     theme_a_unfocused_pressed_shade = NULL;
137     theme_a_unfocused_pressed_set_shade = NULL;
138     theme_a_focused_unpressed_iconify = NULL;
139     theme_a_focused_pressed_iconify = NULL;
140     theme_a_unfocused_unpressed_iconify = NULL;
141     theme_a_unfocused_pressed_iconify = NULL;
142     theme_a_focused_grip = appearance_new(Surface_Planar, 0);
143     theme_a_unfocused_grip = appearance_new(Surface_Planar, 0);
144     theme_a_focused_title = appearance_new(Surface_Planar, 0);
145     theme_a_unfocused_title = appearance_new(Surface_Planar, 0);
146     theme_a_focused_label = appearance_new(Surface_Planar, 1);
147     theme_a_unfocused_label = appearance_new(Surface_Planar, 1);
148     theme_a_icon = appearance_new(Surface_Planar, 1);
149     theme_a_focused_handle = appearance_new(Surface_Planar, 0);
150     theme_a_unfocused_handle = appearance_new(Surface_Planar, 0);
151     theme_a_menu = appearance_new(Surface_Planar, 0);
152     theme_a_menu_title = appearance_new(Surface_Planar, 1);
153     theme_a_menu_item = appearance_new(Surface_Planar, 1);
154     theme_a_menu_disabled = appearance_new(Surface_Planar, 1);
155     theme_a_menu_hilite = appearance_new(Surface_Planar, 1);
156
157     theme_app_hilite_bg = appearance_new(Surface_Planar, 0);
158     theme_app_unhilite_bg = appearance_new(Surface_Planar, 0);
159     theme_app_hilite_label = appearance_new(Surface_Planar, 1);
160     theme_app_unhilite_label = appearance_new(Surface_Planar, 1);
161     theme_app_icon = appearance_new(Surface_Planar, 1);
162
163 }
164
165 void theme_shutdown()
166 {
167     color_free(theme_b_color);
168     color_free(theme_cb_unfocused_color);
169     color_free(theme_cb_focused_color);
170     color_free(theme_title_unfocused_color);
171     color_free(theme_title_focused_color);
172     color_free(theme_titlebut_unfocused_color);
173     color_free(theme_titlebut_focused_color);
174     color_free(theme_menu_color);
175     color_free(theme_menu_title_color);
176     color_free(theme_menu_disabled_color);
177     color_free(theme_menu_hilite_color);
178
179     pixmap_mask_free(theme_max_set_mask);
180     pixmap_mask_free(theme_max_unset_mask);
181     pixmap_mask_free(theme_desk_set_mask);
182     pixmap_mask_free(theme_desk_unset_mask);
183     pixmap_mask_free(theme_shade_set_mask);
184     pixmap_mask_free(theme_shade_unset_mask);
185     pixmap_mask_free(theme_iconify_mask);
186     pixmap_mask_free(theme_close_mask);
187
188     font_close(theme_winfont);
189     font_close(theme_mtitlefont);
190     font_close(theme_mfont);
191
192     g_free(theme_title_layout);
193
194     appearance_free(theme_a_focused_unpressed_max);
195     appearance_free(theme_a_focused_pressed_max);
196     appearance_free(theme_a_focused_pressed_set_max);
197     appearance_free(theme_a_unfocused_unpressed_max);
198     appearance_free(theme_a_unfocused_pressed_max);
199     appearance_free(theme_a_unfocused_pressed_set_max);
200     appearance_free(theme_a_focused_unpressed_close);
201     appearance_free(theme_a_focused_pressed_close);
202     appearance_free(theme_a_unfocused_unpressed_close);
203     appearance_free(theme_a_unfocused_pressed_close);
204     appearance_free(theme_a_focused_unpressed_desk);
205     appearance_free(theme_a_focused_pressed_desk);
206     appearance_free(theme_a_unfocused_unpressed_desk);
207     appearance_free(theme_a_unfocused_pressed_desk);
208     appearance_free(theme_a_focused_unpressed_shade);
209     appearance_free(theme_a_focused_pressed_shade);
210     appearance_free(theme_a_unfocused_unpressed_shade);
211     appearance_free(theme_a_unfocused_pressed_shade);
212     appearance_free(theme_a_focused_unpressed_iconify);
213     appearance_free(theme_a_focused_pressed_iconify);
214     appearance_free(theme_a_unfocused_unpressed_iconify);
215     appearance_free(theme_a_unfocused_pressed_iconify);
216     appearance_free(theme_a_focused_grip);
217     appearance_free(theme_a_unfocused_grip);
218     appearance_free(theme_a_focused_title);
219     appearance_free(theme_a_unfocused_title);
220     appearance_free(theme_a_focused_label);
221     appearance_free(theme_a_unfocused_label);
222     appearance_free(theme_a_icon);
223     appearance_free(theme_a_focused_handle);
224     appearance_free(theme_a_unfocused_handle);
225     appearance_free(theme_a_menu);
226     appearance_free(theme_a_menu_title);
227     appearance_free(theme_a_menu_item);
228     appearance_free(theme_a_menu_disabled);
229     appearance_free(theme_a_menu_hilite);
230     appearance_free(theme_app_hilite_bg);
231     appearance_free(theme_app_unhilite_bg);
232     appearance_free(theme_app_hilite_label);
233     appearance_free(theme_app_unhilite_label);
234     appearance_free(theme_app_icon);
235 }
236
237 static XrmDatabase loaddb(char *theme)
238 {
239     XrmDatabase db;
240
241     db = XrmGetFileDatabase(theme);
242     if (db == NULL) {
243         char *s = g_build_filename(g_get_home_dir(), ".openbox", "themes",
244                                    theme, NULL);
245         db = XrmGetFileDatabase(s);
246         g_free(s);
247     }
248     if (db == NULL) {
249         char *s = g_build_filename(THEMEDIR, theme, NULL);
250         db = XrmGetFileDatabase(s);
251         g_free(s);
252     }
253     return db;
254 }
255
256 static char *create_class_name(char *rname)
257 {
258     char *rclass = g_strdup(rname);
259     char *p = rclass;
260
261     while (TRUE) {
262         *p = toupper(*p);
263         p = strchr(p+1, '.');
264         if (p == NULL) break;
265         ++p;
266         if (*p == '\0') break;
267     }
268     return rclass;
269 }
270
271 static gboolean read_int(XrmDatabase db, char *rname, int *value)
272 {
273     gboolean ret = FALSE;
274     char *rclass = create_class_name(rname);
275     char *rettype, *end;
276     XrmValue retvalue;
277   
278     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
279         retvalue.addr != NULL) {
280         *value = (int)strtol(retvalue.addr, &end, 10);
281         if (end != retvalue.addr)
282             ret = TRUE;
283     }
284
285     g_free(rclass);
286     return ret;
287 }
288
289 static gboolean read_string(XrmDatabase db, char *rname, char **value)
290 {
291     gboolean ret = FALSE;
292     char *rclass = create_class_name(rname);
293     char *rettype;
294     XrmValue retvalue;
295   
296     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
297         retvalue.addr != NULL) {
298         *value = g_strdup(retvalue.addr);
299         ret = TRUE;
300     }
301
302     g_free(rclass);
303     return ret;
304 }
305
306 static gboolean read_color(XrmDatabase db, char *rname, color_rgb **value)
307 {
308     gboolean ret = FALSE;
309     char *rclass = create_class_name(rname);
310     char *rettype;
311     XrmValue retvalue;
312   
313     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
314         retvalue.addr != NULL) {
315         color_rgb *c = color_parse(retvalue.addr);
316         if (c != NULL) {
317             *value = c;
318             ret = TRUE;
319         }
320     }
321
322     g_free(rclass);
323     return ret;
324 }
325
326 static gboolean read_mask(XrmDatabase db, char *rname, char *theme,
327                           pixmap_mask **value)
328 {
329     gboolean ret = FALSE;
330     char *rclass = create_class_name(rname);
331     char *rettype;
332     char *s;
333     char *button_dir;
334     XrmValue retvalue;
335     int hx, hy; /* ignored */
336     unsigned int w, h;
337     unsigned char *b;
338   
339     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
340         retvalue.addr != NULL) {
341
342         button_dir = g_strdup_printf("%s_data", theme);
343
344         s = g_build_filename(g_get_home_dir(), ".openbox", "themes",
345                              button_dir, retvalue.addr, NULL);
346
347         if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess)
348             ret = TRUE;
349         else {
350             g_free(s);
351             s = g_build_filename(THEMEDIR, button_dir, retvalue.addr, NULL);
352         
353             if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess) 
354                 ret = TRUE;
355             else {
356                 char *themename;
357
358                 g_free(s);
359                 themename = g_path_get_basename(theme);
360                 s = g_strdup_printf("%s/%s_data/%s", theme,
361                                     themename, retvalue.addr);
362                 g_free(themename);
363                 if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) ==
364                     BitmapSuccess) 
365                     ret = TRUE;
366                 else
367                     g_message("Unable to find bitmap '%s'", retvalue.addr);
368             }
369         }
370
371         if (ret) {
372             *value = pixmap_mask_new(w, h, (char*)b);
373             XFree(b);
374         }
375       
376         g_free(s);
377         g_free(button_dir);
378     }
379
380     g_free(rclass);
381     return ret;
382 }
383
384 static void parse_appearance(char *tex, SurfaceColorType *grad,
385                              ReliefType *relief, BevelType *bevel,
386                              gboolean *interlaced, gboolean *border)
387 {
388     char *t;
389
390     /* convert to all lowercase */
391     for (t = tex; *t != '\0'; ++t)
392         *t = g_ascii_tolower(*t);
393
394     if (strstr(tex, "parentrelative") != NULL) {
395         *grad = Background_ParentRelative;
396     } else {
397         if (strstr(tex, "gradient") != NULL) {
398             if (strstr(tex, "crossdiagonal") != NULL)
399                 *grad = Background_CrossDiagonal;
400             else if (strstr(tex, "rectangle") != NULL)
401                 *grad = Background_Rectangle;
402             else if (strstr(tex, "pyramid") != NULL)
403                 *grad = Background_Pyramid;
404             else if (strstr(tex, "pipecross") != NULL)
405                 *grad = Background_PipeCross;
406             else if (strstr(tex, "elliptic") != NULL)
407                 *grad = Background_Rectangle;
408             else if (strstr(tex, "horizontal") != NULL)
409                 *grad = Background_Horizontal;
410             else if (strstr(tex, "vertical") != NULL)
411                 *grad = Background_Vertical;
412             else
413                 *grad = Background_Diagonal;
414         } else {
415             *grad = Background_Solid;
416         }
417
418         if (strstr(tex, "sunken") != NULL)
419             *relief = Sunken;
420         else if (strstr(tex, "flat") != NULL)
421             *relief = Flat;
422         else
423             *relief = Raised;
424         
425         *border = FALSE;
426         if (*relief == Flat) {
427             if (strstr(tex, "border") != NULL)
428                 *border = TRUE;
429         } else {
430             if (strstr(tex, "bevel2") != NULL)
431                 *bevel = Bevel2;
432             else
433                 *bevel = Bevel1;
434         }
435
436         if (strstr(tex, "interlaced") != NULL)
437             *interlaced = TRUE;
438         else
439             *interlaced = FALSE;
440     }
441 }
442
443
444 static gboolean read_appearance(XrmDatabase db, char *rname, Appearance *value)
445 {
446     gboolean ret = FALSE;
447     char *rclass = create_class_name(rname), *cname, *ctoname, *bcname;
448     char *rettype;
449     XrmValue retvalue;
450
451     cname = g_strconcat(rname, ".color", NULL);
452     ctoname = g_strconcat(rname, ".colorTo", NULL);
453     bcname = g_strconcat(rname, ".borderColor", NULL);
454
455     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
456         retvalue.addr != NULL) {
457         parse_appearance(retvalue.addr,
458                          &value->surface.data.planar.grad,
459                          &value->surface.data.planar.relief,
460                          &value->surface.data.planar.bevel,
461                          &value->surface.data.planar.interlaced,
462                          &value->surface.data.planar.border);
463         if (!read_color(db, cname, &value->surface.data.planar.primary))
464             value->surface.data.planar.primary = color_new(0, 0, 0);
465         if (!read_color(db, ctoname, &value->surface.data.planar.secondary))
466             value->surface.data.planar.secondary = color_new(0, 0, 0);
467         if (value->surface.data.planar.border)
468             if (!read_color(db, bcname,
469                             &value->surface.data.planar.border_color))
470                 value->surface.data.planar.border_color = color_new(0, 0, 0);
471         ret = TRUE;
472     }
473
474     g_free(bcname);
475     g_free(ctoname);
476     g_free(cname);
477     g_free(rclass);
478     return ret;
479 }
480
481 static void set_default_appearance(Appearance *a)
482 {
483     a->surface.data.planar.grad = Background_Solid;
484     a->surface.data.planar.relief = Flat;
485     a->surface.data.planar.bevel = Bevel1;
486     a->surface.data.planar.interlaced = FALSE;
487     a->surface.data.planar.border = FALSE;
488     a->surface.data.planar.primary = color_new(0, 0, 0);
489     a->surface.data.planar.secondary = color_new(0, 0, 0);
490 }
491
492 char *theme_load(char *theme)
493 {
494     XrmDatabase db = NULL;
495     char *loaded = NULL;
496     Justify winjust, mtitlejust, mjust;
497     char *str;
498     char *font_str;
499
500     if (theme) {
501         db = loaddb(theme);
502         if (db == NULL) {
503             g_warning("Failed to load the theme '%s'", theme);
504             g_message("Falling back to the default: '%s'", DEFAULT_THEME);
505         } else
506             loaded = g_strdup(theme);
507     }
508     if (db == NULL) {
509         db = loaddb(DEFAULT_THEME);
510         if (db == NULL) {
511             g_warning("Failed to load the theme '%s'.", DEFAULT_THEME);
512             return NULL;
513         } else
514             loaded = g_strdup(DEFAULT_THEME);
515     }
516
517     /* load the font stuff */
518     font_str = "arial-8:bold";
519
520     theme_winfont_shadow = FALSE;
521     if (read_string(db, "window.xft.flags", &str)) {
522         if (g_strrstr(str, "shadow"))
523             theme_winfont_shadow = TRUE;
524         g_free(str);
525     }
526  
527     if (!read_int(db, "window.xft.shadow.offset",
528                   &theme_winfont_shadow_offset))
529         theme_winfont_shadow_offset = 1;
530     if (!read_int(db, "window.xft.shadow.tint",
531                   &theme_winfont_shadow_tint) ||
532         theme_winfont_shadow_tint < 100 || theme_winfont_shadow_tint > 100)
533         theme_winfont_shadow_tint = 25;
534
535     theme_winfont = font_open(font_str);
536     theme_winfont_height = font_height(theme_winfont, theme_winfont_shadow,
537                                        theme_winfont_shadow_offset);
538
539     winjust = Justify_Left;
540     if (read_string(db, "window.justify", &str)) {
541         if (!g_ascii_strcasecmp(str, "right"))
542             winjust = Justify_Right;
543         else if (!g_ascii_strcasecmp(str, "center"))
544             winjust = Justify_Center;
545         g_free(str);
546     }
547
548     font_str = "arial-10:bold";
549
550     theme_mtitlefont_shadow = FALSE;
551     if (read_string(db, "menu.title.xft.flags", &str)) {
552         if (g_strrstr(str, "shadow"))
553             theme_mtitlefont_shadow = TRUE;
554         g_free(str);
555     }
556  
557     if (!read_int(db, "menu.title.xft.shadow.offset",
558                   &theme_mtitlefont_shadow_offset))
559         theme_mtitlefont_shadow_offset = 1;
560     if (!read_int(db, "menu.title.xft.shadow.tint",
561                   &theme_mtitlefont_shadow_tint) ||
562         theme_mtitlefont_shadow_tint < 100 ||
563         theme_mtitlefont_shadow_tint > 100)
564         theme_mtitlefont_shadow_tint = 25;
565
566     theme_mtitlefont = font_open(font_str);
567     theme_mtitlefont_height = font_height(theme_mtitlefont,
568                                           theme_mtitlefont_shadow,
569                                           theme_mtitlefont_shadow_offset);
570
571     mtitlejust = Justify_Left;
572     if (read_string(db, "menu.title.justify", &str)) {
573         if (!g_ascii_strcasecmp(str, "right"))
574             mtitlejust = Justify_Right;
575         else if (!g_ascii_strcasecmp(str, "center"))
576             mtitlejust = Justify_Center;
577         g_free(str);
578     }
579
580     font_str = "arial-8";
581
582     theme_mfont_shadow = FALSE;
583     if (read_string(db, "menu.frame.xft.flags", &str)) {
584         if (g_strrstr(str, "shadow"))
585             theme_mfont_shadow = TRUE;
586         g_free(str);
587     }
588  
589     if (!read_int(db, "menu.frame.xft.shadow.offset",
590                   &theme_mfont_shadow_offset))
591         theme_mfont_shadow_offset = 1;
592     if (!read_int(db, "menu.frame.xft.shadow.tint",
593                   &theme_mfont_shadow_tint) ||
594         theme_mfont_shadow_tint < 100 ||
595         theme_mfont_shadow_tint > 100)
596         theme_mfont_shadow_tint = 25;
597
598     theme_mfont = font_open(font_str);
599     theme_mfont_height = font_height(theme_mfont, theme_mfont_shadow,
600                                      theme_mfont_shadow_offset);
601
602     mjust = Justify_Left;
603     if (read_string(db, "menu.frame.justify", &str)) {
604         if (!g_ascii_strcasecmp(str, "right"))
605             mjust = Justify_Right;
606         else if (!g_ascii_strcasecmp(str, "center"))
607             mjust = Justify_Center;
608         g_free(str);
609     }
610
611     /* load the title layout */
612     theme_title_layout = g_strdup("NLIMC");
613
614     if (!read_int(db, "handleWidth", &theme_handle_height) ||
615         theme_handle_height < 0 || theme_handle_height > 100)
616         theme_handle_height = 6;
617     if (!read_int(db, "bevelWidth", &theme_bevel) ||
618         theme_bevel <= 0 || theme_bevel > 100) theme_bevel = 3;
619     if (!read_int(db, "borderWidth", &theme_bwidth) ||
620         theme_bwidth < 0 || theme_bwidth > 100) theme_bwidth = 1;
621     if (!read_int(db, "frameWidth", &theme_cbwidth) ||
622         theme_cbwidth < 0 || theme_cbwidth > 100) theme_cbwidth = theme_bevel;
623
624     /* load colors */
625     if (!read_color(db, "borderColor", &theme_b_color))
626         theme_b_color = color_new(0, 0, 0);
627     if (!read_color(db, "window.frame.focusColor", &theme_cb_focused_color))
628         theme_cb_focused_color = color_new(0xff, 0xff, 0xff);
629     if (!read_color(db, "window.frame.unfocusColor",&theme_cb_unfocused_color))
630         theme_cb_unfocused_color = color_new(0xff, 0xff, 0xff);
631     if (!read_color(db, "window.label.focus.textColor",
632                     &theme_title_focused_color))
633         theme_title_focused_color = color_new(0x0, 0x0, 0x0);
634     if (!read_color(db, "window.label.unfocus.textColor",
635                     &theme_title_unfocused_color))
636         theme_title_unfocused_color = color_new(0xff, 0xff, 0xff);
637     if (!read_color(db, "window.button.focus.picColor",
638                     &theme_titlebut_focused_color))
639         theme_titlebut_focused_color = color_new(0, 0, 0);
640     if (!read_color(db, "window.button.unfocus.picColor",
641                     &theme_titlebut_unfocused_color))
642         theme_titlebut_unfocused_color = color_new(0xff, 0xff, 0xff);
643     if (!read_color(db, "menu.title.textColor", &theme_menu_title_color))
644         theme_menu_title_color = color_new(0, 0, 0);
645     if (!read_color(db, "menu.frame.textColor", &theme_menu_color))
646         theme_menu_color = color_new(0xff, 0xff, 0xff);
647     if (!read_color(db, "menu.frame.disableColor", &theme_menu_disabled_color))
648         theme_menu_disabled_color = color_new(0, 0, 0);
649     if (!read_color(db, "menu.hilite.textColor", &theme_menu_hilite_color))
650         theme_menu_hilite_color = color_new(0, 0, 0);
651
652     if (read_mask(db, "window.button.max.mask", theme, &theme_max_unset_mask)){
653         if (!read_mask(db, "window.button.max.toggled.mask", theme,
654                        &theme_max_set_mask)) {
655             theme_max_set_mask = pixmap_mask_copy(theme_max_unset_mask);
656         }
657     } else {
658         {
659             char data[] = { 0x7f, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x7f };
660             theme_max_unset_mask = pixmap_mask_new(7, 7, data);
661         }
662         {
663             char data[] = { 0x7c, 0x44, 0x47, 0x47, 0x7f, 0x1f, 0x1f };
664             theme_max_set_mask = pixmap_mask_new(7, 7, data);
665         }
666     }
667
668     if (!read_mask(db, "window.button.icon.mask", theme,
669                    &theme_iconify_mask)) {
670         char data[] = { 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x7f };
671         theme_iconify_mask = pixmap_mask_new(7, 7, data);
672     }
673
674     if (read_mask(db, "window.button.stick.mask", theme,
675                    &theme_desk_unset_mask)) {
676         if (!read_mask(db, "window.button.stick.toggled.mask", theme,
677                        &theme_desk_set_mask)) {
678             theme_desk_set_mask =
679                 pixmap_mask_copy(theme_desk_unset_mask);
680         }
681     } else {
682         {
683             char data[] = { 0x63, 0x63, 0x00, 0x00, 0x00, 0x63, 0x63 };
684             theme_desk_unset_mask = pixmap_mask_new(7, 7, data);
685         }
686         {
687             char data[] = { 0x00, 0x36, 0x36, 0x08, 0x36, 0x36, 0x00 };
688             theme_desk_set_mask = pixmap_mask_new(7, 7, data);
689         }
690     }
691
692     if (read_mask(db, "window.button.shade.mask", theme,
693                    &theme_shade_unset_mask)) {
694         if (!read_mask(db, "window.button.shade.toggled.mask", theme,
695                        &theme_shade_set_mask)) {
696             theme_shade_set_mask =
697                 pixmap_mask_copy(theme_shade_unset_mask);
698         }
699     } else {
700         {
701             char data[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00 };
702             theme_shade_unset_mask = pixmap_mask_new(7, 7, data);
703         }
704         {
705             char data[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x7f };
706             theme_shade_set_mask = pixmap_mask_new(7, 7, data);
707         }
708     }
709
710     if (!read_mask(db, "window.button.close.mask", theme,
711                    &theme_close_mask)) {
712         char data[] = { 0x63, 0x77, 0x3e, 0x1c, 0x3e, 0x77, 0x63 };
713         theme_close_mask = pixmap_mask_new(7, 7, data);
714     }        
715
716     /* read the decoration textures */
717     if (!read_appearance(db, "window.title.focus", theme_a_focused_title))
718         set_default_appearance(theme_a_focused_title);
719     if (!read_appearance(db, "window.title.unfocus", theme_a_unfocused_title))
720         set_default_appearance(theme_a_unfocused_title);
721     if (!read_appearance(db, "window.label.focus", theme_a_focused_label))
722         set_default_appearance(theme_a_focused_label);
723     if (!read_appearance(db, "window.label.unfocus", theme_a_unfocused_label))
724         set_default_appearance(theme_a_unfocused_label);
725     if (!read_appearance(db, "window.handle.focus", theme_a_focused_handle))
726         set_default_appearance(theme_a_focused_handle);
727     if (!read_appearance(db, "window.handle.unfocus",theme_a_unfocused_handle))
728         set_default_appearance(theme_a_unfocused_handle);
729     if (!read_appearance(db, "window.grip.focus", theme_a_focused_grip))
730         set_default_appearance(theme_a_focused_grip);
731     if (!read_appearance(db, "window.grip.unfocus", theme_a_unfocused_grip))
732         set_default_appearance(theme_a_unfocused_grip);
733     if (!read_appearance(db, "menu.frame", theme_a_menu))
734         set_default_appearance(theme_a_menu);
735     if (!read_appearance(db, "menu.title", theme_a_menu_title))
736         set_default_appearance(theme_a_menu_title);
737     if (!read_appearance(db, "menu.hilite", theme_a_menu_hilite))
738         set_default_appearance(theme_a_menu_hilite);
739
740     /* read the appearances for rendering non-decorations */
741     if (!read_appearance(db, "window.title.focus", theme_app_hilite_bg))
742         set_default_appearance(theme_app_hilite_bg);
743     if (!read_appearance(db, "window.label.focus", theme_app_hilite_label))
744         set_default_appearance(theme_app_hilite_label);
745     if (!read_appearance(db, "window.title.unfocus", theme_app_unhilite_bg))
746         set_default_appearance(theme_app_unhilite_bg);
747     if (!read_appearance(db, "window.label.unfocus", theme_app_unhilite_label))
748         set_default_appearance(theme_app_unhilite_label);
749
750     /* read buttons textures */
751     if (!read_appearance(db, "window.button.pressed.focus",
752                          theme_a_focused_pressed_max))
753         if (!read_appearance(db, "window.button.pressed",
754                              theme_a_focused_pressed_max))
755             set_default_appearance(theme_a_focused_pressed_max);
756     if (!read_appearance(db, "window.button.pressed.unfocus",
757                          theme_a_unfocused_pressed_max))
758         if (!read_appearance(db, "window.button.pressed",
759                              theme_a_unfocused_pressed_max))
760             set_default_appearance(theme_a_unfocused_pressed_max);
761     if (!read_appearance(db, "window.button.focus",
762                          theme_a_focused_unpressed_max))
763         set_default_appearance(theme_a_focused_unpressed_max);
764     if (!read_appearance(db, "window.button.unfocus",
765                          theme_a_unfocused_unpressed_max))
766         set_default_appearance(theme_a_unfocused_unpressed_max);
767
768     theme_a_unfocused_unpressed_close =
769         appearance_copy(theme_a_unfocused_unpressed_max);
770     theme_a_unfocused_pressed_close =
771         appearance_copy(theme_a_unfocused_pressed_max);
772     theme_a_focused_unpressed_close =
773         appearance_copy(theme_a_focused_unpressed_max);
774     theme_a_focused_pressed_close =
775         appearance_copy(theme_a_focused_pressed_max);
776     theme_a_unfocused_unpressed_desk =
777         appearance_copy(theme_a_unfocused_unpressed_max);
778     theme_a_unfocused_pressed_desk =
779         appearance_copy(theme_a_unfocused_pressed_max);
780     theme_a_unfocused_pressed_set_desk =
781         appearance_copy(theme_a_unfocused_pressed_max);
782     theme_a_focused_unpressed_desk =
783         appearance_copy(theme_a_focused_unpressed_max);
784     theme_a_focused_pressed_desk =
785         appearance_copy(theme_a_focused_pressed_max);
786     theme_a_focused_pressed_set_desk =
787         appearance_copy(theme_a_focused_pressed_max);
788     theme_a_unfocused_unpressed_shade =
789         appearance_copy(theme_a_unfocused_unpressed_max);
790     theme_a_unfocused_pressed_shade =
791         appearance_copy(theme_a_unfocused_pressed_max);
792     theme_a_unfocused_pressed_set_shade =
793         appearance_copy(theme_a_unfocused_pressed_max);
794     theme_a_focused_unpressed_shade =
795         appearance_copy(theme_a_focused_unpressed_max);
796     theme_a_focused_pressed_shade =
797         appearance_copy(theme_a_focused_pressed_max);
798     theme_a_focused_pressed_set_shade =
799         appearance_copy(theme_a_focused_pressed_max);
800     theme_a_unfocused_unpressed_iconify =
801         appearance_copy(theme_a_unfocused_unpressed_max);
802     theme_a_unfocused_pressed_iconify =
803         appearance_copy(theme_a_unfocused_pressed_max);
804     theme_a_focused_unpressed_iconify =
805         appearance_copy(theme_a_focused_unpressed_max);
806     theme_a_focused_pressed_iconify =
807         appearance_copy(theme_a_focused_pressed_max);
808     theme_a_unfocused_pressed_set_max =
809         appearance_copy(theme_a_unfocused_pressed_max);
810     theme_a_focused_pressed_set_max =
811         appearance_copy(theme_a_focused_pressed_max);
812
813     theme_a_icon->surface.data.planar.grad = Background_ParentRelative;
814
815     /* set up the textures */
816     theme_a_focused_label->texture[0].type = 
817         theme_app_hilite_label->texture[0].type = Text;
818     theme_a_focused_label->texture[0].data.text.justify = winjust;
819     theme_app_hilite_label->texture[0].data.text.justify = Justify_Left;
820     theme_a_focused_label->texture[0].data.text.font =
821         theme_app_hilite_label->texture[0].data.text.font = theme_winfont;
822     theme_a_focused_label->texture[0].data.text.shadow =
823         theme_app_hilite_label->texture[0].data.text.shadow =
824         theme_winfont_shadow;
825     theme_a_focused_label->texture[0].data.text.offset =
826         theme_app_hilite_label->texture[0].data.text.offset =
827         theme_winfont_shadow_offset;
828     theme_a_focused_label->texture[0].data.text.tint =
829         theme_app_hilite_label->texture[0].data.text.tint =
830         theme_winfont_shadow_tint;
831     theme_a_focused_label->texture[0].data.text.color =
832         theme_app_hilite_label->texture[0].data.text.color =
833         theme_title_focused_color;
834
835     theme_a_unfocused_label->texture[0].type =
836         theme_app_unhilite_label->texture[0].type = Text;
837     theme_a_unfocused_label->texture[0].data.text.justify = winjust;
838     theme_app_unhilite_label->texture[0].data.text.justify = Justify_Left;
839     theme_a_unfocused_label->texture[0].data.text.font =
840         theme_app_unhilite_label->texture[0].data.text.font = theme_winfont;
841     theme_a_unfocused_label->texture[0].data.text.shadow =
842         theme_app_unhilite_label->texture[0].data.text.shadow =
843         theme_winfont_shadow;
844     theme_a_unfocused_label->texture[0].data.text.offset =
845         theme_app_unhilite_label->texture[0].data.text.offset =
846         theme_winfont_shadow_offset;
847     theme_a_unfocused_label->texture[0].data.text.tint =
848         theme_app_unhilite_label->texture[0].data.text.tint =
849         theme_winfont_shadow_tint;
850     theme_a_unfocused_label->texture[0].data.text.color =
851         theme_app_unhilite_label->texture[0].data.text.color =
852         theme_title_unfocused_color;
853
854     theme_a_menu_title->texture[0].type = Text;
855     theme_a_menu_title->texture[0].data.text.justify = mtitlejust;
856     theme_a_menu_title->texture[0].data.text.font = theme_mtitlefont;
857     theme_a_menu_title->texture[0].data.text.shadow = theme_mtitlefont_shadow;
858     theme_a_menu_title->texture[0].data.text.offset =
859         theme_mtitlefont_shadow_offset;
860     theme_a_menu_title->texture[0].data.text.tint =
861         theme_mtitlefont_shadow_tint;
862     theme_a_menu_title->texture[0].data.text.color = theme_menu_title_color;
863
864     theme_a_menu_item->surface.data.planar.grad = 
865         theme_a_menu_disabled->surface.data.planar.grad =
866         theme_app_icon->surface.data.planar.grad =
867         Background_ParentRelative;
868
869     theme_a_menu_item->texture[0].type =
870         theme_a_menu_disabled->texture[0].type = 
871         theme_a_menu_hilite->texture[0].type = Text;
872     theme_a_menu_item->texture[0].data.text.justify = 
873         theme_a_menu_disabled->texture[0].data.text.justify = 
874         theme_a_menu_hilite->texture[0].data.text.justify = mjust;
875     theme_a_menu_item->texture[0].data.text.font =
876         theme_a_menu_disabled->texture[0].data.text.font =
877         theme_a_menu_hilite->texture[0].data.text.font = theme_mfont;
878     theme_a_menu_item->texture[0].data.text.shadow = 
879         theme_a_menu_disabled->texture[0].data.text.shadow = 
880         theme_a_menu_hilite->texture[0].data.text.shadow = theme_mfont_shadow;
881     theme_a_menu_item->texture[0].data.text.offset =
882         theme_a_menu_disabled->texture[0].data.text.offset = 
883         theme_a_menu_hilite->texture[0].data.text.offset = 
884         theme_mfont_shadow_offset;
885     theme_a_menu_item->texture[0].data.text.tint =
886         theme_a_menu_disabled->texture[0].data.text.tint =
887         theme_a_menu_hilite->texture[0].data.text.tint =
888         theme_mfont_shadow_tint;
889     theme_a_menu_item->texture[0].data.text.color = theme_menu_color;
890     theme_a_menu_disabled->texture[0].data.text.color =
891         theme_menu_disabled_color;
892     theme_a_menu_hilite->texture[0].data.text.color =  theme_menu_hilite_color;
893
894     theme_a_focused_unpressed_max->texture[0].type = 
895         theme_a_focused_pressed_max->texture[0].type = 
896         theme_a_focused_pressed_set_max->texture[0].type =  
897         theme_a_unfocused_unpressed_max->texture[0].type = 
898         theme_a_unfocused_pressed_max->texture[0].type = 
899         theme_a_unfocused_pressed_set_max->texture[0].type = 
900         theme_a_focused_unpressed_close->texture[0].type = 
901         theme_a_focused_pressed_close->texture[0].type = 
902         theme_a_unfocused_unpressed_close->texture[0].type = 
903         theme_a_unfocused_pressed_close->texture[0].type = 
904         theme_a_focused_unpressed_desk->texture[0].type = 
905         theme_a_focused_pressed_desk->texture[0].type = 
906         theme_a_focused_pressed_set_desk->texture[0].type = 
907         theme_a_unfocused_unpressed_desk->texture[0].type = 
908         theme_a_unfocused_pressed_desk->texture[0].type = 
909         theme_a_unfocused_pressed_set_desk->texture[0].type = 
910         theme_a_focused_unpressed_shade->texture[0].type = 
911         theme_a_focused_pressed_shade->texture[0].type = 
912         theme_a_focused_pressed_set_shade->texture[0].type = 
913         theme_a_unfocused_unpressed_shade->texture[0].type = 
914         theme_a_unfocused_pressed_shade->texture[0].type = 
915         theme_a_unfocused_pressed_set_shade->texture[0].type = 
916         theme_a_focused_unpressed_iconify->texture[0].type = 
917         theme_a_focused_pressed_iconify->texture[0].type = 
918         theme_a_unfocused_unpressed_iconify->texture[0].type = 
919         theme_a_unfocused_pressed_iconify->texture[0].type = Bitmask;
920     theme_a_focused_unpressed_max->texture[0].data.mask.mask = 
921         theme_a_unfocused_unpressed_max->texture[0].data.mask.mask = 
922         theme_a_focused_pressed_max->texture[0].data.mask.mask = 
923         theme_a_unfocused_pressed_max->texture[0].data.mask.mask =
924         theme_max_unset_mask;
925     theme_a_focused_pressed_set_max->texture[0].data.mask.mask = 
926         theme_a_unfocused_pressed_set_max->texture[0].data.mask.mask =
927         theme_max_set_mask;
928     theme_a_focused_pressed_close->texture[0].data.mask.mask = 
929         theme_a_unfocused_pressed_close->texture[0].data.mask.mask =
930         theme_a_focused_unpressed_close->texture[0].data.mask.mask = 
931         theme_a_unfocused_unpressed_close->texture[0].data.mask.mask =
932         theme_close_mask;
933     theme_a_focused_unpressed_desk->texture[0].data.mask.mask = 
934         theme_a_unfocused_unpressed_desk->texture[0].data.mask.mask = 
935         theme_a_focused_pressed_desk->texture[0].data.mask.mask = 
936         theme_a_unfocused_pressed_desk->texture[0].data.mask.mask =
937         theme_desk_unset_mask;
938     theme_a_focused_pressed_set_desk->texture[0].data.mask.mask = 
939         theme_a_unfocused_pressed_set_desk->texture[0].data.mask.mask =
940         theme_desk_set_mask;
941     theme_a_focused_unpressed_shade->texture[0].data.mask.mask = 
942         theme_a_unfocused_unpressed_shade->texture[0].data.mask.mask = 
943         theme_a_focused_pressed_shade->texture[0].data.mask.mask = 
944         theme_a_unfocused_pressed_shade->texture[0].data.mask.mask =
945         theme_shade_unset_mask;
946     theme_a_focused_pressed_set_shade->texture[0].data.mask.mask = 
947         theme_a_unfocused_pressed_set_shade->texture[0].data.mask.mask =
948         theme_shade_set_mask;
949     theme_a_focused_unpressed_iconify->texture[0].data.mask.mask = 
950         theme_a_unfocused_unpressed_iconify->texture[0].data.mask.mask = 
951         theme_a_focused_pressed_iconify->texture[0].data.mask.mask = 
952         theme_a_unfocused_pressed_iconify->texture[0].data.mask.mask =
953         theme_iconify_mask;
954     theme_a_focused_unpressed_max->texture[0].data.mask.color = 
955         theme_a_focused_pressed_max->texture[0].data.mask.color = 
956         theme_a_focused_pressed_set_max->texture[0].data.mask.color = 
957         theme_a_focused_unpressed_close->texture[0].data.mask.color = 
958         theme_a_focused_pressed_close->texture[0].data.mask.color = 
959         theme_a_focused_unpressed_desk->texture[0].data.mask.color = 
960         theme_a_focused_pressed_desk->texture[0].data.mask.color = 
961         theme_a_focused_pressed_set_desk->texture[0].data.mask.color = 
962         theme_a_focused_unpressed_shade->texture[0].data.mask.color = 
963         theme_a_focused_pressed_shade->texture[0].data.mask.color = 
964         theme_a_focused_pressed_set_shade->texture[0].data.mask.color = 
965         theme_a_focused_unpressed_iconify->texture[0].data.mask.color = 
966         theme_a_focused_pressed_iconify->texture[0].data.mask.color =
967         theme_titlebut_focused_color;
968     theme_a_unfocused_unpressed_max->texture[0].data.mask.color = 
969         theme_a_unfocused_pressed_max->texture[0].data.mask.color = 
970         theme_a_unfocused_pressed_set_max->texture[0].data.mask.color = 
971         theme_a_unfocused_unpressed_close->texture[0].data.mask.color = 
972         theme_a_unfocused_pressed_close->texture[0].data.mask.color = 
973         theme_a_unfocused_unpressed_desk->texture[0].data.mask.color = 
974         theme_a_unfocused_pressed_desk->texture[0].data.mask.color = 
975         theme_a_unfocused_pressed_set_desk->texture[0].data.mask.color = 
976         theme_a_unfocused_unpressed_shade->texture[0].data.mask.color = 
977         theme_a_unfocused_pressed_shade->texture[0].data.mask.color = 
978         theme_a_unfocused_pressed_set_shade->texture[0].data.mask.color = 
979         theme_a_unfocused_unpressed_iconify->texture[0].data.mask.color = 
980         theme_a_unfocused_pressed_iconify->texture[0].data.mask.color =
981         theme_titlebut_unfocused_color;
982
983     XrmDestroyDatabase(db);
984
985     return loaded;
986 }