1 /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules.
2 * xscreensaver, Copyright (c) 1997-2008 Jamie Zawinski <jwz@jwz.org>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
12 * The definitions in this file make it possible to compile an xlockmore
13 * module into a standalone program, and thus use it with xscreensaver.
14 * By Jamie Zawinski <jwz@jwz.org> on 10-May-97; based on the ideas
15 * in the older xlock.h by Charles Hannum <mycroft@ai.mit.edu>. (I had
16 * to redo it, since xlockmore has diverged so far from xlock...)
21 #endif /* HAVE_CONFIG_H */
24 ERROR! Sorry, xlockmore.h requires ANSI C (gcc, for example.)
25 /* (The ansi dependency is that we use string concatenation,
26 and cpp-based stringification of tokens.) */
29 #include "screenhackI.h"
30 #include "xlockmoreI.h"
35 # include <OpenGL/gl.h>
36 # include <OpenGL/glu.h>
37 # else /* !HAVE_COCOA -- real Xlib */
40 # endif /* !HAVE_COCOA */
42 # define FreeAllGL(dpy) /* */
45 # define ENTRYPOINT static
47 /* Accessor macros for the ModeInfo structure
49 #define MI_DISPLAY(MI) ((MI)->dpy)
50 #define MI_WINDOW(MI) ((MI)->window)
51 #define MI_NUM_SCREENS(MI) ((MI)->num_screens)
52 #define MI_SCREEN(MI) ((MI)->screen_number)
53 #define MI_WIN_WHITE_PIXEL(MI) ((MI)->white)
54 #define MI_WIN_BLACK_PIXEL(MI) ((MI)->black)
55 #define MI_NPIXELS(MI) ((MI)->npixels)
56 #define MI_PIXEL(MI,N) ((MI)->pixels[(N)])
57 #define MI_WIN_WIDTH(MI) ((MI)->xgwa.width)
58 #define MI_WIN_HEIGHT(MI) ((MI)->xgwa.height)
59 #define MI_WIN_DEPTH(MI) ((MI)->xgwa.depth)
60 #define MI_DEPTH(MI) ((MI)->xgwa.depth)
61 #define MI_WIN_COLORMAP(MI) ((MI)->xgwa.colormap)
62 #define MI_VISUAL(MI) ((MI)->xgwa.visual)
63 #define MI_GC(MI) ((MI)->gc)
64 #define MI_PAUSE(MI) ((MI)->pause)
65 #define MI_DELAY(MI) ((MI)->pause)
66 #define MI_WIN_IS_FULLRANDOM(MI)((MI)->fullrandom)
67 #define MI_WIN_IS_VERBOSE(MI) (False)
68 #define MI_WIN_IS_INSTALL(MI) (True)
69 #define MI_WIN_IS_MONO(MI) (mono_p)
70 #define MI_WIN_IS_INROOT(MI) ((MI)->root_p)
71 #define MI_WIN_IS_INWINDOW(MI) (!(MI)->root_p)
72 #define MI_WIN_IS_ICONIC(MI) (False)
73 #define MI_WIN_IS_WIREFRAME(MI) ((MI)->wireframe_p)
74 #define MI_WIN_IS_USE3D(MI) ((MI)->threed)
75 #define MI_LEFT_COLOR(MI) ((MI)->threed_left_color)
76 #define MI_RIGHT_COLOR(MI) ((MI)->threed_right_color)
77 #define MI_BOTH_COLOR(MI) ((MI)->threed_both_color)
78 #define MI_NONE_COLOR(MI) ((MI)->threed_none_color)
79 #define MI_DELTA3D(MI) ((MI)->threed_delta)
80 #define MI_CYCLES(MI) ((MI)->cycles)
81 #define MI_BATCHCOUNT(MI) ((MI)->batchcount)
82 #define MI_SIZE(MI) ((MI)->size)
83 #define MI_IS_DRAWN(MI) ((MI)->is_drawn)
84 #define MI_IS_FPS(MI) ((MI)->fps_p)
85 #define MI_NCOLORS(MI) ((MI)->npixels)
86 #define MI_NAME(MI) (progname)
88 #define MI_COLORMAP(MI) (MI_WIN_COLORMAP((MI)))
89 #define MI_WIDTH(MI) (MI_WIN_WIDTH((MI)))
90 #define MI_HEIGHT(MI) (MI_WIN_HEIGHT((MI)))
91 #define MI_IS_ICONIC(MI) (MI_WIN_IS_ICONIC((MI)))
92 #define MI_IS_WIREFRAME(MI) (MI_WIN_IS_WIREFRAME((MI)))
93 #define MI_IS_MONO(MI) (MI_WIN_IS_MONO((MI)))
94 #define MI_COUNT(MI) (MI_BATCHCOUNT((MI)))
95 #define MI_BLACK_PIXEL(MI) (MI_WIN_BLACK_PIXEL(MI))
96 #define MI_WHITE_PIXEL(MI) (MI_WIN_WHITE_PIXEL(MI))
97 #define MI_IS_FULLRANDOM(MI) (MI_WIN_IS_FULLRANDOM(MI))
98 #define MI_IS_VERBOSE(MI) (MI_WIN_IS_VERBOSE(MI))
99 #define MI_IS_INSTALL(MI) (MI_WIN_IS_INSTALL(MI))
100 #define MI_IS_DEBUG(MI) (False)
101 #define MI_IS_MOUSE(MI) (False)
103 #define MI_CLEARWINDOW(mi) XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi))
105 /* Some other utility macros.
107 #define SINF(n) ((float)sin((double)(n)))
108 #define COSF(n) ((float)cos((double)(n)))
109 #define FABSF(n) ((float)fabs((double)(n)))
114 #define MAX(a,b)((a)>(b)?(a):(b))
115 #define MIN(a,b)((a)<(b)?(a):(b))
116 #define ABS(a)((a)<0 ? -(a) : (a))
118 /* Maximum possible number of colors (*not* default number of colors.) */
119 #define NUMCOLORS 256
122 /* In an Xlib world, we define two global symbols here:
123 a struct in `MODULENAME_xscreensaver_function_table',
124 and a pointer to that in `xscreensaver_function_table'.
126 In a Cocoa world, we only define the prefixed symbol;
127 the un-prefixed symbol does not exist.
130 # define XSCREENSAVER_LINK(NAME)
132 # define XSCREENSAVER_LINK(NAME) \
133 struct xscreensaver_function_table *xscreensaver_function_table = &NAME;
137 # if !defined(USE_GL) || defined(HAVE_COCOA)
138 # define xlockmore_pick_gl_visual 0
139 # define xlockmore_validate_gl_visual 0
140 # endif /* !USE_GL || HAVE_COCOA */
143 # define xlockmore_gl_compute_fps 0
144 # endif /* !USE_GL */
146 #ifdef WRITABLE_COLORS
147 # undef WRITABLE_COLORS
148 # define WRITABLE_COLORS 1
150 # define WRITABLE_COLORS 0
153 #if defined(UNIFORM_COLORS)
154 # define XLOCKMORE_COLOR_SCHEME color_scheme_uniform
155 #elif defined(SMOOTH_COLORS)
156 # define XLOCKMORE_COLOR_SCHEME color_scheme_smooth
157 #elif defined(BRIGHT_COLORS)
158 # define XLOCKMORE_COLOR_SCHEME color_scheme_bright
160 # define XLOCKMORE_COLOR_SCHEME color_scheme_default
163 /* This is the macro that links this program in with the rest of
164 xscreensaver. For example:
166 XSCREENSAVER_MODULE ("Atlantis", atlantis)
167 XSCREENSAVER_MODULE_2 ("GLMatrix", glmatrix, matrix)
169 CLASS: a string, the class name for resources.
170 NAME: a token, the name of the executable. Should be the same
171 as CLASS, but downcased.
172 PREFIX: the symbol used in the function names, e.g., `draw_atlantis'.
174 NAME and PREFIX are usually the same. If they are not, use
175 XSCREENSAVER_MODULE_2() instead of XSCREENSAVER_MODULE().
177 #define XSCREENSAVER_MODULE_2(CLASS,NAME,PREFIX) \
179 static struct xlockmore_function_table \
180 NAME ## _xlockmore_function_table = { \
184 XLOCKMORE_COLOR_SCHEME, \
187 reshape_ ## PREFIX, \
188 refresh_ ## PREFIX, \
189 release_ ## PREFIX, \
190 PREFIX ## _handle_event, \
194 struct xscreensaver_function_table \
195 NAME ## _xscreensaver_function_table = { \
198 & NAME ## _xlockmore_function_table, \
200 xlockmore_gl_compute_fps, \
201 xlockmore_pick_gl_visual, \
202 xlockmore_validate_gl_visual }; \
204 XSCREENSAVER_LINK (NAME ## _xscreensaver_function_table)
206 #define XSCREENSAVER_MODULE(CLASS,PREFIX) \
207 XSCREENSAVER_MODULE_2(CLASS,PREFIX,PREFIX)