diff options
author | noamcore <146050u54@gmail.com> | 2018-10-23 14:26:26 -0300 |
---|---|---|
committer | Bert Münnich <ber.t@posteo.de> | 2019-01-23 19:53:39 +0100 |
commit | 4853e17b831c4ce7021fb314eaa4dafded024d90 (patch) | |
tree | f3f539c1a6a042698f2c773acee984beefeab9ba | |
parent | b83d4fa1bfbd7440ba4dd18bdc04b409db7114c9 (diff) |
Add Xresources capability
-rw-r--r-- | config.def.h | 10 | ||||
-rw-r--r-- | window.c | 37 |
2 files changed, 41 insertions, 6 deletions
diff --git a/config.def.h b/config.def.h index 58e728e..c7a2389 100644 --- a/config.def.h +++ b/config.def.h @@ -14,11 +14,11 @@ static const char * const BAR_FONT = "monospace:size=8"; /* colors: * (see X(7) section "COLOR NAMES" for valid values) */ -static const char * const WIN_BG_COLOR = "#555555"; -static const char * const WIN_FS_COLOR = "#000000"; -static const char * const SEL_COLOR = "#EEEEEE"; -static const char * const BAR_BG_COLOR = "#222222"; -static const char * const BAR_FG_COLOR = "#EEEEEE"; +static char const * WIN_BG_COLOR = "#555555"; +static char const * WIN_FS_COLOR = "#000000"; +static char const * SEL_COLOR = "#EEEEEE"; +static char const * BAR_BG_COLOR = "#222222"; +static char const * BAR_FG_COLOR = "#EEEEEE"; #endif #ifdef _IMAGE_CONFIG @@ -27,6 +27,7 @@ #include <locale.h> #include <X11/cursorfont.h> #include <X11/Xatom.h> +#include <X11/Xresource.h> enum { H_TEXT_PAD = 5, @@ -99,6 +100,35 @@ void win_check_wm_support(Display *dpy, Window root) } } +void get_xresource(Display *dpy, const char* rsc, const void* dst) +{ + char *type; + XrmValue ret; + XrmDatabase db; + char fullname[256]; + char *resource_manager; + + XrmInitialize(); + resource_manager = XResourceManagerString(dpy); + + if (resource_manager == NULL) + return; + + db = XrmGetStringDatabase(resource_manager); + + if (db == NULL) + return; + + snprintf(fullname, sizeof(fullname), ".%s", rsc); + fullname[sizeof(fullname) - 1] = '\0'; + + XrmGetResource(db, fullname, "String", &type, &ret); + + if (ret.addr != NULL || !strncmp("String", type, 64)) { + *( (char **) dst ) = ret.addr; + } +} + #define INIT_ATOM_(atom) \ atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False); @@ -122,6 +152,11 @@ void win_init(win_t *win) if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) error(0, 0, "No locale support"); + get_xresource(e->dpy, "background", &WIN_BG_COLOR); + get_xresource(e->dpy, "background", &BAR_FG_COLOR); + get_xresource(e->dpy, "foreground", &BAR_BG_COLOR); + get_xresource(e->dpy, "foreground", &SEL_COLOR); + win_init_font(e, BAR_FONT); win_alloc_color(e, WIN_BG_COLOR, &win->bgcol); @@ -210,7 +245,7 @@ void win_open(win_t *win) e->depth, InputOutput, e->vis, 0, NULL); if (win->xwin == None) error(EXIT_FAILURE, 0, "Error creating X window"); - + XSelectInput(e->dpy, win->xwin, ButtonReleaseMask | ButtonPressMask | KeyPressMask | PointerMotionMask | StructureNotifyMask); |