made slock more readable, added root variable because we intend to call RootWindow(...) quite a lot
This commit is contained in:
parent
ae8cce24d3
commit
d83a9a1d01
26
slock.c
26
slock.c
|
@ -58,7 +58,7 @@ main(int argc, char **argv) {
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
KeySym ksym;
|
KeySym ksym;
|
||||||
Pixmap pmap;
|
Pixmap pmap;
|
||||||
Window w;
|
Window root, w;
|
||||||
XColor black, dummy;
|
XColor black, dummy;
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
XSetWindowAttributes wa;
|
XSetWindowAttributes wa;
|
||||||
|
@ -73,12 +73,12 @@ main(int argc, char **argv) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
screen = DefaultScreen(dpy);
|
screen = DefaultScreen(dpy);
|
||||||
|
root = RootWindow(dpy, screen);
|
||||||
|
|
||||||
/* init */
|
/* init */
|
||||||
wa.override_redirect = 1;
|
wa.override_redirect = 1;
|
||||||
wa.background_pixel = BlackPixel(dpy, screen);
|
wa.background_pixel = BlackPixel(dpy, screen);
|
||||||
w = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0,
|
w = XCreateWindow(dpy, root, 0, 0, DisplayWidth(dpy, screen), DisplayHeight(dpy, screen),
|
||||||
DisplayWidth(dpy, screen), DisplayHeight(dpy, screen),
|
|
||||||
0, DefaultDepth(dpy, screen), CopyFromParent,
|
0, DefaultDepth(dpy, screen), CopyFromParent,
|
||||||
DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa);
|
DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa);
|
||||||
|
|
||||||
|
@ -86,15 +86,21 @@ main(int argc, char **argv) {
|
||||||
pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8);
|
pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8);
|
||||||
invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0);
|
invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0);
|
||||||
XDefineCursor(dpy, w, invisible);
|
XDefineCursor(dpy, w, invisible);
|
||||||
for(len = 1000; len && (XGrabPointer(dpy, RootWindow(dpy, screen), False,
|
for(len = 1000; len; len--) {
|
||||||
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
if(XGrabPointer(dpy, root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
||||||
GrabModeAsync, GrabModeSync, None, invisible, CurrentTime) != GrabSuccess); len--)
|
GrabModeAsync, GrabModeSync, None, invisible, CurrentTime) == GrabSuccess)
|
||||||
|
break;
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
running = running && (len > 0);
|
}
|
||||||
for(len = 1000; len && (XGrabKeyboard(dpy, RootWindow(dpy, screen), True, GrabModeAsync,
|
if((running = running && (len > 0))) {
|
||||||
GrabModeAsync, CurrentTime) != GrabSuccess); len--)
|
for(len = 1000; len; len--) {
|
||||||
|
if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
|
||||||
|
== GrabSuccess)
|
||||||
|
break;
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
running = running && (len > 0);
|
}
|
||||||
|
running = (len > 0);
|
||||||
|
}
|
||||||
len = 0;
|
len = 0;
|
||||||
XMapRaised(dpy, w);
|
XMapRaised(dpy, w);
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
|
|
Loading…
Reference in New Issue