sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

slock-dwmlogoandblurscreen-1.0.diff (9888B)


      1 diff -u ../slock-orig/config.def.h ./config.def.h
      2 --- ../slock-orig/config.def.h	2022-04-29 17:07:13.872268452 -0400
      3 +++ ./config.def.h	2022-04-29 16:44:38.573566776 -0400
      4 @@ -3,10 +3,36 @@
      5  static const char *group = "nogroup";
      6  
      7  static const char *colorname[NUMCOLS] = {
      8 -	[INIT] =   "black",     /* after initialization */
      9 +    [BACKGROUND] = "white",
     10 +	[INIT] =   "2d2d2d",     /* after initialization */
     11  	[INPUT] =  "#005577",   /* during input */
     12  	[FAILED] = "#CC3333",   /* wrong password */
     13  };
     14  
     15  /* treat a cleared input like a wrong password (color) */
     16  static const int failonclear = 1;
     17 +
     18 +static const int logosize = 75;
     19 +static const int logow = 12; /* Grid width and height for right center alignment*/
     20 +static const int logoh = 6;
     21 +
     22 +static XRectangle rectangles[9] = {
     23 +    {0, 3, 1, 3},
     24 +    {1, 3, 2, 1},
     25 +    {0, 5, 8, 1},
     26 +    {3, 0, 1, 5},
     27 +    {5, 3, 1, 2},
     28 +    {7, 3, 1, 2},
     29 +    {8, 3, 4, 1},
     30 +    {9, 4, 1, 2},
     31 +    {11,4, 1, 2},
     32 +};
     33 +
     34 +/*Enable blur*/
     35 +#define BLUR
     36 +/*Set blur radius*/
     37 +static const int blurRadius=5;
     38 +/*Enable Pixelation*/
     39 +//#define PIXELATION
     40 +/*Set pixelation radius*/
     41 +static const int pixelSize=0;
     42 diff -u ../slock-orig/config.mk ./config.mk
     43 --- ../slock-orig/config.mk	2022-04-29 17:07:13.872268452 -0400
     44 +++ ./config.mk	2022-04-29 17:14:49.416921212 -0400
     45 @@ -10,13 +10,21 @@
     46  X11INC = /usr/X11R6/include
     47  X11LIB = /usr/X11R6/lib
     48  
     49 +# Xinerama, comment if you don't want it
     50 +XINERAMALIBS = -lXinerama
     51 +XINERAMAFLAGS = -DXINERAMA
     52 +
     53 +# freetype
     54 +FREETYPELIBS = -lXft
     55 +FREETYPEINC = /usr/include/freetype2
     56 +
     57  # includes and libs
     58 -INCS = -I. -I/usr/include -I${X11INC}
     59 -LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr
     60 +INCS = -I. -I/usr/include -I${X11INC} -I${FREETYPEINC}
     61 +LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lImlib2 ${XINERAMALIBS} ${FREETYPELIBS} -lXext -lXrandr
     62  
     63  # flags
     64 -CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H
     65 -CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
     66 +CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H ${XINERAMAFLAGS}
     67 +CFLAGS = -std=c99 -pedantic -Wall -Ofast ${INCS} ${CPPFLAGS}
     68  LDFLAGS = -s ${LIBS}
     69  COMPATSRC = explicit_bzero.c
     70  
     71 diff -u ../slock-orig/slock.c ./slock.c
     72 --- ../slock-orig/slock.c	2022-04-29 17:07:13.872268452 -0400
     73 +++ ./slock.c	2022-04-29 17:04:53.424073165 -0400
     74 @@ -1,5 +1,6 @@
     75  /* See LICENSE file for license details. */
     76 -#define _XOPEN_SOURCE 500
     77 +#define _XOPEN_SOURCE   500
     78 +#define LENGTH(X)       (sizeof X / sizeof X[0])
     79  #if HAVE_SHADOW_H
     80  #include <shadow.h>
     81  #endif
     82 @@ -15,9 +16,13 @@
     83  #include <unistd.h>
     84  #include <sys/types.h>
     85  #include <X11/extensions/Xrandr.h>
     86 +#ifdef XINERAMA
     87 +#include <X11/extensions/Xinerama.h>
     88 +#endif
     89  #include <X11/keysym.h>
     90  #include <X11/Xlib.h>
     91  #include <X11/Xutil.h>
     92 +#include <Imlib2.h>
     93  
     94  #include "arg.h"
     95  #include "util.h"
     96 @@ -25,17 +30,26 @@
     97  char *argv0;
     98  
     99  enum {
    100 +    BACKGROUND,
    101  	INIT,
    102  	INPUT,
    103  	FAILED,
    104  	NUMCOLS
    105  };
    106  
    107 +#include "config.h"
    108 +
    109  struct lock {
    110  	int screen;
    111  	Window root, win;
    112  	Pixmap pmap;
    113 +	Pixmap bgmap;
    114  	unsigned long colors[NUMCOLS];
    115 +    unsigned int x, y;
    116 +    unsigned int xoff, yoff, mw, mh;
    117 +    Drawable drawable;
    118 +    GC gc;
    119 +    XRectangle rectangles[LENGTH(rectangles)];
    120  };
    121  
    122  struct xrandr {
    123 @@ -44,7 +58,7 @@
    124  	int errbase;
    125  };
    126  
    127 -#include "config.h"
    128 +Imlib_Image image;
    129  
    130  static void
    131  die(const char *errstr, ...)
    132 @@ -125,6 +139,29 @@
    133  }
    134  
    135  static void
    136 +resizerectangles(struct lock *lock)
    137 +{
    138 +	int i;
    139 +
    140 +	for (i = 0; i < LENGTH(rectangles); i++){
    141 +		lock->rectangles[i].x = (rectangles[i].x * logosize)
    142 +                                + lock->xoff + ((lock->mw) / 2) - (logow / 2 * logosize);
    143 +		lock->rectangles[i].y = (rectangles[i].y * logosize)
    144 +                                + lock->yoff + ((lock->mh) / 2) - (logoh / 2 * logosize);
    145 +		lock->rectangles[i].width = rectangles[i].width * logosize;
    146 +		lock->rectangles[i].height = rectangles[i].height * logosize;
    147 +	}
    148 +}
    149 +
    150 +static void
    151 +drawlogo(Display *dpy, struct lock *lock, int color)
    152 +{
    153 +	XSetForeground(dpy, lock->gc, lock->colors[color]);
    154 +	XFillRectangles(dpy, lock->win, lock->gc, lock->rectangles, LENGTH(rectangles));
    155 +	XSync(dpy, False);
    156 +}
    157 +
    158 +static void
    159  readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
    160         const char *hash)
    161  {
    162 @@ -190,10 +227,12 @@
    163  			color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT);
    164  			if (running && oldc != color) {
    165  				for (screen = 0; screen < nscreens; screen++) {
    166 -					XSetWindowBackground(dpy,
    167 -					                     locks[screen]->win,
    168 -					                     locks[screen]->colors[color]);
    169 -					XClearWindow(dpy, locks[screen]->win);
    170 +                    if(locks[screen]->bgmap)
    171 +                        XSetWindowBackgroundPixmap(dpy, locks[screen]->win, locks[screen]->bgmap);
    172 +                    else
    173 +                        XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]);
    174 +					//XClearWindow(dpy, locks[screen]->win);
    175 +                    drawlogo(dpy, locks[screen], color);
    176  				}
    177  				oldc = color;
    178  			}
    179 @@ -228,6 +267,10 @@
    180  	XColor color, dummy;
    181  	XSetWindowAttributes wa;
    182  	Cursor invisible;
    183 +#ifdef XINERAMA
    184 +	XineramaScreenInfo *info;
    185 +	int n;
    186 +#endif
    187  
    188  	if (dpy == NULL || screen < 0 || !(lock = malloc(sizeof(struct lock))))
    189  		return NULL;
    190 @@ -235,27 +278,61 @@
    191  	lock->screen = screen;
    192  	lock->root = RootWindow(dpy, lock->screen);
    193  
    194 +    if(image) 
    195 +    {
    196 +        lock->bgmap = XCreatePixmap(dpy, lock->root, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), DefaultDepth(dpy, lock->screen));
    197 +        imlib_context_set_image(image);
    198 +        imlib_context_set_display(dpy);
    199 +        imlib_context_set_visual(DefaultVisual(dpy, lock->screen));
    200 +        imlib_context_set_colormap(DefaultColormap(dpy, lock->screen));
    201 +        imlib_context_set_drawable(lock->bgmap);
    202 +        imlib_render_image_on_drawable(0, 0);
    203 +        imlib_free_image();
    204 +    }
    205  	for (i = 0; i < NUMCOLS; i++) {
    206  		XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen),
    207  		                 colorname[i], &color, &dummy);
    208  		lock->colors[i] = color.pixel;
    209  	}
    210  
    211 +	lock->x = DisplayWidth(dpy, lock->screen);
    212 +	lock->y = DisplayHeight(dpy, lock->screen);
    213 +#ifdef XINERAMA
    214 +	if ((info = XineramaQueryScreens(dpy, &n))) {
    215 +		lock->xoff = info[0].x_org;
    216 +		lock->yoff = info[0].y_org;
    217 +		lock->mw = info[0].width;
    218 +		lock->mh = info[0].height;
    219 +	} else
    220 +#endif
    221 +	{
    222 +		lock->xoff = lock->yoff = 0;
    223 +		lock->mw = lock->x;
    224 +		lock->mh = lock->y;
    225 +	}
    226 +	lock->drawable = XCreatePixmap(dpy, lock->root,
    227 +            lock->x, lock->y, DefaultDepth(dpy, screen));
    228 +	lock->gc = XCreateGC(dpy, lock->root, 0, NULL);
    229 +	XSetLineAttributes(dpy, lock->gc, 1, LineSolid, CapButt, JoinMiter);
    230 +
    231  	/* init */
    232  	wa.override_redirect = 1;
    233 -	wa.background_pixel = lock->colors[INIT];
    234 +	wa.background_pixel = lock->colors[BACKGROUND];
    235  	lock->win = XCreateWindow(dpy, lock->root, 0, 0,
    236 -	                          DisplayWidth(dpy, lock->screen),
    237 -	                          DisplayHeight(dpy, lock->screen),
    238 +	                          lock->x, lock->y,
    239  	                          0, DefaultDepth(dpy, lock->screen),
    240  	                          CopyFromParent,
    241  	                          DefaultVisual(dpy, lock->screen),
    242  	                          CWOverrideRedirect | CWBackPixel, &wa);
    243 +    if(lock->bgmap)
    244 +        XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap);
    245  	lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
    246  	invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap,
    247  	                                &color, &color, 0, 0);
    248  	XDefineCursor(dpy, lock->win, invisible);
    249  
    250 +	resizerectangles(lock);
    251 +
    252  	/* Try to grab mouse pointer *and* keyboard for 600ms, else fail the lock */
    253  	for (i = 0, ptgrab = kbgrab = -1; i < 6; i++) {
    254  		if (ptgrab != GrabSuccess) {
    255 @@ -276,6 +353,7 @@
    256  				XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask);
    257  
    258  			XSelectInput(dpy, lock->root, SubstructureNotifyMask);
    259 +			drawlogo(dpy, lock, INIT);
    260  			return lock;
    261  		}
    262  
    263 @@ -355,6 +433,60 @@
    264  	if (setuid(duid) < 0)
    265  		die("slock: setuid: %s\n", strerror(errno));
    266  
    267 +	/*Create screenshot Image*/
    268 +	Screen *scr = ScreenOfDisplay(dpy, DefaultScreen(dpy));
    269 +	image = imlib_create_image(scr->width,scr->height);
    270 +	imlib_context_set_image(image);
    271 +	imlib_context_set_display(dpy);
    272 +	imlib_context_set_visual(DefaultVisual(dpy,0));
    273 +	imlib_context_set_drawable(RootWindow(dpy,XScreenNumberOfScreen(scr)));	
    274 +	imlib_copy_drawable_to_image(0,0,0,scr->width,scr->height,0,0,1);
    275 +
    276 +#ifdef BLUR
    277 +
    278 +	/*Blur function*/
    279 +	imlib_image_blur(blurRadius);
    280 +#endif // BLUR	
    281 +
    282 +#ifdef PIXELATION
    283 +	/*Pixelation*/
    284 +	int width = scr->width;
    285 +	int height = scr->height;
    286 +	
    287 +	for(int y = 0; y < height; y += pixelSize)
    288 +	{
    289 +		for(int x = 0; x < width; x += pixelSize)
    290 +		{
    291 +			int red = 0;
    292 +			int green = 0;
    293 +			int blue = 0;
    294 +
    295 +			Imlib_Color pixel; 
    296 +			Imlib_Color* pp;
    297 +			pp = &pixel;
    298 +			for(int j = 0; j < pixelSize && j < height; j++)
    299 +			{
    300 +				for(int i = 0; i < pixelSize && i < width; i++)
    301 +				{
    302 +					imlib_image_query_pixel(x+i,y+j,pp);
    303 +					red += pixel.red;
    304 +					green += pixel.green;
    305 +					blue += pixel.blue;
    306 +				}
    307 +			}
    308 +			red /= (pixelSize*pixelSize);
    309 +			green /= (pixelSize*pixelSize);
    310 +			blue /= (pixelSize*pixelSize);
    311 +			imlib_context_set_color(red,green,blue,pixel.alpha);
    312 +			imlib_image_fill_rectangle(x,y,pixelSize,pixelSize);
    313 +			red = 0;
    314 +			green = 0;
    315 +			blue = 0;
    316 +		}
    317 +	}
    318 +	
    319 +	
    320 +#endif
    321  	/* check for Xrandr support */
    322  	rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
    323  
    324 @@ -391,5 +523,12 @@
    325  	/* everything is now blank. Wait for the correct password */
    326  	readpw(dpy, &rr, locks, nscreens, hash);
    327  
    328 +	for (nlocks = 0, s = 0; s < nscreens; s++) {
    329 +		XFreePixmap(dpy, locks[s]->drawable);
    330 +		XFreeGC(dpy, locks[s]->gc);
    331 +	}
    332 +
    333 +	XSync(dpy, 0);
    334 +	XCloseDisplay(dpy);
    335  	return 0;
    336  }