4cfc8f05e0ba16466fb34c3e1bf6755691e163e4
[xscreensaver] / hacks / screenhack.h
1
2 #if 0
3  * Found in Don Hopkin`s .plan file:
4  *
5  *   The color situation is a total flying circus.  The X approach to
6  *   device independence is to treat everything like a MicroVax framebuffer
7  *   on acid.  A truely portable X application is required to act like the
8  *   persistent customer in the Monty Python ``Cheese Shop'' sketch.  Even
9  *   the simplest applications must answer many difficult questions, like:
10  *
11  *   WHAT IS YOUR DISPLAY?
12  *       display = XOpenDisplay("unix:0");
13  *   WHAT IS YOUR ROOT?
14  *       root = RootWindow(display, DefaultScreen(display));
15  *   AND WHAT IS YOUR WINDOW?
16  *       win = XCreateSimpleWindow(display, root, 0, 0, 256, 256, 1,
17  *                                 BlackPixel(display, DefaultScreen(display)),
18  *                                 WhitePixel(display, DefaultScreen(display)))
19  *   OH ALL RIGHT, YOU CAN GO ON.
20  *
21  *   WHAT IS YOUR DISPLAY?
22  *         display = XOpenDisplay("unix:0");
23  *   WHAT IS YOUR COLORMAP?
24  *         cmap = DefaultColormap(display, DefaultScreen(display));
25  *   AND WHAT IS YOUR FAVORITE COLOR?
26  *         favorite_color = 0; /* Black. */
27  *         /* Whoops! No, I mean: */
28  *         favorite_color = BlackPixel(display, DefaultScreen(display));
29  *         /* AAAYYYYEEEEE!! (client dumps core & falls into the chasm) */
30  *
31  *   WHAT IS YOUR DISPLAY?
32  *         display = XOpenDisplay("unix:0");
33  *   WHAT IS YOUR VISUAL?
34  *         struct XVisualInfo vinfo;
35  *         if (XMatchVisualInfo(display, DefaultScreen(display),
36  *                              8, PseudoColor, &vinfo) != 0)
37  *            visual = vinfo.visual;
38  *   AND WHAT IS THE NET SPEED VELOCITY OF AN XConfigureWindow REQUEST?
39  *         /* Is that a SubStructureRedirectMask or a ResizeRedirectMask? */
40  *   WHAT??! HOW AM I SUPPOSED TO KNOW THAT?
41  *   AAAAUUUGGGHHH!!!! (server dumps core & falls into the chasm)
42  *
43 #endif /* 0 */
44
45 #ifndef _SCREENHACK_H_
46 #define _SCREENHACK_H_
47
48 #if __STDC__
49 #include <stdlib.h>
50 #endif
51
52 #include <X11/Xlib.h>
53 #include <X11/Xresource.h>
54 #include <X11/Xos.h>
55 #include "vroot.h"
56
57 extern Bool mono_p;
58 extern char *progname;
59 extern char *progclass;
60 extern XrmDatabase db;
61 extern XrmOptionDescRec options [];
62 extern int options_size;
63 extern char *defaults [];
64
65 #if __STDC__
66
67 # define bcopy(from,to,size) memcpy((to),(from),(size))
68 # define bzero(addr,size) memset((addr),0,(size))
69
70 # if defined(SVR4) || defined(SYSV)
71 extern int rand (void);
72 extern void srand (unsigned int);
73 #  define random() rand()
74 #  define srandom(i) srand((unsigned int)(i))
75 # else /* !totally-losing-SYSV */
76 extern long random (void);
77 extern void srandom (int);
78 # endif /* !totally-losing-SYSV */
79 #endif /* __STDC__ */
80
81 #if __STDC__
82 # define P(x)x
83 #else
84 # define P(x)()
85 #endif
86
87 extern void screenhack P((Display*,Window));
88
89 #define usleep screenhack_usleep
90
91 extern void screenhack_usleep P((unsigned long));
92 extern char *get_string_resource P((char*,char*));
93 extern Bool get_boolean_resource P((char*,char*));
94 extern int get_integer_resource P((char*,char*));
95 extern double get_float_resource P((char*,char*));
96 extern unsigned int get_pixel_resource P((char*,char*,Display*,Colormap));
97 extern unsigned int get_minutes_resource P((char*,char*));
98 extern unsigned int get_seconds_resource P((char*,char*));
99
100 extern Visual *get_visual_resource P((Display *, char *, char *));
101 extern int get_visual_depth P((Display *, Visual *));
102
103 void hsv_to_rgb P((int,double,double,unsigned short*,
104                    unsigned short*,unsigned short*));
105 void rgb_to_hsv P((unsigned short,unsigned short,unsigned short,
106                    int*,double*,double*));
107 void cycle_hue P((XColor*,int));
108
109 void make_color_ramp P((int h1, double s1, double v1,
110                         int h2, double s2, double v2,
111                         XColor *pixels, int npixels));
112
113 static double _frand_tmp_;
114 #define frand(f)                                                        \
115  (_frand_tmp_ = (((double) random()) /                                  \
116                  (((double) ((unsigned int)~0)) / ((double) (f+f)))),   \
117   _frand_tmp_ < 0 ? -_frand_tmp_ : _frand_tmp_)
118
119 #undef P
120 #endif /* _SCREENHACK_H_ */