commit 4c905a9c07d1c63e9f9df7187e9e4c5806007920
parent 2cf80900dad28a63647bcd6488382cd243abe562
Author: bakkeby <bakkeby@gmail.com>
Date: Wed, 27 Nov 2019 08:42:00 +0100
Adding xresources patch
Diffstat:
8 files changed, 113 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
@@ -15,6 +15,8 @@ Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/)
### Changelog:
+2019-11-27 - Added xresources patch
+
2019-10-17 - Added capscolor, control clear, dpms, mediakeys, message, pam auth, quickcancel patches
2019-10-16 - Introduced [flexipatch-finalizer](https://github.com/bakkeby/flexipatch-finalizer)
@@ -51,4 +53,7 @@ Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/)
- [unlockscreen](https://tools.suckless.org/slock/patches/unlock_screen/)
- this patch keeps the screen unlocked, but keeps the input locked
- - that is, the screen is not affected by slock, but users will not be able to interact with the X session unless they enter the correct password
-\ No newline at end of file
+ - that is, the screen is not affected by slock, but users will not be able to interact with the X session unless they enter the correct password
+
+ - [xresources](https://tools.suckless.org/slock/patches/xresources/)
+ - this patch adds the ability to get colors via Xresources
+\ No newline at end of file
diff --git a/config.def.h b/config.def.h
@@ -11,8 +11,25 @@ static const char *colorname[NUMCOLS] = {
#endif // CAPSCOLOR_PATCH
#if PAMAUTH_PATCH
[PAM] = "#9400D3", /* waiting for PAM */
- #endif // CAPSCOLOR_PATCH
+ #endif // PAMAUTH_PATCH
+};
+
+#if XRESOURCES_PATCH
+/*
+ * Xresources preferences to load at startup
+ */
+ResourcePref resources[] = {
+ { "color0", STRING, &colorname[INIT] },
+ { "color4", STRING, &colorname[INPUT] },
+ { "color1", STRING, &colorname[FAILED] },
+ #if CAPSCOLOR_PATCH
+ { "color3", STRING, &colorname[CAPS] },
+ #endif // CAPSCOLOR_PATCH
+ #if PAMAUTH_PATCH
+ { "color5", STRING, &colorname[PAM] },
+ #endif // PAMAUTH_PATCH
};
+#endif // XRESOURCES_PATCH
/* treat a cleared input like a wrong password (color) */
static const int failonclear = 1;
diff --git a/patch/include.c b/patch/include.c
@@ -9,4 +9,8 @@
#if PAMAUTH_PATCH
#include "pamauth.c"
+#endif
+
+#if XRESOURCES_PATCH
+#include "xresources.c"
#endif
\ No newline at end of file
diff --git a/patch/include.h b/patch/include.h
@@ -1,4 +1,8 @@
/* Patches */
#if PAMAUTH_PATCH
#include "pamauth.h"
+#endif
+
+#if XRESOURCES_PATCH
+#include "xresources.h"
#endif
\ No newline at end of file
diff --git a/patch/xresources.c b/patch/xresources.c
@@ -0,0 +1,52 @@
+#include <math.h>
+
+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);
+}
diff --git a/patch/xresources.h b/patch/xresources.h
@@ -0,0 +1,17 @@
+#include <X11/Xresource.h>
+
+/* macros */
+#define LEN(a) (sizeof(a) / sizeof(a)[0])
+
+/* Xresources preferences */
+enum resource_type {
+ STRING = 0,
+ INTEGER = 1,
+ FLOAT = 2
+};
+
+typedef struct {
+ char *name;
+ enum resource_type type;
+ void *dst;
+} ResourcePref;
+\ No newline at end of file
diff --git a/patches.h b/patches.h
@@ -72,4 +72,9 @@
* unless they enter the correct password.
* https://tools.suckless.org/slock/patches/unlock_screen/
*/
-#define UNLOCKSCREEN_PATCH 0
-\ No newline at end of file
+#define UNLOCKSCREEN_PATCH 0
+
+/* This patch adds the ability to get colors via Xresources.
+ * https://tools.suckless.org/slock/patches/xresources/
+ */
+#define XRESOURCES_PATCH 0
diff --git a/slock.c b/slock.c
@@ -514,6 +514,10 @@ main(int argc, char **argv) {
if (setuid(duid) < 0)
die("slock: setuid: %s\n", strerror(errno));
+ #if XRESOURCES_PATCH
+ config_init(dpy);
+ #endif // XRESOURCES_PATCH
+
/* check for Xrandr support */
rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);