From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / hacks / screenhack.h
index 9be436724f35c94f344a7d37996debbb4e89c05a..2e55d8930122a0e53371660c65f787f72f5c56e3 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 1992-1995 Jamie Zawinski <jwz@netscape.com>
+/* xscreensaver, Copyright (c) 1992-2015 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
  * implied warranty.
  */
 
-/* Found in Don Hopkins' .plan file:
- *
- *   The color situation is a total flying circus.  The X approach to
- *   device independence is to treat everything like a MicroVax framebuffer
- *   on acid.  A truely portable X application is required to act like the
- *   persistent customer in the Monty Python ``Cheese Shop'' sketch.  Even
- *   the simplest applications must answer many difficult questions, like:
- *
- *   WHAT IS YOUR DISPLAY?
- *       display = XOpenDisplay("unix:0");
- *   WHAT IS YOUR ROOT?
- *       root = RootWindow(display, DefaultScreen(display));
- *   AND WHAT IS YOUR WINDOW?
- *       win = XCreateSimpleWindow(display, root, 0, 0, 256, 256, 1,
- *                                 BlackPixel(display, DefaultScreen(display)),
- *                                 WhitePixel(display, DefaultScreen(display)))
- *   OH ALL RIGHT, YOU CAN GO ON.
- *
- *   WHAT IS YOUR DISPLAY?
- *         display = XOpenDisplay("unix:0");
- *   WHAT IS YOUR COLORMAP?
- *         cmap = DefaultColormap(display, DefaultScreen(display));
- *   AND WHAT IS YOUR FAVORITE COLOR?
- *         favorite_color = 0; / * Black. * /
- *         / * Whoops! No, I mean: * /
- *         favorite_color = BlackPixel(display, DefaultScreen(display));
- *         / * AAAYYYYEEEEE!! (client dumps core & falls into the chasm) * /
- *
- *   WHAT IS YOUR DISPLAY?
- *         display = XOpenDisplay("unix:0");
- *   WHAT IS YOUR VISUAL?
- *         struct XVisualInfo vinfo;
- *         if (XMatchVisualInfo(display, DefaultScreen(display),
- *                              8, PseudoColor, &vinfo) != 0)
- *            visual = vinfo.visual;
- *   AND WHAT IS THE NET SPEED VELOCITY OF AN XConfigureWindow REQUEST?
- *         / * Is that a SubStructureRedirectMask or a ResizeRedirectMask? * /
- *   WHAT?! HOW AM I SUPPOSED TO KNOW THAT?
- *   AAAAUUUGGGHHH!!!! (server dumps core & falls into the chasm)
- */
+#ifndef __SCREENHACK_H__
+#define __SCREENHACK_H__
 
-#ifndef _SCREENHACK_H_
-#define _SCREENHACK_H_
+#include "screenhackI.h"
 
-#if __STDC__
-#include <stdlib.h>
-#endif
+/* In an Xlib world, we define two global symbols here:
+   a struct in `MODULENAME_xscreensaver_function_table',
+   and a pointer to that in `xscreensaver_function_table'.
 
-#ifdef __hpux
- /* Which of the ten billion standards does values.h belong to?
-    What systems always have it? */
-# include <values.h>
+   In a Cocoa/Android world, we only define the prefixed symbol;
+   the un-prefixed symbol does not exist.
+ */
+#ifdef HAVE_JWXYZ
+# define XSCREENSAVER_LINK(NAME)
+#else
+# define XSCREENSAVER_LINK(NAME) \
+   struct xscreensaver_function_table *xscreensaver_function_table = &NAME;
 #endif
 
-#include <X11/Xlib.h>
-#include <X11/Xresource.h>
-#include <X11/Xos.h>
-#include "vroot.h"
-
-extern Bool mono_p;
-extern char *progname;
-extern char *progclass;
-extern XrmDatabase db;
-extern XrmOptionDescRec options [];
-extern int options_size;
-extern char *defaults [];
-
-/* Screw it, we'll just use our own RNG.  See xscreensaver/utils/yarandom.c. */
-#include "yarandom.h"
-
 
-#undef P
-#if __STDC__
-# define P(x)x
+#if defined(HAVE_JWXYZ) && !defined(__XLOCKMORE_INTERNAL_H__)
+  /* this is one enormous kludge... */
+# undef ya_rand_init
+  static void
+  xscreensaver_common_setup(struct xscreensaver_function_table *xsft, void *a)
+  { ya_rand_init(0); }
 #else
-# define P(x)()
+# define xscreensaver_common_setup 0
 #endif
 
-extern void screenhack P((Display*,Window));
-
-#define usleep screenhack_usleep
-
-extern void screenhack_usleep P((unsigned long));
-extern char *get_string_resource P((char*,char*));
-extern Bool get_boolean_resource P((char*,char*));
-extern int get_integer_resource P((char*,char*));
-extern double get_float_resource P((char*,char*));
-extern unsigned int get_pixel_resource P((char*,char*,Display*,Colormap));
-extern unsigned int get_minutes_resource P((char*,char*));
-extern unsigned int get_seconds_resource P((char*,char*));
-
-extern Visual *get_visual_resource P((Display *, char *, char *));
-extern int get_visual_depth P((Display *, Visual *));
-
-extern void hsv_to_rgb P((int,double,double,unsigned short*,
-                         unsigned short*,unsigned short*));
-extern void rgb_to_hsv P((unsigned short,unsigned short,unsigned short,
-                         int*,double*,double*));
-extern void cycle_hue P((XColor*,int));
-
-extern void make_color_ramp P((int h1, double s1, double v1,
-                              int h2, double s2, double v2,
-                              XColor *pixels, int npixels));
-
-extern Pixmap grab_screen_image P((Display *dpy, Window window, int root_p));
-extern void copy_default_colormap_contents P((Display *dpy, Colormap to_cmap,
-                                             Visual *to_visual));
-
-#if defined (__GNUC__) && (__GNUC__ >= 2)
- /* Implement frand using GCC's statement-expression extension. */
-
-# define frand(f)                                                      \
-  ({ double tmp = (((double) random()) /                               \
-                  (((double) ((unsigned int)~0)) / ((double) (f+f)))); \
-     tmp < 0 ? (-tmp) : tmp; })
-
-#else /* not GCC2 - implement frand using a global variable.*/
-
-static double _frand_tmp_;
-# define frand(f)                                                      \
-  (_frand_tmp_ = (((double) random()) /                                \
-                 (((double) ((unsigned int)~0)) / ((double) (f+f)))),  \
-   _frand_tmp_ < 0 ? (-_frand_tmp_) : _frand_tmp_)
-
-#endif /* not GCC2 */
 
-#undef P
-#endif /* _SCREENHACK_H_ */
+#define XSCREENSAVER_MODULE_2(CLASS,NAME,PREFIX)               \
+  struct xscreensaver_function_table                           \
+        NAME ## _xscreensaver_function_table = {               \
+          CLASS,                                               \
+          PREFIX ## _defaults,                                 \
+          PREFIX ## _options,                                  \
+          xscreensaver_common_setup, 0,                        \
+          PREFIX ## _init,                                     \
+          PREFIX ## _draw,                                     \
+          PREFIX ## _reshape,                                  \
+          PREFIX ## _event,                                    \
+          PREFIX ## _free,                                     \
+           0, 0, 0 };                                          \
+  XSCREENSAVER_LINK (NAME ## _xscreensaver_function_table)
+
+#define XSCREENSAVER_MODULE(CLASS,PREFIX)                      \
+      XSCREENSAVER_MODULE_2(CLASS,PREFIX,PREFIX)
+
+#endif /* __SCREENHACK_H__ */