slock

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit e5e04272d1bc7b0f39a942d99cac3ab78bbf9859
parent e5a9d8539b2ec56aacb1db455a4235e4d1ff41ca
Author: bakkeby <bakkeby@gmail.com>
Date:   Mon, 13 Sep 2021 10:48:56 +0200

Adding dwmlogo patch ref. #5

Diffstat:
MREADME.md | 5+++++
Mconfig.def.h | 30++++++++++++++++++++++++++++--
Mconfig.mk | 9+++++----
Mpatch/blur_pixelated_screen.c | 12++++++------
Apatch/dwmlogo.c | 30++++++++++++++++++++++++++++++
Apatch/dwmlogo.h | 3+++
Mpatch/include.c | 4++++
Mpatch/include.h | 8++++----
Mpatch/xresources.c | 3++-
Dpatch/xresources.h | 18------------------
Mpatches.def.h | 5+++++
Mslock.c | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
12 files changed, 181 insertions(+), 39 deletions(-)

diff --git a/README.md b/README.md @@ -26,6 +26,8 @@ slock tool, how to install it and how it works. ### Changelog: +2021-09-13 - Added the dwm logo patch + 2021-09-09 - Added the auto-timeout, failure-command and secret-password patches 2021-06-08 - Added the color message patch @@ -69,6 +71,9 @@ slock tool, how to install it and how it works. - the monitor will automatically be activated by pressing a key or moving the mouse and the password can be entered then + - [dwmlogo](https://tools.suckless.org/slock/patches/dwmlogo/) + - draws the dwm logo which changes color based on the state + - [failure-command](https://tools.suckless.org/slock/patches/failure-command/) - allows for a command to be run after a specified number of incorrect attempts diff --git a/config.def.h b/config.def.h @@ -3,6 +3,9 @@ static const char *user = "nobody"; static const char *group = "nogroup"; // use "nobody" for arch static const char *colorname[NUMCOLS] = { + #if DWM_LOGO_PATCH + [BACKGROUND] = "#2d2d2d", /* after initialization */ + #endif // DWM_LOGO_PATCH [INIT] = "black", /* after initialization */ [INPUT] = "#005577", /* during input */ [FAILED] = "#CC3333", /* wrong password */ @@ -28,11 +31,34 @@ static const char * text_color = "#ffffff"; static const char * font_name = "6x10"; #endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH +#if DWM_LOGO_PATCH +/* insert grid pattern with scale 1:1, the size can be changed with logosize */ +static const int logosize = 75; +static const int logow = 12; /* grid width and height for right center alignment*/ +static const int logoh = 6; + +static XRectangle rectangles[] = { + /* x y w h */ + { 0, 3, 1, 3 }, + { 1, 3, 2, 1 }, + { 0, 5, 8, 1 }, + { 3, 0, 1, 5 }, + { 5, 3, 1, 2 }, + { 7, 3, 1, 2 }, + { 8, 3, 4, 1 }, + { 9, 4, 1, 2 }, + { 11, 4, 1, 2 }, +}; +#endif // DWM_LOGO_PATCH + #if XRESOURCES_PATCH /* * Xresources preferences to load at startup */ ResourcePref resources[] = { + #if DWM_LOGO_PATCH + { "color2", STRING, &colorname[BACKGROUND] }, + #endif //DWM_LOGO_PATCH { "color0", STRING, &colorname[INIT] }, { "color4", STRING, &colorname[INPUT] }, { "color1", STRING, &colorname[FAILED] }, @@ -87,11 +113,11 @@ static const secretpass scom[] = { /* Enable blur */ #define BLUR /* Set blur radius */ -static const int blurRadius=5; +static const int blurRadius = 5; /* Enable Pixelation */ //#define PIXELATION /* Set pixelation radius */ -static const int pixelSize=10; +static const int pixelSize = 10; #endif // BLUR_PIXELATED_SCREEN_PATCH #if CONTROLCLEAR_PATCH diff --git a/config.mk b/config.mk @@ -10,21 +10,22 @@ MANPREFIX = ${PREFIX}/share/man X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib -# Uncomment for message patch / MESSAGE_PATCH / COLORMESSAGE_PATCH -#XINERAMA=-lXinerama +# Uncomment for message patch / MESSAGE_PATCH / COLORMESSAGE_PATCH / DWM_LOGO_PATCH +XINERAMA=-lXinerama +XINERAMAFLAGS = -DXINERAMA # Uncomment for pam auth patch / PAMAUTH_PATCH #PAM=-lpam # Uncomment for blur pixelated screen patch / BLUR_PIXELATED_SCREEN_PATCH -#IMLIB=-lImlib2 +IMLIB=-lImlib2 # includes and libs INCS = -I. -I/usr/include -I${X11INC} LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr ${XINERAMA} ${PAM} ${IMLIB} # flags -CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H +CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H ${XINERAMAFLAGS} CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} LDFLAGS = -s ${LIBS} COMPATSRC = explicit_bzero.c diff --git a/patch/blur_pixelated_screen.c b/patch/blur_pixelated_screen.c @@ -50,17 +50,17 @@ create_lock_image(Display *dpy) pp = &pixel; for (int j = 0; j < pixelSize && j < height; j++) { for (int i = 0; i < pixelSize && i < width; i++) { - imlib_image_query_pixel(x+i,y+j,pp); + imlib_image_query_pixel(x + i, y + j, pp); red += pixel.red; green += pixel.green; blue += pixel.blue; } } - red /= (pixelSize*pixelSize); - green /= (pixelSize*pixelSize); - blue /= (pixelSize*pixelSize); - imlib_context_set_color(red,green,blue,pixel.alpha); - imlib_image_fill_rectangle(x,y,pixelSize,pixelSize); + red /= (pixelSize * pixelSize); + green /= (pixelSize * pixelSize); + blue /= (pixelSize * pixelSize); + imlib_context_set_color(red, green, blue, pixel.alpha); + imlib_image_fill_rectangle(x, y, pixelSize, pixelSize); red = 0; green = 0; blue = 0; diff --git a/patch/dwmlogo.c b/patch/dwmlogo.c @@ -0,0 +1,29 @@ +static void +resizerectangles(struct lock *lock) +{ + int i; + + for (i = 0; i < LENGTH(rectangles); i++){ + lock->rectangles[i].x = (rectangles[i].x * logosize) + + lock->xoff + ((lock->mw) / 2) - (logow / 2 * logosize); + lock->rectangles[i].y = (rectangles[i].y * logosize) + + lock->yoff + ((lock->mh) / 2) - (logoh / 2 * logosize); + lock->rectangles[i].width = rectangles[i].width * logosize; + lock->rectangles[i].height = rectangles[i].height * logosize; + } +} + +static void +drawlogo(Display *dpy, struct lock *lock, int color) +{ + #if BLUR_PIXELATED_SCREEN_PATCH + lock->drawable = lock->bgmap; + #else + XSetForeground(dpy, lock->gc, lock->colors[BACKGROUND]); + XFillRectangle(dpy, lock->drawable, lock->gc, 0, 0, lock->x, lock->y); + #endif // BLUR_PIXELATED_SCREEN_PATCH + XSetForeground(dpy, lock->gc, lock->colors[color]); + XFillRectangles(dpy, lock->drawable, lock->gc, lock->rectangles, LENGTH(rectangles)); + XCopyArea(dpy, lock->drawable, lock->win, lock->gc, 0, 0, lock->x, lock->y, 0, 0); + XSync(dpy, False); +} +\ No newline at end of file diff --git a/patch/dwmlogo.h b/patch/dwmlogo.h @@ -0,0 +1,2 @@ +static void resizerectangles(struct lock *lock); +static void drawlogo(Display *dpy, struct lock *lock, int color); +\ No newline at end of file diff --git a/patch/include.c b/patch/include.c @@ -9,6 +9,10 @@ #include "message.c" #endif +#if DWM_LOGO_PATCH +#include "dwmlogo.c" +#endif + #if KEYPRESS_FEEDBACK_PATCH #include "keypress_feedback.c" #endif diff --git a/patch/include.h b/patch/include.h @@ -3,14 +3,14 @@ #include "blur_pixelated_screen.h" #endif +#if DWM_LOGO_PATCH +#include "dwmlogo.h" +#endif + #if PAMAUTH_PATCH #include "pamauth.h" #endif #if KEYPRESS_FEEDBACK_PATCH #include "keypress_feedback.h" -#endif - -#if XRESOURCES_PATCH -#include "xresources.h" #endif \ No newline at end of file diff --git a/patch/xresources.c b/patch/xresources.c @@ -1,3 +1,4 @@ +#include <X11/Xresource.h> #include <math.h> int @@ -47,6 +48,6 @@ config_init(Display *dpy) return; db = XrmGetStringDatabase(resm); - for (p = resources; p < resources + LEN(resources); p++) + for (p = resources; p < resources + LENGTH(resources); p++) resource_load(db, p->name, p->type, p->dst); } diff --git a/patch/xresources.h b/patch/xresources.h @@ -1,17 +0,0 @@ -#include <X11/Xresource.h> - -/* macros */ -#define LEN(a) (sizeof(a) / sizeof(a)[0]) - -/* Xresources preferences */ -enum resource_type { - STRING = 0, - INTEGER = 1, - FLOAT = 2 -}; - -typedef struct { - char *name; - enum resource_type type; - void *dst; -} ResourcePref; -\ No newline at end of file diff --git a/patches.def.h b/patches.def.h @@ -65,6 +65,11 @@ */ #define DPMS_PATCH 0 +/* This patch draws the dwm logo which changes color based on the state. + * https://tools.suckless.org/slock/patches/dwmlogo/ + */ +#define DWM_LOGO_PATCH 0 + /* This patch allows for a command to be run after a specified number of incorrect attempts. * https://tools.suckless.org/slock/patches/failure-command/ */ diff --git a/slock.c b/slock.c @@ -39,6 +39,9 @@ #if DPMS_PATCH #include <X11/extensions/dpms.h> #endif // DPMS_PATCH +#ifdef XINERAMA +#include <X11/extensions/Xinerama.h> +#endif #include "arg.h" #include "util.h" @@ -57,6 +60,9 @@ static time_t locktime; #endif // QUICKCANCEL_PATCH enum { + #if DWM_LOGO_PATCH && !BLUR_PIXELATED_SCREEN_PATCH + BACKGROUND, + #endif // DWM_LOGO_PATCH INIT, INPUT, FAILED, @@ -72,6 +78,23 @@ enum { NUMCOLS }; +#if XRESOURCES_PATCH +/* Xresources preferences */ +enum resource_type { + STRING = 0, + INTEGER = 1, + FLOAT = 2 +}; + +typedef struct { + char *name; + enum resource_type type; + void *dst; +} ResourcePref; +#endif // XRESOURCES_PATCH + +#include "config.h" + struct lock { int screen; Window root, win; @@ -80,6 +103,13 @@ struct lock { Pixmap bgmap; #endif // BLUR_PIXELATED_SCREEN_PATCH unsigned long colors[NUMCOLS]; + #if DWM_LOGO_PATCH + unsigned int x, y; + unsigned int xoff, yoff, mw, mh; + Drawable drawable; + GC gc; + XRectangle rectangles[LENGTH(rectangles)]; + #endif // DWM_LOGO_PATCH }; #if SECRET_PASSWORD_PATCH @@ -97,7 +127,6 @@ struct xrandr { }; #include "patch/include.h" -#include "config.h" static void die(const char *errstr, ...) @@ -377,17 +406,20 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, #endif // CAPSCOLOR_PATCH if (running && oldc != color) { for (screen = 0; screen < nscreens; screen++) { - #if BLUR_PIXELATED_SCREEN_PATCH + #if DWM_LOGO_PATCH + drawlogo(dpy, locks[screen], color); + #elif BLUR_PIXELATED_SCREEN_PATCH if (locks[screen]->bgmap) XSetWindowBackgroundPixmap(dpy, locks[screen]->win, locks[screen]->bgmap); else XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]); + XClearWindow(dpy, locks[screen]->win); #else XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[color]); - #endif // BLUR_PIXELATED_SCREEN_PATCH XClearWindow(dpy, locks[screen]->win); + #endif // BLUR_PIXELATED_SCREEN_PATCH #if MESSAGE_PATCH || COLOR_MESSAGE_PATCH writemessage(dpy, locks[screen]->win, screen); #endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH @@ -439,7 +471,12 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) XColor color, dummy; XSetWindowAttributes wa; Cursor invisible; - + #if DWM_LOGO_PATCH + #ifdef XINERAMA + XineramaScreenInfo *info; + int n; + #endif + #endif // DWM_LOGO_PATCH #if AUTO_TIMEOUT_PATCH time(&lasttouched); #endif // AUTO_TIMEOUT_PATCH @@ -460,12 +497,43 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) lock->colors[i] = color.pixel; } + #if DWM_LOGO_PATCH + lock->x = DisplayWidth(dpy, lock->screen); + lock->y = DisplayHeight(dpy, lock->screen); + #ifdef XINERAMA + if ((info = XineramaQueryScreens(dpy, &n))) { + lock->xoff = info[0].x_org; + lock->yoff = info[0].y_org; + lock->mw = info[0].width; + lock->mh = info[0].height; + } else + #endif // XINERAMA + { + lock->xoff = lock->yoff = 0; + lock->mw = lock->x; + lock->mh = lock->y; + } + lock->drawable = XCreatePixmap(dpy, lock->root, lock->x, lock->y, DefaultDepth(dpy, screen)); + lock->gc = XCreateGC(dpy, lock->root, 0, NULL); + XSetLineAttributes(dpy, lock->gc, 1, LineSolid, CapButt, JoinMiter); + #endif // DWM_LOGO_PATCH + /* init */ wa.override_redirect = 1; + #if DWM_LOGO_PATCH && BLUR_PIXELATED_SCREEN_PATCH + #elif DWM_LOGO_PATCH + wa.background_pixel = lock->colors[BACKGROUND]; + #else wa.background_pixel = lock->colors[INIT]; + #endif // DWM_LOGO_PATCH lock->win = XCreateWindow(dpy, lock->root, 0, 0, + #if DWM_LOGO_PATCH + lock->x, + lock->y, + #else DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), + #endif // DWM_LOGO_PATCH 0, DefaultDepth(dpy, lock->screen), CopyFromParent, DefaultVisual(dpy, lock->screen), @@ -479,6 +547,10 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) &color, &color, 0, 0); XDefineCursor(dpy, lock->win, invisible); + #if DWM_LOGO_PATCH + resizerectangles(lock); + #endif // DWM_LOGO_PATCH + /* Try to grab mouse pointer *and* keyboard for 600ms, else fail the lock */ for (i = 0, ptgrab = kbgrab = -1; i < 6; i++) { if (ptgrab != GrabSuccess) { @@ -510,6 +582,9 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) #if QUICKCANCEL_PATCH locktime = time(NULL); #endif // QUICKCANCEL_PATCH + #if DWM_LOGO_PATCH + drawlogo(dpy, lock, INIT); + #endif // DWM_LOGO_PATCH #if ALPHA_PATCH unsigned int opacity = (unsigned int)(alpha * 0xffffffff); XChangeProperty(dpy, lock->win, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False), XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1L); @@ -696,5 +771,15 @@ main(int argc, char **argv) { XSync(dpy, 0); #endif // DPMS_PATCH + #if DWM_LOGO_PATCH + for (nlocks = 0, s = 0; s < nscreens; s++) { + XFreePixmap(dpy, locks[s]->drawable); + XFreeGC(dpy, locks[s]->gc); + } + + XSync(dpy, 0); + XCloseDisplay(dpy); + #endif // DWM_LOGO_PATCH + return 0; }