+ XGCValues gcv;
+
+ /* make it square */
+ st->size = (st->width < st->height) ? st->height : st->width;
+ st->size = to_pow2(st, st->size, st->scale_up); /* round up to power of 2 */
+ { /* don't exceed screen size */
+ int s = XScreenNumberOfScreen(st->xgwa.screen);
+ int w = to_pow2(st, XDisplayWidth(st->dpy, s), False);
+ int h = to_pow2(st, XDisplayHeight(st->dpy, s), False);
+ if (st->size > w) st->size = w;
+ if (st->size > h) st->size = h;
+ }
+
+ if (st->self) XFreePixmap (st->dpy, st->self);
+ if (st->temp) XFreePixmap (st->dpy, st->temp);
+ if (st->mask) XFreePixmap (st->dpy, st->mask);
+
+ st->self = XCreatePixmap (st->dpy, st->window, st->size, st->size,
+ st->xgwa.depth);
+ st->temp = XCreatePixmap (st->dpy, st->window, st->size, st->size,
+ st->xgwa.depth);
+ st->mask = XCreatePixmap (st->dpy, st->window, st->size, st->size,
+ st->xgwa.depth);
+ gcv.foreground = (st->xgwa.depth == 1 ? 1 : (~0));
+
+# ifdef USE_XCOPYAREA
+# define make_gc(op) \
+ gcv.function=GX##op; \
+ if (st->gc_##op) XFreeGC (st->dpy, st->gc_##op); \
+ st->gc_##op = XCreateGC (st->dpy, st->self, GCFunction|GCForeground, &gcv)
+ make_gc(set);
+ make_gc(clear);
+ make_gc(copy);
+ make_gc(and);
+ make_gc(or);
+ make_gc(xor);
+# endif /* USE_XCOPYAREA */
+
+ gcv.foreground = gcv.background = st->bg;
+ if (st->gc) XFreeGC (st->dpy, st->gc);
+ st->gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv);
+ /* Clear st->self to the background color (not to 0, which 'clear' does.) */
+ XFillRectangle (st->dpy, st->self, st->gc, 0, 0, st->size, st->size);
+ XSetForeground (st->dpy, st->gc, st->fg);
+
+ XCopyArea (st->dpy, st->bitmap, st->self, st->gc, 0, 0,
+ st->width, st->height,
+ (st->size - st->width) >> 1,
+ (st->size - st->height) >> 1);
+
+ st->qwad = -1;
+ st->first_time = 1;
+}
+
+static void
+display (struct state *st, Pixmap pixmap)
+{
+ XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
+
+ if (st->xgwa.width != st->last_w ||
+ st->xgwa.height != st->last_h)