From f7fc6637f35e43adffb2e1a20ec511dfb9ca7bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Wed, 23 Jan 2019 20:04:17 +0100 Subject: [PATCH] Support X resource entries with Sxiv class name --- window.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/window.c b/window.c index 2f7cf7e..7d85c63 100644 --- a/window.c +++ b/window.c @@ -29,6 +29,8 @@ #include #include +#define RES_CLASS "Sxiv" + enum { H_TEXT_PAD = 5, V_TEXT_PAD = 1 @@ -100,12 +102,11 @@ void win_check_wm_support(Display *dpy, Window root) } } -void win_res(Display *dpy, const char *rsc, const char **dst) +void win_res(Display *dpy, const char *name, const char **dst) { char *type; XrmValue ret; XrmDatabase db; - char fullname[256]; char *res_man; XrmInitialize(); @@ -116,12 +117,7 @@ void win_res(Display *dpy, const char *rsc, const char **dst) if ((db = XrmGetStringDatabase(res_man)) == NULL) return; - snprintf(fullname, sizeof(fullname), ".%s", rsc); - fullname[sizeof(fullname) - 1] = '\0'; - - XrmGetResource(db, fullname, "String", &type, &ret); - - if (ret.addr != NULL && STREQ(type, "String")) + if (XrmGetResource(db, name, name, &type, &ret) && STREQ(type, "String")) *dst = ret.addr; } @@ -148,10 +144,10 @@ void win_init(win_t *win) if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) error(0, 0, "No locale support"); - win_res(e->dpy, "background", &WIN_BG_COLOR); - win_res(e->dpy, "background", &BAR_FG_COLOR); - win_res(e->dpy, "foreground", &BAR_BG_COLOR); - win_res(e->dpy, "foreground", &SEL_COLOR); + 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); @@ -281,7 +277,7 @@ void win_open(win_t *win) win_set_title(win, "sxiv"); - classhint.res_class = "Sxiv"; + classhint.res_class = RES_CLASS; classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv"; XSetClassHint(e->dpy, win->xwin, &classhint);