-/* xscreensaver, Copyright (c) 1992-2013 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 1992-2014 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
# ifndef USE_IPHONE
+# define BACKSLASH(c) \
+ (! ((c >= 'a' && c <= 'z') || \
+ (c >= 'A' && c <= 'Z') || \
+ (c >= '0' && c <= '9') || \
+ c == '.' || c == '_' || c == '-' || c == '+' || c == '/'))
+
/* Gets the name of an image file to load by running xscreensaver-getimage-file
at the end of a pipe. This can be very slow!
*/
static FILE *
open_image_name_pipe (const char *dir)
{
- char *cmd = malloc (strlen(dir) * 2 + 100);
char *s;
- strcpy (cmd, "xscreensaver-getimage-file --name ");
- s = cmd + strlen (cmd);
+
+# ifdef HAVE_COCOA
+ /* /bin/sh on OS X 10.10 wipes out the PATH. */
+ const char *path = getenv("PATH");
+ char *cmd = s = malloc ((strlen(dir) + strlen(path)) * 2 + 100);
+ strcpy (s, "/bin/sh -c 'export PATH=");
+ s += strlen (s);
+ while (*path) {
+ char c = *path++;
+ if (BACKSLASH(c)) *s++ = '\\';
+ *s++ = c;
+ }
+ strcpy (s, "; ");
+ s += strlen (s);
+# else
+ char *cmd = s = malloc (strlen(dir) * 2 + 100);
+# endif
+
+ strcpy (s, "xscreensaver-getimage-file --name ");
+ s += strlen (s);
while (*dir) {
char c = *dir++;
- /* put a backslash in front of any character that might confuse sh. */
- if (! ((c >= 'a' && c <= 'z') ||
- (c >= 'A' && c <= 'Z') ||
- (c >= '0' && c <= '9') ||
- c == '.' || c == '_' || c == '-' || c == '+' || c == '/'))
- *s++ = '\\';
+ if (BACKSLASH(c)) *s++ = '\\';
*s++ = c;
}
+# ifdef HAVE_COCOA
+ strcpy (s, "'");
+ s += strlen (s);
+# endif
*s = 0;
FILE *pipe = popen (cmd, "r");
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;
/* Replace slashes with newlines */
/* while (dot = strchr(buf, '/')) *dot = '\n'; */
/* Replace slashes with spaces */
- while ((dot = strchr(buf, '/'))) *dot = ' ';
+ /* while ((dot = strchr(buf, '/'))) *dot = ' '; */
}
if (absfile) free (absfile);
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;
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");
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);