1 /* xscreensaver, Copyright (c) 1997, 1998 Jamie Zawinski <jwz@jwz.org>
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
11 * Concept snarfed from Michael D. Bayne in
12 * http://www.go2net.com/internet/deep/1997/04/16/body.html
15 #include "screenhack.h"
18 static XColor colors[255];
19 static int ncolors = 0;
20 static int max_depth = 0;
21 static int min_height = 0;
22 static int min_width = 0;
29 int x, int y, int w, int h, int depth)
31 if (((random() % max_depth) < depth) || (w < min_width) || (h < min_height))
35 static int current_color = 0;
36 if (++current_color >= ncolors)
38 XSetForeground(dpy, bgc, colors[current_color].pixel);
40 XFillRectangle (dpy, window, bgc, x, y, w, h);
41 XDrawRectangle (dpy, window, fgc, x, y, w, h);
47 deco (dpy, window, cmap, fgc, bgc, x, y, w/2, h, depth+1);
48 deco (dpy, window, cmap, fgc, bgc, x+w/2, y, w/2, h, depth+1);
52 deco (dpy, window, cmap, fgc, bgc, x, y, w, h/2, depth+1);
53 deco (dpy, window, cmap, fgc, bgc, x, y+h/2, w, h/2, depth+1);
59 char *progclass = "Deco";
69 "*cycleDelay: 1000000",
74 XrmOptionDescRec options [] = {
75 { "-max-depth", ".maxDepth", XrmoptionSepArg, 0 },
76 { "-min-width", ".minWidth", XrmoptionSepArg, 0 },
77 { "-min-height", ".minHeight", XrmoptionSepArg, 0 },
78 { "-delay", ".delay", XrmoptionSepArg, 0 },
79 { "-ncolors", ".ncolors", XrmoptionSepArg, 0 },
80 { "-cycle", ".cycle", XrmoptionNoArg, "True" },
81 { "-no-cycle", ".cycle", XrmoptionNoArg, "False" },
82 { "-cycle-delay", ".cycleDelay", XrmoptionSepArg, 0 },
87 screenhack (Display *dpy, Window window)
91 XWindowAttributes xgwa;
92 int delay = get_integer_resource ("delay", "Integer");
93 int cycle_delay = get_integer_resource ("cycleDelay", "Integer");
94 Bool writable = get_boolean_resource ("cycle", "Boolean");
96 max_depth = get_integer_resource ("maxDepth", "Integer");
97 if (max_depth < 1) max_depth = 1;
98 else if (max_depth > 1000) max_depth = 1000;
100 min_width = get_integer_resource ("minWidth", "Integer");
101 if (min_width < 2) min_width = 2;
102 min_height = get_integer_resource ("minHeight", "Integer");
103 if (min_height < 2) min_height = 2;
105 XGetWindowAttributes (dpy, window, &xgwa);
107 gcv.foreground = get_pixel_resource("foreground", "Foreground",
109 fgc = XCreateGC (dpy, window, GCForeground, &gcv);
111 gcv.foreground = get_pixel_resource("background", "Background",
113 bgc = XCreateGC (dpy, window, GCForeground, &gcv);
115 ncolors = get_integer_resource ("ncolors", "Integer");
117 make_random_colormap (dpy, xgwa.visual, xgwa.colormap, colors, &ncolors,
118 False, True, &writable, True);
132 XGetWindowAttributes (dpy, window, &xgwa);
133 XFillRectangle(dpy, window, bgc, 0, 0, xgwa.width, xgwa.height);
134 deco (dpy, window, xgwa.colormap, fgc, bgc,
135 0, 0, xgwa.width, xgwa.height, 0);
137 screenhack_handle_events (dpy);
139 if (!delay) continue;
144 time_t start = time((time_t) 0);
145 while (start - delay < time((time_t) 0))
147 rotate_colors (dpy, xgwa.colormap, colors, ncolors, 1);
149 screenhack_handle_events (dpy);
151 usleep (cycle_delay);