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
20 extern void screenhack_usleep ();
21 #define usleep screenhack_usleep
23 #define MAX_COLORS 4096
24 static XColor orig_colors [MAX_COLORS];
25 static XColor current_colors [MAX_COLORS];
29 copy_colormap (dpy, cmap, into_cmap)
31 Colormap cmap, into_cmap;
34 ncolors = CellsOfScreen (DefaultScreenOfDisplay (dpy));
35 if (ncolors <= 2 || ncolors > MAX_COLORS)
38 into_cmap = XCreateColormap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
39 DefaultVisual (dpy, DefaultScreen (dpy)),
42 cmap = DefaultColormap (dpy, DefaultScreen (dpy));
43 for (i = 0; i < ncolors; i++)
44 orig_colors [i].pixel = i;
45 XQueryColors (dpy, cmap, orig_colors, ncolors);
46 XStoreColors (dpy, into_cmap, orig_colors, ncolors);
51 blacken_colormap (dpy, cmap)
56 for (i = 0; i < ncolors; i++)
58 current_colors [i].pixel = i;
59 current_colors [i].red = current_colors [i].green =
60 current_colors [i].blue = 0;
62 XStoreColors (dpy, cmap, current_colors, ncolors);
67 fade_colormap (dpy, cmap, cmap2, seconds, ticks, out_p)
74 int steps = seconds * ticks;
80 for (i = 0; i < ncolors; i++)
81 orig_colors [i].pixel = i;
82 XQueryColors (dpy, cmap, orig_colors, ncolors);
83 memcpy (current_colors, orig_colors, ncolors * sizeof (XColor));
85 for (i = (out_p ? steps : 0);
86 (out_p ? i > 0 : i < steps);
90 for (j = 0; j < ncolors; j++)
92 current_colors[j].red = orig_colors[j].red * i / steps;
93 current_colors[j].green = orig_colors[j].green * i / steps;
94 current_colors[j].blue = orig_colors[j].blue * i / steps;
96 XStoreColors (dpy, cmap2, current_colors, ncolors);
99 /* If there is user activity, bug out.
100 We put the event back so that the calling code can notice it too.
101 It would be better to not remove it at all, but that's harder
102 because Xlib has such a non-design for this kind of crap, and
103 in this application it doesn't matter if the events end up out
104 of order, so in the grand unix tradition we say "fuck it" and
105 do something that mostly works for the time being.
107 if (XCheckMaskEvent (dpy, (KeyPressMask | KeyReleaseMask |
108 ButtonPressMask | ButtonReleaseMask |
112 XPutBackEvent (dpy, &dummy_event);
116 usleep (1000000 / (ticks * 2)); /* the 2 is a hack... */
123 char *progclass = "foo";
125 char *defaults [] = {
129 XrmOptionDescRec options [] = {0};
130 int options_size = 0;
137 Colormap cmap = DefaultColormap (dpy, DefaultScreen (dpy));
138 Colormap cmap2 = copy_colormap (dpy, cmap, 0);
141 int ticks = 30 * seconds;
148 XInstallColormap (dpy, cmap2);
149 fade_colormap (dpy, cmap, cmap2, seconds, ticks, True);
150 if (delay) sleep (delay);
151 fade_colormap (dpy, cmap, cmap2, seconds, ticks, False);
152 XInstallColormap (dpy, cmap);
155 if (delay) sleep (delay);