14e9a16cb0d1b1be5ff6c095eb5fa44b4b5df23f
[xscreensaver] / hacks / screenhack.h
1 /* xscreensaver, Copyright (c) 1992, 1993 Jamie Zawinski <jwz@lucid.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 extern Bool mono_p;
68 extern char *progname;
69 extern char *progclass;
70 extern XrmDatabase db;
71 extern XrmOptionDescRec options [];
72 extern int options_size;
73 extern char *defaults [];
74
75 #if __STDC__
76 # if defined(SVR4) || defined(SYSV)
77 #  ifndef random
78     extern int rand (void);
79 #   define random() rand()
80 #  endif
81 #  ifndef srandom
82     extern void srand (unsigned int);
83 #   define srandom(i) srand((unsigned int)(i))
84 #  endif
85 # else /* !totally-losing-SYSV */
86 #  ifndef random
87     extern long random (void);
88 #  endif
89 #  ifndef srandom
90     extern void srandom (int);
91 #  endif
92 # endif /* !totally-losing-SYSV */
93 #endif /* __STDC__ */
94
95 #if __STDC__
96 # define P(x)x
97 #else
98 # define P(x)()
99 #endif
100
101 extern void screenhack P((Display*,Window));
102
103 #define usleep screenhack_usleep
104
105 extern void screenhack_usleep P((unsigned long));
106 extern char *get_string_resource P((char*,char*));
107 extern Bool get_boolean_resource P((char*,char*));
108 extern int get_integer_resource P((char*,char*));
109 extern double get_float_resource P((char*,char*));
110 extern unsigned int get_pixel_resource P((char*,char*,Display*,Colormap));
111 extern unsigned int get_minutes_resource P((char*,char*));
112 extern unsigned int get_seconds_resource P((char*,char*));
113
114 extern Visual *get_visual_resource P((Display *, char *, char *));
115 extern int get_visual_depth P((Display *, Visual *));
116
117 extern void hsv_to_rgb P((int,double,double,unsigned short*,
118                           unsigned short*,unsigned short*));
119 extern void rgb_to_hsv P((unsigned short,unsigned short,unsigned short,
120                           int*,double*,double*));
121 extern void cycle_hue P((XColor*,int));
122
123 extern void make_color_ramp P((int h1, double s1, double v1,
124                                int h2, double s2, double v2,
125                                XColor *pixels, int npixels));
126
127 extern Pixmap grab_screen_image P((Display *dpy, Window window, int root_p));
128
129 static double _frand_tmp_;
130 #define frand(f)                                                        \
131  (_frand_tmp_ = (((double) random()) /                                  \
132                  (((double) ((unsigned int)~0)) / ((double) (f+f)))),   \
133   _frand_tmp_ < 0 ? -_frand_tmp_ : _frand_tmp_)
134
135 #undef P
136 #endif /* _SCREENHACK_H_ */