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