From 3e41e252b1f85babab0a6c8a3cf084a0e06831a2 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Mon, 11 Apr 2022 15:56:12 +0200 Subject: [PATCH] Adding background image reload patch ref. pull request #62 --- README.md | 5 +++++ patch/background_image_x.c | 10 ++++++++++ patch/background_image_x.h | 3 ++- patch/xresources.c | 16 ++-------------- patch/xresources.h | 4 ---- patches.def.h | 6 ++++++ x.c | 30 +++++++++++++++++++++++++----- 7 files changed, 50 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 249cf56..34624c1 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the ### Changelog: +2022-04-11 - Added the background image reload patch + 2022-03-10 - Added the background image patch 2022-02-24 - Upgraded to st 0.8.5 e823e23, 2022-02-17 - removing osc_10_11_12_2 patch as no longer relevant @@ -101,6 +103,9 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the - draws a background image in farbfeld format in place of the defaultbg color allowing for pseudo transparency + - background-image-reload + - allows the background image to be reloaded similar to xresources using USR1 signals + - [blinking-cursor](https://st.suckless.org/patches/blinking_cursor/) - allows the use of a blinking cursor diff --git a/patch/background_image_x.c b/patch/background_image_x.c index fc7532c..3bbb189 100644 --- a/patch/background_image_x.c +++ b/patch/background_image_x.c @@ -94,3 +94,13 @@ bginit() XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs); } } + +#if BACKGROUND_IMAGE_RELOAD_PATCH +void +reload_image() +{ + XFreeGC(xw.dpy, xw.bggc); + bginit(); + redraw(); +} +#endif // XRESOURCES_RELOAD_PATCH diff --git a/patch/background_image_x.h b/patch/background_image_x.h index ea67d7f..e96edd2 100644 --- a/patch/background_image_x.h +++ b/patch/background_image_x.h @@ -2,4 +2,5 @@ static void updatexy(void); static XImage *loadff(const char *); -static void bginit(); \ No newline at end of file +static void bginit(); +static void reload_image(); diff --git a/patch/xresources.c b/patch/xresources.c index 32ab2be..f119ed7 100644 --- a/patch/xresources.c +++ b/patch/xresources.c @@ -35,22 +35,14 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst) } void -#if XRESOURCES_RELOAD_PATCH config_init(Display *dpy) -#else -config_init(void) -#endif // XRESOURCES_RELOAD_PATCH { char *resm; XrmDatabase db; ResourcePref *p; XrmInitialize(); - #if XRESOURCES_RELOAD_PATCH resm = XResourceManagerString(dpy); - #else - resm = XResourceManagerString(xw.dpy); - #endif // XRESOURCES_RELOAD_PATCH if (!resm) return; @@ -69,11 +61,7 @@ reload_config(int sig) die("Can't open display\n"); config_init(dpy); - if (sig != -1) { - /* Called due to a SIGUSR1 */ - xloadcols(); - redraw(); - } - signal(SIGUSR1, reload_config); + xloadcols(); + redraw(); } #endif // XRESOURCES_RELOAD_PATCH diff --git a/patch/xresources.h b/patch/xresources.h index e14b823..c184852 100644 --- a/patch/xresources.h +++ b/patch/xresources.h @@ -14,8 +14,4 @@ typedef struct { } ResourcePref; int resource_load(XrmDatabase, char *, enum resource_type, void *); -#if XRESOURCES_RELOAD_PATCH void config_init(Display *dpy); -#else -void config_init(void); -#endif // XRESOURCES_RELOAD_PATCH diff --git a/patches.def.h b/patches.def.h index be7e2fa..d14548f 100644 --- a/patches.def.h +++ b/patches.def.h @@ -54,6 +54,12 @@ */ #define BACKGROUND_IMAGE_PATCH 0 +/* This patch adds the ability to reload the background image config when a SIGUSR1 signal is + * received, e.g.: killall -USR1 st + * Depends on the BACKGROUND_IMAGE_PATCH. + */ +#define BACKGROUND_IMAGE_RELOAD_PATCH 0 + /* This patch allows the use of a blinking cursor. * Only cursor styles 0, 1, 3, 5, and 7 blink. Set cursorstyle accordingly. * Cursor styles are defined here: diff --git a/x.c b/x.c index e8bbf53..ffd4033 100644 --- a/x.c +++ b/x.c @@ -117,6 +117,9 @@ static void selnotify(XEvent *); static void selclear_(XEvent *); static void selrequest(XEvent *); static void setsel(char *, Time); +#if XRESOURCES_PATCH && XRESOURCES_RELOAD_PATCH || BACKGROUND_IMAGE_PATCH && BACKGROUND_IMAGE_RELOAD_PATCH +static void sigusr1_reload(int sig); +#endif // XRESOURCES_RELOAD_PATCH | BACKGROUND_IMAGE_RELOAD_PATCH static int mouseaction(XEvent *, uint); static void mousesel(XEvent *, int); static void mousereport(XEvent *); @@ -744,6 +747,20 @@ setsel(char *str, Time t) #endif // CLIPBOARD_PATCH } +#if XRESOURCES_PATCH && XRESOURCES_RELOAD_PATCH || BACKGROUND_IMAGE_PATCH && BACKGROUND_IMAGE_RELOAD_PATCH +void +sigusr1_reload(int sig) +{ + #if XRESOURCES_PATCH && XRESOURCES_RELOAD_PATCH + reload_config(sig); + #endif // XRESOURCES_RELOAD_PATCH + #if BACKGROUND_IMAGE_PATCH && BACKGROUND_IMAGE_RELOAD_PATCH + reload_image(); + #endif // BACKGROUND_IMAGE_RELOAD_PATCH + signal(SIGUSR1, sigusr1_reload); +} +#endif // XRESOURCES_RELOAD_PATCH | BACKGROUND_IMAGE_RELOAD_PATCH + void xsetsel(char *str) { @@ -1360,8 +1377,10 @@ xinit(int cols, int rows) XVisualInfo vis; #endif // ALPHA_PATCH + #if !XRESOURCES_PATCH if (!(xw.dpy = XOpenDisplay(NULL))) die("can't open display\n"); + #endif // XRESOURCES_PATCH xw.scr = XDefaultScreen(xw.dpy); #if ALPHA_PATCH @@ -3400,14 +3419,15 @@ run: setlocale(LC_CTYPE, ""); XSetLocaleModifiers(""); - #if XRESOURCES_RELOAD_PATCH && XRESOURCES_PATCH - reload_config(-1); - #elif XRESOURCES_PATCH + #if XRESOURCES_PATCH && XRESOURCES_RELOAD_PATCH || BACKGROUND_IMAGE_PATCH && BACKGROUND_IMAGE_RELOAD_PATCH + signal(SIGUSR1, sigusr1_reload); + #endif // XRESOURCES_RELOAD_PATCH | BACKGROUND_IMAGE_RELOAD_PATCH + #if XRESOURCES_PATCH if (!(xw.dpy = XOpenDisplay(NULL))) die("Can't open display\n"); - config_init(); - #endif // XRESOURCES_RELOAD_PATCH + config_init(xw.dpy); + #endif // XRESOURCES_PATCH cols = MAX(cols, 1); rows = MAX(rows, 1); #if ALPHA_PATCH && ALPHA_FOCUS_HIGHLIGHT_PATCH