[wiki] [sites] [slock][patch] Added new patch that fetches and sets 'feh' background || RiciT

From: <git_AT_suckless.org>
Date: Fri, 01 May 2026 17:12:41 +0200

commit 92cf19d476acbe3042c964af856ff30c30780c91
Author: RiciT <tamas.balint.farago_AT_gmail.com>
Date: Fri May 1 17:10:54 2026 +0200

    [slock][patch] Added new patch that fetches and sets 'feh' background
    
    Patch that is used with the Background Image patch and the feh tool
    to dynamically change the lock screen background to the current
    background.

diff --git a/tools.suckless.org/slock/patches/feh-background/index.md b/tools.suckless.org/slock/patches/feh-background/index.md
new file mode 100644
index 00000000..60c3e3a7
--- /dev/null
+++ b/tools.suckless.org/slock/patches/feh-background/index.md
_AT_@ -0,0 +1,21 @@
+Feh Background
+================
+
+Description
+-----------
+
+This patch allows you to use the current background set with the 'feh' tool as your lock screen. It is useful as the lock screen image changes dynamically if you change your background or if you automatically cycle your background with 'feh'.
+
+> IMPORTANT: This patch depends on the Background Image patch (current available version: slock-background-image-20220318-1c5a538), to use this patch first apply the background-image patch and then this one.
+
+> Note: The .fehbg file should be accessible by the specified user
+
+Download
+--------
+
+* [slock-feh-background-1.6.diff](slock-feh-background-1.6.diff)
+
+Author
+------
+
+* Tamas Farago - <tamas.balint.farago_AT_gmail.com>
diff --git a/tools.suckless.org/slock/patches/feh-background/slock-feh-background-1.6.diff b/tools.suckless.org/slock/patches/feh-background/slock-feh-background-1.6.diff
new file mode 100644
index 00000000..f7e47b8c
--- /dev/null
+++ b/tools.suckless.org/slock/patches/feh-background/slock-feh-background-1.6.diff
_AT_@ -0,0 +1,99 @@
+diff --color -up a/config.def.h b/config.def.h
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -1,6 +1,6 @@
+ /* user and group to drop privileges to */
+ static const char *user = "nobody";
+-static const char *group = "nobody";
++static const char *group = "nogroup";
+
+ static const char *colorname[NUMCOLS] = {
+ [INIT] = "black", /* after initialization */
+_AT_@ -13,3 +13,6 @@ static const int failonclear = 1;
+
+ /* Background image path, should be available to the user above */
+ static const char* background_image = "";
++
++/* Path to .fehbg (default: /home/user/.fehbg), should be available to the user above */
++static const char *fehbg_home_path = "";
+diff --color -up a/slock.c b/slock.c
+--- a/slock.c
++++ b/slock.c
+_AT_@ -129,6 +129,40 @@ gethash(void)
+ return hash;
+ }
+
++static char *
++get_fehbg_path(const char *fehbg_file)
++{
++ FILE *file = fopen(fehbg_file, "r");
++ if (file == NULL) {
++ return NULL;
++ }
++
++ char buffer[500];
++ char *path = NULL;
++
++ while (fgets(buffer, sizeof(buffer), file) != NULL) {
++ /* Look for the first single quote */
++ char *start = strchr(buffer, '\'');
++ if (start != NULL) {
++ /* Look for the closing single quote */
++ char *end = strchr(start + 1, '\'');
++ if (end != NULL) {
++ size_t len = end - start - 1;
++ path = (char *)malloc(len + 1);
++ if (path != NULL) {
++ strncpy(path, start + 1, len);
++ path[len] = '++ }
++ break;
++ }
++ }
++ }
++
++ fclose(file);
++ return path;
++}
++
++
+ static void
+ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
+ const char *hash)
+_AT_@ -378,6 +412,7 @@ main(int argc, char **argv) {
+ die("slock: setuid: %s
", strerror(errno));
+
+ /* Load picture */
++ background_image = get_fehbg_path(fehbg_home_path);
+ Imlib_Image buffer = imlib_load_image(background_image);
+ imlib_context_set_image(buffer);
+ int background_image_width = imlib_image_get_width();
+_AT_@ -395,7 +430,27 @@ main(int argc, char **argv) {
+
+ 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);
++ int m_x = monitors[i].x;
++ int m_y = monitors[i].y;
++ int m_w = monitors[i].width;
++ int m_h = monitors[i].height;
++
++ int s_x = 0;
++ int s_y = 0;
++ int s_w = background_image_width;
++ int s_h = background_image_height;
++
++ /* This implements a stretching behaviour for the given image,
++ * it should not be hard to modify and achieve different effects */
++ if ((double)m_w / m_h > (double)s_w / s_h) {
++ s_h = (s_w * m_h) / m_w;
++ s_y = (background_image_height - s_h) / 2;
++ } else {
++ s_w = (s_h * m_w) / m_h;
++ s_x = (background_image_width - s_w) / 2;
++ }
++
++ imlib_blend_image_onto_image(buffer, 0, s_x, s_y, s_w, s_h, m_x, m_y, m_w, m_h);
+ }
+
+ /* Clean up */
Received on Fri May 01 2026 - 17:12:41 CEST

This archive was generated by hypermail 2.3.0 : Fri May 01 2026 - 17:24:51 CEST