small change to drawtext

pull/1/head
arg@suckless.org 17 years ago
parent fc578c57e4
commit 08bcf721b4
  1. 7
      dwm.c

@ -551,7 +551,7 @@ drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]) {
void void
drawtext(const char *text, ulong col[ColLast], Bool invert) { drawtext(const char *text, ulong col[ColLast], Bool invert) {
int x, y, w, h; int i, x, y, h;
uint len, olen; uint len, olen;
XRectangle r = { dc.x, dc.y, dc.w, dc.h }; XRectangle r = { dc.x, dc.y, dc.w, dc.h };
char buf[256]; char buf[256];
@ -563,16 +563,15 @@ drawtext(const char *text, ulong col[ColLast], Bool invert) {
olen = strlen(text); olen = strlen(text);
len = MIN(olen, sizeof buf); len = MIN(olen, sizeof buf);
memcpy(buf, text, len); memcpy(buf, text, len);
w = 0;
h = dc.font.ascent + dc.font.descent; h = dc.font.ascent + dc.font.descent;
y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
x = dc.x + (h / 2); x = dc.x + (h / 2);
/* shorten text if necessary */ /* shorten text if necessary */
for(; len && (w = textnw(buf, len)) > dc.w - h; len--); for(; len && (i = textnw(buf, len)) > dc.w - h; len--);
if(!len) if(!len)
return; return;
if(len < olen) if(len < olen)
memcpy(&buf[MAX(0, len - 3)], "...", 3); for(i = len; i >= MAX(0, len - 3); buf[i--] = '.');
XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
if(dc.font.set) if(dc.font.set)
XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);

Loading…
Cancel
Save