Sorry, I accidently pushed to the wrong remote.

I've reverted it to the original version.

Have a good day,


On Sun, Apr 05, 2020 at 05:27:02PM +0200, [email protected] wrote:
> commit f33024dd2dbb6471cb2c5c41f901fc19e4c133a8
> Author:     Hiltjo Posthuma <[email protected]>
> AuthorDate: Sun Apr 5 17:26:59 2020 +0200
> Commit:     Hiltjo Posthuma <[email protected]>
> CommitDate: Sun Apr 5 17:26:59 2020 +0200
> 
>     improve lrpad
> 
> diff --git a/x11/drw.c b/x11/drw.c
> index faabe51..6f10331 100644
> --- a/x11/drw.c
> +++ b/x11/drw.c
> @@ -162,21 +162,25 @@ drw_text(Drw *drw, int x, int y, unsigned int w, 
> unsigned int h, unsigned int lp
>       const char *text, int invert)
>  {
>       char buf[256];
> -     int i, tx, ty, th, len, olen;
> +     int i, tx, ty, th, len, olen, render = x || y || w || h;
>       unsigned int texw, texh;
>  
> -     /* TODO: lpad */
> -
> -     XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : 
> ColBg].pixel);
> -     XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
> +     if (!render) {
> +             w = ~w;
> +     } else {
> +             XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : 
> ColBg].pixel);
> +             XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
> +             x += lpad;
> +             w -= lpad;
> +     }
>  
>       olen = strlen(text);
>       drw_font_getexts(drw->fonts, text, olen, &texw, &texh);
>       th = drw->fonts->ascent + drw->fonts->descent;
>       ty = y + (h / 2) - (th / 2) + drw->fonts->ascent;
> -     tx = x + (h / 2);
> +     tx = x;
>       /* shorten text if necessary */
> -     for (len = MIN(olen, sizeof buf); len && (texw > w - texh || w < texh); 
> len--)
> +     for (len = MIN(olen, sizeof buf); len && texw > w; len--)
>               drw_font_getexts(drw->fonts, text, len, &texw, &texh);
>       if (!len)
>               return x;
> @@ -190,7 +194,10 @@ drw_text(Drw *drw, int x, int y, unsigned int w, 
> unsigned int h, unsigned int lp
>       else
>               XDrawString(drw->dpy, drw->drawable, drw->gc, tx, ty, buf, len);
>  
> -     return x + w;
> +     x += texw;
> +     w -= texw;
> +
> +     return x + (render ? w : 0);
>  }
>  
>  void
> @@ -228,10 +235,10 @@ drw_font_getexts(Fnt *font, const char *text, unsigned 
> int len, unsigned int *w,
>               if (h)
>                       *h = r.height;
>       } else {
> -             if (h)
> -                     *h = font->ascent + font->descent;
>               if (w)
>                       *w = XTextWidth(font->xfont, text, len);
> +             if (h)
> +                     *h = font->ascent + font->descent;
>       }
>  }
>  
> 

-- 
Kind regards,
Hiltjo

Reply via email to