| slock-auto-timeout.1.5.diff - sites - public wiki contents of suckless.org | |
| git clone git://git.suckless.org/sites | |
| Log | |
| Files | |
| Refs | |
| --- | |
| slock-auto-timeout.1.5.diff (2417B) | |
| --- | |
| 1 From 4abaf79e90a54c645fbd1a8439a976ee2ba5dde7 Mon Sep 17 00:00:00 2001 | |
| 2 From: Karsaell <[email protected]> | |
| 3 Date: Wed, 5 Oct 2022 14:25:12 +0200 | |
| 4 Subject: [PATCH] [patch][auto-timeout] updated patch autotimeout | |
| 5 | |
| 6 Previous patch had an infinite loop without sleep() | |
| 7 causing slock to run at 100% CPU | |
| 8 (Noticed it because my laptop's fan started a few seconds after slock) | |
| 9 | |
| 10 Now the timeout and its command are run in a separate thread | |
| 11 This adds a dependency to pthread at compile time | |
| 12 (not sure if this can be an issue ?) | |
| 13 --- | |
| 14 config.def.h | 8 ++++++++ | |
| 15 config.mk | 2 +- | |
| 16 slock.c | 20 ++++++++++++++++++++ | |
| 17 3 files changed, 29 insertions(+), 1 deletion(-) | |
| 18 | |
| 19 diff --git a/config.def.h b/config.def.h | |
| 20 index 9855e21..a1179a8 100644 | |
| 21 --- a/config.def.h | |
| 22 +++ b/config.def.h | |
| 23 @@ -10,3 +10,11 @@ static const char *colorname[NUMCOLS] = { | |
| 24 | |
| 25 /* treat a cleared input like a wrong password (color) */ | |
| 26 static const int failonclear = 1; | |
| 27 + | |
| 28 +/* Patch: auto-timeout */ | |
| 29 +/* should [command] be run only once? */ | |
| 30 +static const int runonce = 0; | |
| 31 +/* length of time (seconds) until [command] is executed */ | |
| 32 +static const int timeoffset = 30; | |
| 33 +/* command to be run after [timeoffset] seconds has passed */ | |
| 34 +static const char *command = "/usr/bin/xset dpms force off"; | |
| 35 diff --git a/config.mk b/config.mk | |
| 36 index 1e1ca45..8955075 100644 | |
| 37 --- a/config.mk | |
| 38 +++ b/config.mk | |
| 39 @@ -29,4 +29,4 @@ COMPATSRC = explicit_bzero.c | |
| 40 #COMPATSRC = | |
| 41 | |
| 42 # compiler and linker | |
| 43 -CC = cc | |
| 44 +CC = cc -pthread | |
| 45 diff --git a/slock.c b/slock.c | |
| 46 index 5ae738c..c56c944 100644 | |
| 47 --- a/slock.c | |
| 48 +++ b/slock.c | |
| 49 @@ -19,6 +19,10 @@ | |
| 50 #include <X11/Xlib.h> | |
| 51 #include <X11/Xutil.h> | |
| 52 | |
| 53 +/*POSIX threading for auto-timeout*/ | |
| 54 +#include <pthread.h> | |
| 55 +#include <time.h> | |
| 56 + | |
| 57 #include "arg.h" | |
| 58 #include "util.h" | |
| 59 | |
| 60 @@ -219,6 +223,18 @@ readpw(Display *dpy, struct xrandr *rr, struct lock… | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 +void *timeoutCommand(void *args) | |
| 65 +{ | |
| 66 + int runflag=0; | |
| 67 + while (!runonce || !runflag) | |
| 68 + { | |
| 69 + sleep(timeoffset); | |
| 70 + runflag = 1; | |
| 71 + system(command); | |
| 72 + } | |
| 73 + return args; | |
| 74 +} | |
| 75 + | |
| 76 static struct lock * | |
| 77 lockscreen(Display *dpy, struct xrandr *rr, int screen) | |
| 78 { | |
| 79 @@ -388,6 +404,10 @@ main(int argc, char **argv) { | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 + /*Start the auto-timeout command in its own thread*/ | |
| 84 + pthread_t thread_id; | |
| 85 + pthread_create(&thread_id, NULL, timeoutCommand, NULL); | |
| 86 + | |
| 87 /* everything is now blank. Wait for the correct password */ | |
| 88 readpw(dpy, &rr, locks, nscreens, hash); | |
| 89 | |
| 90 -- | |
| 91 2.30.2 | |
| 92 |