From 809d3c01cfdc8c5bf7eb37e5d3ade59b0947cab3 Mon Sep 17 00:00:00 2001 From: catboomer Date: Mon, 12 Aug 2024 17:55:30 -0500 Subject: [PATCH] [PATCH] passthrough: adds table to config.h to permit certain keys to pass through slock --- config.def.h | 15 +++++++++++++++ slock.c | 28 +++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 9855e21..5b2ff78 100644 --- a/config.def.h +++ b/config.def.h @@ -10,3 +10,18 @@ static const char *colorname[NUMCOLS] = { /* treat a cleared input like a wrong password (color) */ static const int failonclear = 1; + +#include + +static const Passthrough passthroughs[] = { + /* Modifier Key */ + { 0, XF86XK_AudioRaiseVolume }, + { 0, XF86XK_AudioLowerVolume }, + { 0, XF86XK_AudioMute }, + { 0, XF86XK_AudioPause }, + { 0, XF86XK_AudioStop }, + { 0, XF86XK_AudioNext }, + { 0, XF86XK_AudioPrev }, + { 0, XF86XK_MonBrightnessUp }, + { 0, XF86XK_MonBrightnessDown }, +}; diff --git a/slock.c b/slock.c index 5ae738c..522a226 100644 --- a/slock.c +++ b/slock.c @@ -22,6 +22,11 @@ #include "arg.h" #include "util.h" +#include +#define LENGTH(X) (sizeof X / sizeof X[0]) +#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) + +static unsigned int numlockmask = 0; char *argv0; enum { @@ -31,6 +36,11 @@ enum { NUMCOLS }; +typedef struct { + unsigned int mod; + KeySym keysym; +} Passthrough; + struct lock { int screen; Window root, win; @@ -130,7 +140,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, { XRRScreenChangeNotifyEvent *rre; char buf[32], passwd[256], *inputhash; - int num, screen, running, failure, oldc; + int num, screen, running, failure, oldc, i, passing; unsigned int len, color; KeySym ksym; XEvent ev; @@ -156,6 +166,20 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, IsPFKey(ksym) || IsPrivateKeypadKey(ksym)) continue; + + passing = 0; + for (i = 0; i < LENGTH(passthroughs); i++) { + if (ksym == passthroughs[i].keysym && + CLEANMASK(passthroughs[i].mod) == CLEANMASK(ev.xkey.state)) { + passing = 1; + XSendEvent(dpy, DefaultRootWindow(dpy), True, KeyPressMask, &ev); + break; + } + } + + if(passing) + continue; + switch (ksym) { case XK_Return: passwd[len] = '\0'; @@ -184,6 +208,8 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, (len + num < sizeof(passwd))) { memcpy(passwd + len, buf, num); len += num; + } else { + continue; /* Don't trigger fail screen when pressing control characters */ } break; } -- 2.46.0