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/cursorfont.h>
12 #include <X11/keysym.h>
14 #include <X11/Xutil.h>
17 main(int argc, char **argv) {
18 char buf[32], passwd[256];
19 int num, prev_nitem, screen;
27 XSetWindowAttributes wa;
29 if((argc > 1) && !strncmp(argv[1], "-v", 3)) {
30 fputs("slock-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
33 if(!(sp = getspnam(getenv("USER")))) {
34 fputs("slock: cannot retrieve password entry (make sure to suid slock)\n", stderr);
38 if(!(dpy = XOpenDisplay(0))) {
39 fputs("slock: cannot open display\n", stderr);
42 screen = DefaultScreen(dpy);
46 while(XGrabKeyboard(dpy, RootWindow(dpy, screen), True, GrabModeAsync,
47 GrabModeAsync, CurrentTime) != GrabSuccess)
50 wa.override_redirect = 1;
51 wa.background_pixel = BlackPixel(dpy, screen);
52 w = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0,
53 DisplayWidth(dpy, screen), DisplayHeight(dpy, screen),
54 0, DefaultDepth(dpy, screen), CopyFromParent,
55 DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa);
57 XDefineCursor(dpy, w, XCreateFontCursor(dpy, XC_coffee_mug));
62 while(running && !XNextEvent(dpy, &ev))
63 if(ev.type == KeyPress) {
66 num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0);
67 if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
68 || IsMiscFunctionKey(ksym) || IsPFKey(ksym)
69 || IsPrivateKeypadKey(ksym))
71 /* first check if a control mask is omitted */
72 if(ev.xkey.state & ControlMask) {
75 case XK_H: ksym = XK_BackSpace;
78 case XK_U: passwd[0] = 0;
84 if((running = strncmp(crypt(passwd, sp->sp_pwdp), sp->sp_pwdp, sizeof(passwd))))
96 if(num && !iscntrl((int) buf[0])) {
99 strncat(passwd, buf, sizeof(passwd));
101 strncpy(passwd, buf, sizeof(passwd));
106 XDestroyWindow(dpy, w);