X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fdistort.c;h=d7faf900e4975110c560ef1f62b1d53d83be74cc;hb=d6b0217f2417bd19187f0ebc389d6c5c2233b11c;hp=6903c8c7472c9096fe4aa37555d2e4686656f9ae;hpb=dba664f31aa87285db4d76cf8c5e66335299703a;p=xscreensaver diff --git a/hacks/distort.c b/hacks/distort.c index 6903c8c7..d7faf900 100644 --- a/hacks/distort.c +++ b/hacks/distort.c @@ -35,6 +35,7 @@ */ #include +#include #include "screenhack.h" /*#include */ @@ -87,6 +88,7 @@ struct state { void (*draw_routine) (struct state *st, XImage *, XImage *, int, int, int *); async_load_state *img_loader; + Pixmap pm; }; @@ -105,17 +107,15 @@ static void generic_draw(struct state *st, XImage *, XImage *, int, int, int *); static void distort_finish_loading (struct state *); -static void * -distort_init (Display *dpy, Window window) +static void +distort_reset (struct state *st) { - struct state *st = (struct state *) calloc (1, sizeof(*st)); - XGCValues gcv; - long gcflags; - int i; char *s; + int i; - st->dpy = dpy; - st->window = window; + st->start_time = 0; + + XGetWindowAttributes (st->dpy, st->window, &st->xgwa); st->delay = get_integer_resource(st->dpy, "delay", "Integer"); st->duration = get_integer_resource (st->dpy, "duration", "Seconds"); @@ -123,19 +123,15 @@ distort_init (Display *dpy, Window window) st->speed = get_integer_resource(st->dpy, "speed", "Integer"); st->number = get_integer_resource(st->dpy, "number", "Integer"); - if (st->delay < 0) st->delay = 0; - if (st->duration < 1) st->duration = 1; - -#ifdef HAVE_XSHM_EXTENSION - st->use_shm = get_boolean_resource(st->dpy, "useSHM", "Boolean"); -#endif /* HAVE_XSHM_EXTENSION */ - st->blackhole = get_boolean_resource(st->dpy, "blackhole", "Boolean"); st->vortex = get_boolean_resource(st->dpy, "vortex", "Boolean"); st->magnify = get_boolean_resource(st->dpy, "magnify", "Boolean"); st->reflect = get_boolean_resource(st->dpy, "reflect", "Boolean"); st->slow = get_boolean_resource(st->dpy, "slow", "Boolean"); + if (st->delay < 0) st->delay = 0; + if (st->duration < 1) st->duration = 1; + st->effect = NULL; s = get_string_resource(st->dpy, "effect", "String"); if (s && !strcasecmp(s,"swamp")) @@ -147,8 +143,6 @@ distort_init (Display *dpy, Window window) else if (s && *s) fprintf(stderr,"%s: bogus effect: %s\n", progname, s); - XGetWindowAttributes (st->dpy, st->window, &st->xgwa); - if (st->effect == NULL && st->radius == 0 && st->speed == 0 && st->number == 0 && !st->blackhole && !st->vortex && !st->magnify && !st->reflect) { /* if no cmdline options are given, randomly choose one of: @@ -268,6 +262,23 @@ distort_init (Display *dpy, Window window) } if (st->draw == NULL) st->draw = &plain_draw; +} + +static void * +distort_init (Display *dpy, Window window) +{ + struct state *st = (struct state *) calloc (1, sizeof(*st)); + XGCValues gcv; + long gcflags; + + st->dpy = dpy; + st->window = window; + +#ifdef HAVE_XSHM_EXTENSION + st->use_shm = get_boolean_resource(st->dpy, "useSHM", "Boolean"); +#endif /* HAVE_XSHM_EXTENSION */ + + distort_reset (st); st->black_pixel = BlackPixelOfScreen( st->xgwa.screen ); @@ -278,9 +289,16 @@ distort_init (Display *dpy, Window window) gcflags |= GCSubwindowMode; st->gc = XCreateGC (st->dpy, st->window, gcflags, &gcv); + /* On MacOS X11, XGetImage on a Window often gets an inexplicable BadMatch, + possibly due to the window manager having occluded something? It seems + nondeterministic. Loading the image into a pixmap instead fixes it. */ + if (st->pm) XFreePixmap (st->dpy, st->pm); + st->pm = XCreatePixmap (st->dpy, st->window, + st->xgwa.width, st->xgwa.height, st->xgwa.depth); + st->img_loader = load_image_async_simple (0, st->xgwa.screen, st->window, - st->window, 0, 0); - st->start_time = time ((time_t) 0); + st->pm, 0, 0); + st->start_time = time ((time_t *) 0); return st; } @@ -289,11 +307,16 @@ distort_finish_loading (struct state *st) { int i; - st->start_time = time ((time_t) 0); + st->start_time = time ((time_t *) 0); st->buffer_map = 0; - st->orig_map = XGetImage(st->dpy, st->window, 0, 0, st->xgwa.width, st->xgwa.height, - ~0L, ZPixmap); + if (! st->pm) abort(); + XClearWindow (st->dpy, st->window); + XCopyArea (st->dpy, st->pm, st->window, st->gc, + 0, 0, st->xgwa.width, st->xgwa.height, 0, 0); + st->orig_map = XGetImage(st->dpy, st->pm, 0, 0, + st->xgwa.width, st->xgwa.height, + ~0L, ZPixmap); st->buffer_map_cache = malloc(sizeof(unsigned long)*(2*st->radius+st->speed+2)*(2*st->radius+st->speed+2)); if (st->buffer_map_cache == NULL) { @@ -762,9 +785,12 @@ distort_draw (Display *dpy, Window window, void *closure) } if (!st->img_loader && - st->start_time + st->duration < time ((time_t) 0)) { + st->start_time + st->duration < time ((time_t *) 0)) { + if (st->pm) XFreePixmap (st->dpy, st->pm); + st->pm = XCreatePixmap (st->dpy, st->window, + st->xgwa.width, st->xgwa.height, st->xgwa.depth); st->img_loader = load_image_async_simple (0, st->xgwa.screen, st->window, - st->window, 0, 0); + st->pm, 0, 0); return st->delay; } @@ -791,6 +817,12 @@ distort_reshape (Display *dpy, Window window, void *closure, static Bool distort_event (Display *dpy, Window window, void *closure, XEvent *event) { + struct state *st = (struct state *) closure; + if (screenhack_event_helper (dpy, window, event)) + { + distort_reset(st); + return True; + } return False; } @@ -799,6 +831,7 @@ distort_free (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; XFreeGC (st->dpy, st->gc); + if (st->pm) XFreePixmap (dpy, st->pm); if (st->orig_map) XDestroyImage (st->orig_map); if (st->buffer_map) XDestroyImage (st->buffer_map); if (st->from) free (st->from); @@ -832,8 +865,9 @@ static const char *distort_defaults [] = { #ifdef HAVE_XSHM_EXTENSION "*useSHM: False", /* xshm turns out not to help. */ #endif /* HAVE_XSHM_EXTENSION */ -#ifdef USE_IPHONE +#ifdef HAVE_MOBILE "*ignoreRotation: True", + "*rotateImages: True", #endif 0 };