X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=driver%2Fxscreensaver-getimage.c;h=46e3019eee924e3024348b265e53402e49870395;hb=a94197e76a5dea5cb60542840809d6c20d0abbf3;hp=c5c302996315fd5e1352692292a9ac145603587c;hpb=8eb2873d7054e705c4e83f22d18c40946a9e2529;p=xscreensaver diff --git a/driver/xscreensaver-getimage.c b/driver/xscreensaver-getimage.c index c5c30299..46e3019e 100644 --- a/driver/xscreensaver-getimage.c +++ b/driver/xscreensaver-getimage.c @@ -16,6 +16,7 @@ #include "utils.h" #include +#include #include #ifdef HAVE_XMU @@ -32,6 +33,7 @@ #include "grabscreen.h" #include "resources.h" #include "colorbars.h" +#include "visual.h" #include "prefs.h" #include "vroot.h" @@ -129,6 +131,10 @@ get_image (Screen *screen, Window window, Bool verbose_p) enum { do_desk, do_video, do_image, do_bars } which = do_bars; int count = 0; + XWindowAttributes xgwa; + XGetWindowAttributes (dpy, window, &xgwa); + screen = xgwa.screen; + if (verbose_p) { fprintf (stderr, "%s: grabDesktopImages: %s\n", @@ -195,13 +201,17 @@ get_image (Screen *screen, Window window, Bool verbose_p) if (count == 0) which = do_bars; else - while (1) /* loop until we get one that's permitted */ - { - which = (random() % 3); - if (which == do_desk && desk_p) break; - if (which == do_video && video_p) break; - if (which == do_image && image_p) break; - } + { + int i = 0; + while (1) /* loop until we get one that's permitted */ + { + which = (random() % 3); + if (which == do_desk && desk_p) break; + if (which == do_video && video_p) break; + if (which == do_image && image_p) break; + if (++i > 200) abort(); + } + } if (which == do_desk) { @@ -215,8 +225,6 @@ get_image (Screen *screen, Window window, Bool verbose_p) } else if (which == do_bars) { - XWindowAttributes xgwa; - XGetWindowAttributes (dpy, window, &xgwa); if (verbose_p) fprintf (stderr, "%s: drawing colorbars\n", progname); draw_colorbars (dpy, window, 0, 0, xgwa.width, xgwa.height); @@ -271,8 +279,20 @@ get_image (Screen *screen, Window window, Bool verbose_p) { const char *odpy = DisplayString (dpy); char *ndpy = (char *) malloc(strlen(odpy) + 20); + char *s; + int screen_no = screen_number (screen); /* might not be default now */ + strcpy (ndpy, "DISPLAY="); - strcat (ndpy, odpy); + s = ndpy + strlen(ndpy); + strcpy (s, odpy); + + while (*s && *s != ':') s++; /* skip to colon */ + while (*s == ':') s++; /* skip over colons */ + while (isdigit(*s)) s++; /* skip over dpy number */ + while (*s == '.') s++; /* skip over dot */ + if (s[-1] != '.') *s++ = '.'; /* put on a dot */ + sprintf(s, "%d", screen_no); /* put on screen number */ + if (putenv (ndpy)) abort (); }