X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fcoral.c;h=0f7f255a544a3a88e968f5a6ec0edfdd4e7b1398;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=b69f4361c2b34afd5c6f4079082d796e61fa5b00;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/hacks/coral.c b/hacks/coral.c index b69f4361..0f7f255a 100644 --- a/hacks/coral.c +++ b/hacks/coral.c @@ -67,7 +67,7 @@ init_coral(struct state *st) if(!st->board) exit(1); cmap = xgwa.colormap; if( st->ncolors ) { - free_colors(st->dpy, cmap, st->colors, st->ncolors); + free_colors(xgwa.screen, cmap, st->colors, st->ncolors); st->ncolors = 0; } gcv.foreground = st->default_fg_pixel = get_pixel_resource(st->dpy, cmap, "foreground", "Foreground"); @@ -75,7 +75,8 @@ init_coral(struct state *st) gcv.foreground = get_pixel_resource (st->dpy, cmap, "background", "Background"); st->erase_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv); st->ncolors = NCOLORSMAX; - make_uniform_colormap(st->dpy, xgwa.visual, cmap, st->colors, &st->ncolors, True, &writeable, False); + make_uniform_colormap(xgwa.screen, xgwa.visual, cmap, + st->colors, &st->ncolors, True, &writeable, False); if (st->ncolors <= 0) { st->ncolors = 2; st->colors[0].red = st->colors[0].green = st->colors[0].blue = 0; @@ -100,12 +101,15 @@ init_coral(struct state *st) st->colorsloth = st->nwalkers*2/st->ncolors; XSetForeground(st->dpy, st->draw_gc, st->colors[st->colorindex].pixel); + if ((st->width <= 2) || (st->height <= 2)) return; + for( i = 0; i < seeds; i++ ) { int x, y; + int max_repeat = 10; do { x = 1 + random() % (st->width - 2); y = 1 + random() % (st->height - 2); - } while( getdot(x, y) ); + } while( getdot(x, y) && max_repeat--); setdot((x-1), (y-1)); setdot(x, (y-1)); setdot((x+1), (y-1)); setdot((x-1), y ); setdot(x, y ); setdot((x+1), y ); @@ -169,7 +173,8 @@ coral(struct state *st) st->nwalkers--; st->walkers[i].x = st->walkers[st->nwalkers].x; st->walkers[i].y = st->walkers[st->nwalkers].y; - if( 0 == (st->nwalkers%st->colorsloth) ) { + if( 0 == + ((st->colorsloth ? st->nwalkers%st->colorsloth : 0)) ) { color = True; } @@ -257,11 +262,19 @@ static void coral_reshape (Display *dpy, Window window, void *closure, unsigned int w, unsigned int h) { + struct state *st = (struct state *) closure; + init_coral(st); } static Bool coral_event (Display *dpy, Window window, void *closure, XEvent *event) { + struct state *st = (struct state *) closure; + if (screenhack_event_helper (dpy, window, event)) + { + st->reset = 1; + return True; + } return False; } @@ -278,10 +291,14 @@ coral_free (Display *dpy, Window window, void *closure) static const char *coral_defaults[] = { ".background: black", ".foreground: white", + "*fpsSolid: true", "*density: 25", "*seeds: 20", /* too many for 640x480, too few for 1280x1024 */ "*delay: 5", "*delay2: 20000", +#ifdef HAVE_MOBILE + "*ignoreRotation: True", +#endif 0 };