1 /* xscreensaver, Copyright (c) 1992, 1993, 1994
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 (dpy, window)
45 XWindowAttributes xgwa;
49 delay = get_integer_resource ("delay", "Integer");
50 root_p = get_boolean_resource ("root", "Boolean");
52 if (delay < 0) delay = 0;
54 gcv.function = GXcopy;
55 gcv.subwindow_mode = IncludeInferiors;
56 gc = XCreateGC (dpy, window, GCForeground |GCFunction | GCSubwindowMode,
59 XGetWindowAttributes (dpy, window, &xgwa);
63 copy_default_colormap_contents (dpy, xgwa.colormap, xgwa.visual);
64 pixmap = grab_screen_image (dpy, window, root_p);
69 * perform one iteration of decay
76 int left, top, width, height;
78 #define nrnd(x) (random() % (x))
80 switch (random() % 8) {
81 case 0: /* move a block left */
83 left = nrnd(sizex - 1) + 1;
85 width = nrnd(sizex - left);
86 height = nrnd(sizey - top);
87 XCopyArea (dpy, window, window, gc, left, top, width, height,
90 case 2: /* move a block right */
92 left = nrnd(sizex - 1);
94 width = nrnd(sizex - 1 - left);
95 height = nrnd(sizey - top);
96 XCopyArea (dpy, window, window, gc, left, top, width, height,
99 case 4: /* move a block up */
101 top = nrnd(sizey - 1) + 1;
102 width = nrnd(sizex - left);
103 height = nrnd(sizey - top);
104 XCopyArea (dpy, window, window, gc, left, top, width, height,
107 default: /* move block down (biased to this) */
109 top = nrnd(sizey - 1);
110 width = nrnd(sizex - left);
111 height = nrnd(sizey - 1 - top);
112 XCopyArea (dpy, window, window, gc, left, top, width, height,
121 char *progclass = "DecayScreen";
123 char *defaults [] = {
124 "DecayScreen.mappedWhenManaged:false",
125 "DecayScreen.dontClearWindow: true",
130 XrmOptionDescRec options [] = {
131 { "-delay", ".delay", XrmoptionSepArg, 0 },
134 int options_size = (sizeof (options) / sizeof (options[0]));
137 screenhack (dpy, window)
141 init_decay (dpy, window);
143 decay1 (dpy, window);
144 if (delay) usleep (delay);