[hackers] [tabbed ][patch] I am trying to write live reload xresources patch for tabbed.

From: Serhan Ekmekçi <serhan_AT_ekmekci.me>
Date: Tue, 1 Dec 2020 22:55:31 +0300

        I managed to have live reload in st with xst's patch, and managed to do it with dwmc patch and custom function in dwm. Now I am trying to do it with tabbed. I implemented xst's patch for tabbed now it reads from xresources without any problem and when I kill it with USR1 it reads new values from xresources and loads them to variables like normbgcolor, normfgcolor etc. but does not live reload since I don't kow how to redraw bar of tabbed. I need to write proper reload function that reinitialize colors and redraw everything. This is how far I managed to go.


#define XRESOURCE_LOAD_META(NAME) \
        if(!XrmGetResource(xrdb, "tabbed." NAME, "tabbed." NAME, &type, &ret)) \
                XrmGetResource(xrdb, "*." NAME, "*." NAME, &type, &ret); \
        if (ret.addr != NULL && !strncmp("String", type, 64))

#define XRESOURCE_LOAD_STRING(NAME, DST) \
        XRESOURCE_LOAD_META(NAME) \
                DST = ret.addr;

void
xrdb_load(void)
{
        /* XXX */
        char *xrm;
        char *type;
        XrmDatabase xrdb;
        XrmValue ret;
        Display *dpy;

        if(!(dpy = XOpenDisplay(NULL)))
                die("Can't open display\n");

        XrmInitialize();
        xrm = XResourceManagerString(dpy);

        if (xrm != NULL) {
                xrdb = XrmGetStringDatabase(xrm);

                XRESOURCE_LOAD_STRING("normbgcolor", normbgcolor);
                XRESOURCE_LOAD_STRING("normfgcolor", normfgcolor);

                XRESOURCE_LOAD_STRING("selbgcolor", selbgcolor);
                XRESOURCE_LOAD_STRING("selfgcolor", selfgcolor);

                XRESOURCE_LOAD_STRING("font", font);

        }
        XFlush(dpy);
}

void
reload(int sig) {
        xrdb_load();

/* this is what i tried but it crashes unfortunatetly */
// dc.norm[ColFG] = getcolor(normfgcolor);
// dc.sel[ColBG] = getcolor(selbgcolor);
// dc.sel[ColFG] = getcolor(selfgcolor);
// dc.urg[ColBG] = getcolor(urgbgcolor);
// dc.urg[ColFG] = getcolor(urgfgcolor);

        signal(SIGUSR1, reload);
}


This is where I am calling xrdb_load in main function:

        xrdb_load();
        signal(SIGUSR1, reload);
        setup();
        printf("0x%lx\n", win);
        fflush(NULL);

And link to my whole build:

        https://git.ekmekci.me/tabbed.git/
Received on Tue Dec 01 2020 - 20:55:31 CET

This archive was generated by hypermail 2.3.0 : Tue Dec 01 2020 - 21:00:34 CET