1 /* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
10 #include <sys/types.h>
11 #include <X11/keysym.h>
13 #include <X11/Xutil.h>
16 main(int argc, char **argv) {
17 char buf[32], passwd[256];
18 int num, prev_nitem, screen;
26 XSetWindowAttributes wa;
28 if((argc > 1) && !strncmp(argv[1], "-v", 3)) {
29 fputs("slock-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
32 if(!(sp = getspnam(getenv("USER")))) {
33 fputs("slock: cannot retrieve password entry (make sure to suid slock)\n", stderr);
37 if(!(dpy = XOpenDisplay(0))) {
38 fputs("slock: cannot open display\n", stderr);
41 screen = DefaultScreen(dpy);
45 while(XGrabKeyboard(dpy, RootWindow(dpy, screen), True, GrabModeAsync,
46 GrabModeAsync, CurrentTime) != GrabSuccess)
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);
59 while(running && !XNextEvent(dpy, &ev))
60 if(ev.type == KeyPress) {
63 num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0);
64 if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
65 || IsMiscFunctionKey(ksym) || IsPFKey(ksym)
66 || IsPrivateKeypadKey(ksym))
68 /* first check if a control mask is omitted */
69 if(ev.xkey.state & ControlMask) {
72 case XK_H: ksym = XK_BackSpace;
75 case XK_U: passwd[0] = 0;
81 if((running = strncmp(crypt(passwd, sp->sp_pwdp), sp->sp_pwdp, sizeof(passwd))))
93 if(num && !iscntrl((int) buf[0])) {
96 strncat(passwd, buf, sizeof(passwd));
98 strncpy(passwd, buf, sizeof(passwd));
103 XDestroyWindow(dpy, w);