- else {
- if(font->xfont)
- XFreeFont(dpy, font->xfont);
- font->xfont = 0;
- font->xfont = XLoadQueryFont(dpy, fontstr);
- if (!font->xfont)
- font->xfont = XLoadQueryFont(dpy, "fixed");
- if (!font->xfont)
- error("error, cannot load 'fixed' font\n");
- font->ascent = font->xfont->ascent;
- font->descent = font->xfont->descent;
+ XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
+ XSync(dpy, False);
+}
+
+void
+drawtext(const char *text, unsigned long col[ColLast]) {
+ int x, y, w, h;
+ static char buf[256];
+ unsigned int len, olen;
+ XRectangle r = { dc.x, dc.y, dc.w, dc.h };
+
+ XSetForeground(dpy, dc.gc, col[ColBG]);
+ XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
+ if(!text)
+ return;
+ w = 0;
+ olen = len = strlen(text);
+ if(len >= sizeof buf)
+ len = sizeof buf - 1;
+ memcpy(buf, text, len);
+ buf[len] = 0;
+ h = dc.font.ascent + dc.font.descent;
+ y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
+ x = dc.x + (h / 2);
+ /* shorten text if necessary */
+ while(len && (w = textnw(buf, len)) > dc.w - h)
+ buf[--len] = 0;
+ if(len < olen) {
+ if(len > 1)
+ buf[len - 1] = '.';
+ if(len > 2)
+ buf[len - 2] = '.';
+ if(len > 3)
+ buf[len - 3] = '.';