- Pixmap p;
- GC gc;
- XGCValues gcv;
- XFillRectangle (st->dpy, st->window, st->backgroundGC, 0, 0,
- st->windowWidth, st->windowHeight);
-
- p = XCreatePixmap (st->dpy, st->window,
- xwa->width, xwa->height, xwa->depth);
- gc = XCreateGC (st->dpy, st->window, 0, &gcv);
- XCopyArea (st->dpy, st->window, p, gc, 0, 0,
- xwa->width, xwa->height, 0, 0);
- st->backgroundImage =
- XGetImage (st->dpy, p, 0, 0, st->windowWidth, st->windowHeight,
- ~0L, ZPixmap);
- XFreeGC (st->dpy, gc);
- XFreePixmap (st->dpy, p);
+ /* On MacOS X11, XGetImage on a Window often gets an inexplicable BadMatch,
+ possibly due to the window manager having occluded something? It seems
+ nondeterministic. Loading the image into a pixmap instead fixes it. */
+ if (st->pm) XFreePixmap (st->dpy, st->pm);
+ st->pm = XCreatePixmap (st->dpy, st->window,
+ xwa->width, xwa->height, xwa->depth);