1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 theme.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
26 # include "icon-mikamika.h"
30 #include "obt/paths.h"
33 #include <X11/Xresource.h>
39 RrAppearance *focused_disabled;
40 RrAppearance *unfocused_disabled;
41 RrAppearance *focused_hover;
42 RrAppearance *unfocused_hover;
43 RrAppearance *focused_unpressed;
44 RrAppearance *focused_pressed;
45 RrAppearance *unfocused_unpressed;
46 RrAppearance *unfocused_pressed;
47 RrAppearance *focused_hover_toggled;
48 RrAppearance *unfocused_hover_toggled;
49 RrAppearance *focused_unpressed_toggled;
50 RrAppearance *focused_pressed_toggled;
51 RrAppearance *unfocused_unpressed_toggled;
52 RrAppearance *unfocused_pressed_toggled;
55 static XrmDatabase loaddb(const gchar *name, gchar **path);
56 static gboolean read_int(XrmDatabase db, const gchar *rname, gint *value);
57 static gboolean read_string(XrmDatabase db, const gchar *rname, gchar **value);
58 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
59 const gchar *rname, RrColor **value);
60 static gboolean read_mask(const RrInstance *inst, const gchar *path,
61 const gchar *maskname, RrPixmapMask **value);
62 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
63 const gchar *rname, RrAppearance *value,
64 gboolean allow_trans);
65 static int parse_inline_number(const char *p);
66 static RrPixel32* read_c_image(gint width, gint height, const guint8 *data);
67 static void set_default_appearance(RrAppearance *a);
68 static void read_button_styles(XrmDatabase db, const RrInstance *inst,
70 const RrTheme *theme, RrButton *btn,
72 struct fallbacks *fbs,
74 guchar *toggled_mask);
76 static RrFont *get_font(RrFont *target, RrFont **default_font,
77 const RrInstance *inst)
83 /* Only load the default font once */
85 RrFontRef(*default_font);
87 *default_font = RrFontOpenDefault(inst);
93 #define READ_INT(x_resstr, x_var, x_min, x_max, x_def) \
94 if (!read_int(db, x_resstr, & x_var) || \
95 x_var < x_min || x_var > x_max) \
98 #define READ_COLOR(x_resstr, x_var, x_def) \
99 if (!read_color(db, inst, x_resstr, & x_var)) \
102 #define READ_COLOR_(x_res1, x_res2, x_var, x_def) \
103 if (!read_color(db, inst, x_res1, & x_var) && \
104 !read_color(db, inst, x_res2, & x_var)) \
107 #define READ_MASK_COPY(x_file, x_var, x_copysrc) \
108 if (!read_mask(inst, path, x_file, & x_var)) \
109 x_var = RrPixmapMaskCopy(x_copysrc);
111 #define READ_APPEARANCE(x_resstr, x_var, x_parrel) \
112 if (!read_appearance(db, inst, x_resstr, x_var, x_parrel)) \
113 set_default_appearance(x_var);
115 #define READ_APPEARANCE_COPY(x_resstr, x_var, x_parrel, x_defval) \
116 if (!read_appearance(db, inst, x_resstr, x_var, x_parrel)) {\
117 RrAppearanceFree(x_var); \
118 x_var = RrAppearanceCopy(x_defval); }
120 #define READ_APPEARANCE_COPY_TEXTURES(x_resstr, x_var, x_parrel, x_defval, n_tex) \
121 if (!read_appearance(db, inst, x_resstr, x_var, x_parrel)) {\
122 RrAppearanceFree(x_var); \
123 x_var = RrAppearanceCopy(x_defval); \
124 RrAppearanceRemoveTextures(x_var); \
125 RrAppearanceAddTextures(x_var, 5); }
127 #define READ_APPEARANCE_(x_res1, x_res2, x_var, x_parrel, x_defval) \
128 if (!read_appearance(db, inst, x_res1, x_var, x_parrel) && \
129 !read_appearance(db, inst, x_res2, x_var, x_parrel)) {\
130 RrAppearanceFree(x_var); \
131 x_var = RrAppearanceCopy(x_defval); }
133 RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
134 gboolean allow_fallback,
135 RrFont *active_window_font, RrFont *inactive_window_font,
136 RrFont *menu_title_font, RrFont *menu_item_font,
137 RrFont *active_osd_font, RrFont *inactive_osd_font)
139 XrmDatabase db = NULL;
140 RrJustify winjust, mtitlejust;
143 RrFont *default_font = NULL;
145 gint menu_overlap = 0;
146 struct fallbacks fbs;
149 db = loaddb(name, &path);
151 g_message("Unable to load the theme '%s'", name);
153 g_message("Falling back to the default theme '%s'",
155 /* fallback to the default theme */
160 if (allow_fallback) {
161 db = loaddb(DEFAULT_THEME, &path);
163 g_message("Unable to load the theme '%s'", DEFAULT_THEME);
170 /* initialize temp reading textures */
171 fbs.focused_disabled = RrAppearanceNew(inst, 1);
172 fbs.unfocused_disabled = RrAppearanceNew(inst, 1);
173 fbs.focused_hover = RrAppearanceNew(inst, 1);
174 fbs.unfocused_hover = RrAppearanceNew(inst, 1);
175 fbs.focused_unpressed_toggled = RrAppearanceNew(inst, 1);
176 fbs.unfocused_unpressed_toggled = RrAppearanceNew(inst, 1);
177 fbs.focused_hover_toggled = RrAppearanceNew(inst, 1);
178 fbs.unfocused_hover_toggled = RrAppearanceNew(inst, 1);
179 fbs.focused_pressed_toggled = RrAppearanceNew(inst, 1);
180 fbs.unfocused_pressed_toggled = RrAppearanceNew(inst, 1);
181 fbs.focused_unpressed = RrAppearanceNew(inst, 1);
182 fbs.focused_pressed = RrAppearanceNew(inst, 1);
183 fbs.unfocused_unpressed = RrAppearanceNew(inst, 1);
184 fbs.unfocused_pressed = RrAppearanceNew(inst, 1);
186 /* initialize theme */
187 theme = g_slice_new0(RrTheme);
190 theme->name = g_strdup(name ? name : DEFAULT_THEME);
193 theme->btn_max = RrButtonNew(inst);
194 theme->btn_close = RrButtonNew(inst);
195 theme->btn_desk = RrButtonNew(inst);
196 theme->btn_shade = RrButtonNew(inst);
197 theme->btn_iconify = RrButtonNew(inst);
199 /* init appearances */
200 theme->a_focused_grip = RrAppearanceNew(inst, 0);
201 theme->a_unfocused_grip = RrAppearanceNew(inst, 0);
202 theme->a_focused_title = RrAppearanceNew(inst, 0);
203 theme->a_unfocused_title = RrAppearanceNew(inst, 0);
204 theme->a_focused_label = RrAppearanceNew(inst, 1);
205 theme->a_unfocused_label = RrAppearanceNew(inst, 1);
206 theme->a_icon = RrAppearanceNew(inst, 1);
207 theme->a_focused_handle = RrAppearanceNew(inst, 0);
208 theme->a_unfocused_handle = RrAppearanceNew(inst, 0);
209 theme->a_menu = RrAppearanceNew(inst, 0);
210 theme->a_menu_title = RrAppearanceNew(inst, 0);
211 theme->a_menu_text_title = RrAppearanceNew(inst, 1);
212 theme->a_menu_normal = RrAppearanceNew(inst, 0);
213 theme->a_menu_selected = RrAppearanceNew(inst, 0);
214 theme->a_menu_disabled = RrAppearanceNew(inst, 0);
215 /* a_menu_disabled_selected is copied from a_menu_selected */
216 theme->a_menu_text_normal = RrAppearanceNew(inst, 1);
217 theme->a_menu_text_selected = RrAppearanceNew(inst, 1);
218 theme->a_menu_text_disabled = RrAppearanceNew(inst, 1);
219 theme->a_menu_text_disabled_selected = RrAppearanceNew(inst, 1);
220 theme->a_menu_bullet_normal = RrAppearanceNew(inst, 1);
221 theme->a_menu_bullet_selected = RrAppearanceNew(inst, 1);
222 theme->a_clear = RrAppearanceNew(inst, 0);
223 theme->a_clear_tex = RrAppearanceNew(inst, 1);
224 theme->osd_bg = RrAppearanceNew(inst, 0);
225 theme->osd_hilite_label = RrAppearanceNew(inst, 1);
226 theme->osd_hilite_bg = RrAppearanceNew(inst, 0);
227 theme->osd_unhilite_label = RrAppearanceNew(inst, 1);
228 theme->osd_unhilite_bg = RrAppearanceNew(inst, 0);
229 theme->osd_unpressed_button = RrAppearanceNew(inst, 1);
230 theme->osd_pressed_button = RrAppearanceNew(inst, 5);
231 theme->osd_focused_button = RrAppearanceNew(inst, 5);
233 /* load the font stuff */
234 theme->win_font_focused = get_font(active_window_font,
235 &default_font, inst);
236 theme->win_font_unfocused = get_font(inactive_window_font,
237 &default_font, inst);
239 winjust = RR_JUSTIFY_LEFT;
240 if (read_string(db, "window.label.text.justify", &str)) {
241 if (!g_ascii_strcasecmp(str, "right"))
242 winjust = RR_JUSTIFY_RIGHT;
243 else if (!g_ascii_strcasecmp(str, "center"))
244 winjust = RR_JUSTIFY_CENTER;
247 theme->menu_title_font = get_font(menu_title_font, &default_font, inst);
249 mtitlejust = RR_JUSTIFY_LEFT;
250 if (read_string(db, "menu.title.text.justify", &str)) {
251 if (!g_ascii_strcasecmp(str, "right"))
252 mtitlejust = RR_JUSTIFY_RIGHT;
253 else if (!g_ascii_strcasecmp(str, "center"))
254 mtitlejust = RR_JUSTIFY_CENTER;
257 theme->menu_font = get_font(menu_item_font, &default_font, inst);
259 theme->osd_font_hilite = get_font(active_osd_font, &default_font, inst);
260 theme->osd_font_unhilite = get_font(inactive_osd_font, &default_font,inst);
262 /* load direct dimensions */
263 READ_INT("menu.overlap", menu_overlap, -100, 100, 0);
264 READ_INT("menu.overlap.x", theme->menu_overlap_x, -100, 100, menu_overlap);
265 READ_INT("menu.overlap.y", theme->menu_overlap_y, -100, 100, menu_overlap);
266 READ_INT("window.handle.width", theme->handle_height, 0, 100, 6);
267 READ_INT("padding.width", theme->paddingx, 0, 100, 3);
268 READ_INT("padding.height", theme->paddingy, 0, 100, theme->paddingx);
269 READ_INT("border.width", theme->fbwidth, 0, 100, 1);
270 READ_INT("menu.border.width", theme->mbwidth, 0, 100, theme->fbwidth);
271 READ_INT("osd.border.width", theme->obwidth, 0, 100, theme->fbwidth);
272 READ_INT("undecorated.border.width", theme->ubwidth, 0, 100, theme->fbwidth);
273 READ_INT("menu.separator.width", theme->menu_sep_width, 1, 100, 1);
274 READ_INT("menu.separator.padding.width", theme->menu_sep_paddingx, 0, 100, 6);
275 READ_INT("menu.separator.padding.height", theme->menu_sep_paddingy, 0, 100, 3);
276 READ_INT("window.client.padding.width", theme->cbwidthx, 0, 100, theme->paddingx);
277 READ_INT("window.client.padding.height", theme->cbwidthy, 0, 100, theme->cbwidthx);
280 READ_COLOR_("window.active.border.color",
282 theme->frame_focused_border_color,
283 RrColorNew(inst, 0, 0, 0));
284 READ_COLOR("window.undecorated.active.border.color",
285 theme->frame_undecorated_focused_border_color,
286 RrColorCopy(theme->frame_focused_border_color));
287 READ_COLOR("window.active.title.separator.color",
288 theme->title_separator_focused_color,
289 RrColorCopy(theme->frame_focused_border_color));
291 READ_COLOR("window.inactive.border.color",
292 theme->frame_unfocused_border_color,
293 RrColorCopy(theme->frame_focused_border_color));
295 READ_COLOR("window.undecorated.inactive.border.color",
296 theme->frame_undecorated_unfocused_border_color,
297 RrColorCopy(theme->frame_unfocused_border_color));
299 READ_COLOR("window.inactive.title.separator.color",
300 theme->title_separator_unfocused_color,
301 RrColorCopy(theme->frame_unfocused_border_color));
303 READ_COLOR("menu.border.color",
304 theme->menu_border_color,
305 RrColorCopy(theme->frame_focused_border_color));
307 READ_COLOR("osd.border.color",
308 theme->osd_border_color,
309 RrColorCopy(theme->frame_focused_border_color));
311 READ_COLOR("window.active.client.color",
312 theme->cb_focused_color,
313 RrColorNew(inst, 0xff, 0xff, 0xff));
315 READ_COLOR("window.inactive.client.color",
316 theme->cb_unfocused_color,
317 RrColorNew(inst, 0xff, 0xff, 0xff));
319 READ_COLOR("window.active.label.text.color",
320 theme->title_focused_color,
321 RrColorNew(inst, 0x0, 0x0, 0x0));
323 READ_COLOR("window.inactive.label.text.color",
324 theme->title_unfocused_color,
325 RrColorNew(inst, 0xff, 0xff, 0xff));
327 READ_COLOR_("osd.active.label.text.color",
328 "osd.label.text.color",
329 theme->osd_text_active_color,
330 RrColorCopy(theme->title_focused_color));
332 READ_COLOR_("osd.inactive.label.text.color",
333 "osd.label.text.color",
334 theme->osd_text_inactive_color,
335 RrColorCopy(theme->title_unfocused_color));
337 READ_COLOR("window.active.button.unpressed.image.color",
338 theme->titlebut_focused_unpressed_color,
339 RrColorNew(inst, 0, 0, 0));
341 READ_COLOR("window.inactive.button.unpressed.image.color",
342 theme->titlebut_unfocused_unpressed_color,
343 RrColorNew(inst, 0xff, 0xff, 0xff));
345 READ_COLOR("window.active.button.pressed.image.color",
346 theme->titlebut_focused_pressed_color,
347 RrColorCopy(theme->titlebut_focused_unpressed_color));
349 READ_COLOR("window.inactive.button.pressed.image.color",
350 theme->titlebut_unfocused_pressed_color,
351 RrColorCopy(theme->titlebut_unfocused_unpressed_color));
353 READ_COLOR("window.active.button.disabled.image.color",
354 theme->titlebut_focused_disabled_color,
355 RrColorNew(inst, 0xff, 0xff, 0xff));
357 READ_COLOR("window.inactive.button.disabled.image.color",
358 theme->titlebut_unfocused_disabled_color,
359 RrColorNew(inst, 0, 0, 0));
361 READ_COLOR("window.active.button.hover.image.color",
362 theme->titlebut_focused_hover_color,
363 RrColorCopy(theme->titlebut_focused_unpressed_color));
365 READ_COLOR("window.inactive.button.hover.image.color",
366 theme->titlebut_unfocused_hover_color,
367 RrColorCopy(theme->titlebut_unfocused_unpressed_color));
369 READ_COLOR_("window.active.button.toggled.unpressed.image.color",
370 "window.active.button.toggled.image.color",
371 theme->titlebut_focused_unpressed_toggled_color,
372 RrColorCopy(theme->titlebut_focused_pressed_color));
374 READ_COLOR_("window.inactive.button.toggled.unpressed.image.color",
375 "window.inactive.button.toggled.image.color",
376 theme->titlebut_unfocused_unpressed_toggled_color,
377 RrColorCopy(theme->titlebut_unfocused_pressed_color));
379 READ_COLOR("window.active.button.toggled.hover.image.color",
380 theme->titlebut_focused_hover_toggled_color,
381 RrColorCopy(theme->titlebut_focused_unpressed_toggled_color));
383 READ_COLOR("window.inactive.button.toggled.hover.image.color",
384 theme->titlebut_unfocused_hover_toggled_color,
385 RrColorCopy(theme->titlebut_unfocused_unpressed_toggled_color));
387 READ_COLOR("window.active.button.toggled.pressed.image.color",
388 theme->titlebut_focused_pressed_toggled_color,
389 RrColorCopy(theme->titlebut_focused_pressed_color));
391 READ_COLOR("window.inactive.button.toggled.pressed.image.color",
392 theme->titlebut_unfocused_pressed_toggled_color,
393 RrColorCopy(theme->titlebut_unfocused_pressed_color));
395 READ_COLOR("menu.title.text.color",
396 theme->menu_title_color,
397 RrColorNew(inst, 0, 0, 0));
399 READ_COLOR("menu.items.text.color",
401 RrColorNew(inst, 0xff, 0xff, 0xff));
403 READ_COLOR("menu.bullet.image.color",
404 theme->menu_bullet_color,
405 RrColorCopy(theme->menu_color));
407 READ_COLOR("menu.items.disabled.text.color",
408 theme->menu_disabled_color,
409 RrColorNew(inst, 0, 0, 0));
411 READ_COLOR("menu.items.active.disabled.text.color",
412 theme->menu_disabled_selected_color,
413 RrColorCopy(theme->menu_disabled_color));
415 READ_COLOR("menu.items.active.text.color",
416 theme->menu_selected_color,
417 RrColorNew(inst, 0, 0, 0));
419 READ_COLOR("menu.separator.color",
420 theme->menu_sep_color,
421 RrColorCopy(theme->menu_color));
423 READ_COLOR("menu.bullet.selected.image.color",
424 theme->menu_bullet_selected_color,
425 RrColorCopy(theme->menu_selected_color));
427 READ_COLOR("osd.button.unpressed.text.color",
428 theme->osd_unpressed_color,
429 RrColorCopy(theme->osd_text_active_color));
430 READ_COLOR("osd.button.pressed.text.color",
431 theme->osd_pressed_color,
432 RrColorCopy(theme->osd_text_active_color));
433 READ_COLOR("osd.button.focused.text.color",
434 theme->osd_focused_color,
435 RrColorCopy(theme->osd_text_active_color));
436 READ_COLOR("osd.button.pressed.box.color",
437 theme->osd_pressed_lineart,
438 RrColorCopy(theme->titlebut_focused_pressed_color));
439 READ_COLOR("osd.button.focused.box.color",
440 theme->osd_focused_lineart,
441 RrColorCopy(theme->titlebut_focused_hover_color));
443 /* load window buttons */
445 /* bases: unpressed, pressed, disabled */
446 READ_APPEARANCE("window.active.button.unpressed.bg", fbs.focused_unpressed, TRUE);
447 READ_APPEARANCE("window.inactive.button.unpressed.bg", fbs.unfocused_unpressed, TRUE);
448 READ_APPEARANCE("window.active.button.pressed.bg", fbs.focused_pressed, TRUE);
449 READ_APPEARANCE("window.inactive.button.pressed.bg", fbs.unfocused_pressed, TRUE);
450 READ_APPEARANCE("window.active.button.disabled.bg", fbs.focused_disabled, TRUE);
451 READ_APPEARANCE("window.inactive.button.disabled.bg", fbs.unfocused_disabled, TRUE);
454 READ_APPEARANCE_COPY("window.active.button.hover.bg",
455 fbs.focused_hover, TRUE,
456 fbs.focused_unpressed);
457 READ_APPEARANCE_COPY("window.inactive.button.hover.bg",
458 fbs.unfocused_hover, TRUE,
459 fbs.unfocused_unpressed);
461 /* toggled unpressed */
462 READ_APPEARANCE_("window.active.button.toggled.unpressed.bg",
463 "window.active.button.toggled.bg",
464 fbs.focused_unpressed_toggled, TRUE,
465 fbs.focused_pressed);
466 READ_APPEARANCE_("window.inactive.button.toggled.unpressed.bg",
467 "window.inactive.button.toggled.bg",
468 fbs.unfocused_unpressed_toggled, TRUE,
469 fbs.unfocused_pressed);
471 /* toggled pressed */
472 READ_APPEARANCE_COPY("window.active.button.toggled.pressed.bg",
473 fbs.focused_pressed_toggled, TRUE,
474 fbs.focused_pressed);
475 READ_APPEARANCE_COPY("window.inactive.button.toggled.pressed.bg",
476 fbs.unfocused_pressed_toggled, TRUE,
477 fbs.unfocused_pressed);
480 READ_APPEARANCE_COPY("window.active.button.toggled.hover.bg",
481 fbs.focused_hover_toggled, TRUE,
482 fbs.focused_unpressed_toggled);
483 READ_APPEARANCE_COPY("window.inactive.button.toggled.hover.bg",
484 fbs.unfocused_hover_toggled, TRUE,
485 fbs.unfocused_unpressed_toggled);
488 /* now do individual buttons, if specified */
492 guchar normal_mask[] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f };
493 guchar toggled_mask[] = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f };
494 read_button_styles(db, inst, path, theme, theme->btn_max, "max",
495 &fbs, normal_mask, toggled_mask);
500 guchar normal_mask[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 };
501 read_button_styles(db, inst, path, theme, theme->btn_close, "close",
502 &fbs, normal_mask, NULL);
505 /* all desktops button */
507 guchar normal_mask[] = { 0x33, 0x33, 0x00, 0x00, 0x33, 0x33 };
508 guchar toggled_mask[] = { 0x00, 0x1e, 0x1a, 0x16, 0x1e, 0x00 };
509 read_button_styles(db, inst, path, theme, theme->btn_desk, "desk",
510 &fbs, normal_mask, toggled_mask);
515 guchar normal_mask[] = { 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00 };
516 read_button_styles(db, inst, path, theme, theme->btn_shade, "shade",
517 &fbs, normal_mask, normal_mask);
522 guchar normal_mask[] = { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f };
523 read_button_styles(db, inst, path, theme, theme->btn_iconify, "iconify",
524 &fbs, normal_mask, NULL);
527 /* submenu bullet mask */
528 if (!read_mask(inst, path, "bullet.xbm", &theme->menu_bullet_mask))
530 guchar data[] = { 0x01, 0x03, 0x07, 0x0f, 0x07, 0x03, 0x01 };
531 theme->menu_bullet_mask = RrPixmapMaskNew(inst, 4, 7, (gchar*)data);
534 /* up and down arrows */
536 guchar data[] = { 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00 };
537 theme->down_arrow_mask = RrPixmapMaskNew(inst, 9, 4, (gchar*)data);
540 guchar data[] = { 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00 };
541 theme->up_arrow_mask = RrPixmapMaskNew(inst, 9, 4, (gchar*)data);
544 /* setup the default window icon */
545 theme->def_win_icon = read_c_image(OB_DEFAULT_ICON_WIDTH,
546 OB_DEFAULT_ICON_HEIGHT,
547 OB_DEFAULT_ICON_pixel_data);
548 theme->def_win_icon_w = OB_DEFAULT_ICON_WIDTH;
549 theme->def_win_icon_h = OB_DEFAULT_ICON_HEIGHT;
551 /* read the decoration textures */
552 READ_APPEARANCE("window.active.title.bg", theme->a_focused_title, FALSE);
553 READ_APPEARANCE("window.inactive.title.bg", theme->a_unfocused_title, FALSE);
554 READ_APPEARANCE("window.active.label.bg", theme->a_focused_label, TRUE);
555 READ_APPEARANCE("window.inactive.label.bg", theme->a_unfocused_label, TRUE);
556 READ_APPEARANCE("window.active.handle.bg", theme->a_focused_handle, FALSE);
557 READ_APPEARANCE("window.inactive.handle.bg",theme->a_unfocused_handle, FALSE);
558 READ_APPEARANCE("window.active.grip.bg", theme->a_focused_grip, TRUE);
559 READ_APPEARANCE("window.inactive.grip.bg", theme->a_unfocused_grip, TRUE);
560 READ_APPEARANCE("menu.items.bg", theme->a_menu, FALSE);
561 READ_APPEARANCE("menu.title.bg", theme->a_menu_title, TRUE);
562 READ_APPEARANCE("menu.items.active.bg", theme->a_menu_selected, TRUE);
564 theme->a_menu_disabled_selected =
565 RrAppearanceCopy(theme->a_menu_selected);
567 /* read appearances for non-decorations (on-screen-display) */
568 if (!read_appearance(db, inst, "osd.bg", theme->osd_bg, FALSE))
570 RrAppearanceFree(theme->osd_bg);
571 theme->osd_bg = RrAppearanceCopy(theme->a_focused_title);
573 if (!read_appearance(db, inst, "osd.active.label.bg",
574 theme->osd_hilite_label, TRUE) &&
575 !read_appearance(db, inst, "osd.label.bg",
576 theme->osd_hilite_label, TRUE))
578 RrAppearanceFree(theme->osd_hilite_label);
579 theme->osd_hilite_label = RrAppearanceCopy(theme->a_focused_label);
581 if (!read_appearance(db, inst, "osd.inactive.label.bg",
582 theme->osd_unhilite_label, TRUE))
584 RrAppearanceFree(theme->osd_unhilite_label);
585 theme->osd_unhilite_label = RrAppearanceCopy(theme->a_unfocused_label);
587 /* osd_hilite_fg can't be parentrel */
588 if (!read_appearance(db, inst, "osd.hilight.bg",
589 theme->osd_hilite_bg, FALSE))
591 RrAppearanceFree(theme->osd_hilite_bg);
592 if (theme->a_focused_label->surface.grad != RR_SURFACE_PARENTREL)
593 theme->osd_hilite_bg = RrAppearanceCopy(theme->a_focused_label);
595 theme->osd_hilite_bg = RrAppearanceCopy(theme->a_focused_title);
597 /* osd_unhilite_fg can't be parentrel either */
598 if (!read_appearance(db, inst, "osd.unhilight.bg",
599 theme->osd_unhilite_bg, FALSE))
601 RrAppearanceFree(theme->osd_unhilite_bg);
602 if (theme->a_unfocused_label->surface.grad != RR_SURFACE_PARENTREL)
603 theme->osd_unhilite_bg=RrAppearanceCopy(theme->a_unfocused_label);
605 theme->osd_unhilite_bg=RrAppearanceCopy(theme->a_unfocused_title);
609 READ_APPEARANCE_COPY("osd.button.unpressed.bg", theme->osd_unpressed_button, TRUE, fbs.focused_unpressed);
610 READ_APPEARANCE_COPY_TEXTURES("osd.button.pressed.bg", theme->osd_pressed_button, TRUE, fbs.focused_pressed, 5);
611 READ_APPEARANCE_COPY_TEXTURES("osd.button.focused.bg", theme->osd_focused_button, TRUE, fbs.focused_unpressed, 5);
613 theme->a_icon->surface.grad =
614 theme->a_clear->surface.grad =
615 theme->a_clear_tex->surface.grad =
616 theme->a_menu_text_title->surface.grad =
617 theme->a_menu_normal->surface.grad =
618 theme->a_menu_disabled->surface.grad =
619 theme->a_menu_text_normal->surface.grad =
620 theme->a_menu_text_selected->surface.grad =
621 theme->a_menu_text_disabled->surface.grad =
622 theme->a_menu_text_disabled_selected->surface.grad =
623 theme->a_menu_bullet_normal->surface.grad =
624 theme->a_menu_bullet_selected->surface.grad = RR_SURFACE_PARENTREL;
626 /* set up the textures */
627 theme->a_focused_label->texture[0].type = RR_TEXTURE_TEXT;
628 theme->a_focused_label->texture[0].data.text.justify = winjust;
629 theme->a_focused_label->texture[0].data.text.font=theme->win_font_focused;
630 theme->a_focused_label->texture[0].data.text.color =
631 theme->title_focused_color;
633 if (read_string(db, "window.active.label.text.font", &str)) {
637 if (strstr(str, "shadow=y")) {
638 if ((p = strstr(str, "shadowoffset=")))
639 i = parse_inline_number(p + strlen("shadowoffset="));
642 theme->a_focused_label->texture[0].data.text.shadow_offset_x = i;
643 theme->a_focused_label->texture[0].data.text.shadow_offset_y = i;
645 if ((p = strstr(str, "shadowtint="))) {
646 i = parse_inline_number(p + strlen("shadowtint="));
647 j = (i > 0 ? 0 : 255);
650 theme->title_focused_shadow_color = RrColorNew(inst, j, j, j);
651 theme->title_focused_shadow_alpha = i;
653 theme->title_focused_shadow_color = RrColorNew(inst, 0, 0, 0);
654 theme->title_focused_shadow_alpha = 50;
658 theme->a_focused_label->texture[0].data.text.shadow_color = theme->title_focused_shadow_color;
659 theme->a_focused_label->texture[0].data.text.shadow_alpha = theme->title_focused_shadow_alpha;
661 theme->osd_hilite_label->texture[0].type = RR_TEXTURE_TEXT;
662 theme->osd_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
663 theme->osd_hilite_label->texture[0].data.text.font = theme->osd_font_hilite;
664 theme->osd_hilite_label->texture[0].data.text.color = theme->osd_text_active_color;
666 if (read_string(db, "osd.active.label.text.font", &str) ||
667 read_string(db, "osd.label.text.font", &str))
672 if (strstr(str, "shadow=y")) {
673 if ((p = strstr(str, "shadowoffset=")))
674 i = parse_inline_number(p + strlen("shadowoffset="));
677 theme->osd_hilite_label->texture[0].data.text.shadow_offset_x = i;
678 theme->osd_hilite_label->texture[0].data.text.shadow_offset_y = i;
680 if ((p = strstr(str, "shadowtint="))) {
681 i = parse_inline_number(p + strlen("shadowtint="));
682 j = (i > 0 ? 0 : 255);
685 theme->osd_text_active_shadow_color = RrColorNew(inst, j, j, j);
686 theme->osd_text_active_shadow_alpha = i;
688 theme->osd_text_active_shadow_color = RrColorNew(inst, 0, 0, 0);
689 theme->osd_text_active_shadow_alpha = 50;
692 /* inherit the font settings from the focused label */
693 theme->osd_hilite_label->texture[0].data.text.shadow_offset_x =
694 theme->a_focused_label->texture[0].data.text.shadow_offset_x;
695 theme->osd_hilite_label->texture[0].data.text.shadow_offset_y =
696 theme->a_focused_label->texture[0].data.text.shadow_offset_y;
697 if (theme->title_focused_shadow_color)
698 theme->osd_text_active_shadow_color =
699 RrColorCopy(theme->title_focused_shadow_color);
701 theme->osd_text_active_shadow_color = RrColorNew(inst, 0, 0, 0);
702 theme->osd_text_active_shadow_alpha =
703 theme->title_focused_shadow_alpha;
706 theme->osd_hilite_label->texture[0].data.text.shadow_color =
707 theme->osd_text_active_shadow_color;
708 theme->osd_hilite_label->texture[0].data.text.shadow_alpha =
709 theme->osd_text_active_shadow_alpha;
711 theme->osd_unpressed_button->texture[0].type =
712 theme->osd_pressed_button->texture[0].type =
713 theme->osd_focused_button->texture[0].type =
716 theme->osd_unpressed_button->texture[0].data.text.justify =
717 theme->osd_pressed_button->texture[0].data.text.justify =
718 theme->osd_focused_button->texture[0].data.text.justify =
721 theme->osd_unpressed_button->texture[0].data.text.font =
722 theme->osd_pressed_button->texture[0].data.text.font =
723 theme->osd_focused_button->texture[0].data.text.font =
724 theme->osd_font_hilite;
726 theme->osd_unpressed_button->texture[0].data.text.color =
727 theme->osd_unpressed_color;
728 theme->osd_pressed_button->texture[0].data.text.color =
729 theme->osd_pressed_color;
730 theme->osd_focused_button->texture[0].data.text.color =
731 theme->osd_focused_color;
733 theme->osd_pressed_button->texture[1].data.lineart.color =
734 theme->osd_pressed_button->texture[2].data.lineart.color =
735 theme->osd_pressed_button->texture[3].data.lineart.color =
736 theme->osd_pressed_button->texture[4].data.lineart.color =
737 theme->osd_pressed_lineart;
739 theme->osd_focused_button->texture[1].data.lineart.color =
740 theme->osd_focused_button->texture[2].data.lineart.color =
741 theme->osd_focused_button->texture[3].data.lineart.color =
742 theme->osd_focused_button->texture[4].data.lineart.color =
743 theme->osd_focused_lineart;
745 theme->a_unfocused_label->texture[0].type = RR_TEXTURE_TEXT;
746 theme->a_unfocused_label->texture[0].data.text.justify = winjust;
747 theme->a_unfocused_label->texture[0].data.text.font = theme->win_font_unfocused;
748 theme->a_unfocused_label->texture[0].data.text.color = theme->title_unfocused_color;
750 if (read_string(db, "window.inactive.label.text.font", &str)) {
754 if (strstr(str, "shadow=y")) {
755 if ((p = strstr(str, "shadowoffset=")))
756 i = parse_inline_number(p + strlen("shadowoffset="));
759 theme->a_unfocused_label->texture[0].data.text.shadow_offset_x = i;
760 theme->a_unfocused_label->texture[0].data.text.shadow_offset_y = i;
762 if ((p = strstr(str, "shadowtint="))) {
763 i = parse_inline_number(p + strlen("shadowtint="));
764 j = (i > 0 ? 0 : 255);
767 theme->title_unfocused_shadow_color = RrColorNew(inst, j, j, j);
768 theme->title_unfocused_shadow_alpha = i;
770 theme->title_unfocused_shadow_color = RrColorNew(inst, 0, 0, 0);
771 theme->title_unfocused_shadow_alpha = 50;
775 theme->a_unfocused_label->texture[0].data.text.shadow_color =
776 theme->title_unfocused_shadow_color;
777 theme->a_unfocused_label->texture[0].data.text.shadow_alpha =
778 theme->title_unfocused_shadow_alpha;
780 theme->osd_unhilite_label->texture[0].type = RR_TEXTURE_TEXT;
781 theme->osd_unhilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
782 theme->osd_unhilite_label->texture[0].data.text.font =
783 theme->osd_font_unhilite;
784 theme->osd_unhilite_label->texture[0].data.text.color =
785 theme->osd_text_inactive_color;
787 if (read_string(db, "osd.inactive.label.text.font", &str)) {
791 if (strstr(str, "shadow=y")) {
792 if ((p = strstr(str, "shadowoffset=")))
793 i = parse_inline_number(p + strlen("shadowoffset="));
796 theme->osd_unhilite_label->texture[0].data.text.shadow_offset_x=i;
797 theme->osd_unhilite_label->texture[0].data.text.shadow_offset_y=i;
799 if ((p = strstr(str, "shadowtint="))) {
800 i = parse_inline_number(p + strlen("shadowtint="));
801 j = (i > 0 ? 0 : 255);
804 theme->osd_text_inactive_shadow_color = RrColorNew(inst, j, j, j);
805 theme->osd_text_inactive_shadow_alpha = i;
807 theme->osd_text_inactive_shadow_color = RrColorNew(inst, 0, 0, 0);
808 theme->osd_text_inactive_shadow_alpha = 50;
811 /* inherit the font settings from the unfocused label */
812 theme->osd_unhilite_label->texture[0].data.text.shadow_offset_x =
813 theme->a_unfocused_label->texture[0].data.text.shadow_offset_x;
814 theme->osd_unhilite_label->texture[0].data.text.shadow_offset_y =
815 theme->a_unfocused_label->texture[0].data.text.shadow_offset_y;
816 if (theme->title_unfocused_shadow_color)
817 theme->osd_text_inactive_shadow_color =
818 RrColorCopy(theme->title_unfocused_shadow_color);
820 theme->osd_text_inactive_shadow_color = RrColorNew(inst, 0, 0, 0);
821 theme->osd_text_inactive_shadow_alpha =
822 theme->title_unfocused_shadow_alpha;
825 theme->osd_unhilite_label->texture[0].data.text.shadow_color =
826 theme->osd_text_inactive_shadow_color;
827 theme->osd_unhilite_label->texture[0].data.text.shadow_alpha =
828 theme->osd_text_inactive_shadow_alpha;
830 theme->a_menu_text_title->texture[0].type = RR_TEXTURE_TEXT;
831 theme->a_menu_text_title->texture[0].data.text.justify = mtitlejust;
832 theme->a_menu_text_title->texture[0].data.text.font = theme->menu_title_font;
833 theme->a_menu_text_title->texture[0].data.text.color = theme->menu_title_color;
835 if (read_string(db, "menu.title.text.font", &str)) {
839 if (strstr(str, "shadow=y")) {
840 if ((p = strstr(str, "shadowoffset=")))
841 i = parse_inline_number(p + strlen("shadowoffset="));
844 theme->a_menu_text_title->texture[0].data.text.shadow_offset_x = i;
845 theme->a_menu_text_title->texture[0].data.text.shadow_offset_y = i;
847 if ((p = strstr(str, "shadowtint="))) {
848 i = parse_inline_number(p + strlen("shadowtint="));
849 j = (i > 0 ? 0 : 255);
852 theme->menu_title_shadow_color = RrColorNew(inst, j, j, j);
854 theme->menu_title_shadow_color = RrColorNew(inst, 0, 0, 0);
858 theme->a_menu_text_title->texture[0].data.text.shadow_color =
859 theme->menu_title_shadow_color;
860 theme->a_menu_text_title->texture[0].data.text.shadow_alpha =
864 theme->a_menu_text_normal->texture[0].type =
865 theme->a_menu_text_selected->texture[0].type =
866 theme->a_menu_text_disabled->texture[0].type =
867 theme->a_menu_text_disabled_selected->texture[0].type =
869 theme->a_menu_text_normal->texture[0].data.text.justify =
870 theme->a_menu_text_selected->texture[0].data.text.justify =
871 theme->a_menu_text_disabled->texture[0].data.text.justify =
872 theme->a_menu_text_disabled_selected->texture[0].data.text.justify =
874 theme->a_menu_text_normal->texture[0].data.text.font =
875 theme->a_menu_text_selected->texture[0].data.text.font =
876 theme->a_menu_text_disabled->texture[0].data.text.font =
877 theme->a_menu_text_disabled_selected->texture[0].data.text.font =
879 theme->a_menu_text_normal->texture[0].data.text.color = theme->menu_color;
880 theme->a_menu_text_selected->texture[0].data.text.color =
881 theme->menu_selected_color;
882 theme->a_menu_text_disabled->texture[0].data.text.color =
883 theme->menu_disabled_color;
884 theme->a_menu_text_disabled_selected->texture[0].data.text.color =
885 theme->menu_disabled_selected_color;
887 if (read_string(db, "menu.items.font", &str)) {
891 if (strstr(str, "shadow=y")) {
892 if ((p = strstr(str, "shadowoffset=")))
893 i = parse_inline_number(p + strlen("shadowoffset="));
896 theme->a_menu_text_normal->
897 texture[0].data.text.shadow_offset_x = i;
898 theme->a_menu_text_normal->
899 texture[0].data.text.shadow_offset_y = i;
900 theme->a_menu_text_selected->
901 texture[0].data.text.shadow_offset_x = i;
902 theme->a_menu_text_selected->
903 texture[0].data.text.shadow_offset_y = i;
904 theme->a_menu_text_disabled->
905 texture[0].data.text.shadow_offset_x = i;
906 theme->a_menu_text_disabled->
907 texture[0].data.text.shadow_offset_y = i;
908 theme->a_menu_text_disabled_selected->
909 texture[0].data.text.shadow_offset_x = i;
910 theme->a_menu_text_disabled_selected->
911 texture[0].data.text.shadow_offset_y = i;
913 if ((p = strstr(str, "shadowtint="))) {
914 i = parse_inline_number(p + strlen("shadowtint="));
915 j = (i > 0 ? 0 : 255);
918 theme->menu_text_shadow_color = RrColorNew(inst, j, j, j);
920 theme->menu_text_shadow_color = RrColorNew(inst, 0, 0, 0);
924 theme->a_menu_text_normal->texture[0].data.text.shadow_color =
925 theme->a_menu_text_selected->texture[0].data.text.shadow_color =
926 theme->a_menu_text_disabled->texture[0].data.text.shadow_color =
927 theme->a_menu_text_disabled_selected->texture[0].data.text.shadow_color =
928 theme->menu_text_shadow_color;
930 theme->a_menu_text_normal->texture[0].data.text.shadow_alpha =
931 theme->a_menu_text_selected->texture[0].data.text.shadow_alpha =
932 theme->a_menu_text_disabled->texture[0].data.text.shadow_alpha =
933 theme->a_menu_text_disabled_selected->texture[0].data.text.shadow_alpha =
937 theme->a_menu_bullet_normal->texture[0].type =
938 theme->a_menu_bullet_selected->texture[0].type = RR_TEXTURE_MASK;
939 theme->a_menu_bullet_normal->texture[0].data.mask.mask =
940 theme->a_menu_bullet_selected->texture[0].data.mask.mask =
941 theme->menu_bullet_mask;
942 theme->a_menu_bullet_normal->texture[0].data.mask.color =
943 theme->menu_bullet_color;
944 theme->a_menu_bullet_selected->texture[0].data.mask.color =
945 theme->menu_bullet_selected_color;
948 XrmDestroyDatabase(db);
950 /* set the font heights */
951 theme->win_font_height = RrFontHeight(theme->win_font_focused,
952 theme->a_focused_label->texture[0].data.text.shadow_offset_y);
953 theme->win_font_height =
954 MAX(theme->win_font_height,
955 RrFontHeight(theme->win_font_focused,
956 theme->a_unfocused_label->texture[0].data.text.shadow_offset_y));
957 theme->menu_title_font_height = RrFontHeight(theme->menu_title_font,
958 theme->a_menu_text_title->texture[0].data.text.shadow_offset_y);
959 theme->menu_font_height = RrFontHeight(theme->menu_font,
960 theme->a_menu_text_normal->texture[0].data.text.shadow_offset_y);
962 /* calculate some last extents */
964 gint ft, fb, fl, fr, ut, ub, ul, ur;
966 RrMargins(theme->a_focused_label, &fl, &ft, &fr, &fb);
967 RrMargins(theme->a_unfocused_label, &ul, &ut, &ur, &ub);
968 theme->label_height = theme->win_font_height + MAX(ft + fb, ut + ub) + 1;
970 /* this would be nice I think, since padding.width can now be 0,
971 but it breaks frame.c horribly and I don't feel like fixing that
972 right now, so if anyone complains, here is how to keep text from
973 going over the title's bevel/border with a padding.width of 0 and a
974 bevelless/borderless label
975 RrMargins(theme->a_focused_title, &fl, &ft, &fr, &fb);
976 RrMargins(theme->a_unfocused_title, &ul, &ut, &ur, &ub);
977 theme->title_height = theme->label_height +
978 MAX(MAX(theme->padding * 2, ft + fb),
979 MAX(theme->padding * 2, ut + ub));
981 theme->title_height = theme->label_height + theme->paddingy * 2;
983 RrMargins(theme->a_menu_title, &ul, &ut, &ur, &ub);
984 theme->menu_title_label_height = theme->menu_title_font_height+ut+ub;
985 theme->menu_title_height = theme->menu_title_label_height +
988 theme->button_size = theme->label_height - 2;
989 theme->grip_width = 25;
991 RrAppearanceFree(fbs.focused_disabled);
992 RrAppearanceFree(fbs.unfocused_disabled);
993 RrAppearanceFree(fbs.focused_hover);
994 RrAppearanceFree(fbs.unfocused_hover);
995 RrAppearanceFree(fbs.focused_unpressed);
996 RrAppearanceFree(fbs.focused_pressed);
997 RrAppearanceFree(fbs.unfocused_unpressed);
998 RrAppearanceFree(fbs.unfocused_pressed);
999 RrAppearanceFree(fbs.focused_hover_toggled);
1000 RrAppearanceFree(fbs.unfocused_hover_toggled);
1001 RrAppearanceFree(fbs.focused_unpressed_toggled);
1002 RrAppearanceFree(fbs.focused_pressed_toggled);
1003 RrAppearanceFree(fbs.unfocused_unpressed_toggled);
1004 RrAppearanceFree(fbs.unfocused_pressed_toggled);
1009 void RrThemeFree(RrTheme *theme)
1012 g_free(theme->name);
1014 RrButtonFree(theme->btn_max);
1015 RrButtonFree(theme->btn_close);
1016 RrButtonFree(theme->btn_desk);
1017 RrButtonFree(theme->btn_shade);
1018 RrButtonFree(theme->btn_iconify);
1020 RrColorFree(theme->menu_border_color);
1021 RrColorFree(theme->osd_border_color);
1022 RrColorFree(theme->frame_focused_border_color);
1023 RrColorFree(theme->frame_undecorated_focused_border_color);
1024 RrColorFree(theme->frame_unfocused_border_color);
1025 RrColorFree(theme->frame_undecorated_unfocused_border_color);
1026 RrColorFree(theme->title_separator_focused_color);
1027 RrColorFree(theme->title_separator_unfocused_color);
1028 RrColorFree(theme->cb_unfocused_color);
1029 RrColorFree(theme->cb_focused_color);
1030 RrColorFree(theme->title_focused_color);
1031 RrColorFree(theme->title_unfocused_color);
1032 RrColorFree(theme->titlebut_focused_disabled_color);
1033 RrColorFree(theme->titlebut_unfocused_disabled_color);
1034 RrColorFree(theme->titlebut_focused_hover_color);
1035 RrColorFree(theme->titlebut_unfocused_hover_color);
1036 RrColorFree(theme->titlebut_focused_hover_toggled_color);
1037 RrColorFree(theme->titlebut_unfocused_hover_toggled_color);
1038 RrColorFree(theme->titlebut_focused_pressed_toggled_color);
1039 RrColorFree(theme->titlebut_unfocused_pressed_toggled_color);
1040 RrColorFree(theme->titlebut_focused_unpressed_toggled_color);
1041 RrColorFree(theme->titlebut_unfocused_unpressed_toggled_color);
1042 RrColorFree(theme->titlebut_focused_pressed_color);
1043 RrColorFree(theme->titlebut_unfocused_pressed_color);
1044 RrColorFree(theme->titlebut_focused_unpressed_color);
1045 RrColorFree(theme->titlebut_unfocused_unpressed_color);
1046 RrColorFree(theme->menu_title_color);
1047 RrColorFree(theme->menu_sep_color);
1048 RrColorFree(theme->menu_color);
1049 RrColorFree(theme->menu_bullet_color);
1050 RrColorFree(theme->menu_bullet_selected_color);
1051 RrColorFree(theme->menu_selected_color);
1052 RrColorFree(theme->menu_disabled_color);
1053 RrColorFree(theme->menu_disabled_selected_color);
1054 RrColorFree(theme->title_focused_shadow_color);
1055 RrColorFree(theme->title_unfocused_shadow_color);
1056 RrColorFree(theme->osd_text_active_color);
1057 RrColorFree(theme->osd_text_inactive_color);
1058 RrColorFree(theme->osd_text_active_shadow_color);
1059 RrColorFree(theme->osd_text_inactive_shadow_color);
1060 RrColorFree(theme->osd_pressed_color);
1061 RrColorFree(theme->osd_unpressed_color);
1062 RrColorFree(theme->osd_focused_color);
1063 RrColorFree(theme->osd_pressed_lineart);
1064 RrColorFree(theme->osd_focused_lineart);
1065 RrColorFree(theme->menu_title_shadow_color);
1066 RrColorFree(theme->menu_text_shadow_color);
1068 g_free(theme->def_win_icon);
1070 RrPixmapMaskFree(theme->menu_bullet_mask);
1071 RrPixmapMaskFree(theme->down_arrow_mask);
1072 RrPixmapMaskFree(theme->up_arrow_mask);
1074 RrFontClose(theme->win_font_focused);
1075 RrFontClose(theme->win_font_unfocused);
1076 RrFontClose(theme->menu_title_font);
1077 RrFontClose(theme->menu_font);
1078 RrFontClose(theme->osd_font_hilite);
1079 RrFontClose(theme->osd_font_unhilite);
1081 RrAppearanceFree(theme->a_focused_grip);
1082 RrAppearanceFree(theme->a_unfocused_grip);
1083 RrAppearanceFree(theme->a_focused_title);
1084 RrAppearanceFree(theme->a_unfocused_title);
1085 RrAppearanceFree(theme->a_focused_label);
1086 RrAppearanceFree(theme->a_unfocused_label);
1087 RrAppearanceFree(theme->a_icon);
1088 RrAppearanceFree(theme->a_focused_handle);
1089 RrAppearanceFree(theme->a_unfocused_handle);
1090 RrAppearanceFree(theme->a_menu);
1091 RrAppearanceFree(theme->a_menu_title);
1092 RrAppearanceFree(theme->a_menu_text_title);
1093 RrAppearanceFree(theme->a_menu_normal);
1094 RrAppearanceFree(theme->a_menu_selected);
1095 RrAppearanceFree(theme->a_menu_disabled);
1096 RrAppearanceFree(theme->a_menu_disabled_selected);
1097 RrAppearanceFree(theme->a_menu_text_normal);
1098 RrAppearanceFree(theme->a_menu_text_selected);
1099 RrAppearanceFree(theme->a_menu_text_disabled);
1100 RrAppearanceFree(theme->a_menu_text_disabled_selected);
1101 RrAppearanceFree(theme->a_menu_bullet_normal);
1102 RrAppearanceFree(theme->a_menu_bullet_selected);
1103 RrAppearanceFree(theme->a_clear);
1104 RrAppearanceFree(theme->a_clear_tex);
1105 RrAppearanceFree(theme->osd_bg);
1106 RrAppearanceFree(theme->osd_hilite_bg);
1107 RrAppearanceFree(theme->osd_hilite_label);
1108 RrAppearanceFree(theme->osd_unhilite_bg);
1109 RrAppearanceFree(theme->osd_unhilite_label);
1110 RrAppearanceFree(theme->osd_pressed_button);
1111 RrAppearanceFree(theme->osd_unpressed_button);
1112 RrAppearanceFree(theme->osd_focused_button);
1114 g_slice_free(RrTheme, theme);
1118 static XrmDatabase loaddb(const gchar *name, gchar **path)
1121 XrmDatabase db = NULL;
1124 if (name[0] == '/') {
1125 s = g_build_filename(name, "openbox-3", "themerc", NULL);
1126 if ((db = XrmGetFileDatabase(s)))
1127 *path = g_path_get_dirname(s);
1132 p = obt_paths_new();
1134 /* XXX backwards compatibility, remove me sometime later */
1135 s = g_build_filename(g_get_home_dir(), ".themes", name,
1136 "openbox-3", "themerc", NULL);
1137 if ((db = XrmGetFileDatabase(s)))
1138 *path = g_path_get_dirname(s);
1141 for (it = obt_paths_data_dirs(p); !db && it; it = g_slist_next(it))
1143 s = g_build_filename(it->data, "themes", name,
1144 "openbox-3", "themerc", NULL);
1145 if ((db = XrmGetFileDatabase(s)))
1146 *path = g_path_get_dirname(s);
1154 s = g_build_filename(name, "themerc", NULL);
1155 if ((db = XrmGetFileDatabase(s)))
1156 *path = g_path_get_dirname(s);
1163 static gchar *create_class_name(const gchar *rname)
1165 gchar *rclass = g_strdup(rname);
1170 p = strchr(p+1, '.');
1171 if (p == NULL) break;
1173 if (*p == '\0') break;
1178 static gboolean read_int(XrmDatabase db, const gchar *rname, gint *value)
1180 gboolean ret = FALSE;
1181 gchar *rclass = create_class_name(rname);
1182 gchar *rettype, *end;
1185 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1186 retvalue.addr != NULL) {
1187 *value = (gint)strtol(retvalue.addr, &end, 10);
1188 if (end != retvalue.addr)
1196 static gboolean read_string(XrmDatabase db, const gchar *rname, gchar **value)
1198 gboolean ret = FALSE;
1199 gchar *rclass = create_class_name(rname);
1203 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1204 retvalue.addr != NULL) {
1205 g_strstrip(retvalue.addr);
1206 *value = retvalue.addr;
1214 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
1215 const gchar *rname, RrColor **value)
1217 gboolean ret = FALSE;
1218 gchar *rclass = create_class_name(rname);
1222 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1223 retvalue.addr != NULL) {
1226 /* retvalue.addr is inside the xrdb database so we can't destroy it
1227 but we can edit it in place, as g_strstrip does. */
1228 g_strstrip(retvalue.addr);
1229 c = RrColorParse(inst, retvalue.addr);
1240 static gboolean read_mask(const RrInstance *inst, const gchar *path,
1241 const gchar *maskname, RrPixmapMask **value)
1243 gboolean ret = FALSE;
1245 gint hx, hy; /* ignored */
1249 s = g_build_filename(path, maskname, NULL);
1250 if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess) {
1252 *value = RrPixmapMaskNew(inst, w, h, (gchar*)b);
1260 static void parse_appearance(gchar *tex, RrSurfaceColorType *grad,
1261 RrReliefType *relief, RrBevelType *bevel,
1262 gboolean *interlaced, gboolean *border,
1263 gboolean allow_trans)
1267 /* convert to all lowercase */
1268 for (t = tex; *t != '\0'; ++t)
1269 *t = g_ascii_tolower(*t);
1271 if (allow_trans && strstr(tex, "parentrelative") != NULL) {
1272 *grad = RR_SURFACE_PARENTREL;
1274 if (strstr(tex, "gradient") != NULL) {
1275 if (strstr(tex, "crossdiagonal") != NULL)
1276 *grad = RR_SURFACE_CROSS_DIAGONAL;
1277 else if (strstr(tex, "pyramid") != NULL)
1278 *grad = RR_SURFACE_PYRAMID;
1279 else if (strstr(tex, "mirrorhorizontal") != NULL)
1280 *grad = RR_SURFACE_MIRROR_HORIZONTAL;
1281 else if (strstr(tex, "horizontal") != NULL)
1282 *grad = RR_SURFACE_HORIZONTAL;
1283 else if (strstr(tex, "splitvertical") != NULL)
1284 *grad = RR_SURFACE_SPLIT_VERTICAL;
1285 else if (strstr(tex, "vertical") != NULL)
1286 *grad = RR_SURFACE_VERTICAL;
1288 *grad = RR_SURFACE_DIAGONAL;
1290 *grad = RR_SURFACE_SOLID;
1294 if (strstr(tex, "sunken") != NULL)
1295 *relief = RR_RELIEF_SUNKEN;
1296 else if (strstr(tex, "flat") != NULL)
1297 *relief = RR_RELIEF_FLAT;
1298 else if (strstr(tex, "raised") != NULL)
1299 *relief = RR_RELIEF_RAISED;
1301 *relief = (*grad == RR_SURFACE_PARENTREL) ?
1302 RR_RELIEF_FLAT : RR_RELIEF_RAISED;
1305 if (*relief == RR_RELIEF_FLAT) {
1306 if (strstr(tex, "border") != NULL)
1309 if (strstr(tex, "bevel2") != NULL)
1310 *bevel = RR_BEVEL_2;
1312 *bevel = RR_BEVEL_1;
1315 if (strstr(tex, "interlaced") != NULL)
1318 *interlaced = FALSE;
1321 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
1322 const gchar *rname, RrAppearance *value,
1323 gboolean allow_trans)
1325 gboolean ret = FALSE;
1326 gchar *rclass = create_class_name(rname);
1327 gchar *cname, *ctoname, *bcname, *icname, *hname, *sname;
1328 gchar *csplitname, *ctosplitname;
1333 cname = g_strconcat(rname, ".color", NULL);
1334 ctoname = g_strconcat(rname, ".colorTo", NULL);
1335 bcname = g_strconcat(rname, ".border.color", NULL);
1336 icname = g_strconcat(rname, ".interlace.color", NULL);
1337 hname = g_strconcat(rname, ".highlight", NULL);
1338 sname = g_strconcat(rname, ".shadow", NULL);
1339 csplitname = g_strconcat(rname, ".color.splitTo", NULL);
1340 ctosplitname = g_strconcat(rname, ".colorTo.splitTo", NULL);
1342 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1343 retvalue.addr != NULL) {
1344 parse_appearance(retvalue.addr,
1345 &value->surface.grad,
1346 &value->surface.relief,
1347 &value->surface.bevel,
1348 &value->surface.interlaced,
1349 &value->surface.border,
1351 if (!read_color(db, inst, cname, &value->surface.primary))
1352 value->surface.primary = RrColorNew(inst, 0, 0, 0);
1353 if (!read_color(db, inst, ctoname, &value->surface.secondary))
1354 value->surface.secondary = RrColorNew(inst, 0, 0, 0);
1355 if (value->surface.border)
1356 if (!read_color(db, inst, bcname,
1357 &value->surface.border_color))
1358 value->surface.border_color = RrColorNew(inst, 0, 0, 0);
1359 if (value->surface.interlaced)
1360 if (!read_color(db, inst, icname,
1361 &value->surface.interlace_color))
1362 value->surface.interlace_color = RrColorNew(inst, 0, 0, 0);
1363 if (read_int(db, hname, &i) && i >= 0)
1364 value->surface.bevel_light_adjust = i;
1365 if (read_int(db, sname, &i) && i >= 0 && i <= 256)
1366 value->surface.bevel_dark_adjust = i;
1368 if (value->surface.grad == RR_SURFACE_SPLIT_VERTICAL) {
1371 if (!read_color(db, inst, csplitname,
1372 &value->surface.split_primary))
1374 r = value->surface.primary->r;
1376 g = value->surface.primary->g;
1378 b = value->surface.primary->b;
1380 if (r > 0xFF) r = 0xFF;
1381 if (g > 0xFF) g = 0xFF;
1382 if (b > 0xFF) b = 0xFF;
1383 value->surface.split_primary = RrColorNew(inst, r, g, b);
1386 if (!read_color(db, inst, ctosplitname,
1387 &value->surface.split_secondary))
1389 r = value->surface.secondary->r;
1391 g = value->surface.secondary->g;
1393 b = value->surface.secondary->b;
1395 if (r > 0xFF) r = 0xFF;
1396 if (g > 0xFF) g = 0xFF;
1397 if (b > 0xFF) b = 0xFF;
1398 value->surface.split_secondary = RrColorNew(inst, r, g, b);
1405 g_free(ctosplitname);
1417 static int parse_inline_number(const char *p)
1425 for (; isdigit(*p); ++p)
1426 res = res * 10 + *p - '0';
1431 static void set_default_appearance(RrAppearance *a)
1433 a->surface.grad = RR_SURFACE_SOLID;
1434 a->surface.relief = RR_RELIEF_FLAT;
1435 a->surface.bevel = RR_BEVEL_1;
1436 a->surface.interlaced = FALSE;
1437 a->surface.border = FALSE;
1438 a->surface.primary = RrColorNew(a->inst, 0, 0, 0);
1439 a->surface.secondary = RrColorNew(a->inst, 0, 0, 0);
1442 /* Reads the output from gimp's C-Source file format into valid RGBA data for
1443 an RrTextureRGBA. */
1444 static RrPixel32* read_c_image(gint width, gint height, const guint8 *data)
1449 p = im = g_memdup(data, width * height * sizeof(RrPixel32));
1451 for (i = 0; i < width * height; ++i) {
1452 guchar a = ((*p >> 24) & 0xff);
1453 guchar b = ((*p >> 16) & 0xff);
1454 guchar g = ((*p >> 8) & 0xff);
1455 guchar r = ((*p >> 0) & 0xff);
1457 *p = ((r << RrDefaultRedOffset) +
1458 (g << RrDefaultGreenOffset) +
1459 (b << RrDefaultBlueOffset) +
1460 (a << RrDefaultAlphaOffset));
1467 static void read_button_styles(XrmDatabase db, const RrInstance *inst,
1469 const RrTheme *theme, RrButton *btn,
1470 const gchar *btnname,
1471 struct fallbacks *fbs,
1472 guchar *normal_mask,
1473 guchar *toggled_mask)
1475 gchar name[128], name2[128];
1476 gboolean userdef = TRUE;
1478 g_snprintf(name, 128, "%s.xbm", btnname);
1479 if (!read_mask(inst, path, name, &btn->unpressed_mask) && normal_mask)
1481 btn->unpressed_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)normal_mask);
1484 g_snprintf(name, 128, "%s_toggled.xbm", btnname);
1485 if (toggled_mask && !read_mask(inst, path, name, &btn->unpressed_toggled_mask))
1488 btn->unpressed_toggled_mask = RrPixmapMaskCopy(btn->unpressed_mask);
1490 btn->unpressed_toggled_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)toggled_mask);
1492 #define READ_BUTTON_MASK_COPY(type, fallback) \
1493 g_snprintf(name, 128, "%s_" #type ".xbm", btnname); \
1494 READ_MASK_COPY(name, btn->type##_mask, fallback);
1496 READ_BUTTON_MASK_COPY(pressed, btn->unpressed_mask);
1497 READ_BUTTON_MASK_COPY(disabled, btn->unpressed_mask);
1498 READ_BUTTON_MASK_COPY(hover, btn->unpressed_mask);
1500 READ_BUTTON_MASK_COPY(pressed_toggled, btn->unpressed_toggled_mask);
1501 READ_BUTTON_MASK_COPY(hover_toggled, btn->unpressed_toggled_mask);
1504 #define READ_BUTTON_APPEARANCE(typedots, type, fallback) \
1505 g_snprintf(name, 128, "window.active.button.%s." typedots ".image.color", btnname); \
1506 READ_COLOR(name, btn->focused_##type##_color, RrColorCopy(theme->titlebut_focused_##type##_color)); \
1507 g_snprintf(name, 128, "window.inactive.button.%s." typedots ".image.color", btnname); \
1508 READ_COLOR(name, btn->unfocused_##type##_color, RrColorCopy(theme->titlebut_unfocused_##type##_color)); \
1510 g_snprintf(name, 128, "window.active.button.%s." typedots ".bg", btnname); \
1511 g_snprintf(name2, 128, "window.active.button.%s.toggled.bg", btnname); \
1512 READ_APPEARANCE_(name, name2, btn->a_focused_##type, TRUE, fbs->focused_##type); \
1513 g_snprintf(name, 128, "window.inactive.button.%s." typedots ".bg", btnname); \
1514 g_snprintf(name2, 128, "window.inactive.button.%s.toggled.bg", btnname); \
1515 READ_APPEARANCE_(name, name2, btn->a_unfocused_##type, TRUE, fbs->unfocused_##type); \
1517 g_snprintf(name, 128, "window.active.button.%s." typedots ".bg", btnname); \
1518 READ_APPEARANCE_COPY(name, btn->a_focused_##type, TRUE, fbs->focused_##type); \
1519 g_snprintf(name, 128, "window.inactive.button.%s." typedots ".bg", btnname); \
1520 READ_APPEARANCE_COPY(name, btn->a_unfocused_##type, TRUE, fbs->unfocused_##type); \
1522 btn->a_unfocused_##type->texture[0].typ##e = \
1523 btn->a_focused_##type->texture[0].typ##e = \
1525 btn->a_unfocused_##type->texture[0].data.mask.mask = \
1526 btn->a_focused_##type->texture[0].data.mask.mask = \
1528 btn->a_unfocused_##type->texture[0].data.mask.color = \
1529 btn->unfocused_##type##_color; \
1530 btn->a_focused_##type->texture[0].data.mask.color = \
1531 btn->focused_##type##_color;
1533 READ_BUTTON_APPEARANCE("unpressed", unpressed, 0);
1534 READ_BUTTON_APPEARANCE("pressed", pressed, 0);
1535 READ_BUTTON_APPEARANCE("disabled", disabled, 0);
1536 READ_BUTTON_APPEARANCE("hover", hover, 0);
1538 READ_BUTTON_APPEARANCE("unpressed.toggled", unpressed_toggled, 1);
1539 READ_BUTTON_APPEARANCE("pressed.toggled", pressed_toggled, 0);
1540 READ_BUTTON_APPEARANCE("hover.toggled", hover_toggled, 0);