1 /* xscreensaver, Copyright (c) 1992, 1993, 1994, 1996, 1997
2 * Jamie Zawinski <jwz@netscape.com>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
15 * Based on slidescreen program from the xscreensaver application and the
16 * decay program for Sun framebuffers. This is the comment from the decay.c
20 * find the screen bitmap for the console and make it "decay" by
21 * randomly shifting random rectangles by one pixelwidth at a time.
24 * rewritten by Natuerlich!
25 * based on a similar "utility" on the Apollo ring at Yale.
29 * Vivek Khera <khera@cs.duke.edu>
33 #include "screenhack.h"
35 static int sizex, sizey;
40 init_decay (Display *dpy, Window window)
43 XWindowAttributes xgwa;
45 delay = get_integer_resource ("delay", "Integer");
47 if (delay < 0) delay = 0;
49 gcv.function = GXcopy;
50 gcv.subwindow_mode = IncludeInferiors;
51 gc = XCreateGC (dpy, window, GCForeground |GCFunction | GCSubwindowMode,
54 XGetWindowAttributes (dpy, window, &xgwa);
58 grab_screen_image (xgwa.screen, window);
63 * perform one iteration of decay
66 decay1 (Display *dpy, Window window)
68 int left, top, width, height;
70 #define nrnd(x) (random() % (x))
72 switch (random() % 8) {
73 case 0: /* move a block left */
75 left = nrnd(sizex - 1) + 1;
77 width = nrnd(sizex - left);
78 height = nrnd(sizey - top);
79 XCopyArea (dpy, window, window, gc, left, top, width, height,
82 case 2: /* move a block right */
84 left = nrnd(sizex - 1);
86 width = nrnd(sizex - 1 - left);
87 height = nrnd(sizey - top);
88 XCopyArea (dpy, window, window, gc, left, top, width, height,
91 case 4: /* move a block up */
93 top = nrnd(sizey - 1) + 1;
94 width = nrnd(sizex - left);
95 height = nrnd(sizey - top);
96 XCopyArea (dpy, window, window, gc, left, top, width, height,
99 default: /* move block down (biased to this) */
101 top = nrnd(sizey - 1);
102 width = nrnd(sizex - left);
103 height = nrnd(sizey - 1 - top);
104 XCopyArea (dpy, window, window, gc, left, top, width, height,
113 char *progclass = "DecayScreen";
115 char *defaults [] = {
116 "*dontClearRoot: True",
118 #ifdef __sgi /* really, HAVE_READ_DISPLAY_EXTENSION */
126 XrmOptionDescRec options [] = {
127 { "-delay", ".delay", XrmoptionSepArg, 0 },
132 screenhack (Display *dpy, Window window)
134 init_decay (dpy, window);
136 decay1 (dpy, window);
137 if (delay) usleep (delay);