LukeSmithxyz / st

Luke's fork of the suckless simple terminal (st) with vim bindings and Xresource compatibility.
MIT License
1.64k stars 1.01k forks source link

Add support for reloading xrdb #357

Closed wouterj closed 1 year ago

wouterj commented 1 year ago

I'm trying to create a script that automatically toggles ST from light to dark mode, by changing ~/.xresources and reloading it. This works perfect for new ST instances, but it doesn't reload existing ST windows.

Looking at https://st.suckless.org/patches/xresources-with-reload-signal/ , it should be relatively trivial to implement a signal to reload the resources, but my limited C knowledge is failing me. If you're open to add such support to this fork, would you mind helping me with this issue? :pray:

I've created the patch below and I've confirmed that resource_load() is called for all values when a USR1 signal is sent to the program. However, the terminal doesn't update its colors. I guess this means I'm either not reloading the x resources (and thus updating with the old values) or forcing a redraw incorrectly?

diff --git a/x.c b/x.c
index e2ec9db..4d0e3c3 100644
--- a/x.c
+++ b/x.c
@@ -2270,6 +2270,17 @@ config_init(void)
                resource_load(db, p->name, p->type, p->dst);
 }

+void
+reload(int sig)
+{
+   config_init();
+   xloadcols();
+   cresize(0, 0);
+   redraw();
+
+   signal(SIGUSR1, reload);
+}
+
 void
 usage(void)
 {
@@ -2351,6 +2362,7 @@ run:
        die("Can't open display\n");

    config_init();
+   signal(SIGUSR1, reload);
    cols = MAX(cols, 1);
    rows = MAX(rows, 1);
    defaultbg = MAX(LEN(colorname), 256);
LukeSmithxyz commented 1 year ago

http://st.suckless.org/patches/xresources-with-reload-signal/