slock

fork of slock
git clone git://popovic.xyz/slock.git
Log | Files | Refs | README | LICENSE

commit 5098182bc2019f6040de7892fb0d05111ecb2bbe
parent 6e61eaf94bc625cf85b5f9cfc29a9e82020c250f
Author: Milutin Popovic <mika@popovic.xyz>
Date:   Tue, 18 Nov 2025 20:46:45 +0000

enable pixels

Diffstat:
Mconfig.h | 22+++++++++++++++++-----
Mslock | 0
Mslock.c | 72+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mslock.o | 0
Mutil.h | 3+++
5 files changed, 91 insertions(+), 6 deletions(-)

diff --git a/config.h b/config.h @@ -13,10 +13,10 @@ static const char *colorname[NUMCOLS] = { /* treat a cleared input like a wrong password (color) */ static const int failonclear = 1; -static const int monitortime = 5; +static const int monitortime = 600; -static const int logosize = 75; -static const int logow = 12; /* Grid width and height for right center alignment*/ +static const int logosize = 50; +static const int logow = 9; /* Grid width and height for right center alignment*/ static const int logoh = 6; static XRectangle rectangles[9] = { @@ -35,6 +35,18 @@ static XRectangle rectangles[9] = { /*Set blur radius*/ static const int blurRadius=10; /*Enable Pixelation*/ -//#define PIXELATION +#define PIXELATION /*Set pixelation radius*/ -static const int pixelSize=100; +static const int pixelSize=10; + +/* + * Xresources preferences to load at startup + */ +ResourcePref resources[] = { + { "color_background", STRING, &colorname[BACKGROUND] }, + { "color_init", STRING, &colorname[INIT] }, + { "color_input", STRING, &colorname[INPUT] }, + { "color_failed", STRING, &colorname[FAILED] }, + { "color_caps", STRING, &colorname[CAPS] }, +}; + diff --git a/slock b/slock Binary files differ. diff --git a/slock.c b/slock.c @@ -7,6 +7,7 @@ #include <ctype.h> #include <errno.h> +#include <math.h> #include <grp.h> #include <pwd.h> #include <stdarg.h> @@ -25,6 +26,7 @@ #include <X11/Xutil.h> #include <X11/XKBlib.h> #include <X11/Xmd.h> +#include <X11/Xresource.h> #include <X11/extensions/dpms.h> #include <Imlib2.h> @@ -43,6 +45,19 @@ enum { NUMCOLS }; +/* Xresources preferences */ +enum resource_type { + STRING = 0, + INTEGER = 1, + FLOAT = 2 +}; + +typedef struct { + char *name; + enum resource_type type; + void *dst; +} ResourcePref; + #include "config.h" struct lock { @@ -340,8 +355,10 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) CopyFromParent, DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa); - if(lock->bgmap) + if(lock->bgmap) { XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap); + } + lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8); invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, &color, 0, 0); @@ -391,6 +408,57 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) return NULL; } +int +resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst) +{ + char **sdst = dst; + int *idst = dst; + float *fdst = dst; + + char fullname[256]; + char fullclass[256]; + char *type; + XrmValue ret; + + snprintf(fullname, sizeof(fullname), "%s.%s", "slock", name); + snprintf(fullclass, sizeof(fullclass), "%s.%s", "Slock", name); + fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0'; + + XrmGetResource(db, fullname, fullclass, &type, &ret); + if (ret.addr == NULL || strncmp("String", type, 64)) + return 1; + + switch (rtype) { + case STRING: + *sdst = ret.addr; + break; + case INTEGER: + *idst = strtoul(ret.addr, NULL, 10); + break; + case FLOAT: + *fdst = strtof(ret.addr, NULL); + break; + } + return 0; +} + +void +config_init(Display *dpy) +{ + char *resm; + XrmDatabase db; + ResourcePref *p; + + XrmInitialize(); + resm = XResourceManagerString(dpy); + if (!resm) + return; + + db = XrmGetStringDatabase(resm); + for (p = resources; p < resources + LEN(resources); p++) + resource_load(db, p->name, p->type, p->dst); +} + static void usage(void) { @@ -451,6 +519,8 @@ main(int argc, char **argv) { if (setuid(duid) < 0) die("slock: setuid: %s\n", strerror(errno)); + config_init(dpy); + /*Create screenshot Image*/ Screen *scr = ScreenOfDisplay(dpy, DefaultScreen(dpy)); image = imlib_create_image(scr->width,scr->height); diff --git a/slock.o b/slock.o Binary files differ. diff --git a/util.h b/util.h @@ -1,2 +1,5 @@ +/* macros */ +#define LEN(a) (sizeof(a) / sizeof(a)[0]) + #undef explicit_bzero void explicit_bzero(void *, size_t);