[wiki] [sites] Added slock patch for Caps Lock color indicator || Andrew Hills

From: <git_AT_suckless.org>
Date: Sun, 01 Mar 2015 18:48:39 +0100

commit 58fa96d8551dc2de2ff44e650e2b9a65b264bd8b
Author: Andrew Hills <ahills_AT_ednos.net>
Date: Sun Mar 1 12:48:16 2015 -0500

    Added slock patch for Caps Lock color indicator

diff --git a/tools.suckless.org/slock/patches/capscolor.md b/tools.suckless.org/slock/patches/capscolor.md
new file mode 100644
index 0000000..cd0fe80
--- /dev/null
+++ b/tools.suckless.org/slock/patches/capscolor.md
_AT_@ -0,0 +1,19 @@
+Capscolor
+=========
+
+Description
+-----------
+
+Introduces an additional color to indicate the state of Caps Lock. Not
+compatible with the [failcolor](./failcolor) patch. Written against HEAD at
+a31b919, but should apply to 1.2.
+
+Download
+--------
+
+* [slock-capscolor.diff](slock-capscolor.diff)
+
+Author
+------
+
+* Andrew Hills <[ahills_AT_ednos.net](mailto:ahills_AT_ednos.net)>
diff --git a/tools.suckless.org/slock/patches/slock-capscolor.diff b/tools.suckless.org/slock/patches/slock-capscolor.diff
new file mode 100644
index 0000000..164e2ef
--- /dev/null
+++ b/tools.suckless.org/slock/patches/slock-capscolor.diff
_AT_@ -0,0 +1,98 @@
+diff --git a/config.def.h b/config.def.h
+index 89e5977..27d533f 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -1,2 +1,3 @@
+ #define COLOR1 "black"
+ #define COLOR2 "#005577"
++#define COLORC "red"
+diff --git a/slock.c b/slock.c
+index 407a540..77bfc1f 100644
+--- a/slock.c
++++ b/slock.c
+_AT_@ -16,6 +16,7 @@
+ #include <X11/keysym.h>
+ #include <X11/Xlib.h>
+ #include <X11/Xutil.h>
++#include <X11/XKBlib.h>
+
+ #if HAVE_BSD_AUTH
+ #include <login_cap.h>
+_AT_@ -28,7 +29,7 @@ typedef struct {
+ int screen;
+ Window root, win;
+ Pixmap pmap;
+- unsigned long colors[2];
++ unsigned long colors[3];
+ } Lock;
+
+ static Lock **locks;
+_AT_@ -106,14 +107,18 @@ readpw(Display *dpy, const char *pws)
+ #endif
+ {
+ char buf[32], passwd[256];
+- int num, screen;
+- unsigned int len, llen;
++ int num, screen, caps, lcaps;
++ unsigned int len, llen, indicators;
+ KeySym ksym;
+ XEvent ev;
+
+ len = llen = 0;
++ caps = lcaps = 0;
+ running = True;
+
++ if(!XkbGetIndicatorState(dpy, XkbUseCoreKbd, &indicators))
++ caps = indicators & 1;
++
+ /* As "slock" stands for "Simple X display locker", the DPMS settings
+ * had been removed and you can set it with "xset" or some other
+ * utility. This way the user can easily set a customized DPMS
+_AT_@ -153,6 +158,9 @@ readpw(Display *dpy, const char *pws)
+ if (len)
+ --len;
+ break;
++ case XK_Caps_Lock:
++ caps = !caps;
++ break;
+ default:
+ if (num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) {
+ memcpy(passwd + len, buf, num);
+_AT_@ -160,9 +168,9 @@ readpw(Display *dpy, const char *pws)
+ }
+ break;
+ }
+- if (llen == 0 && len != 0) {
++ if ((llen == 0 && len != 0) || caps != lcaps) {
+ for (screen = 0; screen < nscreens; screen++) {
+- XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[1]);
++ XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[caps ? 2 : 1]);
+ XClearWindow(dpy, locks[screen]->win);
+ }
+ } else if (llen != 0 && len == 0) {
+_AT_@ -172,6 +180,7 @@ readpw(Display *dpy, const char *pws)
+ }
+ }
+ llen = len;
++ lcaps = caps;
+ }
+ else for (screen = 0; screen < nscreens; screen++)
+ XRaiseWindow(dpy, locks[screen]->win);
+_AT_@ -185,7 +194,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);
+
+_AT_@ -219,6 +228,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), COLORC, &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);
Received on Sun Mar 01 2015 - 18:48:39 CET

This archive was generated by hypermail 2.3.0 : Thu Jun 18 2015 - 17:40:13 CEST