status2d patch for colors - dwm - my version of dwm (frankenstein's monster)
 (HTM) git clone https://git.drkhsh.at/dwm.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit a65051ecafc14f7d8e57b4606e56c35f4577b571
 (DIR) parent 08c241f472de7ff7d8d816e1efa97bf1cd586712
 (HTM) Author: drkhsh <me@drkhsh.at>
       Date:   Sun,  2 Jun 2024 19:07:43 +0200
       
       status2d patch for colors
       
       Diffstat:
         M dwm.c                               |     121 +++++++++++++++++++++++++++++--
       
       1 file changed, 115 insertions(+), 6 deletions(-)
       ---
 (DIR) diff --git a/dwm.c b/dwm.c
       @@ -216,6 +216,7 @@ static Monitor *dirtomon(int dir);
        static void dragfact(const Arg *arg);
        static void drawbar(Monitor *m);
        static void drawbars(void);
       +static int drawstatusbar(Monitor *m, int bh, char* text);
        static void enternotify(XEvent *e);
        static void expose(XEvent *e);
        static void focus(Client *c);
       @@ -307,7 +308,7 @@ static void zoom(const Arg *arg);
        
        /* variables */
        static const char broken[] = "broken";
       -static char stext[256];
       +static char stext[1024];
        static int screen;
        static int sw, sh;           /* X display screen geometry width, height */
        static int bh;               /* bar height */
       @@ -607,7 +608,7 @@ cleanup(void)
                }
                for (i = 0; i < CurLast; i++)
                        drw_cur_free(drw, cursor[i]);
       -        for (i = 0; i < LENGTH(colors); i++)
       +        for (i = 0; i < LENGTH(colors) + 1; i++)
                        free(scheme[i]);
                free(scheme);
                XDestroyWindow(dpy, wmcheckwin);
       @@ -617,6 +618,115 @@ cleanup(void)
                XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
        }
        
       +int
       +drawstatusbar(Monitor *m, int bh, char* stext) {
       +        int ret, i, w, x, len;
       +        short isCode = 0;
       +        char *text;
       +        char *p;
       +
       +        len = strlen(stext) + 1 ;
       +        if (!(text = (char*) malloc(sizeof(char)*len)))
       +                die("malloc");
       +        p = text;
       +        memcpy(text, stext, len);
       +
       +        /* compute width of the status text */
       +        w = 0;
       +        i = -1;
       +        while (text[++i]) {
       +                if (text[i] == '^') {
       +                        if (!isCode) {
       +                                isCode = 1;
       +                                text[i] = '\0';
       +                                w += TEXTW(text) - lrpad;
       +                                text[i] = '^';
       +                                if (text[++i] == 'f')
       +                                        w += atoi(text + ++i);
       +                        } else {
       +                                isCode = 0;
       +                                text = text + i + 1;
       +                                i = -1;
       +                        }
       +                }
       +        }
       +        if (!isCode)
       +                w += TEXTW(text) - lrpad;
       +        else
       +                isCode = 0;
       +        text = p;
       +
       +        w += 2; /* 1px padding on both sides */
       +        w += lrpad;
       +        ret = x = m->ww - w;
       +
       +        drw_setscheme(drw, scheme[LENGTH(colors)]);
       +        drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
       +        drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
       +        drw_rect(drw, x - 2 * barborderpx, 0 + barborderpx, w, bh - 2 * borderpx, 1, 1);
       +        x++;
       +
       +        /* process status text */
       +        i = -1;
       +        while (text[++i]) {
       +                if (text[i] == '^' && !isCode) {
       +                        isCode = 1;
       +
       +                        text[i] = '\0';
       +                        w = TEXTW(text) - lrpad + 2 * barborderpx;
       +                        drw_text(drw, x, 0 + barborderpx, w, bh - 2 * barborderpx, 0, text, 0);
       +
       +                        x += w;
       +
       +                        /* process code */
       +                        while (text[++i] != '^') {
       +                                if (text[i] == 'c') {
       +                                        char buf[8];
       +                                        memcpy(buf, (char*)text+i+1, 7);
       +                                        buf[7] = '\0';
       +                                        drw_clr_create(drw, &drw->scheme[ColFg], buf, OPAQUE);
       +                                        i += 7;
       +                                } else if (text[i] == 'b') {
       +                                        char buf[8];
       +                                        memcpy(buf, (char*)text+i+1, 7);
       +                                        buf[7] = '\0';
       +                                        drw_clr_create(drw, &drw->scheme[ColBg], buf, OPAQUE);
       +                                        i += 7;
       +                                } else if (text[i] == 'd') {
       +                                        drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
       +                                        drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
       +                                } else if (text[i] == 'r') {
       +                                        int rx = atoi(text + ++i);
       +                                        while (text[++i] != ',');
       +                                        int ry = atoi(text + ++i);
       +                                        while (text[++i] != ',');
       +                                        int rw = atoi(text + ++i);
       +                                        while (text[++i] != ',');
       +                                        int rh = atoi(text + ++i);
       +
       +                                        drw_rect(drw, rx + x, ry, rw, rh, 1, 0);
       +                                } else if (text[i] == 'f') {
       +                                        x += atoi(text + ++i);
       +                                }
       +                        }
       +
       +                        text = text + i + 1;
       +                        i=-1;
       +                        isCode = 0;
       +                }
       +        }
       +
       +        if (!isCode) {
       +                w = TEXTW(text) - lrpad;
       +                drw_text(drw, x, barborderpx, w, bh - 2 * barborderpx, 0, text, 0);
       +        }
       +
       +        drw_setscheme(drw, scheme[SchemeNorm]);
       +        free(p);
       +
       +        return ret;
       +}
       +
        void
        cleanupmon(Monitor *mon)
        {
       @@ -1016,9 +1126,7 @@ drawbar(Monitor *m)
        
                /* draw status first so it can be overdrawn by tags later */
                if (m == selmon) { /* status is only drawn on selected monitor */
       -                drw_setscheme(drw, scheme[SchemeNorm]);
       -                tw = TEXTW(stext);
       -                drw_text(drw, mw - tw - stw, y, tw + barborderpx, th, lrpad / 2, stext, 0);
       +                tw = m->ww - drawstatusbar(m, bh, stext);
                }
        
                for (c = m->clients; c; c = c->next) {
       @@ -2085,7 +2193,8 @@ setup(void)
                cursor[CurMove] = drw_cur_create(drw, XC_fleur);
                cursor[CurDragFact] = drw_cur_create(drw, XC_rightbutton);
                /* init appearance */
       -        scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
       +        scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *));
       +        scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], alphas[0], 3);
                for (i = 0; i < LENGTH(colors); i++)
                        scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 3);
                drw_clr_create(drw, &clrborder, col_borderbar, baralpha);