4 Commits

Author SHA1 Message Date
Sravan Balaji
44a8517dd5 README Update
- Add list of personal modifications
- Convert to markdown
2020-08-01 23:14:32 -04:00
Sravan Balaji
76df5beac4 Add dpms patch
- Add timeout after lock screen starts to turn off monitor
2020-08-01 00:38:46 -04:00
Sravan Balaji
47c9f85af5 Add blurred or pixelated screenshot patch
- Lockscreen is blurred & pixelated version of current screen
2020-08-01 00:20:38 -04:00
Sravan Balaji
dee1d27806 gitignore and user/group config
- Add gitignore for generated files and executable
- Add user and group to config.h
2020-07-31 23:57:58 -04:00
6 changed files with 160 additions and 29 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.vscode/
*.o
slock

24
README
View File

@@ -1,24 +0,0 @@
slock - simple screen locker
============================
simple screen locker utility for X.
Requirements
------------
In order to build slock you need the Xlib header files.
Installation
------------
Edit config.mk to match your local setup (slock is installed into
the /usr/local namespace by default).
Afterwards enter the following command to build and install slock
(if necessary as root):
make clean install
Running slock
-------------
Simply invoke the 'slock' command. To get out of it, enter your password.

35
README.md Normal file
View File

@@ -0,0 +1,35 @@
# Sravan's slock - simple screen locker
[slock](https://tools.suckless.org/slock/) is a simple screen locker utility for X.
This is Sravan's fork of slock with patches and custom modifications.
## slock Information
### Requirements
In order to build slock you need the Xlib header files.
### Installation
Edit config.mk to match your local setup (slock is installed into
the /usr/local namespace by default).
Afterwards enter the following command to build and install slock
(if necessary as root):
make clean install
### Running slock
Simply invoke the 'slock' command. To get out of it, enter your password.
## Personal Modifications
### Patches
* [blur pixelated screen](https://tools.suckless.org/slock/patches/blur-pixelated-screen/)
* [dpms](https://tools.suckless.org/slock/patches/dpms/)
### Modifications
* Update user and group in config

25
config.h Normal file
View File

@@ -0,0 +1,25 @@
/* user and group to drop privileges to */
static const char *user = "sravan";
static const char *group = "sravan";
static const char *colorname[NUMCOLS] = {
[INIT] = "black", /* after initialization */
[INPUT] = "#005577", /* during input */
[FAILED] = "#CC3333", /* wrong password */
};
/* treat a cleared input like a wrong password (color) */
static const int failonclear = 1;
/* time in seconds before the monitor shuts down */
static const int monitortime = 5;
/*Enable blur*/
#define BLUR
/*Set blur radius*/
static const int blurRadius=15;
/*Enable Pixelation*/
#define PIXELATION
/*Set pixelation radius*/
static const int pixelSize=10;

View File

@@ -12,11 +12,11 @@ X11LIB = /usr/X11R6/lib
# includes and libs # includes and libs
INCS = -I. -I/usr/include -I${X11INC} INCS = -I. -I/usr/include -I${X11INC}
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr -lImlib2
# flags # flags
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} CFLAGS = -std=c99 -pedantic -Wall -Ofast ${INCS} ${CPPFLAGS}
LDFLAGS = -s ${LIBS} LDFLAGS = -s ${LIBS}
COMPATSRC = explicit_bzero.c COMPATSRC = explicit_bzero.c

98
slock.c
View File

@@ -15,9 +15,11 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
#include <X11/extensions/dpms.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <Imlib2.h>
#include "arg.h" #include "arg.h"
#include "util.h" #include "util.h"
@@ -35,6 +37,7 @@ struct lock {
int screen; int screen;
Window root, win; Window root, win;
Pixmap pmap; Pixmap pmap;
Pixmap bgmap;
unsigned long colors[NUMCOLS]; unsigned long colors[NUMCOLS];
}; };
@@ -46,6 +49,8 @@ struct xrandr {
#include "config.h" #include "config.h"
Imlib_Image image;
static void static void
die(const char *errstr, ...) die(const char *errstr, ...)
{ {
@@ -190,9 +195,10 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT); color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT);
if (running && oldc != color) { if (running && oldc != color) {
for (screen = 0; screen < nscreens; screen++) { for (screen = 0; screen < nscreens; screen++) {
XSetWindowBackground(dpy, if(locks[screen]->bgmap)
locks[screen]->win, XSetWindowBackgroundPixmap(dpy, locks[screen]->win, locks[screen]->bgmap);
locks[screen]->colors[color]); else
XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]);
XClearWindow(dpy, locks[screen]->win); XClearWindow(dpy, locks[screen]->win);
} }
oldc = color; oldc = color;
@@ -235,6 +241,17 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
lock->screen = screen; lock->screen = screen;
lock->root = RootWindow(dpy, lock->screen); lock->root = RootWindow(dpy, lock->screen);
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();
}
for (i = 0; i < NUMCOLS; i++) { for (i = 0; i < NUMCOLS; i++) {
XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen),
colorname[i], &color, &dummy); colorname[i], &color, &dummy);
@@ -251,6 +268,8 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
CopyFromParent, CopyFromParent,
DefaultVisual(dpy, lock->screen), DefaultVisual(dpy, lock->screen),
CWOverrideRedirect | CWBackPixel, &wa); CWOverrideRedirect | CWBackPixel, &wa);
if(lock->bgmap)
XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap);
lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8); lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap,
&color, &color, 0, 0); &color, &color, 0, 0);
@@ -314,6 +333,7 @@ main(int argc, char **argv) {
const char *hash; const char *hash;
Display *dpy; Display *dpy;
int s, nlocks, nscreens; int s, nlocks, nscreens;
CARD16 standby, suspend, off;
ARGBEGIN { ARGBEGIN {
case 'v': case 'v':
@@ -355,6 +375,60 @@ main(int argc, char **argv) {
if (setuid(duid) < 0) if (setuid(duid) < 0)
die("slock: setuid: %s\n", strerror(errno)); die("slock: setuid: %s\n", strerror(errno));
/*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
/* check for Xrandr support */ /* check for Xrandr support */
rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase); rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
@@ -374,6 +448,20 @@ main(int argc, char **argv) {
if (nlocks != nscreens) if (nlocks != nscreens)
return 1; return 1;
/* DPMS magic to disable the monitor */
if (!DPMSCapable(dpy))
die("slock: DPMSCapable failed\n");
if (!DPMSEnable(dpy))
die("slock: DPMSEnable failed\n");
if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off))
die("slock: DPMSGetTimeouts failed\n");
if (!standby || !suspend || !off)
die("slock: at least one DPMS variable is zero\n");
if (!DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime))
die("slock: DPMSSetTimeouts failed\n");
XSync(dpy, 0);
/* run post-lock command */ /* run post-lock command */
if (argc > 0) { if (argc > 0) {
switch (fork()) { switch (fork()) {
@@ -391,5 +479,9 @@ main(int argc, char **argv) {
/* everything is now blank. Wait for the correct password */ /* everything is now blank. Wait for the correct password */
readpw(dpy, &rr, locks, nscreens, hash); readpw(dpy, &rr, locks, nscreens, hash);
/* reset DPMS values to inital ones */
DPMSSetTimeouts(dpy, standby, suspend, off);
XSync(dpy, 0);
return 0; return 0;
} }