1 /* xscreensaver, Copyright (c) 1992, 1993, 1994 Jamie Zawinski <jwz@mcom.com>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
14 * Based on slidescreen program from the xscreensaver application and the
15 * decay program for Sun framebuffers. This is the comment from the decay.c
19 * find the screen bitmap for the console and make it "decay" by
20 * randomly shifting random rectangles by one pixelwidth at a time.
23 * rewritten by Natuerlich!
24 * based on a similar "utility" on the Apollo ring at Yale.
28 * Vivek Khera <khera@cs.duke.edu>
32 #include "screenhack.h"
34 static int sizex, sizey;
39 init_decay (dpy, window)
44 XWindowAttributes xgwa;
48 delay = get_integer_resource ("delay", "Integer");
49 root_p = get_boolean_resource ("root", "Boolean");
51 if (delay < 0) delay = 0;
53 gcv.function = GXcopy;
54 gcv.subwindow_mode = IncludeInferiors;
55 gc = XCreateGC (dpy, window, GCForeground |GCFunction | GCSubwindowMode,
58 XGetWindowAttributes (dpy, window, &xgwa);
62 copy_default_colormap_contents (dpy, xgwa.colormap, xgwa.visual);
63 pixmap = grab_screen_image (dpy, window, root_p);
68 * perform one iteration of decay
75 int left, top, width, height;
77 #define nrnd(x) (random() % (x))
79 switch (random() % 8) {
80 case 0: /* move a block left */
82 left = nrnd(sizex - 1) + 1;
84 width = nrnd(sizex - left);
85 height = nrnd(sizey - top);
86 XCopyArea (dpy, window, window, gc, left, top, width, height,
89 case 2: /* move a block right */
91 left = nrnd(sizex - 1);
93 width = nrnd(sizex - 1 - left);
94 height = nrnd(sizey - top);
95 XCopyArea (dpy, window, window, gc, left, top, width, height,
98 case 4: /* move a block up */
100 top = nrnd(sizey - 1) + 1;
101 width = nrnd(sizex - left);
102 height = nrnd(sizey - top);
103 XCopyArea (dpy, window, window, gc, left, top, width, height,
106 default: /* move block down (biased to this) */
108 top = nrnd(sizey - 1);
109 width = nrnd(sizex - left);
110 height = nrnd(sizey - 1 - top);
111 XCopyArea (dpy, window, window, gc, left, top, width, height,
120 char *progclass = "DecayScreen";
122 char *defaults [] = {
123 "DecayScreen.mappedWhenManaged:false",
124 "DecayScreen.dontClearWindow: true",
129 XrmOptionDescRec options [] = {
130 { "-delay", ".delay", XrmoptionSepArg, 0 },
133 int options_size = (sizeof (options) / sizeof (options[0]));
136 screenhack (dpy, window)
140 init_decay (dpy, window);
142 decay1 (dpy, window);
143 if (delay) usleep (delay);