summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2020-10-16 00:10:05 -0400
committerBenjamin Chausse <benjamin@chausse.xyz>2020-10-16 00:10:05 -0400
commitb5c81157067c256f16242b7488b1112e8fa13175 (patch)
tree5e1dca710f1a42f043dd38df42ff1512ec2a22de
parent35633d45672d14bd798c478c45d1a17064701aa9 (diff)
Apply patches
-rw-r--r--.gitignore10
-rw-r--r--config.def.h12
-rw-r--r--patches/slock-dpms-1.4.diff62
-rw-r--r--patches/slock-quickcancel-1.4.diff66
-rw-r--r--slock.c25
5 files changed, 172 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..aac3e79
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,10 @@
+# slock files
+config.h
+
+# C files
+*.o
+slock
+
+# patch files
+*.rej
+*.orig
diff --git a/config.def.h b/config.def.h
index 9855e21..d6f0cc3 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,12 +1,18 @@
/* user and group to drop privileges to */
static const char *user = "nobody";
-static const char *group = "nogroup";
+static const char *group = "nobody";
static const char *colorname[NUMCOLS] = {
[INIT] = "black", /* after initialization */
- [INPUT] = "#005577", /* during input */
- [FAILED] = "#CC3333", /* wrong password */
+ [INPUT] = "#66aabb", /* during input */
+ [FAILED] = "#cc3333", /* wrong password */
};
/* treat a cleared input like a wrong password (color) */
static const int failonclear = 1;
+
+/* time in seconds to cancel lock with mouse movement */
+static const int timetocancel = 4;
+
+/* time in seconds before the monitor shuts down */
+static const int monitortime = 5;
diff --git a/patches/slock-dpms-1.4.diff b/patches/slock-dpms-1.4.diff
new file mode 100644
index 0000000..027bbf7
--- /dev/null
+++ b/patches/slock-dpms-1.4.diff
@@ -0,0 +1,62 @@
+diff --git a/config.def.h b/config.def.h
+index 9855e21..d01bd38 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -10,3 +10,6 @@ static const char *colorname[NUMCOLS] = {
+
+ /* treat a cleared input like a wrong password (color) */
+ static const int failonclear = 1;
++
++/* time in seconds before the monitor shuts down */
++static const int monitortime = 5;
+diff --git a/slock.c b/slock.c
+index d2f0886..f65a43b 100644
+--- a/slock.c
++++ b/slock.c
+@@ -15,6 +15,7 @@
+ #include <unistd.h>
+ #include <sys/types.h>
+ #include <X11/extensions/Xrandr.h>
++#include <X11/extensions/dpms.h>
+ #include <X11/keysym.h>
+ #include <X11/Xlib.h>
+ #include <X11/Xutil.h>
+@@ -306,6 +307,7 @@ main(int argc, char **argv) {
+ const char *hash;
+ Display *dpy;
+ int s, nlocks, nscreens;
++ CARD16 standby, suspend, off;
+
+ ARGBEGIN {
+ case 'v':
+@@ -366,6 +368,20 @@ main(int argc, char **argv) {
+ if (nlocks != nscreens)
+ return 1;
+
++ /* DPMS magic to disable the monitor */
++ if (!DPMSCapable(dpy))
++ die("slock: DPMSCapable failed\n");
++ if (!DPMSEnable(dpy))
++ die("slock: DPMSEnable failed\n");
++ if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off))
++ die("slock: DPMSGetTimeouts failed\n");
++ if (!standby || !suspend || !off)
++ die("slock: at least one DPMS variable is zero\n");
++ if (!DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime))
++ die("slock: DPMSSetTimeouts failed\n");
++
++ XSync(dpy, 0);
++
+ /* run post-lock command */
+ if (argc > 0) {
+ switch (fork()) {
+@@ -383,5 +399,9 @@ main(int argc, char **argv) {
+ /* everything is now blank. Wait for the correct password */
+ readpw(dpy, &rr, locks, nscreens, hash);
+
++ /* reset DPMS values to inital ones */
++ DPMSSetTimeouts(dpy, standby, suspend, off);
++ XSync(dpy, 0);
++
+ return 0;
+ }
diff --git a/patches/slock-quickcancel-1.4.diff b/patches/slock-quickcancel-1.4.diff
new file mode 100644
index 0000000..f990806
--- /dev/null
+++ b/patches/slock-quickcancel-1.4.diff
@@ -0,0 +1,66 @@
+From e37f8981efe54bc620cb2f2280832cdab3959a32 Mon Sep 17 00:00:00 2001
+From: aleks <aleks.stier@icloud.com>
+Date: Thu, 10 Oct 2019 17:35:27 +0200
+Subject: [PATCH] Apply quickcancel
+
+Cancel slock by moving the mouse within a certain time-period after
+slock started. The time-period can be defined in seconds with the
+setting *timetocancel* in the config.h. This is useful if you forgot to
+disable `xautolock` during an activity that requires no input (e.g.
+reading text, watching video).
+---
+ config.def.h | 3 +++
+ slock.c | 5 +++++
+ 2 files changed, 8 insertions(+)
+
+diff --git a/config.def.h b/config.def.h
+index 9855e21..e0bf95a 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -10,3 +10,6 @@ static const char *colorname[NUMCOLS] = {
+
+ /* treat a cleared input like a wrong password (color) */
+ static const int failonclear = 1;
++
++/* time in seconds to cancel lock with mouse movement */
++static const int timetocancel = 4;
+diff --git a/slock.c b/slock.c
+index d2f0886..f7462ee 100644
+--- a/slock.c
++++ b/slock.c
+@@ -13,6 +13,7 @@
+ #include <stdio.h>
+ #include <string.h>
+ #include <unistd.h>
++#include <time.h>
+ #include <sys/types.h>
+ #include <X11/extensions/Xrandr.h>
+ #include <X11/keysym.h>
+@@ -24,6 +25,8 @@
+
+ char *argv0;
+
++static time_t locktime;
++
+ enum {
+ INIT,
+ INPUT,
+@@ -141,6 +144,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
+ oldc = INIT;
+
+ while (running && !XNextEvent(dpy, &ev)) {
++ running = !((time(NULL) - locktime < timetocancel) && (ev.type == MotionNotify));
+ if (ev.type == KeyPress) {
+ explicit_bzero(&buf, sizeof(buf));
+ num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0);
+@@ -268,6 +272,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
+ XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask);
+
+ XSelectInput(dpy, lock->root, SubstructureNotifyMask);
++ locktime = time(NULL);
+ return lock;
+ }
+
+--
+2.23.0
+
diff --git a/slock.c b/slock.c
index 5ae738c..c5fcc05 100644
--- a/slock.c
+++ b/slock.c
@@ -13,8 +13,10 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <time.h>
#include <sys/types.h>
#include <X11/extensions/Xrandr.h>
+#include <X11/extensions/dpms.h>
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -24,6 +26,8 @@
char *argv0;
+static time_t locktime;
+
enum {
INIT,
INPUT,
@@ -141,6 +145,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
oldc = INIT;
while (running && !XNextEvent(dpy, &ev)) {
+ running = !((time(NULL) - locktime < timetocancel) && (ev.type == MotionNotify));
if (ev.type == KeyPress) {
explicit_bzero(&buf, sizeof(buf));
num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0);
@@ -276,6 +281,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask);
XSelectInput(dpy, lock->root, SubstructureNotifyMask);
+ locktime = time(NULL);
return lock;
}
@@ -314,6 +320,7 @@ main(int argc, char **argv) {
const char *hash;
Display *dpy;
int s, nlocks, nscreens;
+ CARD16 standby, suspend, off;
ARGBEGIN {
case 'v':
@@ -374,6 +381,20 @@ main(int argc, char **argv) {
if (nlocks != nscreens)
return 1;
+ /* DPMS magic to disable the monitor */
+ if (!DPMSCapable(dpy))
+ die("slock: DPMSCapable failed\n");
+ if (!DPMSEnable(dpy))
+ die("slock: DPMSEnable failed\n");
+ if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off))
+ die("slock: DPMSGetTimeouts failed\n");
+ if (!standby || !suspend || !off)
+ die("slock: at least one DPMS variable is zero\n");
+ if (!DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime))
+ die("slock: DPMSSetTimeouts failed\n");
+
+ XSync(dpy, 0);
+
/* run post-lock command */
if (argc > 0) {
switch (fork()) {
@@ -391,5 +412,9 @@ main(int argc, char **argv) {
/* everything is now blank. Wait for the correct password */
readpw(dpy, &rr, locks, nscreens, hash);
+ /* reset DPMS values to inital ones */
+ DPMSSetTimeouts(dpy, standby, suspend, off);
+ XSync(dpy, 0);
+
return 0;
}