Re: [hackers] [libsl|dmenu][PATCH v2] Fix truncation issues and improve performance

From: NRK <nrk_AT_disroot.org>
Date: Wed, 30 Mar 2022 00:54:31 +0600

On Tue, Mar 29, 2022 at 07:33:27PM +0200, Quentin Rameau wrote:
> > _AT_@ -283,7 +284,10 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
> > }
> >
> > usedfont = drw->fonts;
> > - drw_font_getexts(usedfont, "...", 3, &ellipsis_width, NULL);
> > + if (ellipsis_width < 0) {
> > + ellipsis_width = 0; /* stop infinite recursion */
> > + ellipsis_width = drw_fontset_getwidth(drw, "...");
>
> I don't understand how setting it twice in a row stops a recursion.
> Will not the drw_fontset_getwidth() call *always* overwrite any value set before?

Hi Quentin,

drw_fontset_getwidth() is just a wrapper around drw_text()

        unsigned int
        drw_fontset_getwidth(Drw *drw, const char *text)
        {
                if (!drw || !drw->fonts || !text)
                        return 0;
                return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
        }

so by setting ellipsis_width to 0, we make sure it skips this branch on
the recursive call due to the `if (ellipsis_width < 0)`.

Also, related to the 0 ellipsis_width patch, I'm thinking it might be
better to guard against any 0 width draws *in general* instead of just
for ellipsis_width. So something like this instead:

diff --git a/drw.c b/drw.c
index 96d868d..0cc5cbc 100644
--- a/drw.c
+++ b/drw.c
_AT_@ -268,7 +268,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
         static struct { long codepoint[nomatches_len]; unsigned int idx; } nomatches;
         static int ellipsis_width = -1;
 
- if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
+ if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts)
                 return 0;
 
         if (!render) {

- NRK
Received on Tue Mar 29 2022 - 20:54:31 CEST

This archive was generated by hypermail 2.3.0 : Tue Mar 29 2022 - 21:00:38 CEST