sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

slock-capscolor.diff (3237B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 89e5977..27d533f 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -1,2 +1,3 @@
      6  #define COLOR1 "black"
      7  #define COLOR2 "#005577"
      8 +#define COLORC "red"
      9 diff --git a/slock.c b/slock.c
     10 index 407a540..77bfc1f 100644
     11 --- a/slock.c
     12 +++ b/slock.c
     13 @@ -16,6 +16,7 @@
     14  #include <X11/keysym.h>
     15  #include <X11/Xlib.h>
     16  #include <X11/Xutil.h>
     17 +#include <X11/XKBlib.h>
     18  
     19  #if HAVE_BSD_AUTH
     20  #include <login_cap.h>
     21 @@ -28,7 +29,7 @@ typedef struct {
     22  	int screen;
     23  	Window root, win;
     24  	Pixmap pmap;
     25 -	unsigned long colors[2];
     26 +	unsigned long colors[3];
     27  } Lock;
     28  
     29  static Lock **locks;
     30 @@ -106,14 +107,18 @@ readpw(Display *dpy, const char *pws)
     31  #endif
     32  {
     33  	char buf[32], passwd[256];
     34 -	int num, screen;
     35 -	unsigned int len, llen;
     36 +	int num, screen, caps, lcaps;
     37 +	unsigned int len, llen, indicators;
     38  	KeySym ksym;
     39  	XEvent ev;
     40  
     41  	len = llen = 0;
     42 +    caps = lcaps = 0;
     43  	running = True;
     44  
     45 +    if(!XkbGetIndicatorState(dpy, XkbUseCoreKbd, &indicators))
     46 +        caps = indicators & 1;
     47 +
     48  	/* As "slock" stands for "Simple X display locker", the DPMS settings
     49  	 * had been removed and you can set it with "xset" or some other
     50  	 * utility. This way the user can easily set a customized DPMS
     51 @@ -153,6 +158,9 @@ readpw(Display *dpy, const char *pws)
     52  				if (len)
     53  					--len;
     54  				break;
     55 +            case XK_Caps_Lock:
     56 +                caps = !caps;
     57 +                break;
     58  			default:
     59  				if (num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) {
     60  					memcpy(passwd + len, buf, num);
     61 @@ -160,9 +168,9 @@ readpw(Display *dpy, const char *pws)
     62  				}
     63  				break;
     64  			}
     65 -			if (llen == 0 && len != 0) {
     66 +			if ((llen == 0 && len != 0) || caps != lcaps) {
     67  				for (screen = 0; screen < nscreens; screen++) {
     68 -					XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[1]);
     69 +					XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[caps ? 2 : 1]);
     70  					XClearWindow(dpy, locks[screen]->win);
     71  				}
     72  			} else if (llen != 0 && len == 0) {
     73 @@ -172,6 +180,7 @@ readpw(Display *dpy, const char *pws)
     74  				}
     75  			}
     76  			llen = len;
     77 +            lcaps = caps;
     78  		}
     79  		else for (screen = 0; screen < nscreens; screen++)
     80  			XRaiseWindow(dpy, locks[screen]->win);
     81 @@ -185,7 +194,7 @@ unlockscreen(Display *dpy, Lock *lock)
     82  		return;
     83  
     84  	XUngrabPointer(dpy, CurrentTime);
     85 -	XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, 2, 0);
     86 +	XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, 3, 0);
     87  	XFreePixmap(dpy, lock->pmap);
     88  	XDestroyWindow(dpy, lock->win);
     89  
     90 @@ -219,6 +228,8 @@ lockscreen(Display *dpy, int screen)
     91  	lock->win = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen),
     92  	                          0, DefaultDepth(dpy, lock->screen), CopyFromParent,
     93  	                          DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa);
     94 +	XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLORC, &color, &dummy);
     95 +	lock->colors[2] = color.pixel;
     96  	XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR2, &color, &dummy);
     97  	lock->colors[1] = color.pixel;
     98  	XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), COLOR1, &color, &dummy);