diff options
-rw-r--r-- | slock.c | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -15,13 +15,15 @@ | |||
15 | int | 15 | int |
16 | main(int argc, char **argv) { | 16 | main(int argc, char **argv) { |
17 | char buf[32], passwd[256]; | 17 | char buf[32], passwd[256]; |
18 | int num, prev_nitem; | 18 | int num, prev_nitem, screen; |
19 | struct spwd *sp; | 19 | struct spwd *sp; |
20 | unsigned int i, len; | 20 | unsigned int i, len; |
21 | Bool running = True; | 21 | Bool running = True; |
22 | KeySym ksym; | 22 | KeySym ksym; |
23 | Display *dpy; | 23 | Display *dpy; |
24 | Window w; | ||
24 | XEvent ev; | 25 | XEvent ev; |
26 | XSetWindowAttributes wa; | ||
25 | 27 | ||
26 | if((argc > 1) && !strncmp(argv[1], "-v", 3)) { | 28 | if((argc > 1) && !strncmp(argv[1], "-v", 3)) { |
27 | fputs("slock-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); | 29 | fputs("slock-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); |
@@ -36,13 +38,23 @@ main(int argc, char **argv) { | |||
36 | fputs("slock: cannot open display\n", stderr); | 38 | fputs("slock: cannot open display\n", stderr); |
37 | exit(EXIT_FAILURE); | 39 | exit(EXIT_FAILURE); |
38 | } | 40 | } |
41 | screen = DefaultScreen(dpy); | ||
39 | 42 | ||
40 | /* init */ | 43 | /* init */ |
41 | passwd[0] = 0; | 44 | passwd[0] = 0; |
42 | while(XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync, | 45 | while(XGrabKeyboard(dpy, RootWindow(dpy, screen), True, GrabModeAsync, |
43 | GrabModeAsync, CurrentTime) != GrabSuccess) | 46 | GrabModeAsync, CurrentTime) != GrabSuccess) |
44 | usleep(1000); | 47 | usleep(1000); |
45 | 48 | ||
49 | wa.override_redirect = 1; | ||
50 | wa.background_pixel = BlackPixel(dpy, screen); | ||
51 | w = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0, | ||
52 | DisplayWidth(dpy, screen), DisplayHeight(dpy, screen), | ||
53 | 0, DefaultDepth(dpy, screen), CopyFromParent, | ||
54 | DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa); | ||
55 | XMapRaised(dpy, w); | ||
56 | XSync(dpy, False); | ||
57 | |||
46 | /* main event loop */ | 58 | /* main event loop */ |
47 | while(running && !XNextEvent(dpy, &ev)) | 59 | while(running && !XNextEvent(dpy, &ev)) |
48 | if(ev.type == KeyPress) { | 60 | if(ev.type == KeyPress) { |
@@ -66,7 +78,8 @@ main(int argc, char **argv) { | |||
66 | } | 78 | } |
67 | switch(ksym) { | 79 | switch(ksym) { |
68 | case XK_Return: | 80 | case XK_Return: |
69 | running = strncmp(crypt(passwd, sp->sp_pwdp), sp->sp_pwdp, sizeof(passwd)); | 81 | if((running = strncmp(crypt(passwd, sp->sp_pwdp), sp->sp_pwdp, sizeof(passwd)))) |
82 | XBell(dpy, 100); | ||
70 | passwd[0] = 0; | 83 | passwd[0] = 0; |
71 | break; | 84 | break; |
72 | case XK_Escape: | 85 | case XK_Escape: |
@@ -87,6 +100,7 @@ main(int argc, char **argv) { | |||
87 | break; | 100 | break; |
88 | } | 101 | } |
89 | } | 102 | } |
103 | XDestroyWindow(dpy, w); | ||
90 | XCloseDisplay(dpy); | 104 | XCloseDisplay(dpy); |
91 | return 0; | 105 | return 0; |
92 | } | 106 | } |