Hi,

Markus Teich wrote:
>You can easily tell if someone tried to unlock your computer

Hmm that's actually quite a good point/idea/use of the feature. Three
colours sounds like a good middle ground. Attached is a patch which:

* Adds another colour in config.def.h, COLOR_INIT
* Renames the colours from numerical ones to ones with meaningful
names; COLOUR_INPUT for when there is content in the input buffer and
COLOUR_EMPTY for when the input buffer has been cleared (backspaced or
a failed attempt).
* Ensures XFreeColors frees the right number of colours. This is now
derived from the size of `Lock->colors` rather than being an integer
literal.
* Makes slock exhibit the behaviour described by Markus

The default colours are the same as the ones slock currently uses,
with the exception of the new colour, which I have set to red, as it
indicates someone has either failed an attempt to unlock, or that they
have entered input and erased it all.

Let me know what you think.

Thanks
-- 
Four word witty remark
diff -u a/config.def.h b/config.def.h
--- a/config.def.h      2014-12-22 23:18:07.000000000 +1300
+++ b/config.def.h      2015-02-12 11:41:47.360229925 +1300
@@ -1,2 +1,3 @@
-#define COLOR1 "black"
-#define COLOR2 "#005577"
+#define COLOR_INIT  "black"
+#define COLOR_INPUT "#005577"
+#define COLOR_EMPTY "#CC3333"
diff -u a/slock.c b/slock.c
--- a/slock.c   2014-12-22 23:18:07.000000000 +1300
+++ b/slock.c   2015-02-12 11:40:19.488018866 +1300
@@ -25,11 +25,17 @@
 
 #include "config.h"
 
+enum {
+       INIT,
+       INPUT,
+       EMPTY
+};
+
 typedef struct {
        int screen;
        Window root, win;
        Pixmap pmap;
-       unsigned long colors[2];
+       unsigned long colors[3];
 } Lock;
 
 static Lock **locks;
@@ -157,12 +163,12 @@
                        }
                        if(llen == 0 && len != 0) {
                                for(screen = 0; screen < nscreens; screen++) {
-                                       XSetWindowBackground(dpy, 
locks[screen]->win, locks[screen]->colors[1]);
+                                       XSetWindowBackground(dpy, 
locks[screen]->win, locks[screen]->colors[INPUT]);
                                        XClearWindow(dpy, locks[screen]->win);
                                }
                        } else if(llen != 0 && len == 0) {
                                for(screen = 0; screen < nscreens; screen++) {
-                                       XSetWindowBackground(dpy, 
locks[screen]->win, locks[screen]->colors[0]);
+                                       XSetWindowBackground(dpy, 
locks[screen]->win, locks[screen]->colors[EMPTY]);
                                        XClearWindow(dpy, locks[screen]->win);
                                }
                        }
@@ -179,7 +185,7 @@
                return;
 
        XUngrabPointer(dpy, CurrentTime);
-       XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, 2, 
0);
+       XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, 
sizeof(lock->colors)/sizeof(unsigned long), 0);
        XFreePixmap(dpy, lock->pmap);
        XDestroyWindow(dpy, lock->win);
 
@@ -212,10 +218,12 @@
        lock->win = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, 
lock->screen), DisplayHeight(dpy, lock->screen),
                        0, DefaultDepth(dpy, lock->screen), CopyFromParent,
                        DefaultVisual(dpy, lock->screen), CWOverrideRedirect | 
CWBackPixel, &wa);
-       XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR2, 
&color, &dummy);
-       lock->colors[1] = color.pixel;
-       XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR1, 
&color, &dummy);
-       lock->colors[0] = color.pixel;
+       XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR_INIT, 
&color, &dummy);
+       lock->colors[INIT] = color.pixel;
+       XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR_INPUT, 
&color, &dummy);
+       lock->colors[INPUT] = color.pixel;
+       XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR_EMPTY, 
&color, &dummy);
+       lock->colors[EMPTY] = color.pixel;
        lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
        invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, 
&color, 0, 0);
        XDefineCursor(dpy, lock->win, invisible);
@@ -286,7 +294,11 @@
        int nlocks = 0;
        for(screen = 0; screen < nscreens; screen++) {
                if ( (locks[screen] = lockscreen(dpy, screen)) != NULL)
+               {
+                       XSetWindowBackground(dpy, locks[screen]->win, 
locks[screen]->colors[INIT]);
+                       XClearWindow(dpy, locks[screen]->win);
                        nlocks++;
+               }
        }
        XSync(dpy, False);
 

Reply via email to