commit a18c5c1d3de8cd70c3000812773067a2a6a213ec
parent 98534d6b5bb9ab888b1af00056afed15c67135fb
Author: ViliamKovac1223 <viliamkovac1223@gmail.com>
Date: Fri, 10 Dec 2021 18:41:36 +0100
adding new foreground-image patch to slock
Diffstat:
2 files changed, 118 insertions(+), 0 deletions(-)
diff --git a/tools.suckless.org/slock/patches/foreground-image/index.md b/tools.suckless.org/slock/patches/foreground-image/index.md
@@ -0,0 +1,37 @@
+Foreground Image
+=======
+
+Description
+-----------
+This patch lets you add a foreground image to your lock screen.
+
+Configuration Options
+---------------------
+* `imgpath` - is path to image to display, image must be xpm file
+* `imgwidth` - width of the image
+* `imgheight` - height of the image
+* `imgoffsetx` - image offset from left side
+* `imgoffsety` - image offset from top side
+* `showimgonlyatstart` - if set to 1 image will be shown only at the start (before tipying), if set to 0 image will be always shown
+
+
+Xpm Image
+---------
+Xpm image is bitmap image used by X Windows System. It's one of the few image formats that is supported by Xorg by default.
+
+Convert jpg to xpm:
+```
+convert image.jpg -geometry 1920x1080 -colors 216 image.xpm
+```
+
+Notes
+-----
+This is [patch](https://github.com/ViliamKovac1223/slock-foreground-image-patch) also hosted on my [github](https://github.com/ViliamKovac1223).
+
+Download
+--------
+* [slock-foreground-image-20211210.diff](slock-foreground-image-20211210.diff)
+
+Authors
+-------
+* Viliam Kováč - viliamkovac1223@gmail.com
diff --git a/tools.suckless.org/slock/patches/foreground-image/slock-foreground-image-20211210.diff b/tools.suckless.org/slock/patches/foreground-image/slock-foreground-image-20211210.diff
@@ -0,0 +1,81 @@
+From: Viliam Kováč <viliamkovac1223@gmail.com>
+Date: Fri, 10 Dec 2021 17:22:00
+Subject: [PATCH] Add a image foreground
+diff --git a/config.def.h b/config.def.h
+index 9855e21..dfa61d6 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -10,3 +10,10 @@ static const char *colorname[NUMCOLS] = {
+
+ /* treat a cleared input like a wrong password (color) */
+ static const int failonclear = 1;
++
++static const char *imgpath = "img.xpm";
++static const int imgwidth = 1920;
++static const int imgheight = 1080;
++static const int imgoffsetx = 0;
++static const int imgoffsety = 0;
++static const int showimgonlyatstart = 1;
+diff --git a/config.mk b/config.mk
+index 74429ae..6145285 100644
+--- a/config.mk
++++ b/config.mk
+@@ -12,7 +12,7 @@ X11LIB = /usr/X11R6/lib
+
+ # includes and libs
+ 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 -lXpm
+
+ # flags
+ CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H
+diff --git a/slock.c b/slock.c
+index 5ae738c..b36c347 100644
+--- a/slock.c
++++ b/slock.c
+@@ -18,6 +18,7 @@
+ #include <X11/keysym.h>
+ #include <X11/Xlib.h>
+ #include <X11/Xutil.h>
++#include <X11/xpm.h>
+
+ #include "arg.h"
+ #include "util.h"
+@@ -124,6 +125,19 @@ gethash(void)
+ return hash;
+ }
+
++static void
++showimage(Display *dpy, Window win)
++{
++ XImage *ximage;
++
++ if (!XpmReadFileToImage (dpy, imgpath, &ximage, NULL, NULL)) {
++ XSelectInput(dpy, win, ButtonPressMask|ExposureMask);
++ XMapWindow(dpy, win);
++
++ XPutImage(dpy, win, DefaultGC(dpy, 0), ximage, 0, 0, imgoffsetx, imgoffsety, imgwidth, imgheight);
++ }
++}
++
+ static void
+ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
+ const char *hash)
+@@ -194,6 +208,8 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
+ locks[screen]->win,
+ locks[screen]->colors[color]);
+ XClearWindow(dpy, locks[screen]->win);
++ if (showimgonlyatstart != 1)
++ showimage(dpy, locks[screen]->win);
+ }
+ oldc = color;
+ }
+@@ -256,6 +272,8 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
+ &color, &color, 0, 0);
+ XDefineCursor(dpy, lock->win, invisible);
+
++ showimage(dpy, lock->win);
++
+ /* 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) {