birdwm

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7bc93d29d62f1ccd954efeb8adcd858f608d8502
parent 7d159a7e234b7537314150e0d1ff383d803ed3a3
Author: grouse <bdmfegys@duck.com>
Date:   Sun, 24 Dec 2023 02:12:22 -0500

successfully patch slock xresouces patch

Diffstat:
Mslock/config.def.h | 16++++++++++++++--
Mslock/slock.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mslock/util.h | 3+++
3 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/slock/config.def.h b/slock/config.def.h @@ -4,12 +4,24 @@ static const char *colorname[NUMCOLS] = { [BACKGROUND] = "black", /* after initialization */ - [INIT] = "#2d2d2d", /* after initialization */ - [INPUT] = "#f4cdd4", /* during input */ +// [INIT] = "#2d2d2d", /* after initialization */ + [INIT] = "black", /* after initialization */ +// [INPUT] = "#f4cdd4", /* during input */ + [INPUT] = "#005577", /* during input */ [FAILED] = "#861a22", /* wrong password */ [CAPS] = "#ff00ff", /* CapsLock on */ }; +/* + * Xresources preferences to load at startup + */ +ResourcePref resources[] = { + { "color0", STRING, &colorname[INIT] }, + { "color4", STRING, &colorname[INPUT] }, + { "color1", STRING, &colorname[FAILED] }, + { "color3", STRING, &colorname[CAPS] }, +}; + /* treat a cleared input like a wrong password (color) */ static const int failonclear = 1; diff --git a/slock/slock.c b/slock/slock.c @@ -7,6 +7,7 @@ #include <ctype.h> #include <errno.h> +#include <math.h> #include <grp.h> #include <pwd.h> #include <stdarg.h> @@ -25,6 +26,7 @@ #include <X11/Xutil.h> #include <X11/Xft/Xft.h> #include <X11/XKBlib.h> +#include <X11/Xresource.h> #include "arg.h" #include "util.h" @@ -40,6 +42,19 @@ enum { NUMCOLS }; +/* Xresources preferences */ +enum resource_type { + STRING = 0, + INTEGER = 1, + FLOAT = 2 +}; + +typedef struct { + char *name; + enum resource_type type; + void *dst; +} ResourcePref; + #include "config.h" struct lock { @@ -377,6 +392,57 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) return NULL; } +int +resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst) +{ + char **sdst = dst; + int *idst = dst; + float *fdst = dst; + + char fullname[256]; + char fullclass[256]; + char *type; + XrmValue ret; + + snprintf(fullname, sizeof(fullname), "%s.%s", "slock", name); + snprintf(fullclass, sizeof(fullclass), "%s.%s", "Slock", name); + fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0'; + + XrmGetResource(db, fullname, fullclass, &type, &ret); + if (ret.addr == NULL || strncmp("String", type, 64)) + return 1; + + switch (rtype) { + case STRING: + *sdst = ret.addr; + break; + case INTEGER: + *idst = strtoul(ret.addr, NULL, 10); + break; + case FLOAT: + *fdst = strtof(ret.addr, NULL); + break; + } + return 0; +} + +void +config_init(Display *dpy) +{ + char *resm; + XrmDatabase db; + ResourcePref *p; + + XrmInitialize(); + resm = XResourceManagerString(dpy); + if (!resm) + return; + + db = XrmGetStringDatabase(resm); + for (p = resources; p < resources + LEN(resources); p++) + resource_load(db, p->name, p->type, p->dst); +} + static void usage(void) { @@ -435,6 +501,8 @@ main(int argc, char **argv) { if (setuid(duid) < 0) die("slock: setuid: %s\n", strerror(errno)); + config_init(dpy); + /* check for Xrandr support */ rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase); diff --git a/slock/util.h b/slock/util.h @@ -1,2 +1,5 @@ +/* macros */ +#define LEN(a) (sizeof(a) / sizeof(a)[0]) + #undef explicit_bzero void explicit_bzero(void *, size_t);