X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=slock.c;h=1551a9ec30983a9f1b76c1276a4f82053c154684;hb=b1289f30b79c9c5ea43a9e9c624406d7d0661692;hp=df5c3fea36f2e0f1b7ccdb1e035588bd0f0a5d00;hpb=f2ea92c3ddf1d9476ef61f85ec3aa26818d094a1;p=slock.git diff --git a/slock.c b/slock.c index df5c3fe..1551a9e 100644 --- a/slock.c +++ b/slock.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,7 @@ enum { INIT, INPUT, - EMPTY, + FAILED, NUMCOLS }; @@ -41,6 +42,10 @@ 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; static void die(const char *errstr, ...) @@ -149,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: @@ -174,13 +181,20 @@ 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); } } llen = len; - } - else for (screen = 0; screen < nscreens; screen++) + } else if (rr && ev.type == rrevbase + RRScreenChangeNotify) { + XRRScreenChangeNotifyEvent *rre = (XRRScreenChangeNotifyEvent*)&ev; + for (screen = 0; screen < nscreens; screen++) { + if (locks[screen]->win == rre->window) { + XResizeWindow(dpy, locks[screen]->win, rre->width, rre->height); + XClearWindow(dpy, locks[screen]->win); + } + } + } else for (screen = 0; screen < nscreens; screen++) XRaiseWindow(dpy, locks[screen]->win); } } @@ -236,6 +250,8 @@ lockscreen(Display *dpy, int screen) invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, &color, 0, 0); XDefineCursor(dpy, lock->win, invisible); XMapRaised(dpy, lock->win); + if (rr) + XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask); for (len = 1000; len; len--) { if (XGrabPointer(dpy, lock->root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess) @@ -295,6 +311,7 @@ main(int argc, char **argv) { if (!(dpy = XOpenDisplay(0))) die("slock: cannot open display\n"); + rr = XRRQueryExtension(dpy, &rrevbase, &rrerrbase); /* Get the number of screens in display "dpy" and blank them all. */ nscreens = ScreenCount(dpy); locks = malloc(sizeof(Lock *) * nscreens);