gnotclub / xst

st fork that uses Xresources and some pretty good patches
MIT License
536 stars 73 forks source link

stx does not automatically update data from Xresources when Xresources file is updated/xrdb is ran #112

Closed BombchuLink closed 4 years ago

BombchuLink commented 4 years ago

xst does not automatically update data from Xresources when Xresources is updated. It is required that you close the terminal emulator and re-open it to see the new updates to the font/colours.

How to implement:

1 got to x.c:1972 and pull date last modified from xresources

2 go to the for loop at X.c:1994 and check xresources to original pulled date at x.c:1972

3 call function that sets colours from xresources inside of the checking if statement

4 ????

5 profit

I've managed to do step 1...

    struct tm *timeinit;
    struct tm *timenow;
    struct stat attrib;
    /* Get last-modified time of Xresources*/
    stat("~/.config/Xresources", &attrib);
    timeinit = localtime(&(attrib.st_ctime));

and 2

        /* Check if Xresources was changed since init*/
        stat("~/.config/Xresources", &attrib);
        timenow = localtime(&(attrib.st_ctime));
        if (timeinit->tm_year != timenow->tm_year ||
            timeinit->tm_mon  != timenow->tm_mon  ||
            timeinit->tm_mday != timenow->tm_mday ||
            timeinit->tm_hour != timenow->tm_hour ||
            timeinit->tm_min  != timenow->tm_min
            ){
            printf("XRESOURCES IS OUTDATED\n");
            timeinit->tm_year = timenow->tm_year;
            timeinit->tm_mon  = timenow->tm_mon;
            timeinit->tm_mday = timenow->tm_mday;
            timeinit->tm_hour = timenow->tm_hour;
            timeinit->tm_min  = timenow->tm_min;
        }
        else {
            printf("XResources is up to date\n");
        }

However with this method it does put a dependency on <sys/stat.h> and . Also I'm sure there's a better way to write this, but I'm not terribly good at writing C. ;_;

as for step 3... I can't seem to actually get any ground with this one. I'm probably just being stupid but xloadcols(), xinit(), and even changing xw.cmap doesn't seem to get it to re-load the Xresources assets at any point, and thus I'm at a dead end.

Also from what (limited) information I can find, no other terminal does this, so I guess nobody has bothered to make this a thing before (or it's much more difficult to do with terminal emulation than one would think, or it would possibly be a common feature)

Hopefully you all know your way around st better than I do, and you can help push me in the right direction lol. Thanks for your time.

neeasade commented 4 years ago

if you are willing to do this outside the terminal, you may accomplish this with a script -- an example is given below. (using inotify-tools). xst reloads itself through the USR1 signal. An alternative to inotifywait may be entr

#!/bin/sh

while true; do
    if ! inotifywait -e close_write "${HOME}/.Xresources"; then
    continue
    fi
    echo reloading!
    xrdb -merge "${HOME}/.Xresources"
    pkill -x --signal USR1 xst
done
BombchuLink commented 4 years ago

Wow, I didn't know that was possible, seems to work absolutely perfectly!

Thank you so much.