slock-passthrough-20240812-809d3c0.diff (2918B)
1 From 809d3c01cfdc8c5bf7eb37e5d3ade59b0947cab3 Mon Sep 17 00:00:00 2001 2 From: catboomer <catb00mer@proton.me> 3 Date: Mon, 12 Aug 2024 17:55:30 -0500 4 Subject: [PATCH] [PATCH] passthrough: adds table to config.h to permit certain 5 keys to pass through slock 6 7 --- 8 config.def.h | 15 +++++++++++++++ 9 slock.c | 28 +++++++++++++++++++++++++++- 10 2 files changed, 42 insertions(+), 1 deletion(-) 11 12 diff --git a/config.def.h b/config.def.h 13 index 9855e21..5b2ff78 100644 14 --- a/config.def.h 15 +++ b/config.def.h 16 @@ -10,3 +10,18 @@ static const char *colorname[NUMCOLS] = { 17 18 /* treat a cleared input like a wrong password (color) */ 19 static const int failonclear = 1; 20 + 21 +#include <X11/XF86keysym.h> 22 + 23 +static const Passthrough passthroughs[] = { 24 + /* Modifier Key */ 25 + { 0, XF86XK_AudioRaiseVolume }, 26 + { 0, XF86XK_AudioLowerVolume }, 27 + { 0, XF86XK_AudioMute }, 28 + { 0, XF86XK_AudioPause }, 29 + { 0, XF86XK_AudioStop }, 30 + { 0, XF86XK_AudioNext }, 31 + { 0, XF86XK_AudioPrev }, 32 + { 0, XF86XK_MonBrightnessUp }, 33 + { 0, XF86XK_MonBrightnessDown }, 34 +}; 35 diff --git a/slock.c b/slock.c 36 index 5ae738c..522a226 100644 37 --- a/slock.c 38 +++ b/slock.c 39 @@ -22,6 +22,11 @@ 40 #include "arg.h" 41 #include "util.h" 42 43 +#include <X11/XF86keysym.h> 44 +#define LENGTH(X) (sizeof X / sizeof X[0]) 45 +#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) 46 + 47 +static unsigned int numlockmask = 0; 48 char *argv0; 49 50 enum { 51 @@ -31,6 +36,11 @@ enum { 52 NUMCOLS 53 }; 54 55 +typedef struct { 56 + unsigned int mod; 57 + KeySym keysym; 58 +} Passthrough; 59 + 60 struct lock { 61 int screen; 62 Window root, win; 63 @@ -130,7 +140,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, 64 { 65 XRRScreenChangeNotifyEvent *rre; 66 char buf[32], passwd[256], *inputhash; 67 - int num, screen, running, failure, oldc; 68 + int num, screen, running, failure, oldc, i, passing; 69 unsigned int len, color; 70 KeySym ksym; 71 XEvent ev; 72 @@ -156,6 +166,20 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, 73 IsPFKey(ksym) || 74 IsPrivateKeypadKey(ksym)) 75 continue; 76 + 77 + passing = 0; 78 + for (i = 0; i < LENGTH(passthroughs); i++) { 79 + if (ksym == passthroughs[i].keysym && 80 + CLEANMASK(passthroughs[i].mod) == CLEANMASK(ev.xkey.state)) { 81 + passing = 1; 82 + XSendEvent(dpy, DefaultRootWindow(dpy), True, KeyPressMask, &ev); 83 + break; 84 + } 85 + } 86 + 87 + if(passing) 88 + continue; 89 + 90 switch (ksym) { 91 case XK_Return: 92 passwd[len] = '\0'; 93 @@ -184,6 +208,8 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, 94 (len + num < sizeof(passwd))) { 95 memcpy(passwd + len, buf, num); 96 len += num; 97 + } else { 98 + continue; /* Don't trigger fail screen when pressing control characters */ 99 } 100 break; 101 } 102 -- 103 2.46.0 104