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; distort_reset (st); st->black_pixel = BlackPixelOfScreen( st->xgwa.screen ); gcv.function = GXcopy; gcv.subwindow_mode = IncludeInferiors; gcflags = GCFunction; if (use_subwindow_mode_p(st->xgwa.screen, st->window)) /* see grabscreen.c */ 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->pm, 0, 0); st->start_time = time ((time_t *) 0); return st; }
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; s = get_string_resource(st->dpy, "mode", "Mode"); if (s && !strcmp(s, "shuffle")) st->mode = SHUFFLE; else if (s && !strcmp(s, "up")) st->mode = UP; else if (s && !strcmp(s, "left")) st->mode = LEFT; else if (s && !strcmp(s, "right")) st->mode = RIGHT; else if (s && !strcmp(s, "down")) st->mode = DOWN; else if (s && !strcmp(s, "upleft")) st->mode = UPLEFT; else if (s && !strcmp(s, "downleft")) st->mode = DOWNLEFT; else if (s && !strcmp(s, "upright")) st->mode = UPRIGHT; else if (s && !strcmp(s, "downright")) st->mode = DOWNRIGHT; else if (s && !strcmp(s, "in")) st->mode = IN; else if (s && !strcmp(s, "out")) st->mode = OUT; else if (s && !strcmp(s, "melt")) st->mode = MELT; else if (s && !strcmp(s, "stretch")) st->mode = STRETCH; else if (s && !strcmp(s, "fuzz")) st->mode = FUZZ; else { if (s && *s && !!strcmp(s, "random")) fprintf(stderr, "%s: unknown mode %s\n", progname, s); 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); gcv.function = GXcopy; gcv.subwindow_mode = IncludeInferiors; bg = get_pixel_resource (st->dpy, xgwa.colormap, "background", "Background"); gcv.foreground = bg; gcflags = GCForeground | GCFunction; if (use_subwindow_mode_p(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); return st; }
static void * zoom_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues gcv; XWindowAttributes xgwa; Colormap cmap; unsigned long bg; long gcflags; int nblocksx, nblocksy; st->dpy = dpy; st->window = window; XGetWindowAttributes(st->dpy, st->window, &xgwa); st->screen = xgwa.screen; st->sizex = xgwa.width; st->sizey = xgwa.height; cmap = xgwa.colormap; bg = get_pixel_resource(st->dpy, cmap, "background", "Background"); st->delay = get_integer_resource(st->dpy, "delay", "Integer"); if (st->delay < 1) st->delay = 1; st->duration = get_integer_resource (st->dpy, "duration", "Seconds"); if (st->duration < 1) st->duration = 1; st->pixwidth = get_integer_resource(st->dpy, "pixwidth", "Integer"); if (st->pixwidth < 1) st->pixwidth = 1; st->pixheight = get_integer_resource(st->dpy, "pixheight", "Integer"); if (st->pixheight < 1) st->pixheight = 1; st->pixspacex = get_integer_resource(st->dpy, "pixspacex", "Integer"); if (st->pixspacex < 0) st->pixspacex = 0; st->pixspacey = get_integer_resource(st->dpy, "pixspacey", "Integer"); if (st->pixspacey < 0) st->pixspacey = 0; st->lenses = get_boolean_resource(st->dpy, "lenses", "Boolean"); st->lensoffsetx = get_integer_resource(st->dpy, "lensoffsetx", "Integer"); st->lensoffsetx = MAX(0, MIN(st->pixwidth, st->lensoffsetx)); st->lensoffsety = get_integer_resource(st->dpy, "lensoffsety", "Integer"); st->lensoffsety = MAX(0, MIN(st->pixwidth, st->lensoffsety)); gcv.function = GXcopy; gcv.subwindow_mode = IncludeInferiors; gcflags = GCForeground|GCFunction; gcv.foreground = bg; if (!st->lenses && use_subwindow_mode_p(xgwa.screen, st->window)) /* see grabscreen.c */ gcflags |= GCSubwindowMode; st->window_gc = XCreateGC(st->dpy, st->window, gcflags, &gcv); st->orig_map = NULL; st->pm = XCreatePixmap(st->dpy, st->window, st->sizex, st->sizey, xgwa.depth); XFillRectangle(st->dpy, st->window, st->window_gc, 0, 0, st->sizex, st->sizey); XSetWindowBackground(st->dpy, st->window, bg); st->start_time = time ((time_t) 0); st->img_loader = load_image_async_simple (0, xgwa.screen, st->window, st->pm, 0, 0); /* We might have needed this to grab the image, but if we leave this set to GCSubwindowMode, then we'll *draw* right over subwindows too. */ XSetSubwindowMode (st->dpy, st->window_gc, ClipByChildren); nblocksx = (int)ceil((double)st->sizex / (double)(st->pixwidth + st->pixspacex)); nblocksy = (int)ceil((double)st->sizey / (double)(st->pixheight + st->pixspacey)); if (st->lenses) st->s = MAX((nblocksx - 1) * st->lensoffsetx + st->pixwidth, (nblocksy - 1) * st->lensoffsety + st->pixheight) * 2; else st->s = MAX(nblocksx, nblocksy) * 2; st->sinusoid_offset = random(); return st; }
static void * spotlight_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues gcv; XWindowAttributes xgwa; long gcflags; Colormap cmap; unsigned long fg, bg; GC clip_gc; Pixmap clip_pm; st->dpy = dpy; st->window = window; st->first_p = True; XGetWindowAttributes (st->dpy, st->window, &xgwa); st->sizex = xgwa.width; st->sizey = xgwa.height; cmap = xgwa.colormap; fg = get_pixel_resource (st->dpy, cmap, "foreground", "Foreground"); bg = get_pixel_resource (st->dpy, cmap, "background", "Background"); /* read parameters, keep em sane */ st->delay = get_integer_resource (st->dpy, "delay", "Integer"); if (st->delay < 1) st->delay = 1; st->radius = get_integer_resource (st->dpy, "radius", "Integer"); if (st->radius < 0) st->radius = 125; /* Don't let the spotlight be bigger than the window */ while (st->radius > xgwa.width * 0.45) st->radius /= 2; while (st->radius > xgwa.height * 0.45) st->radius /= 2; if (st->radius < 4) st->radius = 4; /* do the dance */ gcv.function = GXcopy; gcv.subwindow_mode = IncludeInferiors; gcflags = GCForeground | GCFunction; gcv.foreground = bg; #ifdef NOPE if (use_subwindow_mode_p(xgwa.screen, st->window)) /* see grabscreen.c */ gcflags |= GCSubwindowMode; #endif st->window_gc = XCreateGC(st->dpy, st->window, gcflags, &gcv); /* grab screen to pixmap */ st->pm = XCreatePixmap(st->dpy, st->window, st->sizex, st->sizey, xgwa.depth); XClearWindow(st->dpy, st->window); /* create buffer to reduce flicker */ #ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ st->buffer = 0; #else st->buffer = XCreatePixmap(st->dpy, st->window, st->sizex, st->sizey, xgwa.depth); #endif st->buffer_gc = XCreateGC(st->dpy, (st->buffer ? st->buffer : window), gcflags, &gcv); if (st->buffer) XFillRectangle(st->dpy, st->buffer, st->buffer_gc, 0, 0, st->sizex, st->sizey); /* blank out screen */ XFillRectangle(st->dpy, st->window, st->window_gc, 0, 0, st->sizex, st->sizey); XSetWindowBackground (st->dpy, st->window, bg); /* create clip mask (so it's a circle, not a square) */ clip_pm = XCreatePixmap(st->dpy, st->window, st->radius*4, st->radius*4, 1); st->img_loader = load_image_async_simple (0, xgwa.screen, st->window, st->pm, 0, 0); gcv.foreground = 0L; clip_gc = XCreateGC(st->dpy, clip_pm, gcflags, &gcv); XFillRectangle(st->dpy, clip_pm, clip_gc, 0, 0, st->radius*4, st->radius*4); XSetForeground(st->dpy, clip_gc, 1L); XFillArc(st->dpy, clip_pm, clip_gc, st->radius , st->radius, st->radius*2, st->radius*2, 0, 360*64); /* set buffer's clip mask to the one we just made */ XSetClipMask(st->dpy, st->buffer_gc, clip_pm); /* free everything */ XFreeGC(st->dpy, clip_gc); XFreePixmap(st->dpy, clip_pm); /* avoid remants */ st->max_x_speed = st->max_y_speed = st->radius; st->off = random(); #ifdef DEBUG /* create GC with white fg */ gcv.foreground = fg; st->white_gc = XCreateGC(st->dpy, st->window, gcflags, &gcv); #endif return st; }