commit 1faf5f475161b2362b077be9f3ddde84a95514ce
parent ded6077af12634bd0fb0cd1f31bf2995bcf800ca
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Mon, 9 Aug 2021 18:26:02 +0200
sync drw.c: improve speed of large fonts and free fontset
Diffstat:
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drw.c b/drw.c
@@ -95,6 +95,7 @@ drw_free(Drw *drw)
{
XFreePixmap(drw->dpy, drw->drawable);
XFreeGC(drw->dpy, drw->gc);
+ drw_fontset_free(drw->fonts);
free(drw);
}
@@ -309,8 +310,11 @@ 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 */
- for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--)
- drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
+ if (ew > w)
+ for (ew = 0, len = 0; ew < w - lpad * 2 && len < MIN(utf8strlen, sizeof(buf) - 1); len++)
+ drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
+ else
+ len = MIN(utf8strlen, sizeof(buf) - 1);
if (len) {
memcpy(buf, utf8str, len);