8 #include <X11/Xresource.h>
10 static XrmDatabase
loaddb(RrTheme
*theme
, char *name
);
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(const RrInstance
*inst
,
16 gchar
*maskname
, RrTheme
*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
);
22 RrTheme
* RrThemeNew(const RrInstance
*inst
, gchar
*name
)
24 XrmDatabase db
= NULL
;
25 RrJustify winjust
, mtitlejust
, mjust
;
30 theme
= g_new0(RrTheme
, 1);
34 theme
->a_disabled_focused_max
= RrAppearanceNew(inst
, 1);
35 theme
->a_disabled_unfocused_max
= RrAppearanceNew(inst
, 1);
36 theme
->a_focused_unpressed_max
= RrAppearanceNew(inst
, 1);
37 theme
->a_focused_pressed_max
= RrAppearanceNew(inst
, 1);
38 theme
->a_focused_pressed_set_max
= RrAppearanceNew(inst
, 1);
39 theme
->a_unfocused_unpressed_max
= RrAppearanceNew(inst
, 1);
40 theme
->a_unfocused_pressed_max
= RrAppearanceNew(inst
, 1);
41 theme
->a_unfocused_pressed_set_max
= RrAppearanceNew(inst
, 1);
42 theme
->a_focused_grip
= RrAppearanceNew(inst
, 0);
43 theme
->a_unfocused_grip
= RrAppearanceNew(inst
, 0);
44 theme
->a_focused_title
= RrAppearanceNew(inst
, 0);
45 theme
->a_unfocused_title
= RrAppearanceNew(inst
, 0);
46 theme
->a_focused_label
= RrAppearanceNew(inst
, 1);
47 theme
->a_unfocused_label
= RrAppearanceNew(inst
, 1);
48 theme
->a_icon
= RrAppearanceNew(inst
, 1);
49 theme
->a_focused_handle
= RrAppearanceNew(inst
, 0);
50 theme
->a_unfocused_handle
= RrAppearanceNew(inst
, 0);
51 theme
->a_menu
= RrAppearanceNew(inst
, 0);
52 theme
->a_menu_title
= RrAppearanceNew(inst
, 1);
53 theme
->a_menu_item
= RrAppearanceNew(inst
, 1);
54 theme
->a_menu_disabled
= RrAppearanceNew(inst
, 1);
55 theme
->a_menu_hilite
= RrAppearanceNew(inst
, 1);
57 theme
->app_hilite_bg
= RrAppearanceNew(inst
, 0);
58 theme
->app_unhilite_bg
= RrAppearanceNew(inst
, 0);
59 theme
->app_hilite_label
= RrAppearanceNew(inst
, 1);
60 theme
->app_unhilite_label
= RrAppearanceNew(inst
, 1);
61 theme
->app_icon
= RrAppearanceNew(inst
, 1);
64 db
= loaddb(theme
, name
);
66 g_warning("Failed to load the theme '%s'\n"
67 "Falling back to the default: '%s'",
70 theme
->name
= g_path_get_basename(name
);
73 db
= loaddb(theme
, DEFAULT_THEME
);
75 g_warning("Failed to load the theme '%s'.", DEFAULT_THEME
);
78 theme
->name
= g_path_get_basename(DEFAULT_THEME
);
81 /* load the font stuff */
82 if (!read_string(db
, "window.title.xftfont", &font_str
))
83 font_str
= "arial,sans:bold:pixelsize=10:shadow=y:shadowtint=50";
85 if (!(theme
->winfont
= RrFontOpen(inst
, font_str
))) {
89 theme
->winfont_height
= RrFontHeight(theme
->winfont
);
91 winjust
= RR_JUSTIFY_LEFT
;
92 if (read_string(db
, "window.justify", &str
)) {
93 if (!g_ascii_strcasecmp(str
, "right"))
94 winjust
= RR_JUSTIFY_RIGHT
;
95 else if (!g_ascii_strcasecmp(str
, "center"))
96 winjust
= RR_JUSTIFY_CENTER
;
99 if (!read_string(db
, "menu.title.xftfont", &font_str
))
100 font_str
= "arial,sans:bold:pixelsize=12:shadow=y";
102 if (!(theme
->mtitlefont
= RrFontOpen(inst
, font_str
))) {
106 theme
->mtitlefont_height
= RrFontHeight(theme
->mtitlefont
);
108 mtitlejust
= RR_JUSTIFY_LEFT
;
109 if (read_string(db
, "menu.title.justify", &str
)) {
110 if (!g_ascii_strcasecmp(str
, "right"))
111 mtitlejust
= RR_JUSTIFY_RIGHT
;
112 else if (!g_ascii_strcasecmp(str
, "center"))
113 mtitlejust
= RR_JUSTIFY_CENTER
;
116 if (!read_string(db
, "menu.frame.xftfont", &font_str
))
117 font_str
= "arial,sans:bold:pixelsize=11:shadow=y";
119 if (!(theme
->mfont
= RrFontOpen(inst
, font_str
))) {
123 theme
->mfont_height
= RrFontHeight(theme
->mfont
);
125 mjust
= RR_JUSTIFY_LEFT
;
126 if (read_string(db
, "menu.frame.justify", &str
)) {
127 if (!g_ascii_strcasecmp(str
, "right"))
128 mjust
= RR_JUSTIFY_RIGHT
;
129 else if (!g_ascii_strcasecmp(str
, "center"))
130 mjust
= RR_JUSTIFY_CENTER
;
133 /* load the title layout */
134 if (!read_string(db
, "window.title.layout", &font_str
))
136 theme
->title_layout
= g_strdup(font_str
);
138 /* load direct dimensions */
139 if (!read_int(db
, "menuOverlap", &theme
->menu_overlap
) ||
140 theme
->menu_overlap
< 0 || theme
->menu_overlap
> 20)
141 theme
->handle_height
= 0;
142 if (!read_int(db
, "handleWidth", &theme
->handle_height
) ||
143 theme
->handle_height
< 0 || theme
->handle_height
> 100)
144 theme
->handle_height
= 6;
145 if (!read_int(db
, "bevelWidth", &theme
->bevel
) ||
146 theme
->bevel
<= 0 || theme
->bevel
> 100) theme
->bevel
= 3;
147 if (!read_int(db
, "borderWidth", &theme
->bwidth
) ||
148 theme
->bwidth
< 0 || theme
->bwidth
> 100) theme
->bwidth
= 1;
149 if (!read_int(db
, "frameWidth", &theme
->cbwidth
) ||
150 theme
->cbwidth
< 0 || theme
->cbwidth
> 100)
151 theme
->cbwidth
= theme
->bevel
;
154 if (!read_color(db
, inst
,
155 "borderColor", &theme
->b_color
))
156 theme
->b_color
= RrColorNew(inst
, 0, 0, 0);
157 if (!read_color(db
, inst
,
158 "window.frame.focusColor", &theme
->cb_focused_color
))
159 theme
->cb_focused_color
= RrColorNew(inst
, 0xff, 0xff, 0xff);
160 if (!read_color(db
, inst
,
161 "window.frame.unfocusColor",&theme
->cb_unfocused_color
))
162 theme
->cb_unfocused_color
= RrColorNew(inst
, 0xff, 0xff, 0xff);
163 if (!read_color(db
, inst
,
164 "window.label.focus.textColor",
165 &theme
->title_focused_color
))
166 theme
->title_focused_color
= RrColorNew(inst
, 0x0, 0x0, 0x0);
167 if (!read_color(db
, inst
,
168 "window.label.unfocus.textColor",
169 &theme
->title_unfocused_color
))
170 theme
->title_unfocused_color
= RrColorNew(inst
, 0xff, 0xff, 0xff);
171 if (!read_color(db
, inst
,
172 "window.button.focus.picColor",
173 &theme
->titlebut_focused_color
))
174 theme
->titlebut_focused_color
= RrColorNew(inst
, 0, 0, 0);
175 if (!read_color(db
, inst
,
176 "window.button.unfocus.picColor",
177 &theme
->titlebut_unfocused_color
))
178 theme
->titlebut_unfocused_color
= RrColorNew(inst
, 0xff, 0xff, 0xff);
179 if (!read_color(db
, inst
,
180 "window.button.disabled.focus.picColor",
181 &theme
->titlebut_disabled_focused_color
))
182 theme
->titlebut_disabled_focused_color
=
183 RrColorNew(inst
, 0xff, 0xff, 0xff);
184 if (!read_color(db
, inst
,
185 "window.button.disabled.unfocus.picColor",
186 &theme
->titlebut_disabled_unfocused_color
))
187 theme
->titlebut_disabled_unfocused_color
= RrColorNew(inst
, 0, 0, 0);
188 if (!read_color(db
, inst
,
189 "menu.title.textColor", &theme
->menu_title_color
))
190 theme
->menu_title_color
= RrColorNew(inst
, 0, 0, 0);
191 if (!read_color(db
, inst
,
192 "menu.frame.textColor", &theme
->menu_color
))
193 theme
->menu_color
= RrColorNew(inst
, 0xff, 0xff, 0xff);
194 if (!read_color(db
, inst
,
195 "menu.frame.disableColor", &theme
->menu_disabled_color
))
196 theme
->menu_disabled_color
= RrColorNew(inst
, 0, 0, 0);
197 if (!read_color(db
, inst
,
198 "menu.hilite.textColor", &theme
->menu_hilite_color
))
199 theme
->menu_hilite_color
= RrColorNew(inst
, 0, 0, 0);
201 if (read_mask(inst
, "max.xbm", theme
, &theme
->max_unset_mask
)){
202 if (!read_mask(inst
, "max_t.xbm", theme
, &theme
->max_set_mask
)) {
203 theme
->max_set_mask
= RrPixmapMaskCopy(theme
->max_unset_mask
);
207 char data
[] = { 0x7f, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x7f };
208 theme
->max_unset_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
211 char data
[] = { 0x7c, 0x44, 0x47, 0x47, 0x7f, 0x1f, 0x1f };
212 theme
->max_set_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
216 if (!read_mask(inst
, "iconify.xbm", theme
, &theme
->iconify_mask
)) {
217 char data
[] = { 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x7f };
218 theme
->iconify_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
221 if (read_mask(inst
, "stick.xbm", theme
, &theme
->desk_unset_mask
)) {
222 if (!read_mask(inst
, "stick_t.xbm", theme
, &theme
->desk_set_mask
)) {
223 theme
->desk_set_mask
=
224 RrPixmapMaskCopy(theme
->desk_unset_mask
);
228 char data
[] = { 0x63, 0x63, 0x00, 0x00, 0x00, 0x63, 0x63 };
229 theme
->desk_unset_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
232 char data
[] = { 0x00, 0x36, 0x36, 0x08, 0x36, 0x36, 0x00 };
233 theme
->desk_set_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
237 if (read_mask(inst
, "shade.xbm", theme
, &theme
->shade_unset_mask
)) {
238 if (!read_mask(inst
, "shade_t.xbm", theme
, &theme
->shade_set_mask
)) {
239 theme
->shade_set_mask
=
240 RrPixmapMaskCopy(theme
->shade_unset_mask
);
244 char data
[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00 };
245 theme
->shade_unset_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
248 char data
[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x7f };
249 theme
->shade_set_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
253 if (!read_mask(inst
, "close.xbm", theme
, &theme
->close_mask
)) {
254 char data
[] = { 0x63, 0x77, 0x3e, 0x1c, 0x3e, 0x77, 0x63 };
255 theme
->close_mask
= RrPixmapMaskNew(inst
, 7, 7, data
);
258 /* read the decoration textures */
259 if (!read_appearance(db
, inst
,
260 "window.title.focus", theme
->a_focused_title
))
261 set_default_appearance(theme
->a_focused_title
);
262 if (!read_appearance(db
, inst
,
263 "window.title.unfocus", theme
->a_unfocused_title
))
264 set_default_appearance(theme
->a_unfocused_title
);
265 if (!read_appearance(db
, inst
,
266 "window.label.focus", theme
->a_focused_label
))
267 set_default_appearance(theme
->a_focused_label
);
268 if (!read_appearance(db
, inst
,
269 "window.label.unfocus", theme
->a_unfocused_label
))
270 set_default_appearance(theme
->a_unfocused_label
);
271 if (!read_appearance(db
, inst
,
272 "window.handle.focus", theme
->a_focused_handle
))
273 set_default_appearance(theme
->a_focused_handle
);
274 if (!read_appearance(db
, inst
,
275 "window.handle.unfocus",theme
->a_unfocused_handle
))
276 set_default_appearance(theme
->a_unfocused_handle
);
277 if (!read_appearance(db
, inst
,
278 "window.grip.focus", theme
->a_focused_grip
))
279 set_default_appearance(theme
->a_focused_grip
);
280 if (!read_appearance(db
, inst
,
281 "window.grip.unfocus", theme
->a_unfocused_grip
))
282 set_default_appearance(theme
->a_unfocused_grip
);
283 if (!read_appearance(db
, inst
,
284 "menu.frame", theme
->a_menu
))
285 set_default_appearance(theme
->a_menu
);
286 if (!read_appearance(db
, inst
,
287 "menu.title", theme
->a_menu_title
))
288 set_default_appearance(theme
->a_menu_title
);
289 if (!read_appearance(db
, inst
,
290 "menu.hilite", theme
->a_menu_hilite
))
291 set_default_appearance(theme
->a_menu_hilite
);
293 /* read the appearances for rendering non-decorations */
294 if (!read_appearance(db
, inst
,
295 "window.title.focus", theme
->app_hilite_bg
))
296 set_default_appearance(theme
->app_hilite_bg
);
297 if (!read_appearance(db
, inst
,
298 "window.label.focus", theme
->app_hilite_label
))
299 set_default_appearance(theme
->app_hilite_label
);
300 if (!read_appearance(db
, inst
,
301 "window.title.unfocus", theme
->app_unhilite_bg
))
302 set_default_appearance(theme
->app_unhilite_bg
);
303 if (!read_appearance(db
, inst
,
304 "window.label.unfocus", theme
->app_unhilite_label
))
305 set_default_appearance(theme
->app_unhilite_label
);
307 /* read buttons textures */
308 if (!read_appearance(db
, inst
,
309 "window.button.disabled.focus",
310 theme
->a_disabled_focused_max
))
311 set_default_appearance(theme
->a_disabled_focused_max
);
312 if (!read_appearance(db
, inst
,
313 "window.button.disabled.unfocus",
314 theme
->a_disabled_unfocused_max
))
315 set_default_appearance(theme
->a_disabled_unfocused_max
);
316 if (!read_appearance(db
, inst
,
317 "window.button.pressed.focus",
318 theme
->a_focused_pressed_max
))
319 if (!read_appearance(db
, inst
,
320 "window.button.pressed",
321 theme
->a_focused_pressed_max
))
322 set_default_appearance(theme
->a_focused_pressed_max
);
323 if (!read_appearance(db
, inst
,
324 "window.button.pressed.unfocus",
325 theme
->a_unfocused_pressed_max
))
326 if (!read_appearance(db
, inst
,
327 "window.button.pressed",
328 theme
->a_unfocused_pressed_max
))
329 set_default_appearance(theme
->a_unfocused_pressed_max
);
330 if (!read_appearance(db
, inst
,
331 "window.button.focus",
332 theme
->a_focused_unpressed_max
))
333 set_default_appearance(theme
->a_focused_unpressed_max
);
334 if (!read_appearance(db
, inst
,
335 "window.button.unfocus",
336 theme
->a_unfocused_unpressed_max
))
337 set_default_appearance(theme
->a_unfocused_unpressed_max
);
339 theme
->a_disabled_focused_close
=
340 RrAppearanceCopy(theme
->a_disabled_focused_max
);
341 theme
->a_disabled_unfocused_close
=
342 RrAppearanceCopy(theme
->a_disabled_unfocused_max
);
343 theme
->a_unfocused_unpressed_close
=
344 RrAppearanceCopy(theme
->a_unfocused_unpressed_max
);
345 theme
->a_unfocused_pressed_close
=
346 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
347 theme
->a_focused_unpressed_close
=
348 RrAppearanceCopy(theme
->a_focused_unpressed_max
);
349 theme
->a_focused_pressed_close
=
350 RrAppearanceCopy(theme
->a_focused_pressed_max
);
351 theme
->a_disabled_focused_desk
=
352 RrAppearanceCopy(theme
->a_disabled_focused_max
);
353 theme
->a_disabled_unfocused_desk
=
354 RrAppearanceCopy(theme
->a_disabled_unfocused_max
);
355 theme
->a_unfocused_unpressed_desk
=
356 RrAppearanceCopy(theme
->a_unfocused_unpressed_max
);
357 theme
->a_unfocused_pressed_desk
=
358 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
359 theme
->a_unfocused_pressed_set_desk
=
360 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
361 theme
->a_focused_unpressed_desk
=
362 RrAppearanceCopy(theme
->a_focused_unpressed_max
);
363 theme
->a_focused_pressed_desk
=
364 RrAppearanceCopy(theme
->a_focused_pressed_max
);
365 theme
->a_focused_pressed_set_desk
=
366 RrAppearanceCopy(theme
->a_focused_pressed_max
);
367 theme
->a_disabled_focused_shade
=
368 RrAppearanceCopy(theme
->a_disabled_focused_max
);
369 theme
->a_disabled_unfocused_shade
=
370 RrAppearanceCopy(theme
->a_disabled_unfocused_max
);
371 theme
->a_unfocused_unpressed_shade
=
372 RrAppearanceCopy(theme
->a_unfocused_unpressed_max
);
373 theme
->a_unfocused_pressed_shade
=
374 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
375 theme
->a_unfocused_pressed_set_shade
=
376 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
377 theme
->a_focused_unpressed_shade
=
378 RrAppearanceCopy(theme
->a_focused_unpressed_max
);
379 theme
->a_focused_pressed_shade
=
380 RrAppearanceCopy(theme
->a_focused_pressed_max
);
381 theme
->a_focused_pressed_set_shade
=
382 RrAppearanceCopy(theme
->a_focused_pressed_max
);
383 theme
->a_disabled_focused_iconify
=
384 RrAppearanceCopy(theme
->a_disabled_focused_max
);
385 theme
->a_disabled_unfocused_iconify
=
386 RrAppearanceCopy(theme
->a_disabled_focused_max
);
387 theme
->a_unfocused_unpressed_iconify
=
388 RrAppearanceCopy(theme
->a_unfocused_unpressed_max
);
389 theme
->a_unfocused_pressed_iconify
=
390 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
391 theme
->a_focused_unpressed_iconify
=
392 RrAppearanceCopy(theme
->a_focused_unpressed_max
);
393 theme
->a_focused_pressed_iconify
=
394 RrAppearanceCopy(theme
->a_focused_pressed_max
);
395 theme
->a_unfocused_pressed_set_max
=
396 RrAppearanceCopy(theme
->a_unfocused_pressed_max
);
397 theme
->a_focused_pressed_set_max
=
398 RrAppearanceCopy(theme
->a_focused_pressed_max
);
400 theme
->a_icon
->surface
.grad
= RR_SURFACE_PARENTREL
;
402 /* set up the textures */
403 theme
->a_focused_label
->texture
[0].type
=
404 theme
->app_hilite_label
->texture
[0].type
= RR_TEXTURE_TEXT
;
405 theme
->a_focused_label
->texture
[0].data
.text
.justify
= winjust
;
406 theme
->app_hilite_label
->texture
[0].data
.text
.justify
= RR_JUSTIFY_LEFT
;
407 theme
->a_focused_label
->texture
[0].data
.text
.font
=
408 theme
->app_hilite_label
->texture
[0].data
.text
.font
= theme
->winfont
;
409 theme
->a_focused_label
->texture
[0].data
.text
.color
=
410 theme
->app_hilite_label
->texture
[0].data
.text
.color
=
411 theme
->title_focused_color
;
413 theme
->a_unfocused_label
->texture
[0].type
=
414 theme
->app_unhilite_label
->texture
[0].type
= RR_TEXTURE_TEXT
;
415 theme
->a_unfocused_label
->texture
[0].data
.text
.justify
= winjust
;
416 theme
->app_unhilite_label
->texture
[0].data
.text
.justify
= RR_JUSTIFY_LEFT
;
417 theme
->a_unfocused_label
->texture
[0].data
.text
.font
=
418 theme
->app_unhilite_label
->texture
[0].data
.text
.font
= theme
->winfont
;
419 theme
->a_unfocused_label
->texture
[0].data
.text
.color
=
420 theme
->app_unhilite_label
->texture
[0].data
.text
.color
=
421 theme
->title_unfocused_color
;
423 theme
->a_menu_title
->texture
[0].type
= RR_TEXTURE_TEXT
;
424 theme
->a_menu_title
->texture
[0].data
.text
.justify
= mtitlejust
;
425 theme
->a_menu_title
->texture
[0].data
.text
.font
= theme
->mtitlefont
;
426 theme
->a_menu_title
->texture
[0].data
.text
.color
= theme
->menu_title_color
;
428 theme
->a_menu_item
->surface
.grad
=
429 theme
->a_menu_disabled
->surface
.grad
=
430 theme
->app_icon
->surface
.grad
= RR_SURFACE_PARENTREL
;
432 theme
->a_menu_item
->texture
[0].type
=
433 theme
->a_menu_disabled
->texture
[0].type
=
434 theme
->a_menu_hilite
->texture
[0].type
= RR_TEXTURE_TEXT
;
435 theme
->a_menu_item
->texture
[0].data
.text
.justify
=
436 theme
->a_menu_disabled
->texture
[0].data
.text
.justify
=
437 theme
->a_menu_hilite
->texture
[0].data
.text
.justify
= mjust
;
438 theme
->a_menu_item
->texture
[0].data
.text
.font
=
439 theme
->a_menu_disabled
->texture
[0].data
.text
.font
=
440 theme
->a_menu_hilite
->texture
[0].data
.text
.font
= theme
->mfont
;
441 theme
->a_menu_item
->texture
[0].data
.text
.color
= theme
->menu_color
;
442 theme
->a_menu_disabled
->texture
[0].data
.text
.color
=
443 theme
->menu_disabled_color
;
444 theme
->a_menu_hilite
->texture
[0].data
.text
.color
=
445 theme
->menu_hilite_color
;
447 theme
->a_disabled_focused_max
->texture
[0].type
=
448 theme
->a_disabled_unfocused_max
->texture
[0].type
=
449 theme
->a_focused_unpressed_max
->texture
[0].type
=
450 theme
->a_focused_pressed_max
->texture
[0].type
=
451 theme
->a_focused_pressed_set_max
->texture
[0].type
=
452 theme
->a_unfocused_unpressed_max
->texture
[0].type
=
453 theme
->a_unfocused_pressed_max
->texture
[0].type
=
454 theme
->a_unfocused_pressed_set_max
->texture
[0].type
=
455 theme
->a_disabled_focused_close
->texture
[0].type
=
456 theme
->a_disabled_unfocused_close
->texture
[0].type
=
457 theme
->a_focused_unpressed_close
->texture
[0].type
=
458 theme
->a_focused_pressed_close
->texture
[0].type
=
459 theme
->a_unfocused_unpressed_close
->texture
[0].type
=
460 theme
->a_unfocused_pressed_close
->texture
[0].type
=
461 theme
->a_disabled_focused_desk
->texture
[0].type
=
462 theme
->a_disabled_unfocused_desk
->texture
[0].type
=
463 theme
->a_focused_unpressed_desk
->texture
[0].type
=
464 theme
->a_focused_pressed_desk
->texture
[0].type
=
465 theme
->a_focused_pressed_set_desk
->texture
[0].type
=
466 theme
->a_unfocused_unpressed_desk
->texture
[0].type
=
467 theme
->a_unfocused_pressed_desk
->texture
[0].type
=
468 theme
->a_unfocused_pressed_set_desk
->texture
[0].type
=
469 theme
->a_disabled_focused_shade
->texture
[0].type
=
470 theme
->a_disabled_unfocused_shade
->texture
[0].type
=
471 theme
->a_focused_unpressed_shade
->texture
[0].type
=
472 theme
->a_focused_pressed_shade
->texture
[0].type
=
473 theme
->a_focused_pressed_set_shade
->texture
[0].type
=
474 theme
->a_unfocused_unpressed_shade
->texture
[0].type
=
475 theme
->a_unfocused_pressed_shade
->texture
[0].type
=
476 theme
->a_unfocused_pressed_set_shade
->texture
[0].type
=
477 theme
->a_disabled_focused_iconify
->texture
[0].type
=
478 theme
->a_disabled_unfocused_iconify
->texture
[0].type
=
479 theme
->a_focused_unpressed_iconify
->texture
[0].type
=
480 theme
->a_focused_pressed_iconify
->texture
[0].type
=
481 theme
->a_unfocused_unpressed_iconify
->texture
[0].type
=
482 theme
->a_unfocused_pressed_iconify
->texture
[0].type
= RR_TEXTURE_MASK
;
483 theme
->a_disabled_focused_max
->texture
[0].data
.mask
.mask
=
484 theme
->a_disabled_unfocused_max
->texture
[0].data
.mask
.mask
=
485 theme
->a_focused_unpressed_max
->texture
[0].data
.mask
.mask
=
486 theme
->a_unfocused_unpressed_max
->texture
[0].data
.mask
.mask
=
487 theme
->a_focused_pressed_max
->texture
[0].data
.mask
.mask
=
488 theme
->a_unfocused_pressed_max
->texture
[0].data
.mask
.mask
=
489 theme
->max_unset_mask
;
490 theme
->a_focused_pressed_set_max
->texture
[0].data
.mask
.mask
=
491 theme
->a_unfocused_pressed_set_max
->texture
[0].data
.mask
.mask
=
493 theme
->a_disabled_focused_close
->texture
[0].data
.mask
.mask
=
494 theme
->a_disabled_unfocused_close
->texture
[0].data
.mask
.mask
=
495 theme
->a_focused_pressed_close
->texture
[0].data
.mask
.mask
=
496 theme
->a_unfocused_pressed_close
->texture
[0].data
.mask
.mask
=
497 theme
->a_focused_unpressed_close
->texture
[0].data
.mask
.mask
=
498 theme
->a_unfocused_unpressed_close
->texture
[0].data
.mask
.mask
=
500 theme
->a_disabled_focused_desk
->texture
[0].data
.mask
.mask
=
501 theme
->a_disabled_unfocused_desk
->texture
[0].data
.mask
.mask
=
502 theme
->a_focused_unpressed_desk
->texture
[0].data
.mask
.mask
=
503 theme
->a_unfocused_unpressed_desk
->texture
[0].data
.mask
.mask
=
504 theme
->a_focused_pressed_desk
->texture
[0].data
.mask
.mask
=
505 theme
->a_unfocused_pressed_desk
->texture
[0].data
.mask
.mask
=
506 theme
->desk_unset_mask
;
507 theme
->a_focused_pressed_set_desk
->texture
[0].data
.mask
.mask
=
508 theme
->a_unfocused_pressed_set_desk
->texture
[0].data
.mask
.mask
=
509 theme
->desk_set_mask
;
510 theme
->a_disabled_focused_shade
->texture
[0].data
.mask
.mask
=
511 theme
->a_disabled_unfocused_shade
->texture
[0].data
.mask
.mask
=
512 theme
->a_focused_unpressed_shade
->texture
[0].data
.mask
.mask
=
513 theme
->a_unfocused_unpressed_shade
->texture
[0].data
.mask
.mask
=
514 theme
->a_focused_pressed_shade
->texture
[0].data
.mask
.mask
=
515 theme
->a_unfocused_pressed_shade
->texture
[0].data
.mask
.mask
=
516 theme
->shade_unset_mask
;
517 theme
->a_focused_pressed_set_shade
->texture
[0].data
.mask
.mask
=
518 theme
->a_unfocused_pressed_set_shade
->texture
[0].data
.mask
.mask
=
519 theme
->shade_set_mask
;
520 theme
->a_disabled_focused_iconify
->texture
[0].data
.mask
.mask
=
521 theme
->a_disabled_unfocused_iconify
->texture
[0].data
.mask
.mask
=
522 theme
->a_focused_unpressed_iconify
->texture
[0].data
.mask
.mask
=
523 theme
->a_unfocused_unpressed_iconify
->texture
[0].data
.mask
.mask
=
524 theme
->a_focused_pressed_iconify
->texture
[0].data
.mask
.mask
=
525 theme
->a_unfocused_pressed_iconify
->texture
[0].data
.mask
.mask
=
527 theme
->a_disabled_focused_max
->texture
[0].data
.mask
.color
=
528 theme
->a_disabled_focused_close
->texture
[0].data
.mask
.color
=
529 theme
->a_disabled_focused_desk
->texture
[0].data
.mask
.color
=
530 theme
->a_disabled_focused_shade
->texture
[0].data
.mask
.color
=
531 theme
->a_disabled_focused_iconify
->texture
[0].data
.mask
.color
=
532 theme
->titlebut_disabled_focused_color
;
533 theme
->a_disabled_unfocused_max
->texture
[0].data
.mask
.color
=
534 theme
->a_disabled_unfocused_close
->texture
[0].data
.mask
.color
=
535 theme
->a_disabled_unfocused_desk
->texture
[0].data
.mask
.color
=
536 theme
->a_disabled_unfocused_shade
->texture
[0].data
.mask
.color
=
537 theme
->a_disabled_unfocused_iconify
->texture
[0].data
.mask
.color
=
538 theme
->titlebut_disabled_unfocused_color
;
539 theme
->a_focused_unpressed_max
->texture
[0].data
.mask
.color
=
540 theme
->a_focused_pressed_max
->texture
[0].data
.mask
.color
=
541 theme
->a_focused_pressed_set_max
->texture
[0].data
.mask
.color
=
542 theme
->a_focused_unpressed_close
->texture
[0].data
.mask
.color
=
543 theme
->a_focused_pressed_close
->texture
[0].data
.mask
.color
=
544 theme
->a_focused_unpressed_desk
->texture
[0].data
.mask
.color
=
545 theme
->a_focused_pressed_desk
->texture
[0].data
.mask
.color
=
546 theme
->a_focused_pressed_set_desk
->texture
[0].data
.mask
.color
=
547 theme
->a_focused_unpressed_shade
->texture
[0].data
.mask
.color
=
548 theme
->a_focused_pressed_shade
->texture
[0].data
.mask
.color
=
549 theme
->a_focused_pressed_set_shade
->texture
[0].data
.mask
.color
=
550 theme
->a_focused_unpressed_iconify
->texture
[0].data
.mask
.color
=
551 theme
->a_focused_pressed_iconify
->texture
[0].data
.mask
.color
=
552 theme
->titlebut_focused_color
;
553 theme
->a_unfocused_unpressed_max
->texture
[0].data
.mask
.color
=
554 theme
->a_unfocused_pressed_max
->texture
[0].data
.mask
.color
=
555 theme
->a_unfocused_pressed_set_max
->texture
[0].data
.mask
.color
=
556 theme
->a_unfocused_unpressed_close
->texture
[0].data
.mask
.color
=
557 theme
->a_unfocused_pressed_close
->texture
[0].data
.mask
.color
=
558 theme
->a_unfocused_unpressed_desk
->texture
[0].data
.mask
.color
=
559 theme
->a_unfocused_pressed_desk
->texture
[0].data
.mask
.color
=
560 theme
->a_unfocused_pressed_set_desk
->texture
[0].data
.mask
.color
=
561 theme
->a_unfocused_unpressed_shade
->texture
[0].data
.mask
.color
=
562 theme
->a_unfocused_pressed_shade
->texture
[0].data
.mask
.color
=
563 theme
->a_unfocused_pressed_set_shade
->texture
[0].data
.mask
.color
=
564 theme
->a_unfocused_unpressed_iconify
->texture
[0].data
.mask
.color
=
565 theme
->a_unfocused_pressed_iconify
->texture
[0].data
.mask
.color
=
566 theme
->titlebut_unfocused_color
;
568 XrmDestroyDatabase(db
);
570 theme
->label_height
= theme
->winfont_height
;
571 theme
->title_height
= theme
->label_height
+ theme
->bevel
* 2;
572 theme
->button_size
= theme
->label_height
- 2;
573 theme
->grip_width
= theme
->button_size
* 2;
578 void RrThemeFree(RrTheme
*theme
)
583 RrColorFree(theme
->b_color
);
584 RrColorFree(theme
->cb_unfocused_color
);
585 RrColorFree(theme
->cb_focused_color
);
586 RrColorFree(theme
->title_unfocused_color
);
587 RrColorFree(theme
->title_focused_color
);
588 RrColorFree(theme
->titlebut_unfocused_color
);
589 RrColorFree(theme
->titlebut_focused_color
);
590 RrColorFree(theme
->menu_color
);
591 RrColorFree(theme
->menu_title_color
);
592 RrColorFree(theme
->menu_disabled_color
);
593 RrColorFree(theme
->menu_hilite_color
);
595 RrPixmapMaskFree(theme
->max_set_mask
);
596 RrPixmapMaskFree(theme
->max_unset_mask
);
597 RrPixmapMaskFree(theme
->desk_set_mask
);
598 RrPixmapMaskFree(theme
->desk_unset_mask
);
599 RrPixmapMaskFree(theme
->shade_set_mask
);
600 RrPixmapMaskFree(theme
->shade_unset_mask
);
601 RrPixmapMaskFree(theme
->iconify_mask
);
602 RrPixmapMaskFree(theme
->close_mask
);
604 RrFontClose(theme
->winfont
);
605 RrFontClose(theme
->mtitlefont
);
606 RrFontClose(theme
->mfont
);
608 g_free(theme
->title_layout
);
610 RrAppearanceFree(theme
->a_focused_unpressed_max
);
611 RrAppearanceFree(theme
->a_focused_pressed_max
);
612 RrAppearanceFree(theme
->a_focused_pressed_set_max
);
613 RrAppearanceFree(theme
->a_unfocused_unpressed_max
);
614 RrAppearanceFree(theme
->a_unfocused_pressed_max
);
615 RrAppearanceFree(theme
->a_unfocused_pressed_set_max
);
616 RrAppearanceFree(theme
->a_focused_unpressed_close
);
617 RrAppearanceFree(theme
->a_focused_pressed_close
);
618 RrAppearanceFree(theme
->a_unfocused_unpressed_close
);
619 RrAppearanceFree(theme
->a_unfocused_pressed_close
);
620 RrAppearanceFree(theme
->a_focused_unpressed_desk
);
621 RrAppearanceFree(theme
->a_focused_pressed_desk
);
622 RrAppearanceFree(theme
->a_unfocused_unpressed_desk
);
623 RrAppearanceFree(theme
->a_unfocused_pressed_desk
);
624 RrAppearanceFree(theme
->a_focused_unpressed_shade
);
625 RrAppearanceFree(theme
->a_focused_pressed_shade
);
626 RrAppearanceFree(theme
->a_unfocused_unpressed_shade
);
627 RrAppearanceFree(theme
->a_unfocused_pressed_shade
);
628 RrAppearanceFree(theme
->a_focused_unpressed_iconify
);
629 RrAppearanceFree(theme
->a_focused_pressed_iconify
);
630 RrAppearanceFree(theme
->a_unfocused_unpressed_iconify
);
631 RrAppearanceFree(theme
->a_unfocused_pressed_iconify
);
632 RrAppearanceFree(theme
->a_focused_grip
);
633 RrAppearanceFree(theme
->a_unfocused_grip
);
634 RrAppearanceFree(theme
->a_focused_title
);
635 RrAppearanceFree(theme
->a_unfocused_title
);
636 RrAppearanceFree(theme
->a_focused_label
);
637 RrAppearanceFree(theme
->a_unfocused_label
);
638 RrAppearanceFree(theme
->a_icon
);
639 RrAppearanceFree(theme
->a_focused_handle
);
640 RrAppearanceFree(theme
->a_unfocused_handle
);
641 RrAppearanceFree(theme
->a_menu
);
642 RrAppearanceFree(theme
->a_menu_title
);
643 RrAppearanceFree(theme
->a_menu_item
);
644 RrAppearanceFree(theme
->a_menu_disabled
);
645 RrAppearanceFree(theme
->a_menu_hilite
);
646 RrAppearanceFree(theme
->app_hilite_bg
);
647 RrAppearanceFree(theme
->app_unhilite_bg
);
648 RrAppearanceFree(theme
->app_hilite_label
);
649 RrAppearanceFree(theme
->app_unhilite_label
);
650 RrAppearanceFree(theme
->app_icon
);
654 static XrmDatabase
loaddb(RrTheme
*theme
, char *name
)
658 if ((db
= XrmGetFileDatabase(name
)))
659 theme
->path
= g_path_get_dirname(name
);
661 char *s
= g_build_filename(g_get_home_dir(), ".openbox", "themes",
663 if ((db
= XrmGetFileDatabase(s
)))
664 theme
->path
= g_path_get_dirname(s
);
668 char *s
= g_build_filename(THEMEDIR
, name
, NULL
);
669 if ((db
= XrmGetFileDatabase(s
)))
670 theme
->path
= g_path_get_dirname(s
);
677 static char *create_class_name(char *rname
)
679 char *rclass
= g_strdup(rname
);
684 p
= strchr(p
+1, '.');
685 if (p
== NULL
) break;
687 if (*p
== '\0') break;
692 static gboolean
read_int(XrmDatabase db
, char *rname
, int *value
)
694 gboolean ret
= FALSE
;
695 char *rclass
= create_class_name(rname
);
699 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
700 retvalue
.addr
!= NULL
) {
701 *value
= (int)strtol(retvalue
.addr
, &end
, 10);
702 if (end
!= retvalue
.addr
)
710 static gboolean
read_string(XrmDatabase db
, char *rname
, char **value
)
712 gboolean ret
= FALSE
;
713 char *rclass
= create_class_name(rname
);
717 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
718 retvalue
.addr
!= NULL
) {
719 *value
= retvalue
.addr
;
727 static gboolean
read_color(XrmDatabase db
, const RrInstance
*inst
,
728 gchar
*rname
, RrColor
**value
)
730 gboolean ret
= FALSE
;
731 char *rclass
= create_class_name(rname
);
735 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
736 retvalue
.addr
!= NULL
) {
737 RrColor
*c
= RrColorParse(inst
, retvalue
.addr
);
748 static gboolean
read_mask(const RrInstance
*inst
,
749 gchar
*maskname
, RrTheme
*theme
,
750 RrPixmapMask
**value
)
752 gboolean ret
= FALSE
;
755 int hx
, hy
; /* ignored */
759 data_dir
= g_strdup_printf("%s_data", theme
->name
);
761 s
= g_build_filename(g_get_home_dir(), ".openbox", "themes",
762 data_dir
, maskname
, NULL
);
763 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) == BitmapSuccess
)
767 s
= g_build_filename(THEMEDIR
, data_dir
, maskname
, NULL
);
768 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) == BitmapSuccess
)
772 s
= g_build_filename(theme
->path
, data_dir
, maskname
, NULL
);
773 if (XReadBitmapFileData(s
, &w
, &h
, &b
, &hx
, &hy
) == BitmapSuccess
)
779 *value
= RrPixmapMaskNew(inst
, w
, h
, (char*)b
);
789 static void parse_appearance(gchar
*tex
, RrSurfaceColorType
*grad
,
790 RrReliefType
*relief
, RrBevelType
*bevel
,
791 gboolean
*interlaced
, gboolean
*border
)
795 /* convert to all lowercase */
796 for (t
= tex
; *t
!= '\0'; ++t
)
797 *t
= g_ascii_tolower(*t
);
799 if (strstr(tex
, "parentrelative") != NULL
) {
800 *grad
= RR_SURFACE_PARENTREL
;
802 if (strstr(tex
, "gradient") != NULL
) {
803 if (strstr(tex
, "crossdiagonal") != NULL
)
804 *grad
= RR_SURFACE_CROSS_DIAGONAL
;
805 else if (strstr(tex
, "pyramid") != NULL
)
806 *grad
= RR_SURFACE_PYRAMID
;
807 else if (strstr(tex
, "horizontal") != NULL
)
808 *grad
= RR_SURFACE_HORIZONTAL
;
809 else if (strstr(tex
, "vertical") != NULL
)
810 *grad
= RR_SURFACE_VERTICAL
;
812 *grad
= RR_SURFACE_DIAGONAL
;
814 *grad
= RR_SURFACE_SOLID
;
817 if (strstr(tex
, "sunken") != NULL
)
818 *relief
= RR_RELIEF_SUNKEN
;
819 else if (strstr(tex
, "flat") != NULL
)
820 *relief
= RR_RELIEF_FLAT
;
822 *relief
= RR_RELIEF_RAISED
;
825 if (*relief
== RR_RELIEF_FLAT
) {
826 if (strstr(tex
, "border") != NULL
)
829 if (strstr(tex
, "bevel2") != NULL
)
835 if (strstr(tex
, "interlaced") != NULL
)
843 static gboolean
read_appearance(XrmDatabase db
, const RrInstance
*inst
,
844 gchar
*rname
, RrAppearance
*value
)
846 gboolean ret
= FALSE
;
847 char *rclass
= create_class_name(rname
), *cname
, *ctoname
, *bcname
;
851 cname
= g_strconcat(rname
, ".color", NULL
);
852 ctoname
= g_strconcat(rname
, ".colorTo", NULL
);
853 bcname
= g_strconcat(rname
, ".borderColor", NULL
);
855 if (XrmGetResource(db
, rname
, rclass
, &rettype
, &retvalue
) &&
856 retvalue
.addr
!= NULL
) {
857 parse_appearance(retvalue
.addr
,
858 &value
->surface
.grad
,
859 &value
->surface
.relief
,
860 &value
->surface
.bevel
,
861 &value
->surface
.interlaced
,
862 &value
->surface
.border
);
863 if (!read_color(db
, inst
, cname
, &value
->surface
.primary
))
864 value
->surface
.primary
= RrColorNew(inst
, 0, 0, 0);
865 if (!read_color(db
, inst
, ctoname
, &value
->surface
.secondary
))
866 value
->surface
.secondary
= RrColorNew(inst
, 0, 0, 0);
867 if (value
->surface
.border
)
868 if (!read_color(db
, inst
, bcname
,
869 &value
->surface
.border_color
))
870 value
->surface
.border_color
= RrColorNew(inst
, 0, 0, 0);
881 static void set_default_appearance(RrAppearance
*a
)
883 a
->surface
.grad
= RR_SURFACE_SOLID
;
884 a
->surface
.relief
= RR_RELIEF_FLAT
;
885 a
->surface
.bevel
= RR_BEVEL_1
;
886 a
->surface
.interlaced
= FALSE
;
887 a
->surface
.border
= FALSE
;
888 a
->surface
.primary
= RrColorNew(a
->inst
, 0, 0, 0);
889 a
->surface
.secondary
= RrColorNew(a
->inst
, 0, 0, 0);