[wiki] [sites] 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. || Christian Tenllado

From: <git_AT_suckless.org>
Date: Mon, 04 May 2020 19:25:23 +0200

commit 267913ce9a70234c16de0af00ee18d128e4b303e
Author: Christian Tenllado <ctenllado_AT_gmail.com>
Date: Mon May 4 19:24:47 2020 +0200

    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.

diff --git a/dwm.suckless.org/patches/statuscolors/dwm-statuscolors-20200413-14f723a.diff b/dwm.suckless.org/patches/statuscolors/dwm-statuscolors-20200413-14f723a.diff
new file mode 100644
index 00000000..a305753a
--- /dev/null
+++ b/dwm.suckless.org/patches/statuscolors/dwm-statuscolors-20200413-14f723a.diff
_AT_@ -0,0 +1,114 @@
+From 14f723a7812cf5a2a7b924a3bf494e51bfedf7bc Mon Sep 17 00:00:00 2001
+From: Christian Tenllado <ctenllado_AT_gmail.com>
+Date: Mon, 13 Apr 2020 18:12:36 +0200
+Subject: [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.
+---
+ config.def.h | 13 ++++++++++---
+ dwm.c | 40 +++++++++++++++++++++++++++++++++++++---
+ 2 files changed, 47 insertions(+), 6 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 1c0b587..df92695 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -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 4465af1..0856993 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -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 */
+_AT_@ -692,6 +692,26 @@ dirtomon(int dir)
+ return m;
+ }
+
++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 = '++ sw += drw_fontset_getwidth(drw, tp);
++ *ts = ctmp;
++ if (ctmp == '++ tp = ++ts;
++ }
++
++ return sw;
++}
++
+ void
+ drawbar(Monitor *m)
+ {
+_AT_@ -699,13 +719,27 @@ 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;
+
+ /* 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]);
+- sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
+- drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0);
++ sw = textw_wosc(stext) + 2;
++ while (1) {
++ if ((unsigned int)*ts > LENGTH(colors)) { ts++; continue ; }
++ ctmp = *ts;
++ *ts = '++ drw_text(drw, m->ww - sw + tx, 0, sw - tx, bh, 0, tp, 0);
++ tx += TEXTW(tp) -lrpad;
++ if (ctmp == '++ drw_setscheme(drw, scheme[(unsigned int)(ctmp-1)]);
++ *ts = ctmp;
++ tp = ++ts;
++ }
+ }
+
+ for (c = m->clients; c; c = c->next) {
+--
+2.20.1
+
Received on Mon May 04 2020 - 19:25:23 CEST

This archive was generated by hypermail 2.3.0 : Mon May 04 2020 - 19:36:49 CEST