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