Krolyxon
Commit f7fc663

Branches

Refs →

nsxivf7fc663

Support X resource entries with Sxiv class name

Author
Bert Münnich
Date
2019-01-23 20:04 +0100
Parent
e4fb084
Commit
f7fc6637f35e43adffb2e1a20ec511dfb9ca7bd1

+9 −13

1 file changed

  1. M window.c +9 −13
M window.c View
@@ -29,6 +29,8 @@
2929 #include <X11/Xatom.h>
3030 #include <X11/Xresource.h>
3131
32+#define RES_CLASS "Sxiv"
33+
3234 enum {
3335 H_TEXT_PAD = 5,
3436 V_TEXT_PAD = 1
@@ -100,12 +102,11 @@ void win_check_wm_support(Display *dpy, Window root)
100102 }
101103 }
102104
103−void win_res(Display *dpy, const char *rsc, const char **dst)
105+void win_res(Display *dpy, const char *name, const char **dst)
104106 {
105107 char *type;
106108 XrmValue ret;
107109 XrmDatabase db;
108− char fullname[256];
109110 char *res_man;
110111
111112 XrmInitialize();
@@ -116,12 +117,7 @@ void win_res(Display *dpy, const char *rsc, const char **dst)
116117 if ((db = XrmGetStringDatabase(res_man)) == NULL)
117118 return;
118119
119− snprintf(fullname, sizeof(fullname), ".%s", rsc);
120− fullname[sizeof(fullname) - 1] = '\0';
121−
122− XrmGetResource(db, fullname, "String", &type, &ret);
123−
124− if (ret.addr != NULL && STREQ(type, "String"))
120+ if (XrmGetResource(db, name, name, &type, &ret) && STREQ(type, "String"))
125121 *dst = ret.addr;
126122 }
127123
@@ -148,10 +144,10 @@ void win_init(win_t *win)
148144 if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0)
149145 error(0, 0, "No locale support");
150146
151− win_res(e->dpy, "background", &WIN_BG_COLOR);
152− win_res(e->dpy, "background", &BAR_FG_COLOR);
153− win_res(e->dpy, "foreground", &BAR_BG_COLOR);
154− win_res(e->dpy, "foreground", &SEL_COLOR);
147+ win_res(e->dpy, RES_CLASS ".background", &WIN_BG_COLOR);
148+ win_res(e->dpy, RES_CLASS ".background", &BAR_FG_COLOR);
149+ win_res(e->dpy, RES_CLASS ".foreground", &BAR_BG_COLOR);
150+ win_res(e->dpy, RES_CLASS ".foreground", &SEL_COLOR);
155151
156152 win_init_font(e, BAR_FONT);
157153
@@ -281,7 +277,7 @@ void win_open(win_t *win)
281277
282278 win_set_title(win, "sxiv");
283279
284− classhint.res_class = "Sxiv";
280+ classhint.res_class = RES_CLASS;
285281 classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv";
286282 XSetClassHint(e->dpy, win->xwin, &classhint);
287283