Re: [hackers] [dwm][PATCH] Fix wrong computation in drw_text

From: Viktor Grigorov <vlg_AT_tutamail.com>
Date: Thu, 19 Aug 2021 05:30:14 +0200 (CEST)

This results in 1-character elements being unrendered.
I was wondering why two of my surfraw elvi were blank, they just were getting drawn.

Aug 16, 2021, 20:17 by suckless_AT_jochen.sprickerhof.de:

> From: Jochen Sprickerhof <suckless_AT_jochen.sprickerhof.de>
>
> In case lpad * 2 > w, w - lpad * 2 wraps around and comparing it with ew
> is always true.
> Also shorten the text if the initial width does not fit with padding.
> ---
> drw.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drw.c b/drw.c
> index 9c39086..36b56df 100644
> --- a/drw.c
> +++ b/drw.c
> _AT_@ -310,8 +310,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
> if (utf8strlen) {
> drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
> /* shorten text if necessary */
> - if (ew > w)
> - for (ew = 0, len = 0; ew < w - lpad * 2 && len < MIN(utf8strlen, sizeof(buf) - 1); len++)
> + if (ew + lpad * 2 > w)
> + for (ew = 0, len = 0; ew + lpad * 2 < w && len < MIN(utf8strlen, sizeof(buf) - 1); len++)
> drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
> else
> len = MIN(utf8strlen, sizeof(buf) - 1);
> --
> 2.32.0
>
Received on Thu Aug 19 2021 - 05:30:14 CEST

This archive was generated by hypermail 2.3.0 : Thu Aug 19 2021 - 05:36:30 CEST