aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.mk4
-rw-r--r--slock.c27
2 files changed, 24 insertions, 7 deletions
diff --git a/config.mk b/config.mk
index f438ed4..addb499 100644
--- a/config.mk
+++ b/config.mk
@@ -1,5 +1,5 @@
1# slock version 1# slock version
2VERSION = 1.0 2VERSION = 1.0-tip
3 3
4# Customize below to fit your system 4# Customize below to fit your system
5 5
@@ -14,7 +14,7 @@ INCS = -I. -I/usr/include -I${X11INC}
14LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext 14LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext
15 15
16# flags 16# flags
17CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H 17CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H -DCOLOR1=\"black\" -DCOLOR2=\"\#005577\"
18CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} 18CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
19LDFLAGS = -s ${LIBS} 19LDFLAGS = -s ${LIBS}
20 20
diff --git a/slock.c b/slock.c
index 96d4379..12b8d4d 100644
--- a/slock.c
+++ b/slock.c
@@ -26,6 +26,7 @@ typedef struct {
26 int screen; 26 int screen;
27 Window root, win; 27 Window root, win;
28 Pixmap pmap; 28 Pixmap pmap;
29 unsigned long colors[2];
29} Lock; 30} Lock;
30 31
31static Lock **locks; 32static Lock **locks;
@@ -81,11 +82,11 @@ readpw(Display *dpy, const char *pws)
81{ 82{
82 char buf[32], passwd[256]; 83 char buf[32], passwd[256];
83 int num, screen; 84 int num, screen;
84 unsigned int len; 85 unsigned int len, llen;
85 KeySym ksym; 86 KeySym ksym;
86 XEvent ev; 87 XEvent ev;
87 88
88 len = 0; 89 len = llen = 0;
89 running = True; 90 running = True;
90 91
91 /* As "slock" stands for "Simple X display locker", the DPMS settings 92 /* As "slock" stands for "Simple X display locker", the DPMS settings
@@ -132,6 +133,18 @@ readpw(Display *dpy, const char *pws)
132 } 133 }
133 break; 134 break;
134 } 135 }
136 if(llen == 0 && len != 0) {
137 for(screen = 0; screen < nscreens; screen++) {
138 XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[1]);
139 XClearWindow(dpy, locks[screen]->win);
140 }
141 } else if(llen != 0 && len == 0) {
142 for(screen = 0; screen < nscreens; screen++) {
143 XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]);
144 XClearWindow(dpy, locks[screen]->win);
145 }
146 }
147 llen = len;
135 } 148 }
136 else for(screen = 0; screen < nscreens; screen++) 149 else for(screen = 0; screen < nscreens; screen++)
137 XRaiseWindow(dpy, locks[screen]->win); 150 XRaiseWindow(dpy, locks[screen]->win);
@@ -144,6 +157,7 @@ unlockscreen(Display *dpy, Lock *lock) {
144 return; 157 return;
145 158
146 XUngrabPointer(dpy, CurrentTime); 159 XUngrabPointer(dpy, CurrentTime);
160 XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, 2, 0);
147 XFreePixmap(dpy, lock->pmap); 161 XFreePixmap(dpy, lock->pmap);
148 XDestroyWindow(dpy, lock->win); 162 XDestroyWindow(dpy, lock->win);
149 163
@@ -155,7 +169,7 @@ lockscreen(Display *dpy, int screen) {
155 char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; 169 char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};
156 unsigned int len; 170 unsigned int len;
157 Lock *lock; 171 Lock *lock;
158 XColor black, dummy; 172 XColor color, dummy;
159 XSetWindowAttributes wa; 173 XSetWindowAttributes wa;
160 Cursor invisible; 174 Cursor invisible;
161 175
@@ -176,9 +190,12 @@ lockscreen(Display *dpy, int screen) {
176 lock->win = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), 190 lock->win = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen),
177 0, DefaultDepth(dpy, lock->screen), CopyFromParent, 191 0, DefaultDepth(dpy, lock->screen), CopyFromParent,
178 DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa); 192 DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa);
179 XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), "black", &black, &dummy); 193 XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR2, &color, &dummy);
194 lock->colors[1] = color.pixel;
195 XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR1, &color, &dummy);
196 lock->colors[0] = color.pixel;
180 lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8); 197 lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
181 invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &black, &black, 0, 0); 198 invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, &color, 0, 0);
182 XDefineCursor(dpy, lock->win, invisible); 199 XDefineCursor(dpy, lock->win, invisible);
183 XMapRaised(dpy, lock->win); 200 XMapRaised(dpy, lock->win);
184 for(len = 1000; len; len--) { 201 for(len = 1000; len; len--) {