ftp://ftp.zenez.com/pub/SCO/Skunk96/UnixWare/FreeBird/x11/utils/xscreensaver-1.18...
[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
77 # define bcopy(from,to,size) memcpy((to),(from),(size))
78 # define bzero(addr,size) memset((addr),0,(size))
79
80 # if defined(SVR4) || defined(SYSV)
81 extern int rand (void);
82 extern void srand (unsigned int);
83 #  define random() rand()
84 #  define srandom(i) srand((unsigned int)(i))
85 # else /* !totally-losing-SYSV */
86 extern long random (void);
87 extern void srandom (int);
88 # endif /* !totally-losing-SYSV */
89 #endif /* __STDC__ */
90
91 #if __STDC__
92 # define P(x)x
93 #else
94 # define P(x)()
95 #endif
96
97 extern void screenhack P((Display*,Window));
98
99 #define usleep screenhack_usleep
100
101 extern void screenhack_usleep P((unsigned long));
102 extern char *get_string_resource P((char*,char*));
103 extern Bool get_boolean_resource P((char*,char*));
104 extern int get_integer_resource P((char*,char*));
105 extern double get_float_resource P((char*,char*));
106 extern unsigned int get_pixel_resource P((char*,char*,Display*,Colormap));
107 extern unsigned int get_minutes_resource P((char*,char*));
108 extern unsigned int get_seconds_resource P((char*,char*));
109
110 extern Visual *get_visual_resource P((Display *, char *, char *));
111 extern int get_visual_depth P((Display *, Visual *));
112
113 extern void hsv_to_rgb P((int,double,double,unsigned short*,
114                           unsigned short*,unsigned short*));
115 extern void rgb_to_hsv P((unsigned short,unsigned short,unsigned short,
116                           int*,double*,double*));
117 extern void cycle_hue P((XColor*,int));
118
119 extern void make_color_ramp P((int h1, double s1, double v1,
120                                int h2, double s2, double v2,
121                                XColor *pixels, int npixels));
122
123 extern Pixmap grab_screen_image P((Display *dpy, Window window, int root_p));
124
125 static double _frand_tmp_;
126 #define frand(f)                                                        \
127  (_frand_tmp_ = (((double) random()) /                                  \
128                  (((double) ((unsigned int)~0)) / ((double) (f+f)))),   \
129   _frand_tmp_ < 0 ? -_frand_tmp_ : _frand_tmp_)
130
131 #undef P
132 #endif /* _SCREENHACK_H_ */