1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
From 809d3c01cfdc8c5bf7eb37e5d3ade59b0947cab3 Mon Sep 17 00:00:00 2001
From: catboomer <catb00mer@proton.me>
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 <X11/XF86keysym.h>
+
+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 <X11/XF86keysym.h>
+#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
|