X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fspotlight.c;h=2616b849a9662c0561607849bb78f8379fe85fcf;hp=209a67c80351a7d6b5500d41db0597116342b87d;hb=ffd8c0873576a9e3065696a624dce6b766b77062;hpb=8eb2873d7054e705c4e83f22d18c40946a9e2529 diff --git a/hacks/spotlight.c b/hacks/spotlight.c index 209a67c8..2616b849 100644 --- a/hacks/spotlight.c +++ b/hacks/spotlight.c @@ -50,6 +50,10 @@ static GC clip_gc; /* GC for the clip pixmap */ static int x, y, s; /* x & y coords of buffer (upper left corner) */ /* s is the width of the buffer */ +static int off = 0; /* random offset from currentTimeInMs(), so that + two concurrent copies of spotlight have different + behavior. */ + static int oldx, oldy, max_x_speed, max_y_speed; /* used to keep the new buffer position over the old spotlight image to make sure @@ -109,14 +113,11 @@ init_hack (Display *dpy, Window window) #endif window_gc = XCreateGC(dpy, window, gcflags, &gcv); - - /* grab screen to window */ - grab_screen_image(xgwa.screen, window); - - /* save screen to pixmap for copying later */ + /* grab screen to pixmap */ pm = XCreatePixmap(dpy, window, sizex, sizey, xgwa.depth); - XCopyArea(dpy, window, pm, window_gc, 0, 0, sizex, sizey, 0, 0); - + load_random_image (xgwa.screen, window, pm, NULL); + XClearWindow(dpy, window); + XFlush (dpy); /* create buffer to reduce flicker */ buffer = XCreatePixmap(dpy, window, sizex, sizey, xgwa.depth); @@ -147,19 +148,14 @@ init_hack (Display *dpy, Window window) /* avoid remants */ max_x_speed = max_y_speed = radius; + + off = random(); #ifdef DEBUG /* create GC with white fg */ gcv.foreground = fg; white_gc = XCreateGC(dpy, window, gcflags, &gcv); #endif - - /* initialize x and y to avoid initial `jump' across screen */ - x = ((1 + sin(((float)currentTimeInMs()) / X_PERIOD * 2. * M_PI))/2.0) - * (sizex - s/2) -s/4 + MINX; - y = ((1 + sin(((float)currentTimeInMs()) / Y_PERIOD * 2. * M_PI))/2.0) - * (sizey - s/2) -s/4 + MINY; - } @@ -167,7 +163,7 @@ init_hack (Display *dpy, Window window) * perform one iteration */ static void -onestep (Display *dpy, Window window) +onestep (Display *dpy, Window window, Bool first_p) { long now; @@ -182,7 +178,7 @@ onestep (Display *dpy, Window window) s = radius *4 ; /* s = width of buffer */ - now = currentTimeInMs(); + now = currentTimeInMs() + off; /* find new x,y */ x = ((1 + sin(((float)now) / X_PERIOD * 2. * M_PI))/2.0) @@ -190,11 +186,14 @@ onestep (Display *dpy, Window window) y = ((1 + sin(((float)now) / Y_PERIOD * 2. * M_PI))/2.0) * (sizey - s/2) -s/4 + MINY; - /* limit change in x and y to buffer width */ - if ( x < (oldx - max_x_speed) ) x = oldx - max_x_speed; - if ( x > (oldx + max_x_speed) ) x = oldx + max_x_speed; - if ( y < (oldy - max_y_speed) ) y = oldy - max_y_speed; - if ( y > (oldy + max_y_speed) ) y = oldy + max_y_speed; + if (!first_p) + { + /* limit change in x and y to buffer width */ + if ( x < (oldx - max_x_speed) ) x = oldx - max_x_speed; + if ( x > (oldx + max_x_speed) ) x = oldx + max_x_speed; + if ( y < (oldy - max_y_speed) ) y = oldy - max_y_speed; + if ( y > (oldy + max_y_speed) ) y = oldy + max_y_speed; + } /* copy area of screen image (pm) to buffer Clip to a circle */ @@ -217,6 +216,8 @@ onestep (Display *dpy, Window window) char *progclass = "Spotlight"; char *defaults [] = { + ".background: black", + ".foreground: white", "*dontClearRoot: True", #ifdef __sgi /* really, HAVE_READ_DISPLAY_EXTENSION */ @@ -237,9 +238,11 @@ XrmOptionDescRec options [] = { void screenhack (Display *dpy, Window window) { + Bool first_p = True; init_hack (dpy, window); while (1) { - onestep(dpy, window); + onestep(dpy, window, first_p); + first_p = False; XSync(dpy, False); if (delay) usleep (delay); screenhack_handle_events (dpy);