2 #include "../../kernel/config.h"
3 #include "../../kernel/openbox.h"
7 #include <X11/Xresource.h>
18 static XrmDatabase
loaddb(char *theme
)
22 db
= XrmGetFileDatabase(theme
);
24 char *s
= g_build_filename(g_get_home_dir(), ".openbox", "themes",
25 "openbox", theme
, NULL
);
26 db
= XrmGetFileDatabase(s
);
30 char *s
= g_build_filename(THEMEDIR
, theme
, NULL
);
31 db
= XrmGetFileDatabase(s
);
37 static char *create_class_name(char *rname
)
39 char *rclass
= g_strdup(rname
);
47 if (*p
== '\0') break;
52 static gboolean
read_int(XrmDatabase db
, char *rname
, int *value
)
55 char *rclass
= create_class_name(rname
);
59 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
60 retvalue
.addr
!= NULL
) {
61 *value
= (int)strtol(retvalue
.addr
, &end
, 10);
62 if (end
!= retvalue
.addr
)
70 static gboolean
read_string(XrmDatabase db
, char *rname
, char **value
)
73 char *rclass
= create_class_name(rname
);
77 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
78 retvalue
.addr
!= NULL
) {
79 *value
= g_strdup(retvalue
.addr
);
87 static gboolean
read_color(XrmDatabase db
, char *rname
, color_rgb
**value
)
90 char *rclass
= create_class_name(rname
);
94 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
95 retvalue
.addr
!= NULL
) {
96 color_rgb
*c
= color_parse(retvalue
.addr
);
107 static gboolean
read_mask(XrmDatabase db
, char *rname
, pixmap_mask
**value
)
109 gboolean ret
= FALSE
;
110 char *rclass
= create_class_name(rname
);
115 int hx
, hy
; /* ignored */
120 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
121 retvalue
.addr
!= NULL
) {
122 if (!config_get("theme", Config_String
, &theme
))
123 g_assert_not_reached(); /* where's the default!? its not set? */
125 button_dir
= g_strdup_printf("%s_buttons", theme
.string
);
127 s
= g_build_filename(g_get_home_dir(), ".openbox", "themes",
128 "openbox", button_dir
, retvalue
.addr
, NULL
);
130 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) == BitmapSuccess
)
134 s
= g_build_filename(THEMEDIR
, button_dir
, retvalue
.addr
, NULL
);
136 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) == BitmapSuccess
)
142 themename
= g_path_get_basename(theme
.string
);
143 s
= g_strdup_printf("%s_buttons/%s", theme
.string
,
146 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) ==
150 g_message("Unable to find bitmap '%s'", s
);
155 *value
= pixmap_mask_new(w
, h
, (char*)b
);
167 static void parse_appearance(char *tex
, SurfaceColorType
*grad
,
168 ReliefType
*relief
, BevelType
*bevel
,
169 gboolean
*interlaced
, gboolean
*border
)
173 /* convert to all lowercase */
174 for (t
= tex
; *t
!= '\0'; ++t
)
175 *t
= g_ascii_tolower(*t
);
177 if (strstr(tex
, "parentrelative") != NULL
) {
178 *grad
= Background_ParentRelative
;
180 if (strstr(tex
, "gradient") != NULL
) {
181 if (strstr(tex
, "crossdiagonal") != NULL
)
182 *grad
= Background_CrossDiagonal
;
183 else if (strstr(tex
, "rectangle") != NULL
)
184 *grad
= Background_Rectangle
;
185 else if (strstr(tex
, "pyramid") != NULL
)
186 *grad
= Background_Pyramid
;
187 else if (strstr(tex
, "pipecross") != NULL
)
188 *grad
= Background_PipeCross
;
189 else if (strstr(tex
, "elliptic") != NULL
)
190 *grad
= Background_Elliptic
;
191 else if (strstr(tex
, "horizontal") != NULL
)
192 *grad
= Background_Horizontal
;
193 else if (strstr(tex
, "vertical") != NULL
)
194 *grad
= Background_Vertical
;
196 *grad
= Background_Diagonal
;
198 *grad
= Background_Solid
;
201 if (strstr(tex
, "sunken") != NULL
)
203 else if (strstr(tex
, "flat") != NULL
)
209 if (*relief
== Flat
) {
210 if (strstr(tex
, "border") != NULL
)
213 if (strstr(tex
, "bevel2") != NULL
)
219 if (strstr(tex
, "interlaced") != NULL
)
227 static gboolean
read_appearance(XrmDatabase db
, char *rname
, Appearance
*value
)
229 gboolean ret
= FALSE
;
230 char *rclass
= create_class_name(rname
), *cname
, *ctoname
, *bcname
;
234 cname
= g_strconcat(rname
, ".color", NULL
);
235 ctoname
= g_strconcat(rname
, ".colorTo", NULL
);
236 bcname
= g_strconcat(rname
, ".borderColor", NULL
);
238 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
239 retvalue
.addr
!= NULL
) {
240 parse_appearance(retvalue
.addr
,
241 &value
->surface
.data
.planar
.grad
,
242 &value
->surface
.data
.planar
.relief
,
243 &value
->surface
.data
.planar
.bevel
,
244 &value
->surface
.data
.planar
.interlaced
,
245 &value
->surface
.data
.planar
.border
);
246 if (!read_color(db
, cname
, &value
->surface
.data
.planar
.primary
))
247 value
->surface
.data
.planar
.primary
= color_new(0, 0, 0);
248 if (!read_color(db
, ctoname
, &value
->surface
.data
.planar
.secondary
))
249 value
->surface
.data
.planar
.secondary
= color_new(0, 0, 0);
250 if (value
->surface
.data
.planar
.border
)
251 if (!read_color(db
, bcname
,
252 &value
->surface
.data
.planar
.border_color
))
253 value
->surface
.data
.planar
.border_color
= color_new(0, 0, 0);
264 static void set_default_appearance(Appearance
*a
)
266 a
->surface
.data
.planar
.grad
= Background_Solid
;
267 a
->surface
.data
.planar
.relief
= Flat
;
268 a
->surface
.data
.planar
.bevel
= Bevel1
;
269 a
->surface
.data
.planar
.interlaced
= FALSE
;
270 a
->surface
.data
.planar
.border
= FALSE
;
271 a
->surface
.data
.planar
.primary
= color_new(0, 0, 0);
272 a
->surface
.data
.planar
.secondary
= color_new(0, 0, 0);
275 gboolean
obtheme_load()
277 XrmDatabase db
= NULL
;
280 ConfigValue theme
, shadow
, offset
, font
;
282 if (config_get("theme", Config_String
, &theme
)) {
283 db
= loaddb(theme
.string
);
285 g_warning("Failed to load the theme '%s'", theme
.string
);
286 g_message("Falling back to the default: '%s'", DEFAULT_THEME
);
290 db
= loaddb(DEFAULT_THEME
);
292 g_warning("Failed to load the theme '%s'.", DEFAULT_THEME
);
295 /* change to reflect what was actually loaded */
296 theme
.string
= DEFAULT_THEME
;
297 config_set("theme", Config_String
, theme
);
300 /* load the font, not from the theme file tho, its in the config */
302 if (!config_get("font.shadow", Config_Bool
, &shadow
)) {
303 shadow
.bool = TRUE
; /* default */
304 config_set("font.shadow", Config_Bool
, shadow
);
306 ob_s_winfont_shadow
= shadow
.bool;
307 if (!config_get("font.shadow.offset", Config_Integer
, &offset
) ||
308 offset
.integer
< 0 || offset
.integer
>= 10) {
309 offset
.integer
= 1; /* default */
310 config_set("font.shadow.offset", Config_Integer
, offset
);
312 ob_s_winfont_shadow_offset
= offset
.integer
;
313 if (!config_get("font", Config_String
, &font
)) {
314 font
.string
= DEFAULT_FONT
;
315 config_set("font", Config_String
, font
);
317 ob_s_winfont
= font_open(font
.string
);
318 ob_s_winfont_height
= font_height(ob_s_winfont
, ob_s_winfont_shadow
,
319 ob_s_winfont_shadow_offset
);
321 winjust
= Justify_Left
;
322 if (read_string(db
, "window.justify", &winjuststr
)) {
323 if (!g_ascii_strcasecmp(winjuststr
, "right"))
324 winjust
= Justify_Right
;
325 else if (!g_ascii_strcasecmp(winjuststr
, "center"))
326 winjust
= Justify_Center
;
330 if (!read_int(db
, "handleWidth", &ob_s_handle_height
) ||
331 ob_s_handle_height
< 0 || ob_s_handle_height
> 100) ob_s_handle_height
= 6;
332 if (!read_int(db
, "bevelWidth", &ob_s_bevel
) ||
333 ob_s_bevel
<= 0 || ob_s_bevel
> 100) ob_s_bevel
= 3;
334 if (!read_int(db
, "borderWidth", &ob_s_bwidth
) ||
335 ob_s_bwidth
< 0 || ob_s_bwidth
> 100) ob_s_bwidth
= 1;
336 if (!read_int(db
, "frameWidth", &ob_s_cbwidth
) ||
337 ob_s_cbwidth
< 0 || ob_s_cbwidth
> 100) ob_s_cbwidth
= ob_s_bevel
;
339 if (!read_color(db
, "borderColor", &ob_s_b_color
))
340 ob_s_b_color
= color_new(0, 0, 0);
341 if (!read_color(db
, "window.frame.focusColor", &ob_s_cb_focused_color
))
342 ob_s_cb_focused_color
= color_new(0xff, 0xff, 0xff);
343 if (!read_color(db
, "window.frame.unfocusColor", &ob_s_cb_unfocused_color
))
344 ob_s_cb_unfocused_color
= color_new(0xff, 0xff, 0xff);
345 if (!read_color(db
, "window.label.focus.textColor",
346 &ob_s_title_focused_color
))
347 ob_s_title_focused_color
= color_new(0xff, 0xff, 0xff);
348 if (!read_color(db
, "window.label.unfocus.textColor",
349 &ob_s_title_unfocused_color
))
350 ob_s_title_unfocused_color
= color_new(0xff, 0xff, 0xff);
351 if (!read_color(db
, "window.button.focus.picColor",
352 &ob_s_titlebut_focused_color
))
353 ob_s_titlebut_focused_color
= color_new(0, 0, 0);
354 if (!read_color(db
, "window.button.unfocus.picColor",
355 &ob_s_titlebut_unfocused_color
))
356 ob_s_titlebut_unfocused_color
= color_new(0xff, 0xff, 0xff);
358 if (!read_mask(db
, "window.button.max.mask", &ob_s_max_unpressed_mask
)) {
359 char data
[] = { 0x7c, 0x44, 0x47, 0x47, 0x7f, 0x1f, 0x1f };
360 ob_s_max_unpressed_mask
= pixmap_mask_new(7, 7, data
);
362 if (!read_mask(db
, "window.button.max.pressed.mask",
363 &ob_s_max_pressed_mask
)) {
364 ob_s_max_pressed_mask
= pixmap_mask_copy(ob_s_max_unpressed_mask
);
367 if (!read_mask(db
, "window.button.icon.mask",
368 &ob_s_iconify_unpressed_mask
)) {
369 char data
[] = { 0x00, 0x00, 0x00, 0x00, 0x3e, 0x3e, 0x3e };
370 ob_s_iconify_unpressed_mask
= pixmap_mask_new(7, 7, data
);
372 if (!read_mask(db
, "window.button.icon.pressed.mask",
373 &ob_s_iconify_pressed_mask
)) {
374 ob_s_iconify_pressed_mask
=
375 pixmap_mask_copy(ob_s_iconify_unpressed_mask
);
378 if (!read_mask(db
, "window.button.stick.mask",
379 &ob_s_desk_unpressed_mask
)) {
380 char data
[] = { 0x00, 0x36, 0x36, 0x00, 0x36, 0x36, 0x00 };
381 ob_s_desk_unpressed_mask
= pixmap_mask_new(7, 7, data
);
383 if (!read_mask(db
, "window.button.stick.pressed.mask",
384 &ob_s_desk_pressed_mask
)) {
385 ob_s_desk_pressed_mask
= pixmap_mask_copy(ob_s_desk_unpressed_mask
);
388 if (!read_mask(db
, "window.button.close.mask",
389 &ob_s_close_unpressed_mask
)) {
390 char data
[] = { 0x22, 0x77, 0x3e, 0x1c, 0x3e, 0x77, 0x22 };
391 ob_s_close_unpressed_mask
= pixmap_mask_new(7, 7, data
);
393 if (!read_mask(db
, "window.button.close.pressed.mask",
394 &ob_s_close_pressed_mask
)) {
395 ob_s_close_pressed_mask
= pixmap_mask_copy(ob_s_close_unpressed_mask
);
398 if (!read_appearance(db
, "window.title.focus", ob_a_focused_title
))
399 set_default_appearance(ob_a_focused_title
);
400 if (!read_appearance(db
, "window.title.unfocus", ob_a_unfocused_title
))
401 set_default_appearance(ob_a_unfocused_title
);
402 if (!read_appearance(db
, "window.label.focus", ob_a_focused_label
))
403 set_default_appearance(ob_a_focused_label
);
404 if (!read_appearance(db
, "window.label.unfocus", ob_a_unfocused_label
))
405 set_default_appearance(ob_a_unfocused_label
);
406 if (!read_appearance(db
, "window.handle.focus", ob_a_focused_handle
))
407 set_default_appearance(ob_a_focused_handle
);
408 if (!read_appearance(db
, "window.handle.unfocus", ob_a_unfocused_handle
))
409 set_default_appearance(ob_a_unfocused_handle
);
410 if (!read_appearance(db
, "window.grip.focus", ob_a_focused_grip
))
411 set_default_appearance(ob_a_focused_grip
);
412 if (!read_appearance(db
, "window.grip.unfocus", ob_a_unfocused_grip
))
413 set_default_appearance(ob_a_unfocused_grip
);
415 if (!read_appearance(db
, "window.button.pressed.focus",
416 ob_a_focused_pressed_max
))
417 if (!read_appearance(db
, "window.button.pressed",
418 ob_a_focused_pressed_max
))
419 set_default_appearance(ob_a_focused_pressed_max
);
420 if (!read_appearance(db
, "window.button.pressed.unfocus",
421 ob_a_unfocused_pressed_max
))
422 if (!read_appearance(db
, "window.button.pressed",
423 ob_a_unfocused_pressed_max
))
424 set_default_appearance(ob_a_unfocused_pressed_max
);
425 if (!read_appearance(db
, "window.button.focus",
426 ob_a_focused_unpressed_max
))
427 set_default_appearance(ob_a_focused_unpressed_max
);
428 if (!read_appearance(db
, "window.button.unfocus",
429 ob_a_unfocused_unpressed_max
))
430 set_default_appearance(ob_a_unfocused_unpressed_max
);
432 ob_a_unfocused_unpressed_close
=
433 appearance_copy(ob_a_unfocused_unpressed_max
);
434 ob_a_unfocused_pressed_close
= appearance_copy(ob_a_unfocused_pressed_max
);
435 ob_a_focused_unpressed_close
= appearance_copy(ob_a_focused_unpressed_max
);
436 ob_a_focused_pressed_close
= appearance_copy(ob_a_focused_pressed_max
);
437 ob_a_unfocused_unpressed_desk
=
438 appearance_copy(ob_a_unfocused_unpressed_max
);
439 ob_a_unfocused_pressed_desk
= appearance_copy(ob_a_unfocused_pressed_max
);
440 ob_a_focused_unpressed_desk
= appearance_copy(ob_a_focused_unpressed_max
);
441 ob_a_focused_pressed_desk
= appearance_copy(ob_a_focused_pressed_max
);
442 ob_a_unfocused_unpressed_iconify
=
443 appearance_copy(ob_a_unfocused_unpressed_max
);
444 ob_a_unfocused_pressed_iconify
=
445 appearance_copy(ob_a_unfocused_pressed_max
);
446 ob_a_focused_unpressed_iconify
=
447 appearance_copy(ob_a_focused_unpressed_max
);
448 ob_a_focused_pressed_iconify
= appearance_copy(ob_a_focused_pressed_max
);
450 ob_a_icon
->surface
.data
.planar
.grad
= Background_ParentRelative
;
452 /* set up the textures */
453 ob_a_focused_label
->texture
[0].type
= Text
;
454 ob_a_focused_label
->texture
[0].data
.text
.justify
= winjust
;
455 ob_a_focused_label
->texture
[0].data
.text
.font
= ob_s_winfont
;
456 ob_a_focused_label
->texture
[0].data
.text
.shadow
= ob_s_winfont_shadow
;
457 ob_a_focused_label
->texture
[0].data
.text
.offset
=
458 ob_s_winfont_shadow_offset
;
459 ob_a_focused_label
->texture
[0].data
.text
.color
= ob_s_title_focused_color
;
461 ob_a_unfocused_label
->texture
[0].type
= Text
;
462 ob_a_unfocused_label
->texture
[0].data
.text
.justify
= winjust
;
463 ob_a_unfocused_label
->texture
[0].data
.text
.font
= ob_s_winfont
;
464 ob_a_unfocused_label
->texture
[0].data
.text
.shadow
= ob_s_winfont_shadow
;
465 ob_a_unfocused_label
->texture
[0].data
.text
.offset
=
466 ob_s_winfont_shadow_offset
;
467 ob_a_unfocused_label
->texture
[0].data
.text
.color
=
468 ob_s_title_unfocused_color
;
470 ob_a_focused_unpressed_max
->texture
[0].type
=
471 ob_a_focused_pressed_max
->texture
[0].type
=
472 ob_a_unfocused_unpressed_max
->texture
[0].type
=
473 ob_a_unfocused_pressed_max
->texture
[0].type
=
474 ob_a_focused_unpressed_close
->texture
[0].type
=
475 ob_a_focused_pressed_close
->texture
[0].type
=
476 ob_a_unfocused_unpressed_close
->texture
[0].type
=
477 ob_a_unfocused_pressed_close
->texture
[0].type
=
478 ob_a_focused_unpressed_desk
->texture
[0].type
=
479 ob_a_focused_pressed_desk
->texture
[0].type
=
480 ob_a_unfocused_unpressed_desk
->texture
[0].type
=
481 ob_a_unfocused_pressed_desk
->texture
[0].type
=
482 ob_a_focused_unpressed_iconify
->texture
[0].type
=
483 ob_a_focused_pressed_iconify
->texture
[0].type
=
484 ob_a_unfocused_unpressed_iconify
->texture
[0].type
=
485 ob_a_unfocused_pressed_iconify
->texture
[0].type
= Bitmask
;
486 ob_a_focused_unpressed_max
->texture
[0].data
.mask
.mask
=
487 ob_a_unfocused_unpressed_max
->texture
[0].data
.mask
.mask
=
488 ob_s_max_unpressed_mask
;
489 ob_a_focused_pressed_max
->texture
[0].data
.mask
.mask
=
490 ob_a_unfocused_pressed_max
->texture
[0].data
.mask
.mask
=
491 ob_s_max_pressed_mask
;
492 ob_a_focused_unpressed_close
->texture
[0].data
.mask
.mask
=
493 ob_a_unfocused_unpressed_close
->texture
[0].data
.mask
.mask
=
494 ob_s_close_unpressed_mask
;
495 ob_a_focused_pressed_close
->texture
[0].data
.mask
.mask
=
496 ob_a_unfocused_pressed_close
->texture
[0].data
.mask
.mask
=
497 ob_s_close_pressed_mask
;
498 ob_a_focused_unpressed_desk
->texture
[0].data
.mask
.mask
=
499 ob_a_unfocused_unpressed_desk
->texture
[0].data
.mask
.mask
=
500 ob_s_desk_unpressed_mask
;
501 ob_a_focused_pressed_desk
->texture
[0].data
.mask
.mask
=
502 ob_a_unfocused_pressed_desk
->texture
[0].data
.mask
.mask
=
503 ob_s_desk_pressed_mask
;
504 ob_a_focused_unpressed_iconify
->texture
[0].data
.mask
.mask
=
505 ob_a_unfocused_unpressed_iconify
->texture
[0].data
.mask
.mask
=
506 ob_s_iconify_unpressed_mask
;
507 ob_a_focused_pressed_iconify
->texture
[0].data
.mask
.mask
=
508 ob_a_unfocused_pressed_iconify
->texture
[0].data
.mask
.mask
=
509 ob_s_iconify_pressed_mask
;
510 ob_a_focused_unpressed_max
->texture
[0].data
.mask
.color
=
511 ob_a_focused_pressed_max
->texture
[0].data
.mask
.color
=
512 ob_a_focused_unpressed_close
->texture
[0].data
.mask
.color
=
513 ob_a_focused_pressed_close
->texture
[0].data
.mask
.color
=
514 ob_a_focused_unpressed_desk
->texture
[0].data
.mask
.color
=
515 ob_a_focused_pressed_desk
->texture
[0].data
.mask
.color
=
516 ob_a_focused_unpressed_iconify
->texture
[0].data
.mask
.color
=
517 ob_a_focused_pressed_iconify
->texture
[0].data
.mask
.color
=
518 ob_s_titlebut_focused_color
;
519 ob_a_unfocused_unpressed_max
->texture
[0].data
.mask
.color
=
520 ob_a_unfocused_pressed_max
->texture
[0].data
.mask
.color
=
521 ob_a_unfocused_unpressed_close
->texture
[0].data
.mask
.color
=
522 ob_a_unfocused_pressed_close
->texture
[0].data
.mask
.color
=
523 ob_a_unfocused_unpressed_desk
->texture
[0].data
.mask
.color
=
524 ob_a_unfocused_pressed_desk
->texture
[0].data
.mask
.color
=
525 ob_a_unfocused_unpressed_iconify
->texture
[0].data
.mask
.color
=
526 ob_a_unfocused_pressed_iconify
->texture
[0].data
.mask
.color
=
527 ob_s_titlebut_unfocused_color
;
529 XrmDestroyDatabase(db
);