[wiki] [sites] [slock][squares]: add squares patch || bsuth

From: <git_AT_suckless.org>
Date: Tue, 27 Dec 2022 07:36:13 +0100

commit 0d0c051ff1bef1480c9cd00e1126c5fe988dc892
Author: bsuth <bsuth701_AT_gmail.com>
Date: Tue Dec 27 15:33:19 2022 +0900

    [slock][squares]: add squares patch
    
    Instead of changing the color of the entire screen to indicate the current lock
    state, draw centered squares on each monitor and change the square colors.
    
    This patch requires xrandr to be active and otherwise defaults to the original
    slock behavior.

diff --git a/tools.suckless.org/slock/patches/squares/index.md b/tools.suckless.org/slock/patches/squares/index.md
new file mode 100644
index 00000000..43c75e85
--- /dev/null
+++ b/tools.suckless.org/slock/patches/squares/index.md
_AT_@ -0,0 +1,20 @@
+Squares
+=======
+
+Description
+-----------
+Instead of changing the color of the entire screen to indicate the current lock
+state, draw centered squares on each monitor and change the square colors.
+
+This patch requires xrandr to be active and otherwise defaults to the original
+slock behavior.
+
+Use `squaresize` in `config.def.h` to set the size of the square (in px).
+
+Download
+--------
+* [slock-squares-1.5.diff](slock-squares-1.5.diff)
+
+Authors
+-------
+* bsuth - <bsuth701_AT_gmail.com>
diff --git a/tools.suckless.org/slock/patches/squares/slock-squares-1.5.diff b/tools.suckless.org/slock/patches/squares/slock-squares-1.5.diff
new file mode 100644
index 00000000..e9e9ad0d
--- /dev/null
+++ b/tools.suckless.org/slock/patches/squares/slock-squares-1.5.diff
_AT_@ -0,0 +1,157 @@
+From 2f6938b87a09abcd41fd6792a40b0bd7b088f41a Mon Sep 17 00:00:00 2001
+From: bsuth <bsuth701_AT_gmail.com>
+Date: Tue, 27 Dec 2022 12:44:23 +0900
+Subject: [PATCH] Use centered squares to indicate lock state
+
+Instead of changing the color of the entire screen to indicate the
+current lock state, draw centered squares on each monitor and change the
+square colors.
+
+This patch requires xrandr to be active and otherwise defaults to the
+original slock behavior.
+---
+ config.def.h | 6 +++++-
+ slock.c | 58 +++++++++++++++++++++++++++++++++++++++++++++-------
+ 2 files changed, 56 insertions(+), 8 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 9855e21..e7106fb 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -3,10 +3,14 @@ static const char *user = "nobody";
+ static const char *group = "nogroup";
+
+ static const char *colorname[NUMCOLS] = {
+- [INIT] = "black", /* after initialization */
++ [BG] = "black", /* background */
++ [INIT] = "#4f525c", /* after initialization */
+ [INPUT] = "#005577", /* during input */
+ [FAILED] = "#CC3333", /* wrong password */
+ };
+
+ /* treat a cleared input like a wrong password (color) */
+ static const int failonclear = 1;
++
++/* size of square in px */
++static const int squaresize = 50;
+diff --git a/slock.c b/slock.c
+index 5ae738c..0750768 100644
+--- a/slock.c
++++ b/slock.c
+_AT_@ -25,6 +25,7 @@
+ char *argv0;
+
+ enum {
++ BG,
+ INIT,
+ INPUT,
+ FAILED,
+_AT_@ -36,6 +37,8 @@ struct lock {
+ Window root, win;
+ Pixmap pmap;
+ unsigned long colors[NUMCOLS];
++ GC gc;
++ XRRScreenResources *rrsr;
+ };
+
+ struct xrandr {
+_AT_@ -124,6 +127,44 @@ gethash(void)
+ return hash;
+ }
+
++static void
++draw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
++ unsigned int color)
++{
++ int screen, crtc;
++ XRRCrtcInfo* rrci;
++
++ if (rr->active) {
++ for (screen = 0; screen < nscreens; screen++) {
++ XSetWindowBackground(dpy, locks[screen]->win,locks[screen]->colors[BG]);
++ XClearWindow(dpy, locks[screen]->win);
++ XSetForeground(dpy, locks[screen]->gc, locks[screen]->colors[color]);
++ for (crtc = 0; crtc < locks[screen]->rrsr->ncrtc; ++crtc) {
++ rrci = XRRGetCrtcInfo(dpy,
++ 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);
++ XRRFreeCrtcInfo(rrci);
++ }
++ }
++ } else {
++ for (screen = 0; screen < nscreens; screen++) {
++ XSetWindowBackground(dpy,
++ locks[screen]->win,
++ locks[screen]->colors[color]);
++ XClearWindow(dpy, locks[screen]->win);
++ }
++ }
++}
++
+ static void
+ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
+ const char *hash)
+_AT_@ -189,12 +230,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
+ }
+ color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT);
+ if (running && oldc != color) {
+- for (screen = 0; screen < nscreens; screen++) {
+- XSetWindowBackground(dpy,
+- locks[screen]->win,
+- locks[screen]->colors[color]);
+- XClearWindow(dpy, locks[screen]->win);
+- }
++ draw(dpy, rr, locks, nscreens, color);
+ oldc = color;
+ }
+ } else if (rr->active && ev.type == rr->evbase + RRScreenChangeNotify) {
+_AT_@ -228,6 +264,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
+ XColor color, dummy;
+ XSetWindowAttributes wa;
+ Cursor invisible;
++ XGCValues gcvalues;
+
+ if (dpy == NULL || screen < 0 || !(lock = malloc(sizeof(struct lock))))
+ return NULL;
+_AT_@ -243,7 +280,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
+
+ /* init */
+ wa.override_redirect = 1;
+- wa.background_pixel = lock->colors[INIT];
++ wa.background_pixel = lock->colors[BG];
+ lock->win = XCreateWindow(dpy, lock->root, 0, 0,
+ DisplayWidth(dpy, lock->screen),
+ DisplayHeight(dpy, lock->screen),
+_AT_@ -255,6 +292,10 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
+ invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap,
+ &color, &color, 0, 0);
+ XDefineCursor(dpy, lock->win, invisible);
++ lock->gc = XCreateGC(dpy, lock->win, 0, &gcvalues);
++ XSetForeground(dpy, lock->gc, lock->colors[INIT]);
++ if (rr->active)
++ lock->rrsr = XRRGetScreenResourcesCurrent(dpy, lock->root);
+
+ /* Try to grab mouse pointer *and* keyboard for 600ms, else fail the lock */
+ for (i = 0, ptgrab = kbgrab = -1; i < 6; i++) {
+_AT_@ -388,6 +429,9 @@ main(int argc, char **argv) {
+ }
+ }
+
++ /* draw the initial rectangle */
++ draw(dpy, &rr, locks, nscreens, INIT);
++
+ /* everything is now blank. Wait for the correct password */
+ readpw(dpy, &rr, locks, nscreens, hash);
+
+--
+2.39.0
+
Received on Tue Dec 27 2022 - 07:36:13 CET

This archive was generated by hypermail 2.3.0 : Tue Dec 27 2022 - 07:36:48 CET