-#ifdef HAVE_XPM
- XpmAttributes xpmattrs;
- int result;
- xpmattrs.valuemask = 0;
- bitmap = 0;
- result = XpmReadFileToPixmap (dpy, window, bitmap_name, &bitmap, 0,
- &xpmattrs);
- switch (result)
- {
- case XpmColorError:
- fprintf (stderr, "%s: warning: xpm color substitution performed\n",
- progname);
- /* fall through */
- case XpmSuccess:
- *widthP = xpmattrs.width;
- *heightP = xpmattrs.height;
- break;
- case XpmFileInvalid:
- case XpmOpenFailed:
- bitmap = 0;
- break;
- case XpmColorFailed:
- fprintf (stderr, "%s: xpm: color allocation failed\n", progname);
- exit (-1);
- case XpmNoMemory:
- fprintf (stderr, "%s: xpm: out of memory\n", progname);
- exit (-1);
- default:
- fprintf (stderr, "%s: xpm: unknown error code %d\n", progname, result);
- exit (-1);
- }
- if (! bitmap)
-#endif
- {
- int xh, yh;
- Pixmap b2;
- bitmap = XmuLocateBitmapFile (DefaultScreenOfDisplay (dpy), bitmap_name,
- 0, 0, widthP, heightP, &xh, &yh);
- if (! bitmap)
- {
- fprintf (stderr, "%s: couldn't find bitmap %s\n", progname,
- bitmap_name);
- exit (1);
- }
- b2 = XmuCreatePixmapFromBitmap (dpy, window, bitmap, *widthP, *heightP,
- depth, fg, bg);
- XFreePixmap (dpy, bitmap);
- bitmap = b2;
- }
+ Pixmap p;
+ XWindowAttributes xgwa;
+ XGCValues gcv;
+ GC gc;
+ XGetWindowAttributes (dpy, window, &xgwa);
+ *widthP = xgwa.width;
+ *heightP = xgwa.height;
+
+ grab_screen_image(xgwa.screen, window);
+ p = XCreatePixmap(dpy, window, *widthP, *heightP, xgwa.depth);
+ gcv.function = GXcopy;
+ gc = XCreateGC (dpy, window, GCFunction, &gcv);
+ XCopyArea (dpy, window, p, gc, 0, 0, *widthP, *heightP, 0, 0);
+
+ /* Reset the window's background color... */
+ XSetWindowBackground (dpy, window,
+ get_pixel_resource ("background", "Background",
+ dpy, xgwa.colormap));
+ XCopyArea (dpy, p, window, gc, 0, 0, *widthP, *heightP, 0, 0);
+ XFreeGC (dpy, gc);
+
+ return p;
+}
+
+
+static int
+to_pow2(int n, Bool up)
+{
+ /* sizeof(Dimension) == 2. */
+ int powers_of_2[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,
+ 2048, 4096, 8192, 16384, 32768, 65536 };
+ int i = 0;
+ if (n > 65536) size = 65536;
+ while (n >= powers_of_2[i]) i++;
+ if (n == powers_of_2[i-1])
+ return n;
+ else
+ return powers_of_2[up ? i : i-1];