mirror of
https://github.com/mintycube/slock.git
synced 2024-10-22 14:05:51 +02:00
Adding background image patch
This commit is contained in:
parent
312951b978
commit
e71a42ee2b
@ -26,6 +26,8 @@ slock tool, how to install it and how it works.
|
|||||||
|
|
||||||
### Changelog:
|
### Changelog:
|
||||||
|
|
||||||
|
2022-03-28 - Added the background image patch
|
||||||
|
|
||||||
2021-09-13 - Added the dwm logo patch
|
2021-09-13 - Added the dwm logo patch
|
||||||
|
|
||||||
2021-09-09 - Added the auto-timeout, failure-command and secret-password patches
|
2021-09-09 - Added the auto-timeout, failure-command and secret-password patches
|
||||||
@ -49,6 +51,9 @@ slock tool, how to install it and how it works.
|
|||||||
- [auto-timeout](https://tools.suckless.org/slock/patches/auto-timeout/)
|
- [auto-timeout](https://tools.suckless.org/slock/patches/auto-timeout/)
|
||||||
- allows for a command to be executed after a specified time of inactivity
|
- allows for a command to be executed after a specified time of inactivity
|
||||||
|
|
||||||
|
- [background_image](https://tools.suckless.org/slock/patches/background-image/)
|
||||||
|
- sets the lockscreen picture to a background image
|
||||||
|
|
||||||
- [blur_pixelated_screen](https://tools.suckless.org/slock/patches/blur-pixelated-screen/)
|
- [blur_pixelated_screen](https://tools.suckless.org/slock/patches/blur-pixelated-screen/)
|
||||||
- sets the lockscreen picture to a blured or pixelated screenshot
|
- sets the lockscreen picture to a blured or pixelated screenshot
|
||||||
|
|
||||||
|
24
config.def.h
24
config.def.h
@ -31,6 +31,11 @@ static const char * text_color = "#ffffff";
|
|||||||
static const char * font_name = "6x10";
|
static const char * font_name = "6x10";
|
||||||
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||||
|
|
||||||
|
#if BACKGROUND_IMAGE_PATCH
|
||||||
|
/* Background image path, should be available to the user above */
|
||||||
|
static const char * background_image = "";
|
||||||
|
#endif // BACKGROUND_IMAGE_PATCH
|
||||||
|
|
||||||
#if DWM_LOGO_PATCH
|
#if DWM_LOGO_PATCH
|
||||||
/* insert grid pattern with scale 1:1, the size can be changed with logosize */
|
/* insert grid pattern with scale 1:1, the size can be changed with logosize */
|
||||||
static const int logosize = 75;
|
static const int logosize = 75;
|
||||||
@ -57,19 +62,24 @@ static XRectangle rectangles[] = {
|
|||||||
*/
|
*/
|
||||||
ResourcePref resources[] = {
|
ResourcePref resources[] = {
|
||||||
#if DWM_LOGO_PATCH && !BLUR_PIXELATED_SCREEN_PATCH
|
#if DWM_LOGO_PATCH && !BLUR_PIXELATED_SCREEN_PATCH
|
||||||
{ "color2", STRING, &colorname[BACKGROUND] },
|
{ "background", STRING, &colorname[BACKGROUND] },
|
||||||
#endif //DWM_LOGO_PATCH
|
#endif //DWM_LOGO_PATCH
|
||||||
{ "color0", STRING, &colorname[INIT] },
|
#if BACKGROUND_IMAGE_PATCH
|
||||||
{ "color4", STRING, &colorname[INPUT] },
|
{ "bg_image", STRING, &background_image },
|
||||||
{ "color1", STRING, &colorname[FAILED] },
|
#endif // BACKGROUND_IMAGE_PATCH
|
||||||
|
{ "locked", STRING, &colorname[INIT] },
|
||||||
|
{ "input", STRING, &colorname[INPUT] },
|
||||||
|
{ "failed", STRING, &colorname[FAILED] },
|
||||||
#if CAPSCOLOR_PATCH
|
#if CAPSCOLOR_PATCH
|
||||||
{ "color3", STRING, &colorname[CAPS] },
|
{ "capslock", STRING, &colorname[CAPS] },
|
||||||
#endif // CAPSCOLOR_PATCH
|
#endif // CAPSCOLOR_PATCH
|
||||||
#if PAMAUTH_PATCH
|
#if PAMAUTH_PATCH
|
||||||
{ "color5", STRING, &colorname[PAM] },
|
{ "pamauth", STRING, &colorname[PAM] },
|
||||||
#endif // PAMAUTH_PATCH
|
#endif // PAMAUTH_PATCH
|
||||||
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||||
{ "color6", STRING, &text_color },
|
{ "message", STRING, &message },
|
||||||
|
{ "text_color", STRING, &text_color },
|
||||||
|
{ "font_name", STRING, &font_name },
|
||||||
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||||
};
|
};
|
||||||
#endif // XRESOURCES_PATCH
|
#endif // XRESOURCES_PATCH
|
||||||
|
@ -17,7 +17,7 @@ X11LIB = /usr/X11R6/lib
|
|||||||
# Uncomment for pam auth patch / PAMAUTH_PATCH
|
# Uncomment for pam auth patch / PAMAUTH_PATCH
|
||||||
#PAM=-lpam
|
#PAM=-lpam
|
||||||
|
|
||||||
# Uncomment for blur pixelated screen patch / BLUR_PIXELATED_SCREEN_PATCH
|
# Uncomment for blur pixelated screen and background image patches / BLUR_PIXELATED_SCREEN_PATCH, BACKGROUND_IMAGE_PATCH
|
||||||
#IMLIB=-lImlib2
|
#IMLIB=-lImlib2
|
||||||
|
|
||||||
# includes and libs
|
# includes and libs
|
||||||
|
47
patch/background_image.c
Normal file
47
patch/background_image.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include <Imlib2.h>
|
||||||
|
|
||||||
|
Imlib_Image image;
|
||||||
|
|
||||||
|
void
|
||||||
|
render_lock_image(Display *dpy, struct lock *lock, Imlib_Image image)
|
||||||
|
{
|
||||||
|
if (image) {
|
||||||
|
lock->bgmap = XCreatePixmap(dpy, lock->root, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), DefaultDepth(dpy, lock->screen));
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
create_lock_image(Display *dpy)
|
||||||
|
{
|
||||||
|
/* Load picture */
|
||||||
|
Imlib_Image buffer = imlib_load_image(background_image);
|
||||||
|
imlib_context_set_image(buffer);
|
||||||
|
int background_image_width = imlib_image_get_width();
|
||||||
|
int background_image_height = imlib_image_get_height();
|
||||||
|
|
||||||
|
/* Create an image to be rendered */
|
||||||
|
Screen *scr = ScreenOfDisplay(dpy, DefaultScreen(dpy));
|
||||||
|
image = imlib_create_image(scr->width, scr->height);
|
||||||
|
imlib_context_set_image(image);
|
||||||
|
|
||||||
|
/* Fill the image for every X monitor */
|
||||||
|
XRRMonitorInfo *monitors;
|
||||||
|
int number_of_monitors;
|
||||||
|
monitors = XRRGetMonitors(dpy, RootWindow(dpy, XScreenNumberOfScreen(scr)), True, &number_of_monitors);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < number_of_monitors; i++) {
|
||||||
|
imlib_blend_image_onto_image(buffer, 0, 0, 0, background_image_width, background_image_height, monitors[i].x, monitors[i].y, monitors[i].width, monitors[i].height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clean up */
|
||||||
|
imlib_context_set_image(buffer);
|
||||||
|
imlib_free_image();
|
||||||
|
imlib_context_set_image(image);
|
||||||
|
}
|
4
patch/background_image.h
Normal file
4
patch/background_image.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#include <Imlib2.h>
|
||||||
|
|
||||||
|
static void create_lock_image(Display *dpy);
|
||||||
|
static void render_lock_image(Display *dpy, struct lock *lock, Imlib_Image image);
|
@ -1,5 +1,7 @@
|
|||||||
/* Patches */
|
/* Patches */
|
||||||
#if BLUR_PIXELATED_SCREEN_PATCH
|
#if BACKGROUND_IMAGE_PATCH
|
||||||
|
#include "background_image.c"
|
||||||
|
#elif BLUR_PIXELATED_SCREEN_PATCH
|
||||||
#include "blur_pixelated_screen.c"
|
#include "blur_pixelated_screen.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
/* Patches */
|
/* Patches */
|
||||||
#if BLUR_PIXELATED_SCREEN_PATCH
|
#if BACKGROUND_IMAGE_PATCH
|
||||||
|
#include "background_image.h"
|
||||||
|
#elif BLUR_PIXELATED_SCREEN_PATCH
|
||||||
#include "blur_pixelated_screen.h"
|
#include "blur_pixelated_screen.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -21,9 +21,18 @@
|
|||||||
*/
|
*/
|
||||||
#define AUTO_TIMEOUT_PATCH 0
|
#define AUTO_TIMEOUT_PATCH 0
|
||||||
|
|
||||||
|
/* This patch adds a background image for slock.
|
||||||
|
* This patch depends on the Imlib2 library, uncomment the relevant line in
|
||||||
|
* config.mk when enabling this patch.
|
||||||
|
* This patch is a variant of the blur pixelated screen patch and takes precedence over that.
|
||||||
|
* https://tools.suckless.org/slock/patches/background-image/
|
||||||
|
*/
|
||||||
|
#define BACKGROUND_IMAGE_PATCH 0
|
||||||
|
|
||||||
/* This patch sets the lockscreen picture to a blured or pixelated screenshot.
|
/* This patch sets the lockscreen picture to a blured or pixelated screenshot.
|
||||||
* This patch depends on the Imlib2 library, uncomment the relevant line in
|
* This patch depends on the Imlib2 library, uncomment the relevant line in
|
||||||
* config.mk when enabling this patch.
|
* config.mk when enabling this patch.
|
||||||
|
* The background image patch takes precedence over this patch.
|
||||||
* https://tools.suckless.org/slock/patches/blur-pixelated-screen/
|
* https://tools.suckless.org/slock/patches/blur-pixelated-screen/
|
||||||
*/
|
*/
|
||||||
#define BLUR_PIXELATED_SCREEN_PATCH 0
|
#define BLUR_PIXELATED_SCREEN_PATCH 0
|
||||||
|
22
slock.c
22
slock.c
@ -107,9 +107,9 @@ struct lock {
|
|||||||
int screen;
|
int screen;
|
||||||
Window root, win;
|
Window root, win;
|
||||||
Pixmap pmap;
|
Pixmap pmap;
|
||||||
#if BLUR_PIXELATED_SCREEN_PATCH
|
#if BLUR_PIXELATED_SCREEN_PATCH || BACKGROUND_IMAGE_PATCH
|
||||||
Pixmap bgmap;
|
Pixmap bgmap;
|
||||||
#endif // BLUR_PIXELATED_SCREEN_PATCH
|
#endif // BLUR_PIXELATED_SCREEN_PATCH | BACKGROUND_IMAGE_PATCH
|
||||||
unsigned long colors[NUMCOLS];
|
unsigned long colors[NUMCOLS];
|
||||||
#if DWM_LOGO_PATCH
|
#if DWM_LOGO_PATCH
|
||||||
unsigned int x, y;
|
unsigned int x, y;
|
||||||
@ -408,7 +408,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
|
|||||||
for (screen = 0; screen < nscreens; screen++) {
|
for (screen = 0; screen < nscreens; screen++) {
|
||||||
#if DWM_LOGO_PATCH
|
#if DWM_LOGO_PATCH
|
||||||
drawlogo(dpy, locks[screen], color);
|
drawlogo(dpy, locks[screen], color);
|
||||||
#elif BLUR_PIXELATED_SCREEN_PATCH
|
#elif BLUR_PIXELATED_SCREEN_PATCH || BACKGROUND_IMAGE_PATCH
|
||||||
if (locks[screen]->bgmap)
|
if (locks[screen]->bgmap)
|
||||||
XSetWindowBackgroundPixmap(dpy, locks[screen]->win, locks[screen]->bgmap);
|
XSetWindowBackgroundPixmap(dpy, locks[screen]->win, locks[screen]->bgmap);
|
||||||
else
|
else
|
||||||
@ -488,9 +488,9 @@ 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 BLUR_PIXELATED_SCREEN_PATCH
|
#if BLUR_PIXELATED_SCREEN_PATCH || BACKGROUND_IMAGE_PATCH
|
||||||
render_lock_image(dpy, lock, image);
|
render_lock_image(dpy, lock, image);
|
||||||
#endif // BLUR_PIXELATED_SCREEN_PATCH
|
#endif // BLUR_PIXELATED_SCREEN_PATCH | BACKGROUND_IMAGE_PATCH
|
||||||
|
|
||||||
for (i = 0; i < NUMCOLS; i++) {
|
for (i = 0; i < NUMCOLS; i++) {
|
||||||
XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen),
|
XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen),
|
||||||
@ -539,10 +539,10 @@ 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 BLUR_PIXELATED_SCREEN_PATCH
|
#if BLUR_PIXELATED_SCREEN_PATCH || BACKGROUND_IMAGE_PATCH
|
||||||
if (lock->bgmap)
|
if (lock->bgmap)
|
||||||
XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap);
|
XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap);
|
||||||
#endif // BLUR_PIXELATED_SCREEN_PATCH
|
#endif // BLUR_PIXELATED_SCREEN_PATCH | BACKGROUND_IMAGE_PATCH
|
||||||
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);
|
||||||
@ -698,14 +698,14 @@ 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));
|
||||||
|
|
||||||
#if BLUR_PIXELATED_SCREEN_PATCH
|
|
||||||
create_lock_image(dpy);
|
|
||||||
#endif // BLUR_PIXELATED_SCREEN_PATCH
|
|
||||||
|
|
||||||
#if XRESOURCES_PATCH
|
#if XRESOURCES_PATCH
|
||||||
config_init(dpy);
|
config_init(dpy);
|
||||||
#endif // XRESOURCES_PATCH
|
#endif // XRESOURCES_PATCH
|
||||||
|
|
||||||
|
#if BLUR_PIXELATED_SCREEN_PATCH || BACKGROUND_IMAGE_PATCH
|
||||||
|
create_lock_image(dpy);
|
||||||
|
#endif // BLUR_PIXELATED_SCREEN_PATCH | BACKGROUND_IMAGE_PATCH
|
||||||
|
|
||||||
#if KEYPRESS_FEEDBACK_PATCH
|
#if KEYPRESS_FEEDBACK_PATCH
|
||||||
time_t t;
|
time_t t;
|
||||||
srand((unsigned) time(&t));
|
srand((unsigned) time(&t));
|
||||||
|
Loading…
Reference in New Issue
Block a user