2 #include "../../kernel/themerc.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 gboolean
read_bool(XrmDatabase db
, char *rname
, gboolean
*value
)
55 char *rclass
= create_class_name(rname
);
59 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
60 retvalue
.addr
!= NULL
) {
61 if (!g_ascii_strcasecmp(retvalue
.addr
, "true"))
72 gboolean
read_int(XrmDatabase db
, char *rname
, int *value
)
75 char *rclass
= create_class_name(rname
);
79 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
80 retvalue
.addr
!= NULL
) {
81 *value
= (int)strtol(retvalue
.addr
, &end
, 10);
82 if (end
!= retvalue
.addr
)
90 gboolean
read_string(XrmDatabase db
, char *rname
, char **value
)
93 char *rclass
= create_class_name(rname
);
97 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
98 retvalue
.addr
!= NULL
) {
99 *value
= g_strdup(retvalue
.addr
);
107 gboolean
read_color(XrmDatabase db
, char *rname
, color_rgb
**value
)
109 gboolean ret
= FALSE
;
110 char *rclass
= create_class_name(rname
);
114 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
115 retvalue
.addr
!= NULL
) {
116 color_rgb
*c
= color_parse(retvalue
.addr
);
127 gboolean
read_mask(XrmDatabase db
, char *rname
, pixmap_mask
**value
)
129 gboolean ret
= FALSE
;
130 char *rclass
= create_class_name(rname
);
135 int hx
, hy
; /* ignored */
139 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
140 retvalue
.addr
!= NULL
) {
141 button_dir
= g_strdup_printf("%s_buttons", themerc_theme
);
143 s
= g_build_filename(g_get_home_dir(), ".openbox", "themes",
144 "openbox", button_dir
, retvalue
.addr
, NULL
);
146 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) == BitmapSuccess
)
150 s
= g_build_filename(THEMEDIR
, button_dir
, retvalue
.addr
, NULL
);
152 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) == BitmapSuccess
)
156 s
= g_strdup_printf("%s_buttons/%s", themerc_theme
,
158 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) ==
162 g_message("Unable to find bitmap '%s'", s
);
167 *value
= pixmap_mask_new(w
, h
, (char*)b
);
179 static void parse_appearance(char *tex
, SurfaceColorType
*grad
,
180 ReliefType
*relief
, BevelType
*bevel
,
181 gboolean
*interlaced
, gboolean
*border
)
185 /* convert to all lowercase */
186 for (t
= tex
; *t
!= '\0'; ++t
)
187 *t
= g_ascii_tolower(*t
);
189 if (strstr(tex
, "parentrelative") != NULL
) {
190 *grad
= Background_ParentRelative
;
192 if (strstr(tex
, "gradient") != NULL
) {
193 if (strstr(tex
, "crossdiagonal") != NULL
)
194 *grad
= Background_CrossDiagonal
;
195 else if (strstr(tex
, "rectangle") != NULL
)
196 *grad
= Background_Rectangle
;
197 else if (strstr(tex
, "pyramid") != NULL
)
198 *grad
= Background_Pyramid
;
199 else if (strstr(tex
, "pipecross") != NULL
)
200 *grad
= Background_PipeCross
;
201 else if (strstr(tex
, "elliptic") != NULL
)
202 *grad
= Background_Elliptic
;
203 else if (strstr(tex
, "horizontal") != NULL
)
204 *grad
= Background_Horizontal
;
205 else if (strstr(tex
, "vertical") != NULL
)
206 *grad
= Background_Vertical
;
208 *grad
= Background_Diagonal
;
210 *grad
= Background_Solid
;
213 if (strstr(tex
, "sunken") != NULL
)
215 else if (strstr(tex
, "flat") != NULL
)
221 if (*relief
== Flat
) {
222 if (strstr(tex
, "border") != NULL
)
225 if (strstr(tex
, "bevel2") != NULL
)
231 if (strstr(tex
, "interlaced") != NULL
)
239 gboolean
read_appearance(XrmDatabase db
, char *rname
, Appearance
*value
)
241 gboolean ret
= FALSE
;
242 char *rclass
= create_class_name(rname
), *cname
, *ctoname
, *bcname
;
246 cname
= g_strconcat(rname
, ".color", NULL
);
247 ctoname
= g_strconcat(rname
, ".colorTo", NULL
);
248 bcname
= g_strconcat(rname
, ".borderColor", NULL
);
250 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
251 retvalue
.addr
!= NULL
) {
252 parse_appearance(retvalue
.addr
,
253 &value
->surface
.data
.planar
.grad
,
254 &value
->surface
.data
.planar
.relief
,
255 &value
->surface
.data
.planar
.bevel
,
256 &value
->surface
.data
.planar
.interlaced
,
257 &value
->surface
.data
.planar
.border
);
258 if (!read_color(db
, cname
, &value
->surface
.data
.planar
.primary
))
259 value
->surface
.data
.planar
.primary
= color_new(0, 0, 0);
260 if (!read_color(db
, ctoname
, &value
->surface
.data
.planar
.secondary
))
261 value
->surface
.data
.planar
.secondary
= color_new(0, 0, 0);
262 if (value
->surface
.data
.planar
.border
)
263 if (!read_color(db
, bcname
,
264 &value
->surface
.data
.planar
.border_color
))
265 value
->surface
.data
.planar
.border_color
= color_new(0, 0, 0);
276 void set_default_appearance(Appearance
*a
)
278 a
->surface
.data
.planar
.grad
= Background_Solid
;
279 a
->surface
.data
.planar
.relief
= Flat
;
280 a
->surface
.data
.planar
.bevel
= Bevel1
;
281 a
->surface
.data
.planar
.interlaced
= FALSE
;
282 a
->surface
.data
.planar
.border
= FALSE
;
283 a
->surface
.data
.planar
.primary
= color_new(0, 0, 0);
284 a
->surface
.data
.planar
.secondary
= color_new(0, 0, 0);
289 XrmDatabase db
= NULL
;
293 if (themerc_theme
!= NULL
) {
294 db
= loaddb(themerc_theme
);
296 g_warning("Failed to load the theme '%s'", themerc_theme
);
297 g_message("Falling back to the default: '%s'", DEFAULT_THEME
);
301 db
= loaddb(DEFAULT_THEME
);
303 g_warning("Failed to load the theme '%s'.", DEFAULT_THEME
);
306 /* change to reflect what was actually loaded */
307 g_free(themerc_theme
);
308 themerc_theme
= g_strdup(DEFAULT_THEME
);
311 /* load the font, not from the theme file tho, its in themerc_font */
312 s_winfont_shadow
= 1; /* XXX read from themrc */
313 s_winfont_shadow_offset
= 1; /* XXX read from themerc */
314 s_winfont
= font_open(themerc_font
);
315 s_winfont_height
= font_height(s_winfont
, s_winfont_shadow
,
316 s_winfont_shadow_offset
);
318 winjust
= Justify_Left
;
319 if (read_string(db
, "window.justify", &winjuststr
)) {
320 if (!g_ascii_strcasecmp(winjuststr
, "right"))
321 winjust
= Justify_Right
;
322 else if (!g_ascii_strcasecmp(winjuststr
, "center"))
323 winjust
= Justify_Center
;
327 if (!read_int(db
, "handleWidth", &s_handle_height
) ||
328 s_handle_height
< 0 || s_handle_height
> 100) s_handle_height
= 6;
329 if (!read_int(db
, "bevelWidth", &s_bevel
) ||
330 s_bevel
<= 0 || s_bevel
> 100) s_bevel
= 3;
331 if (!read_int(db
, "borderWidth", &s_bwidth
) ||
332 s_bwidth
< 0 || s_bwidth
> 100) s_bwidth
= 1;
333 if (!read_int(db
, "frameWidth", &s_cbwidth
) ||
334 s_cbwidth
< 0 || s_cbwidth
> 100) s_cbwidth
= s_bevel
;
336 if (!read_color(db
, "borderColor", &s_b_color
))
337 s_b_color
= color_new(0, 0, 0);
338 if (!read_color(db
, "window.frame.focusColor", &s_cb_focused_color
))
339 s_cb_focused_color
= color_new(0xff, 0xff, 0xff);
340 if (!read_color(db
, "window.frame.unfocusColor", &s_cb_unfocused_color
))
341 s_cb_unfocused_color
= color_new(0xff, 0xff, 0xff);
342 if (!read_color(db
, "window.label.focus.textColor",
343 &s_title_focused_color
))
344 s_title_focused_color
= color_new(0xff, 0xff, 0xff);
345 if (!read_color(db
, "window.label.unfocus.textColor",
346 &s_title_unfocused_color
))
347 s_title_unfocused_color
= color_new(0xff, 0xff, 0xff);
348 if (!read_color(db
, "window.button.focus.picColor",
349 &s_titlebut_focused_color
))
350 s_titlebut_focused_color
= color_new(0, 0, 0);
351 if (!read_color(db
, "window.button.unfocus.picColor",
352 &s_titlebut_unfocused_color
))
353 s_titlebut_unfocused_color
= color_new(0xff, 0xff, 0xff);
355 if (!read_mask(db
, "window.button.max.mask", &s_max_mask
)) {
356 char data
[] = { 0x7c, 0x44, 0x47, 0x47, 0x7f, 0x1f, 0x1f };
357 s_max_mask
= pixmap_mask_new(7, 7, data
);
359 if (!read_mask(db
, "window.button.icon.mask", &s_icon_mask
)) {
360 char data
[] = { 0x00, 0x00, 0x00, 0x00, 0x3e, 0x3e, 0x3e };
361 s_icon_mask
= pixmap_mask_new(7, 7, data
);
363 if (!read_mask(db
, "window.button.stick.mask", &s_desk_mask
)) {
364 char data
[] = { 0x00, 0x36, 0x36, 0x00, 0x36, 0x36, 0x00 };
365 s_desk_mask
= pixmap_mask_new(7, 7, data
);
367 if (!read_mask(db
, "window.button.close.mask", &s_close_mask
)) {
368 char data
[] = { 0x22, 0x77, 0x3e, 0x1c, 0x3e, 0x77, 0x22 };
369 s_close_mask
= pixmap_mask_new(7, 7, data
);
372 if (!read_appearance(db
, "window.title.focus", a_focused_title
))
373 set_default_appearance(a_focused_title
);
374 if (!read_appearance(db
, "window.title.unfocus", a_unfocused_title
))
375 set_default_appearance(a_unfocused_title
);
376 if (!read_appearance(db
, "window.label.focus", a_focused_label
))
377 set_default_appearance(a_focused_label
);
378 if (!read_appearance(db
, "window.label.unfocus", a_unfocused_label
))
379 set_default_appearance(a_unfocused_label
);
380 if (!read_appearance(db
, "window.handle.focus", a_focused_handle
))
381 set_default_appearance(a_focused_handle
);
382 if (!read_appearance(db
, "window.handle.unfocus", a_unfocused_handle
))
383 set_default_appearance(a_unfocused_handle
);
384 if (!read_appearance(db
, "window.grip.focus", a_focused_grip
))
385 set_default_appearance(a_focused_grip
);
386 if (!read_appearance(db
, "window.grip.unfocus", a_unfocused_grip
))
387 set_default_appearance(a_unfocused_grip
);
389 if (!read_appearance(db
, "window.button.pressed.focus",
390 a_focused_pressed_max
))
391 if (!read_appearance(db
, "window.button.pressed",
392 a_focused_pressed_max
))
393 set_default_appearance(a_focused_pressed_max
);
394 if (!read_appearance(db
, "window.button.pressed.unfocus",
395 a_unfocused_pressed_max
))
396 if (!read_appearance(db
, "window.button.pressed",
397 a_unfocused_pressed_max
))
398 set_default_appearance(a_unfocused_pressed_max
);
399 if (!read_appearance(db
, "window.button.focus",
400 a_focused_unpressed_max
))
401 set_default_appearance(a_focused_unpressed_max
);
402 if (!read_appearance(db
, "window.button.unfocus",
403 a_unfocused_unpressed_max
))
404 set_default_appearance(a_unfocused_unpressed_max
);
406 a_unfocused_unpressed_close
= appearance_copy(a_unfocused_unpressed_max
);
407 a_unfocused_pressed_close
= appearance_copy(a_unfocused_pressed_max
);
408 a_focused_unpressed_close
= appearance_copy(a_focused_unpressed_max
);
409 a_focused_pressed_close
= appearance_copy(a_focused_pressed_max
);
410 a_unfocused_unpressed_desk
= appearance_copy(a_unfocused_unpressed_max
);
411 a_unfocused_pressed_desk
= appearance_copy(a_unfocused_pressed_max
);
412 a_focused_unpressed_desk
= appearance_copy(a_focused_unpressed_max
);
413 a_focused_pressed_desk
= appearance_copy(a_focused_pressed_max
);
414 a_unfocused_unpressed_iconify
= appearance_copy(a_unfocused_unpressed_max
);
415 a_unfocused_pressed_iconify
= appearance_copy(a_unfocused_pressed_max
);
416 a_focused_unpressed_iconify
= appearance_copy(a_focused_unpressed_max
);
417 a_focused_pressed_iconify
= appearance_copy(a_focused_pressed_max
);
419 a_icon
->surface
.data
.planar
.grad
= Background_ParentRelative
;
421 /* set up the textures */
422 a_focused_label
->texture
[0].type
= Text
;
423 a_focused_label
->texture
[0].data
.text
.justify
= winjust
;
424 a_focused_label
->texture
[0].data
.text
.font
= s_winfont
;
425 a_focused_label
->texture
[0].data
.text
.shadow
= s_winfont_shadow
;
426 a_focused_label
->texture
[0].data
.text
.offset
= s_winfont_shadow_offset
;
427 a_focused_label
->texture
[0].data
.text
.color
= s_title_focused_color
;
429 a_unfocused_label
->texture
[0].type
= Text
;
430 a_unfocused_label
->texture
[0].data
.text
.justify
= winjust
;
431 a_unfocused_label
->texture
[0].data
.text
.font
= s_winfont
;
432 a_unfocused_label
->texture
[0].data
.text
.shadow
= s_winfont_shadow
;
433 a_unfocused_label
->texture
[0].data
.text
.offset
= s_winfont_shadow_offset
;
434 a_unfocused_label
->texture
[0].data
.text
.color
= s_title_unfocused_color
;
436 a_focused_unpressed_max
->texture
[0].type
=
437 a_focused_pressed_max
->texture
[0].type
=
438 a_unfocused_unpressed_max
->texture
[0].type
=
439 a_unfocused_pressed_max
->texture
[0].type
=
440 a_focused_unpressed_close
->texture
[0].type
=
441 a_focused_pressed_close
->texture
[0].type
=
442 a_unfocused_unpressed_close
->texture
[0].type
=
443 a_unfocused_pressed_close
->texture
[0].type
=
444 a_focused_unpressed_desk
->texture
[0].type
=
445 a_focused_pressed_desk
->texture
[0].type
=
446 a_unfocused_unpressed_desk
->texture
[0].type
=
447 a_unfocused_pressed_desk
->texture
[0].type
=
448 a_focused_unpressed_iconify
->texture
[0].type
=
449 a_focused_pressed_iconify
->texture
[0].type
=
450 a_unfocused_unpressed_iconify
->texture
[0].type
=
451 a_unfocused_pressed_iconify
->texture
[0].type
= Bitmask
;
452 a_focused_unpressed_max
->texture
[0].data
.mask
.mask
=
453 a_focused_pressed_max
->texture
[0].data
.mask
.mask
=
454 a_unfocused_unpressed_max
->texture
[0].data
.mask
.mask
=
455 a_unfocused_pressed_max
->texture
[0].data
.mask
.mask
= s_max_mask
;
456 a_focused_unpressed_close
->texture
[0].data
.mask
.mask
=
457 a_focused_pressed_close
->texture
[0].data
.mask
.mask
=
458 a_unfocused_unpressed_close
->texture
[0].data
.mask
.mask
=
459 a_unfocused_pressed_close
->texture
[0].data
.mask
.mask
= s_close_mask
;
460 a_focused_unpressed_desk
->texture
[0].data
.mask
.mask
=
461 a_focused_pressed_desk
->texture
[0].data
.mask
.mask
=
462 a_unfocused_unpressed_desk
->texture
[0].data
.mask
.mask
=
463 a_unfocused_pressed_desk
->texture
[0].data
.mask
.mask
= s_desk_mask
;
464 a_focused_unpressed_iconify
->texture
[0].data
.mask
.mask
=
465 a_focused_pressed_iconify
->texture
[0].data
.mask
.mask
=
466 a_unfocused_unpressed_iconify
->texture
[0].data
.mask
.mask
=
467 a_unfocused_pressed_iconify
->texture
[0].data
.mask
.mask
= s_icon_mask
;
468 a_focused_unpressed_max
->texture
[0].data
.mask
.color
=
469 a_focused_pressed_max
->texture
[0].data
.mask
.color
=
470 a_focused_unpressed_close
->texture
[0].data
.mask
.color
=
471 a_focused_pressed_close
->texture
[0].data
.mask
.color
=
472 a_focused_unpressed_desk
->texture
[0].data
.mask
.color
=
473 a_focused_pressed_desk
->texture
[0].data
.mask
.color
=
474 a_focused_unpressed_iconify
->texture
[0].data
.mask
.color
=
475 a_focused_pressed_iconify
->texture
[0].data
.mask
.color
=
476 s_titlebut_focused_color
;
477 a_unfocused_unpressed_max
->texture
[0].data
.mask
.color
=
478 a_unfocused_pressed_max
->texture
[0].data
.mask
.color
=
479 a_unfocused_unpressed_close
->texture
[0].data
.mask
.color
=
480 a_unfocused_pressed_close
->texture
[0].data
.mask
.color
=
481 a_unfocused_unpressed_desk
->texture
[0].data
.mask
.color
=
482 a_unfocused_pressed_desk
->texture
[0].data
.mask
.color
=
483 a_unfocused_unpressed_iconify
->texture
[0].data
.mask
.color
=
484 a_unfocused_pressed_iconify
->texture
[0].data
.mask
.color
=
485 s_titlebut_unfocused_color
;
487 XrmDestroyDatabase(db
);