nsxiv9d244da
Simplify X resource retrieval
Also makes the color names in config.def.h constant again.
+22 −23
2 files changed
- M config.def.h +5 −5
- M window.c +17 −18
| @@ -14,11 +14,11 @@ static const char * const BAR_FONT = "monospace:size=8"; | |||
| 14 | 14 | /* colors: | |
| 15 | 15 | * (see X(7) section "COLOR NAMES" for valid values) | |
| 16 | 16 | */ | |
| 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"; | |
| 22 | 22 | ||
| 23 | 23 | #endif | |
| 24 | 24 | #ifdef _IMAGE_CONFIG | |
| @@ -102,7 +102,7 @@ void win_check_wm_support(Display *dpy, Window root) | |||
| 102 | 102 | } | |
| 103 | 103 | } | |
| 104 | 104 | ||
| 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) | |
| 106 | 106 | { | |
| 107 | 107 | char *type; | |
| 108 | 108 | XrmValue ret; | |
| @@ -111,14 +111,14 @@ void win_res(Display *dpy, const char *name, const char **dst) | |||
| 111 | 111 | ||
| 112 | 112 | XrmInitialize(); | |
| 113 | 113 | ||
| 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 | + | } | |
| 122 | 122 | } | |
| 123 | 123 | ||
| 124 | 124 | #define INIT_ATOM_(atom) \ | |
| @@ -144,18 +144,17 @@ void win_init(win_t *win) | |||
| 144 | 144 | if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) | |
| 145 | 145 | error(0, 0, "No locale support"); | |
| 146 | 146 | ||
| 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 | − | ||
| 152 | 147 | win_init_font(e, BAR_FONT); | |
| 153 | 148 | ||
| 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); | |
| 155 | 151 | 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); | |
| 159 | 158 | ||
| 160 | 159 | win->bar.l.size = BAR_L_LEN; | |
| 161 | 160 | win->bar.r.size = BAR_R_LEN; | |