libsl/x11: add new function drw_fontset_getwidth_clamp - libsl - draw back-ends for dwm, dmenu, etc
(HTM) git clone git://git.codemadness.org/libsl
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 3e27a145b9678dd8c68d2cd71fd78966b215b7c2
(DIR) parent f33024dd2dbb6471cb2c5c41f901fc19e4c133a8
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Tue, 10 May 2022 19:12:33 +0200
libsl/x11: add new function drw_fontset_getwidth_clamp
Diffstat:
M x11/drw.c | 12 +++++++++---
M x11/drw.h | 1 +
2 files changed, 10 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/x11/drw.c b/x11/drw.c
@@ -147,10 +147,7 @@ void
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled,
int invert)
{
- int dx;
-
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColBg : ColFg].pixel);
- dx = (drw->fonts->ascent + drw->fonts->descent + 2) / 4;
if (filled)
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w + 1, h + 1);
else
@@ -223,6 +220,15 @@ drw_fontset_getwidth(Drw *drw, const char *text)
return drw_font_getexts_width(drw->fonts, text, strlen(text));
}
+unsigned int
+drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n)
+{
+ unsigned int tmp = 0;
+ if (drw && drw->fonts && text && n)
+ tmp = drw_text(drw, 0, 0, 0, 0, 0, text, n);
+ return MIN(n, tmp);
+}
+
void
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
{
(DIR) diff --git a/x11/drw.h b/x11/drw.h
@@ -36,6 +36,7 @@ void drw_free(Drw *drw);
Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount);
void drw_fontset_free(Fnt* set);
unsigned int drw_fontset_getwidth(Drw *drw, const char *text);
+unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n);
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
/* Colorscheme abstraction */