Hi,
>> - if(llen == 0 && len != 0) {
>> + caps_state = ev.xkey.state && LockMask;
>> + if((llen == 0 && len != 0)) {
>
> Why the extra parentheses in the if statement?
A prior test was including another condition. It was a leftover from that.
>
>> - XSetWindowBackground(dpy,
>> locks[screen]->win, locks[screen]->colors[1]);
>> + if(caps_state)
>> + XSetWindowBackground(dpy,
>> locks[screen]->win, locks[screen]->colors[2]);
>> + else
>> + XSetWindowBackground(dpy,
>> locks[screen]->win, locks[screen]->colors[1]);
>
> How about the ?: operator here?
>
See attached!
Cheers,
Thiébaud
diff -up slock-1.1/config.mk slock-1.1.new/config.mk
--- slock-1.1/config.mk 2014-04-27 18:28:22.635615638 +1000
+++ slock-1.1.new/config.mk 2014-04-27 18:39:23.874262103 +1000
@@ -14,7 +14,7 @@ INCS = -I. -I/usr/include -I${X11INC}
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext
# flags
-CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H -DCOLOR1=\"black\" -DCOLOR2=\"\#005577\"
+CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H -DCOLOR1=\"black\" -DCOLOR2=\"\#005577\" -DCOLOR3=\"\#AA0000\"
CFLAGS += -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
LDFLAGS += ${LIBS}
Only in slock-1.1.new/: slock
diff -up slock-1.1/slock.c slock-1.1.new/slock.c
--- slock-1.1/slock.c 2012-10-26 06:00:04.000000000 +1100
+++ slock-1.1.new/slock.c 2014-04-28 19:57:41.126915519 +1000
@@ -27,7 +27,7 @@ typedef struct {
int screen;
Window root, win;
Pixmap pmap;
- unsigned long colors[2];
+ unsigned long colors[3];
} Lock;
static Lock **locks;
@@ -83,7 +83,7 @@ readpw(Display *dpy, const char *pws)
{
char buf[32], passwd[256];
int num, screen;
- unsigned int len, llen;
+ unsigned int len, llen, caps_state;
KeySym ksym;
XEvent ev;
@@ -134,9 +134,11 @@ readpw(Display *dpy, const char *pws)
}
break;
}
+ caps_state = ev.xkey.state && LockMask;
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, (caps_state) ?
+ locks[screen]->colors[2] : locks[screen]->colors[1]);
XClearWindow(dpy, locks[screen]->win);
}
} else if(llen != 0 && len == 0) {
@@ -158,7 +160,7 @@ unlockscreen(Display *dpy, Lock *lock) {
return;
XUngrabPointer(dpy, CurrentTime);
- XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, 2, 0);
+ XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, 3, 0);
XFreePixmap(dpy, lock->pmap);
XDestroyWindow(dpy, lock->win);
@@ -191,6 +193,8 @@ lockscreen(Display *dpy, int screen) {
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), COLOR3, &color, &dummy);
+ lock->colors[2] = color.pixel;
XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR2, &color, &dummy);
lock->colors[1] = color.pixel;
XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR1, &color, &dummy);
Only in slock-1.1.new/: slock.o