1 /* xscreensaver, Copyright (c) 1992, 1995, 1996, 1997, 1998, 2003
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 unsigned char stipple_bits[] = {
37 0x55, 0x55, 0xee, 0xee, 0x55, 0x55, 0xba, 0xbb};
39 #define cross_weave_width 16
40 #define cross_weave_height 16
41 static unsigned char cross_weave_bits[] = {
42 0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22, 0x55, 0x55, 0x88, 0x88,
43 0x55, 0x55, 0x22, 0x22, 0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22,
44 0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22};
46 #define dimple1_width 16
47 #define dimple1_height 16
48 static unsigned char dimple1_bits[] = {
49 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00,
50 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00,
51 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00};
53 #define dimple3_width 16
54 #define dimple3_height 16
55 static unsigned char dimple3_bits[] = {
56 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00,
57 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
60 #define flipped_gray_width 4
61 #define flipped_gray_height 2
62 static char flipped_gray_bits[] = { 0x07, 0x0d};
64 #define gray1_height 2
65 static char gray1_bits[] = { 0x01, 0x02};
67 #define gray3_height 4
68 static char gray3_bits[] = { 0x01, 0x00, 0x04, 0x00};
69 #define hlines2_width 1
70 #define hlines2_height 2
71 static char hlines2_bits[] = { 0x01, 0x00};
72 #define light_gray_width 4
73 #define light_gray_height 2
74 static char light_gray_bits[] = { 0x08, 0x02};
75 #define root_weave_width 4
76 #define root_weave_height 4
77 static char root_weave_bits[] = { 0x07, 0x0d, 0x0b, 0x0e};
78 #define vlines2_width 2
79 #define vlines2_height 1
80 static char vlines2_bits[] = { 0x01};
81 #define vlines3_width 3
82 #define vlines3_height 1
83 static char vlines3_bits[] = { 0x02};
88 static Pixmap pixmaps [NBITS];
91 static unsigned long fg, bg, pixels [512];
95 init_greynetic (Display *dpy, Window window)
99 XWindowAttributes xgwa;
101 XGetWindowAttributes (dpy, window, &xgwa);
102 cmap = xgwa.colormap;
104 gcv.foreground= fg= get_pixel_resource("foreground","Foreground", dpy, cmap);
105 gcv.background= bg= get_pixel_resource("background","Background", dpy, cmap);
106 gcv.fill_style= FillOpaqueStippled;
107 gc = XCreateGC (dpy, window, GCForeground|GCBackground|GCFillStyle, &gcv);
109 delay = get_integer_resource ("delay", "Integer");
110 if (delay < 0) delay = 0;
113 #define BITS(n,w,h) \
115 XCreatePixmapFromBitmapData (dpy, window, (char *) n, w, h, 1, 0, 1)
117 BITS (stipple_bits, stipple_width, stipple_height);
118 BITS (cross_weave_bits, cross_weave_width, cross_weave_height);
119 BITS (dimple1_bits, dimple1_width, dimple1_height);
120 BITS (dimple3_bits, dimple3_width, dimple3_height);
121 BITS (flipped_gray_bits, flipped_gray_width, flipped_gray_height);
122 BITS (gray1_bits, gray1_width, gray1_height);
123 BITS (gray3_bits, gray3_width, gray3_height);
124 BITS (hlines2_bits, hlines2_width, hlines2_height);
125 BITS (light_gray_bits, light_gray_width, light_gray_height);
126 BITS (root_weave_bits, root_weave_width, root_weave_height);
127 BITS (vlines2_bits, vlines2_width, vlines2_height);
128 BITS (vlines3_bits, vlines3_width, vlines3_height);
132 greynetic (Display *dpy, Window window)
134 static int tick = 500, xlim, ylim;
135 static Colormap cmap;
136 int x, y, w=0, h=0, i;
140 XWindowAttributes xgwa;
141 XGetWindowAttributes (dpy, window, &xgwa);
145 cmap = xgwa.colormap;
147 for (i = 0; i < 10; i++) /* minimize area, but don't try too hard */
149 w = 50 + random () % (xlim - 50);
150 h = 50 + random () % (ylim - 50);
151 if (w + h < xlim && w + h < ylim)
154 x = random () % (xlim - w);
155 y = random () % (ylim - h);
156 gcv.stipple = pixmaps [random () % NBITS];
161 gcv.foreground = fg, gcv.background = bg;
163 gcv.foreground = bg, gcv.background = fg;
168 if (npixels == sizeof (pixels) / sizeof (unsigned long))
170 fgc.flags = bgc.flags = DoRed|DoGreen|DoBlue;
172 fgc.green = random ();
173 fgc.blue = random ();
175 bgc.green = random ();
176 bgc.blue = random ();
177 if (! XAllocColor (dpy, cmap, &fgc))
179 pixels [npixels++] = fgc.pixel;
180 gcv.foreground = fgc.pixel;
181 if (! XAllocColor (dpy, cmap, &bgc))
183 pixels [npixels++] = bgc.pixel;
184 gcv.background = bgc.pixel;
192 gcv.foreground = pixels [random () % npixels];
193 gcv.background = pixels [random () % npixels];
197 XChangeGC (dpy, gc, GCStipple|GCForeground|GCBackground, &gcv);
198 XFillRectangle (dpy, window, gc, x, y, w, h);
203 char *progclass = "Greynetic";
205 char *defaults [] = {
206 ".background: black",
207 ".foreground: white",
212 XrmOptionDescRec options [] = {
213 { "-delay", ".delay", XrmoptionSepArg, 0 },
218 screenhack (Display *dpy, Window window)
220 init_greynetic (dpy, window);
223 greynetic (dpy, window);
224 screenhack_handle_events (dpy);
225 if (delay) usleep (delay);