]> Dogcows Code - chaz/openbox/blob - render/theme.c
Introducing the icon cache.
[chaz/openbox] / render / theme.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 theme.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6
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.
11
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.
16
17 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "render.h"
21 #include "color.h"
22 #include "font.h"
23 #include "mask.h"
24 #include "theme.h"
25 #include "icon.h"
26 #include "parser/parse.h"
27
28 #include <X11/Xlib.h>
29 #include <X11/Xresource.h>
30 #include <ctype.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 static XrmDatabase loaddb(const gchar *name, gchar **path);
35 static gboolean read_int(XrmDatabase db, const gchar *rname, gint *value);
36 static gboolean read_string(XrmDatabase db, const gchar *rname, gchar **value);
37 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
38 const gchar *rname, RrColor **value);
39 static gboolean read_mask(const RrInstance *inst, const gchar *path,
40 RrTheme *theme, const gchar *maskname,
41 RrPixmapMask **value);
42 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
43 const gchar *rname, RrAppearance *value,
44 gboolean allow_trans);
45 static int parse_inline_number(const char *p);
46 static RrPixel32* read_c_image(gint width, gint height, const guint8 *data);
47 static void set_default_appearance(RrAppearance *a);
48
49 RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
50 gboolean allow_fallback,
51 RrFont *active_window_font, RrFont *inactive_window_font,
52 RrFont *menu_title_font, RrFont *menu_item_font,
53 RrFont *osd_font)
54 {
55 XrmDatabase db = NULL;
56 RrJustify winjust, mtitlejust;
57 gchar *str;
58 RrTheme *theme;
59 gchar *path;
60 gboolean userdef;
61
62 if (name) {
63 db = loaddb(name, &path);
64 if (db == NULL) {
65 g_message("Unable to load the theme '%s'", name);
66 if (allow_fallback)
67 g_message("Falling back to the default theme '%s'",
68 DEFAULT_THEME);
69 /* fallback to the default theme */
70 name = NULL;
71 }
72 }
73 if (name == NULL) {
74 if (allow_fallback) {
75 db = loaddb(DEFAULT_THEME, &path);
76 if (db == NULL) {
77 g_message("Unable to load the theme '%s'", DEFAULT_THEME);
78 return NULL;
79 }
80 } else
81 return NULL;
82 }
83
84 theme = g_new0(RrTheme, 1);
85
86 theme->inst = inst;
87 theme->name = g_strdup(name ? name : DEFAULT_THEME);
88
89 theme->a_disabled_focused_max = RrAppearanceNew(inst, 1);
90 theme->a_disabled_unfocused_max = RrAppearanceNew(inst, 1);
91 theme->a_hover_focused_max = RrAppearanceNew(inst, 1);
92 theme->a_hover_unfocused_max = RrAppearanceNew(inst, 1);
93 theme->a_toggled_focused_unpressed_max = RrAppearanceNew(inst, 1);
94 theme->a_toggled_unfocused_unpressed_max = RrAppearanceNew(inst, 1);
95 theme->a_toggled_hover_focused_max = RrAppearanceNew(inst, 1);
96 theme->a_toggled_hover_unfocused_max = RrAppearanceNew(inst, 1);
97 theme->a_toggled_focused_pressed_max = RrAppearanceNew(inst, 1);
98 theme->a_toggled_unfocused_pressed_max = RrAppearanceNew(inst, 1);
99 theme->a_focused_unpressed_max = RrAppearanceNew(inst, 1);
100 theme->a_focused_pressed_max = RrAppearanceNew(inst, 1);
101 theme->a_unfocused_unpressed_max = RrAppearanceNew(inst, 1);
102 theme->a_unfocused_pressed_max = RrAppearanceNew(inst, 1);
103 theme->a_focused_grip = RrAppearanceNew(inst, 0);
104 theme->a_unfocused_grip = RrAppearanceNew(inst, 0);
105 theme->a_focused_title = RrAppearanceNew(inst, 0);
106 theme->a_unfocused_title = RrAppearanceNew(inst, 0);
107 theme->a_focused_label = RrAppearanceNew(inst, 1);
108 theme->a_unfocused_label = RrAppearanceNew(inst, 1);
109 theme->a_icon = RrAppearanceNew(inst, 1);
110 theme->a_focused_handle = RrAppearanceNew(inst, 0);
111 theme->a_unfocused_handle = RrAppearanceNew(inst, 0);
112 theme->a_menu = RrAppearanceNew(inst, 0);
113 theme->a_menu_title = RrAppearanceNew(inst, 0);
114 theme->a_menu_text_title = RrAppearanceNew(inst, 1);
115 theme->a_menu_normal = RrAppearanceNew(inst, 0);
116 theme->a_menu_selected = RrAppearanceNew(inst, 0);
117 theme->a_menu_disabled = RrAppearanceNew(inst, 0);
118 /* a_menu_disabled_selected is copied from a_menu_selected */
119 theme->a_menu_text_normal = RrAppearanceNew(inst, 1);
120 theme->a_menu_text_selected = RrAppearanceNew(inst, 1);
121 theme->a_menu_text_disabled = RrAppearanceNew(inst, 1);
122 theme->a_menu_text_disabled_selected = RrAppearanceNew(inst, 1);
123 theme->a_menu_bullet_normal = RrAppearanceNew(inst, 1);
124 theme->a_menu_bullet_selected = RrAppearanceNew(inst, 1);
125 theme->a_clear = RrAppearanceNew(inst, 0);
126 theme->a_clear_tex = RrAppearanceNew(inst, 1);
127 theme->osd_hilite_bg = RrAppearanceNew(inst, 0);
128 theme->osd_hilite_label = RrAppearanceNew(inst, 1);
129 theme->osd_hilite_fg = RrAppearanceNew(inst, 0);
130 theme->osd_unhilite_fg = RrAppearanceNew(inst, 0);
131
132 /* load the font stuff */
133 if (active_window_font) {
134 theme->win_font_focused = active_window_font;
135 RrFontRef(active_window_font);
136 } else
137 theme->win_font_focused = RrFontOpenDefault(inst);
138
139 if (inactive_window_font) {
140 theme->win_font_unfocused = inactive_window_font;
141 RrFontRef(inactive_window_font);
142 } else
143 theme->win_font_unfocused = RrFontOpenDefault(inst);
144
145 winjust = RR_JUSTIFY_LEFT;
146 if (read_string(db, "window.label.text.justify", &str)) {
147 if (!g_ascii_strcasecmp(str, "right"))
148 winjust = RR_JUSTIFY_RIGHT;
149 else if (!g_ascii_strcasecmp(str, "center"))
150 winjust = RR_JUSTIFY_CENTER;
151 }
152
153 if (menu_title_font) {
154 theme->menu_title_font = menu_title_font;
155 RrFontRef(menu_title_font);
156 } else
157 theme->menu_title_font = RrFontOpenDefault(inst);
158
159 mtitlejust = RR_JUSTIFY_LEFT;
160 if (read_string(db, "menu.title.text.justify", &str)) {
161 if (!g_ascii_strcasecmp(str, "right"))
162 mtitlejust = RR_JUSTIFY_RIGHT;
163 else if (!g_ascii_strcasecmp(str, "center"))
164 mtitlejust = RR_JUSTIFY_CENTER;
165 }
166
167 if (menu_item_font) {
168 theme->menu_font = menu_item_font;
169 RrFontRef(menu_item_font);
170 } else
171 theme->menu_font = RrFontOpenDefault(inst);
172
173 if (osd_font) {
174 theme->osd_font = osd_font;
175 RrFontRef(osd_font);
176 } else
177 theme->osd_font = RrFontOpenDefault(inst);
178
179 /* load direct dimensions */
180 if ((!read_int(db, "menu.overlap.x", &theme->menu_overlap_x) &&
181 !read_int(db, "menu.overlap", &theme->menu_overlap_x)) ||
182 theme->menu_overlap_x < -100 || theme->menu_overlap_x > 100)
183 theme->menu_overlap_x = 0;
184 if ((!read_int(db, "menu.overlap.y", &theme->menu_overlap_y) &&
185 !read_int(db, "menu.overlap", &theme->menu_overlap_y)) ||
186 theme->menu_overlap_y < -100 || theme->menu_overlap_y > 100)
187 theme->menu_overlap_y = 0;
188 if (!read_int(db, "window.handle.width", &theme->handle_height) ||
189 theme->handle_height < 0 || theme->handle_height > 100)
190 theme->handle_height = 6;
191 if (!read_int(db, "padding.width", &theme->paddingx) ||
192 theme->paddingx < 0 || theme->paddingx > 100)
193 theme->paddingx = 3;
194 if (!read_int(db, "padding.height", &theme->paddingy) ||
195 theme->paddingy < 0 || theme->paddingy > 100)
196 theme->paddingy = theme->paddingx;
197 if (!read_int(db, "border.width", &theme->fbwidth) ||
198 theme->fbwidth < 0 || theme->fbwidth > 100)
199 theme->fbwidth = 1;
200 /* menu border width inherits from the frame border width */
201 if (!read_int(db, "menu.border.width", &theme->mbwidth) ||
202 theme->mbwidth < 0 || theme->mbwidth > 100)
203 theme->mbwidth = theme->fbwidth;
204 /* osd border width inherits from the frame border width */
205 if (!read_int(db, "osd.border.width", &theme->obwidth) ||
206 theme->obwidth < 0 || theme->obwidth > 100)
207 theme->obwidth = theme->fbwidth;
208 if (!read_int(db, "window.client.padding.width", &theme->cbwidthx) ||
209 theme->cbwidthx < 0 || theme->cbwidthx > 100)
210 theme->cbwidthx = theme->paddingx;
211 if (!read_int(db, "window.client.padding.height", &theme->cbwidthy) ||
212 theme->cbwidthy < 0 || theme->cbwidthy > 100)
213 theme->cbwidthy = theme->cbwidthx;
214
215 /* load colors */
216 if (!read_color(db, inst,
217 "window.active.border.color",
218 &theme->frame_focused_border_color) &&
219 !read_color(db, inst,
220 "border.color",
221 &theme->frame_focused_border_color))
222 theme->frame_focused_border_color = RrColorNew(inst, 0, 0, 0);
223 /* title separator focused color inherits from focused boder color */
224 if (!read_color(db, inst,
225 "window.active.title.separator.color",
226 &theme->title_separator_focused_color))
227 theme->title_separator_focused_color =
228 RrColorNew(inst,
229 theme->frame_focused_border_color->r,
230 theme->frame_focused_border_color->g,
231 theme->frame_focused_border_color->b);
232 /* unfocused border color inherits from frame focused border color */
233 if (!read_color(db, inst,
234 "window.inactive.border.color",
235 &theme->frame_unfocused_border_color))
236 theme->frame_unfocused_border_color =
237 RrColorNew(inst, theme->frame_focused_border_color->r,
238 theme->frame_focused_border_color->g,
239 theme->frame_focused_border_color->b);
240 /* title separator unfocused color inherits from unfocused boder color */
241 if (!read_color(db, inst,
242 "window.inactive.title.separator.color",
243 &theme->title_separator_unfocused_color))
244 theme->title_separator_unfocused_color =
245 RrColorNew(inst,
246 theme->frame_unfocused_border_color->r,
247 theme->frame_unfocused_border_color->g,
248 theme->frame_unfocused_border_color->b);
249
250 /* menu border color inherits from frame focused border color */
251 if (!read_color(db, inst, "menu.border.color", &theme->menu_border_color))
252 theme->menu_border_color =
253 RrColorNew(inst,
254 theme->frame_focused_border_color->r,
255 theme->frame_focused_border_color->g,
256 theme->frame_focused_border_color->b);
257 /* osd border color inherits from frame focused border color */
258 if (!read_color(db, inst, "osd.border.color", &theme->osd_border_color))
259 theme->osd_border_color =
260 RrColorNew(inst,
261 theme->frame_focused_border_color->r,
262 theme->frame_focused_border_color->g,
263 theme->frame_focused_border_color->b);
264 if (!read_color(db, inst,
265 "window.active.client.color",
266 &theme->cb_focused_color))
267 theme->cb_focused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
268 if (!read_color(db, inst,
269 "window.inactive.client.color",
270 &theme->cb_unfocused_color))
271 theme->cb_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
272 if (!read_color(db, inst,
273 "window.active.label.text.color",
274 &theme->title_focused_color))
275 theme->title_focused_color = RrColorNew(inst, 0x0, 0x0, 0x0);
276 if (!read_color(db, inst, "osd.label.text.color", &theme->osd_color))
277 theme->osd_color = RrColorNew(inst,
278 theme->title_focused_color->r,
279 theme->title_focused_color->g,
280 theme->title_focused_color->b);
281 if (!read_color(db, inst,
282 "window.inactive.label.text.color",
283 &theme->title_unfocused_color))
284 theme->title_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
285 if (!read_color(db, inst,
286 "window.active.button.unpressed.image.color",
287 &theme->titlebut_focused_unpressed_color))
288 theme->titlebut_focused_unpressed_color = RrColorNew(inst, 0, 0, 0);
289 if (!read_color(db, inst,
290 "window.inactive.button.unpressed.image.color",
291 &theme->titlebut_unfocused_unpressed_color))
292 theme->titlebut_unfocused_unpressed_color =
293 RrColorNew(inst, 0xff, 0xff, 0xff);
294 if (!read_color(db, inst,
295 "window.active.button.pressed.image.color",
296 &theme->titlebut_focused_pressed_color))
297 theme->titlebut_focused_pressed_color =
298 RrColorNew(inst,
299 theme->titlebut_focused_unpressed_color->r,
300 theme->titlebut_focused_unpressed_color->g,
301 theme->titlebut_focused_unpressed_color->b);
302 if (!read_color(db, inst,
303 "window.inactive.button.pressed.image.color",
304 &theme->titlebut_unfocused_pressed_color))
305 theme->titlebut_unfocused_pressed_color =
306 RrColorNew(inst,
307 theme->titlebut_unfocused_unpressed_color->r,
308 theme->titlebut_unfocused_unpressed_color->g,
309 theme->titlebut_unfocused_unpressed_color->b);
310 if (!read_color(db, inst,
311 "window.active.button.disabled.image.color",
312 &theme->titlebut_disabled_focused_color))
313 theme->titlebut_disabled_focused_color =
314 RrColorNew(inst, 0xff, 0xff, 0xff);
315 if (!read_color(db, inst,
316 "window.inactive.button.disabled.image.color",
317 &theme->titlebut_disabled_unfocused_color))
318 theme->titlebut_disabled_unfocused_color = RrColorNew(inst, 0, 0, 0);
319 if (!read_color(db, inst,
320 "window.active.button.hover.image.color",
321 &theme->titlebut_hover_focused_color))
322 theme->titlebut_hover_focused_color =
323 RrColorNew(inst,
324 theme->titlebut_focused_unpressed_color->r,
325 theme->titlebut_focused_unpressed_color->g,
326 theme->titlebut_focused_unpressed_color->b);
327 if (!read_color(db, inst,
328 "window.inactive.button.hover.image.color",
329 &theme->titlebut_hover_unfocused_color))
330 theme->titlebut_hover_unfocused_color =
331 RrColorNew(inst,
332 theme->titlebut_unfocused_unpressed_color->r,
333 theme->titlebut_unfocused_unpressed_color->g,
334 theme->titlebut_unfocused_unpressed_color->b);
335 if (!read_color(db, inst,
336 "window.active.button.toggled.unpressed.image.color",
337 &theme->titlebut_toggled_focused_unpressed_color) &&
338 !read_color(db, inst,
339 "window.active.button.toggled.image.color",
340 &theme->titlebut_toggled_focused_unpressed_color))
341 theme->titlebut_toggled_focused_unpressed_color =
342 RrColorNew(inst,
343 theme->titlebut_focused_pressed_color->r,
344 theme->titlebut_focused_pressed_color->g,
345 theme->titlebut_focused_pressed_color->b);
346 if (!read_color(db, inst,
347 "window.inactive.button.toggled.unpressed.image.color",
348 &theme->titlebut_toggled_unfocused_unpressed_color) &&
349 !read_color(db, inst,
350 "window.inactive.button.toggled.image.color",
351 &theme->titlebut_toggled_unfocused_unpressed_color))
352 theme->titlebut_toggled_unfocused_unpressed_color =
353 RrColorNew(inst,
354 theme->titlebut_unfocused_pressed_color->r,
355 theme->titlebut_unfocused_pressed_color->g,
356 theme->titlebut_unfocused_pressed_color->b);
357 if (!read_color(db, inst,
358 "window.active.button.toggled.hover.image.color",
359 &theme->titlebut_toggled_hover_focused_color))
360 theme->titlebut_toggled_hover_focused_color =
361 RrColorNew(inst,
362 theme->titlebut_toggled_focused_unpressed_color->r,
363 theme->titlebut_toggled_focused_unpressed_color->g,
364 theme->titlebut_toggled_focused_unpressed_color->b);
365 if (!read_color(db, inst,
366 "window.inactive.button.toggled.hover.image.color",
367 &theme->titlebut_toggled_hover_unfocused_color))
368 theme->titlebut_toggled_hover_unfocused_color =
369 RrColorNew(inst,
370 theme->titlebut_toggled_unfocused_unpressed_color->r,
371 theme->titlebut_toggled_unfocused_unpressed_color->g,
372 theme->titlebut_toggled_unfocused_unpressed_color->b);
373 if (!read_color(db, inst,
374 "window.active.button.toggled.pressed.image.color",
375 &theme->titlebut_toggled_focused_pressed_color))
376 theme->titlebut_toggled_focused_pressed_color =
377 RrColorNew(inst,
378 theme->titlebut_focused_pressed_color->r,
379 theme->titlebut_focused_pressed_color->g,
380 theme->titlebut_focused_pressed_color->b);
381 if (!read_color(db, inst,
382 "window.inactive.button.toggled.pressed.image.color",
383 &theme->titlebut_toggled_unfocused_pressed_color))
384 theme->titlebut_toggled_unfocused_pressed_color =
385 RrColorNew(inst,
386 theme->titlebut_unfocused_pressed_color->r,
387 theme->titlebut_unfocused_pressed_color->g,
388 theme->titlebut_unfocused_pressed_color->b);
389 if (!read_color(db, inst,
390 "menu.title.text.color", &theme->menu_title_color))
391 theme->menu_title_color = RrColorNew(inst, 0, 0, 0);
392 if (!read_color(db, inst,
393 "menu.items.text.color", &theme->menu_color))
394 theme->menu_color = RrColorNew(inst, 0xff, 0xff, 0xff);
395 if (!read_color(db, inst,
396 "menu.items.disabled.text.color",
397 &theme->menu_disabled_color))
398 theme->menu_disabled_color = RrColorNew(inst, 0, 0, 0);
399 if (!read_color(db, inst,
400 "menu.items.active.disabled.text.color",
401 &theme->menu_disabled_selected_color))
402 theme->menu_disabled_selected_color =
403 RrColorNew(inst,
404 theme->menu_disabled_color->r,
405 theme->menu_disabled_color->g,
406 theme->menu_disabled_color->b);
407 if (!read_color(db, inst,
408 "menu.items.active.text.color",
409 &theme->menu_selected_color))
410 theme->menu_selected_color = RrColorNew(inst, 0, 0, 0);
411
412 /* load the image masks */
413
414 /* maximize button masks */
415 userdef = TRUE;
416 if (!read_mask(inst, path, theme, "max.xbm", &theme->max_mask)) {
417 guchar data[] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f };
418 theme->max_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
419 userdef = FALSE;
420 }
421 if (!read_mask(inst, path, theme, "max_toggled.xbm",
422 &theme->max_toggled_mask))
423 {
424 if (userdef)
425 theme->max_toggled_mask = RrPixmapMaskCopy(theme->max_mask);
426 else {
427 guchar data[] = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f };
428 theme->max_toggled_mask = RrPixmapMaskNew(inst, 6, 6,(gchar*)data);
429 }
430 }
431 if (!read_mask(inst, path, theme, "max_pressed.xbm",
432 &theme->max_pressed_mask))
433 theme->max_pressed_mask = RrPixmapMaskCopy(theme->max_mask);
434 if (!read_mask(inst,path,theme,"max_disabled.xbm",
435 &theme->max_disabled_mask))
436 theme->max_disabled_mask = RrPixmapMaskCopy(theme->max_mask);
437 if (!read_mask(inst, path, theme, "max_hover.xbm", &theme->max_hover_mask))
438 theme->max_hover_mask = RrPixmapMaskCopy(theme->max_mask);
439 if (!read_mask(inst, path, theme, "max_toggled_pressed.xbm",
440 &theme->max_toggled_pressed_mask))
441 theme->max_toggled_pressed_mask =
442 RrPixmapMaskCopy(theme->max_toggled_mask);
443 if (!read_mask(inst, path, theme, "max_toggled_hover.xbm",
444 &theme->max_toggled_hover_mask))
445 theme->max_toggled_hover_mask =
446 RrPixmapMaskCopy(theme->max_toggled_mask);
447
448 /* iconify button masks */
449 if (!read_mask(inst, path, theme, "iconify.xbm", &theme->iconify_mask)) {
450 guchar data[] = { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f };
451 theme->iconify_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
452 }
453 if (!read_mask(inst, path, theme, "iconify_pressed.xbm",
454 &theme->iconify_pressed_mask))
455 theme->iconify_pressed_mask = RrPixmapMaskCopy(theme->iconify_mask);
456 if (!read_mask(inst, path, theme, "iconify_disabled.xbm",
457 &theme->iconify_disabled_mask))
458 theme->iconify_disabled_mask = RrPixmapMaskCopy(theme->iconify_mask);
459 if (!read_mask(inst, path, theme, "iconify_hover.xbm",
460 &theme->iconify_hover_mask))
461 theme->iconify_hover_mask = RrPixmapMaskCopy(theme->iconify_mask);
462
463 /* all desktops button masks */
464 userdef = TRUE;
465 if (!read_mask(inst, path, theme, "desk.xbm", &theme->desk_mask)) {
466 guchar data[] = { 0x33, 0x33, 0x00, 0x00, 0x33, 0x33 };
467 theme->desk_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
468 userdef = FALSE;
469 }
470 if (!read_mask(inst, path, theme, "desk_toggled.xbm",
471 &theme->desk_toggled_mask)) {
472 if (userdef)
473 theme->desk_toggled_mask = RrPixmapMaskCopy(theme->desk_mask);
474 else {
475 guchar data[] = { 0x00, 0x1e, 0x1a, 0x16, 0x1e, 0x00 };
476 theme->desk_toggled_mask =
477 RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
478 }
479 }
480 if (!read_mask(inst, path, theme, "desk_pressed.xbm",
481 &theme->desk_pressed_mask))
482 theme->desk_pressed_mask = RrPixmapMaskCopy(theme->desk_mask);
483 if (!read_mask(inst, path, theme, "desk_disabled.xbm",
484 &theme->desk_disabled_mask))
485 theme->desk_disabled_mask = RrPixmapMaskCopy(theme->desk_mask);
486 if (!read_mask(inst, path, theme, "desk_hover.xbm",
487 &theme->desk_hover_mask))
488 theme->desk_hover_mask = RrPixmapMaskCopy(theme->desk_mask);
489 if (!read_mask(inst, path, theme, "desk_toggled_pressed.xbm",
490 &theme->desk_toggled_pressed_mask))
491 theme->desk_toggled_pressed_mask =
492 RrPixmapMaskCopy(theme->desk_toggled_mask);
493 if (!read_mask(inst, path, theme, "desk_toggled_hover.xbm",
494 &theme->desk_toggled_hover_mask))
495 theme->desk_toggled_hover_mask =
496 RrPixmapMaskCopy(theme->desk_toggled_mask);
497
498 /* shade button masks */
499 if (!read_mask(inst, path, theme, "shade.xbm", &theme->shade_mask)) {
500 guchar data[] = { 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00 };
501 theme->shade_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
502 }
503 if (!read_mask(inst, path, theme, "shade_toggled.xbm",
504 &theme->shade_toggled_mask))
505 theme->shade_toggled_mask = RrPixmapMaskCopy(theme->shade_mask);
506 if (!read_mask(inst, path, theme, "shade_pressed.xbm",
507 &theme->shade_pressed_mask))
508 theme->shade_pressed_mask = RrPixmapMaskCopy(theme->shade_mask);
509 if (!read_mask(inst, path, theme, "shade_disabled.xbm",
510 &theme->shade_disabled_mask))
511 theme->shade_disabled_mask = RrPixmapMaskCopy(theme->shade_mask);
512 if (!read_mask(inst, path, theme, "shade_hover.xbm",
513 &theme->shade_hover_mask))
514 theme->shade_hover_mask = RrPixmapMaskCopy(theme->shade_mask);
515 if (!read_mask(inst, path, theme, "shade_toggled_pressed.xbm",
516 &theme->shade_toggled_pressed_mask))
517 theme->shade_toggled_pressed_mask =
518 RrPixmapMaskCopy(theme->shade_toggled_mask);
519 if (!read_mask(inst, path, theme, "shade_toggled_hover.xbm",
520 &theme->shade_toggled_hover_mask))
521 theme->shade_toggled_hover_mask =
522 RrPixmapMaskCopy(theme->shade_toggled_mask);
523
524 /* close button masks */
525 if (!read_mask(inst, path, theme, "close.xbm", &theme->close_mask)) {
526 guchar data[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 };
527 theme->close_mask = RrPixmapMaskNew(inst, 6, 6, (gchar*)data);
528 }
529 if (!read_mask(inst, path, theme, "close_pressed.xbm",
530 &theme->close_pressed_mask))
531 theme->close_pressed_mask = RrPixmapMaskCopy(theme->close_mask);
532 if (!read_mask(inst, path, theme, "close_disabled.xbm",
533 &theme->close_disabled_mask))
534 theme->close_disabled_mask = RrPixmapMaskCopy(theme->close_mask);
535 if (!read_mask(inst, path, theme, "close_hover.xbm",
536 &theme->close_hover_mask))
537 theme->close_hover_mask = RrPixmapMaskCopy(theme->close_mask);
538
539 /* submenu bullet mask */
540 if (!read_mask(inst, path, theme, "bullet.xbm", &theme->menu_bullet_mask))
541 {
542 guchar data[] = { 0x01, 0x03, 0x07, 0x0f, 0x07, 0x03, 0x01 };
543 theme->menu_bullet_mask = RrPixmapMaskNew(inst, 4, 7, (gchar*)data);
544 }
545
546 /* setup the default window icon */
547 theme->def_win_icon = read_c_image(OB_DEFAULT_ICON_WIDTH,
548 OB_DEFAULT_ICON_HEIGHT,
549 OB_DEFAULT_ICON_pixel_data);
550 theme->def_win_icon_w = OB_DEFAULT_ICON_WIDTH;
551 theme->def_win_icon_h = OB_DEFAULT_ICON_HEIGHT;
552
553
554 /* read the decoration textures */
555 if (!read_appearance(db, inst,
556 "window.active.title.bg", theme->a_focused_title,
557 FALSE))
558 set_default_appearance(theme->a_focused_title);
559 if (!read_appearance(db, inst,
560 "window.inactive.title.bg", theme->a_unfocused_title,
561 FALSE))
562 set_default_appearance(theme->a_unfocused_title);
563 if (!read_appearance(db, inst,
564 "window.active.label.bg", theme->a_focused_label,
565 TRUE))
566 set_default_appearance(theme->a_focused_label);
567 if (!read_appearance(db, inst,
568 "window.inactive.label.bg", theme->a_unfocused_label,
569 TRUE))
570 set_default_appearance(theme->a_unfocused_label);
571 if (!read_appearance(db, inst,
572 "window.active.handle.bg", theme->a_focused_handle,
573 FALSE))
574 set_default_appearance(theme->a_focused_handle);
575 if (!read_appearance(db, inst,
576 "window.inactive.handle.bg",theme->a_unfocused_handle,
577 FALSE))
578 set_default_appearance(theme->a_unfocused_handle);
579 if (!read_appearance(db, inst,
580 "window.active.grip.bg", theme->a_focused_grip,
581 TRUE))
582 set_default_appearance(theme->a_focused_grip);
583 if (!read_appearance(db, inst,
584 "window.inactive.grip.bg", theme->a_unfocused_grip,
585 TRUE))
586 set_default_appearance(theme->a_unfocused_grip);
587 if (!read_appearance(db, inst,
588 "menu.items.bg", theme->a_menu,
589 FALSE))
590 set_default_appearance(theme->a_menu);
591 if (!read_appearance(db, inst,
592 "menu.title.bg", theme->a_menu_title,
593 TRUE))
594 set_default_appearance(theme->a_menu_title);
595 if (!read_appearance(db, inst,
596 "menu.items.active.bg", theme->a_menu_selected,
597 TRUE))
598 set_default_appearance(theme->a_menu_selected);
599 theme->a_menu_disabled_selected =
600 RrAppearanceCopy(theme->a_menu_selected);
601
602 /* read appearances for non-decorations (on-screen-display) */
603 if (!read_appearance(db, inst, "osd.bg", theme->osd_hilite_bg, FALSE)) {
604 RrAppearanceFree(theme->osd_hilite_bg);
605 theme->osd_hilite_bg = RrAppearanceCopy(theme->a_focused_title);
606 }
607 if (!read_appearance(db, inst, "osd.label.bg",
608 theme->osd_hilite_label, TRUE)) {
609 RrAppearanceFree(theme->osd_hilite_label);
610 theme->osd_hilite_label = RrAppearanceCopy(theme->a_focused_label);
611 }
612 /* osd_hilite_fg can't be parentrel */
613 if (!read_appearance(db, inst, "osd.hilight.bg",
614 theme->osd_hilite_fg, FALSE)) {
615 RrAppearanceFree(theme->osd_hilite_fg);
616 if (theme->a_focused_label->surface.grad != RR_SURFACE_PARENTREL)
617 theme->osd_hilite_fg = RrAppearanceCopy(theme->a_focused_label);
618 else
619 theme->osd_hilite_fg = RrAppearanceCopy(theme->a_focused_title);
620 }
621 /* osd_unhilite_fg can't be parentrel either */
622 if (!read_appearance(db, inst, "osd.unhilight.bg",
623 theme->osd_unhilite_fg, FALSE)) {
624 RrAppearanceFree(theme->osd_unhilite_fg);
625 if (theme->a_unfocused_label->surface.grad != RR_SURFACE_PARENTREL)
626 theme->osd_unhilite_fg=RrAppearanceCopy(theme->a_unfocused_label);
627 else
628 theme->osd_unhilite_fg=RrAppearanceCopy(theme->a_unfocused_title);
629 }
630
631 /* read buttons textures */
632 if (!read_appearance(db, inst,
633 "window.active.button.disabled.bg",
634 theme->a_disabled_focused_max,
635 TRUE))
636 set_default_appearance(theme->a_disabled_focused_max);
637 if (!read_appearance(db, inst,
638 "window.inactive.button.disabled.bg",
639 theme->a_disabled_unfocused_max,
640 TRUE))
641 set_default_appearance(theme->a_disabled_unfocused_max);
642 if (!read_appearance(db, inst,
643 "window.active.button.pressed.bg",
644 theme->a_focused_pressed_max,
645 TRUE))
646 set_default_appearance(theme->a_focused_pressed_max);
647 if (!read_appearance(db, inst,
648 "window.inactive.button.pressed.bg",
649 theme->a_unfocused_pressed_max,
650 TRUE))
651 set_default_appearance(theme->a_unfocused_pressed_max);
652 if (!read_appearance(db, inst,
653 "window.active.button.toggled.unpressed.bg",
654 theme->a_toggled_focused_unpressed_max,
655 TRUE) &&
656 !read_appearance(db, inst,
657 "window.active.button.toggled.bg",
658 theme->a_toggled_focused_unpressed_max,
659 TRUE))
660 {
661 RrAppearanceFree(theme->a_toggled_focused_unpressed_max);
662 theme->a_toggled_focused_unpressed_max =
663 RrAppearanceCopy(theme->a_focused_pressed_max);
664 }
665 if (!read_appearance(db, inst,
666 "window.inactive.button.toggled.unpressed.bg",
667 theme->a_toggled_unfocused_unpressed_max,
668 TRUE) &&
669 !read_appearance(db, inst,
670 "window.inactive.button.toggled.bg",
671 theme->a_toggled_unfocused_unpressed_max,
672 TRUE))
673 {
674 RrAppearanceFree(theme->a_toggled_unfocused_unpressed_max);
675 theme->a_toggled_unfocused_unpressed_max =
676 RrAppearanceCopy(theme->a_unfocused_pressed_max);
677 }
678 if (!read_appearance(db, inst,
679 "window.active.button.toggled.hover.bg",
680 theme->a_toggled_hover_focused_max,
681 TRUE))
682 {
683 RrAppearanceFree(theme->a_toggled_hover_focused_max);
684 theme->a_toggled_hover_focused_max =
685 RrAppearanceCopy(theme->a_toggled_focused_unpressed_max);
686 }
687 if (!read_appearance(db, inst,
688 "window.inactive.button.toggled.hover.bg",
689 theme->a_toggled_hover_unfocused_max,
690 TRUE))
691 {
692 RrAppearanceFree(theme->a_toggled_hover_unfocused_max);
693 theme->a_toggled_hover_unfocused_max =
694 RrAppearanceCopy(theme->a_toggled_unfocused_unpressed_max);
695 }
696 if (!read_appearance(db, inst,
697 "window.active.button.toggled.pressed.bg",
698 theme->a_toggled_focused_pressed_max,
699 TRUE))
700 {
701 RrAppearanceFree(theme->a_toggled_focused_pressed_max);
702 theme->a_toggled_focused_pressed_max =
703 RrAppearanceCopy(theme->a_focused_pressed_max);
704 }
705 if (!read_appearance(db, inst,
706 "window.inactive.button.toggled.pressed.bg",
707 theme->a_toggled_unfocused_pressed_max,
708 TRUE))
709 {
710 RrAppearanceFree(theme->a_toggled_unfocused_pressed_max);
711 theme->a_toggled_unfocused_pressed_max =
712 RrAppearanceCopy(theme->a_unfocused_pressed_max);
713 }
714 if (!read_appearance(db, inst,
715 "window.active.button.unpressed.bg",
716 theme->a_focused_unpressed_max,
717 TRUE))
718 set_default_appearance(theme->a_focused_unpressed_max);
719 if (!read_appearance(db, inst,
720 "window.inactive.button.unpressed.bg",
721 theme->a_unfocused_unpressed_max,
722 TRUE))
723 set_default_appearance(theme->a_unfocused_unpressed_max);
724 if (!read_appearance(db, inst,
725 "window.active.button.hover.bg",
726 theme->a_hover_focused_max,
727 TRUE))
728 {
729 RrAppearanceFree(theme->a_hover_focused_max);
730 theme->a_hover_focused_max =
731 RrAppearanceCopy(theme->a_focused_unpressed_max);
732 }
733 if (!read_appearance(db, inst,
734 "window.inactive.button.hover.bg",
735 theme->a_hover_unfocused_max,
736 TRUE))
737 {
738 RrAppearanceFree(theme->a_hover_unfocused_max);
739 theme->a_hover_unfocused_max =
740 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
741 }
742
743 theme->a_disabled_focused_close =
744 RrAppearanceCopy(theme->a_disabled_focused_max);
745 theme->a_disabled_unfocused_close =
746 RrAppearanceCopy(theme->a_disabled_unfocused_max);
747 theme->a_hover_focused_close =
748 RrAppearanceCopy(theme->a_hover_focused_max);
749 theme->a_hover_unfocused_close =
750 RrAppearanceCopy(theme->a_hover_unfocused_max);
751 theme->a_unfocused_unpressed_close =
752 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
753 theme->a_unfocused_pressed_close =
754 RrAppearanceCopy(theme->a_unfocused_pressed_max);
755 theme->a_focused_unpressed_close =
756 RrAppearanceCopy(theme->a_focused_unpressed_max);
757 theme->a_focused_pressed_close =
758 RrAppearanceCopy(theme->a_focused_pressed_max);
759 theme->a_disabled_focused_desk =
760 RrAppearanceCopy(theme->a_disabled_focused_max);
761 theme->a_disabled_unfocused_desk =
762 RrAppearanceCopy(theme->a_disabled_unfocused_max);
763 theme->a_hover_focused_desk =
764 RrAppearanceCopy(theme->a_hover_focused_max);
765 theme->a_hover_unfocused_desk =
766 RrAppearanceCopy(theme->a_hover_unfocused_max);
767 theme->a_toggled_hover_focused_desk =
768 RrAppearanceCopy(theme->a_toggled_hover_focused_max);
769 theme->a_toggled_hover_unfocused_desk =
770 RrAppearanceCopy(theme->a_toggled_hover_unfocused_max);
771 theme->a_toggled_focused_unpressed_desk =
772 RrAppearanceCopy(theme->a_toggled_focused_unpressed_max);
773 theme->a_toggled_unfocused_unpressed_desk =
774 RrAppearanceCopy(theme->a_toggled_unfocused_unpressed_max);
775 theme->a_toggled_focused_pressed_desk =
776 RrAppearanceCopy(theme->a_toggled_focused_pressed_max);
777 theme->a_toggled_unfocused_pressed_desk =
778 RrAppearanceCopy(theme->a_toggled_unfocused_pressed_max);
779 theme->a_unfocused_unpressed_desk =
780 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
781 theme->a_unfocused_pressed_desk =
782 RrAppearanceCopy(theme->a_unfocused_pressed_max);
783 theme->a_focused_unpressed_desk =
784 RrAppearanceCopy(theme->a_focused_unpressed_max);
785 theme->a_focused_pressed_desk =
786 RrAppearanceCopy(theme->a_focused_pressed_max);
787 theme->a_disabled_focused_shade =
788 RrAppearanceCopy(theme->a_disabled_focused_max);
789 theme->a_disabled_unfocused_shade =
790 RrAppearanceCopy(theme->a_disabled_unfocused_max);
791 theme->a_hover_focused_shade =
792 RrAppearanceCopy(theme->a_hover_focused_max);
793 theme->a_hover_unfocused_shade =
794 RrAppearanceCopy(theme->a_hover_unfocused_max);
795 theme->a_toggled_hover_focused_shade =
796 RrAppearanceCopy(theme->a_toggled_hover_focused_max);
797 theme->a_toggled_hover_unfocused_shade =
798 RrAppearanceCopy(theme->a_toggled_hover_unfocused_max);
799 theme->a_toggled_focused_unpressed_shade =
800 RrAppearanceCopy(theme->a_toggled_focused_unpressed_max);
801 theme->a_toggled_unfocused_unpressed_shade =
802 RrAppearanceCopy(theme->a_toggled_unfocused_unpressed_max);
803 theme->a_toggled_focused_pressed_shade =
804 RrAppearanceCopy(theme->a_toggled_focused_pressed_max);
805 theme->a_toggled_unfocused_pressed_shade =
806 RrAppearanceCopy(theme->a_toggled_unfocused_pressed_max);
807 theme->a_unfocused_unpressed_shade =
808 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
809 theme->a_unfocused_pressed_shade =
810 RrAppearanceCopy(theme->a_unfocused_pressed_max);
811 theme->a_focused_unpressed_shade =
812 RrAppearanceCopy(theme->a_focused_unpressed_max);
813 theme->a_focused_pressed_shade =
814 RrAppearanceCopy(theme->a_focused_pressed_max);
815 theme->a_disabled_focused_iconify =
816 RrAppearanceCopy(theme->a_disabled_focused_max);
817 theme->a_disabled_unfocused_iconify =
818 RrAppearanceCopy(theme->a_disabled_focused_max);
819 theme->a_hover_focused_iconify =
820 RrAppearanceCopy(theme->a_hover_focused_max);
821 theme->a_hover_unfocused_iconify =
822 RrAppearanceCopy(theme->a_hover_unfocused_max);
823 theme->a_unfocused_unpressed_iconify =
824 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
825 theme->a_unfocused_pressed_iconify =
826 RrAppearanceCopy(theme->a_unfocused_pressed_max);
827 theme->a_focused_unpressed_iconify =
828 RrAppearanceCopy(theme->a_focused_unpressed_max);
829 theme->a_focused_pressed_iconify =
830 RrAppearanceCopy(theme->a_focused_pressed_max);
831
832 theme->a_icon->surface.grad =
833 theme->a_clear->surface.grad =
834 theme->a_clear_tex->surface.grad =
835 theme->a_menu_text_title->surface.grad =
836 theme->a_menu_normal->surface.grad =
837 theme->a_menu_disabled->surface.grad =
838 theme->a_menu_text_normal->surface.grad =
839 theme->a_menu_text_selected->surface.grad =
840 theme->a_menu_text_disabled->surface.grad =
841 theme->a_menu_text_disabled_selected->surface.grad =
842 theme->a_menu_bullet_normal->surface.grad =
843 theme->a_menu_bullet_selected->surface.grad = RR_SURFACE_PARENTREL;
844
845 /* set up the textures */
846 theme->a_focused_label->texture[0].type = RR_TEXTURE_TEXT;
847 theme->a_focused_label->texture[0].data.text.justify = winjust;
848 theme->a_focused_label->texture[0].data.text.font=theme->win_font_focused;
849 theme->a_focused_label->texture[0].data.text.color =
850 theme->title_focused_color;
851
852 if (read_string(db, "window.active.label.text.font", &str)) {
853 char *p;
854 gint i = 0;
855 gint j;
856 if (strstr(str, "shadow=y")) {
857 if ((p = strstr(str, "shadowoffset=")))
858 i = parse_inline_number(p + strlen("shadowoffset="));
859 else
860 i = 1;
861 theme->a_focused_label->texture[0].data.text.shadow_offset_x = i;
862 theme->a_focused_label->texture[0].data.text.shadow_offset_y = i;
863 }
864 if ((p = strstr(str, "shadowtint=")))
865 {
866 i = parse_inline_number(p + strlen("shadowtint="));
867 j = (i > 0 ? 0 : 255);
868 i = ABS(i*255/100);
869
870 theme->title_focused_shadow_color = RrColorNew(inst, j, j, j);
871 theme->title_focused_shadow_alpha = i;
872 } else {
873 theme->title_focused_shadow_color = RrColorNew(inst, 0, 0, 0);
874 theme->title_focused_shadow_alpha = 50;
875 }
876 }
877
878 theme->a_focused_label->texture[0].data.text.shadow_color =
879 theme->title_focused_shadow_color;
880 theme->a_focused_label->texture[0].data.text.shadow_alpha =
881 theme->title_focused_shadow_alpha;
882
883 theme->osd_hilite_label->texture[0].type = RR_TEXTURE_TEXT;
884 theme->osd_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
885 theme->osd_hilite_label->texture[0].data.text.font = theme->osd_font;
886 theme->osd_hilite_label->texture[0].data.text.color = theme->osd_color;
887
888 if (read_string(db, "osd.label.text.font", &str)) {
889 char *p;
890 gint i = 0;
891 gint j;
892 if (strstr(str, "shadow=y")) {
893 if ((p = strstr(str, "shadowoffset=")))
894 i = parse_inline_number(p + strlen("shadowoffset="));
895 else
896 i = 1;
897 theme->a_focused_label->texture[0].data.text.shadow_offset_x = i;
898 theme->a_focused_label->texture[0].data.text.shadow_offset_y = i;
899 theme->osd_hilite_label->texture[0].data.text.shadow_offset_x = i;
900 theme->osd_hilite_label->texture[0].data.text.shadow_offset_y = i;
901 }
902 if ((p = strstr(str, "shadowtint=")))
903 {
904 i = parse_inline_number(p + strlen("shadowtint="));
905 j = (i > 0 ? 0 : 255);
906 i = ABS(i*255/100);
907
908 theme->osd_shadow_color = RrColorNew(inst, j, j, j);
909 theme->osd_shadow_alpha = i;
910 } else {
911 theme->osd_shadow_color = RrColorNew(inst, 0, 0, 0);
912 theme->osd_shadow_alpha = 50;
913 }
914 } else {
915 /* inherit the font settings from the focused label */
916 theme->osd_hilite_label->texture[0].data.text.shadow_offset_x =
917 theme->a_focused_label->texture[0].data.text.shadow_offset_x;
918 theme->osd_hilite_label->texture[0].data.text.shadow_offset_y =
919 theme->a_focused_label->texture[0].data.text.shadow_offset_y;
920 if (theme->title_focused_shadow_color)
921 theme->osd_shadow_color =
922 RrColorNew(inst,
923 theme->title_focused_shadow_color->r,
924 theme->title_focused_shadow_color->g,
925 theme->title_focused_shadow_color->b);
926 else
927 theme->osd_shadow_color = RrColorNew(inst, 0, 0, 0);
928 theme->osd_shadow_alpha = theme->title_focused_shadow_alpha;
929 }
930
931 theme->osd_hilite_label->texture[0].data.text.shadow_color =
932 theme->osd_shadow_color;
933 theme->osd_hilite_label->texture[0].data.text.shadow_alpha =
934 theme->osd_shadow_alpha;
935
936 theme->a_unfocused_label->texture[0].type = RR_TEXTURE_TEXT;
937 theme->a_unfocused_label->texture[0].data.text.justify = winjust;
938 theme->a_unfocused_label->texture[0].data.text.font =
939 theme->win_font_unfocused;
940 theme->a_unfocused_label->texture[0].data.text.color =
941 theme->title_unfocused_color;
942
943 if (read_string(db, "window.inactive.label.text.font", &str)) {
944 char *p;
945 gint i = 0;
946 gint j;
947 if (strstr(str, "shadow=y")) {
948 if ((p = strstr(str, "shadowoffset=")))
949 i = parse_inline_number(p + strlen("shadowoffset="));
950 else
951 i = 1;
952 theme->a_unfocused_label->texture[0].data.text.shadow_offset_x = i;
953 theme->a_unfocused_label->texture[0].data.text.shadow_offset_y = i;
954 }
955 if ((p = strstr(str, "shadowtint=")))
956 {
957 i = parse_inline_number(p + strlen("shadowtint="));
958 j = (i > 0 ? 0 : 255);
959 i = ABS(i*255/100);
960
961 theme->title_unfocused_shadow_color = RrColorNew(inst, j, j, j);
962 theme->title_unfocused_shadow_alpha = i;
963 } else {
964 theme->title_unfocused_shadow_color = RrColorNew(inst, 0, 0, 0);
965 theme->title_unfocused_shadow_alpha = 50;
966 }
967 }
968
969 theme->a_unfocused_label->texture[0].data.text.shadow_color =
970 theme->title_unfocused_shadow_color;
971 theme->a_unfocused_label->texture[0].data.text.shadow_alpha =
972 theme->title_unfocused_shadow_alpha;
973
974 theme->a_menu_text_title->texture[0].type = RR_TEXTURE_TEXT;
975 theme->a_menu_text_title->texture[0].data.text.justify = mtitlejust;
976 theme->a_menu_text_title->texture[0].data.text.font =
977 theme->menu_title_font;
978 theme->a_menu_text_title->texture[0].data.text.color =
979 theme->menu_title_color;
980
981 if (read_string(db, "menu.title.text.font", &str)) {
982 char *p;
983 gint i = 0;
984 gint j;
985 if (strstr(str, "shadow=y")) {
986 if ((p = strstr(str, "shadowoffset=")))
987 i = parse_inline_number(p + strlen("shadowoffset="));
988 else
989 i = 1;
990 theme->a_menu_text_title->texture[0].data.text.shadow_offset_x = i;
991 theme->a_menu_text_title->texture[0].data.text.shadow_offset_y = i;
992 }
993 if ((p = strstr(str, "shadowtint=")))
994 {
995 i = parse_inline_number(p + strlen("shadowtint="));
996 j = (i > 0 ? 0 : 255);
997 i = ABS(i*255/100);
998
999 theme->menu_title_shadow_color = RrColorNew(inst, j, j, j);
1000 theme->menu_title_shadow_alpha = i;
1001 } else {
1002 theme->menu_title_shadow_color = RrColorNew(inst, 0, 0, 0);
1003 theme->menu_title_shadow_alpha = 50;
1004 }
1005 }
1006
1007 theme->a_menu_text_title->texture[0].data.text.shadow_color =
1008 theme->menu_title_shadow_color;
1009 theme->a_menu_text_title->texture[0].data.text.shadow_alpha =
1010 theme->menu_title_shadow_alpha;
1011
1012 theme->a_menu_text_normal->texture[0].type =
1013 theme->a_menu_text_selected->texture[0].type =
1014 theme->a_menu_text_disabled->texture[0].type =
1015 theme->a_menu_text_disabled_selected->texture[0].type =
1016 RR_TEXTURE_TEXT;
1017 theme->a_menu_text_normal->texture[0].data.text.justify =
1018 theme->a_menu_text_selected->texture[0].data.text.justify =
1019 theme->a_menu_text_disabled->texture[0].data.text.justify =
1020 theme->a_menu_text_disabled_selected->texture[0].data.text.justify =
1021 RR_JUSTIFY_LEFT;
1022 theme->a_menu_text_normal->texture[0].data.text.font =
1023 theme->a_menu_text_selected->texture[0].data.text.font =
1024 theme->a_menu_text_disabled->texture[0].data.text.font =
1025 theme->a_menu_text_disabled_selected->texture[0].data.text.font =
1026 theme->menu_font;
1027 theme->a_menu_text_normal->texture[0].data.text.color = theme->menu_color;
1028 theme->a_menu_text_selected->texture[0].data.text.color =
1029 theme->menu_selected_color;
1030 theme->a_menu_text_disabled->texture[0].data.text.color =
1031 theme->menu_disabled_color;
1032 theme->a_menu_text_disabled_selected->texture[0].data.text.color =
1033 theme->menu_disabled_selected_color;
1034
1035 if (read_string(db, "menu.items.font", &str)) {
1036 char *p;
1037 gint i = 0;
1038 gint j;
1039 if (strstr(str, "shadow=y")) {
1040 if ((p = strstr(str, "shadowoffset=")))
1041 i = parse_inline_number(p + strlen("shadowoffset="));
1042 else
1043 i = 1;
1044 theme->a_menu_text_normal->
1045 texture[0].data.text.shadow_offset_x = i;
1046 theme->a_menu_text_normal->
1047 texture[0].data.text.shadow_offset_y = i;
1048 theme->a_menu_text_selected->
1049 texture[0].data.text.shadow_offset_x = i;
1050 theme->a_menu_text_selected->
1051 texture[0].data.text.shadow_offset_y = i;
1052 theme->a_menu_text_disabled->
1053 texture[0].data.text.shadow_offset_x = i;
1054 theme->a_menu_text_disabled->
1055 texture[0].data.text.shadow_offset_y = i;
1056 theme->a_menu_text_disabled_selected->
1057 texture[0].data.text.shadow_offset_x = i;
1058 theme->a_menu_text_disabled_selected->
1059 texture[0].data.text.shadow_offset_y = i;
1060 }
1061 if ((p = strstr(str, "shadowtint=")))
1062 {
1063 i = parse_inline_number(p + strlen("shadowtint="));
1064 j = (i > 0 ? 0 : 255);
1065 i = ABS(i*255/100);
1066
1067 theme->menu_text_normal_shadow_color = RrColorNew(inst, j, j, j);
1068 theme->menu_text_selected_shadow_color = RrColorNew(inst, j, j, j);
1069 theme->menu_text_disabled_shadow_color = RrColorNew(inst, j, j, j);
1070 theme->menu_text_normal_shadow_alpha = i;
1071 theme->menu_text_selected_shadow_alpha = i;
1072 theme->menu_text_disabled_shadow_alpha = i;
1073 theme->menu_text_disabled_selected_shadow_alpha = i;
1074 } else {
1075 theme->menu_text_normal_shadow_color = RrColorNew(inst, 0, 0, 0);
1076 theme->menu_text_selected_shadow_color = RrColorNew(inst, 0, 0, 0);
1077 theme->menu_text_disabled_shadow_color = RrColorNew(inst, 0, 0, 0);
1078 theme->menu_text_normal_shadow_alpha = 50;
1079 theme->menu_text_selected_shadow_alpha = 50;
1080 theme->menu_text_disabled_selected_shadow_alpha = 50;
1081 }
1082 }
1083
1084 theme->a_menu_text_normal->texture[0].data.text.shadow_color =
1085 theme->menu_text_normal_shadow_color;
1086 theme->a_menu_text_normal->texture[0].data.text.shadow_alpha =
1087 theme->menu_text_normal_shadow_alpha;
1088 theme->a_menu_text_selected->texture[0].data.text.shadow_color =
1089 theme->menu_text_selected_shadow_color;
1090 theme->a_menu_text_selected->texture[0].data.text.shadow_alpha =
1091 theme->menu_text_selected_shadow_alpha;
1092 theme->a_menu_text_disabled->texture[0].data.text.shadow_color =
1093 theme->menu_text_disabled_shadow_color;
1094 theme->a_menu_text_disabled->texture[0].data.text.shadow_alpha =
1095 theme->menu_text_disabled_shadow_alpha;
1096 theme->a_menu_text_disabled_selected->texture[0].data.text.shadow_color =
1097 theme->menu_text_disabled_shadow_color;
1098 theme->a_menu_text_disabled_selected->texture[0].data.text.shadow_alpha =
1099 theme->menu_text_disabled_shadow_alpha;
1100
1101 theme->a_disabled_focused_max->texture[0].type =
1102 theme->a_disabled_unfocused_max->texture[0].type =
1103 theme->a_hover_focused_max->texture[0].type =
1104 theme->a_hover_unfocused_max->texture[0].type =
1105 theme->a_toggled_hover_focused_max->texture[0].type =
1106 theme->a_toggled_hover_unfocused_max->texture[0].type =
1107 theme->a_toggled_focused_unpressed_max->texture[0].type =
1108 theme->a_toggled_unfocused_unpressed_max->texture[0].type =
1109 theme->a_toggled_focused_pressed_max->texture[0].type =
1110 theme->a_toggled_unfocused_pressed_max->texture[0].type =
1111 theme->a_focused_unpressed_max->texture[0].type =
1112 theme->a_focused_pressed_max->texture[0].type =
1113 theme->a_unfocused_unpressed_max->texture[0].type =
1114 theme->a_unfocused_pressed_max->texture[0].type =
1115 theme->a_disabled_focused_close->texture[0].type =
1116 theme->a_disabled_unfocused_close->texture[0].type =
1117 theme->a_hover_focused_close->texture[0].type =
1118 theme->a_hover_unfocused_close->texture[0].type =
1119 theme->a_focused_unpressed_close->texture[0].type =
1120 theme->a_focused_pressed_close->texture[0].type =
1121 theme->a_unfocused_unpressed_close->texture[0].type =
1122 theme->a_unfocused_pressed_close->texture[0].type =
1123 theme->a_disabled_focused_desk->texture[0].type =
1124 theme->a_disabled_unfocused_desk->texture[0].type =
1125 theme->a_hover_focused_desk->texture[0].type =
1126 theme->a_hover_unfocused_desk->texture[0].type =
1127 theme->a_toggled_hover_focused_desk->texture[0].type =
1128 theme->a_toggled_hover_unfocused_desk->texture[0].type =
1129 theme->a_toggled_focused_unpressed_desk->texture[0].type =
1130 theme->a_toggled_unfocused_unpressed_desk->texture[0].type =
1131 theme->a_toggled_focused_pressed_desk->texture[0].type =
1132 theme->a_toggled_unfocused_pressed_desk->texture[0].type =
1133 theme->a_focused_unpressed_desk->texture[0].type =
1134 theme->a_focused_pressed_desk->texture[0].type =
1135 theme->a_unfocused_unpressed_desk->texture[0].type =
1136 theme->a_unfocused_pressed_desk->texture[0].type =
1137 theme->a_disabled_focused_shade->texture[0].type =
1138 theme->a_disabled_unfocused_shade->texture[0].type =
1139 theme->a_hover_focused_shade->texture[0].type =
1140 theme->a_hover_unfocused_shade->texture[0].type =
1141 theme->a_toggled_hover_focused_shade->texture[0].type =
1142 theme->a_toggled_hover_unfocused_shade->texture[0].type =
1143 theme->a_toggled_focused_unpressed_shade->texture[0].type =
1144 theme->a_toggled_unfocused_unpressed_shade->texture[0].type =
1145 theme->a_toggled_focused_pressed_shade->texture[0].type =
1146 theme->a_toggled_unfocused_pressed_shade->texture[0].type =
1147 theme->a_focused_unpressed_shade->texture[0].type =
1148 theme->a_focused_pressed_shade->texture[0].type =
1149 theme->a_unfocused_unpressed_shade->texture[0].type =
1150 theme->a_unfocused_pressed_shade->texture[0].type =
1151 theme->a_disabled_focused_iconify->texture[0].type =
1152 theme->a_disabled_unfocused_iconify->texture[0].type =
1153 theme->a_hover_focused_iconify->texture[0].type =
1154 theme->a_hover_unfocused_iconify->texture[0].type =
1155 theme->a_focused_unpressed_iconify->texture[0].type =
1156 theme->a_focused_pressed_iconify->texture[0].type =
1157 theme->a_unfocused_unpressed_iconify->texture[0].type =
1158 theme->a_unfocused_pressed_iconify->texture[0].type =
1159 theme->a_menu_bullet_normal->texture[0].type =
1160 theme->a_menu_bullet_selected->texture[0].type = RR_TEXTURE_MASK;
1161
1162 theme->a_disabled_focused_max->texture[0].data.mask.mask =
1163 theme->a_disabled_unfocused_max->texture[0].data.mask.mask =
1164 theme->max_disabled_mask;
1165 theme->a_hover_focused_max->texture[0].data.mask.mask =
1166 theme->a_hover_unfocused_max->texture[0].data.mask.mask =
1167 theme->max_hover_mask;
1168 theme->a_focused_pressed_max->texture[0].data.mask.mask =
1169 theme->a_unfocused_pressed_max->texture[0].data.mask.mask =
1170 theme->max_pressed_mask;
1171 theme->a_focused_unpressed_max->texture[0].data.mask.mask =
1172 theme->a_unfocused_unpressed_max->texture[0].data.mask.mask =
1173 theme->max_mask;
1174 theme->a_toggled_hover_focused_max->texture[0].data.mask.mask =
1175 theme->a_toggled_hover_unfocused_max->texture[0].data.mask.mask =
1176 theme->max_toggled_hover_mask;
1177 theme->a_toggled_focused_unpressed_max->texture[0].data.mask.mask =
1178 theme->a_toggled_unfocused_unpressed_max->texture[0].data.mask.mask =
1179 theme->max_toggled_mask;
1180 theme->a_toggled_focused_pressed_max->texture[0].data.mask.mask =
1181 theme->a_toggled_unfocused_pressed_max->texture[0].data.mask.mask =
1182 theme->max_toggled_pressed_mask;
1183 theme->a_disabled_focused_close->texture[0].data.mask.mask =
1184 theme->a_disabled_unfocused_close->texture[0].data.mask.mask =
1185 theme->close_disabled_mask;
1186 theme->a_hover_focused_close->texture[0].data.mask.mask =
1187 theme->a_hover_unfocused_close->texture[0].data.mask.mask =
1188 theme->close_hover_mask;
1189 theme->a_focused_pressed_close->texture[0].data.mask.mask =
1190 theme->a_unfocused_pressed_close->texture[0].data.mask.mask =
1191 theme->close_pressed_mask;
1192 theme->a_focused_unpressed_close->texture[0].data.mask.mask =
1193 theme->a_unfocused_unpressed_close->texture[0].data.mask.mask =
1194 theme->close_mask;
1195 theme->a_disabled_focused_desk->texture[0].data.mask.mask =
1196 theme->a_disabled_unfocused_desk->texture[0].data.mask.mask =
1197 theme->desk_disabled_mask;
1198 theme->a_hover_focused_desk->texture[0].data.mask.mask =
1199 theme->a_hover_unfocused_desk->texture[0].data.mask.mask =
1200 theme->desk_hover_mask;
1201 theme->a_focused_pressed_desk->texture[0].data.mask.mask =
1202 theme->a_unfocused_pressed_desk->texture[0].data.mask.mask =
1203 theme->desk_pressed_mask;
1204 theme->a_focused_unpressed_desk->texture[0].data.mask.mask =
1205 theme->a_unfocused_unpressed_desk->texture[0].data.mask.mask =
1206 theme->desk_mask;
1207 theme->a_toggled_hover_focused_desk->texture[0].data.mask.mask =
1208 theme->a_toggled_hover_unfocused_desk->texture[0].data.mask.mask =
1209 theme->desk_toggled_hover_mask;
1210 theme->a_toggled_focused_unpressed_desk->texture[0].data.mask.mask =
1211 theme->a_toggled_unfocused_unpressed_desk->texture[0].data.mask.mask =
1212 theme->desk_toggled_mask;
1213 theme->a_toggled_focused_pressed_desk->texture[0].data.mask.mask =
1214 theme->a_toggled_unfocused_pressed_desk->texture[0].data.mask.mask =
1215 theme->desk_toggled_pressed_mask;
1216 theme->a_disabled_focused_shade->texture[0].data.mask.mask =
1217 theme->a_disabled_unfocused_shade->texture[0].data.mask.mask =
1218 theme->shade_disabled_mask;
1219 theme->a_hover_focused_shade->texture[0].data.mask.mask =
1220 theme->a_hover_unfocused_shade->texture[0].data.mask.mask =
1221 theme->shade_hover_mask;
1222 theme->a_focused_pressed_shade->texture[0].data.mask.mask =
1223 theme->a_unfocused_pressed_shade->texture[0].data.mask.mask =
1224 theme->shade_pressed_mask;
1225 theme->a_focused_unpressed_shade->texture[0].data.mask.mask =
1226 theme->a_unfocused_unpressed_shade->texture[0].data.mask.mask =
1227 theme->shade_mask;
1228 theme->a_toggled_hover_focused_shade->texture[0].data.mask.mask =
1229 theme->a_toggled_hover_unfocused_shade->texture[0].data.mask.mask =
1230 theme->shade_toggled_hover_mask;
1231 theme->a_toggled_focused_unpressed_shade->texture[0].data.mask.mask =
1232 theme->a_toggled_unfocused_unpressed_shade->texture[0].data.mask.mask =
1233 theme->shade_toggled_mask;
1234 theme->a_toggled_focused_pressed_shade->texture[0].data.mask.mask =
1235 theme->a_toggled_unfocused_pressed_shade->texture[0].data.mask.mask =
1236 theme->shade_toggled_pressed_mask;
1237 theme->a_disabled_focused_iconify->texture[0].data.mask.mask =
1238 theme->a_disabled_unfocused_iconify->texture[0].data.mask.mask =
1239 theme->iconify_disabled_mask;
1240 theme->a_hover_focused_iconify->texture[0].data.mask.mask =
1241 theme->a_hover_unfocused_iconify->texture[0].data.mask.mask =
1242 theme->iconify_hover_mask;
1243 theme->a_focused_pressed_iconify->texture[0].data.mask.mask =
1244 theme->a_unfocused_pressed_iconify->texture[0].data.mask.mask =
1245 theme->iconify_pressed_mask;
1246 theme->a_focused_unpressed_iconify->texture[0].data.mask.mask =
1247 theme->a_unfocused_unpressed_iconify->texture[0].data.mask.mask =
1248 theme->iconify_mask;
1249 theme->a_menu_bullet_normal->texture[0].data.mask.mask =
1250 theme->a_menu_bullet_selected->texture[0].data.mask.mask =
1251 theme->menu_bullet_mask;
1252 theme->a_disabled_focused_max->texture[0].data.mask.color =
1253 theme->a_disabled_focused_close->texture[0].data.mask.color =
1254 theme->a_disabled_focused_desk->texture[0].data.mask.color =
1255 theme->a_disabled_focused_shade->texture[0].data.mask.color =
1256 theme->a_disabled_focused_iconify->texture[0].data.mask.color =
1257 theme->titlebut_disabled_focused_color;
1258 theme->a_disabled_unfocused_max->texture[0].data.mask.color =
1259 theme->a_disabled_unfocused_close->texture[0].data.mask.color =
1260 theme->a_disabled_unfocused_desk->texture[0].data.mask.color =
1261 theme->a_disabled_unfocused_shade->texture[0].data.mask.color =
1262 theme->a_disabled_unfocused_iconify->texture[0].data.mask.color =
1263 theme->titlebut_disabled_unfocused_color;
1264 theme->a_hover_focused_max->texture[0].data.mask.color =
1265 theme->a_hover_focused_close->texture[0].data.mask.color =
1266 theme->a_hover_focused_desk->texture[0].data.mask.color =
1267 theme->a_hover_focused_shade->texture[0].data.mask.color =
1268 theme->a_hover_focused_iconify->texture[0].data.mask.color =
1269 theme->titlebut_hover_focused_color;
1270 theme->a_hover_unfocused_max->texture[0].data.mask.color =
1271 theme->a_hover_unfocused_close->texture[0].data.mask.color =
1272 theme->a_hover_unfocused_desk->texture[0].data.mask.color =
1273 theme->a_hover_unfocused_shade->texture[0].data.mask.color =
1274 theme->a_hover_unfocused_iconify->texture[0].data.mask.color =
1275 theme->titlebut_hover_unfocused_color;
1276 theme->a_toggled_hover_focused_max->texture[0].data.mask.color =
1277 theme->a_toggled_hover_focused_desk->texture[0].data.mask.color =
1278 theme->a_toggled_hover_focused_shade->texture[0].data.mask.color =
1279 theme->titlebut_toggled_hover_focused_color;
1280 theme->a_toggled_hover_unfocused_max->texture[0].data.mask.color =
1281 theme->a_toggled_hover_unfocused_desk->texture[0].data.mask.color =
1282 theme->a_toggled_hover_unfocused_shade->texture[0].data.mask.color =
1283 theme->titlebut_toggled_hover_unfocused_color;
1284 theme->a_toggled_focused_unpressed_max->texture[0].data.mask.color =
1285 theme->a_toggled_focused_unpressed_desk->texture[0].data.mask.color =
1286 theme->a_toggled_focused_unpressed_shade->texture[0].data.mask.color =
1287 theme->titlebut_toggled_focused_unpressed_color;
1288 theme->a_toggled_unfocused_unpressed_max->texture[0].data.mask.color =
1289 theme->a_toggled_unfocused_unpressed_desk->texture[0].data.mask.color =
1290 theme->a_toggled_unfocused_unpressed_shade->texture[0].data.mask.color=
1291 theme->titlebut_toggled_unfocused_unpressed_color;
1292 theme->a_toggled_focused_pressed_max->texture[0].data.mask.color =
1293 theme->a_toggled_focused_pressed_desk->texture[0].data.mask.color =
1294 theme->a_toggled_focused_pressed_shade->texture[0].data.mask.color =
1295 theme->titlebut_toggled_focused_pressed_color;
1296 theme->a_toggled_unfocused_pressed_max->texture[0].data.mask.color =
1297 theme->a_toggled_unfocused_pressed_desk->texture[0].data.mask.color =
1298 theme->a_toggled_unfocused_pressed_shade->texture[0].data.mask.color =
1299 theme->titlebut_toggled_unfocused_pressed_color;
1300 theme->a_focused_unpressed_max->texture[0].data.mask.color =
1301 theme->a_focused_unpressed_close->texture[0].data.mask.color =
1302 theme->a_focused_unpressed_desk->texture[0].data.mask.color =
1303 theme->a_focused_unpressed_shade->texture[0].data.mask.color =
1304 theme->a_focused_unpressed_iconify->texture[0].data.mask.color =
1305 theme->titlebut_focused_unpressed_color;
1306 theme->a_focused_pressed_max->texture[0].data.mask.color =
1307 theme->a_focused_pressed_close->texture[0].data.mask.color =
1308 theme->a_focused_pressed_desk->texture[0].data.mask.color =
1309 theme->a_focused_pressed_shade->texture[0].data.mask.color =
1310 theme->a_focused_pressed_iconify->texture[0].data.mask.color =
1311 theme->titlebut_focused_pressed_color;
1312 theme->a_unfocused_unpressed_max->texture[0].data.mask.color =
1313 theme->a_unfocused_unpressed_close->texture[0].data.mask.color =
1314 theme->a_unfocused_unpressed_desk->texture[0].data.mask.color =
1315 theme->a_unfocused_unpressed_shade->texture[0].data.mask.color =
1316 theme->a_unfocused_unpressed_iconify->texture[0].data.mask.color =
1317 theme->titlebut_unfocused_unpressed_color;
1318 theme->a_unfocused_pressed_max->texture[0].data.mask.color =
1319 theme->a_unfocused_pressed_close->texture[0].data.mask.color =
1320 theme->a_unfocused_pressed_desk->texture[0].data.mask.color =
1321 theme->a_unfocused_pressed_shade->texture[0].data.mask.color =
1322 theme->a_unfocused_pressed_iconify->texture[0].data.mask.color =
1323 theme->titlebut_unfocused_pressed_color;
1324 theme->a_menu_bullet_normal->texture[0].data.mask.color =
1325 theme->menu_color;
1326 theme->a_menu_bullet_selected->texture[0].data.mask.color =
1327 theme->menu_selected_color;
1328
1329 g_free(path);
1330 XrmDestroyDatabase(db);
1331
1332 /* set the font heights */
1333 theme->win_font_height = RrFontHeight
1334 (theme->win_font_focused,
1335 theme->a_focused_label->texture[0].data.text.shadow_offset_y);
1336 theme->win_font_height =
1337 MAX(theme->win_font_height,
1338 RrFontHeight
1339 (theme->win_font_focused,
1340 theme->a_unfocused_label->texture[0].data.text.shadow_offset_y));
1341 theme->menu_title_font_height = RrFontHeight
1342 (theme->menu_title_font,
1343 theme->a_menu_text_title->texture[0].data.text.shadow_offset_y);
1344 theme->menu_font_height = RrFontHeight
1345 (theme->menu_font,
1346 theme->a_menu_text_normal->texture[0].data.text.shadow_offset_y);
1347
1348 /* calculate some last extents */
1349 {
1350 gint ft, fb, fl, fr, ut, ub, ul, ur;
1351
1352 RrMargins(theme->a_focused_label, &fl, &ft, &fr, &fb);
1353 RrMargins(theme->a_unfocused_label, &ul, &ut, &ur, &ub);
1354 theme->label_height = theme->win_font_height + MAX(ft + fb, ut + ub);
1355 theme->label_height += theme->label_height % 2;
1356
1357 /* this would be nice I think, since padding.width can now be 0,
1358 but it breaks frame.c horribly and I don't feel like fixing that
1359 right now, so if anyone complains, here is how to keep text from
1360 going over the title's bevel/border with a padding.width of 0 and a
1361 bevelless/borderless label
1362 RrMargins(theme->a_focused_title, &fl, &ft, &fr, &fb);
1363 RrMargins(theme->a_unfocused_title, &ul, &ut, &ur, &ub);
1364 theme->title_height = theme->label_height +
1365 MAX(MAX(theme->padding * 2, ft + fb),
1366 MAX(theme->padding * 2, ut + ub));
1367 */
1368 theme->title_height = theme->label_height + theme->paddingy * 2;
1369
1370 RrMargins(theme->a_menu_title, &ul, &ut, &ur, &ub);
1371 theme->menu_title_label_height = theme->menu_title_font_height+ut+ub;
1372 theme->menu_title_height = theme->menu_title_label_height +
1373 theme->paddingy * 2;
1374 }
1375 theme->button_size = theme->label_height - 2;
1376 theme->grip_width = 25;
1377
1378 return theme;
1379 }
1380
1381 void RrThemeFree(RrTheme *theme)
1382 {
1383 if (theme) {
1384 g_free(theme->name);
1385
1386 RrColorFree(theme->menu_border_color);
1387 RrColorFree(theme->osd_border_color);
1388 RrColorFree(theme->frame_focused_border_color);
1389 RrColorFree(theme->frame_unfocused_border_color);
1390 RrColorFree(theme->title_separator_focused_color);
1391 RrColorFree(theme->title_separator_unfocused_color);
1392 RrColorFree(theme->cb_unfocused_color);
1393 RrColorFree(theme->cb_focused_color);
1394 RrColorFree(theme->title_focused_color);
1395 RrColorFree(theme->title_unfocused_color);
1396 RrColorFree(theme->titlebut_disabled_focused_color);
1397 RrColorFree(theme->titlebut_disabled_unfocused_color);
1398 RrColorFree(theme->titlebut_hover_focused_color);
1399 RrColorFree(theme->titlebut_hover_unfocused_color);
1400 RrColorFree(theme->titlebut_toggled_hover_focused_color);
1401 RrColorFree(theme->titlebut_toggled_hover_unfocused_color);
1402 RrColorFree(theme->titlebut_toggled_focused_pressed_color);
1403 RrColorFree(theme->titlebut_toggled_unfocused_pressed_color);
1404 RrColorFree(theme->titlebut_toggled_focused_unpressed_color);
1405 RrColorFree(theme->titlebut_toggled_unfocused_unpressed_color);
1406 RrColorFree(theme->titlebut_focused_pressed_color);
1407 RrColorFree(theme->titlebut_unfocused_pressed_color);
1408 RrColorFree(theme->titlebut_focused_unpressed_color);
1409 RrColorFree(theme->titlebut_unfocused_unpressed_color);
1410 RrColorFree(theme->menu_title_color);
1411 RrColorFree(theme->menu_color);
1412 RrColorFree(theme->menu_selected_color);
1413 RrColorFree(theme->menu_disabled_color);
1414 RrColorFree(theme->menu_disabled_selected_color);
1415 RrColorFree(theme->title_focused_shadow_color);
1416 RrColorFree(theme->title_unfocused_shadow_color);
1417 RrColorFree(theme->osd_color);
1418 RrColorFree(theme->osd_shadow_color);
1419 RrColorFree(theme->menu_title_shadow_color);
1420 RrColorFree(theme->menu_text_normal_shadow_color);
1421 RrColorFree(theme->menu_text_selected_shadow_color);
1422 RrColorFree(theme->menu_text_disabled_shadow_color);
1423 RrColorFree(theme->menu_text_disabled_selected_shadow_color);
1424
1425 g_free(theme->def_win_icon);
1426
1427 RrPixmapMaskFree(theme->max_mask);
1428 RrPixmapMaskFree(theme->max_toggled_mask);
1429 RrPixmapMaskFree(theme->max_toggled_hover_mask);
1430 RrPixmapMaskFree(theme->max_toggled_pressed_mask);
1431 RrPixmapMaskFree(theme->max_disabled_mask);
1432 RrPixmapMaskFree(theme->max_hover_mask);
1433 RrPixmapMaskFree(theme->max_pressed_mask);
1434 RrPixmapMaskFree(theme->desk_mask);
1435 RrPixmapMaskFree(theme->desk_toggled_mask);
1436 RrPixmapMaskFree(theme->desk_toggled_hover_mask);
1437 RrPixmapMaskFree(theme->desk_toggled_pressed_mask);
1438 RrPixmapMaskFree(theme->desk_disabled_mask);
1439 RrPixmapMaskFree(theme->desk_hover_mask);
1440 RrPixmapMaskFree(theme->desk_pressed_mask);
1441 RrPixmapMaskFree(theme->shade_mask);
1442 RrPixmapMaskFree(theme->shade_toggled_mask);
1443 RrPixmapMaskFree(theme->shade_toggled_hover_mask);
1444 RrPixmapMaskFree(theme->shade_toggled_pressed_mask);
1445 RrPixmapMaskFree(theme->shade_disabled_mask);
1446 RrPixmapMaskFree(theme->shade_hover_mask);
1447 RrPixmapMaskFree(theme->shade_pressed_mask);
1448 RrPixmapMaskFree(theme->iconify_mask);
1449 RrPixmapMaskFree(theme->iconify_disabled_mask);
1450 RrPixmapMaskFree(theme->iconify_hover_mask);
1451 RrPixmapMaskFree(theme->iconify_pressed_mask);
1452 RrPixmapMaskFree(theme->close_mask);
1453 RrPixmapMaskFree(theme->close_disabled_mask);
1454 RrPixmapMaskFree(theme->close_hover_mask);
1455 RrPixmapMaskFree(theme->close_pressed_mask);
1456 RrPixmapMaskFree(theme->menu_bullet_mask);
1457
1458 RrFontClose(theme->win_font_focused);
1459 RrFontClose(theme->win_font_unfocused);
1460 RrFontClose(theme->menu_title_font);
1461 RrFontClose(theme->menu_font);
1462 RrFontClose(theme->osd_font);
1463
1464 RrAppearanceFree(theme->a_disabled_focused_max);
1465 RrAppearanceFree(theme->a_disabled_unfocused_max);
1466 RrAppearanceFree(theme->a_hover_focused_max);
1467 RrAppearanceFree(theme->a_hover_unfocused_max);
1468 RrAppearanceFree(theme->a_toggled_hover_focused_max);
1469 RrAppearanceFree(theme->a_toggled_hover_unfocused_max);
1470 RrAppearanceFree(theme->a_toggled_focused_unpressed_max);
1471 RrAppearanceFree(theme->a_toggled_focused_pressed_max);
1472 RrAppearanceFree(theme->a_toggled_unfocused_unpressed_max);
1473 RrAppearanceFree(theme->a_toggled_unfocused_pressed_max);
1474 RrAppearanceFree(theme->a_focused_unpressed_max);
1475 RrAppearanceFree(theme->a_focused_pressed_max);
1476 RrAppearanceFree(theme->a_unfocused_unpressed_max);
1477 RrAppearanceFree(theme->a_unfocused_pressed_max);
1478 RrAppearanceFree(theme->a_disabled_focused_close);
1479 RrAppearanceFree(theme->a_disabled_unfocused_close);
1480 RrAppearanceFree(theme->a_hover_focused_close);
1481 RrAppearanceFree(theme->a_hover_unfocused_close);
1482 RrAppearanceFree(theme->a_focused_unpressed_close);
1483 RrAppearanceFree(theme->a_focused_pressed_close);
1484 RrAppearanceFree(theme->a_unfocused_unpressed_close);
1485 RrAppearanceFree(theme->a_unfocused_pressed_close);
1486 RrAppearanceFree(theme->a_disabled_focused_desk);
1487 RrAppearanceFree(theme->a_disabled_unfocused_desk);
1488 RrAppearanceFree(theme->a_hover_focused_desk);
1489 RrAppearanceFree(theme->a_hover_unfocused_desk);
1490 RrAppearanceFree(theme->a_toggled_hover_focused_desk);
1491 RrAppearanceFree(theme->a_toggled_hover_unfocused_desk);
1492 RrAppearanceFree(theme->a_toggled_focused_unpressed_desk);
1493 RrAppearanceFree(theme->a_toggled_focused_pressed_desk);
1494 RrAppearanceFree(theme->a_toggled_unfocused_unpressed_desk);
1495 RrAppearanceFree(theme->a_toggled_unfocused_pressed_desk);
1496 RrAppearanceFree(theme->a_focused_unpressed_desk);
1497 RrAppearanceFree(theme->a_focused_pressed_desk);
1498 RrAppearanceFree(theme->a_unfocused_unpressed_desk);
1499 RrAppearanceFree(theme->a_unfocused_pressed_desk);
1500 RrAppearanceFree(theme->a_disabled_focused_shade);
1501 RrAppearanceFree(theme->a_disabled_unfocused_shade);
1502 RrAppearanceFree(theme->a_hover_focused_shade);
1503 RrAppearanceFree(theme->a_hover_unfocused_shade);
1504 RrAppearanceFree(theme->a_toggled_hover_focused_shade);
1505 RrAppearanceFree(theme->a_toggled_hover_unfocused_shade);
1506 RrAppearanceFree(theme->a_toggled_focused_unpressed_shade);
1507 RrAppearanceFree(theme->a_toggled_focused_pressed_shade);
1508 RrAppearanceFree(theme->a_toggled_unfocused_unpressed_shade);
1509 RrAppearanceFree(theme->a_toggled_unfocused_pressed_shade);
1510 RrAppearanceFree(theme->a_focused_unpressed_shade);
1511 RrAppearanceFree(theme->a_focused_pressed_shade);
1512 RrAppearanceFree(theme->a_unfocused_unpressed_shade);
1513 RrAppearanceFree(theme->a_unfocused_pressed_shade);
1514 RrAppearanceFree(theme->a_disabled_focused_iconify);
1515 RrAppearanceFree(theme->a_disabled_unfocused_iconify);
1516 RrAppearanceFree(theme->a_hover_focused_iconify);
1517 RrAppearanceFree(theme->a_hover_unfocused_iconify);
1518 RrAppearanceFree(theme->a_focused_unpressed_iconify);
1519 RrAppearanceFree(theme->a_focused_pressed_iconify);
1520 RrAppearanceFree(theme->a_unfocused_unpressed_iconify);
1521 RrAppearanceFree(theme->a_unfocused_pressed_iconify);
1522 RrAppearanceFree(theme->a_focused_grip);
1523 RrAppearanceFree(theme->a_unfocused_grip);
1524 RrAppearanceFree(theme->a_focused_title);
1525 RrAppearanceFree(theme->a_unfocused_title);
1526 RrAppearanceFree(theme->a_focused_label);
1527 RrAppearanceFree(theme->a_unfocused_label);
1528 RrAppearanceFree(theme->a_icon);
1529 RrAppearanceFree(theme->a_focused_handle);
1530 RrAppearanceFree(theme->a_unfocused_handle);
1531 RrAppearanceFree(theme->a_menu);
1532 RrAppearanceFree(theme->a_menu_title);
1533 RrAppearanceFree(theme->a_menu_text_title);
1534 RrAppearanceFree(theme->a_menu_normal);
1535 RrAppearanceFree(theme->a_menu_selected);
1536 RrAppearanceFree(theme->a_menu_disabled);
1537 RrAppearanceFree(theme->a_menu_disabled_selected);
1538 RrAppearanceFree(theme->a_menu_text_normal);
1539 RrAppearanceFree(theme->a_menu_text_selected);
1540 RrAppearanceFree(theme->a_menu_text_disabled);
1541 RrAppearanceFree(theme->a_menu_text_disabled_selected);
1542 RrAppearanceFree(theme->a_menu_bullet_normal);
1543 RrAppearanceFree(theme->a_menu_bullet_selected);
1544 RrAppearanceFree(theme->a_clear);
1545 RrAppearanceFree(theme->a_clear_tex);
1546 RrAppearanceFree(theme->osd_hilite_bg);
1547 RrAppearanceFree(theme->osd_hilite_fg);
1548 RrAppearanceFree(theme->osd_hilite_label);
1549 RrAppearanceFree(theme->osd_unhilite_fg);
1550
1551 g_free(theme);
1552 }
1553 }
1554
1555 static XrmDatabase loaddb(const gchar *name, gchar **path)
1556 {
1557 GSList *it;
1558 XrmDatabase db = NULL;
1559 gchar *s;
1560
1561 if (name[0] == '/') {
1562 s = g_build_filename(name, "openbox-3", "themerc", NULL);
1563 if ((db = XrmGetFileDatabase(s)))
1564 *path = g_path_get_dirname(s);
1565 g_free(s);
1566 } else {
1567 /* XXX backwards compatibility, remove me sometime later */
1568 s = g_build_filename(g_get_home_dir(), ".themes", name,
1569 "openbox-3", "themerc", NULL);
1570 if ((db = XrmGetFileDatabase(s)))
1571 *path = g_path_get_dirname(s);
1572 g_free(s);
1573
1574 for (it = parse_xdg_data_dir_paths(); !db && it;
1575 it = g_slist_next(it))
1576 {
1577 s = g_build_filename(it->data, "themes", name,
1578 "openbox-3", "themerc", NULL);
1579 if ((db = XrmGetFileDatabase(s)))
1580 *path = g_path_get_dirname(s);
1581 g_free(s);
1582 }
1583 }
1584
1585 if (db == NULL) {
1586 s = g_build_filename(name, "themerc", NULL);
1587 if ((db = XrmGetFileDatabase(s)))
1588 *path = g_path_get_dirname(s);
1589 g_free(s);
1590 }
1591
1592 return db;
1593 }
1594
1595 static gchar *create_class_name(const gchar *rname)
1596 {
1597 gchar *rclass = g_strdup(rname);
1598 gchar *p = rclass;
1599
1600 while (TRUE) {
1601 *p = toupper(*p);
1602 p = strchr(p+1, '.');
1603 if (p == NULL) break;
1604 ++p;
1605 if (*p == '\0') break;
1606 }
1607 return rclass;
1608 }
1609
1610 static gboolean read_int(XrmDatabase db, const gchar *rname, gint *value)
1611 {
1612 gboolean ret = FALSE;
1613 gchar *rclass = create_class_name(rname);
1614 gchar *rettype, *end;
1615 XrmValue retvalue;
1616
1617 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1618 retvalue.addr != NULL) {
1619 *value = (gint)strtol(retvalue.addr, &end, 10);
1620 if (end != retvalue.addr)
1621 ret = TRUE;
1622 }
1623
1624 g_free(rclass);
1625 return ret;
1626 }
1627
1628 static gboolean read_string(XrmDatabase db, const gchar *rname, gchar **value)
1629 {
1630 gboolean ret = FALSE;
1631 gchar *rclass = create_class_name(rname);
1632 gchar *rettype;
1633 XrmValue retvalue;
1634
1635 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1636 retvalue.addr != NULL) {
1637 *value = retvalue.addr;
1638 ret = TRUE;
1639 }
1640
1641 g_free(rclass);
1642 return ret;
1643 }
1644
1645 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
1646 const gchar *rname, RrColor **value)
1647 {
1648 gboolean ret = FALSE;
1649 gchar *rclass = create_class_name(rname);
1650 gchar *rettype;
1651 XrmValue retvalue;
1652
1653 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1654 retvalue.addr != NULL) {
1655 RrColor *c = RrColorParse(inst, retvalue.addr);
1656 if (c != NULL) {
1657 *value = c;
1658 ret = TRUE;
1659 }
1660 }
1661
1662 g_free(rclass);
1663 return ret;
1664 }
1665
1666 static gboolean read_mask(const RrInstance *inst, const gchar *path,
1667 RrTheme *theme, const gchar *maskname,
1668 RrPixmapMask **value)
1669 {
1670 gboolean ret = FALSE;
1671 gchar *s;
1672 gint hx, hy; /* ignored */
1673 guint w, h;
1674 guchar *b;
1675
1676 s = g_build_filename(path, maskname, NULL);
1677 if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess) {
1678 ret = TRUE;
1679 *value = RrPixmapMaskNew(inst, w, h, (gchar*)b);
1680 XFree(b);
1681 }
1682 g_free(s);
1683
1684 return ret;
1685 }
1686
1687 static void parse_appearance(gchar *tex, RrSurfaceColorType *grad,
1688 RrReliefType *relief, RrBevelType *bevel,
1689 gboolean *interlaced, gboolean *border,
1690 gboolean allow_trans)
1691 {
1692 gchar *t;
1693
1694 /* convert to all lowercase */
1695 for (t = tex; *t != '\0'; ++t)
1696 *t = g_ascii_tolower(*t);
1697
1698 if (allow_trans && strstr(tex, "parentrelative") != NULL) {
1699 *grad = RR_SURFACE_PARENTREL;
1700 } else {
1701 if (strstr(tex, "gradient") != NULL) {
1702 if (strstr(tex, "crossdiagonal") != NULL)
1703 *grad = RR_SURFACE_CROSS_DIAGONAL;
1704 else if (strstr(tex, "pyramid") != NULL)
1705 *grad = RR_SURFACE_PYRAMID;
1706 else if (strstr(tex, "mirrorhorizontal") != NULL)
1707 *grad = RR_SURFACE_MIRROR_HORIZONTAL;
1708 else if (strstr(tex, "horizontal") != NULL)
1709 *grad = RR_SURFACE_HORIZONTAL;
1710 else if (strstr(tex, "splitvertical") != NULL)
1711 *grad = RR_SURFACE_SPLIT_VERTICAL;
1712 else if (strstr(tex, "vertical") != NULL)
1713 *grad = RR_SURFACE_VERTICAL;
1714 else
1715 *grad = RR_SURFACE_DIAGONAL;
1716 } else {
1717 *grad = RR_SURFACE_SOLID;
1718 }
1719 }
1720
1721 if (strstr(tex, "sunken") != NULL)
1722 *relief = RR_RELIEF_SUNKEN;
1723 else if (strstr(tex, "flat") != NULL)
1724 *relief = RR_RELIEF_FLAT;
1725 else if (strstr(tex, "raised") != NULL)
1726 *relief = RR_RELIEF_RAISED;
1727 else
1728 *relief = (*grad == RR_SURFACE_PARENTREL) ?
1729 RR_RELIEF_FLAT : RR_RELIEF_RAISED;
1730
1731 *border = FALSE;
1732 if (*relief == RR_RELIEF_FLAT) {
1733 if (strstr(tex, "border") != NULL)
1734 *border = TRUE;
1735 } else {
1736 if (strstr(tex, "bevel2") != NULL)
1737 *bevel = RR_BEVEL_2;
1738 else
1739 *bevel = RR_BEVEL_1;
1740 }
1741
1742 if (strstr(tex, "interlaced") != NULL)
1743 *interlaced = TRUE;
1744 else
1745 *interlaced = FALSE;
1746 }
1747
1748
1749 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
1750 const gchar *rname, RrAppearance *value,
1751 gboolean allow_trans)
1752 {
1753 gboolean ret = FALSE;
1754 gchar *rclass = create_class_name(rname);
1755 gchar *cname, *ctoname, *bcname, *icname, *hname, *sname;
1756 gchar *csplitname, *ctosplitname;
1757 gchar *rettype;
1758 XrmValue retvalue;
1759 gint i;
1760
1761 cname = g_strconcat(rname, ".color", NULL);
1762 ctoname = g_strconcat(rname, ".colorTo", NULL);
1763 bcname = g_strconcat(rname, ".border.color", NULL);
1764 icname = g_strconcat(rname, ".interlace.color", NULL);
1765 hname = g_strconcat(rname, ".highlight", NULL);
1766 sname = g_strconcat(rname, ".shadow", NULL);
1767 csplitname = g_strconcat(rname, ".color.splitTo", NULL);
1768 ctosplitname = g_strconcat(rname, ".colorTo.splitTo", NULL);
1769
1770 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
1771 retvalue.addr != NULL) {
1772 parse_appearance(retvalue.addr,
1773 &value->surface.grad,
1774 &value->surface.relief,
1775 &value->surface.bevel,
1776 &value->surface.interlaced,
1777 &value->surface.border,
1778 allow_trans);
1779 if (!read_color(db, inst, cname, &value->surface.primary))
1780 value->surface.primary = RrColorNew(inst, 0, 0, 0);
1781 if (!read_color(db, inst, ctoname, &value->surface.secondary))
1782 value->surface.secondary = RrColorNew(inst, 0, 0, 0);
1783 if (value->surface.border)
1784 if (!read_color(db, inst, bcname,
1785 &value->surface.border_color))
1786 value->surface.border_color = RrColorNew(inst, 0, 0, 0);
1787 if (value->surface.interlaced)
1788 if (!read_color(db, inst, icname,
1789 &value->surface.interlace_color))
1790 value->surface.interlace_color = RrColorNew(inst, 0, 0, 0);
1791 if (read_int(db, hname, &i) && i >= 0)
1792 value->surface.bevel_light_adjust = i;
1793 if (read_int(db, sname, &i) && i >= 0 && i <= 256)
1794 value->surface.bevel_dark_adjust = i;
1795
1796 if (value->surface.grad == RR_SURFACE_SPLIT_VERTICAL) {
1797 gint r, g, b;
1798
1799 if (!read_color(db, inst, csplitname,
1800 &value->surface.split_primary))
1801 {
1802 r = value->surface.primary->r;
1803 r += r >> 2;
1804 g = value->surface.primary->g;
1805 g += g >> 2;
1806 b = value->surface.primary->b;
1807 b += b >> 2;
1808 if (r > 0xFF) r = 0xFF;
1809 if (g > 0xFF) g = 0xFF;
1810 if (b > 0xFF) b = 0xFF;
1811 value->surface.split_primary = RrColorNew(inst, r, g, b);
1812 }
1813
1814 if (!read_color(db, inst, ctosplitname,
1815 &value->surface.split_secondary))
1816 {
1817 r = value->surface.secondary->r;
1818 r += r >> 4;
1819 g = value->surface.secondary->g;
1820 g += g >> 4;
1821 b = value->surface.secondary->b;
1822 b += b >> 4;
1823 if (r > 0xFF) r = 0xFF;
1824 if (g > 0xFF) g = 0xFF;
1825 if (b > 0xFF) b = 0xFF;
1826 value->surface.split_secondary = RrColorNew(inst, r, g, b);
1827 }
1828 }
1829
1830 ret = TRUE;
1831 }
1832
1833 g_free(ctosplitname);
1834 g_free(csplitname);
1835 g_free(sname);
1836 g_free(hname);
1837 g_free(icname);
1838 g_free(bcname);
1839 g_free(ctoname);
1840 g_free(cname);
1841 g_free(rclass);
1842 return ret;
1843 }
1844
1845 static int parse_inline_number(const char *p)
1846 {
1847 int neg = 1;
1848 int res = 0;
1849 if (*p == '-') {
1850 neg = -1;
1851 ++p;
1852 }
1853 for (; isdigit(*p); ++p)
1854 res = res * 10 + *p - '0';
1855 res *= neg;
1856 return res;
1857 }
1858
1859 static void set_default_appearance(RrAppearance *a)
1860 {
1861 a->surface.grad = RR_SURFACE_SOLID;
1862 a->surface.relief = RR_RELIEF_FLAT;
1863 a->surface.bevel = RR_BEVEL_1;
1864 a->surface.interlaced = FALSE;
1865 a->surface.border = FALSE;
1866 a->surface.primary = RrColorNew(a->inst, 0, 0, 0);
1867 a->surface.secondary = RrColorNew(a->inst, 0, 0, 0);
1868 }
1869
1870 /* Reads the output from gimp's C-Source file format into valid RGBA data for
1871 an RrTextureRGBA. */
1872 static RrPixel32* read_c_image(gint width, gint height, const guint8 *data)
1873 {
1874 RrPixel32 *im, *p;
1875 gint i;
1876
1877 p = im = g_memdup(data, width * height * sizeof(RrPixel32));
1878
1879 for (i = 0; i < width * height; ++i) {
1880 guchar a = ((*p >> 24) & 0xff);
1881 guchar b = ((*p >> 16) & 0xff);
1882 guchar g = ((*p >> 8) & 0xff);
1883 guchar r = ((*p >> 0) & 0xff);
1884
1885 *p = ((r << RrDefaultRedOffset) +
1886 (g << RrDefaultGreenOffset) +
1887 (b << RrDefaultBlueOffset) +
1888 (a << RrDefaultAlphaOffset));
1889 p++;
1890 }
1891
1892 return im;
1893 }
This page took 0.127744 seconds and 4 git commands to generate.