1 /* xscreensaver, Copyright (c) 1992 Jamie Zawinski <jwz@lucid.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
21 # define bcopy(from,to,size) memcpy((to),(from),(size))
22 # define bzero(addr,size) memset((addr),0,(size))
23 extern void screenhack_usleep (unsigned long);
25 extern void screenhack_usleep ();
28 #define usleep screenhack_usleep
30 #define MAX_COLORS 4096
31 static XColor orig_colors [MAX_COLORS];
32 static XColor current_colors [MAX_COLORS];
36 copy_colormap (dpy, cmap, into_cmap)
38 Colormap cmap, into_cmap;
41 ncolors = CellsOfScreen (DefaultScreenOfDisplay (dpy));
42 if (ncolors <= 2 || ncolors > MAX_COLORS)
45 into_cmap = XCreateColormap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
46 DefaultVisual (dpy, DefaultScreen (dpy)),
49 cmap = DefaultColormap (dpy, DefaultScreen (dpy));
50 for (i = 0; i < ncolors; i++)
51 orig_colors [i].pixel = i;
52 XQueryColors (dpy, cmap, orig_colors, ncolors);
53 XStoreColors (dpy, into_cmap, orig_colors, ncolors);
58 blacken_colormap (dpy, cmap)
63 for (i = 0; i < ncolors; i++)
65 current_colors [i].pixel = i;
66 current_colors [i].red = current_colors [i].green =
67 current_colors [i].blue = 0;
69 XStoreColors (dpy, cmap, current_colors, ncolors);
74 fade_colormap (dpy, cmap, cmap2, seconds, ticks, out_p)
81 int steps = seconds * ticks;
87 for (i = 0; i < ncolors; i++)
88 orig_colors [i].pixel = i;
89 XQueryColors (dpy, cmap, orig_colors, ncolors);
90 bcopy (orig_colors, current_colors, ncolors * sizeof (XColor));
92 for (i = (out_p ? steps : 0);
93 (out_p ? i > 0 : i < steps);
97 for (j = 0; j < ncolors; j++)
99 current_colors[j].red = (int)orig_colors[j].red * i / steps;
100 current_colors[j].green = (int)orig_colors[j].green * i / steps;
101 current_colors[j].blue = (int)orig_colors[j].blue * i / steps;
103 XStoreColors (dpy, cmap2, current_colors, ncolors);
106 /* If there is user activity, bug out.
107 We put the event back so that the calling code can notice it too.
108 It would be better to not remove it at all, but that's harder
109 because Xlib has such a non-design for this kind of crap, and
110 in this application it doesn't matter if the events end up out
111 of order, so in the grand unix tradition we say "fuck it" and
112 do something that mostly works for the time being.
114 if (XCheckMaskEvent (dpy, (KeyPressMask | KeyReleaseMask |
115 ButtonPressMask | ButtonReleaseMask |
119 XPutBackEvent (dpy, &dummy_event);
123 usleep (1000000 / (ticks * 2)); /* the 2 is a hack... */
130 char *progclass = "foo";
132 char *defaults [] = {
136 XrmOptionDescRec options [] = {0};
137 int options_size = 0;
144 Colormap cmap = DefaultColormap (dpy, DefaultScreen (dpy));
145 Colormap cmap2 = copy_colormap (dpy, cmap, 0);
148 int ticks = 30 * seconds;
155 XInstallColormap (dpy, cmap2);
156 fade_colormap (dpy, cmap, cmap2, seconds, ticks, True);
157 if (delay) sleep (delay);
158 fade_colormap (dpy, cmap, cmap2, seconds, ticks, False);
159 XInstallColormap (dpy, cmap);
162 if (delay) sleep (delay);