1 /* xscreensaver, Copyright (c) 1992, 1995, 1996, 1997, 1998
2 * Jamie Zawinski <jwz@jwz.org>
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
13 #include "screenhack.h"
17 /* On some systems (notably MacOS X) these files are messed up.
18 * They're tiny, so we might as well just inline them here.
20 * # include <X11/bitmaps/stipple>
21 * # include <X11/bitmaps/cross_weave>
22 * # include <X11/bitmaps/dimple1>
23 * # include <X11/bitmaps/dimple3>
24 * # include <X11/bitmaps/flipped_gray>
25 * # include <X11/bitmaps/gray1>
26 * # include <X11/bitmaps/gray3>
27 * # include <X11/bitmaps/hlines2>
28 * # include <X11/bitmaps/light_gray>
29 * # include <X11/bitmaps/root_weave>
30 * # include <X11/bitmaps/vlines2>
31 * # include <X11/bitmaps/vlines3>
34 #define stipple_width 16
35 #define stipple_height 4
36 static char stipple_bits[] = { 0x55, 0x55, 0xee, 0xee, 0x55, 0x55, 0xba, 0xbb};
38 #define cross_weave_width 16
39 #define cross_weave_height 16
40 static char cross_weave_bits[] = {
41 0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22, 0x55, 0x55, 0x88, 0x88,
42 0x55, 0x55, 0x22, 0x22, 0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22,
43 0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22};
45 #define dimple1_width 16
46 #define dimple1_height 16
47 static char dimple1_bits[] = {
48 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00,
49 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00,
50 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00};
52 #define dimple3_width 16
53 #define dimple3_height 16
54 static char dimple3_bits[] = {
55 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00,
56 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
59 #define flipped_gray_width 4
60 #define flipped_gray_height 2
61 static char flipped_gray_bits[] = { 0x07, 0x0d};
63 #define gray1_height 2
64 static char gray1_bits[] = { 0x01, 0x02};
66 #define gray3_height 4
67 static char gray3_bits[] = { 0x01, 0x00, 0x04, 0x00};
68 #define hlines2_width 1
69 #define hlines2_height 2
70 static char hlines2_bits[] = { 0x01, 0x00};
71 #define light_gray_width 4
72 #define light_gray_height 2
73 static char light_gray_bits[] = { 0x08, 0x02};
74 #define root_weave_width 4
75 #define root_weave_height 4
76 static char root_weave_bits[] = { 0x07, 0x0d, 0x0b, 0x0e};
77 #define vlines2_width 2
78 #define vlines2_height 1
79 static char vlines2_bits[] = { 0x01};
80 #define vlines3_width 3
81 #define vlines3_height 1
82 static char vlines3_bits[] = { 0x02};
87 static Pixmap pixmaps [NBITS];
90 static unsigned long fg, bg, pixels [512];
94 init_greynetic (Display *dpy, Window window)
98 XWindowAttributes xgwa;
100 XGetWindowAttributes (dpy, window, &xgwa);
101 cmap = xgwa.colormap;
103 gcv.foreground= fg= get_pixel_resource("foreground","Foreground", dpy, cmap);
104 gcv.background= bg= get_pixel_resource("background","Background", dpy, cmap);
105 gcv.fill_style= FillOpaqueStippled;
106 gc = XCreateGC (dpy, window, GCForeground|GCBackground|GCFillStyle, &gcv);
108 delay = get_integer_resource ("delay", "Integer");
109 if (delay < 0) delay = 0;
112 #define BITS(n,w,h) \
113 pixmaps [i++] = XCreatePixmapFromBitmapData (dpy, window, n, w, h, 1, 0, 1)
115 BITS (stipple_bits, stipple_width, stipple_height);
116 BITS (cross_weave_bits, cross_weave_width, cross_weave_height);
117 BITS (dimple1_bits, dimple1_width, dimple1_height);
118 BITS (dimple3_bits, dimple3_width, dimple3_height);
119 BITS (flipped_gray_bits, flipped_gray_width, flipped_gray_height);
120 BITS (gray1_bits, gray1_width, gray1_height);
121 BITS (gray3_bits, gray3_width, gray3_height);
122 BITS (hlines2_bits, hlines2_width, hlines2_height);
123 BITS (light_gray_bits, light_gray_width, light_gray_height);
124 BITS (root_weave_bits, root_weave_width, root_weave_height);
125 BITS (vlines2_bits, vlines2_width, vlines2_height);
126 BITS (vlines3_bits, vlines3_width, vlines3_height);
130 greynetic (Display *dpy, Window window)
132 static int tick = 500, xlim, ylim;
133 static Colormap cmap;
134 int x, y, w=0, h=0, i;
138 XWindowAttributes xgwa;
139 XGetWindowAttributes (dpy, window, &xgwa);
143 cmap = xgwa.colormap;
145 for (i = 0; i < 10; i++) /* minimize area, but don't try too hard */
147 w = 50 + random () % (xlim - 50);
148 h = 50 + random () % (ylim - 50);
149 if (w + h < xlim && w + h < ylim)
152 x = random () % (xlim - w);
153 y = random () % (ylim - h);
154 gcv.stipple = pixmaps [random () % NBITS];
159 gcv.foreground = fg, gcv.background = bg;
161 gcv.foreground = bg, gcv.background = fg;
166 if (npixels == sizeof (pixels) / sizeof (unsigned long))
168 fgc.flags = bgc.flags = DoRed|DoGreen|DoBlue;
170 fgc.green = random ();
171 fgc.blue = random ();
173 bgc.green = random ();
174 bgc.blue = random ();
175 if (! XAllocColor (dpy, cmap, &fgc))
177 pixels [npixels++] = fgc.pixel;
178 gcv.foreground = fgc.pixel;
179 if (! XAllocColor (dpy, cmap, &bgc))
181 pixels [npixels++] = bgc.pixel;
182 gcv.background = bgc.pixel;
190 gcv.foreground = pixels [random () % npixels];
191 gcv.background = pixels [random () % npixels];
195 XChangeGC (dpy, gc, GCStipple|GCForeground|GCBackground, &gcv);
196 XFillRectangle (dpy, window, gc, x, y, w, h);
201 char *progclass = "Greynetic";
203 char *defaults [] = {
204 ".background: black",
205 ".foreground: white",
210 XrmOptionDescRec options [] = {
211 { "-delay", ".delay", XrmoptionSepArg, 0 },
216 screenhack (Display *dpy, Window window)
218 init_greynetic (dpy, window);
221 greynetic (dpy, window);
222 screenhack_handle_events (dpy);
223 if (delay) usleep (delay);