X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=slock.c;h=68e813f4e86041ed7be45492771adcdfcb7d9187;hb=10d4e479c5f6d91bf86e15be3a12c6b09c9808be;hp=6502c86157ec2022f8ca2a3782a5e4880412000a;hpb=f5ef1b8eb5555da11e81d92d8d05acd4aba1ef40;p=slock.git diff --git a/slock.c b/slock.c index 6502c86..68e813f 100644 --- a/slock.c +++ b/slock.c @@ -26,7 +26,7 @@ enum { INIT, INPUT, - EMPTY, + FAILED, NUMCOLS }; @@ -42,6 +42,7 @@ typedef struct { static Lock **locks; static int nscreens; static Bool running = True; +static Bool failure = False; static Bool rr; static int rrevbase; static int rrerrbase; @@ -132,7 +133,7 @@ readpw(Display *dpy, const char *pws) while (running && !XNextEvent(dpy, &ev)) { if (ev.type == KeyPress) { buf[0] = 0; - num = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, 0); + num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0); if (IsKeypadKey(ksym)) { if (ksym == XK_KP_Enter) ksym = XK_Return; @@ -153,8 +154,10 @@ readpw(Display *dpy, const char *pws) #else running = !!strcmp(crypt(passwd, pws), pws); #endif - if (running) + if (running) { XBell(dpy, 100); + failure = True; + } len = 0; break; case XK_Escape: @@ -165,7 +168,7 @@ readpw(Display *dpy, const char *pws) --len; break; default: - if (num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) { + if (num && !iscntrl((int) buf[0]) && (len + num < sizeof(passwd))) { memcpy(passwd + len, buf, num); len += num; } @@ -178,7 +181,7 @@ readpw(Display *dpy, const char *pws) } } else if (llen != 0 && len == 0) { for (screen = 0; screen < nscreens; screen++) { - XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[EMPTY]); + XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[failure || failonclear ? FAILED : INIT]); XClearWindow(dpy, locks[screen]->win); } }