-/* static */
-
-static void
-drawcaret(unsigned long col[ColLast]) {
- int x;
- XGCValues gcv;
- XPoint pt[3];
-
- gcv.foreground = col[ColFG];
- XChangeGC(dpy, dc.gc, GCForeground, &gcv);
- x = (dc.font.ascent + dc.font.descent) / 2;
- pt[0].x = dc.x + 1;
- pt[0].y = dc.y + 1 + x;
- pt[1].x = 0;
- pt[1].y = -x;
- pt[2].x = x;
- pt[2].y = 0;
- XDrawLines(dpy, dc.drawable, dc.gc, pt, 3, CoordModePrevious);
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define DEFAULTFN "fixed"
+
+static Bool loadfont(DC *dc, const char *fontstr);
+
+void
+drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color) {
+ XSetForeground(dc->dpy, dc->gc, color);
+ if(fill)
+ XFillRectangle(dc->dpy, dc->canvas, dc->gc, dc->x + x, dc->y + y, w, h);
+ else
+ XDrawRectangle(dc->dpy, dc->canvas, dc->gc, dc->x + x, dc->y + y, w-1, h-1);
+}
+
+void
+drawtext(DC *dc, const char *text, unsigned long col[ColLast]) {
+ char buf[BUFSIZ];
+ size_t mn, n = strlen(text);
+
+ /* shorten text if necessary */
+ for(mn = MIN(n, sizeof buf); textnw(dc, text, mn) + dc->font.height/2 > dc->w; mn--)
+ if(mn == 0)
+ return;
+ memcpy(buf, text, mn);
+ if(mn < n)
+ for(n = MAX(mn-3, 0); n < mn; buf[n++] = '.');
+
+ drawrect(dc, 0, 0, dc->w, dc->h, True, BG(dc, col));
+ drawtextn(dc, buf, mn, col);