+#endif /* !XMU */
+}
+
+
+static Pixmap
+read_screen (Display *dpy, Window window, int *widthP, int *heightP)
+{
+ 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];
+}
+
+static void
+init (void)
+{
+ XWindowAttributes xgwa;
+ Colormap cmap;
+ XGCValues gcv;
+ int width, height;
+ char *bitmap_name;
+ Bool scale_up;
+
+ XGetWindowAttributes (dpy, window, &xgwa);
+ cmap = xgwa.colormap;
+ depth = xgwa.depth;
+
+ fg = get_pixel_resource ("foreground", "Foreground", dpy, cmap);
+ bg = get_pixel_resource ("background", "Background", dpy, cmap);
+ delay = get_integer_resource ("delay", "Integer");
+ delay2 = get_integer_resource ("delay2", "Integer");
+ if (delay < 0) delay = 0;
+ if (delay2 < 0) delay2 = 0;
+ bitmap_name = get_string_resource ("bitmap", "Bitmap");
+ if (! bitmap_name || !*bitmap_name)
+ bitmap_name = "(default)";
+
+ if (!strcmp (bitmap_name, "(default)"))
+ {
+ width = som_width;
+ height = som_height;
+ bitmap = XCreatePixmapFromBitmapData (dpy, window, (char *) som_bits,
+ width, height, fg, bg, depth);
+ scale_up = True; /* definitely. */
+ }
+ else if (!strcmp (bitmap_name, "(screen)"))
+ {
+ bitmap = read_screen (dpy, window, &width, &height);
+ scale_up = True; /* maybe? */
+ }
+ else
+ {
+ read_bitmap (bitmap_name, &width, &height);
+ scale_up = True; /* probably? */
+ }