X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=slock.c;h=6502c86157ec2022f8ca2a3782a5e4880412000a;hb=f5ef1b8eb5555da11e81d92d8d05acd4aba1ef40;hp=407a54024bd25b5507d6838de934aa14d0054258;hpb=a31b9191111572dafaa8366415b89a4472aa4626;p=slock.git diff --git a/slock.c b/slock.c index 407a540..6502c86 100644 --- a/slock.c +++ b/slock.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -22,18 +23,28 @@ #include #endif +enum { + INIT, + INPUT, + EMPTY, + NUMCOLS +}; + #include "config.h" typedef struct { int screen; Window root, win; Pixmap pmap; - unsigned long colors[2]; + unsigned long colors[NUMCOLS]; } Lock; static Lock **locks; static int nscreens; static Bool running = True; +static Bool rr; +static int rrevbase; +static int rrerrbase; static void die(const char *errstr, ...) @@ -162,18 +173,25 @@ readpw(Display *dpy, const char *pws) } if (llen == 0 && len != 0) { for (screen = 0; screen < nscreens; screen++) { - XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[1]); + XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[INPUT]); XClearWindow(dpy, locks[screen]->win); } } else if (llen != 0 && len == 0) { for (screen = 0; screen < nscreens; screen++) { - XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]); + XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[EMPTY]); 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); } } @@ -185,7 +203,7 @@ unlockscreen(Display *dpy, Lock *lock) return; XUngrabPointer(dpy, CurrentTime); - XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, 2, 0); + XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, NUMCOLS, 0); XFreePixmap(dpy, lock->pmap); XDestroyWindow(dpy, lock->win); @@ -197,6 +215,7 @@ lockscreen(Display *dpy, int screen) { char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; unsigned int len; + int i; Lock *lock; XColor color, dummy; XSetWindowAttributes wa; @@ -213,20 +232,23 @@ lockscreen(Display *dpy, int screen) lock->root = RootWindow(dpy, lock->screen); + for (i = 0; i < NUMCOLS; i++) { + XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), colorname[i], &color, &dummy); + lock->colors[i] = color.pixel; + } + /* init */ wa.override_redirect = 1; - wa.background_pixel = BlackPixel(dpy, lock->screen); + wa.background_pixel = lock->colors[INIT]; lock->win = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), 0, DefaultDepth(dpy, lock->screen), CopyFromParent, DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa); - XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR2, &color, &dummy); - lock->colors[1] = color.pixel; - XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR1, &color, &dummy); - lock->colors[0] = color.pixel; lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8); 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) @@ -286,6 +308,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);