X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fdecayscreen.c;h=8b45af9e675846d56e0f201ec2f017afc2fec065;hb=78add6e627ee5f10e1fa6f3852602ea5066eee5a;hp=855d80a5e45dc819445d4219d838619fd7d18602;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/hacks/decayscreen.c b/hacks/decayscreen.c index 855d80a5..8b45af9e 100644 --- a/hacks/decayscreen.c +++ b/hacks/decayscreen.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992-2006 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992-2018 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -36,16 +36,22 @@ */ #include "screenhack.h" +#include struct state { Display *dpy; Window window; + XWindowAttributes xgwa; + Pixmap saved; + int saved_w, saved_h; int sizex, sizey; int delay; + int duration; GC gc; int mode; - int iterations; + int random_p; + time_t start_time; int fuzz_toggle; const int *current_bias; @@ -69,18 +75,31 @@ struct state { #define STRETCH 12 #define FUZZ 13 +static void +decayscreen_load_image (struct state *st) +{ + XWindowAttributes xgwa; + XGetWindowAttributes (st->dpy, st->window, &xgwa); + st->sizex = xgwa.width; + st->sizey = xgwa.height; + if (st->img_loader) abort(); + + st->img_loader = load_image_async_simple (0, xgwa.screen, st->window, + st->window, 0, 0); +} + static void * decayscreen_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues gcv; - XWindowAttributes xgwa; long gcflags; unsigned long bg; char *s; st->dpy = dpy; st->window = window; + st->random_p = 0; s = get_string_resource(st->dpy, "mode", "Mode"); if (s && !strcmp(s, "shuffle")) st->mode = SHUFFLE; @@ -100,33 +119,30 @@ decayscreen_init (Display *dpy, Window window) else { if (s && *s && !!strcmp(s, "random")) fprintf(stderr, "%s: unknown mode %s\n", progname, s); + st->random_p = 1; st->mode = random() % (FUZZ+1); } st->delay = get_integer_resource (st->dpy, "delay", "Integer"); - if (st->delay < 0) st->delay = 0; - XGetWindowAttributes (st->dpy, st->window, &xgwa); + st->duration = get_integer_resource (st->dpy, "duration", "Seconds"); + if (st->duration < 1) st->duration = 1; + + XGetWindowAttributes (st->dpy, st->window, &st->xgwa); gcv.function = GXcopy; gcv.subwindow_mode = IncludeInferiors; - bg = get_pixel_resource (st->dpy, xgwa.colormap, "background", "Background"); + bg = get_pixel_resource (st->dpy, st->xgwa.colormap, "background", "Background"); gcv.foreground = bg; gcflags = GCForeground | GCFunction; - if (use_subwindow_mode_p(xgwa.screen, st->window)) /* see grabscreen.c */ + if (use_subwindow_mode_p(st->xgwa.screen, st->window)) /* see grabscreen.c */ gcflags |= GCSubwindowMode; st->gc = XCreateGC (st->dpy, st->window, gcflags, &gcv); - st->sizex = xgwa.width; - st->sizey = xgwa.height; - - if (st->mode == MELT || st->mode == STRETCH) - st->iterations = 1; /* slow down for smoother melting */ - - st->img_loader = load_image_async_simple (0, xgwa.screen, st->window, - st->window, 0, 0); + st->start_time = time ((time_t *) 0); + decayscreen_load_image (st); return st; } @@ -156,18 +172,41 @@ decayscreen_draw (Display *dpy, Window window, void *closure) static const int upright_bias[] = { L,L,L,R, R,R,R,R, U,U,U,U, U,D,D,D }; static const int downright_bias[] = { L,L,L,R, R,R,R,R, U,U,U,D, D,D,D,D }; + int off = 1; + if (st->sizex > 2560) off *= 2; /* Retina displays */ + if (st->img_loader) /* still loading */ { st->img_loader = load_image_async_simple (st->img_loader, 0, 0, 0, 0, 0); if (! st->img_loader) { /* just finished */ + + st->start_time = time ((time_t *) 0); + if (st->random_p) + st->mode = random() % (FUZZ+1); + if (st->mode == MELT || st->mode == STRETCH) /* make sure screen eventually turns background color */ XDrawLine (st->dpy, st->window, st->gc, 0, 0, st->sizex, 0); + + if (!st->saved) { + st->saved = XCreatePixmap (st->dpy, st->window, + st->sizex, st->sizey, + st->xgwa.depth); + st->saved_w = st->sizex; + st->saved_h = st->sizey; + } + XCopyArea (st->dpy, st->window, st->saved, st->gc, 0, 0, + st->sizex, st->sizey, 0, 0); } return st->delay; } + if (!st->img_loader && + st->start_time + st->duration < time ((time_t *) 0)) { + decayscreen_load_image (st); + } + switch (st->mode) { case SHUFFLE: st->current_bias = no_bias; break; case UP: st->current_bias = up_bias; break; @@ -186,7 +225,7 @@ decayscreen_draw (Display *dpy, Window window, void *closure) default: abort(); } -#define nrnd(x) (random() % (x)) +#define nrnd(x) ((x) ? random() % (x) : x) if (st->mode == MELT || st->mode == STRETCH) { left = nrnd(st->sizex/2); @@ -194,7 +233,7 @@ decayscreen_draw (Display *dpy, Window window, void *closure) width = nrnd( st->sizex/2 ) + st->sizex/2 - left; height = nrnd(st->sizey - top); toleft = left; - totop = top+1; + totop = top+off; } else if (st->mode == FUZZ) { /* By Vince Levey ; inspired by the "melt" mode of the @@ -206,7 +245,7 @@ decayscreen_draw (Display *dpy, Window window, void *closure) if (st->fuzz_toggle) { totop = top; - height = 1; + height = off; toleft = nrnd(st->sizex - 1); if (toleft > left) { @@ -224,7 +263,7 @@ decayscreen_draw (Display *dpy, Window window, void *closure) else { toleft = left; - width = 1; + width = off; totop = nrnd(st->sizey - 1); if (totop > top) { @@ -268,19 +307,21 @@ decayscreen_draw (Display *dpy, Window window, void *closure) } switch (st->current_bias[random() % (sizeof(no_bias)/sizeof(*no_bias))]) { - case L: toleft = left-1; break; - case R: toleft = left+1; break; - case U: totop = top-1; break; - case D: totop = top+1; break; + case L: toleft = left-off; break; + case R: toleft = left+off; break; + case U: totop = top-off; break; + case D: totop = top+off; break; default: abort(); break; } } if (st->mode == STRETCH) { - XCopyArea (st->dpy, st->window, st->window, st->gc, 0, st->sizey-top-2, st->sizex, top+1, - 0, st->sizey-top-1); + XCopyArea (st->dpy, st->window, st->window, st->gc, + 0, st->sizey-top-off*2, st->sizex, top+off, + 0, st->sizey-top-off); } else { - XCopyArea (st->dpy, st->window, st->window, st->gc, left, top, width, height, + XCopyArea (st->dpy, st->window, st->window, st->gc, + left, top, width, height, toleft, totop); } @@ -294,6 +335,12 @@ decayscreen_reshape (Display *dpy, Window window, void *closure, unsigned int w, unsigned int h) { struct state *st = (struct state *) closure; + if (! st->saved) return; /* Image might not be loaded yet */ + XClearWindow (st->dpy, st->window); + XCopyArea (st->dpy, st->saved, st->window, st->gc, + 0, 0, st->saved_w, st->saved_h, + ((int)w - st->saved_w) / 2, + ((int)h - st->saved_h) / 2); st->sizex = w; st->sizey = h; } @@ -301,6 +348,12 @@ decayscreen_reshape (Display *dpy, Window window, void *closure, static Bool decayscreen_event (Display *dpy, Window window, void *closure, XEvent *event) { + struct state *st = (struct state *) closure; + if (screenhack_event_helper (dpy, window, event)) + { + st->start_time = 0; + return True; + } return False; } @@ -317,6 +370,7 @@ static const char *decayscreen_defaults [] = { ".background: Black", ".foreground: Yellow", "*dontClearRoot: True", + "*fpsSolid: True", #ifdef __sgi /* really, HAVE_READ_DISPLAY_EXTENSION */ "*visualID: Best", @@ -324,12 +378,18 @@ static const char *decayscreen_defaults [] = { "*delay: 10000", "*mode: random", + "*duration: 120", +#ifdef HAVE_MOBILE + "*ignoreRotation: True", + "*rotateImages: True", +#endif 0 }; static XrmOptionDescRec decayscreen_options [] = { { "-delay", ".delay", XrmoptionSepArg, 0 }, { "-mode", ".mode", XrmoptionSepArg, 0 }, + { "-duration", ".duration", XrmoptionSepArg, 0 }, { 0, 0, 0, 0 } };