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