From 4ceaa81c0d5e9b1330a960f8711646c946aeeb8c Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sun, 17 Apr 2022 10:05:43 +0200 Subject: [PATCH] Moving ellipsis text into a variable for clarity --- drw.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drw.c b/drw.c index bca53d3..a9c23cd 100644 --- a/drw.c +++ b/drw.c @@ -431,7 +431,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) { int i, ty, ellipsis_x = 0; - unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len, ellipsis_width; + unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len; XftDraw *d = NULL; Fnt *usedfont, *curfont, *nextfont; int utf8strlen, utf8charlen, render = x || y || w || h; @@ -445,6 +445,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp /* keep track of a couple codepoints for which we have no match. */ enum { nomatches_len = 64 }; static struct { long codepoint[nomatches_len]; unsigned int idx; } nomatches; + const char *ellipsis = "..."; + static unsigned int ellipsis_width = 0; if (!drw || (render && !drw->scheme) || !text || !drw->fonts) return 0; @@ -466,7 +468,8 @@ 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 && render) + ellipsis_width = drw_fontset_getwidth(drw, ellipsis); while (1) { ew = ellipsis_len = utf8strlen = 0; utf8str = text; @@ -520,7 +523,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp w -= ew; } if (render && overflow && ellipsis_w) - drw_text(drw, ellipsis_x, y, ellipsis_w, h, 0, "...", invert); + drw_text(drw, ellipsis_x, y, ellipsis_w, h, 0, ellipsis, invert); if (!*text || overflow) { break;