]> Dogcows Code - chaz/openbox/blob - render/theme.c
read fonts and titlebar layout from theme files
[chaz/openbox] / render / theme.c
1 #include "render.h"
2 #include "color.h"
3 #include "font.h"
4 #include "mask.h"
5 #include "theme.h"
6
7 #include <X11/Xlib.h>
8 #include <X11/Xresource.h>
9
10 static XrmDatabase loaddb(char *theme);
11 static gboolean read_int(XrmDatabase db, char *rname, int *value);
12 static gboolean read_string(XrmDatabase db, char *rname, char **value);
13 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
14 gchar *rname, RrColor **value);
15 static gboolean read_mask(XrmDatabase db, const RrInstance *inst,
16 gchar *rname, gchar *theme,
17 RrPixmapMask **value);
18 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
19 gchar *rname, RrAppearance *value);
20 static void set_default_appearance(RrAppearance *a);
21
22 RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
23 {
24 XrmDatabase db = NULL;
25 RrJustify winjust, mtitlejust, mjust;
26 gchar *str;
27 gchar *font_str;
28 RrTheme *theme;
29
30 theme = g_new0(RrTheme, 1);
31
32 theme->inst = inst;
33
34 theme->b_color = theme->cb_unfocused_color = theme->cb_focused_color =
35 theme->title_unfocused_color = theme->title_focused_color =
36 theme->titlebut_unfocused_color = theme->titlebut_focused_color =
37 theme->menu_color = theme->menu_title_color =
38 theme->menu_disabled_color = theme->menu_hilite_color = NULL;
39 theme->winfont = theme->mtitlefont = theme->mfont = NULL;
40 theme->title_layout = NULL;
41 theme->max_set_mask = theme->max_unset_mask = NULL;
42 theme->desk_set_mask = theme->desk_unset_mask = NULL;
43 theme->shade_set_mask = theme->shade_unset_mask = NULL;
44 theme->iconify_mask = theme->close_mask = NULL;
45
46 theme->a_focused_unpressed_max = RrAppearanceNew(inst, 1);
47 theme->a_focused_pressed_max = RrAppearanceNew(inst, 1);
48 theme->a_focused_pressed_set_max = RrAppearanceNew(inst, 1);
49 theme->a_unfocused_unpressed_max = RrAppearanceNew(inst, 1);
50 theme->a_unfocused_pressed_max = RrAppearanceNew(inst, 1);
51 theme->a_unfocused_pressed_set_max = RrAppearanceNew(inst, 1);
52 theme->a_focused_unpressed_close = NULL;
53 theme->a_focused_pressed_close = NULL;
54 theme->a_unfocused_unpressed_close = NULL;
55 theme->a_unfocused_pressed_close = NULL;
56 theme->a_focused_unpressed_desk = NULL;
57 theme->a_focused_pressed_desk = NULL;
58 theme->a_focused_pressed_set_desk = NULL;
59 theme->a_unfocused_unpressed_desk = NULL;
60 theme->a_unfocused_pressed_desk = NULL;
61 theme->a_unfocused_pressed_set_desk = NULL;
62 theme->a_focused_unpressed_shade = NULL;
63 theme->a_focused_pressed_shade = NULL;
64 theme->a_focused_pressed_set_shade = NULL;
65 theme->a_unfocused_unpressed_shade = NULL;
66 theme->a_unfocused_pressed_shade = NULL;
67 theme->a_unfocused_pressed_set_shade = NULL;
68 theme->a_focused_unpressed_iconify = NULL;
69 theme->a_focused_pressed_iconify = NULL;
70 theme->a_unfocused_unpressed_iconify = NULL;
71 theme->a_unfocused_pressed_iconify = NULL;
72 theme->a_focused_grip = RrAppearanceNew(inst, 0);
73 theme->a_unfocused_grip = RrAppearanceNew(inst, 0);
74 theme->a_focused_title = RrAppearanceNew(inst, 0);
75 theme->a_unfocused_title = RrAppearanceNew(inst, 0);
76 theme->a_focused_label = RrAppearanceNew(inst, 1);
77 theme->a_unfocused_label = RrAppearanceNew(inst, 1);
78 theme->a_icon = RrAppearanceNew(inst, 1);
79 theme->a_focused_handle = RrAppearanceNew(inst, 0);
80 theme->a_unfocused_handle = RrAppearanceNew(inst, 0);
81 theme->a_menu = RrAppearanceNew(inst, 0);
82 theme->a_menu_title = RrAppearanceNew(inst, 1);
83 theme->a_menu_item = RrAppearanceNew(inst, 1);
84 theme->a_menu_disabled = RrAppearanceNew(inst, 1);
85 theme->a_menu_hilite = RrAppearanceNew(inst, 1);
86
87 theme->app_hilite_bg = RrAppearanceNew(inst, 0);
88 theme->app_unhilite_bg = RrAppearanceNew(inst, 0);
89 theme->app_hilite_label = RrAppearanceNew(inst, 1);
90 theme->app_unhilite_label = RrAppearanceNew(inst, 1);
91 theme->app_icon = RrAppearanceNew(inst, 1);
92
93 if (name) {
94 db = loaddb(name);
95 if (db == NULL) {
96 g_warning("Failed to load the theme '%s'", name);
97 g_message("Falling back to the default: '%s'", DEFAULT_THEME);
98 } else
99 theme->name = g_strdup(name);
100 }
101 if (db == NULL) {
102 db = loaddb(DEFAULT_THEME);
103 if (db == NULL) {
104 g_warning("Failed to load the theme '%s'.", DEFAULT_THEME);
105 return NULL;
106 } else
107 theme->name = g_strdup(DEFAULT_THEME);
108 }
109
110 /* load the font stuff */
111 if (!read_string(db, "window.title.xftfont", &font_str))
112 font_str = "arial,sans:bold:pixelsize=10:shadow=y:shadowtint=50";
113
114 if (!(theme->winfont = RrFontOpen(inst, font_str))) {
115 RrThemeFree(theme);
116 return NULL;
117 }
118 theme->winfont_height = RrFontHeight(theme->winfont);
119
120 winjust = RR_JUSTIFY_LEFT;
121 if (read_string(db, "window.justify", &str)) {
122 if (!g_ascii_strcasecmp(str, "right"))
123 winjust = RR_JUSTIFY_RIGHT;
124 else if (!g_ascii_strcasecmp(str, "center"))
125 winjust = RR_JUSTIFY_CENTER;
126 }
127
128 if (!read_string(db, "menu.title.xftfont", &font_str))
129 font_str = "arial,sans:bold:pixelsize=12:shadow=y";
130
131 if (!(theme->mtitlefont = RrFontOpen(inst, font_str))) {
132 RrThemeFree(theme);
133 return NULL;
134 }
135 theme->mtitlefont_height = RrFontHeight(theme->mtitlefont);
136
137 mtitlejust = RR_JUSTIFY_LEFT;
138 if (read_string(db, "menu.title.justify", &str)) {
139 if (!g_ascii_strcasecmp(str, "right"))
140 mtitlejust = RR_JUSTIFY_RIGHT;
141 else if (!g_ascii_strcasecmp(str, "center"))
142 mtitlejust = RR_JUSTIFY_CENTER;
143 }
144
145 if (!read_string(db, "menu.frame.xftfont", &font_str))
146 font_str = "arial,sans:bold:pixelsize=11:shadow=y";
147
148 if (!(theme->mfont = RrFontOpen(inst, font_str))) {
149 RrThemeFree(theme);
150 return NULL;
151 }
152 theme->mfont_height = RrFontHeight(theme->mfont);
153
154 mjust = RR_JUSTIFY_LEFT;
155 if (read_string(db, "menu.frame.justify", &str)) {
156 if (!g_ascii_strcasecmp(str, "right"))
157 mjust = RR_JUSTIFY_RIGHT;
158 else if (!g_ascii_strcasecmp(str, "center"))
159 mjust = RR_JUSTIFY_CENTER;
160 }
161
162 /* load the title layout */
163 if (!read_string(db, "window.title.layout", &font_str))
164 font_str = "NLIMC";
165 theme->title_layout = g_strdup(font_str);
166
167 if (!read_int(db, "handleWidth", &theme->handle_height) ||
168 theme->handle_height < 0 || theme->handle_height > 100)
169 theme->handle_height = 6;
170 if (!read_int(db, "bevelWidth", &theme->bevel) ||
171 theme->bevel <= 0 || theme->bevel > 100) theme->bevel = 3;
172 if (!read_int(db, "borderWidth", &theme->bwidth) ||
173 theme->bwidth < 0 || theme->bwidth > 100) theme->bwidth = 1;
174 if (!read_int(db, "frameWidth", &theme->cbwidth) ||
175 theme->cbwidth < 0 || theme->cbwidth > 100)
176 theme->cbwidth = theme->bevel;
177
178 /* load colors */
179 if (!read_color(db, inst,
180 "borderColor", &theme->b_color))
181 theme->b_color = RrColorNew(inst, 0, 0, 0);
182 if (!read_color(db, inst,
183 "window.frame.focusColor", &theme->cb_focused_color))
184 theme->cb_focused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
185 if (!read_color(db, inst,
186 "window.frame.unfocusColor",&theme->cb_unfocused_color))
187 theme->cb_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
188 if (!read_color(db, inst,
189 "window.label.focus.textColor",
190 &theme->title_focused_color))
191 theme->title_focused_color = RrColorNew(inst, 0x0, 0x0, 0x0);
192 if (!read_color(db, inst,
193 "window.label.unfocus.textColor",
194 &theme->title_unfocused_color))
195 theme->title_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
196 if (!read_color(db, inst,
197 "window.button.focus.picColor",
198 &theme->titlebut_focused_color))
199 theme->titlebut_focused_color = RrColorNew(inst, 0, 0, 0);
200 if (!read_color(db, inst,
201 "window.button.unfocus.picColor",
202 &theme->titlebut_unfocused_color))
203 theme->titlebut_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
204 if (!read_color(db, inst,
205 "menu.title.textColor", &theme->menu_title_color))
206 theme->menu_title_color = RrColorNew(inst, 0, 0, 0);
207 if (!read_color(db, inst,
208 "menu.frame.textColor", &theme->menu_color))
209 theme->menu_color = RrColorNew(inst, 0xff, 0xff, 0xff);
210 if (!read_color(db, inst,
211 "menu.frame.disableColor", &theme->menu_disabled_color))
212 theme->menu_disabled_color = RrColorNew(inst, 0, 0, 0);
213 if (!read_color(db, inst,
214 "menu.hilite.textColor", &theme->menu_hilite_color))
215 theme->menu_hilite_color = RrColorNew(inst, 0, 0, 0);
216
217 if (read_mask(db, inst,
218 "window.button.max.mask", name, &theme->max_unset_mask)){
219 if (!read_mask(db, inst,
220 "window.button.max.toggled.mask", name,
221 &theme->max_set_mask)) {
222 theme->max_set_mask = RrPixmapMaskCopy(theme->max_unset_mask);
223 }
224 } else {
225 {
226 char data[] = { 0x7f, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x7f };
227 theme->max_unset_mask = RrPixmapMaskNew(inst, 7, 7, data);
228 }
229 {
230 char data[] = { 0x7c, 0x44, 0x47, 0x47, 0x7f, 0x1f, 0x1f };
231 theme->max_set_mask = RrPixmapMaskNew(inst, 7, 7, data);
232 }
233 }
234
235 if (!read_mask(db, inst,
236 "window.button.icon.mask", name,
237 &theme->iconify_mask)) {
238 char data[] = { 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x7f };
239 theme->iconify_mask = RrPixmapMaskNew(inst, 7, 7, data);
240 }
241
242 if (read_mask(db, inst,
243 "window.button.stick.mask", name,
244 &theme->desk_unset_mask)) {
245 if (!read_mask(db, inst, "window.button.stick.toggled.mask", name,
246 &theme->desk_set_mask)) {
247 theme->desk_set_mask =
248 RrPixmapMaskCopy(theme->desk_unset_mask);
249 }
250 } else {
251 {
252 char data[] = { 0x63, 0x63, 0x00, 0x00, 0x00, 0x63, 0x63 };
253 theme->desk_unset_mask = RrPixmapMaskNew(inst, 7, 7, data);
254 }
255 {
256 char data[] = { 0x00, 0x36, 0x36, 0x08, 0x36, 0x36, 0x00 };
257 theme->desk_set_mask = RrPixmapMaskNew(inst, 7, 7, data);
258 }
259 }
260
261 if (read_mask(db, inst, "window.button.shade.mask", name,
262 &theme->shade_unset_mask)) {
263 if (!read_mask(db, inst, "window.button.shade.toggled.mask", name,
264 &theme->shade_set_mask)) {
265 theme->shade_set_mask =
266 RrPixmapMaskCopy(theme->shade_unset_mask);
267 }
268 } else {
269 {
270 char data[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00 };
271 theme->shade_unset_mask = RrPixmapMaskNew(inst, 7, 7, data);
272 }
273 {
274 char data[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x7f };
275 theme->shade_set_mask = RrPixmapMaskNew(inst, 7, 7, data);
276 }
277 }
278
279 if (!read_mask(db, inst, "window.button.close.mask", name,
280 &theme->close_mask)) {
281 char data[] = { 0x63, 0x77, 0x3e, 0x1c, 0x3e, 0x77, 0x63 };
282 theme->close_mask = RrPixmapMaskNew(inst, 7, 7, data);
283 }
284
285 /* read the decoration textures */
286 if (!read_appearance(db, inst,
287 "window.title.focus", theme->a_focused_title))
288 set_default_appearance(theme->a_focused_title);
289 if (!read_appearance(db, inst,
290 "window.title.unfocus", theme->a_unfocused_title))
291 set_default_appearance(theme->a_unfocused_title);
292 if (!read_appearance(db, inst,
293 "window.label.focus", theme->a_focused_label))
294 set_default_appearance(theme->a_focused_label);
295 if (!read_appearance(db, inst,
296 "window.label.unfocus", theme->a_unfocused_label))
297 set_default_appearance(theme->a_unfocused_label);
298 if (!read_appearance(db, inst,
299 "window.handle.focus", theme->a_focused_handle))
300 set_default_appearance(theme->a_focused_handle);
301 if (!read_appearance(db, inst,
302 "window.handle.unfocus",theme->a_unfocused_handle))
303 set_default_appearance(theme->a_unfocused_handle);
304 if (!read_appearance(db, inst,
305 "window.grip.focus", theme->a_focused_grip))
306 set_default_appearance(theme->a_focused_grip);
307 if (!read_appearance(db, inst,
308 "window.grip.unfocus", theme->a_unfocused_grip))
309 set_default_appearance(theme->a_unfocused_grip);
310 if (!read_appearance(db, inst,
311 "menu.frame", theme->a_menu))
312 set_default_appearance(theme->a_menu);
313 if (!read_appearance(db, inst,
314 "menu.title", theme->a_menu_title))
315 set_default_appearance(theme->a_menu_title);
316 if (!read_appearance(db, inst,
317 "menu.hilite", theme->a_menu_hilite))
318 set_default_appearance(theme->a_menu_hilite);
319
320 /* read the appearances for rendering non-decorations */
321 if (!read_appearance(db, inst,
322 "window.title.focus", theme->app_hilite_bg))
323 set_default_appearance(theme->app_hilite_bg);
324 if (!read_appearance(db, inst,
325 "window.label.focus", theme->app_hilite_label))
326 set_default_appearance(theme->app_hilite_label);
327 if (!read_appearance(db, inst,
328 "window.title.unfocus", theme->app_unhilite_bg))
329 set_default_appearance(theme->app_unhilite_bg);
330 if (!read_appearance(db, inst,
331 "window.label.unfocus", theme->app_unhilite_label))
332 set_default_appearance(theme->app_unhilite_label);
333
334 /* read buttons textures */
335 if (!read_appearance(db, inst,
336 "window.button.pressed.focus",
337 theme->a_focused_pressed_max))
338 if (!read_appearance(db, inst,
339 "window.button.pressed",
340 theme->a_focused_pressed_max))
341 set_default_appearance(theme->a_focused_pressed_max);
342 if (!read_appearance(db, inst,
343 "window.button.pressed.unfocus",
344 theme->a_unfocused_pressed_max))
345 if (!read_appearance(db, inst,
346 "window.button.pressed",
347 theme->a_unfocused_pressed_max))
348 set_default_appearance(theme->a_unfocused_pressed_max);
349 if (!read_appearance(db, inst,
350 "window.button.focus",
351 theme->a_focused_unpressed_max))
352 set_default_appearance(theme->a_focused_unpressed_max);
353 if (!read_appearance(db, inst,
354 "window.button.unfocus",
355 theme->a_unfocused_unpressed_max))
356 set_default_appearance(theme->a_unfocused_unpressed_max);
357
358 theme->a_unfocused_unpressed_close =
359 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
360 theme->a_unfocused_pressed_close =
361 RrAppearanceCopy(theme->a_unfocused_pressed_max);
362 theme->a_focused_unpressed_close =
363 RrAppearanceCopy(theme->a_focused_unpressed_max);
364 theme->a_focused_pressed_close =
365 RrAppearanceCopy(theme->a_focused_pressed_max);
366 theme->a_unfocused_unpressed_desk =
367 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
368 theme->a_unfocused_pressed_desk =
369 RrAppearanceCopy(theme->a_unfocused_pressed_max);
370 theme->a_unfocused_pressed_set_desk =
371 RrAppearanceCopy(theme->a_unfocused_pressed_max);
372 theme->a_focused_unpressed_desk =
373 RrAppearanceCopy(theme->a_focused_unpressed_max);
374 theme->a_focused_pressed_desk =
375 RrAppearanceCopy(theme->a_focused_pressed_max);
376 theme->a_focused_pressed_set_desk =
377 RrAppearanceCopy(theme->a_focused_pressed_max);
378 theme->a_unfocused_unpressed_shade =
379 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
380 theme->a_unfocused_pressed_shade =
381 RrAppearanceCopy(theme->a_unfocused_pressed_max);
382 theme->a_unfocused_pressed_set_shade =
383 RrAppearanceCopy(theme->a_unfocused_pressed_max);
384 theme->a_focused_unpressed_shade =
385 RrAppearanceCopy(theme->a_focused_unpressed_max);
386 theme->a_focused_pressed_shade =
387 RrAppearanceCopy(theme->a_focused_pressed_max);
388 theme->a_focused_pressed_set_shade =
389 RrAppearanceCopy(theme->a_focused_pressed_max);
390 theme->a_unfocused_unpressed_iconify =
391 RrAppearanceCopy(theme->a_unfocused_unpressed_max);
392 theme->a_unfocused_pressed_iconify =
393 RrAppearanceCopy(theme->a_unfocused_pressed_max);
394 theme->a_focused_unpressed_iconify =
395 RrAppearanceCopy(theme->a_focused_unpressed_max);
396 theme->a_focused_pressed_iconify =
397 RrAppearanceCopy(theme->a_focused_pressed_max);
398 theme->a_unfocused_pressed_set_max =
399 RrAppearanceCopy(theme->a_unfocused_pressed_max);
400 theme->a_focused_pressed_set_max =
401 RrAppearanceCopy(theme->a_focused_pressed_max);
402
403 theme->a_icon->surface.grad = RR_SURFACE_PARENTREL;
404
405 /* set up the textures */
406 theme->a_focused_label->texture[0].type =
407 theme->app_hilite_label->texture[0].type = RR_TEXTURE_TEXT;
408 theme->a_focused_label->texture[0].data.text.justify = winjust;
409 theme->app_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
410 theme->a_focused_label->texture[0].data.text.font =
411 theme->app_hilite_label->texture[0].data.text.font = theme->winfont;
412 theme->a_focused_label->texture[0].data.text.color =
413 theme->app_hilite_label->texture[0].data.text.color =
414 theme->title_focused_color;
415
416 theme->a_unfocused_label->texture[0].type =
417 theme->app_unhilite_label->texture[0].type = RR_TEXTURE_TEXT;
418 theme->a_unfocused_label->texture[0].data.text.justify = winjust;
419 theme->app_unhilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
420 theme->a_unfocused_label->texture[0].data.text.font =
421 theme->app_unhilite_label->texture[0].data.text.font = theme->winfont;
422 theme->a_unfocused_label->texture[0].data.text.color =
423 theme->app_unhilite_label->texture[0].data.text.color =
424 theme->title_unfocused_color;
425
426 theme->a_menu_title->texture[0].type = RR_TEXTURE_TEXT;
427 theme->a_menu_title->texture[0].data.text.justify = mtitlejust;
428 theme->a_menu_title->texture[0].data.text.font = theme->mtitlefont;
429 theme->a_menu_title->texture[0].data.text.color = theme->menu_title_color;
430
431 theme->a_menu_item->surface.grad =
432 theme->a_menu_disabled->surface.grad =
433 theme->app_icon->surface.grad = RR_SURFACE_PARENTREL;
434
435 theme->a_menu_item->texture[0].type =
436 theme->a_menu_disabled->texture[0].type =
437 theme->a_menu_hilite->texture[0].type = RR_TEXTURE_TEXT;
438 theme->a_menu_item->texture[0].data.text.justify =
439 theme->a_menu_disabled->texture[0].data.text.justify =
440 theme->a_menu_hilite->texture[0].data.text.justify = mjust;
441 theme->a_menu_item->texture[0].data.text.font =
442 theme->a_menu_disabled->texture[0].data.text.font =
443 theme->a_menu_hilite->texture[0].data.text.font = theme->mfont;
444 theme->a_menu_item->texture[0].data.text.color = theme->menu_color;
445 theme->a_menu_disabled->texture[0].data.text.color =
446 theme->menu_disabled_color;
447 theme->a_menu_hilite->texture[0].data.text.color =
448 theme->menu_hilite_color;
449
450 theme->a_focused_unpressed_max->texture[0].type =
451 theme->a_focused_pressed_max->texture[0].type =
452 theme->a_focused_pressed_set_max->texture[0].type =
453 theme->a_unfocused_unpressed_max->texture[0].type =
454 theme->a_unfocused_pressed_max->texture[0].type =
455 theme->a_unfocused_pressed_set_max->texture[0].type =
456 theme->a_focused_unpressed_close->texture[0].type =
457 theme->a_focused_pressed_close->texture[0].type =
458 theme->a_unfocused_unpressed_close->texture[0].type =
459 theme->a_unfocused_pressed_close->texture[0].type =
460 theme->a_focused_unpressed_desk->texture[0].type =
461 theme->a_focused_pressed_desk->texture[0].type =
462 theme->a_focused_pressed_set_desk->texture[0].type =
463 theme->a_unfocused_unpressed_desk->texture[0].type =
464 theme->a_unfocused_pressed_desk->texture[0].type =
465 theme->a_unfocused_pressed_set_desk->texture[0].type =
466 theme->a_focused_unpressed_shade->texture[0].type =
467 theme->a_focused_pressed_shade->texture[0].type =
468 theme->a_focused_pressed_set_shade->texture[0].type =
469 theme->a_unfocused_unpressed_shade->texture[0].type =
470 theme->a_unfocused_pressed_shade->texture[0].type =
471 theme->a_unfocused_pressed_set_shade->texture[0].type =
472 theme->a_focused_unpressed_iconify->texture[0].type =
473 theme->a_focused_pressed_iconify->texture[0].type =
474 theme->a_unfocused_unpressed_iconify->texture[0].type =
475 theme->a_unfocused_pressed_iconify->texture[0].type = RR_TEXTURE_MASK;
476 theme->a_focused_unpressed_max->texture[0].data.mask.mask =
477 theme->a_unfocused_unpressed_max->texture[0].data.mask.mask =
478 theme->a_focused_pressed_max->texture[0].data.mask.mask =
479 theme->a_unfocused_pressed_max->texture[0].data.mask.mask =
480 theme->max_unset_mask;
481 theme->a_focused_pressed_set_max->texture[0].data.mask.mask =
482 theme->a_unfocused_pressed_set_max->texture[0].data.mask.mask =
483 theme->max_set_mask;
484 theme->a_focused_pressed_close->texture[0].data.mask.mask =
485 theme->a_unfocused_pressed_close->texture[0].data.mask.mask =
486 theme->a_focused_unpressed_close->texture[0].data.mask.mask =
487 theme->a_unfocused_unpressed_close->texture[0].data.mask.mask =
488 theme->close_mask;
489 theme->a_focused_unpressed_desk->texture[0].data.mask.mask =
490 theme->a_unfocused_unpressed_desk->texture[0].data.mask.mask =
491 theme->a_focused_pressed_desk->texture[0].data.mask.mask =
492 theme->a_unfocused_pressed_desk->texture[0].data.mask.mask =
493 theme->desk_unset_mask;
494 theme->a_focused_pressed_set_desk->texture[0].data.mask.mask =
495 theme->a_unfocused_pressed_set_desk->texture[0].data.mask.mask =
496 theme->desk_set_mask;
497 theme->a_focused_unpressed_shade->texture[0].data.mask.mask =
498 theme->a_unfocused_unpressed_shade->texture[0].data.mask.mask =
499 theme->a_focused_pressed_shade->texture[0].data.mask.mask =
500 theme->a_unfocused_pressed_shade->texture[0].data.mask.mask =
501 theme->shade_unset_mask;
502 theme->a_focused_pressed_set_shade->texture[0].data.mask.mask =
503 theme->a_unfocused_pressed_set_shade->texture[0].data.mask.mask =
504 theme->shade_set_mask;
505 theme->a_focused_unpressed_iconify->texture[0].data.mask.mask =
506 theme->a_unfocused_unpressed_iconify->texture[0].data.mask.mask =
507 theme->a_focused_pressed_iconify->texture[0].data.mask.mask =
508 theme->a_unfocused_pressed_iconify->texture[0].data.mask.mask =
509 theme->iconify_mask;
510 theme->a_focused_unpressed_max->texture[0].data.mask.color =
511 theme->a_focused_pressed_max->texture[0].data.mask.color =
512 theme->a_focused_pressed_set_max->texture[0].data.mask.color =
513 theme->a_focused_unpressed_close->texture[0].data.mask.color =
514 theme->a_focused_pressed_close->texture[0].data.mask.color =
515 theme->a_focused_unpressed_desk->texture[0].data.mask.color =
516 theme->a_focused_pressed_desk->texture[0].data.mask.color =
517 theme->a_focused_pressed_set_desk->texture[0].data.mask.color =
518 theme->a_focused_unpressed_shade->texture[0].data.mask.color =
519 theme->a_focused_pressed_shade->texture[0].data.mask.color =
520 theme->a_focused_pressed_set_shade->texture[0].data.mask.color =
521 theme->a_focused_unpressed_iconify->texture[0].data.mask.color =
522 theme->a_focused_pressed_iconify->texture[0].data.mask.color =
523 theme->titlebut_focused_color;
524 theme->a_unfocused_unpressed_max->texture[0].data.mask.color =
525 theme->a_unfocused_pressed_max->texture[0].data.mask.color =
526 theme->a_unfocused_pressed_set_max->texture[0].data.mask.color =
527 theme->a_unfocused_unpressed_close->texture[0].data.mask.color =
528 theme->a_unfocused_pressed_close->texture[0].data.mask.color =
529 theme->a_unfocused_unpressed_desk->texture[0].data.mask.color =
530 theme->a_unfocused_pressed_desk->texture[0].data.mask.color =
531 theme->a_unfocused_pressed_set_desk->texture[0].data.mask.color =
532 theme->a_unfocused_unpressed_shade->texture[0].data.mask.color =
533 theme->a_unfocused_pressed_shade->texture[0].data.mask.color =
534 theme->a_unfocused_pressed_set_shade->texture[0].data.mask.color =
535 theme->a_unfocused_unpressed_iconify->texture[0].data.mask.color =
536 theme->a_unfocused_pressed_iconify->texture[0].data.mask.color =
537 theme->titlebut_unfocused_color;
538
539 XrmDestroyDatabase(db);
540
541 theme->label_height = theme->winfont_height;
542 theme->title_height = theme->label_height + theme->bevel * 2;
543 theme->button_size = theme->label_height - 2;
544 theme->grip_width = theme->button_size * 2;
545
546 return theme;
547 }
548
549 void RrThemeFree(RrTheme *theme)
550 {
551 if (theme) {
552 g_free(theme->name);
553
554 RrColorFree(theme->b_color);
555 RrColorFree(theme->cb_unfocused_color);
556 RrColorFree(theme->cb_focused_color);
557 RrColorFree(theme->title_unfocused_color);
558 RrColorFree(theme->title_focused_color);
559 RrColorFree(theme->titlebut_unfocused_color);
560 RrColorFree(theme->titlebut_focused_color);
561 RrColorFree(theme->menu_color);
562 RrColorFree(theme->menu_title_color);
563 RrColorFree(theme->menu_disabled_color);
564 RrColorFree(theme->menu_hilite_color);
565
566 RrPixmapMaskFree(theme->max_set_mask);
567 RrPixmapMaskFree(theme->max_unset_mask);
568 RrPixmapMaskFree(theme->desk_set_mask);
569 RrPixmapMaskFree(theme->desk_unset_mask);
570 RrPixmapMaskFree(theme->shade_set_mask);
571 RrPixmapMaskFree(theme->shade_unset_mask);
572 RrPixmapMaskFree(theme->iconify_mask);
573 RrPixmapMaskFree(theme->close_mask);
574
575 RrFontClose(theme->winfont);
576 RrFontClose(theme->mtitlefont);
577 RrFontClose(theme->mfont);
578
579 g_free(theme->title_layout);
580
581 RrAppearanceFree(theme->a_focused_unpressed_max);
582 RrAppearanceFree(theme->a_focused_pressed_max);
583 RrAppearanceFree(theme->a_focused_pressed_set_max);
584 RrAppearanceFree(theme->a_unfocused_unpressed_max);
585 RrAppearanceFree(theme->a_unfocused_pressed_max);
586 RrAppearanceFree(theme->a_unfocused_pressed_set_max);
587 RrAppearanceFree(theme->a_focused_unpressed_close);
588 RrAppearanceFree(theme->a_focused_pressed_close);
589 RrAppearanceFree(theme->a_unfocused_unpressed_close);
590 RrAppearanceFree(theme->a_unfocused_pressed_close);
591 RrAppearanceFree(theme->a_focused_unpressed_desk);
592 RrAppearanceFree(theme->a_focused_pressed_desk);
593 RrAppearanceFree(theme->a_unfocused_unpressed_desk);
594 RrAppearanceFree(theme->a_unfocused_pressed_desk);
595 RrAppearanceFree(theme->a_focused_unpressed_shade);
596 RrAppearanceFree(theme->a_focused_pressed_shade);
597 RrAppearanceFree(theme->a_unfocused_unpressed_shade);
598 RrAppearanceFree(theme->a_unfocused_pressed_shade);
599 RrAppearanceFree(theme->a_focused_unpressed_iconify);
600 RrAppearanceFree(theme->a_focused_pressed_iconify);
601 RrAppearanceFree(theme->a_unfocused_unpressed_iconify);
602 RrAppearanceFree(theme->a_unfocused_pressed_iconify);
603 RrAppearanceFree(theme->a_focused_grip);
604 RrAppearanceFree(theme->a_unfocused_grip);
605 RrAppearanceFree(theme->a_focused_title);
606 RrAppearanceFree(theme->a_unfocused_title);
607 RrAppearanceFree(theme->a_focused_label);
608 RrAppearanceFree(theme->a_unfocused_label);
609 RrAppearanceFree(theme->a_icon);
610 RrAppearanceFree(theme->a_focused_handle);
611 RrAppearanceFree(theme->a_unfocused_handle);
612 RrAppearanceFree(theme->a_menu);
613 RrAppearanceFree(theme->a_menu_title);
614 RrAppearanceFree(theme->a_menu_item);
615 RrAppearanceFree(theme->a_menu_disabled);
616 RrAppearanceFree(theme->a_menu_hilite);
617 RrAppearanceFree(theme->app_hilite_bg);
618 RrAppearanceFree(theme->app_unhilite_bg);
619 RrAppearanceFree(theme->app_hilite_label);
620 RrAppearanceFree(theme->app_unhilite_label);
621 RrAppearanceFree(theme->app_icon);
622 }
623 }
624
625 static XrmDatabase loaddb(char *theme)
626 {
627 XrmDatabase db;
628
629 db = XrmGetFileDatabase(theme);
630 if (db == NULL) {
631 char *s = g_build_filename(g_get_home_dir(), ".openbox", "themes",
632 theme, NULL);
633 db = XrmGetFileDatabase(s);
634 g_free(s);
635 }
636 if (db == NULL) {
637 char *s = g_build_filename(THEMEDIR, theme, NULL);
638 db = XrmGetFileDatabase(s);
639 g_free(s);
640 }
641 return db;
642 }
643
644 static char *create_class_name(char *rname)
645 {
646 char *rclass = g_strdup(rname);
647 char *p = rclass;
648
649 while (TRUE) {
650 *p = toupper(*p);
651 p = strchr(p+1, '.');
652 if (p == NULL) break;
653 ++p;
654 if (*p == '\0') break;
655 }
656 return rclass;
657 }
658
659 static gboolean read_int(XrmDatabase db, char *rname, int *value)
660 {
661 gboolean ret = FALSE;
662 char *rclass = create_class_name(rname);
663 char *rettype, *end;
664 XrmValue retvalue;
665
666 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
667 retvalue.addr != NULL) {
668 *value = (int)strtol(retvalue.addr, &end, 10);
669 if (end != retvalue.addr)
670 ret = TRUE;
671 }
672
673 g_free(rclass);
674 return ret;
675 }
676
677 static gboolean read_string(XrmDatabase db, char *rname, char **value)
678 {
679 gboolean ret = FALSE;
680 char *rclass = create_class_name(rname);
681 char *rettype;
682 XrmValue retvalue;
683
684 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
685 retvalue.addr != NULL) {
686 *value = retvalue.addr;
687 ret = TRUE;
688 }
689
690 g_free(rclass);
691 return ret;
692 }
693
694 static gboolean read_color(XrmDatabase db, const RrInstance *inst,
695 gchar *rname, RrColor **value)
696 {
697 gboolean ret = FALSE;
698 char *rclass = create_class_name(rname);
699 char *rettype;
700 XrmValue retvalue;
701
702 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
703 retvalue.addr != NULL) {
704 RrColor *c = RrColorParse(inst, retvalue.addr);
705 if (c != NULL) {
706 *value = c;
707 ret = TRUE;
708 }
709 }
710
711 g_free(rclass);
712 return ret;
713 }
714
715 static gboolean read_mask(XrmDatabase db, const RrInstance *inst,
716 gchar *rname, gchar *theme,
717 RrPixmapMask **value)
718 {
719 gboolean ret = FALSE;
720 char *rclass = create_class_name(rname);
721 char *rettype;
722 char *s;
723 char *button_dir;
724 XrmValue retvalue;
725 int hx, hy; /* ignored */
726 unsigned int w, h;
727 unsigned char *b;
728
729 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
730 retvalue.addr != NULL) {
731
732 button_dir = g_strdup_printf("%s_data", theme);
733
734 s = g_build_filename(g_get_home_dir(), ".openbox", "themes",
735 button_dir, retvalue.addr, NULL);
736
737 if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess)
738 ret = TRUE;
739 else {
740 g_free(s);
741 s = g_build_filename(THEMEDIR, button_dir, retvalue.addr, NULL);
742
743 if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == BitmapSuccess)
744 ret = TRUE;
745 else {
746 char *themename;
747
748 g_free(s);
749 themename = g_path_get_basename(theme);
750 s = g_strdup_printf("%s/%s_data/%s", theme,
751 themename, retvalue.addr);
752 g_free(themename);
753 if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) ==
754 BitmapSuccess)
755 ret = TRUE;
756 else
757 g_message("Unable to find bitmap '%s'", retvalue.addr);
758 }
759 }
760
761 if (ret) {
762 *value = RrPixmapMaskNew(inst, w, h, (char*)b);
763 XFree(b);
764 }
765
766 g_free(s);
767 g_free(button_dir);
768 }
769
770 g_free(rclass);
771 return ret;
772 }
773
774 static void parse_appearance(gchar *tex, RrSurfaceColorType *grad,
775 RrReliefType *relief, RrBevelType *bevel,
776 gboolean *interlaced, gboolean *border)
777 {
778 char *t;
779
780 /* convert to all lowercase */
781 for (t = tex; *t != '\0'; ++t)
782 *t = g_ascii_tolower(*t);
783
784 if (strstr(tex, "parentrelative") != NULL) {
785 *grad = RR_SURFACE_PARENTREL;
786 } else {
787 if (strstr(tex, "gradient") != NULL) {
788 if (strstr(tex, "crossdiagonal") != NULL)
789 *grad = RR_SURFACE_CROSS_DIAGONAL;
790 else if (strstr(tex, "pyramid") != NULL)
791 *grad = RR_SURFACE_PYRAMID;
792 else if (strstr(tex, "horizontal") != NULL)
793 *grad = RR_SURFACE_HORIZONTAL;
794 else if (strstr(tex, "vertical") != NULL)
795 *grad = RR_SURFACE_VERTICAL;
796 else
797 *grad = RR_SURFACE_DIAGONAL;
798 } else {
799 *grad = RR_SURFACE_SOLID;
800 }
801
802 if (strstr(tex, "sunken") != NULL)
803 *relief = RR_RELIEF_SUNKEN;
804 else if (strstr(tex, "flat") != NULL)
805 *relief = RR_RELIEF_FLAT;
806 else
807 *relief = RR_RELIEF_RAISED;
808
809 *border = FALSE;
810 if (*relief == RR_RELIEF_FLAT) {
811 if (strstr(tex, "border") != NULL)
812 *border = TRUE;
813 } else {
814 if (strstr(tex, "bevel2") != NULL)
815 *bevel = RR_BEVEL_2;
816 else
817 *bevel = RR_BEVEL_1;
818 }
819
820 if (strstr(tex, "interlaced") != NULL)
821 *interlaced = TRUE;
822 else
823 *interlaced = FALSE;
824 }
825 }
826
827
828 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
829 gchar *rname, RrAppearance *value)
830 {
831 gboolean ret = FALSE;
832 char *rclass = create_class_name(rname), *cname, *ctoname, *bcname;
833 char *rettype;
834 XrmValue retvalue;
835
836 cname = g_strconcat(rname, ".color", NULL);
837 ctoname = g_strconcat(rname, ".colorTo", NULL);
838 bcname = g_strconcat(rname, ".borderColor", NULL);
839
840 if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
841 retvalue.addr != NULL) {
842 parse_appearance(retvalue.addr,
843 &value->surface.grad,
844 &value->surface.relief,
845 &value->surface.bevel,
846 &value->surface.interlaced,
847 &value->surface.border);
848 if (!read_color(db, inst, cname, &value->surface.primary))
849 value->surface.primary = RrColorNew(inst, 0, 0, 0);
850 if (!read_color(db, inst, ctoname, &value->surface.secondary))
851 value->surface.secondary = RrColorNew(inst, 0, 0, 0);
852 if (value->surface.border)
853 if (!read_color(db, inst, bcname,
854 &value->surface.border_color))
855 value->surface.border_color = RrColorNew(inst, 0, 0, 0);
856 ret = TRUE;
857 }
858
859 g_free(bcname);
860 g_free(ctoname);
861 g_free(cname);
862 g_free(rclass);
863 return ret;
864 }
865
866 static void set_default_appearance(RrAppearance *a)
867 {
868 a->surface.grad = RR_SURFACE_SOLID;
869 a->surface.relief = RR_RELIEF_FLAT;
870 a->surface.bevel = RR_BEVEL_1;
871 a->surface.interlaced = FALSE;
872 a->surface.border = FALSE;
873 a->surface.primary = RrColorNew(a->inst, 0, 0, 0);
874 a->surface.secondary = RrColorNew(a->inst, 0, 0, 0);
875 }
This page took 0.080688 seconds and 5 git commands to generate.