diff options
author | Bert Münnich <ber.t@posteo.de> | 2019-01-23 20:13:25 +0100 |
---|---|---|
committer | Bert Münnich <ber.t@posteo.de> | 2019-01-23 20:13:25 +0100 |
commit | 9d244da5124bf13046a4f9606b616ab1d8244e0e (patch) | |
tree | 6c28825bc202310e09588a818b6e57aa53b99056 /window.c | |
parent | f7fc6637f35e43adffb2e1a20ec511dfb9ca7bd1 (diff) |
Simplify X resource retrieval
Also makes the color names in config.def.h constant again.
Diffstat (limited to 'window.c')
-rw-r--r-- | window.c | 35 |
1 files changed, 17 insertions, 18 deletions
@@ -102,7 +102,7 @@ void win_check_wm_support(Display *dpy, Window root) } } -void win_res(Display *dpy, const char *name, const char **dst) +const char* win_res(Display *dpy, const char *name, const char *def) { char *type; XrmValue ret; @@ -111,14 +111,14 @@ void win_res(Display *dpy, const char *name, const char **dst) XrmInitialize(); - if ((res_man = XResourceManagerString(dpy)) == NULL) - return; - - if ((db = XrmGetStringDatabase(res_man)) == NULL) - return; - - if (XrmGetResource(db, name, name, &type, &ret) && STREQ(type, "String")) - *dst = ret.addr; + if ((res_man = XResourceManagerString(dpy)) != NULL && + (db = XrmGetStringDatabase(res_man)) != NULL && + XrmGetResource(db, name, name, &type, &ret) && STREQ(type, "String")) + { + return ret.addr; + } else { + return def; + } } #define INIT_ATOM_(atom) \ @@ -144,18 +144,17 @@ void win_init(win_t *win) if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) error(0, 0, "No locale support"); - win_res(e->dpy, RES_CLASS ".background", &WIN_BG_COLOR); - win_res(e->dpy, RES_CLASS ".background", &BAR_FG_COLOR); - win_res(e->dpy, RES_CLASS ".foreground", &BAR_BG_COLOR); - win_res(e->dpy, RES_CLASS ".foreground", &SEL_COLOR); - win_init_font(e, BAR_FONT); - win_alloc_color(e, WIN_BG_COLOR, &win->bgcol); + win_alloc_color(e, win_res(e->dpy, RES_CLASS ".background", WIN_BG_COLOR), + &win->bgcol); win_alloc_color(e, WIN_FS_COLOR, &win->fscol); - win_alloc_color(e, SEL_COLOR, &win->selcol); - win_alloc_color(e, BAR_BG_COLOR, &win->bar.bgcol); - win_alloc_color(e, BAR_FG_COLOR, &win->bar.fgcol); + win_alloc_color(e, win_res(e->dpy, RES_CLASS ".foreground", SEL_COLOR), + &win->selcol); + win_alloc_color(e, win_res(e->dpy, RES_CLASS ".foreground", BAR_BG_COLOR), + &win->bar.bgcol); + win_alloc_color(e, win_res(e->dpy, RES_CLASS ".background", BAR_FG_COLOR), + &win->bar.fgcol); win->bar.l.size = BAR_L_LEN; win->bar.r.size = BAR_R_LEN; |