commit d8d8254a7c029dd099577f2dfc564f2fe99aa07c
parent 28b1a4a1dabbf5d8832f69b107fae2389269dbbc
Author: jack-avery <47289484+jack-avery@users.noreply.github.com>
Date: Tue, 15 Apr 2025 00:58:31 -0400
[slock][patch][squares-password]Add squares-password patch
Diffstat:
2 files changed, 93 insertions(+), 0 deletions(-)
diff --git a/tools.suckless.org/slock/patches/squares/index.md b/tools.suckless.org/slock/patches/squares/index.md
@@ -15,6 +15,11 @@ Download
--------
* [slock-squares-1.5.diff](slock-squares-1.5.diff)
+Apply the following patch on top of the previous to have the number of squares equal the length of your current input (for responsive input):
+
+* [slock-squares-password-1.5.diff](slock-squares-password-1.5.diff)
+
Authors
-------
* bsuth - <bsuth701@gmail.com>
+* Jack Avery - <jack.avery.business@gmail.com> (input patch)
diff --git a/tools.suckless.org/slock/patches/squares/slock-squares-password-1.5.diff b/tools.suckless.org/slock/patches/squares/slock-squares-password-1.5.diff
@@ -0,0 +1,88 @@
+diff -up ./config.def.h ../config.def.h
+--- ./config.def.h 2025-04-15 00:55:12.710000000 -0400
++++ ../config.def.h 2025-04-15 00:55:54.790000000 -0400
+@@ -10,3 +10,6 @@ static const int failonclear = 1;
+
+ /* size of square in px */
+ static const int squaresize = 50;
++
++/* spacing between squares in px */
++static const int squarespacing = 10;
+diff -up ./slock.c ../slock.c
+--- ./slock.c 2025-04-15 00:55:12.710000000 -0400
++++ ../slock.c 2025-04-15 00:54:09.660000000 -0400
+@@ -130,7 +130,7 @@ gethash(void)
+
+ static void
+ draw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
+- unsigned int color)
++ unsigned int len, unsigned int color)
+ {
+ int screen, crtc;
+ XRRCrtcInfo* rrci;
+@@ -145,14 +145,19 @@ draw(Display *dpy, struct xrandr *rr, st
+ locks[screen]->rrsr,
+ locks[screen]->rrsr->crtcs[crtc]);
+ /* skip disabled crtc */
+- if (rrci->noutput > 0)
+- XFillRectangle(dpy,
+- locks[screen]->win,
+- locks[screen]->gc,
+- rrci->x + (rrci->width - squaresize) / 2,
+- rrci->y + (rrci->height - squaresize) / 2,
+- squaresize,
+- squaresize);
++ if (rrci->noutput > 0) {
++ if (len < 1)
++ len = 1;
++ int xoffset = (int) ((squaresize * len) + squarespacing * (len - 1)) / 2;
++ for (int i = 0; i < len; i++)
++ XFillRectangle(dpy,
++ locks[screen]->win,
++ locks[screen]->gc,
++ rrci->x - xoffset + ((rrci->width - squaresize) / 2 ) + ((squaresize + squarespacing) * i),
++ rrci->y + (rrci->height - squaresize) / 2,
++ squaresize,
++ squaresize);
++ }
+ XRRFreeCrtcInfo(rrci);
+ }
+ }
+@@ -172,7 +177,7 @@ readpw(Display *dpy, struct xrandr *rr,
+ {
+ XRRScreenChangeNotifyEvent *rre;
+ char buf[32], passwd[256], *inputhash;
+- int num, screen, running, failure, oldc;
++ int num, screen, running, failure;
+ unsigned int len, color;
+ KeySym ksym;
+ XEvent ev;
+@@ -180,7 +185,6 @@ readpw(Display *dpy, struct xrandr *rr,
+ len = 0;
+ running = 1;
+ failure = 0;
+- oldc = INIT;
+
+ while (running && !XNextEvent(dpy, &ev)) {
+ if (ev.type == KeyPress) {
+@@ -230,9 +234,8 @@ readpw(Display *dpy, struct xrandr *rr,
+ break;
+ }
+ color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT);
+- if (running && oldc != color) {
+- draw(dpy, rr, locks, nscreens, color);
+- oldc = color;
++ if (running) {
++ draw(dpy, rr, locks, nscreens, len, color);
+ }
+ } else if (rr->active && ev.type == rr->evbase + RRScreenChangeNotify) {
+ rre = (XRRScreenChangeNotifyEvent*)&ev;
+@@ -428,7 +431,7 @@ main(int argc, char **argv) {
+ }
+
+ /* draw the initial rectangle */
+- draw(dpy, &rr, locks, nscreens, INIT);
++ draw(dpy, &rr, locks, nscreens, 0, INIT);
+
+ /* everything is now blank. Wait for the correct password */
+ readpw(dpy, &rr, locks, nscreens, hash);