aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slock.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/slock.c b/slock.c
index 65722ea..ba75493 100644
--- a/slock.c
+++ b/slock.c
@@ -58,7 +58,7 @@ main(int argc, char **argv) {
58 Display *dpy; 58 Display *dpy;
59 KeySym ksym; 59 KeySym ksym;
60 Pixmap pmap; 60 Pixmap pmap;
61 Window w; 61 Window root, w;
62 XColor black, dummy; 62 XColor black, dummy;
63 XEvent ev; 63 XEvent ev;
64 XSetWindowAttributes wa; 64 XSetWindowAttributes wa;
@@ -73,12 +73,12 @@ main(int argc, char **argv) {
73 exit(EXIT_FAILURE); 73 exit(EXIT_FAILURE);
74 } 74 }
75 screen = DefaultScreen(dpy); 75 screen = DefaultScreen(dpy);
76 root = RootWindow(dpy, screen);
76 77
77 /* init */ 78 /* init */
78 wa.override_redirect = 1; 79 wa.override_redirect = 1;
79 wa.background_pixel = BlackPixel(dpy, screen); 80 wa.background_pixel = BlackPixel(dpy, screen);
80 w = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0, 81 w = XCreateWindow(dpy, root, 0, 0, DisplayWidth(dpy, screen), DisplayHeight(dpy, screen),
81 DisplayWidth(dpy, screen), DisplayHeight(dpy, screen),
82 0, DefaultDepth(dpy, screen), CopyFromParent, 82 0, DefaultDepth(dpy, screen), CopyFromParent,
83 DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa); 83 DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa);
84 84
@@ -86,15 +86,21 @@ main(int argc, char **argv) {
86 pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8); 86 pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8);
87 invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0); 87 invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0);
88 XDefineCursor(dpy, w, invisible); 88 XDefineCursor(dpy, w, invisible);
89 for(len = 1000; len && (XGrabPointer(dpy, RootWindow(dpy, screen), False, 89 for(len = 1000; len; len--) {
90 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, 90 if(XGrabPointer(dpy, root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
91 GrabModeAsync, GrabModeSync, None, invisible, CurrentTime) != GrabSuccess); len--) 91 GrabModeAsync, GrabModeSync, None, invisible, CurrentTime) == GrabSuccess)
92 break;
92 usleep(1000); 93 usleep(1000);
93 running = running && (len > 0); 94 }
94 for(len = 1000; len && (XGrabKeyboard(dpy, RootWindow(dpy, screen), True, GrabModeAsync, 95 if((running = running && (len > 0))) {
95 GrabModeAsync, CurrentTime) != GrabSuccess); len--) 96 for(len = 1000; len; len--) {
96 usleep(1000); 97 if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
97 running = running && (len > 0); 98 == GrabSuccess)
99 break;
100 usleep(1000);
101 }
102 running = (len > 0);
103 }
98 len = 0; 104 len = 0;
99 XMapRaised(dpy, w); 105 XMapRaised(dpy, w);
100 XSync(dpy, False); 106 XSync(dpy, False);