Ejemplo n.º 1
0
/* Loads an image into the Drawable, returning once the image is loaded.
 */
static void
load_random_image_android (Screen *screen, Window window, Drawable drawable,
                           void (*callback) (Screen *, Window, Drawable,
                                             const char *name,
                                             XRectangle *geom, void *closure),
                           void *closure)
{
  Display *dpy = DisplayOfScreen (screen);
  XWindowAttributes xgwa;
  XRectangle geom;
  char *name = 0;
  char *data = 0;
  int width  = 0;
  int height = 0;
  
  if (!drawable) abort();

  XGetWindowAttributes (dpy, window, &xgwa);
  {
    Window r;
    int x, y;
    unsigned int w, h, bbw, d;
    XGetGeometry (dpy, drawable, &r, &x, &y, &w, &h, &bbw, &d);
    xgwa.width = w;
    xgwa.height = h;
  }

  geom.x = 0;
  geom.y = 0;
  geom.width  = xgwa.width;
  geom.height = xgwa.height;

  data = jwxyz_load_random_image (dpy, &width, &height, &name);
  if (! data)
    draw_colorbars (screen, xgwa.visual, drawable, xgwa.colormap,
                    0, 0, xgwa.width, xgwa.height);
  else
    {
      XImage *img = XCreateImage (dpy, xgwa.visual, 32,
                                  ZPixmap, 0, data, width, height, 0, 0);
      XGCValues gcv;
      GC gc;
      gcv.foreground = BlackPixelOfScreen (screen);
      gc = XCreateGC (dpy, drawable, GCForeground, &gcv);
      XFillRectangle (dpy, drawable, gc, 0, 0, xgwa.width, xgwa.height);
      XPutImage (dpy, drawable, gc, img, 0, 0, 
                 (xgwa.width  - width) / 2,
                 (xgwa.height - height) / 2,
                 width, height);
      XDestroyImage (img);
      XFreeGC (dpy, gc);
    }

  callback (screen, window, drawable, name, &geom, closure);
  if (name) free (name);
}
Ejemplo n.º 2
0
/* Callback for ios_load_random_image(), called after we have loaded an
   image from the iOS device's Photo Library.  See iosgrabimage.m.
 */
static void
ios_load_random_image_cb (void *uiimage, const char *filename, 
                          int width, int height, void *closure)
{
  struct pipe_closure *clo2 = (struct pipe_closure *) closure;
  Display *dpy = DisplayOfScreen (clo2->screen);
  XRectangle geom;
  XWindowAttributes xgwa;
  Window r;
  int x, y;
  unsigned int w, h, bbw, d;
  int rot = 0;

  XGetWindowAttributes (dpy, clo2->xwindow, &xgwa);
  XGetGeometry (dpy, clo2->drawable, &r, &x, &y, &w, &h, &bbw, &d);

  /* If the image is portrait and the window is landscape, or vice versa,
     rotate the image. The idea is to fill up as many pixels as possible,
     and assume the user will just rotate their phone until it looks right.
     This makes "decayscreen", etc. much more easily viewable.
   */
  if (get_boolean_resource (dpy, "rotateImages", "RotateImages")) {
    if ((width > height) != (w > h))
      rot = 5;
  }

  if (uiimage)
    {
      jwxyz_draw_NSImage_or_CGImage (DisplayOfScreen (clo2->screen), 
                                     clo2->drawable,
                                     True, uiimage, &geom,
                                     rot);
    }
  else  /* Probably means no images in the gallery. */
    {
      draw_colorbars (clo2->screen, xgwa.visual, clo2->drawable, xgwa.colormap,
                      0, 0, w, h);
      geom.x = geom.y = 0;
      geom.width = w;
      geom.height = h;
      filename = 0;
    }

  clo2->callback (clo2->screen, clo2->xwindow, clo2->drawable,
                  filename, &geom, clo2->closure);
  clo2->callback = 0;
  if (clo2->directory) free (clo2->directory);
  free (clo2);
}
Ejemplo n.º 3
0
/* Callback for ios_load_random_image(), called after we have loaded an
   image from the iOS device's Photo Library.  See iosgrabimage.m.
 */
static void
ios_load_random_image_cb (void *uiimage, const char *filename, void *closure)
{
  struct pipe_closure *clo2 = (struct pipe_closure *) closure;
  Display *dpy = DisplayOfScreen (clo2->screen);
  XRectangle geom;

  if (uiimage)
    {
      jwxyz_draw_NSImage_or_CGImage (DisplayOfScreen (clo2->screen), 
                                     clo2->drawable,
                                     True, uiimage, &geom,
                                     0);
    }
  else  /* Probably means no images in the gallery. */
    {
      XWindowAttributes xgwa;
      Window r;
      int x, y;
      unsigned int w, h, bbw, d;
      XGetWindowAttributes (dpy, clo2->xwindow, &xgwa);
      XGetGeometry (dpy, clo2->drawable, &r, &x, &y, &w, &h, &bbw, &d);
      draw_colorbars (clo2->screen, xgwa.visual, clo2->drawable, xgwa.colormap,
                      0, 0, w, h);
      geom.x = geom.y = 0;
      geom.width = w;
      geom.height = h;
      filename = 0;
    }

  clo2->callback (clo2->screen, clo2->xwindow, clo2->drawable,
                  filename, &geom, clo2->closure);
  clo2->callback = 0;
  if (clo2->directory) free (clo2->directory);
  free (clo2);
}
Ejemplo n.º 4
0
/* Loads an image into the Drawable, returning once the image is loaded.
 */
static void
load_random_image_1 (Screen *screen, Window window, Drawable drawable,
                     void (*callback) (Screen *, Window, Drawable,
                                       const char *name, XRectangle *geom,
                                       void *closure),
                     void *closure,
                     char **name_ret,
                     XRectangle *geom_ret)
{
  Display *dpy = DisplayOfScreen (screen);
  XWindowAttributes xgwa;
  Bool deskp = get_boolean_resource (dpy, "grabDesktopImages",  "Boolean");
  Bool filep = get_boolean_resource (dpy, "chooseRandomImages", "Boolean");
  const char *dir = 0;
  Bool done = False;
  XRectangle geom_ret_2;
  char *name_ret_2 = 0;
  
  if (!drawable) abort();

  if (callback) {
    geom_ret = &geom_ret_2;
    name_ret = &name_ret_2;
  }

  XGetWindowAttributes (dpy, window, &xgwa);
  {
    Window r;
    int x, y;
    unsigned int w, h, bbw, d;
    XGetGeometry (dpy, drawable, &r, &x, &y, &w, &h, &bbw, &d);
    xgwa.width = w;
    xgwa.height = h;
  }

  if (name_ret)
    *name_ret = 0;

  if (geom_ret) {
    geom_ret->x = 0;
    geom_ret->y = 0;
    geom_ret->width  = xgwa.width;
    geom_ret->height = xgwa.height;
  }

# ifndef USE_IPHONE
  if (filep)
    dir = get_string_resource (dpy, "imageDirectory", "ImageDirectory");

  if (!dir || !*dir)
    filep = False;
# endif /* ! USE_IPHONE */

  if (deskp && filep) {
    deskp = !(random() & 5);    /* if both, desktop 1/5th of the time */
    filep = !deskp;
  }

  if (filep && !done) {
    osx_load_image_file_async (screen, window, drawable, dir, 
                               callback, closure);
    return;
  }

  if (deskp && !done) {
    if (osx_grab_desktop_image (screen, window, drawable, &geom_ret_2)) {
      if (name_ret)
        *name_ret = strdup ("desktop");
      done = True;
    }
  }

  if (! done)
    draw_colorbars (screen, xgwa.visual, drawable, xgwa.colormap,
                    0, 0, xgwa.width, xgwa.height);

  if (callback) {
    /* If we got here, we loaded synchronously even though they wanted async.
     */
    callback (screen, window, drawable, name_ret_2, &geom_ret_2, closure);
    if (name_ret_2) free (name_ret_2);
  }
}
Ejemplo n.º 5
0
static void
pipe_cb (XtPointer closure, int *source, XtInputId *id)
{
  /* This is not called from a signal handler, so doing stuff here is fine.
   */
  struct pipe_closure *clo2 = (struct pipe_closure *) closure;
  char buf[10240];
  const char *dir = clo2->directory;
  char *absfile = 0;
  *buf = 0;
  fgets (buf, sizeof(buf)-1, clo2->pipe);
  pclose (clo2->pipe);
  clo2->pipe = 0;
  XtRemoveInput (clo2->id);
  clo2->id = 0;

  /* strip trailing newline */
  int L = strlen(buf);
  while (L > 0 && (buf[L-1] == '\r' || buf[L-1] == '\n'))
    buf[--L] = 0;

  Display *dpy = DisplayOfScreen (clo2->screen);
  XRectangle geom;

  if (*buf && *buf != '/')		/* pathname is relative to dir. */
    {
      absfile = malloc (strlen(dir) + strlen(buf) + 10);
      strcpy (absfile, dir);
      if (dir[strlen(dir)-1] != '/')
        strcat (absfile, "/");
      strcat (absfile, buf);
    }

  if (! osx_load_image_file (clo2->screen, clo2->xwindow, clo2->drawable,
                             (absfile ? absfile : buf), &geom)) {
    /* unable to load image - draw colorbars 
     */
    XWindowAttributes xgwa;
    XGetWindowAttributes (dpy, clo2->xwindow, &xgwa);
    Window r;
    int x, y;
    unsigned int w, h, bbw, d;
    struct stat st;

    /* Log something to syslog so we can tell the difference between
       corrupted images and broken symlinks. */
    if (!*buf)
      fprintf (stderr, "%s: no image filename found\n", progname);
    else if (! stat (buf, &st))
      fprintf (stderr, "%s: %s: unparsable\n", progname, buf);
    else
      {
        char buf2[2048];
        sprintf (buf2, "%.255s: %.1024s", progname, buf);
        perror (buf2);
      }

    XGetGeometry (dpy, clo2->drawable, &r, &x, &y, &w, &h, &bbw, &d);
    draw_colorbars (clo2->screen, xgwa.visual, clo2->drawable, xgwa.colormap,
                    0, 0, w, h);
    geom.x = geom.y = 0;
    geom.width = w;
    geom.height = h;
  }

  /* Take the extension off of the file name. */
  /* Duplicated in driver/xscreensaver-getimage.c. */
  if (buf && *buf)
    {
      char *slash = strrchr (buf, '/');
      char *dot = strrchr ((slash ? slash : buf), '.');
      if (dot) *dot = 0;
      /* Replace slashes with newlines */
      /* while (dot = strchr(buf, '/')) *dot = '\n'; */
      /* Replace slashes with spaces */
      /* while ((dot = strchr(buf, '/'))) *dot = ' '; */
    }

  if (absfile) free (absfile);
  clo2->callback (clo2->screen, clo2->xwindow, clo2->drawable, buf, &geom,
                  clo2->closure);
  clo2->callback = 0;
  free (clo2->directory);
  free (clo2);
}