commit 9e6e305e93a78f36f987d9a47fa3820a6d53b20f
parent 4748c4de8b1610d8f1c90ce7b62512246cb7ce39
Author: Markus Hanetzok <markus@hanetzok.net>
Date: Fri, 10 Oct 2025 14:38:35 +0200
apply auto-timeout
Diffstat:
3 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -3,10 +3,20 @@ static const char *user = "nobody";
static const char *group = "nogroup";
static const char *colorname[NUMCOLS] = {
- [INIT] = "black", /* after initialization */
- [INPUT] = "#005577", /* during input */
- [FAILED] = "#CC3333", /* wrong password */
+ [INIT] = "#000000", /* after initialization */
+ [INPUT] = "#83A598", /* during input */
+ [FAILED] = "#CC241D", /* wrong password */
};
/* treat a cleared input like a wrong password (color) */
static const int failonclear = 1;
+
+
+/* Patch: auto-timeout */
+/* should [command] be run only once? */
+static const int runonce = 0;
+/* length of time (seconds) until [command] is executed */
+static const int timeoffset = 30;
+/* command to be run after [timeoffset] seconds has passed */
+static const char *command = "/usr/bin/xset dpms force off";
+
diff --git a/config.mk b/config.mk
@@ -27,3 +27,5 @@ COMPATSRC = explicit_bzero.c
#CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_NETBSD_SOURCE
# On OpenBSD set COMPATSRC to empty
#COMPATSRC =
+ # compiler and linker
+CC = cc -pthread
diff --git a/slock.c b/slock.c
@@ -20,6 +20,10 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
+/*POSIX threading for auto-timeout*/
+#include <pthread.h>
+#include <time.h>
+
#include "arg.h"
#include "util.h"
@@ -223,6 +227,18 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
}
}
+void *timeoutCommand(void *args)
+{
+ int runflag=0;
+ while (!runonce || !runflag)
+ {
+ sleep(timeoffset);
+ runflag = 1;
+ system(command);
+ }
+ return args;
+}
+
static struct lock *
lockscreen(Display *dpy, struct xrandr *rr, int screen)
{
@@ -389,6 +405,10 @@ main(int argc, char **argv) {
}
}
+ /*Start the auto-timeout command in its own thread*/
+ pthread_t thread_id;
+ pthread_create(&thread_id, NULL, timeoutCommand, NULL);
+
/* everything is now blank. Wait for the correct password */
readpw(dpy, &rr, locks, nscreens, hash);