X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fsquiral.c;h=48cd5f8c9049e11b5560973d0e0820a89bff58e1;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=3e13116e534e0c63219bf884362c10fd0100d0fd;hpb=07faf451b99879183ed7e909e43a0e065be1ee7f;p=xscreensaver diff --git a/hacks/squiral.c b/hacks/squiral.c index 3e13116e..48cd5f8c 100644 --- a/hacks/squiral.c +++ b/hacks/squiral.c @@ -14,7 +14,7 @@ #include "erase.h" #include "yarandom.h" -#define R(x) (abs(random())%x) +#define R(x) (random()%x) #define PROB(x) (frand(1.0) < (x)) #define NCOLORSMAX 255 @@ -107,6 +107,28 @@ do_worm(struct state *st, struct worm *w) w->v = w->v % st->height; } +static void +squiral_init_1 (struct state *st) +{ + int i; + if (st->worms) free (st->worms); + if (st->fill) free (st->fill); + + st->worms=calloc(st->count, sizeof(struct worm)); + st->fill=calloc(st->width*st->height, sizeof(int)); + + st->dirh[0]=0; st->dirh[1]=1; st->dirh[2]=0; st->dirh[3]=st->width-1; + st->dirv[0]=st->height-1; st->dirv[1]=0; st->dirv[2]=1; st->dirv[3]=0; + for(i=0;icount;i++) { + st->worms[i].h=R(st->width); + st->worms[i].v=R(st->height); + st->worms[i].s=R(4)+4*PROB(st->handedness); + st->worms[i].c=R(st->ncolors); + if(st->cycle) { st->worms[i].cc=R(3)+st->ncolors; } + else st->worms[i].cc=0; + } +} + static void * squiral_init (Display *dpy, Window window) { @@ -115,7 +137,6 @@ squiral_init (Display *dpy, Window window) Colormap cmap; XWindowAttributes xgwa; Bool writeable = False; - int i; st->dpy = dpy; st->window = window; @@ -135,7 +156,7 @@ squiral_init (Display *dpy, Window window) st->erase_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv); 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; } if( mono_p ) { @@ -145,7 +166,8 @@ squiral_init (Display *dpy, Window window) st->ncolors = get_integer_resource(st->dpy, "ncolors", "Integer"); if (st->ncolors < 0 || st->ncolors > NCOLORSMAX) st->ncolors = NCOLORSMAX; - make_uniform_colormap(st->dpy, xgwa.visual, cmap, st->colors, &st->ncolors, True, + make_uniform_colormap(xgwa.screen, xgwa.visual, cmap, + st->colors, &st->ncolors, True, &writeable, False); if (st->ncolors <= 0) { st->ncolors = 1; @@ -167,19 +189,7 @@ squiral_init (Display *dpy, Window window) if(st->worms) free(st->worms); if(st->fill) free(st->fill); - st->worms=calloc(st->count, sizeof(struct worm)); - st->fill=calloc(st->width*st->height, sizeof(int)); - - st->dirh[0]=0; st->dirh[1]=1; st->dirh[2]=0; st->dirh[3]=st->width-1; - st->dirv[0]=st->height-1; st->dirv[1]=0; st->dirv[2]=1; st->dirv[3]=0; - for(i=0;icount;i++) { - st->worms[i].h=R(st->width); - st->worms[i].v=R(st->height); - st->worms[i].s=R(4)+4*PROB(st->handedness); - st->worms[i].c=R(st->ncolors); - if(st->cycle) { st->worms[i].cc=R(3)+st->ncolors; } - else st->worms[i].cc=0; - } + squiral_init_1 (st); return st; } @@ -219,11 +229,23 @@ static void squiral_reshape (Display *dpy, Window window, void *closure, unsigned int w, unsigned int h) { + struct state *st = (struct state *) closure; + st->width = w; + st->height = h; + squiral_init_1 (st); + XClearWindow (dpy, window); } static Bool squiral_event (Display *dpy, Window window, void *closure, XEvent *event) { + struct state *st = (struct state *) closure; + if (screenhack_event_helper (dpy, window, event)) + { + squiral_init_1 (st); + XClearWindow (dpy, window); + return True; + } return False; } @@ -238,13 +260,17 @@ squiral_free (Display *dpy, Window window, void *closure) static const char *squiral_defaults[] = { ".background: black", ".foreground: white", + "*fpsSolid: true", "*fill: 75", "*count: 0", "*ncolors: 100", - "*delay: 1000", + "*delay: 10000", "*disorder: 0.005", "*cycle: False", - "*handedness: .5", + "*handedness: 0.5", +#ifdef HAVE_MOBILE + "*ignoreRotation: True", +#endif 0 };