1 /* xscreensaver, Copyright (c) 1992-1996 Jamie Zawinski <jwz@netscape.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
26 extern int get_visual_class P((Display *, Visual *));
27 extern void screenhack_usleep P((unsigned long));
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 Screen *screen = DefaultScreenOfDisplay (dpy);
42 Visual *visual = DefaultVisualOfScreen (screen);
43 Window window = RootWindowOfScreen (screen);
44 int vclass = get_visual_class (dpy, visual);
46 ncolors = CellsOfScreen (screen);
48 /* If this is a colormap on a mono visual, or one with insanely many
49 color cells, bug out. */
50 if (ncolors <= 2 || ncolors > MAX_COLORS)
52 /* If this is a non-writable visual, bug out. */
53 if (vclass == StaticGray || vclass == StaticColor || vclass == TrueColor)
57 into_cmap = XCreateColormap (dpy, window, visual, AllocAll);
59 cmap = DefaultColormap (dpy, DefaultScreen (dpy));
60 for (i = 0; i < ncolors; i++)
61 orig_colors [i].pixel = i;
62 XQueryColors (dpy, cmap, orig_colors, ncolors);
63 XStoreColors (dpy, into_cmap, orig_colors, ncolors);
68 blacken_colormap (dpy, cmap)
73 for (i = 0; i < ncolors; i++)
75 current_colors [i].pixel = i;
76 current_colors [i].red = current_colors [i].green =
77 current_colors [i].blue = 0;
79 XStoreColors (dpy, cmap, current_colors, ncolors);
83 /* The business with `install_p' and `extra_cmaps' is to fake out the SGI
84 8-bit video hardware, which is capable of installing multiple (4) colormaps
85 simultaniously. We have to install multiple copies of the same set of
86 colors in order to fill up all the available slots in the hardware color
91 fade_colormap (dpy, cmap, cmap2, seconds, ticks, out_p, install_p)
99 int steps = seconds * ticks;
102 Screen *screen = DefaultScreenOfDisplay (dpy);
103 Visual *visual = DefaultVisualOfScreen (screen);
104 Window window = RootWindowOfScreen (screen);
105 static Colormap extra_cmaps[4] = { 0, };
106 int n_extra_cmaps = sizeof(extra_cmaps)/sizeof(*extra_cmaps);
111 for (i = 0; i < ncolors; i++)
112 orig_colors [i].pixel = i;
113 XQueryColors (dpy, cmap, orig_colors, ncolors);
114 memcpy (current_colors, orig_colors, ncolors * sizeof (XColor));
117 for (i=0; i < n_extra_cmaps; i++)
119 extra_cmaps[i] = XCreateColormap (dpy, window, visual, AllocAll);
121 for (i = (out_p ? steps : 0);
122 (out_p ? i > 0 : i < steps);
126 for (j = 0; j < ncolors; j++)
128 current_colors[j].red = orig_colors[j].red * i / steps;
129 current_colors[j].green = orig_colors[j].green * i / steps;
130 current_colors[j].blue = orig_colors[j].blue * i / steps;
132 XStoreColors (dpy, cmap2, current_colors, ncolors);
136 for (j=0; j < n_extra_cmaps; j++)
138 XStoreColors (dpy, extra_cmaps[j], current_colors, ncolors);
140 for (j=0; j < n_extra_cmaps; j++)
142 XInstallColormap (dpy, extra_cmaps[j]);
143 XInstallColormap (dpy, cmap2);
148 /* If there is user activity, bug out.
149 We put the event back so that the calling code can notice it too.
150 It would be better to not remove it at all, but that's harder
151 because Xlib has such a non-design for this kind of crap, and
152 in this application it doesn't matter if the events end up out
153 of order, so in the grand unix tradition we say "fuck it" and
154 do something that mostly works for the time being.
156 if (XCheckMaskEvent (dpy, (KeyPressMask | KeyReleaseMask |
157 ButtonPressMask | ButtonReleaseMask |
161 XPutBackEvent (dpy, &dummy_event);
165 usleep (1000000 / (ticks * 2)); /* the 2 is a hack... */
172 XInstallColormap (dpy, cmap2);
173 /* for (i=0; i < n_extra_cmaps; i++)
175 XFreeColormap (dpy, extra_cmaps[i]);
182 #include "../hacks/screenhack.h"
183 char *progclass = "foo";
184 char *defaults [] = {
188 XrmOptionDescRec options [] = {0};
189 int options_size = 0;
196 Colormap cmap = DefaultColormap (dpy, DefaultScreen (dpy));
197 Colormap cmap2 = copy_colormap (dpy, cmap, 0);
200 int ticks = 30 * seconds;
203 XSynchronize (dpy, True);
208 /* XGrabServer (dpy); */
209 fprintf(stderr,"out..."); fflush(stderr);
210 XInstallColormap (dpy, cmap2);
211 fade_colormap (dpy, cmap, cmap2, seconds, ticks, True, True);
212 fprintf(stderr, "done.\n"); fflush(stderr);
213 if (delay) sleep (delay);
214 fprintf(stderr,"in..."); fflush(stderr);
215 fade_colormap (dpy, cmap, cmap2, seconds, ticks, False, True);
216 XInstallColormap (dpy, cmap);
217 fprintf(stderr, "done.\n"); fflush(stderr);
220 if (delay) sleep (delay);