1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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) {
|