From 2445d75b5db8a16f1d98c91bf0fd767a4cd6bbe7 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sun, 26 Jan 2020 16:16:38 +0100 Subject: [PATCH] Fix bug in DPMS patch + moved patches.h to patches.def.h to match that of config --- .gitignore | 1 + Makefile | 6 +++++- patch/dpms.c | 9 --------- patch/include.c | 4 ---- patches.h => patches.def.h | 0 slock.c | 19 ++++++++++--------- 6 files changed, 16 insertions(+), 23 deletions(-) delete mode 100644 patch/dpms.c rename patches.h => patches.def.h (100%) diff --git a/.gitignore b/.gitignore index f913c1b10f339ec11362e24d1c80370f41380fb8..88d2ee6470473edfd79e1181a89381cd293f2172 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.o dwm config.h +patches.h diff --git a/Makefile b/Makefile index f4ffbb7e0263da9d91a733611955f8fbf764d741..87dfa2b159ccb8928c94324c9df4b2c9daaaf8f8 100644 --- a/Makefile +++ b/Makefile @@ -18,12 +18,16 @@ options: @echo CC $< @${CC} -c ${CFLAGS} $< -${OBJ}: config.h config.mk arg.h util.h +${OBJ}: config.h config.mk arg.h util.h patches.h config.h: @echo creating $@ from config.def.h @cp config.def.h $@ +patches.h: + @echo creating $@ from patches.def.h + @cp patches.def.h $@ + slock: ${OBJ} @echo CC -o $@ @${CC} -o $@ ${OBJ} ${LDFLAGS} diff --git a/patch/dpms.c b/patch/dpms.c deleted file mode 100644 index b5fc267adf71395c06c31d2db894dfee59f4655d..0000000000000000000000000000000000000000 --- a/patch/dpms.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -static void -monitorreset(Display* dpy, CARD16 standby, CARD16 suspend, CARD16 off) -{ - DPMSSetTimeouts(dpy, standby, suspend, off); - DPMSForceLevel(dpy, DPMSModeOn); - XFlush(dpy); -} \ No newline at end of file diff --git a/patch/include.c b/patch/include.c index 760b3acaec6879085e5ef73b50106fa5e855607b..7bd5cd04881a4be5ca8559239852476d06f3309f 100644 --- a/patch/include.c +++ b/patch/include.c @@ -1,8 +1,4 @@ /* Patches */ -#if DPMS_PATCH -#include "dpms.c" -#endif - #if MESSAGE_PATCH #include "message.c" #endif diff --git a/patches.h b/patches.def.h similarity index 100% rename from patches.h rename to patches.def.h diff --git a/slock.c b/slock.c index c0f8251b4282f5176aeac1e756b40b262578aeeb..a9a22c7c25ce539f818c5dbb611ca6df090d7818 100644 --- a/slock.c +++ b/slock.c @@ -29,6 +29,9 @@ #if QUICKCANCEL_PATCH #include #endif // QUICKCANCEL_PATCH +#if DPMS_PATCH +#include +#endif // DPMS_PATCH #include "arg.h" #include "util.h" @@ -542,7 +545,7 @@ main(int argc, char **argv) { return 1; #if DPMS_PATCH - /* DPMS-magic to disable the monitor */ + /* DPMS magic to disable the monitor */ if (!DPMSCapable(dpy)) die("slock: DPMSCapable failed\n"); if (!DPMSEnable(dpy)) @@ -550,11 +553,11 @@ main(int argc, char **argv) { if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off)) die("slock: DPMSGetTimeouts failed\n"); if (!standby || !suspend || !off) - /* set values if there arent some */ - standby = suspend = off = 300; + die("slock: at least one DPMS variable is zero\n"); + if (!DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime)) + die("slock: DPMSSetTimeouts failed\n"); - DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime); - XFlush(dpy); + XSync(dpy, 0); #endif // DPMS_PATCH /* run post-lock command */ @@ -563,9 +566,6 @@ main(int argc, char **argv) { case -1: die("slock: fork failed: %s\n", strerror(errno)); case 0: - #if DPMS_PATCH - monitorreset(dpy, standby, suspend, off); - #endif // DPMS_PATCH if (close(ConnectionNumber(dpy)) < 0) die("slock: close: %s\n", strerror(errno)); execvp(argv[0], argv); @@ -578,7 +578,8 @@ main(int argc, char **argv) { readpw(dpy, &rr, locks, nscreens, hash); #if DPMS_PATCH /* reset DPMS values to inital ones */ - monitorreset(dpy, standby, suspend, off); + DPMSSetTimeouts(dpy, standby, suspend, off); + XSync(dpy, 0); #endif // DPMS_PATCH return 0;