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