]> icculus.org git repositories - mikachu/openbox.git/blob - tools/themetoxml/themetoxml.c
add osd theme elements
[mikachu/openbox.git] / tools / themetoxml / themetoxml.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    themetoxml.c for the Openbox window manager
4    Copyright (c) 2007        Dana Jansens
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "rgb.h"
20
21 #include <X11/Xlib.h>
22 #include <X11/Xresource.h>
23 #include <glib.h>
24 #include <libxml/parser.h>
25 #include <unistd.h>
26 #include <ctype.h>
27 #include <string.h>
28
29 static gboolean read_int(XrmDatabase db, const gchar *rname, gint *value);
30 static gboolean read_string(XrmDatabase db, const gchar *rname,
31                             const gchar **value);
32 static gboolean read_color(XrmDatabase db, const gchar *rname,
33                            gint *r, gint *g, gint *b);
34
35 static int parse_inline_number(const char *p)
36 {
37     int neg = 1;
38     int res = 0;
39     if (*p == '-') {
40         neg = -1;
41         ++p;
42     }
43     for (; isdigit(*p); ++p)
44         res = res * 10 + *p - '0';
45     res *= neg;
46     return res;
47 }
48
49 static gchar *create_class_name(const gchar *rname)
50 {
51     gchar *rclass = g_strdup(rname);
52     gchar *p = rclass;
53
54     while (TRUE) {
55         *p = toupper(*p);
56         p = strchr(p+1, '.');
57         if (p == NULL) break;
58         ++p;
59         if (*p == '\0') break;
60     }
61     return rclass;
62 }
63
64 static gboolean read_int(XrmDatabase db, const gchar *rname, gint *value)
65 {
66     gboolean ret = FALSE;
67     gchar *rclass = create_class_name(rname);
68     gchar *rettype, *end;
69     XrmValue retvalue;
70   
71     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
72         retvalue.addr != NULL) {
73         *value = (gint)strtol(retvalue.addr, &end, 10);
74         if (end != retvalue.addr)
75             ret = TRUE;
76     }
77
78     g_free(rclass);
79     return ret;
80 }
81
82 static gboolean read_string(XrmDatabase db, const gchar *rname,
83                             const gchar **value)
84 {
85     gboolean ret = FALSE;
86     gchar *rclass = create_class_name(rname);
87     gchar *rettype;
88     XrmValue retvalue;
89   
90     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
91         retvalue.addr != NULL) {
92         *value = g_strstrip(retvalue.addr);
93         ret = TRUE;
94     }
95
96     g_free(rclass);
97     return ret;
98 }
99
100 static gchar hextodec(gchar h)
101 {
102     if (h >= '0' && h <= '9') return h - '0';
103     else if (h >= 'a' && h <= 'f') return h - 'a' + 10;
104     else if (h >= 'A' && h <= 'F') return h - 'A' + 10;
105     return -1;
106 }
107
108 static gboolean parse_color(const gchar *c, gint *r, gint *g, gint *b)
109 {
110     int dig1, dig2, i, color[3];
111     int len = strlen(c);
112
113     if (len > 4 && c[0] == 'r' && c[1] == 'g' && c[2] == 'b' && c[3] == ':') {
114         c += 4;
115         for (i = 0; i < 3; ++i) {
116             dig1 = hextodec(c[0]);
117             if (c[1] == '/' || (c[1] == '\0' && i == 2)) { dig2 = dig1; c+=2; }
118             else { dig2 = hextodec(c[1]); c+=3; }
119
120             if (dig1 < 0 || dig2 < 0) return FALSE;
121             
122             color[i] = dig1*16 + dig2;
123         }
124         *r = color[0]; *g = color[1]; *b = color[2];
125         return TRUE;
126     } else if ((len == 4 || len == 7) && c[0] == '#') {
127         c++;
128         for (i = 0; i < 3; ++i) {
129             dig1 = hextodec(c[0]);
130             if (len == 4) { dig2 = dig1; c++; }
131             else { dig2 = hextodec(c[1]); c+=2; }
132
133             if (dig1 < 0 || dig2 < 0) return FALSE;
134             
135             color[i] = dig1*16 + dig2;
136         }
137         *r = color[0]; *g = color[1]; *b = color[2];
138         return TRUE;
139     } else {
140         int i;
141
142         for (i = 0; colornames[i].name != NULL; ++i) {
143             if (!strcmp(colornames[i].name, c)) {
144                 *r = colornames[i].r;
145                 *g = colornames[i].g;
146                 *b = colornames[i].b;
147                 return TRUE;
148             }
149         }
150     }
151     return FALSE;
152 }
153
154 static gboolean read_color(XrmDatabase db, const gchar *rname,
155                            gint *r, gint *g, gint *b)
156 {
157     gboolean ret = FALSE;
158     gchar *rclass = create_class_name(rname);
159     gchar *rettype;
160     XrmValue retvalue;
161   
162     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
163         retvalue.addr != NULL) {
164         ret = parse_color(retvalue.addr, r, g, b);
165     }
166
167     g_free(rclass);
168     return ret;
169 }
170
171 xmlNodePtr go(xmlNodePtr node, const char *s)
172 {
173     xmlNodePtr p;
174
175     for (p = node->children; p; p = p->next) {
176         if (!xmlStrcasecmp(p->name, (const xmlChar*) s))
177             return p;
178     }
179     return xmlAddChild(node, xmlNewNode(NULL, (const xmlChar*) s));
180 }
181
182 static gchar number[20];
183 static inline gchar* NUM(int i) {
184     g_snprintf(number, 20, "%d", i); return number;
185 }
186 static xmlDocPtr doc;
187 static xmlNodePtr root;
188
189 #define GO1(a) (go(root, a))
190 #define GO2(a,b) (go(GO1(a), b))
191 #define GO3(a,b,c) (go(GO2(a, b), c))
192 #define GO4(a,b,c,d) (go(GO3(a, b, c), d))
193 #define GO5(a,b,c,d,e) (go(GO4(a, b, c, d), e))
194 #define GO6(a,b,c,d,e,f) (go(GO5(a, b, c, d, e), f))
195 #define GO7(a,b,c,d,e,f,g) (go(GO6(a, b, c, d, e, f), g))
196
197 #define CONT1(a,cont) (xmlNodeSetContent(GO1(a), (const xmlChar*)cont))
198 #define CONT2(a,b,cont) (xmlNodeSetContent(GO2(a,b), (const xmlChar*)cont))
199 #define CONT3(a,b,c,cont) (xmlNodeSetContent(GO3(a,b,c), (const xmlChar*)cont))
200 #define CONT4(a,b,c,d,cont) (xmlNodeSetContent(GO4(a,b,c,d), (const xmlChar*)cont))
201 #define CONT5(a,b,c,d,e,cont) (xmlNodeSetContent(GO5(a,b,c,d,e), (const xmlChar*)cont))
202 #define CONT6(a,b,c,d,e,f,cont) (xmlNodeSetContent(GO6(a,b,c,d,e,f), (const xmlChar*)cont))
203
204 #define ATTR1(a,name,cont) (xmlSetProp(GO1(a), (const xmlChar*)name, (const xmlChar*)cont))
205 #define ATTR2(a,b,name,cont) (xmlSetProp(GO2(a,b), (const xmlChar*)name, (const xmlChar*)cont))
206 #define ATTR3(a,b,c,name,cont) (xmlSetProp(GO3(a,b,c), (const xmlChar*)name, (const xmlChar*)cont))
207 #define ATTR4(a,b,c,d,name,cont) (xmlSetProp(GO4(a,b,c,d), (const xmlChar*)name, (const xmlChar*)cont))
208 #define ATTR5(a,b,c,d,e,name,cont) (xmlSetProp(GO5(a,b,c,d,e), (const xmlChar*)name, (const xmlChar*)cont))
209 #define ATTR6(a,b,c,d,e,f,name,cont) (xmlSetProp(GO6(a,b,c,d,e,f), (const xmlChar*)name, (const xmlChar*)cont))
210 #define ATTR7(a,b,c,d,e,f,g,name,cont) (xmlSetProp(GO7(a,b,c,d,e,f,g), (const xmlChar*)name, (const xmlChar*)cont))
211
212 #define COLOR1(a,R,G,B,A) (ATTR1(a,"r",NUM(R)), \
213                            ATTR1(a,"g",NUM(G)), \
214                            ATTR1(a,"b",NUM(B)), \
215                            ATTR1(a,"a",NUM(A)))
216 #define COLOR2(a,b,R,G,B,A) (ATTR2(a,b,"r",NUM(R)), \
217                              ATTR2(a,b,"g",NUM(G)), \
218                              ATTR2(a,b,"b",NUM(B)), \
219                              ATTR2(a,b,"a",NUM(A)))
220 #define COLOR3(a,b,c,R,G,B,A) (ATTR3(a,b,c,"r",NUM(R)), \
221                                ATTR3(a,b,c,"g",NUM(G)), \
222                                ATTR3(a,b,c,"b",NUM(B)), \
223                                ATTR3(a,b,c,"a",NUM(A)))
224 #define COLOR4(a,b,c,d,R,G,B,A) (ATTR4(a,b,c,d,"r",NUM(R)), \
225                                  ATTR4(a,b,c,d,"g",NUM(G)), \
226                                  ATTR4(a,b,c,d,"b",NUM(B)), \
227                                  ATTR4(a,b,c,d,"a",NUM(A)))
228 #define COLOR5(a,b,c,d,e,R,G,B,A) (ATTR5(a,b,c,d,e,"r",NUM(R)), \
229                                    ATTR5(a,b,c,d,e,"g",NUM(G)), \
230                                    ATTR5(a,b,c,d,e,"b",NUM(B)), \
231                                    ATTR5(a,b,c,d,e,"a",NUM(A)))
232 #define COLOR6(a,b,c,d,e,f,R,G,B,A) (ATTR6(a,b,c,d,e,f,"r",NUM(R)), \
233                                      ATTR6(a,b,c,d,e,f,"g",NUM(G)), \
234                                      ATTR6(a,b,c,d,e,f,"b",NUM(B)), \
235                                      ATTR6(a,b,c,d,e,f,"a",NUM(A)))
236
237 #define APPEARANCE2(res,a,b) \
238 { \
239     if (read_string(db, res, &s)) \
240         CONT3(a, b, "style", s); \
241     if (read_color(db, res".color", &i, &j, &k)) \
242         COLOR3(a, b, "primary", i, j, k, 255); \
243     if (read_color(db, res".colorTo", &i, &j, &k)) \
244         COLOR3(a, b, "secondary", i, j, k, 255); \
245     if (read_color(db, res".border.color", &i, &j, &k)) \
246         COLOR3(a, b, "border", i, j, k, 255); \
247     if (read_color(db, res".interlace.color", &i, &j, &k)) \
248         COLOR3(a, b, "interlace", i, j, k, 255); \
249 }
250
251 #define APPEARANCE3(res,a,b,c) \
252 { \
253     if (read_string(db, res, &s)) \
254         CONT4(a, b, c, "style", s); \
255     if (read_color(db, res".color", &i, &j, &k)) \
256         COLOR4(a, b, c, "primary", i, j, k, 255); \
257     if (read_color(db, res".colorTo", &i, &j, &k)) \
258         COLOR4(a, b, c, "secondary", i, j, k, 255); \
259     if (read_color(db, res".border.color", &i, &j, &k)) \
260         COLOR4(a, b, c, "border", i, j, k, 255); \
261     if (read_color(db, res".interlace.color", &i, &j, &k)) \
262         COLOR4(a, b, c, "interlace", i, j, k, 255); \
263 }
264
265 #define APPEARANCE4(res,a,b,c,d) \
266 { \
267     if (read_string(db, res, &s)) \
268         CONT5(a, b, c, d, "style", s); \
269     if (read_color(db, res".color", &i, &j, &k)) \
270         COLOR5(a, b, c, d, "primary", i, j, k, 255); \
271     if (read_color(db, res".colorTo", &i, &j, &k)) \
272         COLOR5(a, b, c, d, "secondary", i, j, k, 255); \
273     if (read_color(db, res".border.color", &i, &j, &k)) \
274         COLOR5(a, b, c, d, "border", i, j, k, 255); \
275     if (read_color(db, res".interlace.color", &i, &j, &k)) \
276         COLOR5(a, b, c, d, "interlace", i, j, k, 255); \
277 }
278
279 int main(int argc, char **argv)
280 {
281     XrmDatabase db;
282     int i,j,k;
283     const gchar *s;
284     int ret = 0;
285
286     if (argc > 2) {
287         fprintf(stderr, "themetoxml (C) 2007 Dana Jansens\n"
288                 "This tool takes an older Openbox3 themerc file and prints "
289                 "out the theme in\n"
290                 "theme in the newer XML (themerc.xml) style.\n");
291         return 0;
292     }
293
294     if (argc == 1 || !strcmp(argv[1], "-")) {
295         gchar *buf = g_new(gchar, 1000);
296         gint sz = 1000;
297         gint r = 0, rthis;
298
299         while ((rthis = read(0, buf + r, sz - r)) > 0) {
300             r+=rthis;
301             if (r==sz) {
302                 sz+=1000;
303                 buf = g_renew(gchar,buf,sz);
304             }
305         }
306         
307
308         if ((db = XrmGetStringDatabase(buf)) == NULL) {
309             fprintf(stderr, "Unable to read the database from stdin\n");
310             return 1;
311         }
312         g_free(buf);
313     }
314     else if (argc == 2) {
315         if ((db = XrmGetFileDatabase(argv[1])) == NULL) {
316             fprintf(stderr, "Unable to read the database from %s\n", argv[1]);
317             return 1;
318         }
319     }
320
321
322     doc = xmlNewDoc((const xmlChar*) "1.0");
323     xmlDocSetRootElement
324         (doc,(root = xmlNewNode(NULL, (const xmlChar*)"openbox_theme")));
325     xmlSetProp(root, (const xmlChar*)"engine", (const xmlChar*)"box");
326     xmlSetProp(root, (const xmlChar*)"version", (const xmlChar*)"1");
327     xmlSetProp(root, (const xmlChar*)"xmlns",
328                (const xmlChar*)"http://openbox.org/4.0/themerc");
329     CONT2("about", "author", "");
330     CONT2("about", "email", "");
331     CONT2("about", "webpage", "");
332     CONT2("about", "comment", "");
333
334     if (read_int(db, "window.handle.width", &i))
335         CONT2("dimensions", "handle", NUM(i));
336
337     if (read_int(db, "padding.width", &i)) {
338         ATTR2("dimensions", "padding", "x", NUM(i));
339         ATTR2("dimensions", "padding", "y", NUM(i));
340     }
341     
342     if (read_int(db, "borderWidth", &i)) {
343         CONT3("dimensions", "window", "border", NUM(i));
344         CONT3("dimensions", "menu", "border", NUM(i));
345     } else if (read_int(db, "border.width", &i)) {
346         CONT3("dimensions", "window", "border", NUM(i));
347         CONT3("dimensions", "menu", "border", NUM(i));
348     }
349     if (read_int(db, "menu.border.width", &i)) 
350         CONT3("dimensions", "menu", "border", NUM(i));
351
352     if (read_color(db, "border.color", &i, &j, &k)) {
353         COLOR3("window", "active", "border", i, j, k, 255);
354         COLOR3("window", "active", "titleseparator", i, j, k, 255);
355         COLOR3("window", "inactive", "border", i, j, k, 255);
356         COLOR3("window", "inactive", "titleseparator", i, j, k, 255);
357         COLOR2("menu", "border", i, j, k, 255);
358     }
359     if (read_color(db, "window.active.border.color", &i, &j, &k)) {
360         COLOR3("window", "active", "border", i, j, k, 255);
361         COLOR3("window", "active", "titleseparator", i, j, k, 255);
362     }
363     if (read_color(db, "window.active.title.separator.color", &i, &j, &k))
364         COLOR3("window", "active", "titleseparator", i, j, k, 255);
365     if (read_color(db, "window.inactive.border.color", &i, &j, &k)) {
366         COLOR3("window", "inactive", "border", i, j, k, 255);
367         COLOR3("window", "inactive", "titleseparator", i, j, k, 255);
368     }
369     if (read_color(db, "window.inactive.title.separator.color", &i, &j, &k))
370         COLOR3("window", "inactive", "titleseparator", i, j, k, 255);
371     if (read_color(db, "menu.border.color", &i, &j, &k))
372         COLOR2("menu", "border", i, j, k, 255);
373
374     if (read_int(db, "window.client.padding.width", &i)) {
375         ATTR3("dimensions", "window", "clientpadding", "x", NUM(i));
376         ATTR3("dimensions", "window", "clientpadding", "y", NUM(i));
377     }
378
379     if (read_string(db, "window.label.text.justify", &s)) {
380         if (!g_ascii_strcasecmp(s, "right")) s = "right";
381         else if (!g_ascii_strcasecmp(s, "center")) s = "center";
382         else s = "left";
383         CONT2("window", "justify", s);
384     }
385
386     if (read_string(db, "menu.title.text.justify", &s)) {
387         if (!g_ascii_strcasecmp(s, "right")) s = "right";
388         else if (!g_ascii_strcasecmp(s, "center")) s = "center";
389         else s = "left";
390         CONT2("menu", "justify", s);
391     }
392
393     if (read_int(db, "menu.overlap", &i))
394         CONT2("menu", "overlap", NUM(i));
395
396     if (read_color(db, "window.active.client.color", &i, &j, &k))
397         COLOR3("window","active","clientpadding",i,j,k,255);
398     
399     if (read_color(db, "window.inactive.client.color", &i, &j, &k))
400         COLOR3("window","inactive","clientpadding",i,j,k,255);
401
402     if (read_color(db, "window.active.label.text.color", &i, &j, &k))
403         COLOR5("window","active","label","text","primary",i,j,k,255);
404
405     if (read_color(db, "window.inactive.label.text.color", &i, &j, &k))
406         COLOR5("window","inactive","label","text","primary",i,j,k,255);
407
408     if (read_color(db, "window.active.button.unpressed.image.color",
409                    &i, &j, &k))
410         COLOR5("window","active","buttons","unpressed","image",i,j,k,255);
411
412     if (read_color(db, "window.inactive.button.unpressed.image.color",
413                    &i, &j, &k))
414         COLOR5("window","inactive","buttons","unpressed","image",i,j,k,255);
415
416     if (read_color(db, "window.active.button.pressed.image.color",
417                    &i, &j, &k))
418         COLOR5("window","active","buttons","pressed","image",i,j,k,255);
419
420     if (read_color(db, "window.inactive.button.pressed.image.color",
421                    &i, &j, &k))
422         COLOR5("window","inactive","buttons","pressed","image",i,j,k,255);
423
424     if (read_color(db, "window.active.button.disabled.image.color",
425                    &i, &j, &k))
426         COLOR5("window","active","buttons","disabled","image",i,j,k,255);
427
428     if (read_color(db, "window.inactive.button.disabled.image.color",
429                    &i, &j, &k))
430         COLOR5("window","inactive","buttons","disabled","image",i,j,k,255);
431
432     if (read_color(db, "window.active.button.hover.image.color",
433                    &i, &j, &k))
434         COLOR5("window","active","buttons","hover","image",i,j,k,255);
435
436     if (read_color(db, "window.inactive.button.hover.image.color",
437                    &i, &j, &k))
438         COLOR5("window","inactive","buttons","hover","image",i,j,k,255);
439
440     if (read_color(db, "window.active.button.toggled.image.color",
441                    &i, &j, &k))
442         COLOR5("window","active","buttons","toggled-unpressed","image",i,j,k,255);
443
444     if (read_color(db, "window.inactive.button.toggled.image.color",
445                    &i, &j, &k))
446         COLOR5("window","inactive","buttons","toggled-unpressed","image",i,j,k,255);
447
448     if (read_color(db, "menu.title.text.color",
449                    &i, &j, &k))
450         COLOR4("menu","title","text","primary",i,j,k,255);
451
452     if (read_color(db, "menu.items.text.color",
453                    &i, &j, &k))
454         COLOR3("menu","inactive","primary",i,j,k,255);
455
456     if (read_color(db, "menu.items.disabled.text.color",
457                    &i, &j, &k)) {
458         COLOR3("menu","disabled","primary",i,j,k,255);
459         read_color(db, "menu.items.active.disabled.text.color",
460                    &i, &j, &k); /* read this if we can */
461         COLOR4("menu","active-disabled","text","primary",i,j,k,255);
462     }
463
464     if (read_color(db, "menu.items.active.text.color",
465                    &i, &j, &k))
466         COLOR4("menu","active","text","primary",i,j,k,255);
467
468     if (read_color(db, "osd.label.text.color", &i, &j, &k))
469         COLOR4("osd","label","text","primary",i,j,k,255);
470
471     APPEARANCE3("window.active.title.bg", "window", "active", "titlebar");
472     APPEARANCE3("window.inactive.title.bg", "window", "inactive", "titlebar");
473     APPEARANCE3("window.active.label.bg", "window", "active", "label");
474     APPEARANCE3("window.inactive.label.bg", "window", "inactive", "label");
475     APPEARANCE3("window.active.handle.bg", "window", "active", "handle");
476     APPEARANCE3("window.inactive.handle.bg", "window", "inactive", "handle");
477     APPEARANCE3("window.active.grip.bg", "window", "active", "grip");
478     APPEARANCE3("window.inactive.grip.bg", "window", "inactive", "grip");
479     APPEARANCE2("menu.items.bg", "menu", "entries");
480     APPEARANCE2("menu.items.active.bg", "menu", "active");
481     APPEARANCE2("menu.items.active.bg", "menu", "active-disabled");
482     APPEARANCE2("menu.title.bg", "menu", "title");
483
484     APPEARANCE4("window.active.button.disabled.bg",
485                 "window", "active", "buttons", "disabled");
486     APPEARANCE4("window.inactive.button.disabled.bg",
487                 "window", "inactive", "buttons", "disabled");
488     APPEARANCE4("window.active.button.pressed.bg",
489                 "window", "active", "buttons", "pressed");
490     APPEARANCE4("window.inactive.button.pressed.bg",
491                 "window", "inactive", "buttons", "pressed");
492     APPEARANCE4("window.active.button.toggled.bg",
493                 "window", "active", "buttons", "toggled-unpressed");
494     APPEARANCE4("window.inactive.button.toggled.bg",
495                 "window", "inactive", "buttons", "toggled-unpressed");
496     APPEARANCE4("window.active.button.unpressed.bg",
497                 "window", "active", "buttons", "unpressed");
498     APPEARANCE4("window.inactive.button.unpressed.bg",
499                 "window", "inactive", "buttons", "unpressed");
500     APPEARANCE4("window.active.button.hover.bg",
501                 "window", "active", "buttons", "hover");
502     APPEARANCE4("window.inactive.button.hover.bg",
503                 "window", "inactive", "buttons", "hover");
504
505     APPEARANCE2("osd.bg", "osd", "background");
506     APPEARANCE2("osd.label.bg", "osd", "label");
507     APPEARANCE2("osd.hilight.bg", "osd", "hilight");
508     APPEARANCE2("osd.unhilight.bg", "osd", "unhilight");
509
510     if (read_string(db, "window.active.label.text.font", &s)) {
511         char *p;
512         if (strstr(s, "shadow=y")) {
513             if ((p = strstr(s, "shadowoffset=")))
514                 i = parse_inline_number(p + strlen("shadowoffset="));
515             else
516                 i = 1;
517             ATTR6("window","active","label","text","shadow","offset",
518                      "x",NUM(i));
519             ATTR6("window","active","label","text","shadow","offset",
520                      "y",NUM(i));
521         }
522         if ((p = strstr(s, "shadowtint=")))
523         {
524             i = parse_inline_number(p + strlen("shadowtint="));
525             j = (i > 0 ? 0 : 255);
526             i = ABS(i*255/100);
527             COLOR6("window","active","label","text","shadow","primary",
528                    j,j,j,i);
529         }
530     }
531
532     if (read_string(db, "window.inactive.label.text.font", &s)) {
533         char *p;
534         if (strstr(s, "shadow=y")) {
535             if ((p = strstr(s, "shadowoffset=")))
536                 i = parse_inline_number(p + strlen("shadowoffset="));
537             else
538                 i = 1;
539             ATTR6("window","inactive","label","text","shadow","offset",
540                      "x",NUM(i));
541             ATTR6("window","inactive","label","text","shadow","offset",
542                      "y",NUM(i));
543         }
544         if ((p = strstr(s, "shadowtint=")))
545         {
546             i = parse_inline_number(p + strlen("shadowtint="));
547             j = (i > 0 ? 0 : 255);
548             i = ABS(i*255/100);
549             COLOR6("window","inactive","label","text","shadow","primary",
550                    j,j,j,i);
551         }
552     }
553
554     if (read_string(db, "menu.title.text.font", &s)) {
555         char *p;
556         if (strstr(s, "shadow=y")) {
557             if ((p = strstr(s, "shadowoffset=")))
558                 i = parse_inline_number(p + strlen("shadowoffset="));
559             else
560                 i = 1;
561             ATTR5("menu","title","text","shadow","offset","x",NUM(i));
562             ATTR5("menu","title","text","shadow","offset","y",NUM(i));
563         }
564         if ((p = strstr(s, "shadowtint=")))
565         {
566             i = parse_inline_number(p + strlen("shadowtint="));
567             j = (i > 0 ? 0 : 255);
568             i = ABS(i*255/100);
569             COLOR5("menu","title","text","shadow","primary",j,j,j,i);
570         }
571     }
572
573     if (read_string(db, "menu.items.font", &s)) {
574         char *p;
575         if (strstr(s, "shadow=y")) {
576             if ((p = strstr(s, "shadowoffset=")))
577                 i = parse_inline_number(p + strlen("shadowoffset="));
578             else
579                 i = 1;
580             ATTR4("menu","inactive","shadow","offset","x",NUM(i));
581             ATTR4("menu","inactive","shadow","offset","y",NUM(i));
582             ATTR5("menu","active","text","shadow","offset","x",NUM(i));
583             ATTR5("menu","active","text","shadow","offset","y",NUM(i));
584             ATTR4("menu","disabled","shadow","offset","x",NUM(i));
585             ATTR4("menu","disabled","shadow","offset","y",NUM(i));
586             ATTR5("menu","active-disabled","text","shadow","offset","x",
587                   NUM(i));
588             ATTR5("menu","active-disabled","text","shadow","offset","y",
589                   NUM(i));
590         }
591         if ((p = strstr(s, "shadowtint=")))
592         {
593             i = parse_inline_number(p + strlen("shadowtint="));
594             j = (i > 0 ? 0 : 255);
595             i = ABS(i*255/100);
596             COLOR4("menu","inactive","shadow","primary",j,j,j,i);
597             COLOR5("menu","active","text","shadow","primary",j,j,j,i);
598             COLOR4("menu","disabled","shadow","primary",j,j,j,i);
599             COLOR5("menu","active-disabled","text","shadow","primary",j,j,j,i);
600         }
601     }
602
603     if (read_string(db, "osd.label.text.font", &s)) {
604         char *p;
605         if (strstr(s, "shadow=y")) {
606             if ((p = strstr(s, "shadowoffset=")))
607                 i = parse_inline_number(p + strlen("shadowoffset="));
608             else
609                 i = 1;
610             ATTR5("osd","label","text","shadow","offset","x",NUM(i));
611             ATTR5("osd","label","text","shadow","offset","y",NUM(i));
612         }
613         if ((p = strstr(s, "shadowtint=")))
614         {
615             i = parse_inline_number(p + strlen("shadowtint="));
616             j = (i > 0 ? 0 : 255);
617             i = ABS(i*255/100);
618             COLOR5("osd","label","text","shadow","primary",j,j,j,i);
619         }
620     }
621
622     if (xmlSaveFormatFile("-", doc, 1) < 0) {
623         fprintf(stderr, "Error writing the xml tree\n");
624         ret = 1;
625     }
626
627     xmlFreeDoc(doc);
628     return ret;
629 }