Adding dwmlogo patch ref. #5

This commit is contained in:
bakkeby 2021-09-13 10:48:56 +02:00
parent e5a9d8539b
commit e5e04272d1
12 changed files with 179 additions and 38 deletions

View File

@ -26,6 +26,8 @@ slock tool, how to install it and how it works.
### Changelog:
2021-09-13 - Added the dwm logo patch
2021-09-09 - Added the auto-timeout, failure-command and secret-password patches
2021-06-08 - Added the color message patch
@ -69,6 +71,9 @@ slock tool, how to install it and how it works.
- the monitor will automatically be activated by pressing a key or moving the mouse and the
password can be entered then
- [dwmlogo](https://tools.suckless.org/slock/patches/dwmlogo/)
- draws the dwm logo which changes color based on the state
- [failure-command](https://tools.suckless.org/slock/patches/failure-command/)
- allows for a command to be run after a specified number of incorrect attempts

View File

@ -3,6 +3,9 @@ static const char *user = "nobody";
static const char *group = "nogroup"; // use "nobody" for arch
static const char *colorname[NUMCOLS] = {
#if DWM_LOGO_PATCH
[BACKGROUND] = "#2d2d2d", /* after initialization */
#endif // DWM_LOGO_PATCH
[INIT] = "black", /* after initialization */
[INPUT] = "#005577", /* during input */
[FAILED] = "#CC3333", /* wrong password */
@ -28,11 +31,34 @@ static const char * text_color = "#ffffff";
static const char * font_name = "6x10";
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
#if DWM_LOGO_PATCH
/* insert grid pattern with scale 1:1, the size can be changed with logosize */
static const int logosize = 75;
static const int logow = 12; /* grid width and height for right center alignment*/
static const int logoh = 6;
static XRectangle rectangles[] = {
/* 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 },
};
#endif // DWM_LOGO_PATCH
#if XRESOURCES_PATCH
/*
* Xresources preferences to load at startup
*/
ResourcePref resources[] = {
#if DWM_LOGO_PATCH
{ "color2", STRING, &colorname[BACKGROUND] },
#endif //DWM_LOGO_PATCH
{ "color0", STRING, &colorname[INIT] },
{ "color4", STRING, &colorname[INPUT] },
{ "color1", STRING, &colorname[FAILED] },
@ -87,11 +113,11 @@ static const secretpass scom[] = {
/* Enable blur */
#define BLUR
/* Set blur radius */
static const int blurRadius=5;
static const int blurRadius = 5;
/* Enable Pixelation */
//#define PIXELATION
/* Set pixelation radius */
static const int pixelSize=10;
static const int pixelSize = 10;
#endif // BLUR_PIXELATED_SCREEN_PATCH
#if CONTROLCLEAR_PATCH

View File

@ -10,21 +10,22 @@ MANPREFIX = ${PREFIX}/share/man
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
# Uncomment for message patch / MESSAGE_PATCH / COLORMESSAGE_PATCH
#XINERAMA=-lXinerama
# Uncomment for message patch / MESSAGE_PATCH / COLORMESSAGE_PATCH / DWM_LOGO_PATCH
XINERAMA=-lXinerama
XINERAMAFLAGS = -DXINERAMA
# Uncomment for pam auth patch / PAMAUTH_PATCH
#PAM=-lpam
# Uncomment for blur pixelated screen patch / BLUR_PIXELATED_SCREEN_PATCH
#IMLIB=-lImlib2
IMLIB=-lImlib2
# includes and libs
INCS = -I. -I/usr/include -I${X11INC}
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr ${XINERAMA} ${PAM} ${IMLIB}
# flags
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H ${XINERAMAFLAGS}
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
LDFLAGS = -s ${LIBS}
COMPATSRC = explicit_bzero.c

View File

@ -50,17 +50,17 @@ create_lock_image(Display *dpy)
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);
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 /= (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;

29
patch/dwmlogo.c Normal file
View File

@ -0,0 +1,29 @@
static void
resizerectangles(struct lock *lock)
{
int i;
for (i = 0; i < LENGTH(rectangles); i++){
lock->rectangles[i].x = (rectangles[i].x * logosize)
+ lock->xoff + ((lock->mw) / 2) - (logow / 2 * logosize);
lock->rectangles[i].y = (rectangles[i].y * logosize)
+ lock->yoff + ((lock->mh) / 2) - (logoh / 2 * logosize);
lock->rectangles[i].width = rectangles[i].width * logosize;
lock->rectangles[i].height = rectangles[i].height * logosize;
}
}
static void
drawlogo(Display *dpy, struct lock *lock, int color)
{
#if BLUR_PIXELATED_SCREEN_PATCH
lock->drawable = lock->bgmap;
#else
XSetForeground(dpy, lock->gc, lock->colors[BACKGROUND]);
XFillRectangle(dpy, lock->drawable, lock->gc, 0, 0, lock->x, lock->y);
#endif // BLUR_PIXELATED_SCREEN_PATCH
XSetForeground(dpy, lock->gc, lock->colors[color]);
XFillRectangles(dpy, lock->drawable, lock->gc, lock->rectangles, LENGTH(rectangles));
XCopyArea(dpy, lock->drawable, lock->win, lock->gc, 0, 0, lock->x, lock->y, 0, 0);
XSync(dpy, False);
}

2
patch/dwmlogo.h Normal file
View File

@ -0,0 +1,2 @@
static void resizerectangles(struct lock *lock);
static void drawlogo(Display *dpy, struct lock *lock, int color);

View File

@ -9,6 +9,10 @@
#include "message.c"
#endif
#if DWM_LOGO_PATCH
#include "dwmlogo.c"
#endif
#if KEYPRESS_FEEDBACK_PATCH
#include "keypress_feedback.c"
#endif

View File

@ -3,14 +3,14 @@
#include "blur_pixelated_screen.h"
#endif
#if DWM_LOGO_PATCH
#include "dwmlogo.h"
#endif
#if PAMAUTH_PATCH
#include "pamauth.h"
#endif
#if KEYPRESS_FEEDBACK_PATCH
#include "keypress_feedback.h"
#endif
#if XRESOURCES_PATCH
#include "xresources.h"
#endif

View File

@ -1,3 +1,4 @@
#include <X11/Xresource.h>
#include <math.h>
int
@ -47,6 +48,6 @@ config_init(Display *dpy)
return;
db = XrmGetStringDatabase(resm);
for (p = resources; p < resources + LEN(resources); p++)
for (p = resources; p < resources + LENGTH(resources); p++)
resource_load(db, p->name, p->type, p->dst);
}

View File

@ -1,17 +0,0 @@
#include <X11/Xresource.h>
/* macros */
#define LEN(a) (sizeof(a) / sizeof(a)[0])
/* Xresources preferences */
enum resource_type {
STRING = 0,
INTEGER = 1,
FLOAT = 2
};
typedef struct {
char *name;
enum resource_type type;
void *dst;
} ResourcePref;

View File

@ -65,6 +65,11 @@
*/
#define DPMS_PATCH 0
/* This patch draws the dwm logo which changes color based on the state.
* https://tools.suckless.org/slock/patches/dwmlogo/
*/
#define DWM_LOGO_PATCH 0
/* This patch allows for a command to be run after a specified number of incorrect attempts.
* https://tools.suckless.org/slock/patches/failure-command/
*/

93
slock.c
View File

@ -39,6 +39,9 @@
#if DPMS_PATCH
#include <X11/extensions/dpms.h>
#endif // DPMS_PATCH
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
#include "arg.h"
#include "util.h"
@ -57,6 +60,9 @@ static time_t locktime;
#endif // QUICKCANCEL_PATCH
enum {
#if DWM_LOGO_PATCH && !BLUR_PIXELATED_SCREEN_PATCH
BACKGROUND,
#endif // DWM_LOGO_PATCH
INIT,
INPUT,
FAILED,
@ -72,6 +78,23 @@ enum {
NUMCOLS
};
#if XRESOURCES_PATCH
/* Xresources preferences */
enum resource_type {
STRING = 0,
INTEGER = 1,
FLOAT = 2
};
typedef struct {
char *name;
enum resource_type type;
void *dst;
} ResourcePref;
#endif // XRESOURCES_PATCH
#include "config.h"
struct lock {
int screen;
Window root, win;
@ -80,6 +103,13 @@ struct lock {
Pixmap bgmap;
#endif // BLUR_PIXELATED_SCREEN_PATCH
unsigned long colors[NUMCOLS];
#if DWM_LOGO_PATCH
unsigned int x, y;
unsigned int xoff, yoff, mw, mh;
Drawable drawable;
GC gc;
XRectangle rectangles[LENGTH(rectangles)];
#endif // DWM_LOGO_PATCH
};
#if SECRET_PASSWORD_PATCH
@ -97,7 +127,6 @@ struct xrandr {
};
#include "patch/include.h"
#include "config.h"
static void
die(const char *errstr, ...)
@ -377,17 +406,20 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
#endif // CAPSCOLOR_PATCH
if (running && oldc != color) {
for (screen = 0; screen < nscreens; screen++) {
#if BLUR_PIXELATED_SCREEN_PATCH
#if DWM_LOGO_PATCH
drawlogo(dpy, locks[screen], color);
#elif BLUR_PIXELATED_SCREEN_PATCH
if (locks[screen]->bgmap)
XSetWindowBackgroundPixmap(dpy, locks[screen]->win, locks[screen]->bgmap);
else
XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]);
XClearWindow(dpy, locks[screen]->win);
#else
XSetWindowBackground(dpy,
locks[screen]->win,
locks[screen]->colors[color]);
#endif // BLUR_PIXELATED_SCREEN_PATCH
XClearWindow(dpy, locks[screen]->win);
#endif // BLUR_PIXELATED_SCREEN_PATCH
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
writemessage(dpy, locks[screen]->win, screen);
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
@ -439,7 +471,12 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
XColor color, dummy;
XSetWindowAttributes wa;
Cursor invisible;
#if DWM_LOGO_PATCH
#ifdef XINERAMA
XineramaScreenInfo *info;
int n;
#endif
#endif // DWM_LOGO_PATCH
#if AUTO_TIMEOUT_PATCH
time(&lasttouched);
#endif // AUTO_TIMEOUT_PATCH
@ -460,12 +497,43 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
lock->colors[i] = color.pixel;
}
#if DWM_LOGO_PATCH
lock->x = DisplayWidth(dpy, lock->screen);
lock->y = DisplayHeight(dpy, lock->screen);
#ifdef XINERAMA
if ((info = XineramaQueryScreens(dpy, &n))) {
lock->xoff = info[0].x_org;
lock->yoff = info[0].y_org;
lock->mw = info[0].width;
lock->mh = info[0].height;
} else
#endif // XINERAMA
{
lock->xoff = lock->yoff = 0;
lock->mw = lock->x;
lock->mh = lock->y;
}
lock->drawable = XCreatePixmap(dpy, lock->root, lock->x, lock->y, DefaultDepth(dpy, screen));
lock->gc = XCreateGC(dpy, lock->root, 0, NULL);
XSetLineAttributes(dpy, lock->gc, 1, LineSolid, CapButt, JoinMiter);
#endif // DWM_LOGO_PATCH
/* init */
wa.override_redirect = 1;
#if DWM_LOGO_PATCH && BLUR_PIXELATED_SCREEN_PATCH
#elif DWM_LOGO_PATCH
wa.background_pixel = lock->colors[BACKGROUND];
#else
wa.background_pixel = lock->colors[INIT];
#endif // DWM_LOGO_PATCH
lock->win = XCreateWindow(dpy, lock->root, 0, 0,
#if DWM_LOGO_PATCH
lock->x,
lock->y,
#else
DisplayWidth(dpy, lock->screen),
DisplayHeight(dpy, lock->screen),
#endif // DWM_LOGO_PATCH
0, DefaultDepth(dpy, lock->screen),
CopyFromParent,
DefaultVisual(dpy, lock->screen),
@ -479,6 +547,10 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
&color, &color, 0, 0);
XDefineCursor(dpy, lock->win, invisible);
#if DWM_LOGO_PATCH
resizerectangles(lock);
#endif // DWM_LOGO_PATCH
/* 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) {
@ -510,6 +582,9 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
#if QUICKCANCEL_PATCH
locktime = time(NULL);
#endif // QUICKCANCEL_PATCH
#if DWM_LOGO_PATCH
drawlogo(dpy, lock, INIT);
#endif // DWM_LOGO_PATCH
#if ALPHA_PATCH
unsigned int opacity = (unsigned int)(alpha * 0xffffffff);
XChangeProperty(dpy, lock->win, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False), XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1L);
@ -696,5 +771,15 @@ main(int argc, char **argv) {
XSync(dpy, 0);
#endif // DPMS_PATCH
#if DWM_LOGO_PATCH
for (nlocks = 0, s = 0; s < nscreens; s++) {
XFreePixmap(dpy, locks[s]->drawable);
XFreeGC(dpy, locks[s]->gc);
}
XSync(dpy, 0);
XCloseDisplay(dpy);
#endif // DWM_LOGO_PATCH
return 0;
}