diff options
author | Eddy Pedroni <epedroni@pm.me> | 2023-12-16 17:50:57 +0100 |
---|---|---|
committer | Eddy Pedroni <epedroni@pm.me> | 2023-12-16 17:50:57 +0100 |
commit | e05bcf6982cc0b098a4b8276da5a80dd36f98e17 (patch) | |
tree | 0f145149188ba983994cd1a41fb11684c7f1efe9 | |
parent | 8d054f66e8ce3835b552936b34c4bd3baf2ecc09 (diff) |
Add correct statuscolors patch
-rw-r--r-- | patches/dwm-statuscolors-20220322-bece862.diff | 83 | ||||
-rw-r--r-- | patches/dwm-statuscolors-6.1.diff | 194 |
2 files changed, 83 insertions, 194 deletions
diff --git a/patches/dwm-statuscolors-20220322-bece862.diff b/patches/dwm-statuscolors-20220322-bece862.diff new file mode 100644 index 0000000..2425419 --- /dev/null +++ b/patches/dwm-statuscolors-20220322-bece862.diff @@ -0,0 +1,83 @@ +From 301db3986527041d64f4b58026677709a34b153f Mon Sep 17 00:00:00 2001 +From: dan soucy <dev@danso.ca> +Date: Tue, 22 Mar 2022 03:15:00 -0400 +Subject: [PATCH] enable colored text in the status bar + +This patch is an update of statuscolors patch to work with 6.3. +It is known to work up to commit bece862. +--- + config.def.h | 13 ++++++++++--- + dwm.c | 18 ++++++++++++++++-- + 2 files changed, 26 insertions(+), 5 deletions(-) + +diff --git a/config.def.h b/config.def.h +index a2ac963..a635f76 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -12,10 +12,17 @@ static const char col_gray2[] = "#444444"; + static const char col_gray3[] = "#bbbbbb"; + static const char col_gray4[] = "#eeeeee"; + static const char col_cyan[] = "#005577"; ++static const char col_black[] = "#000000"; ++static const char col_red[] = "#ff0000"; ++static const char col_yellow[] = "#ffff00"; ++static const char col_white[] = "#ffffff"; ++ + static const char *colors[][3] = { +- /* fg bg border */ +- [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, +- [SchemeSel] = { col_gray4, col_cyan, col_cyan }, ++ /* fg bg border */ ++ [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, ++ [SchemeSel] = { col_gray4, col_cyan, col_cyan }, ++ [SchemeWarn] = { col_black, col_yellow, col_red }, ++ [SchemeUrgent]= { col_white, col_red, col_red }, + }; + + /* tagging */ +diff --git a/dwm.c b/dwm.c +index 5f16260..3c5e26b 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -59,7 +59,7 @@ + + /* enums */ + enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ +-enum { SchemeNorm, SchemeSel }; /* color schemes */ ++enum { SchemeNorm, SchemeSel, SchemeWarn, SchemeUrgent }; /* color schemes */ + enum { NetSupported, NetWMName, NetWMState, NetWMCheck, + NetWMFullscreen, NetActiveWindow, NetWMWindowType, + NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ +@@ -701,6 +701,10 @@ drawbar(Monitor *m) + int boxs = drw->fonts->h / 9; + int boxw = drw->fonts->h / 6 + 2; + unsigned int i, occ = 0, urg = 0; ++ char *ts = stext; ++ char *tp = stext; ++ int tx = 0; ++ char ctmp; + Client *c; + + if (!m->showbar) +@@ -710,7 +714,17 @@ drawbar(Monitor *m) + if (m == selmon) { /* status is only drawn on selected monitor */ + drw_setscheme(drw, scheme[SchemeNorm]); + tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ +- drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0); ++ while (1) { ++ if ((unsigned int)*ts > LENGTH(colors)) { ts++; continue ; } ++ ctmp = *ts; ++ *ts = '\0'; ++ drw_text(drw, m->ww - tw + tx, 0, tw - tx, bh, 0, tp, 0); ++ tx += TEXTW(tp) -lrpad; ++ if (ctmp == '\0') { break; } ++ drw_setscheme(drw, scheme[(unsigned int)(ctmp-1)]); ++ *ts = ctmp; ++ tp = ++ts; ++ } + } + + for (c = m->clients; c; c = c->next) { +-- +2.35.1 + diff --git a/patches/dwm-statuscolors-6.1.diff b/patches/dwm-statuscolors-6.1.diff deleted file mode 100644 index 3aead49..0000000 --- a/patches/dwm-statuscolors-6.1.diff +++ /dev/null @@ -1,194 +0,0 @@ -diff -up dwm/drw.c dwm-statuscolors/drw.c ---- dwm/drw.c 2015-11-08 15:39:37.000000000 -0700 -+++ dwm-statuscolors/drw.c 2015-11-28 15:42:28.534399525 -0700 -@@ -206,6 +206,68 @@ drw_setscheme(Drw *drw, ClrScheme *schem - drw->scheme = scheme; - } - -+int -+drw_get_width(Drw *drw, int numcolors, const char *text) -+{ -+ int i; -+ Fnt *curfont = drw->fonts[0]; -+ int w = drw_text(drw, 0, 0, 0, 0, text, 0) + curfont->h; -+ -+ for (i = 0; i < strlen(text); i++) { -+ if (text[i] > 0 && text[i] <= numcolors) { -+ /* we found a color code -+ * drw_text counted it as a normal character and added one character's width -+ * we aren't going to render this character, so we remove one character's width */ -+ w -= curfont->xfont->max_advance_width; -+ -+ if (i == 0 || i + 1 == strlen(text)) { -+ /* we're on the first or the last character of the string -+ * drw_text already added one character's height (divided by 2) as padding to the beginning and end -+ * we don't want to double this padding, so we skip this character */ -+ continue; -+ } -+ -+ if (text[i - 1] > 0 && text[i - 1] <= numcolors) { -+ /* the previous character was also a color code -+ * we already added padding in the previous iteration -+ * we don't want to double this padding, so we skip this character */ -+ continue; -+ } -+ -+ /* we are somewhere in the middle of the string and the color has changed -+ * we want to add one character's height (divided by 2) as padding to the end of the previous colored text -+ * and to the beginning of the new colored text */ -+ w += curfont->h; -+ } -+ } -+ -+ return w; -+} -+ -+void -+drw_colored_text(Drw *drw, ClrScheme *scheme, int numcolors, int x, int y, unsigned int w, unsigned int h, char *text) -+{ -+ if (!drw || !drw->fontcount || !drw->scheme) -+ return; -+ -+ char *buf = text, *ptr = buf, c = 1; -+ int i; -+ -+ while (*ptr) { -+ for (i = 0; *ptr < 0 || *ptr > numcolors; i++, ptr++); -+ if (!*ptr) -+ break; -+ c = *ptr; -+ *ptr = 0; -+ if (i) -+ x = drw_text(drw, x, y, w, h, buf, 0) + drw->fonts[0]->h; -+ *ptr = c; -+ drw_setscheme(drw, &scheme[c-1]); -+ buf = ++ptr; -+ } -+ drw_text(drw, x, y, w, h, buf, 0); -+} -+ - void - drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert) - { -diff -up dwm/drw.h dwm-statuscolors/drw.h ---- dwm/drw.h 2015-11-08 15:39:37.000000000 -0700 -+++ dwm-statuscolors/drw.h 2015-11-28 15:39:44.427726312 -0700 -@@ -67,6 +67,8 @@ void drw_setfont(Drw *, Fnt *); - void drw_setscheme(Drw *, ClrScheme *); - - /* Drawing functions */ -+int drw_get_width(Drw *, int, const char *); -+void drw_colored_text(Drw *, ClrScheme *, int, int, int, unsigned int, unsigned int, char *); - void drw_rect(Drw *, int, int, unsigned int, unsigned int, int, int, int); - int drw_text(Drw *, int, int, unsigned int, unsigned int, const char *, int); - -diff -up dwm/dwm.c dwm-statuscolors/dwm.c ---- dwm/dwm.c 2015-11-08 15:39:37.000000000 -0700 -+++ dwm-statuscolors/dwm.c 2015-11-28 15:45:32.134406853 -0700 -@@ -51,6 +51,7 @@ - * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy))) - #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags])) - #define LENGTH(X) (sizeof X / sizeof X[0]) -+#define MAXCOLORS 9 - #define MOUSEMASK (BUTTONMASK|PointerMotionMask) - #define WIDTH(X) ((X)->w + 2 * (X)->bw) - #define HEIGHT(X) ((X)->h + 2 * (X)->bw) -@@ -261,7 +262,7 @@ static void (*handler[LASTEvent]) (XEven - static Atom wmatom[WMLast], netatom[NetLast]; - static int running = 1; - static Cur *cursor[CurLast]; --static ClrScheme scheme[SchemeLast]; -+static ClrScheme scheme[MAXCOLORS]; - static Display *dpy; - static Drw *drw; - static Monitor *mons, *selmon; -@@ -718,35 +719,35 @@ drawbar(Monitor *m) - x = 0; - for (i = 0; i < LENGTH(tags); i++) { - w = TEXTW(tags[i]); -- drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]); -- drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i); -+ drw_setscheme(drw, &scheme[(m->tagset[m->seltags] & 1 << i) ? 1 : (urg & 1 << i ? 2 : 0)]); -+ drw_text(drw, x, 0, w, bh, tags[i], 0); - drw_rect(drw, x + 1, 1, dx, dx, m == selmon && selmon->sel && selmon->sel->tags & 1 << i, -- occ & 1 << i, urg & 1 << i); -+ occ & 1 << i, 0); - x += w; - } - w = blw = TEXTW(m->ltsymbol); -- drw_setscheme(drw, &scheme[SchemeNorm]); -+ drw_setscheme(drw, &scheme[0]); - drw_text(drw, x, 0, w, bh, m->ltsymbol, 0); - x += w; - xx = x; - if (m == selmon) { /* status is only drawn on selected monitor */ -- w = TEXTW(stext); -+ w = drw_get_width(drw, NUMCOLORS, stext); - x = m->ww - w; - if (x < xx) { - x = xx; - w = m->ww - xx; - } -- drw_text(drw, x, 0, w, bh, stext, 0); -+ drw_colored_text(drw, scheme, NUMCOLORS, x, 0, w, bh, stext); - } else - x = m->ww; - if ((w = x - xx) > bh) { - x = xx; - if (m->sel) { -- drw_setscheme(drw, m == selmon ? &scheme[SchemeSel] : &scheme[SchemeNorm]); -+ drw_setscheme(drw, &scheme[m == selmon ? 1 : 0]); - drw_text(drw, x, 0, w, bh, m->sel->name, 0); - drw_rect(drw, x + 1, 1, dx, dx, m->sel->isfixed, m->sel->isfloating, 0); - } else { -- drw_setscheme(drw, &scheme[SchemeNorm]); -+ drw_setscheme(drw, &scheme[0]); - drw_rect(drw, x, 0, w, bh, 1, 0, 1); - } - } -@@ -807,7 +808,7 @@ focus(Client *c) - detachstack(c); - attachstack(c); - grabbuttons(c, 1); -- XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->pix); -+ XSetWindowBorder(dpy, c->win, scheme[1].border->pix); - setfocus(c); - } else { - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); -@@ -1065,7 +1066,7 @@ manage(Window w, XWindowAttributes *wa) - - wc.border_width = c->bw; - XConfigureWindow(dpy, w, CWBorderWidth, &wc); -- XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->pix); -+ XSetWindowBorder(dpy, w, scheme[0].border->pix); - configure(c); /* propagates border_width, if size doesn't change */ - updatewindowtype(c); - updatesizehints(c); -@@ -1580,12 +1581,12 @@ setup(void) - cursor[CurResize] = drw_cur_create(drw, XC_sizing); - cursor[CurMove] = drw_cur_create(drw, XC_fleur); - /* init appearance */ -- scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor); -- scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor); -- scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor); -- scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor); -- scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor); -- scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor); -+ for(int i = 0; i < NUMCOLORS; i++){ -+ scheme[i].border = drw_clr_create(drw, colors[i][0]); -+ scheme[i].fg = drw_clr_create(drw, colors[i][1]); -+ scheme[i].bg = drw_clr_create(drw, colors[i][2]); -+ } -+ - /* init bars */ - updatebars(); - updatestatus(); -@@ -1745,7 +1746,7 @@ unfocus(Client *c, int setfocus) - if (!c) - return; - grabbuttons(c, 0); -- XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->pix); -+ XSetWindowBorder(dpy, c->win, scheme[0].border->pix); - if (setfocus) { - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); - XDeleteProperty(dpy, root, netatom[NetActiveWindow]); |