[hackers] slock - Feedback when typing password

From: Christian Laursen <xi_AT_borderworlds.dk>
Date: Wed, 27 Feb 2008 20:01:15 +0100

Hello

For quite some time now I have been looking for a decent screen
locking program. I dislike both xscreensaver and xlock for a number of
reasons, one of which being that they contain a lot of crap that I
don't need just to lock my screen. (Of course you know that already)

Yesterday I happened to find slock which is almost perfect. Although I
like the minimal approach, I do find it nice to get at least a little
feedback indicating that slock is receiving my keypresses.

So I added that functionality which is contained in the patch below. I
hope that you will not regard this as bloat and include it in the next
release.

Thanks.

--- /usr/ports/x11/slock/work/slock-0.7/slock.c 2007-11-24 21:18:01.000000000 +0100
+++ slock.c 2008-02-26 21:15:29.000000000 +0100
@@ -52,6 +52,16 @@
         return rval;
 }
 
+void
+clear_password(unsigned int len, Display *dpy, Window w, XColor black) {
+ unsigned int i;
+
+ XSetForeground(dpy, XDefaultGC(dpy, 0), black.pixel);
+ for (i = 0; i < len; i++) {
+ XDrawArc(dpy, w, XDefaultGC(dpy, 0), (i + 1) * 10, 10, 6, 6, 0, 23040);
+ }
+}
+
 int
 main(int argc, char **argv) {
         char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};
@@ -65,7 +75,7 @@
         KeySym ksym;
         Pixmap pmap;
         Window root, w;
- XColor black, dummy;
+ XColor black, white, dummy;
         XEvent ev;
         XSetWindowAttributes wa;
 
@@ -84,6 +94,7 @@
                         0, DefaultDepth(dpy, screen), CopyFromParent,
                         DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa);
         XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "black", &black, &dummy);
+ XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "white", &white, &dummy);
         pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8);
         invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0);
         XDefineCursor(dpy, w, invisible);
@@ -120,19 +131,25 @@
                                 passwd[len] = 0;
                                 if((running = strcmp(crypt(passwd, pws), pws)) != 0)
                                         XBell(dpy, 100);
+ clear_password(len, dpy, w, black);
                                 len = 0;
                                 break;
                         case XK_Escape:
+ clear_password(len, dpy, w, black);
                                 len = 0;
                                 break;
                         case XK_BackSpace:
                                 if(len)
                                         --len;
+ XSetForeground(dpy, XDefaultGC(dpy, 0), black.pixel);
+ XDrawArc(dpy, w, XDefaultGC(dpy, 0), (len + 1) * 10, 10, 6, 6, 0, 23040);
                                 break;
                         default:
                                 if(num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) {
                                         memcpy(passwd + len, buf, num);
                                         len += num;
+ XSetForeground(dpy, XDefaultGC(dpy, 0), white.pixel);
+ XDrawArc(dpy, w, XDefaultGC(dpy, 0), len * 10, 10, 6, 6, 0, 23040);
                                 }
                                 break;
                         }

-- 
Christian Laursen
Received on Wed Feb 27 2008 - 20:01:16 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:59:21 UTC