aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h7
-rw-r--r--slock.c27
2 files changed, 23 insertions, 11 deletions
diff --git a/config.def.h b/config.def.h
index 89e5977..4bccb5d 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,2 +1,5 @@
1#define COLOR1 "black" 1static const char *colorname[NUMCOLS] = {
2#define COLOR2 "#005577" 2 "black", /* after initialization */
3 "#005577", /* during input */
4 "#CC3333", /* failed/cleared the input */
5};
diff --git a/slock.c b/slock.c
index 407a540..df5c3fe 100644
--- a/slock.c
+++ b/slock.c
@@ -22,13 +22,20 @@
22#include <bsd_auth.h> 22#include <bsd_auth.h>
23#endif 23#endif
24 24
25enum {
26 INIT,
27 INPUT,
28 EMPTY,
29 NUMCOLS
30};
31
25#include "config.h" 32#include "config.h"
26 33
27typedef struct { 34typedef struct {
28 int screen; 35 int screen;
29 Window root, win; 36 Window root, win;
30 Pixmap pmap; 37 Pixmap pmap;
31 unsigned long colors[2]; 38 unsigned long colors[NUMCOLS];
32} Lock; 39} Lock;
33 40
34static Lock **locks; 41static Lock **locks;
@@ -162,12 +169,12 @@ readpw(Display *dpy, const char *pws)
162 } 169 }
163 if (llen == 0 && len != 0) { 170 if (llen == 0 && len != 0) {
164 for (screen = 0; screen < nscreens; screen++) { 171 for (screen = 0; screen < nscreens; screen++) {
165 XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[1]); 172 XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[INPUT]);
166 XClearWindow(dpy, locks[screen]->win); 173 XClearWindow(dpy, locks[screen]->win);
167 } 174 }
168 } else if (llen != 0 && len == 0) { 175 } else if (llen != 0 && len == 0) {
169 for (screen = 0; screen < nscreens; screen++) { 176 for (screen = 0; screen < nscreens; screen++) {
170 XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]); 177 XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[EMPTY]);
171 XClearWindow(dpy, locks[screen]->win); 178 XClearWindow(dpy, locks[screen]->win);
172 } 179 }
173 } 180 }
@@ -185,7 +192,7 @@ unlockscreen(Display *dpy, Lock *lock)
185 return; 192 return;
186 193
187 XUngrabPointer(dpy, CurrentTime); 194 XUngrabPointer(dpy, CurrentTime);
188 XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, 2, 0); 195 XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, NUMCOLS, 0);
189 XFreePixmap(dpy, lock->pmap); 196 XFreePixmap(dpy, lock->pmap);
190 XDestroyWindow(dpy, lock->win); 197 XDestroyWindow(dpy, lock->win);
191 198
@@ -197,6 +204,7 @@ lockscreen(Display *dpy, int screen)
197{ 204{
198 char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; 205 char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};
199 unsigned int len; 206 unsigned int len;
207 int i;
200 Lock *lock; 208 Lock *lock;
201 XColor color, dummy; 209 XColor color, dummy;
202 XSetWindowAttributes wa; 210 XSetWindowAttributes wa;
@@ -213,16 +221,17 @@ lockscreen(Display *dpy, int screen)
213 221
214 lock->root = RootWindow(dpy, lock->screen); 222 lock->root = RootWindow(dpy, lock->screen);
215 223
224 for (i = 0; i < NUMCOLS; i++) {
225 XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), colorname[i], &color, &dummy);
226 lock->colors[i] = color.pixel;
227 }
228
216 /* init */ 229 /* init */
217 wa.override_redirect = 1; 230 wa.override_redirect = 1;
218 wa.background_pixel = BlackPixel(dpy, lock->screen); 231 wa.background_pixel = lock->colors[INIT];
219 lock->win = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), 232 lock->win = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen),
220 0, DefaultDepth(dpy, lock->screen), CopyFromParent, 233 0, DefaultDepth(dpy, lock->screen), CopyFromParent,
221 DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa); 234 DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa);
222 XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR2, &color, &dummy);
223 lock->colors[1] = color.pixel;
224 XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR1, &color, &dummy);
225 lock->colors[0] = color.pixel;
226 lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8); 235 lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
227 invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, &color, 0, 0); 236 invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, &color, 0, 0);
228 XDefineCursor(dpy, lock->win, invisible); 237 XDefineCursor(dpy, lock->win, invisible);