+ XSync (dpy, False);
+ return True;
+
+# endif /* !USE_EXTERNAL_SCREEN_GRABBER */
+}
+
+
+/* Whether the given Drawable is unreasonably small.
+ */
+static Bool
+drawable_miniscule_p (Display *dpy, Drawable drawable)
+{
+ Window root;
+ int xx, yy;
+ unsigned int bw, d, w = 0, h = 0;
+ XGetGeometry (dpy, drawable, &root, &xx, &yy, &w, &h, &bw, &d);
+ return (w < 32 || h < 32);
+}
+
+
+/* Grabs an image (from a file, video, or the desktop) and renders it on
+ the Drawable. If `file' is specified, always use that file. Otherwise,
+ select randomly, based on the other arguments.
+ */
+static void
+get_image (Screen *screen,
+ Window window, Drawable drawable,
+ Bool verbose_p,
+ Bool desk_p,
+ Bool video_p,
+ Bool image_p,
+ const char *dir,
+ const char *file)
+{
+ Display *dpy = DisplayOfScreen (screen);
+ grab_type which = GRAB_BARS;
+ struct stat st;
+ const char *file_prop = 0;
+ char *absfile = 0;
+ XRectangle geom = { 0, 0, 0, 0 };
+
+ if (! drawable_window_p (dpy, window))
+ {
+ fprintf (stderr, "%s: 0x%lx is a pixmap, not a window!\n",
+ progname, (unsigned long) window);
+ exit (1);
+ }
+
+ /* Make sure the Screen and the Window correspond. */
+ {
+ XWindowAttributes xgwa;
+ XGetWindowAttributes (dpy, window, &xgwa);
+ screen = xgwa.screen;
+ }
+
+ if (file && stat (file, &st))
+ {
+ fprintf (stderr, "%s: file \"%s\" does not exist\n", progname, file);
+ file = 0;
+ }
+
+ if (verbose_p)
+ {
+ fprintf (stderr, "%s: grabDesktopImages: %s\n",
+ progname, desk_p ? "True" : "False");
+ fprintf (stderr, "%s: grabVideoFrames: %s\n",
+ progname, video_p ? "True" : "False");
+ fprintf (stderr, "%s: chooseRandomImages: %s\n",
+ progname, image_p ? "True" : "False");
+ fprintf (stderr, "%s: imageDirectory: %s\n",
+ progname, (file ? file : dir ? dir : ""));
+ }
+
+# if !(defined(HAVE_GDK_PIXBUF) || defined(HAVE_JPEGLIB))
+ image_p = False; /* can't load images from files... */
+# ifdef USE_EXTERNAL_SCREEN_GRABBER
+ desk_p = False; /* ...or from desktops grabbed to files. */
+# endif
+
+ if (file)
+ {
+ fprintf (stderr,
+ "%s: image file loading not available at compile-time\n",
+ progname);
+ fprintf (stderr, "%s: can't load \"%s\"\n", progname, file);
+ file = 0;
+ }
+# endif /* !(HAVE_GDK_PIXBUF || HAVE_JPEGLIB) */
+
+ if (file)
+ {
+ desk_p = False;
+ video_p = False;
+ image_p = True;
+ }
+ else if (!dir || !*dir)
+ {
+ if (verbose_p && image_p)
+ fprintf (stderr,
+ "%s: no imageDirectory: turning off chooseRandomImages.\n",
+ progname);
+ image_p = False;
+ }
+
+ /* If the target drawable is really small, no good can come of that.
+ Always do colorbars in that case.
+ */
+ if (drawable_miniscule_p (dpy, drawable))
+ {
+ desk_p = False;
+ video_p = False;
+ image_p = False;
+ }
+
+# ifndef _VROOT_H_
+# error Error! This file definitely needs vroot.h!
+# endif
+
+ /* We can grab desktop images (using the normal X11 method) if:
+ - the window is the real root window;
+ - the window is a toplevel window.
+ We cannot grab desktop images that way if:
+ - the window is a non-top-level window.
+
+ Under X11 on MacOS, desktops are just like loaded image files.
+ Under Cocoa on MacOS, this code is not used at all.
+ */
+# ifndef USE_EXTERNAL_SCREEN_GRABBER
+ if (desk_p)
+ {
+ if (!top_level_window_p (screen, window))
+ {
+ desk_p = False;
+ if (verbose_p)
+ fprintf (stderr,
+ "%s: 0x%x not top-level: turning off grabDesktopImages.\n",
+ progname, (unsigned int) window);
+ }