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.

Unlike the "Unlock Screen" patch, this uses an arg (-u) to enable the
unlocked screen functionality, and the mouse will remain hidden. The
primary use case for this would be in a script to spawn a screensaver
when the screen is locked. AFAIK the existing arg parsing system does
not support continuing execution if a flag is set, so sorry for the
messy arg handling.
---
 slock.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/slock.c b/slock.c
index b5a9b04..1cd4995 100644
--- a/slock.c
+++ b/slock.c
@@ -9,6 +9,7 @@
 #include <grp.h>
 #include <pwd.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -45,6 +46,8 @@ struct xrandr {
        int errbase;
 };
 
+bool visual_unlock = false;
+
 #include "config.h"
 
 static void
@@ -272,7 +275,8 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
 
                /* input is grabbed: we can lock the screen */
                if (ptgrab == GrabSuccess && kbgrab == GrabSuccess) {
-                       XMapRaised(dpy, lock->win);
+                       if (!visual_unlock)
+                               XMapRaised(dpy, lock->win);
                        if (rr->active)
                                XRRSelectInput(dpy, lock->win, 
RRScreenChangeNotifyMask);
 
@@ -301,7 +305,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
 static void
 usage(void)
 {
-       die("usage: slock [-v] [cmd [arg ...]]\n");
+       die("usage: slock [-u] [-v] [cmd [arg ...]]\n");
 }
 
 int
@@ -316,13 +320,17 @@ main(int argc, char **argv) {
        Display *dpy;
        int s, nlocks, nscreens;
 
-       ARGBEGIN {
-       case 'v':
-               puts("slock-"VERSION);
-               return 0;
-       default:
-               usage();
-       } ARGEND
+       if (argc > 1 && strcmp(argv[1], "-u") == 0) {
+               visual_unlock = true;
+       } else {
+               ARGBEGIN {
+               case 'v':
+                       puts("slock-"VERSION);
+                       return 0;
+               default:
+                       usage();
+               } ARGEND
+       }
 
        /* validate drop-user and -group */
        errno = 0;
-- 
2.51.0


Reply via email to