nsxiv4853e17
Add Xresources capability
+41 −6
2 files changed
- M config.def.h +5 −5
- M window.c +36 −1
| @@ -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 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"; | |
| 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"; | |
| 22 | 22 | ||
| 23 | 23 | #endif | |
| 24 | 24 | #ifdef _IMAGE_CONFIG | |
| @@ -27,6 +27,7 @@ | |||
| 27 | 27 | #include <locale.h> | |
| 28 | 28 | #include <X11/cursorfont.h> | |
| 29 | 29 | #include <X11/Xatom.h> | |
| 30 | + | #include <X11/Xresource.h> | |
| 30 | 31 | ||
| 31 | 32 | enum { | |
| 32 | 33 | H_TEXT_PAD = 5, | |
| @@ -99,6 +100,35 @@ void win_check_wm_support(Display *dpy, Window root) | |||
| 99 | 100 | } | |
| 100 | 101 | } | |
| 101 | 102 | ||
| 103 | + | void get_xresource(Display *dpy, const char* rsc, const void* dst) | |
| 104 | + | { | |
| 105 | + | char *type; | |
| 106 | + | XrmValue ret; | |
| 107 | + | XrmDatabase db; | |
| 108 | + | char fullname[256]; | |
| 109 | + | char *resource_manager; | |
| 110 | + | ||
| 111 | + | XrmInitialize(); | |
| 112 | + | resource_manager = XResourceManagerString(dpy); | |
| 113 | + | ||
| 114 | + | if (resource_manager == NULL) | |
| 115 | + | return; | |
| 116 | + | ||
| 117 | + | db = XrmGetStringDatabase(resource_manager); | |
| 118 | + | ||
| 119 | + | if (db == NULL) | |
| 120 | + | return; | |
| 121 | + | ||
| 122 | + | snprintf(fullname, sizeof(fullname), ".%s", rsc); | |
| 123 | + | fullname[sizeof(fullname) - 1] = '\0'; | |
| 124 | + | ||
| 125 | + | XrmGetResource(db, fullname, "String", &type, &ret); | |
| 126 | + | ||
| 127 | + | if (ret.addr != NULL || !strncmp("String", type, 64)) { | |
| 128 | + | *( (char **) dst ) = ret.addr; | |
| 129 | + | } | |
| 130 | + | } | |
| 131 | + | ||
| 102 | 132 | #define INIT_ATOM_(atom) \ | |
| 103 | 133 | atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False); | |
| 104 | 134 | ||
| @@ -122,6 +152,11 @@ void win_init(win_t *win) | |||
| 122 | 152 | if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) | |
| 123 | 153 | error(0, 0, "No locale support"); | |
| 124 | 154 | ||
| 155 | + | get_xresource(e->dpy, "background", &WIN_BG_COLOR); | |
| 156 | + | get_xresource(e->dpy, "background", &BAR_FG_COLOR); | |
| 157 | + | get_xresource(e->dpy, "foreground", &BAR_BG_COLOR); | |
| 158 | + | get_xresource(e->dpy, "foreground", &SEL_COLOR); | |
| 159 | + | ||
| 125 | 160 | win_init_font(e, BAR_FONT); | |
| 126 | 161 | ||
| 127 | 162 | win_alloc_color(e, WIN_BG_COLOR, &win->bgcol); | |
| @@ -210,7 +245,7 @@ void win_open(win_t *win) | |||
| 210 | 245 | e->depth, InputOutput, e->vis, 0, NULL); | |
| 211 | 246 | if (win->xwin == None) | |
| 212 | 247 | error(EXIT_FAILURE, 0, "Error creating X window"); | |
| 213 | − | ||
| 248 | + | ||
| 214 | 249 | XSelectInput(e->dpy, win->xwin, | |
| 215 | 250 | ButtonReleaseMask | ButtonPressMask | KeyPressMask | | |
| 216 | 251 | PointerMotionMask | StructureNotifyMask); | |