]> Dogcows Code - chaz/openbox/blob - render/theme.c
bigtime theme changes. bigtime.
[chaz/openbox] / render / theme.c
1 #include "render.h"
2 #include "color.h"
3 #include "font.h"
4 #include "mask.h"
5 #include "theme.h"
6
7 #include <X11/Xlib.h>
8 #include <X11/Xresource.h>
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 static XrmDatabase loaddb(RrTheme *theme, char *name);
14 static gboolean read_int(XrmDatabase db, char *rname, int *value);
15 static gboolean read_string(XrmDatabase db, char *rname, char **value);
16 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
17 gchar *rname, RrColor **value);
18 static gboolean read_mask(const RrInstance *inst,
19 gchar *maskname, RrTheme *theme,
20 RrPixmapMask **value);
21 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
22 gchar *rname, RrAppearance *value,
23 gboolean allow_trans);
24 static void set_default_appearance(RrAppearance *a);
25
26 RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
27 {
28 XrmDatabase db = NULL;
29 RrJustify winjust, mtitlejust;
30 gchar *str;
31 gchar *font_str;
32 RrTheme *theme;
33
34 theme = g_new0(RrTheme, 1);
35
36 theme->inst = inst;
37
38 theme->show_handle = TRUE;
39
40 theme->a_disabled_focused_max = RrAppearanceNew(inst, 1);
41 theme->a_disabled_unfocused_max = RrAppearanceNew(inst, 1);
42 theme->a_hover_focused_max = RrAppearanceNew(inst, 1);
43 theme->a_hover_unfocused_max = RrAppearanceNew(inst, 1);
44 theme->a_toggled_focused_max = RrAppearanceNew(inst, 1);
45 theme->a_toggled_unfocused_max = RrAppearanceNew(inst, 1);
46 theme->a_focused_unpressed_max = RrAppearanceNew(inst, 1);
47 theme->a_focused_pressed_max = RrAppearanceNew(inst, 1);
48 theme->a_unfocused_unpressed_max = RrAppearanceNew(inst, 1);
49 theme->a_unfocused_pressed_max = RrAppearanceNew(inst, 1);
50 theme->a_focused_grip = RrAppearanceNew(inst, 0);
51 theme->a_unfocused_grip = RrAppearanceNew(inst, 0);
52 theme->a_focused_title = RrAppearanceNew(inst, 0);
53 theme->a_unfocused_title = RrAppearanceNew(inst, 0);
54 theme->a_focused_label = RrAppearanceNew(inst, 1);
55 theme->a_unfocused_label = RrAppearanceNew(inst, 1);
56 theme->a_icon = RrAppearanceNew(inst, 1);
57 theme->a_focused_handle = RrAppearanceNew(inst, 0);
58 theme->a_unfocused_handle = RrAppearanceNew(inst, 0);
59 theme->a_menu = RrAppearanceNew(inst, 0);
60 theme->a_menu_title = RrAppearanceNew(inst, 1);
61 theme->a_menu_normal = RrAppearanceNew(inst, 0);
62 theme->a_menu_disabled = RrAppearanceNew(inst, 0);
63 theme->a_menu_selected = RrAppearanceNew(inst, 0);
64 theme->a_menu_text_normal = RrAppearanceNew(inst, 1);
65 theme->a_menu_text_disabled = RrAppearanceNew(inst, 1);
66 theme->a_menu_text_selected = RrAppearanceNew(inst, 1);
67 theme->a_menu_bullet_normal = RrAppearanceNew(inst, 1);
68 theme->a_menu_bullet_selected = RrAppearanceNew(inst, 1);
69 theme->a_clear = RrAppearanceNew(inst, 0);
70 theme->a_clear_tex = RrAppearanceNew(inst, 1);
71
72 theme->app_hilite_bg = RrAppearanceNew(inst, 0);
73 theme->app_unhilite_bg = RrAppearanceNew(inst, 0);
74 theme->app_hilite_label = RrAppearanceNew(inst, 1);
75 theme->app_unhilite_label = RrAppearanceNew(inst, 1);
76
77 if (name) {
78 db = loaddb(theme, name);
79 if (db == NULL) {
80 g_warning("Failed to load the theme '%s'\n"
81 "Falling back to the default: '%s'",
82 name, DEFAULT_THEME);
83 } else
84 theme->name = g_path_get_basename(name);
85 }
86 if (db == NULL) {
87 db = loaddb(theme, DEFAULT_THEME);
88 if (db == NULL) {
89 g_warning("Failed to load the theme '%s'.", DEFAULT_THEME);
90 return NULL;
91 } else
92 theme->name = g_path_get_basename(DEFAULT_THEME);
93 }
94
95 /* load the font stuff */
96 if (!read_string(db, "window.active.label.text.font", &font_str))
97 font_str = "arial,sans:bold:pixelsize=10:shadow=y:shadowtint=50";
98
99 if (!(theme->winfont_focused = RrFontOpen(inst, font_str))) {
100 RrThemeFree(theme);
101 return NULL;
102 }
103 theme->winfont_height = RrFontHeight(theme->winfont_focused);
104
105 if (!read_string(db, "window.inactive.label.text.font", &font_str))
106 /* font_str will already be set to the last one */;
107
108 if (!(theme->winfont_unfocused = RrFontOpen(inst, font_str))) {
109 RrThemeFree(theme);
110 return NULL;
111 }
112 theme->winfont_height = MAX(theme->winfont_height,
113 RrFontHeight(theme->winfont_unfocused));
114
115 winjust = RR_JUSTIFY_LEFT;
116 if (read_string(db, "window.label.text.justify", &str)) {
117 if (!g_ascii_strcasecmp(str, "right"))
118 winjust = RR_JUSTIFY_RIGHT;
119 else if (!g_ascii_strcasecmp(str, "center"))
120 winjust = RR_JUSTIFY_CENTER;
121 }
122
123 if (!read_string(db, "menu.title.text.font", &font_str))
124 font_str = "arial,sans:bold:pixelsize=12:shadow=y";
125
126 if (!(theme->mtitlefont = RrFontOpen(inst, font_str))) {
127 RrThemeFree(theme);
128 return NULL;
129 }
130 theme->mtitlefont_height = RrFontHeight(theme->mtitlefont);
131
132 mtitlejust = RR_JUSTIFY_LEFT;
133 if (read_string(db, "menu.title.text.justify", &str)) {
134 if (!g_ascii_strcasecmp(str, "right"))
135 mtitlejust = RR_JUSTIFY_RIGHT;
136 else if (!g_ascii_strcasecmp(str, "center"))
137 mtitlejust = RR_JUSTIFY_CENTER;
138 }
139
140 if (!read_string(db, "menu.items.font", &font_str))
141 font_str = "arial,sans:bold:pixelsize=11:shadow=y";
142
143 if (!(theme->mfont = RrFontOpen(inst, font_str))) {
144 RrThemeFree(theme);
145 return NULL;
146 }
147 theme->mfont_height = RrFontHeight(theme->mfont);
148
149 /* load direct dimensions */
150 if (!read_int(db, "menu.overlap", &theme->menu_overlap) ||
151 theme->menu_overlap < 0 || theme->menu_overlap > 20)
152 theme->menu_overlap = 0;
153 if (!read_int(db, "window.handle.width", &theme->handle_height))
154 theme->handle_height = 6;
155 if (!theme->handle_height)
156 theme->show_handle = FALSE;
157 if (theme->handle_height <= 0 || theme->handle_height > 100)
158 theme->handle_height = 6;
159 if (!read_int(db, "padding.width", &theme->padding) ||
160 theme->padding <= 0 || theme->padding > 100)
161 theme->padding = 3;
162 if (!read_int(db, "border.width", &theme->bwidth) ||
163 theme->bwidth < 0 || theme->bwidth > 100)
164 theme->bwidth = 1;
165 if (!read_int(db, "window.client.padding.width", &theme->cbwidth) ||
166 theme->cbwidth < 0 || theme->cbwidth > 100)
167 theme->cbwidth = theme->padding;
168
169 /* load colors */
170 if (!read_color(db, inst,
171 "border.color", &theme->b_color))
172 theme->b_color = RrColorNew(inst, 0, 0, 0);
173 if (!read_color(db, inst,
174 "window.active.client.color",
175 &theme->cb_focused_color))
176 theme->cb_focused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
177 if (!read_color(db, inst,
178 "window.inactive.client.color",
179 &theme->cb_unfocused_color))
180 theme->cb_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
181 if (!read_color(db, inst,
182 "window.active.label.text.color",
183 &theme->title_focused_color))
184 theme->title_focused_color = RrColorNew(inst, 0x0, 0x0, 0x0);
185 if (!read_color(db, inst,
186 "window.inactive.label.text.color",
187 &theme->title_unfocused_color))
188 theme->title_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
189 if (!read_color(db, inst,
190 "window.active.button.unpressed.image.color",
191 &theme->titlebut_focused_unpressed_color))
192 theme->titlebut_focused_unpressed_color = RrColorNew(inst, 0, 0, 0);
193 if (!read_color(db, inst,
194 "window.inactive.button.unpressed.image.color",
195 &theme->titlebut_unfocused_unpressed_color))
196 theme->titlebut_unfocused_unpressed_color =
197 RrColorNew(inst, 0xff, 0xff, 0xff);
198 if (!read_color(db, inst,
199 "window.active.button.pressed.image.color",
200 &theme->titlebut_focused_pressed_color))
201 theme->titlebut_focused_pressed_color =
202 RrColorNew(inst,
203 theme->titlebut_focused_unpressed_color->r,
204 theme->titlebut_focused_unpressed_color->g,
205 theme->titlebut_focused_unpressed_color->b);
206 if (!read_color(db, inst,
207 "window.inactive.button.pressed.image.color",
208 &theme->titlebut_unfocused_pressed_color))
209 theme->titlebut_unfocused_pressed_color =
210 RrColorNew(inst,
211 theme->titlebut_unfocused_unpressed_color->r,
212 theme->titlebut_unfocused_unpressed_color->g,
213 theme->titlebut_unfocused_unpressed_color->b);
214 if (!read_color(db, inst,
215 "window.active.button.disabled.image.color",
216 &theme->titlebut_disabled_focused_color))
217 theme->titlebut_disabled_focused_color =
218 RrColorNew(inst, 0xff, 0xff, 0xff);
219 if (!read_color(db, inst,
220 "window.inactive.button.disabled.image.color",
221 &theme->titlebut_disabled_unfocused_color))
222 theme->titlebut_disabled_unfocused_color = RrColorNew(inst, 0, 0, 0);
223 if (!read_color(db, inst,
224 "window.active.button.hover.image.color",
225 &theme->titlebut_hover_focused_color))
226 theme->titlebut_hover_focused_color =
227 RrColorNew(inst,
228 theme->titlebut_focused_unpressed_color->r,
229 theme->titlebut_focused_unpressed_color->g,
230 theme->titlebut_focused_unpressed_color->b);
231 if (!read_color(db, inst,
232 "window.inactive.button.hover.image.color",
233 &theme->titlebut_hover_unfocused_color))
234 theme->titlebut_hover_unfocused_color =
235 RrColorNew(inst,
236 theme->titlebut_unfocused_unpressed_color->r,
237 theme->titlebut_unfocused_unpressed_color->g,
238 theme->titlebut_unfocused_unpressed_color->b);
239 if (!read_color(db, inst,
240 "window.active.button.toggled.image.color",
241 &theme->titlebut_toggled_focused_color))
242 theme->titlebut_toggled_focused_color =
243 RrColorNew(inst,
244 theme->titlebut_focused_pressed_color->r,
245 theme->titlebut_focused_pressed_color->g,
246 theme->titlebut_focused_pressed_color->b);
247 if (!read_color(db, inst,
248 "window.inactive.button.toggled.image.color",
249 &theme->titlebut_toggled_unfocused_color))
250 theme->titlebut_toggled_unfocused_color =
251 RrColorNew(inst,
252 theme->titlebut_unfocused_pressed_color->r,
253 theme->titlebut_unfocused_pressed_color->g,
254 theme->titlebut_unfocused_pressed_color->b);
255 if (!read_color(db, inst,
256 "menu.title.text.color", &theme->menu_title_color))
257 theme->menu_title_color = RrColorNew(inst, 0, 0, 0);
258 if (!read_color(db, inst,
259 "menu.items.text.color", &theme->menu_color))
260 theme->menu_color = RrColorNew(inst, 0xff, 0xff, 0xff);
261 if (!read_color(db, inst,
262 "menu.items.disabled.text.color",
263 &theme->menu_disabled_color))
264 theme->menu_disabled_color = RrColorNew(inst, 0, 0, 0);
265 if (!read_color(db, inst,
266 "menu.items.active.text.color",
267 &theme->menu_selected_color))
268 theme->menu_selected_color = RrColorNew(inst, 0, 0, 0);
269
270 if (read_mask(inst, "max.xbm", theme, &theme->max_mask)) {
271 if (!read_mask(inst, "max_pressed.xbm", theme,
272 &theme->max_pressed_mask)) {
273 theme->max_pressed_mask = RrPixmapMaskCopy(theme->max_mask);
274 }
275 if (!read_mask(inst, "max_toggled.xbm", theme,
276 &theme->max_toggled_mask)) {
277 theme->max_toggled_mask =
278 RrPixmapMaskCopy(theme->max_pressed_mask);
279 }
280 if (!read_mask(inst, "max_disabled.xbm", theme,
281 &theme->max_disabled_mask)) {
282 theme->max_disabled_mask = RrPixmapMaskCopy(theme->max_mask);
283 }
284 if (!read_mask(inst, "max_hover.xbm", theme, &theme->max_hover_mask)) {
285 theme->max_hover_mask = RrPixmapMaskCopy(theme->max_mask);
286 }
287 } else {
288 {
289 guchar data[] = { 0x7f, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x7f };
290 theme->max_mask = RrPixmapMaskNew(inst, 7, 7, (char*)data);
291 }
292 {
293 guchar data[] = { 0x7c, 0x44, 0x47, 0x47, 0x7f, 0x1f, 0x1f };
294 theme->max_toggled_mask = RrPixmapMaskNew(inst, 7, 7, (char*)data);
295 }
296 theme->max_pressed_mask = RrPixmapMaskCopy(theme->max_mask);
297 theme->max_disabled_mask = RrPixmapMaskCopy(theme->max_mask);
298 theme->max_hover_mask = RrPixmapMaskCopy(theme->max_mask);
299 }
300
301 if (read_mask(inst, "iconify.xbm", theme, &theme->iconify_mask)) {
302 if (!read_mask(inst, "iconify_pressed.xbm", theme,
303 &theme->iconify_pressed_mask)) {
304 theme->iconify_pressed_mask =
305 RrPixmapMaskCopy(theme->iconify_mask);
306 }
307 if (!read_mask(inst, "iconify_disabled.xbm", theme,
308 &theme->iconify_disabled_mask)) {
309 theme->iconify_disabled_mask =
310 RrPixmapMaskCopy(theme->iconify_mask);
311 }
312 if (!read_mask(inst, "iconify_hover.xbm", theme,
313 &theme->iconify_hover_mask)) {
314 theme->iconify_hover_mask = RrPixmapMaskCopy(theme->iconify_mask);
315 }
316 } else {
317 {
318 guchar data[] = { 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x7f };
319 theme->iconify_mask = RrPixmapMaskNew(inst, 7, 7, (char*)data);
320 }
321 theme->iconify_pressed_mask = RrPixmapMaskCopy(theme->iconify_mask);
322 theme->iconify_disabled_mask = RrPixmapMaskCopy(theme->iconify_mask);
323 theme->iconify_hover_mask = RrPixmapMaskCopy(theme->iconify_mask);
324 }
325
326 if (read_mask(inst, "desk.xbm", theme, &theme->desk_mask)) {
327 if (!read_mask(inst, "desk_pressed.xbm", theme,
328 &theme->desk_pressed_mask)) {
329 theme->desk_pressed_mask = RrPixmapMaskCopy(theme->desk_mask);
330 }
331 if (!read_mask(inst, "desk_toggled.xbm", theme,
332 &theme->desk_toggled_mask)) {
333 theme->desk_toggled_mask =
334 RrPixmapMaskCopy(theme->desk_pressed_mask);
335 }
336 if (!read_mask(inst, "desk_disabled.xbm", theme,
337 &theme->desk_disabled_mask)) {
338 theme->desk_disabled_mask = RrPixmapMaskCopy(theme->desk_mask);
339 }
340 if (!read_mask(inst, "desk_hover.xbm", theme,
341 &theme->desk_hover_mask)) {
342 theme->desk_hover_mask = RrPixmapMaskCopy(theme->desk_mask);
343 }
344 } else {
345 {
346 guchar data[] = { 0x63, 0x63, 0x00, 0x00, 0x00, 0x63, 0x63 };
347 theme->desk_mask = RrPixmapMaskNew(inst, 7, 7, (char*)data);
348 }
349 {
350 guchar data[] = { 0x00, 0x36, 0x36, 0x08, 0x36, 0x36, 0x00 };
351 theme->desk_toggled_mask = RrPixmapMaskNew(inst, 7, 7,
352 (char*)data);
353 }
354 theme->desk_pressed_mask = RrPixmapMaskCopy(theme->desk_mask);
355 theme->desk_disabled_mask = RrPixmapMaskCopy(theme->desk_mask);
356 theme->desk_hover_mask = RrPixmapMaskCopy(theme->desk_mask);
357 }
358
359 if (read_mask(inst, "shade.xbm", theme, &theme->shade_mask)) {
360 if (!read_mask(inst, "shade_pressed.xbm", theme,
361 &theme->shade_pressed_mask)) {
362 theme->shade_pressed_mask = RrPixmapMaskCopy(theme->shade_mask);
363 }
364 if (!read_mask(inst, "shade_toggled.xbm", theme,
365 &theme->shade_toggled_mask)) {
366 theme->shade_toggled_mask =
367 RrPixmapMaskCopy(theme->shade_pressed_mask);
368 }
369 if (!read_mask(inst, "shade_disabled.xbm", theme,
370 &theme->shade_disabled_mask)) {
371 theme->shade_disabled_mask = RrPixmapMaskCopy(theme->shade_mask);
372 }
373 if (!read_mask(inst, "shade_hover.xbm", theme,
374 &theme->shade_hover_mask)) {
375 theme->shade_hover_mask = RrPixmapMaskCopy(theme->shade_mask);
376 }
377 } else {
378 {
379 guchar data[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00 };
380 theme->shade_mask = RrPixmapMaskNew(inst, 7, 7, (char*)data);
381 }
382 {
383 guchar data[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x7f };
384 theme->shade_toggled_mask = RrPixmapMaskNew(inst, 7, 7,
385 (char*)data);
386 }
387 theme->shade_pressed_mask = RrPixmapMaskCopy(theme->shade_mask);
388 theme->shade_disabled_mask = RrPixmapMaskCopy(theme->shade_mask);
389 theme->shade_hover_mask = RrPixmapMaskCopy(theme->shade_mask);
390 }
391
392 if (read_mask(inst, "close.xbm", theme, &theme->close_mask)) {
393 if (!read_mask(inst, "close_pressed.xbm", theme,
394 &theme->close_pressed_mask)) {
395 theme->close_pressed_mask = RrPixmapMaskCopy(theme->close_mask);
396 }
397 if (!read_mask(inst, "close_disabled.xbm", theme,
398 &theme->close_disabled_mask)) {
399 theme->close_disabled_mask = RrPixmapMaskCopy(theme->close_mask);
400 }
401 if (!read_mask(inst, "close_hover.xbm", theme,
402 &theme->close_hover_mask)) {
403 theme->close_hover_mask = RrPixmapMaskCopy(theme->close_mask);
404 }
405 } else {
406 {
407 guchar data[] = { 0x63, 0x77, 0x3e, 0x1c, 0x3e, 0x77, 0x63 };
408 theme->close_mask = RrPixmapMaskNew(inst, 7, 7, (char*)data);
409 }
410 theme->close_pressed_mask = RrPixmapMaskCopy(theme->close_mask);
411 theme->close_disabled_mask = RrPixmapMaskCopy(theme->close_mask);
412 theme->close_hover_mask = RrPixmapMaskCopy(theme->close_mask);
413 }
414
415 if (!read_mask(inst, "bullet.xbm", theme, &theme->menu_bullet_mask)) {
416 guchar data[] = { 0x01, 0x03, 0x07, 0x0f, 0x07, 0x03, 0x01 };
417 theme->menu_bullet_mask = RrPixmapMaskNew(inst, 4, 7, (char*)data);
418 }
419
420 /* read the decoration textures */
421 if (!read_appearance(db, inst,
422 "window.active.title.bg", theme->a_focused_title,
423 FALSE))
424 set_default_appearance(theme->a_focused_title);
425 if (!read_appearance(db, inst,
426 "window.inactive.title.bg", theme->a_unfocused_title,
427 FALSE))
428 set_default_appearance(theme->a_unfocused_title);
429 if (!read_appearance(db, inst,
430 "window.active.label.bg", theme->a_focused_label,
431 TRUE))
432 set_default_appearance(theme->a_focused_label);
433 if (!read_appearance(db, inst,
434 "window.inactive.label.bg", theme->a_unfocused_label,
435 TRUE))
436 set_default_appearance(theme->a_unfocused_label);
437 if (!read_appearance(db, inst,
438 "window.active.handle.bg", theme->a_focused_handle,
439 FALSE))
440 set_default_appearance(theme->a_focused_handle);
441 if (!read_appearance(db, inst,
442 "window.inactive.handle.bg",theme->a_unfocused_handle,
443 FALSE))
444 set_default_appearance(theme->a_unfocused_handle);
445 if (!read_appearance(db, inst,
446 "window.active.grip.bg", theme->a_focused_grip,
447 TRUE))
448 set_default_appearance(theme->a_focused_grip);
449 if (!read_appearance(db, inst,
450 "window.inactive.grip.bg", theme->a_unfocused_grip,
451 TRUE))
452 set_default_appearance(theme->a_unfocused_grip);
453 if (!read_appearance(db, inst,
454 "menu.items.bg", theme->a_menu,
455 FALSE))
456 set_default_appearance(theme->a_menu);
457 if (!read_appearance(db, inst,
458 "menu.title.bg", theme->a_menu_title,
459 FALSE))
460 set_default_appearance(theme->a_menu_title);
461 if (!read_appearance(db, inst,
462 "menu.items.active.bg", theme->a_menu_selected,
463 TRUE))
464 set_default_appearance(theme->a_menu_selected);
465
466 /* read the appearances for rendering non-decorations */
467 if (!read_appearance(db, inst,
468 "window.active.title.bg", theme->app_hilite_bg,
469 FALSE))
470 set_default_appearance(theme->app_hilite_bg);
471 if (!read_appearance(db, inst,
472 "window.active.label.bg", theme->app_hilite_label,
473 TRUE))
474 set_default_appearance(theme->app_hilite_label);
475 if (!read_appearance(db, inst,
476 "window.inactive.title.bg", theme->app_unhilite_bg,
477 FALSE))
478 set_default_appearance(theme->app_unhilite_bg);
479 if (!read_appearance(db, inst,
480 "window.inactive.label.bg", theme->app_unhilite_label,
481 TRUE))
482 set_default_appearance(theme->app_unhilite_label);
483
484 /* read buttons textures */
485 if (!read_appearance(db, inst,
486 "window.active.button.disabled.bg",
487 theme->a_disabled_focused_max,
488 TRUE))
489 set_default_appearance(theme->a_disabled_focused_max);
490 if (!read_appearance(db, inst,
491 "window.inactive.button.disabled.bg",
492 theme->a_disabled_unfocused_max,
493 TRUE))
494 set_default_appearance(theme->a_disabled_unfocused_max);
495 if (!read_appearance(db, inst,
496 "window.active.button.pressed.bg",
497 theme->a_focused_pressed_max,
498 TRUE))
499 set_default_appearance(theme->a_focused_pressed_max);
500 if (!read_appearance(db, inst,
501 "window.inactive.button.pressed.bg",
502 theme->a_unfocused_pressed_max,
503 TRUE))
504 set_default_appearance(theme->a_unfocused_pressed_max);
505 if (!read_appearance(db, inst,
506 "window.active.button.toggled.bg",
507 theme->a_toggled_focused_max,
508 TRUE))
509 {
510 RrAppearanceFree(theme->a_toggled_focused_max);
511 theme->a_toggled_focused_max =
512 RrAppearanceCopy(theme->a_focused_pressed_max);
513 }
514 if (!read_appearance(db, inst,
515 "window.inactive.button.toggled.bg",
516 theme->a_toggled_unfocused_max,
517 TRUE))
518 {
519 RrAppearanceFree(theme->a_toggled_unfocused_max);
520 theme->a_toggled_unfocused_max =
521 RrAppearanceCopy(theme->a_unfocused_pressed_max);
522 }
523 if (!read_appearance(db, inst,
524 "window.active.button.unpressed.bg",
525 theme->a_focused_unpressed_max,
526 TRUE))
527 set_default_appearance(theme->a_focused_unpressed_max);
528 if (!read_appearance(db, inst,
529 "window.inactive.button.unpressed.bg",
530 theme->a_unfocused_unpressed_max,
531 TRUE))
532 set_default_appearance(theme->a_unfocused_unpressed_max);
533 if (!read_appearance(db, inst,
534 "window.active.button.hover.bg",
535 theme->a_hover_focused_max,
536 TRUE))
537 {
538 RrAppearanceFree(theme->a_hover_focused_max);
539 theme->a_hover_focused_max =
540 RrAppearanceCopy(theme->a_focused_unpressed_max);
541 }
542 if (!read_appearance(db, inst,
543 "window.inactive.button.hover.bg",
544 theme->a_hover_unfocused_max,
545 TRUE))
546 {
547 RrAppearanceFree(theme->a_hover_unfocused_max);
548 theme->a_hover_unfocused_max =
549 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
550 }
551
552 theme->a_disabled_focused_close =
553 RrAppearanceCopy(theme->a_disabled_focused_max);
554 theme->a_disabled_unfocused_close =
555 RrAppearanceCopy(theme->a_disabled_unfocused_max);
556 theme->a_hover_focused_close =
557 RrAppearanceCopy(theme->a_hover_focused_max);
558 theme->a_hover_unfocused_close =
559 RrAppearanceCopy(theme->a_hover_unfocused_max);
560 theme->a_unfocused_unpressed_close =
561 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
562 theme->a_unfocused_pressed_close =
563 RrAppearanceCopy(theme->a_unfocused_pressed_max);
564 theme->a_focused_unpressed_close =
565 RrAppearanceCopy(theme->a_focused_unpressed_max);
566 theme->a_focused_pressed_close =
567 RrAppearanceCopy(theme->a_focused_pressed_max);
568 theme->a_disabled_focused_desk =
569 RrAppearanceCopy(theme->a_disabled_focused_max);
570 theme->a_disabled_unfocused_desk =
571 RrAppearanceCopy(theme->a_disabled_unfocused_max);
572 theme->a_hover_focused_desk =
573 RrAppearanceCopy(theme->a_hover_focused_max);
574 theme->a_hover_unfocused_desk =
575 RrAppearanceCopy(theme->a_hover_unfocused_max);
576 theme->a_toggled_focused_desk =
577 RrAppearanceCopy(theme->a_toggled_focused_max);
578 theme->a_toggled_unfocused_desk =
579 RrAppearanceCopy(theme->a_toggled_unfocused_max);
580 theme->a_unfocused_unpressed_desk =
581 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
582 theme->a_unfocused_pressed_desk =
583 RrAppearanceCopy(theme->a_unfocused_pressed_max);
584 theme->a_focused_unpressed_desk =
585 RrAppearanceCopy(theme->a_focused_unpressed_max);
586 theme->a_focused_pressed_desk =
587 RrAppearanceCopy(theme->a_focused_pressed_max);
588 theme->a_disabled_focused_shade =
589 RrAppearanceCopy(theme->a_disabled_focused_max);
590 theme->a_disabled_unfocused_shade =
591 RrAppearanceCopy(theme->a_disabled_unfocused_max);
592 theme->a_hover_focused_shade =
593 RrAppearanceCopy(theme->a_hover_focused_max);
594 theme->a_hover_unfocused_shade =
595 RrAppearanceCopy(theme->a_hover_unfocused_max);
596 theme->a_toggled_focused_shade =
597 RrAppearanceCopy(theme->a_toggled_focused_max);
598 theme->a_toggled_unfocused_shade =
599 RrAppearanceCopy(theme->a_toggled_unfocused_max);
600 theme->a_unfocused_unpressed_shade =
601 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
602 theme->a_unfocused_pressed_shade =
603 RrAppearanceCopy(theme->a_unfocused_pressed_max);
604 theme->a_focused_unpressed_shade =
605 RrAppearanceCopy(theme->a_focused_unpressed_max);
606 theme->a_focused_pressed_shade =
607 RrAppearanceCopy(theme->a_focused_pressed_max);
608 theme->a_disabled_focused_iconify =
609 RrAppearanceCopy(theme->a_disabled_focused_max);
610 theme->a_disabled_unfocused_iconify =
611 RrAppearanceCopy(theme->a_disabled_focused_max);
612 theme->a_hover_focused_iconify =
613 RrAppearanceCopy(theme->a_hover_focused_max);
614 theme->a_hover_unfocused_iconify =
615 RrAppearanceCopy(theme->a_hover_unfocused_max);
616 theme->a_unfocused_unpressed_iconify =
617 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
618 theme->a_unfocused_pressed_iconify =
619 RrAppearanceCopy(theme->a_unfocused_pressed_max);
620 theme->a_focused_unpressed_iconify =
621 RrAppearanceCopy(theme->a_focused_unpressed_max);
622 theme->a_focused_pressed_iconify =
623 RrAppearanceCopy(theme->a_focused_pressed_max);
624
625 theme->a_icon->surface.grad =
626 theme->a_clear->surface.grad =
627 theme->a_clear_tex->surface.grad =
628 theme->a_menu_normal->surface.grad =
629 theme->a_menu_disabled->surface.grad =
630 theme->a_menu_text_normal->surface.grad =
631 theme->a_menu_text_disabled->surface.grad =
632 theme->a_menu_text_selected->surface.grad =
633 theme->a_menu_bullet_normal->surface.grad =
634 theme->a_menu_bullet_selected->surface.grad = RR_SURFACE_PARENTREL;
635
636 /* set up the textures */
637 theme->a_focused_label->texture[0].type =
638 theme->app_hilite_label->texture[0].type = RR_TEXTURE_TEXT;
639 theme->a_focused_label->texture[0].data.text.justify = winjust;
640 theme->app_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
641 theme->a_focused_label->texture[0].data.text.font =
642 theme->app_hilite_label->texture[0].data.text.font =
643 theme->winfont_focused;
644 theme->a_focused_label->texture[0].data.text.color =
645 theme->app_hilite_label->texture[0].data.text.color =
646 theme->title_focused_color;
647
648 theme->a_unfocused_label->texture[0].type =
649 theme->app_unhilite_label->texture[0].type = RR_TEXTURE_TEXT;
650 theme->a_unfocused_label->texture[0].data.text.justify = winjust;
651 theme->app_unhilite_label->texture[0].data.text.justify =
652 RR_JUSTIFY_LEFT;
653 theme->a_unfocused_label->texture[0].data.text.font =
654 theme->app_unhilite_label->texture[0].data.text.font =
655 theme->winfont_unfocused;
656 theme->a_unfocused_label->texture[0].data.text.color =
657 theme->app_unhilite_label->texture[0].data.text.color =
658 theme->title_unfocused_color;
659
660 theme->a_menu_title->texture[0].type = RR_TEXTURE_TEXT;
661 theme->a_menu_title->texture[0].data.text.justify = mtitlejust;
662 theme->a_menu_title->texture[0].data.text.font = theme->mtitlefont;
663 theme->a_menu_title->texture[0].data.text.color = theme->menu_title_color;
664
665 theme->a_menu_text_normal->texture[0].type =
666 theme->a_menu_text_disabled->texture[0].type =
667 theme->a_menu_text_selected->texture[0].type = RR_TEXTURE_TEXT;
668 theme->a_menu_text_normal->texture[0].data.text.justify =
669 theme->a_menu_text_disabled->texture[0].data.text.justify =
670 theme->a_menu_text_selected->texture[0].data.text.justify =
671 RR_JUSTIFY_LEFT;
672 theme->a_menu_text_normal->texture[0].data.text.font =
673 theme->a_menu_text_disabled->texture[0].data.text.font =
674 theme->a_menu_text_selected->texture[0].data.text.font = theme->mfont;
675 theme->a_menu_text_normal->texture[0].data.text.color = theme->menu_color;
676 theme->a_menu_text_disabled->texture[0].data.text.color =
677 theme->menu_disabled_color;
678 theme->a_menu_text_selected->texture[0].data.text.color =
679 theme->menu_selected_color;
680
681 theme->a_disabled_focused_max->texture[0].type =
682 theme->a_disabled_unfocused_max->texture[0].type =
683 theme->a_hover_focused_max->texture[0].type =
684 theme->a_hover_unfocused_max->texture[0].type =
685 theme->a_toggled_focused_max->texture[0].type =
686 theme->a_toggled_unfocused_max->texture[0].type =
687 theme->a_focused_unpressed_max->texture[0].type =
688 theme->a_focused_pressed_max->texture[0].type =
689 theme->a_unfocused_unpressed_max->texture[0].type =
690 theme->a_unfocused_pressed_max->texture[0].type =
691 theme->a_disabled_focused_close->texture[0].type =
692 theme->a_disabled_unfocused_close->texture[0].type =
693 theme->a_hover_focused_close->texture[0].type =
694 theme->a_hover_unfocused_close->texture[0].type =
695 theme->a_focused_unpressed_close->texture[0].type =
696 theme->a_focused_pressed_close->texture[0].type =
697 theme->a_unfocused_unpressed_close->texture[0].type =
698 theme->a_unfocused_pressed_close->texture[0].type =
699 theme->a_disabled_focused_desk->texture[0].type =
700 theme->a_disabled_unfocused_desk->texture[0].type =
701 theme->a_hover_focused_desk->texture[0].type =
702 theme->a_hover_unfocused_desk->texture[0].type =
703 theme->a_toggled_focused_desk->texture[0].type =
704 theme->a_toggled_unfocused_desk->texture[0].type =
705 theme->a_focused_unpressed_desk->texture[0].type =
706 theme->a_focused_pressed_desk->texture[0].type =
707 theme->a_unfocused_unpressed_desk->texture[0].type =
708 theme->a_unfocused_pressed_desk->texture[0].type =
709 theme->a_disabled_focused_shade->texture[0].type =
710 theme->a_disabled_unfocused_shade->texture[0].type =
711 theme->a_hover_focused_shade->texture[0].type =
712 theme->a_hover_unfocused_shade->texture[0].type =
713 theme->a_toggled_focused_shade->texture[0].type =
714 theme->a_toggled_unfocused_shade->texture[0].type =
715 theme->a_focused_unpressed_shade->texture[0].type =
716 theme->a_focused_pressed_shade->texture[0].type =
717 theme->a_unfocused_unpressed_shade->texture[0].type =
718 theme->a_unfocused_pressed_shade->texture[0].type =
719 theme->a_disabled_focused_iconify->texture[0].type =
720 theme->a_disabled_unfocused_iconify->texture[0].type =
721 theme->a_hover_focused_iconify->texture[0].type =
722 theme->a_hover_unfocused_iconify->texture[0].type =
723 theme->a_focused_unpressed_iconify->texture[0].type =
724 theme->a_focused_pressed_iconify->texture[0].type =
725 theme->a_unfocused_unpressed_iconify->texture[0].type =
726 theme->a_unfocused_pressed_iconify->texture[0].type =
727 theme->a_menu_bullet_normal->texture[0].type =
728 theme->a_menu_bullet_selected->texture[0].type = RR_TEXTURE_MASK;
729
730 theme->a_disabled_focused_max->texture[0].data.mask.mask =
731 theme->a_disabled_unfocused_max->texture[0].data.mask.mask =
732 theme->max_disabled_mask;
733 theme->a_hover_focused_max->texture[0].data.mask.mask =
734 theme->a_hover_unfocused_max->texture[0].data.mask.mask =
735 theme->max_hover_mask;
736 theme->a_focused_pressed_max->texture[0].data.mask.mask =
737 theme->a_unfocused_pressed_max->texture[0].data.mask.mask =
738 theme->max_pressed_mask;
739 theme->a_focused_unpressed_max->texture[0].data.mask.mask =
740 theme->a_unfocused_unpressed_max->texture[0].data.mask.mask =
741 theme->max_mask;
742 theme->a_toggled_focused_max->texture[0].data.mask.mask =
743 theme->a_toggled_unfocused_max->texture[0].data.mask.mask =
744 theme->max_toggled_mask;
745 theme->a_disabled_focused_close->texture[0].data.mask.mask =
746 theme->a_disabled_unfocused_close->texture[0].data.mask.mask =
747 theme->close_disabled_mask;
748 theme->a_hover_focused_close->texture[0].data.mask.mask =
749 theme->a_hover_unfocused_close->texture[0].data.mask.mask =
750 theme->close_hover_mask;
751 theme->a_focused_pressed_close->texture[0].data.mask.mask =
752 theme->a_unfocused_pressed_close->texture[0].data.mask.mask =
753 theme->close_pressed_mask;
754 theme->a_focused_unpressed_close->texture[0].data.mask.mask =
755 theme->a_unfocused_unpressed_close->texture[0].data.mask.mask =
756 theme->close_mask;
757 theme->a_disabled_focused_desk->texture[0].data.mask.mask =
758 theme->a_disabled_unfocused_desk->texture[0].data.mask.mask =
759 theme->desk_disabled_mask;
760 theme->a_hover_focused_desk->texture[0].data.mask.mask =
761 theme->a_hover_unfocused_desk->texture[0].data.mask.mask =
762 theme->desk_hover_mask;
763 theme->a_focused_pressed_desk->texture[0].data.mask.mask =
764 theme->a_unfocused_pressed_desk->texture[0].data.mask.mask =
765 theme->desk_pressed_mask;
766 theme->a_focused_unpressed_desk->texture[0].data.mask.mask =
767 theme->a_unfocused_unpressed_desk->texture[0].data.mask.mask =
768 theme->desk_mask;
769 theme->a_toggled_focused_desk->texture[0].data.mask.mask =
770 theme->a_toggled_unfocused_desk->texture[0].data.mask.mask =
771 theme->desk_toggled_mask;
772 theme->a_disabled_focused_shade->texture[0].data.mask.mask =
773 theme->a_disabled_unfocused_shade->texture[0].data.mask.mask =
774 theme->shade_disabled_mask;
775 theme->a_hover_focused_shade->texture[0].data.mask.mask =
776 theme->a_hover_unfocused_shade->texture[0].data.mask.mask =
777 theme->shade_hover_mask;
778 theme->a_focused_pressed_shade->texture[0].data.mask.mask =
779 theme->a_unfocused_pressed_shade->texture[0].data.mask.mask =
780 theme->shade_pressed_mask;
781 theme->a_focused_unpressed_shade->texture[0].data.mask.mask =
782 theme->a_unfocused_unpressed_shade->texture[0].data.mask.mask =
783 theme->shade_mask;
784 theme->a_toggled_focused_shade->texture[0].data.mask.mask =
785 theme->a_toggled_unfocused_shade->texture[0].data.mask.mask =
786 theme->shade_toggled_mask;
787 theme->a_disabled_focused_iconify->texture[0].data.mask.mask =
788 theme->a_disabled_unfocused_iconify->texture[0].data.mask.mask =
789 theme->iconify_disabled_mask;
790 theme->a_hover_focused_iconify->texture[0].data.mask.mask =
791 theme->a_hover_unfocused_iconify->texture[0].data.mask.mask =
792 theme->iconify_hover_mask;
793 theme->a_focused_pressed_iconify->texture[0].data.mask.mask =
794 theme->a_unfocused_pressed_iconify->texture[0].data.mask.mask =
795 theme->iconify_pressed_mask;
796 theme->a_focused_unpressed_iconify->texture[0].data.mask.mask =
797 theme->a_unfocused_unpressed_iconify->texture[0].data.mask.mask =
798 theme->iconify_mask;
799 theme->a_menu_bullet_normal->texture[0].data.mask.mask =
800 theme->a_menu_bullet_selected->texture[0].data.mask.mask =
801 theme->menu_bullet_mask;
802 theme->a_disabled_focused_max->texture[0].data.mask.color =
803 theme->a_disabled_focused_close->texture[0].data.mask.color =
804 theme->a_disabled_focused_desk->texture[0].data.mask.color =
805 theme->a_disabled_focused_shade->texture[0].data.mask.color =
806 theme->a_disabled_focused_iconify->texture[0].data.mask.color =
807 theme->titlebut_disabled_focused_color;
808 theme->a_disabled_unfocused_max->texture[0].data.mask.color =
809 theme->a_disabled_unfocused_close->texture[0].data.mask.color =
810 theme->a_disabled_unfocused_desk->texture[0].data.mask.color =
811 theme->a_disabled_unfocused_shade->texture[0].data.mask.color =
812 theme->a_disabled_unfocused_iconify->texture[0].data.mask.color =
813 theme->titlebut_disabled_unfocused_color;
814 theme->a_hover_focused_max->texture[0].data.mask.color =
815 theme->a_hover_focused_close->texture[0].data.mask.color =
816 theme->a_hover_focused_desk->texture[0].data.mask.color =
817 theme->a_hover_focused_shade->texture[0].data.mask.color =
818 theme->a_hover_focused_iconify->texture[0].data.mask.color =
819 theme->titlebut_hover_focused_color;
820 theme->a_hover_unfocused_max->texture[0].data.mask.color =
821 theme->a_hover_unfocused_close->texture[0].data.mask.color =
822 theme->a_hover_unfocused_desk->texture[0].data.mask.color =
823 theme->a_hover_unfocused_shade->texture[0].data.mask.color =
824 theme->a_hover_unfocused_iconify->texture[0].data.mask.color =
825 theme->titlebut_hover_unfocused_color;
826 theme->a_toggled_focused_max->texture[0].data.mask.color =
827 theme->a_toggled_focused_desk->texture[0].data.mask.color =
828 theme->a_toggled_focused_shade->texture[0].data.mask.color =
829 theme->titlebut_toggled_focused_color;
830 theme->a_toggled_unfocused_max->texture[0].data.mask.color =
831 theme->a_toggled_unfocused_desk->texture[0].data.mask.color =
832 theme->a_toggled_unfocused_shade->texture[0].data.mask.color =
833 theme->titlebut_toggled_unfocused_color;
834 theme->a_focused_unpressed_max->texture[0].data.mask.color =
835 theme->a_focused_unpressed_close->texture[0].data.mask.color =
836 theme->a_focused_unpressed_desk->texture[0].data.mask.color =
837 theme->a_focused_unpressed_shade->texture[0].data.mask.color =
838 theme->a_focused_unpressed_iconify->texture[0].data.mask.color =
839 theme->titlebut_focused_unpressed_color;
840 theme->a_focused_pressed_max->texture[0].data.mask.color =
841 theme->a_focused_pressed_close->texture[0].data.mask.color =
842 theme->a_focused_pressed_desk->texture[0].data.mask.color =
843 theme->a_focused_pressed_shade->texture[0].data.mask.color =
844 theme->a_focused_pressed_iconify->texture[0].data.mask.color =
845 theme->titlebut_focused_pressed_color;
846 theme->a_unfocused_unpressed_max->texture[0].data.mask.color =
847 theme->a_unfocused_unpressed_close->texture[0].data.mask.color =
848 theme->a_unfocused_unpressed_desk->texture[0].data.mask.color =
849 theme->a_unfocused_unpressed_shade->texture[0].data.mask.color =
850 theme->a_unfocused_unpressed_iconify->texture[0].data.mask.color =
851 theme->titlebut_unfocused_unpressed_color;
852 theme->a_unfocused_pressed_max->texture[0].data.mask.color =
853 theme->a_unfocused_pressed_close->texture[0].data.mask.color =
854 theme->a_unfocused_pressed_desk->texture[0].data.mask.color =
855 theme->a_unfocused_pressed_shade->texture[0].data.mask.color =
856 theme->a_unfocused_pressed_iconify->texture[0].data.mask.color =
857 theme->titlebut_unfocused_pressed_color;
858 theme->a_menu_bullet_normal->texture[0].data.mask.color =
859 theme->menu_color;
860 theme->a_menu_bullet_selected->texture[0].data.mask.color =
861 theme->menu_selected_color;
862
863 XrmDestroyDatabase(db);
864
865 {
866 gint fl, ft, fr, fb;
867 gint ul, ut, ur, ub;
868
869 RrMargins(theme->a_focused_label, &fl, &ft, &fr, &fb);
870 RrMargins(theme->a_unfocused_label, &ul, &ut, &ur, &ub);
871 theme->label_height = theme->winfont_height
872 + MAX(ft + fb, ut + ub);
873 }
874 theme->title_height = theme->label_height + theme->padding * 2;
875 theme->button_size = theme->label_height - 2;
876 theme->grip_width = theme->title_height * 1.5;
877
878 return theme;
879 }
880
881 void RrThemeFree(RrTheme *theme)
882 {
883 if (theme) {
884 g_free(theme->name);
885
886 RrColorFree(theme->b_color);
887 RrColorFree(theme->cb_unfocused_color);
888 RrColorFree(theme->cb_focused_color);
889 RrColorFree(theme->title_unfocused_color);
890 RrColorFree(theme->title_focused_color);
891 RrColorFree(theme->titlebut_disabled_focused_color);
892 RrColorFree(theme->titlebut_disabled_unfocused_color);
893 RrColorFree(theme->titlebut_hover_focused_color);
894 RrColorFree(theme->titlebut_hover_unfocused_color);
895 RrColorFree(theme->titlebut_toggled_focused_color);
896 RrColorFree(theme->titlebut_toggled_unfocused_color);
897 RrColorFree(theme->titlebut_unfocused_pressed_color);
898 RrColorFree(theme->titlebut_focused_pressed_color);
899 RrColorFree(theme->titlebut_unfocused_unpressed_color);
900 RrColorFree(theme->titlebut_focused_unpressed_color);
901 RrColorFree(theme->menu_color);
902 RrColorFree(theme->menu_title_color);
903 RrColorFree(theme->menu_disabled_color);
904 RrColorFree(theme->menu_selected_color);
905
906 RrPixmapMaskFree(theme->max_mask);
907 RrPixmapMaskFree(theme->max_toggled_mask);
908 RrPixmapMaskFree(theme->max_disabled_mask);
909 RrPixmapMaskFree(theme->max_hover_mask);
910 RrPixmapMaskFree(theme->max_pressed_mask);
911 RrPixmapMaskFree(theme->desk_mask);
912 RrPixmapMaskFree(theme->desk_toggled_mask);
913 RrPixmapMaskFree(theme->desk_disabled_mask);
914 RrPixmapMaskFree(theme->desk_hover_mask);
915 RrPixmapMaskFree(theme->desk_pressed_mask);
916 RrPixmapMaskFree(theme->shade_mask);
917 RrPixmapMaskFree(theme->shade_toggled_mask);
918 RrPixmapMaskFree(theme->shade_disabled_mask);
919 RrPixmapMaskFree(theme->shade_hover_mask);
920 RrPixmapMaskFree(theme->shade_pressed_mask);
921 RrPixmapMaskFree(theme->iconify_mask);
922 RrPixmapMaskFree(theme->iconify_disabled_mask);
923 RrPixmapMaskFree(theme->iconify_hover_mask);
924 RrPixmapMaskFree(theme->iconify_pressed_mask);
925 RrPixmapMaskFree(theme->close_mask);
926 RrPixmapMaskFree(theme->close_disabled_mask);
927 RrPixmapMaskFree(theme->close_hover_mask);
928 RrPixmapMaskFree(theme->close_pressed_mask);
929 RrPixmapMaskFree(theme->menu_bullet_mask);
930
931 RrFontClose(theme->winfont_focused);
932 RrFontClose(theme->winfont_unfocused);
933 RrFontClose(theme->mtitlefont);
934 RrFontClose(theme->mfont);
935
936 RrAppearanceFree(theme->a_disabled_focused_max);
937 RrAppearanceFree(theme->a_disabled_unfocused_max);
938 RrAppearanceFree(theme->a_hover_focused_max);
939 RrAppearanceFree(theme->a_hover_unfocused_max);
940 RrAppearanceFree(theme->a_toggled_focused_max);
941 RrAppearanceFree(theme->a_toggled_unfocused_max);
942 RrAppearanceFree(theme->a_focused_unpressed_max);
943 RrAppearanceFree(theme->a_focused_pressed_max);
944 RrAppearanceFree(theme->a_unfocused_unpressed_max);
945 RrAppearanceFree(theme->a_unfocused_pressed_max);
946 RrAppearanceFree(theme->a_disabled_focused_close);
947 RrAppearanceFree(theme->a_disabled_unfocused_close);
948 RrAppearanceFree(theme->a_hover_focused_close);
949 RrAppearanceFree(theme->a_hover_unfocused_close);
950 RrAppearanceFree(theme->a_focused_unpressed_close);
951 RrAppearanceFree(theme->a_focused_pressed_close);
952 RrAppearanceFree(theme->a_unfocused_unpressed_close);
953 RrAppearanceFree(theme->a_unfocused_pressed_close);
954 RrAppearanceFree(theme->a_disabled_focused_desk);
955 RrAppearanceFree(theme->a_disabled_unfocused_desk);
956 RrAppearanceFree(theme->a_hover_focused_desk);
957 RrAppearanceFree(theme->a_hover_unfocused_desk);
958 RrAppearanceFree(theme->a_toggled_focused_desk);
959 RrAppearanceFree(theme->a_toggled_unfocused_desk);
960 RrAppearanceFree(theme->a_focused_unpressed_desk);
961 RrAppearanceFree(theme->a_focused_pressed_desk);
962 RrAppearanceFree(theme->a_unfocused_unpressed_desk);
963 RrAppearanceFree(theme->a_unfocused_pressed_desk);
964 RrAppearanceFree(theme->a_disabled_focused_shade);
965 RrAppearanceFree(theme->a_disabled_unfocused_shade);
966 RrAppearanceFree(theme->a_hover_focused_shade);
967 RrAppearanceFree(theme->a_hover_unfocused_shade);
968 RrAppearanceFree(theme->a_toggled_focused_shade);
969 RrAppearanceFree(theme->a_toggled_unfocused_shade);
970 RrAppearanceFree(theme->a_focused_unpressed_shade);
971 RrAppearanceFree(theme->a_focused_pressed_shade);
972 RrAppearanceFree(theme->a_unfocused_unpressed_shade);
973 RrAppearanceFree(theme->a_unfocused_pressed_shade);
974 RrAppearanceFree(theme->a_disabled_focused_iconify);
975 RrAppearanceFree(theme->a_disabled_unfocused_iconify);
976 RrAppearanceFree(theme->a_hover_focused_iconify);
977 RrAppearanceFree(theme->a_hover_unfocused_iconify);
978 RrAppearanceFree(theme->a_focused_unpressed_iconify);
979 RrAppearanceFree(theme->a_focused_pressed_iconify);
980 RrAppearanceFree(theme->a_unfocused_unpressed_iconify);
981 RrAppearanceFree(theme->a_unfocused_pressed_iconify);
982 RrAppearanceFree(theme->a_focused_grip);
983 RrAppearanceFree(theme->a_unfocused_grip);
984 RrAppearanceFree(theme->a_focused_title);
985 RrAppearanceFree(theme->a_unfocused_title);
986 RrAppearanceFree(theme->a_focused_label);
987 RrAppearanceFree(theme->a_unfocused_label);
988 RrAppearanceFree(theme->a_icon);
989 RrAppearanceFree(theme->a_focused_handle);
990 RrAppearanceFree(theme->a_unfocused_handle);
991 RrAppearanceFree(theme->a_menu);
992 RrAppearanceFree(theme->a_menu_title);
993 RrAppearanceFree(theme->a_menu_normal);
994 RrAppearanceFree(theme->a_menu_disabled);
995 RrAppearanceFree(theme->a_menu_selected);
996 RrAppearanceFree(theme->a_menu_text_normal);
997 RrAppearanceFree(theme->a_menu_text_disabled);
998 RrAppearanceFree(theme->a_menu_text_selected);
999 RrAppearanceFree(theme->a_menu_bullet_normal);
1000 RrAppearanceFree(theme->a_menu_bullet_selected);
1001 RrAppearanceFree(theme->a_clear);
1002 RrAppearanceFree(theme->a_clear_tex);
1003 RrAppearanceFree(theme->app_hilite_bg);
1004 RrAppearanceFree(theme->app_unhilite_bg);
1005 RrAppearanceFree(theme->app_hilite_label);
1006 RrAppearanceFree(theme->app_unhilite_label);
1007 }
1008 }
1009
1010 static XrmDatabase loaddb(RrTheme *theme, char *name)
1011 {
1012 XrmDatabase db;
1013
1014 char *s = g_build_filename(g_get_home_dir(), ".openbox", "themes",
1015 name, "themerc", NULL);
1016 if ((db = XrmGetFileDatabase(s)))
1017 theme->path = g_path_get_dirname(s);
1018 g_free(s);
1019 if (db == NULL) {
1020 char *s = g_build_filename(THEMEDIR, name, "themerc", NULL);
1021 if ((db = XrmGetFileDatabase(s)))
1022 theme->path = g_path_get_dirname(s);
1023 g_free(s);
1024 }
1025 if (db == NULL) {
1026 char *s = g_build_filename(name, "themerc", NULL);
1027 if ((db = XrmGetFileDatabase(s)))
1028 theme->path = g_path_get_dirname(s);
1029 g_free(s);
1030 }
1031
1032 return db;
1033 }
1034
1035 static char *create_class_name(char *rname)
1036 {
1037 char *rclass = g_strdup(rname);
1038 char *p = rclass;
1039
1040 while (TRUE) {
1041 *p = toupper(*p);
1042 p = strchr(p+1, '.');
1043 if (p == NULL) break;
1044 ++p;
1045 if (*p == '\0') break;
1046 }
1047 return rclass;
1048 }
1049
1050 static gboolean read_int(XrmDatabase db, char *rname, int *value)
1051 {
1052 gboolean ret = FALSE;
1053 char *rclass = create_class_name(rname);
1054 char *rettype, *end;
1055 XrmValue retvalue;
1056
1057 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1058 retvalue.addr != NULL) {
1059 *value = (int)strtol(retvalue.addr, &end, 10);
1060 if (end != retvalue.addr)
1061 ret = TRUE;
1062 }
1063
1064 g_free(rclass);
1065 return ret;
1066 }
1067
1068 static gboolean read_string(XrmDatabase db, char *rname, char **value)
1069 {
1070 gboolean ret = FALSE;
1071 char *rclass = create_class_name(rname);
1072 char *rettype;
1073 XrmValue retvalue;
1074
1075 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1076 retvalue.addr != NULL) {
1077 *value = retvalue.addr;
1078 ret = TRUE;
1079 }
1080
1081 g_free(rclass);
1082 return ret;
1083 }
1084
1085 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
1086 gchar *rname, RrColor **value)
1087 {
1088 gboolean ret = FALSE;
1089 char *rclass = create_class_name(rname);
1090 char *rettype;
1091 XrmValue retvalue;
1092
1093 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1094 retvalue.addr != NULL) {
1095 RrColor *c = RrColorParse(inst, retvalue.addr);
1096 if (c != NULL) {
1097 *value = c;
1098 ret = TRUE;
1099 }
1100 }
1101
1102 g_free(rclass);
1103 return ret;
1104 }
1105
1106 static gboolean read_mask(const RrInstance *inst,
1107 gchar *maskname, RrTheme *theme,
1108 RrPixmapMask **value)
1109 {
1110 gboolean ret = FALSE;
1111 char *s;
1112 int hx, hy; /* ignored */
1113 unsigned int w, h;
1114 unsigned char *b;
1115
1116 s = g_build_filename(theme->path, maskname, NULL);
1117 if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess) {
1118 ret = TRUE;
1119 *value = RrPixmapMaskNew(inst, w, h, (char*)b);
1120 XFree(b);
1121 }
1122 g_free(s);
1123
1124 return ret;
1125 }
1126
1127 static void parse_appearance(gchar *tex, RrSurfaceColorType *grad,
1128 RrReliefType *relief, RrBevelType *bevel,
1129 gboolean *interlaced, gboolean *border,
1130 gboolean allow_trans)
1131 {
1132 char *t;
1133
1134 /* convert to all lowercase */
1135 for (t = tex; *t != '\0'; ++t)
1136 *t = g_ascii_tolower(*t);
1137
1138 if (allow_trans && strstr(tex, "parentrelative") != NULL) {
1139 *grad = RR_SURFACE_PARENTREL;
1140 } else {
1141 if (strstr(tex, "gradient") != NULL) {
1142 if (strstr(tex, "crossdiagonal") != NULL)
1143 *grad = RR_SURFACE_CROSS_DIAGONAL;
1144 else if (strstr(tex, "pyramid") != NULL)
1145 *grad = RR_SURFACE_PYRAMID;
1146 else if (strstr(tex, "horizontal") != NULL)
1147 *grad = RR_SURFACE_HORIZONTAL;
1148 else if (strstr(tex, "vertical") != NULL)
1149 *grad = RR_SURFACE_VERTICAL;
1150 else
1151 *grad = RR_SURFACE_DIAGONAL;
1152 } else {
1153 *grad = RR_SURFACE_SOLID;
1154 }
1155
1156 if (strstr(tex, "sunken") != NULL)
1157 *relief = RR_RELIEF_SUNKEN;
1158 else if (strstr(tex, "flat") != NULL)
1159 *relief = RR_RELIEF_FLAT;
1160 else
1161 *relief = RR_RELIEF_RAISED;
1162
1163 *border = FALSE;
1164 if (*relief == RR_RELIEF_FLAT) {
1165 if (strstr(tex, "border") != NULL)
1166 *border = TRUE;
1167 } else {
1168 if (strstr(tex, "bevel2") != NULL)
1169 *bevel = RR_BEVEL_2;
1170 else
1171 *bevel = RR_BEVEL_1;
1172 }
1173
1174 if (strstr(tex, "interlaced") != NULL)
1175 *interlaced = TRUE;
1176 else
1177 *interlaced = FALSE;
1178 }
1179 }
1180
1181
1182 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
1183 gchar *rname, RrAppearance *value,
1184 gboolean allow_trans)
1185 {
1186 gboolean ret = FALSE;
1187 char *rclass = create_class_name(rname);
1188 char *cname, *ctoname, *bcname, *icname;
1189 char *rettype;
1190 XrmValue retvalue;
1191
1192 cname = g_strconcat(rname, ".color", NULL);
1193 ctoname = g_strconcat(rname, ".colorTo", NULL);
1194 bcname = g_strconcat(rname, ".border.color", NULL);
1195 icname = g_strconcat(rname, ".interlace.color", NULL);
1196
1197 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1198 retvalue.addr != NULL) {
1199 parse_appearance(retvalue.addr,
1200 &value->surface.grad,
1201 &value->surface.relief,
1202 &value->surface.bevel,
1203 &value->surface.interlaced,
1204 &value->surface.border,
1205 allow_trans);
1206 if (!read_color(db, inst, cname, &value->surface.primary))
1207 value->surface.primary = RrColorNew(inst, 0, 0, 0);
1208 if (!read_color(db, inst, ctoname, &value->surface.secondary))
1209 value->surface.secondary = RrColorNew(inst, 0, 0, 0);
1210 if (value->surface.border)
1211 if (!read_color(db, inst, bcname,
1212 &value->surface.border_color))
1213 value->surface.border_color = RrColorNew(inst, 0, 0, 0);
1214 if (value->surface.interlaced)
1215 if (!read_color(db, inst, icname,
1216 &value->surface.interlace_color))
1217 value->surface.interlace_color = RrColorNew(inst, 0, 0, 0);
1218 ret = TRUE;
1219 }
1220
1221 g_free(icname);
1222 g_free(bcname);
1223 g_free(ctoname);
1224 g_free(cname);
1225 g_free(rclass);
1226 return ret;
1227 }
1228
1229 static void set_default_appearance(RrAppearance *a)
1230 {
1231 a->surface.grad = RR_SURFACE_SOLID;
1232 a->surface.relief = RR_RELIEF_FLAT;
1233 a->surface.bevel = RR_BEVEL_1;
1234 a->surface.interlaced = FALSE;
1235 a->surface.border = FALSE;
1236 a->surface.primary = RrColorNew(a->inst, 0, 0, 0);
1237 a->surface.secondary = RrColorNew(a->inst, 0, 0, 0);
1238 }
This page took 0.101451 seconds and 4 git commands to generate.