Introduction
Introduction Statistics Contact Development Disclaimer Help
improve lrpad - libsl - draw back-ends for dwm, dmenu, etc
git clone git://git.codemadness.org/libsl
Log
Files
Refs
LICENSE
---
commit f33024dd2dbb6471cb2c5c41f901fc19e4c133a8
parent b450cbeceb639c6372733d14d1a3af95550109d2
Author: Hiltjo Posthuma <[email protected]>
Date: Sun, 5 Apr 2020 17:26:59 +0200
improve lrpad
Diffstat:
M x11/drw.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/x11/drw.c b/x11/drw.c
@@ -162,21 +162,25 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned…
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].…
- 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 :…
+ 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)…
+ 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 …
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 in…
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;
}
}
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.