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