X-Git-Url: https://git.xinqibao.xyz/slock.git/blobdiff_plain/e5216380276932d7cd5576bac0ee9255b58d2e17..d83a9a1d01fb70df9859ea231c8d7a2fb898c1e7:/slock.c diff --git a/slock.c b/slock.c index aafc7c0..ba75493 100644 --- a/slock.c +++ b/slock.c @@ -1,4 +1,4 @@ -/* (C)opyright MMIV-MMV Anselm R. Garbe +/* (C)opyright MMVI-MMVII Anselm R. Garbe * See LICENSE file for license details. */ #define _XOPEN_SOURCE 500 @@ -58,7 +58,7 @@ main(int argc, char **argv) { Display *dpy; KeySym ksym; Pixmap pmap; - Window w; + Window root, w; XColor black, dummy; XEvent ev; XSetWindowAttributes wa; @@ -73,12 +73,12 @@ main(int argc, char **argv) { exit(EXIT_FAILURE); } screen = DefaultScreen(dpy); + root = RootWindow(dpy, screen); /* init */ wa.override_redirect = 1; wa.background_pixel = BlackPixel(dpy, screen); - w = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0, - DisplayWidth(dpy, screen), DisplayHeight(dpy, screen), + w = XCreateWindow(dpy, root, 0, 0, DisplayWidth(dpy, screen), DisplayHeight(dpy, screen), 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa); @@ -86,14 +86,21 @@ main(int argc, char **argv) { pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8); invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0); XDefineCursor(dpy, w, invisible); - running = XGrabPointer(dpy, RootWindow(dpy, screen), False, - ButtonPressMask | ButtonReleaseMask | PointerMotionMask, - GrabModeAsync, GrabModeSync, None, invisible, CurrentTime) == GrabSuccess; - len = 10; - for(len = 10; len && (XGrabKeyboard(dpy, RootWindow(dpy, screen), True, GrabModeAsync, - GrabModeAsync, CurrentTime) != GrabSuccess); len--) + for(len = 1000; len; len--) { + if(XGrabPointer(dpy, root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, + GrabModeAsync, GrabModeSync, None, invisible, CurrentTime) == GrabSuccess) + break; usleep(1000); - running = running && (len > 0); + } + if((running = running && (len > 0))) { + for(len = 1000; len; len--) { + if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) + == GrabSuccess) + break; + usleep(1000); + } + running = (len > 0); + } len = 0; XMapRaised(dpy, w); XSync(dpy, False); @@ -122,7 +129,7 @@ main(int argc, char **argv) { --len; break; default: - if(num && !iscntrl((int) buf[0])) { + if(num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) { memcpy(passwd + len, buf, num); len += num; }