~kris/suckless

slock

74c66223a5743aba14789cfb07ffae1e9d4d6bc8 — bakkeby 6 years ago c07648d
Adding blur pixelated screen patch
M README.md => README.md +4 -1
@@ 15,7 15,7 @@ Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/) 

### Changelog:

2020-08-03 - Added keypress_feedback patch
2020-08-03 - Added keypress_feedback and blur_pixelated_screen patches

2019-11-27 - Added xresources patch



@@ 25,6 25,9 @@ Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/) 

### Patches included:

   - [blur_pixelated_screen](https://tools.suckless.org/slock/patches/blur-pixelated-screen/)
      - sets the lockscreen picture to a blured or pixelated screenshot

   - [capscolor](https://tools.suckless.org/slock/patches/capscolor/)
      - adds an additional color to indicate the state of Caps Lock


M config.def.h => config.def.h +11 -0
@@ 37,6 37,17 @@ ResourcePref resources[] = {
/* treat a cleared input like a wrong password (color) */
static const int failonclear = 1;

#if BLUR_PIXELATED_SCREEN_PATCH
/* Enable blur */
#define BLUR
/* Set blur radius */
static const int blurRadius=5;
/* Enable Pixelation */
//#define PIXELATION
/* Set pixelation radius */
static const int pixelSize=10;
#endif // BLUR_PIXELATED_SCREEN_PATCH

#if CONTROLCLEAR_PATCH
/* allow control key to trigger fail on clear */
static const int controlkeyclear = 0;

M config.mk => config.mk +4 -1
@@ 16,9 16,12 @@ X11LIB = /usr/X11R6/lib
# Uncomment for pam auth patch / PAMAUTH_PATCH
#PAM=-lpam

# Uncomment for blur pixelated screen patch / BLUR_PIXELATED_SCREEN_PATCH
#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}
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr ${XINERAMA} ${PAM} ${IMLIB}

# flags
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H

A patch/blur_pixelated_screen.c => patch/blur_pixelated_screen.c +70 -0
@@ 0,0 1,70 @@
#include <Imlib2.h>

Imlib_Image image;

void
render_lock_image(Display *dpy, struct lock *lock, Imlib_Image image)
{
	if (image) {
		lock->bgmap = XCreatePixmap(dpy, lock->root, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), DefaultDepth(dpy, lock->screen));
		imlib_context_set_image(image);
		imlib_context_set_display(dpy);
		imlib_context_set_visual(DefaultVisual(dpy, lock->screen));
		imlib_context_set_colormap(DefaultColormap(dpy, lock->screen));
		imlib_context_set_drawable(lock->bgmap);
		imlib_render_image_on_drawable(0, 0);
		imlib_free_image();
	}
}

void
create_lock_image(Display *dpy)
{
	/* Create screenshot Image */
	Screen *scr = ScreenOfDisplay(dpy, DefaultScreen(dpy));
	image = imlib_create_image(scr->width,scr->height);
	imlib_context_set_image(image);
	imlib_context_set_display(dpy);
	imlib_context_set_visual(DefaultVisual(dpy,0));
	imlib_context_set_drawable(RootWindow(dpy,XScreenNumberOfScreen(scr)));
	imlib_copy_drawable_to_image(0,0,0,scr->width,scr->height,0,0,1);

	#ifdef BLUR
	/* Blur function */
	imlib_image_blur(blurRadius);
	#endif // BLUR

	#ifdef PIXELATION
	/* Pixelation */
	int width = scr->width;
	int height = scr->height;

	for (int y = 0; y < height; y += pixelSize) {
		for (int x = 0; x < width; x += pixelSize) {
			int red = 0;
			int green = 0;
			int blue = 0;

			Imlib_Color pixel;
			Imlib_Color* pp;
			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);
					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 = 0;
			green = 0;
			blue = 0;
		}
	}
	#endif
}
\ No newline at end of file

A patch/blur_pixelated_screen.h => patch/blur_pixelated_screen.h +4 -0
@@ 0,0 1,4 @@
#include <Imlib2.h>

static void create_lock_image(Display *dpy);
static void render_lock_image(Display *dpy, struct lock *lock, Imlib_Image image);
\ No newline at end of file

M patch/include.c => patch/include.c +4 -0
@@ 1,4 1,8 @@
/* Patches */
#if BLUR_PIXELATED_SCREEN_PATCH
#include "blur_pixelated_screen.c"
#endif

#if MESSAGE_PATCH
#include "message.c"
#endif

M patch/include.h => patch/include.h +4 -0
@@ 1,4 1,8 @@
/* Patches */
#if BLUR_PIXELATED_SCREEN_PATCH
#include "blur_pixelated_screen.h"
#endif

#if PAMAUTH_PATCH
#include "pamauth.h"
#endif

M patches.def.h => patches.def.h +7 -0
@@ 9,6 9,13 @@

/* Patches */

/* This patch sets the lockscreen picture to a blured or pixelated screenshot.
 * This patch depends on the Imlib2 library, uncomment the relevant line in
 * config.mk when enabling this patch.
 * https://tools.suckless.org/slock/patches/blur-pixelated-screen/
 */
#define BLUR_PIXELATED_SCREEN_PATCH 0

/* This patch introduces an additional color to indicate the state of Caps Lock.
 * https://tools.suckless.org/slock/patches/capscolor/
 */

M slock.c => slock.c +22 -0
@@ 65,6 65,9 @@ struct lock {
	int screen;
	Window root, win;
	Pixmap pmap;
	#if BLUR_PIXELATED_SCREEN_PATCH
	Pixmap bgmap;
	#endif // BLUR_PIXELATED_SCREEN_PATCH
	unsigned long colors[NUMCOLS];
};



@@ 321,9 324,16 @@ 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 (locks[screen]->bgmap)
						XSetWindowBackgroundPixmap(dpy, locks[screen]->win, locks[screen]->bgmap);
					else
						XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]);
					#else
					XSetWindowBackground(dpy,
					                     locks[screen]->win,
					                     locks[screen]->colors[color]);
					#endif // BLUR_PIXELATED_SCREEN_PATCH
					XClearWindow(dpy, locks[screen]->win);
					#if MESSAGE_PATCH
					writemessage(dpy, locks[screen]->win, screen);


@@ 369,6 379,10 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
	lock->screen = screen;
	lock->root = RootWindow(dpy, lock->screen);

	#if BLUR_PIXELATED_SCREEN_PATCH
	render_lock_image(dpy, lock, image);
	#endif // BLUR_PIXELATED_SCREEN_PATCH

	for (i = 0; i < NUMCOLS; i++) {
		XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen),
		                 colorname[i], &color, &dummy);


@@ 385,6 399,10 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
	                          CopyFromParent,
	                          DefaultVisual(dpy, lock->screen),
	                          CWOverrideRedirect | CWBackPixel, &wa);
	#if BLUR_PIXELATED_SCREEN_PATCH
	if (lock->bgmap)
		XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap);
	#endif // BLUR_PIXELATED_SCREEN_PATCH
	lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
	invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap,
	                                &color, &color, 0, 0);


@@ 528,6 546,10 @@ main(int argc, char **argv) {
	if (setuid(duid) < 0)
		die("slock: setuid: %s\n", strerror(errno));

	#if BLUR_PIXELATED_SCREEN_PATCH
	create_lock_image(dpy);
	#endif // BLUR_PIXELATED_SCREEN_PATCH

	#if XRESOURCES_PATCH
	config_init(dpy);
	#endif // XRESOURCES_PATCH