aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidpkj <davidpenkow1@gmail.com>2023-08-27 20:54:30 +0200
committerdavidpkj <davidpenkow1@gmail.com>2023-08-27 20:54:30 +0200
commit16f60c2b10a168255d8ed2675c4ef7eb092268b3 (patch)
treee7d7c4dce8b2d6cbe805522f3e154ee22fe446d8
parentc2fdbc6b2f9808405db3709f25c3a240104a4bcc (diff)
Updated to currently used versionHEADmaster
-rw-r--r--config.h13
-rw-r--r--config.h.orig40
-rw-r--r--config.h.rej26
-rw-r--r--explicit_bzero.obin1496 -> 1504 bytes
-rwxr-xr-xslockbin23360 -> 27536 bytes
-rw-r--r--slock.17
-rw-r--r--slock.c152
-rw-r--r--slock.c.orig15
-rw-r--r--slock.c.rej18
-rw-r--r--slock.obin18000 -> 21640 bytes
10 files changed, 192 insertions, 79 deletions
diff --git a/config.h b/config.h
index c1541ca..e5dbdd2 100644
--- a/config.h
+++ b/config.h
@@ -10,11 +10,16 @@ static const char *colorname[NUMCOLS] = {
/* XResources preferences to load at startup */
ResourcePref resources[] = {
- { "color0", STRING, &colorname[INIT] },
- { "color1", STRING, &colorname[INPUT] },
- { "color3", STRING, &colorname[FAILED] },
+ { "primary", STRING, &colorname[INIT] },
+ { "accent", STRING, &colorname[INPUT] },
+ { "color1", STRING, &colorname[FAILED] },
};
+/* show color message */
+static const char *message = "";
+static const char *text_color = "#FFFFFF";
+static const char *font_name = "6x13";
+
/* treat a cleared input like a wrong password (color) */
static const int failonclear = 0;
@@ -43,7 +48,7 @@ static XRectangle rectangles[9] = {
/*Enable blur*/
#define BLUR
/*Set blur radius*/
-static const int blurRadius=5;
+static const int blurRadius=10;
/*Enable Pixelation*/
//#define PIXELATION
/*Set pixelation radius*/
diff --git a/config.h.orig b/config.h.orig
deleted file mode 100644
index 7b3aaf3..0000000
--- a/config.h.orig
+++ /dev/null
@@ -1,40 +0,0 @@
-/* user and group to drop privileges to */
-static const char *user = "me";
-static const char *group = "users";
-
-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;
-
-/* insert grid pattern with scale 1:1, the size can be changed with logosize */
-static const int logosize = 75;
-/* grid width and height for right center alignment */
-static const int logow = 12;
-static const int logoh = 6;
-
-static XRectangle rectangles[9] = {
- /* x y w h */
- { 0, 3, 1, 3 },
- { 1, 3, 2, 1 },
- { 0, 5, 8, 1 },
- { 3, 0, 1, 5 },
- { 5, 3, 1, 2 },
- { 7, 3, 1, 2 },
- { 8, 3, 4, 1 },
- { 9, 4, 1, 2 },
- { 11, 4, 1, 2 },
-};
-
-/*Enable blur*/
-#define BLUR
-/*Set blur radius*/
-static const int blurRadius=9;
-/*Enable Pixelation*/
-//#define PIXELATION
-/*Set pixelation radius*/
-static const int pixelSize=0;
diff --git a/config.h.rej b/config.h.rej
deleted file mode 100644
index 828bd10..0000000
--- a/config.h.rej
+++ /dev/null
@@ -1,26 +0,0 @@
---- config.def.h
-+++ config.def.h
-@@ -3,11 +3,21 @@ static const char *user = "nobody";
- static const char *group = "nogroup";
-
- static const char *colorname[NUMCOLS] = {
-- [INIT] = "black", /* after initialization */
-- [INPUT] = "#005577", /* during input */
-+ [INIT] = "black", /* after initialization */
-+ [INPUT] = "#005577", /* during input */
- [FAILED] = "#CC3333", /* wrong password */
- [CAPS] = "red", /* CapsLock on */
- };
-
-+/*
-+ * Xresources preferences to load at startup
-+ */
-+ResourcePref resources[] = {
-+ { "color0", STRING, &colorname[INIT] },
-+ { "color4", STRING, &colorname[INPUT] },
-+ { "color1", STRING, &colorname[FAILED] },
-+ { "color3", STRING, &colorname[CAPS] },
-+};
-+
- /* treat a cleared input like a wrong password (color) */
- static const int failonclear = 1;
diff --git a/explicit_bzero.o b/explicit_bzero.o
index 55d6605..e1092c8 100644
--- a/explicit_bzero.o
+++ b/explicit_bzero.o
Binary files differ
diff --git a/slock b/slock
index 1c17b8e..4235296 100755
--- a/slock
+++ b/slock
Binary files differ
diff --git a/slock.1 b/slock.1
index 82cdcd6..946165f 100644
--- a/slock.1
+++ b/slock.1
@@ -6,6 +6,8 @@
.Sh SYNOPSIS
.Nm
.Op Fl v
+.Op Fl f
+.Op Fl m Ar message
.Op Ar cmd Op Ar arg ...
.Sh DESCRIPTION
.Nm
@@ -16,6 +18,11 @@ is executed after the screen has been locked.
.Bl -tag -width Ds
.It Fl v
Print version information to stdout and exit.
+.It Fl f
+List all valid X fonts and exit.
+.It Fl m Ar message
+Overrides default slock lock message.
+.TP
.El
.Sh SECURITY CONSIDERATIONS
To make sure a locked screen can not be bypassed by switching VTs
diff --git a/slock.c b/slock.c
index 2729bee..a5d915c 100644
--- a/slock.c
+++ b/slock.c
@@ -36,6 +36,9 @@ char *argv0;
static time_t locktime;
+/* global count to prevent repeated error messages */
+int count_error = 0;
+
enum {
INIT,
INPUT,
@@ -116,6 +119,132 @@ dontkillme(void)
}
#endif
+static int
+readescapedint(const char *str, int *i) {
+ int n = 0;
+ if (str[*i])
+ ++*i;
+ while(str[*i] && str[*i] != ';' && str[*i] != 'm') {
+ n = 10 * n + str[*i] - '0';
+ ++*i;
+ }
+ return n;
+}
+
+static void
+writemessage(Display *dpy, Window win, int screen)
+{
+ int len, line_len, width, height, s_width, s_height, i, k, tab_size, r, g, b, escaped_int, curr_line_len;
+ XGCValues gr_values;
+ XFontStruct *fontinfo;
+ XColor color, dummy;
+ XineramaScreenInfo *xsi;
+ GC gc;
+ fontinfo = XLoadQueryFont(dpy, font_name);
+
+ if (fontinfo == NULL) {
+ if (count_error == 0) {
+ fprintf(stderr, "slock: Unable to load font \"%s\"\n", font_name);
+ fprintf(stderr, "slock: Try listing fonts with 'slock -f'\n");
+ count_error++;
+ }
+ return;
+ }
+
+ tab_size = 8 * XTextWidth(fontinfo, " ", 1);
+
+ XAllocNamedColor(dpy, DefaultColormap(dpy, screen),
+ text_color, &color, &dummy);
+
+ gr_values.font = fontinfo->fid;
+ gr_values.foreground = color.pixel;
+ gc=XCreateGC(dpy,win,GCFont+GCForeground, &gr_values);
+
+ /* To prevent "Uninitialized" warnings. */
+ xsi = NULL;
+
+ /*
+ * Start formatting and drawing text
+ */
+
+ len = strlen(message);
+
+ /* Max max line length (cut at '\n') */
+ line_len = curr_line_len = 0;
+ k = 0;
+ for (i = 0; i < len; i++) {
+ if (message[i] == '\n') {
+ curr_line_len = 0;
+ k++;
+ } else if (message[i] == 0x1b) {
+ while (i < len && message[i] != 'm') {
+ i++;
+ }
+ if (i == len)
+ die("slock: unclosed escape sequence\n");
+ } else {
+ curr_line_len += XTextWidth(fontinfo, message + i, 1);
+ if (curr_line_len > line_len)
+ line_len = curr_line_len;
+ }
+ }
+ /* If there is only one line */
+ if (line_len == 0)
+ line_len = len;
+
+ if (XineramaIsActive(dpy)) {
+ xsi = XineramaQueryScreens(dpy, &i);
+ s_width = xsi[0].width;
+ s_height = xsi[0].height;
+ } else {
+ s_width = DisplayWidth(dpy, screen);
+ s_height = DisplayHeight(dpy, screen);
+ }
+ height = s_height*3/7 - (k*20)/3;
+ width = (s_width - line_len)/2;
+
+ line_len = 0;
+ /* print the text while parsing 24 bit color ANSI escape codes*/
+ for (i = k = 0; i < len; i++) {
+ switch (message[i]) {
+ case '\n':
+ line_len = 0;
+ while (message[i + 1] == '\t') {
+ line_len += tab_size;
+ i++;
+ }
+ k++;
+ break;
+ case 0x1b:
+ i++;
+ if (message[i] == '[') {
+ escaped_int = readescapedint(message, &i);
+ if (escaped_int == 39)
+ continue;
+ if (escaped_int != 38)
+ die("slock: unknown escape sequence%d\n", escaped_int);
+ if (readescapedint(message, &i) != 2)
+ die("slock: only 24 bit color supported\n");
+ r = readescapedint(message, &i) & 0xff;
+ g = readescapedint(message, &i) & 0xff;
+ b = readescapedint(message, &i) & 0xff;
+ XSetForeground(dpy, gc, r << 16 | g << 8 | b);
+ } else
+ die("slock: unknown escape sequence\n");
+ break;
+ default:
+ XDrawString(dpy, win, gc, width + line_len, height + 20 * k, message + i, 1);
+ line_len += XTextWidth(fontinfo, message + i, 1);
+ }
+ }
+
+ /* xsi should not be NULL anyway if Xinerama is active, but to be safe */
+ if (XineramaIsActive(dpy) && xsi != NULL)
+ XFree(xsi);
+}
+
+
+
static const char *
gethash(void)
{
@@ -463,7 +592,7 @@ config_init(Display *dpy)
static void
usage(void)
{
- die("usage: slock [-v] [cmd [arg ...]]\n");
+ die("usage: slock [-v] [-f] [-m message] [cmd [arg ...]]\n");
}
int
@@ -476,12 +605,25 @@ main(int argc, char **argv) {
gid_t dgid;
const char *hash;
Display *dpy;
- int s, nlocks, nscreens;
+ int i, s, nlocks, nscreens;
+ int count_fonts;
+ char **font_names;
ARGBEGIN {
case 'v':
fprintf(stderr, "slock-"VERSION"\n");
return 0;
+ case 'm':
+ message = EARGF(usage());
+ break;
+ case 'f':
+ if (!(dpy = XOpenDisplay(NULL)))
+ die("slock: cannot open display\n");
+ font_names = XListFonts(dpy, "*", 10000 /* list 10000 fonts*/, &count_fonts);
+ for (i=0; i<count_fonts; i++) {
+ fprintf(stderr, "%s\n", *(font_names+i));
+ }
+ return 0;
default:
usage();
} ARGEND
@@ -582,10 +724,12 @@ main(int argc, char **argv) {
if (!(locks = calloc(nscreens, sizeof(struct lock *))))
die("slock: out of memory\n");
for (nlocks = 0, s = 0; s < nscreens; s++) {
- if ((locks[s] = lockscreen(dpy, &rr, s)) != NULL)
+ if ((locks[s] = lockscreen(dpy, &rr, s)) != NULL) {
+ writemessage(dpy, locks[s]->win, s);
nlocks++;
- else
+ } else {
break;
+ }
}
XSync(dpy, 0);
diff --git a/slock.c.orig b/slock.c.orig
index 5d63a9a..2729bee 100644
--- a/slock.c.orig
+++ b/slock.c.orig
@@ -26,6 +26,7 @@
#include <X11/Xutil.h>
#include <X11/Xft/Xft.h>
#include <X11/Xresource.h>
+#include <X11/XF86keysym.h>
#include <Imlib2.h>
#include "arg.h"
@@ -218,6 +219,20 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
IsPrivateKeypadKey(ksym))
continue;
switch (ksym) {
+ case XF86XK_AudioPlay:
+ case XF86XK_AudioStop:
+ case XF86XK_AudioPrev:
+ case XF86XK_AudioNext:
+ case XF86XK_AudioRaiseVolume:
+ case XF86XK_AudioLowerVolume:
+ case XF86XK_AudioMute:
+ case XF86XK_AudioMicMute:
+ case XF86XK_MonBrightnessDown:
+ case XF86XK_MonBrightnessUp:
+ case XF86XK_KbdBrightnessDown:
+ case XF86XK_KbdBrightnessUp:
+ XSendEvent(dpy, DefaultRootWindow(dpy), True, KeyPressMask, &ev);
+ break;
case XK_Return:
passwd[len] = '\0';
errno = 0;
diff --git a/slock.c.rej b/slock.c.rej
index cad6d5a..5eb25a3 100644
--- a/slock.c.rej
+++ b/slock.c.rej
@@ -1,10 +1,18 @@
--- slock.c
+++ slock.c
-@@ -18,6 +18,7 @@
+@@ -15,6 +15,7 @@
+ #include <unistd.h>
+ #include <sys/types.h>
+ #include <X11/extensions/Xrandr.h>
++#include <X11/extensions/Xinerama.h>
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
-+#include <X11/XF86keysym.h>
-
- #include "arg.h"
- #include "util.h"
+@@ -323,6 +453,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
+ locks[screen]->win,
+ locks[screen]->colors[color]);
+ XClearWindow(dpy, locks[screen]->win);
++ writemessage(dpy, locks[screen]->win, screen);
+ }
+ oldc = color;
+ }
diff --git a/slock.o b/slock.o
index e8b225b..805e061 100644
--- a/slock.o
+++ b/slock.o
Binary files differ