[dwm][PATCH] statuscolors, fix status text width computation

This is an updated version of the statuscolors patch that fixes the
computation of the text width. The previous version of the patch
inculded all the byte codes that are used to select the color schemes
when computing the width, obaining a width that is larger than the real
width. This patch fixes that by adding up the widths of the individual
chunks, separated by the codes that select the color schemes.
pull/32/head
bakkeby 4 years ago
parent f9a001dee7
commit ec32a28380

@ -15,7 +15,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog:
2020-04-16 - Upgraded the scratchpad patch to the multiple scratchpads patch \[[ref](https://lists.suckless.org/hackers/2004/17205.html)\]
2020-04-16 - Upgraded the scratchpad patch to the multiple scratchpads patch \[[ref](https://lists.suckless.org/hackers/2004/17205.html)\]. Updated the statuscolors patch with the width computation fix \[[ref](https://lists.suckless.org/hackers/2004/17207.html)\].
2020-04-13 - Added statuscmd patch

14
dwm.c

@ -1462,12 +1462,12 @@ drawbar(Monitor *m)
#else
drw_setscheme(drw, scheme[SchemeNorm]);
#endif // VTCOLORS_PATCH
#if STATUSCOLORS_PATCH
#if STATUSPADDING_PATCH
sw = TEXTW(stext);
sw = textw_wosc(stext) + lrpad + 2;
#else
sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
sw = textw_wosc(stext) + 2;
#endif // STATUSPADDING_PATCH
#if STATUSCOLORS_PATCH
while (1) {
if ((unsigned int)*ts > LENGTH(colors)) {
ts++;
@ -1477,14 +1477,18 @@ drawbar(Monitor *m)
*ts = '\0';
drw_text(drw, m->ww - sw - stw + tx, 0, sw - tx, bh, stp, tp, 0);
tx += TEXTW(tp) -lrpad;
if (ctmp == '\0') {
if (ctmp == '\0')
break;
}
drw_setscheme(drw, scheme[(unsigned int)(ctmp-1)]);
*ts = ctmp;
tp = ++ts;
}
#else // STATUSCOLORS_PATCH
#if STATUSPADDING_PATCH
sw = TEXTW(stext);
#else
sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
#endif // STATUSPADDING_PATCH
drw_text(drw, m->ww - sw - stw, 0, sw, bh, stp, stext, 0);
#endif // STATUSCOLORS_PATCH
#if !STATUSALLMONS_PATCH

@ -110,6 +110,9 @@
#if STACKER_PATCH
#include "stacker.c"
#endif
#if STATUSCOLORS_PATCH
#include "statuscolors.c"
#endif
#if STATUSCMD_PATCH
#include "statuscmd.c"
#endif
@ -221,4 +224,4 @@
#endif
#if TILE_LAYOUT
#include "tile.c"
#endif
#endif

@ -0,0 +1,23 @@
int
textw_wosc(char *s)
{
char *ts = s;
char *tp = s;
int sw = 0;
char ctmp;
while (1) {
if ((unsigned int)*ts > LENGTH(colors)) {
ts++;
continue;
}
ctmp = *ts;
*ts = '\0';
sw += drw_fontset_getwidth(drw, tp);
*ts = ctmp;
if (ctmp == '\0')
break;
tp = ++ts;
}
return sw;
}
Loading…
Cancel
Save