- else {
- if(font->xfont)
- XFreeFont(dpy, font->xfont);
- font->xfont = NULL;
- font->xfont = XLoadQueryFont(dpy, fontstr);
- if (!font->xfont)
- font->xfont = XLoadQueryFont(dpy, "fixed");
- if (!font->xfont)
- eprint("error, cannot load 'fixed' font\n");
- font->ascent = font->xfont->ascent;
- font->descent = font->xfont->descent;
+ else if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) {
+ 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->x = dc->y = 0;
+ dc->w = w;
+ dc->h = h;
+ dc->invert = False;
+}
+
+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;