X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utils%2Fgrabclient.c;h=dd8b225807843f995af36529161df20aaecc3e66;hb=6afd6db0ae9396cd7ff897ade597cd5483f49b0e;hp=58d506efd888ac9a3b7c7a06fdbd91aacad72ab5;hpb=6f5482d73adb0165c0130bb47d852644ab0c4869;p=xscreensaver diff --git a/utils/grabclient.c b/utils/grabclient.c index 58d506ef..dd8b2258 100644 --- a/utils/grabclient.c +++ b/utils/grabclient.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992-2012 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992-2014 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -564,6 +564,7 @@ pipe_cb (XtPointer closure, int *source, XtInputId *id) 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; @@ -619,6 +620,19 @@ pipe_cb (XtPointer closure, int *source, XtInputId *id) 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); @@ -634,27 +648,40 @@ pipe_cb (XtPointer closure, int *source, XtInputId *id) 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) +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, - 0); + rot); } 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; @@ -810,6 +837,7 @@ load_random_image_1 (Screen *screen, Window window, Drawable drawable, /* 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); } } @@ -847,7 +875,7 @@ print_loading_msg (Screen *screen, Window window) fn = 0; XGetWindowAttributes (dpy, window, &xgwa); - w = XTextWidth (f, text, strlen(text)); + w = XTextWidth (f, text, (int) strlen(text)); gcv.foreground = get_pixel_resource (dpy, xgwa.colormap, "foreground", "Foreground"); @@ -858,7 +886,7 @@ print_loading_msg (Screen *screen, Window window) XDrawImageString (dpy, window, gc, (xgwa.width - w) / 2, (xgwa.height - (f->ascent + f->descent)) / 2 + f->ascent, - text, strlen(text)); + text, (int) strlen(text)); XFreeFont (dpy, f); XFreeGC (dpy, gc); XSync (dpy, False);