Krolyxon
Commit 9d244da

Branches

Refs →

nsxiv9d244da

Simplify X resource retrieval

Also makes the color names in config.def.h constant again.
Author
Bert Münnich
Date
2019-01-23 20:13 +0100
Parent
f7fc663
Commit
9d244da5124bf13046a4f9606b616ab1d8244e0e

+22 −23

2 files changed

  1. M config.def.h +5 −5
  2. M window.c +17 −18
M config.def.h View
@@ -14,11 +14,11 @@ static const char * const BAR_FONT = "monospace:size=8";
1414 /* colors:
1515 * (see X(7) section "COLOR NAMES" for valid values)
1616 */
17−static char const * WIN_BG_COLOR = "#555555";
18−static char const * WIN_FS_COLOR = "#000000";
19−static char const * SEL_COLOR = "#EEEEEE";
20−static char const * BAR_BG_COLOR = "#222222";
21−static char const * BAR_FG_COLOR = "#EEEEEE";
17+static const char * const WIN_BG_COLOR = "#555555";
18+static const char * const WIN_FS_COLOR = "#000000";
19+static const char * const SEL_COLOR = "#EEEEEE";
20+static const char * const BAR_BG_COLOR = "#222222";
21+static const char * const BAR_FG_COLOR = "#EEEEEE";
2222
2323 #endif
2424 #ifdef _IMAGE_CONFIG
M window.c View
@@ -102,7 +102,7 @@ void win_check_wm_support(Display *dpy, Window root)
102102 }
103103 }
104104
105−void win_res(Display *dpy, const char *name, const char **dst)
105+const char* win_res(Display *dpy, const char *name, const char *def)
106106 {
107107 char *type;
108108 XrmValue ret;
@@ -111,14 +111,14 @@ void win_res(Display *dpy, const char *name, const char **dst)
111111
112112 XrmInitialize();
113113
114− if ((res_man = XResourceManagerString(dpy)) == NULL)
115− return;
116−
117− if ((db = XrmGetStringDatabase(res_man)) == NULL)
118− return;
119−
120− if (XrmGetResource(db, name, name, &type, &ret) && STREQ(type, "String"))
121− *dst = ret.addr;
114+ if ((res_man = XResourceManagerString(dpy)) != NULL &&
115+ (db = XrmGetStringDatabase(res_man)) != NULL &&
116+ XrmGetResource(db, name, name, &type, &ret) && STREQ(type, "String"))
117+ {
118+ return ret.addr;
119+ } else {
120+ return def;
121+ }
122122 }
123123
124124 #define INIT_ATOM_(atom) \
@@ -144,18 +144,17 @@ void win_init(win_t *win)
144144 if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0)
145145 error(0, 0, "No locale support");
146146
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);
151−
152147 win_init_font(e, BAR_FONT);
153148
154− win_alloc_color(e, WIN_BG_COLOR, &win->bgcol);
149+ win_alloc_color(e, win_res(e->dpy, RES_CLASS ".background", WIN_BG_COLOR),
150+ &win->bgcol);
155151 win_alloc_color(e, WIN_FS_COLOR, &win->fscol);
156− win_alloc_color(e, SEL_COLOR, &win->selcol);
157− win_alloc_color(e, BAR_BG_COLOR, &win->bar.bgcol);
158− win_alloc_color(e, BAR_FG_COLOR, &win->bar.fgcol);
152+ win_alloc_color(e, win_res(e->dpy, RES_CLASS ".foreground", SEL_COLOR),
153+ &win->selcol);
154+ win_alloc_color(e, win_res(e->dpy, RES_CLASS ".foreground", BAR_BG_COLOR),
155+ &win->bar.bgcol);
156+ win_alloc_color(e, win_res(e->dpy, RES_CLASS ".background", BAR_FG_COLOR),
157+ &win->bar.fgcol);
159158
160159 win->bar.l.size = BAR_L_LEN;
161160 win->bar.r.size = BAR_R_LEN;