slock
simple X display locker utility
git clone https://9o.is/git/slock.git
commit abe486733568fe73a5cd134bb9b93342989b90df parent 16aac2fdb460a19b328eca15672cf3c9d69d2b61 Author: Jul <jul@9o.is> Date: Thu, 5 Feb 2026 15:17:06 -0500 set input/failure colors on font Diffstat:
| M | config.def.h | | | 4 | ++-- |
| M | config.h | | | 8 | ++++---- |
| M | slock.c | | | 33 | +++++++++++++++------------------ |
3 files changed, 21 insertions(+), 24 deletions(-)
diff --git a/config.def.h b/config.def.h @@ -2,8 +2,9 @@ static const char *user = "nobody"; static const char *group = "nogroup"; +static const char *bgcolor = "black"; static const char *colorname[NUMCOLS] = { - [INIT] = "black", /* after initialization */ + [INIT] = "white", /* after initialization */ [INPUT] = "#005577", /* during input */ [FAILED] = "#CC3333", /* wrong password */ }; @@ -12,6 +13,5 @@ static const char *colorname[NUMCOLS] = { static const int failonclear = 1; static const char *font = "monospace-16"; -static const char *fontcolor = "white"; static const char *message = "Enter Password"; static const char *timer_message = "Locked:"; diff --git a/config.h b/config.h @@ -2,16 +2,16 @@ static const char *user = "nobody"; static const char *group = "nobody"; +static const char *bgcolor = "#131314"; static const char *colorname[NUMCOLS] = { - [INIT] = "#131314", /* after initialization */ - [INPUT] = "#131314", /* during input */ - [FAILED] = "#131314", /* wrong password */ + [INIT] = "#E3E3E3", /* after initialization */ + [INPUT] = "#89B4FA", /* during input */ + [FAILED] = "#F38BA8", /* wrong password */ }; /* treat a cleared input like a wrong password (color) */ static const int failonclear = 1; static const char *font = "Fira Mono-18"; -static const char *fontcolor = "#E3E3E3"; static const char *message = "Enter Password"; static const char *timer_message = "LOCKED!"; diff --git a/slock.c b/slock.c @@ -38,10 +38,10 @@ struct lock { int screen; Window root, win; Pixmap pmap; - unsigned long colors[NUMCOLS]; - XftColor xftcolor; XftDraw *xftdraw; XftFont *xftfont; + XftColor colors[NUMCOLS]; + unsigned long bgcolor; }; struct xrandr { @@ -53,7 +53,7 @@ struct xrandr { #include "config.h" static void -drawtext(Display *dpy, struct lock *lock, const char *text) +drawtext(Display *dpy, struct lock *lock, const char *text, int color) { int w, h, x, y; XGlyphInfo extents; @@ -70,7 +70,7 @@ drawtext(Display *dpy, struct lock *lock, const char *text) x = (DisplayWidth(dpy, lock->screen) - w) / 2; y = (DisplayHeight(dpy, lock->screen) - h) / 2 + lock->xftfont->ascent; - XftDrawStringUtf8(lock->xftdraw, &lock->xftcolor, lock->xftfont, x, y, + XftDrawStringUtf8(lock->xftdraw, &lock->colors[color], lock->xftfont, x, y, (const XftChar8 *)text, strlen(text)); } @@ -89,9 +89,6 @@ initxftfont(Display *dpy, struct lock *lock) XFT_SIZE, XftTypeDouble, 16.0, NULL); } - - XftColorAllocName(dpy, DefaultVisual(dpy, lock->screen), - DefaultColormap(dpy, lock->screen), fontcolor, &lock->xftcolor); } static void @@ -116,7 +113,7 @@ locktimer(Display *dpy, struct lock **locks, int nscreens, int timeout) m = remaining / 60; s = remaining % 60; snprintf(timer_text, sizeof(timer_text), "%s %d:%02d remaining", timer_message, m, s); - drawtext(dpy, locks[screen], timer_text); + drawtext(dpy, locks[screen], timer_text, INIT); } while (XPending(dpy)) @@ -127,7 +124,7 @@ locktimer(Display *dpy, struct lock **locks, int nscreens, int timeout) } for (screen = 0; screen < nscreens; screen++) - drawtext(dpy, locks[screen], message); + drawtext(dpy, locks[screen], message, INIT); } static void @@ -277,10 +274,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT); if (running && oldc != color) { for (screen = 0; screen < nscreens; screen++) { - XSetWindowBackground(dpy, - locks[screen]->win, - locks[screen]->colors[color]); - drawtext(dpy, locks[screen], message); + drawtext(dpy, locks[screen], message, color); } oldc = color; } @@ -295,7 +289,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, else XResizeWindow(dpy, locks[screen]->win, rre->width, rre->height); - drawtext(dpy, locks[screen], message); + drawtext(dpy, locks[screen], message, INIT); break; } } @@ -322,15 +316,18 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) lock->screen = screen; lock->root = RootWindow(dpy, lock->screen); + XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), + bgcolor, &color, &dummy); + lock->bgcolor = color.pixel; + for (i = 0; i < NUMCOLS; i++) { - XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), - colorname[i], &color, &dummy); - lock->colors[i] = color.pixel; + XftColorAllocName(dpy, DefaultVisual(dpy, lock->screen), + DefaultColormap(dpy, lock->screen), colorname[i], &lock->colors[i]); } /* init */ wa.override_redirect = 1; - wa.background_pixel = lock->colors[INIT]; + wa.background_pixel = lock->bgcolor; lock->win = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen),