sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

slock-squares-password-1.5.diff (3022B)


      1 diff -up ./config.def.h ../config.def.h
      2 --- ./config.def.h	2025-04-15 00:55:12.710000000 -0400
      3 +++ ../config.def.h	2025-04-15 00:55:54.790000000 -0400
      4 @@ -10,3 +10,6 @@ static const int failonclear = 1;
      5  
      6  /* size of square in px */
      7  static const int squaresize = 50;
      8 +
      9 +/* spacing between squares in px */
     10 +static const int squarespacing = 10;
     11 diff -up ./slock.c ../slock.c
     12 --- ./slock.c	2025-04-15 00:55:12.710000000 -0400
     13 +++ ../slock.c	2025-04-15 00:54:09.660000000 -0400
     14 @@ -130,7 +130,7 @@ gethash(void)
     15  
     16  static void
     17  draw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
     18 -     unsigned int color)
     19 +     unsigned int len, unsigned int color)
     20  {
     21  	int screen, crtc;
     22  	XRRCrtcInfo* rrci;
     23 @@ -145,14 +145,19 @@ draw(Display *dpy, struct xrandr *rr, st
     24  				                      locks[screen]->rrsr,
     25  				                      locks[screen]->rrsr->crtcs[crtc]);
     26  				/* skip disabled crtc */
     27 -				if (rrci->noutput > 0)
     28 -					XFillRectangle(dpy,
     29 -					               locks[screen]->win,
     30 -					               locks[screen]->gc,
     31 -					               rrci->x + (rrci->width - squaresize) / 2,
     32 -					               rrci->y + (rrci->height - squaresize) / 2,
     33 -					               squaresize,
     34 -					               squaresize);
     35 +				if (rrci->noutput > 0) {
     36 +					if (len < 1)
     37 +						len = 1;
     38 +					int xoffset = (int) ((squaresize * len) + squarespacing * (len - 1)) / 2;
     39 +					for (int i = 0; i < len; i++)
     40 +						XFillRectangle(dpy,
     41 +						               locks[screen]->win,
     42 +						               locks[screen]->gc,
     43 +						               rrci->x - xoffset + ((rrci->width - squaresize) / 2 ) + ((squaresize + squarespacing) * i),
     44 +						               rrci->y + (rrci->height - squaresize) / 2,
     45 +						               squaresize,
     46 +						               squaresize);
     47 +				}
     48  				XRRFreeCrtcInfo(rrci);
     49  			}
     50  		}
     51 @@ -172,7 +177,7 @@ readpw(Display *dpy, struct xrandr *rr,
     52  {
     53  	XRRScreenChangeNotifyEvent *rre;
     54  	char buf[32], passwd[256], *inputhash;
     55 -	int num, screen, running, failure, oldc;
     56 +	int num, screen, running, failure;
     57  	unsigned int len, color;
     58  	KeySym ksym;
     59  	XEvent ev;
     60 @@ -180,7 +185,6 @@ readpw(Display *dpy, struct xrandr *rr,
     61  	len = 0;
     62  	running = 1;
     63  	failure = 0;
     64 -	oldc = INIT;
     65  
     66  	while (running && !XNextEvent(dpy, &ev)) {
     67  		if (ev.type == KeyPress) {
     68 @@ -230,9 +234,8 @@ readpw(Display *dpy, struct xrandr *rr,
     69  				break;
     70  			}
     71  			color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT);
     72 -			if (running && oldc != color) {
     73 -				draw(dpy, rr, locks, nscreens, color);
     74 -				oldc = color;
     75 +			if (running) {
     76 +				draw(dpy, rr, locks, nscreens, len, color);
     77  			}
     78  		} else if (rr->active && ev.type == rr->evbase + RRScreenChangeNotify) {
     79  			rre = (XRRScreenChangeNotifyEvent*)&ev;
     80 @@ -428,7 +431,7 @@ main(int argc, char **argv) {
     81  	}
     82  
     83  	/* draw the initial rectangle */
     84 -	draw(dpy, &rr, locks, nscreens, INIT);
     85 +	draw(dpy, &rr, locks, nscreens, 0, INIT);
     86  
     87  	/* everything is now blank. Wait for the correct password */
     88  	readpw(dpy, &rr, locks, nscreens, hash);