- else {
- if(dc.font.xfont)
- XFreeFont(dpy, dc.font.xfont);
- dc.font.xfont = NULL;
- dc.font.xfont = XLoadQueryFont(dpy, fontstr);
- if (!dc.font.xfont)
- dc.font.xfont = XLoadQueryFont(dpy, "fixed");
- if (!dc.font.xfont)
- eprint("error, cannot init 'fixed' font\n");
- dc.font.ascent = dc.font.xfont->ascent;
- dc.font.descent = dc.font.xfont->descent;
+ if(missing)
+ XFreeStringList(missing);
+ return (dc->font.set || dc->font.xfont);
+}
+
+void
+mapdc(DC *dc, Window win, unsigned int w, unsigned int h) {
+ XCopyArea(dc->dpy, dc->canvas, win, dc->gc, 0, 0, w, h, 0, 0);
+}
+
+void
+resizedc(DC *dc, unsigned int w, unsigned int h) {
+ if(dc->canvas)
+ XFreePixmap(dc->dpy, dc->canvas);
+
+ dc->canvas = XCreatePixmap(dc->dpy, DefaultRootWindow(dc->dpy), w, h,
+ DefaultDepth(dc->dpy, DefaultScreen(dc->dpy)));
+ dc->w = w;
+ dc->h = h;
+}
+
+int
+textnw(DC *dc, const char *text, size_t len) {
+ if(dc->font.set) {
+ XRectangle r;
+
+ XmbTextExtents(dc->font.set, text, len, NULL, &r);
+ return r.width;