1 /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules.
2 * xscreensaver, Copyright (c) 1997-2012 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"
32 # define ENTRYPOINT static
34 /* Accessor macros for the ModeInfo structure
36 #define MI_DISPLAY(MI) ((MI)->dpy)
37 #define MI_WINDOW(MI) ((MI)->window)
38 #define MI_NUM_SCREENS(MI) ((MI)->num_screens)
39 #define MI_SCREEN(MI) ((MI)->screen_number)
40 #define MI_WIN_WHITE_PIXEL(MI) ((MI)->white)
41 #define MI_WIN_BLACK_PIXEL(MI) ((MI)->black)
42 #define MI_NPIXELS(MI) ((MI)->npixels)
43 #define MI_PIXEL(MI,N) ((MI)->pixels[(N)])
44 #define MI_WIN_WIDTH(MI) ((MI)->xgwa.width)
45 #define MI_WIN_HEIGHT(MI) ((MI)->xgwa.height)
46 #define MI_WIN_DEPTH(MI) ((MI)->xgwa.depth)
47 #define MI_DEPTH(MI) ((MI)->xgwa.depth)
48 #define MI_WIN_COLORMAP(MI) ((MI)->xgwa.colormap)
49 #define MI_VISUAL(MI) ((MI)->xgwa.visual)
50 #define MI_GC(MI) ((MI)->gc)
51 #define MI_PAUSE(MI) ((MI)->pause)
52 #define MI_DELAY(MI) ((MI)->pause)
53 #define MI_WIN_IS_FULLRANDOM(MI)((MI)->fullrandom)
54 #define MI_WIN_IS_VERBOSE(MI) (False)
55 #define MI_WIN_IS_INSTALL(MI) (True)
56 #define MI_WIN_IS_MONO(MI) (mono_p)
57 #define MI_WIN_IS_INROOT(MI) ((MI)->root_p)
58 #define MI_WIN_IS_INWINDOW(MI) (!(MI)->root_p)
59 #define MI_WIN_IS_ICONIC(MI) (False)
60 #define MI_WIN_IS_WIREFRAME(MI) ((MI)->wireframe_p)
61 #define MI_WIN_IS_USE3D(MI) ((MI)->threed)
62 #define MI_LEFT_COLOR(MI) ((MI)->threed_left_color)
63 #define MI_RIGHT_COLOR(MI) ((MI)->threed_right_color)
64 #define MI_BOTH_COLOR(MI) ((MI)->threed_both_color)
65 #define MI_NONE_COLOR(MI) ((MI)->threed_none_color)
66 #define MI_DELTA3D(MI) ((MI)->threed_delta)
67 #define MI_CYCLES(MI) ((MI)->cycles)
68 #define MI_BATCHCOUNT(MI) ((MI)->batchcount)
69 #define MI_SIZE(MI) ((MI)->size)
70 #define MI_IS_DRAWN(MI) ((MI)->is_drawn)
71 #define MI_IS_FPS(MI) ((MI)->fps_p)
72 #define MI_NCOLORS(MI) ((MI)->npixels)
73 #define MI_NAME(MI) (progname)
75 #define MI_COLORMAP(MI) (MI_WIN_COLORMAP((MI)))
76 #define MI_WIDTH(MI) (MI_WIN_WIDTH((MI)))
77 #define MI_HEIGHT(MI) (MI_WIN_HEIGHT((MI)))
78 #define MI_IS_ICONIC(MI) (MI_WIN_IS_ICONIC((MI)))
79 #define MI_IS_WIREFRAME(MI) (MI_WIN_IS_WIREFRAME((MI)))
80 #define MI_IS_MONO(MI) (MI_WIN_IS_MONO((MI)))
81 #define MI_COUNT(MI) (MI_BATCHCOUNT((MI)))
82 #define MI_BLACK_PIXEL(MI) (MI_WIN_BLACK_PIXEL(MI))
83 #define MI_WHITE_PIXEL(MI) (MI_WIN_WHITE_PIXEL(MI))
84 #define MI_IS_FULLRANDOM(MI) (MI_WIN_IS_FULLRANDOM(MI))
85 #define MI_IS_VERBOSE(MI) (MI_WIN_IS_VERBOSE(MI))
86 #define MI_IS_INSTALL(MI) (MI_WIN_IS_INSTALL(MI))
87 #define MI_IS_DEBUG(MI) (False)
88 #define MI_IS_MOUSE(MI) (False)
90 #define MI_CLEARWINDOW(mi) XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi))
92 #define FreeAllGL(dpy) /* */
94 /* Some other utility macros.
96 #define SINF(n) ((float)sin((double)(n)))
97 #define COSF(n) ((float)cos((double)(n)))
98 #define FABSF(n) ((float)fabs((double)(n)))
103 #define MAX(a,b)((a)>(b)?(a):(b))
104 #define MIN(a,b)((a)<(b)?(a):(b))
105 #define ABS(a)((a)<0 ? -(a) : (a))
107 /* Maximum possible number of colors (*not* default number of colors.) */
108 #define NUMCOLORS 256
111 /* In an Xlib world, we define two global symbols here:
112 a struct in `MODULENAME_xscreensaver_function_table',
113 and a pointer to that in `xscreensaver_function_table'.
115 In a Cocoa or Android world, we only define the prefixed symbol;
116 the un-prefixed symbol does not exist.
119 # define XSCREENSAVER_LINK(NAME)
121 # define XSCREENSAVER_LINK(NAME) \
122 struct xscreensaver_function_table *xscreensaver_function_table = &NAME;
126 # if !defined(USE_GL) || defined(HAVE_COCOA) || defined(HAVE_ANDROID)
127 # define xlockmore_pick_gl_visual 0
128 # define xlockmore_validate_gl_visual 0
129 # endif /* !USE_GL || HAVE_COCOA || HAVE_ANDROID */
132 # define XLOCKMORE_FPS xlockmore_gl_compute_fps
134 # define XLOCKMORE_FPS xlockmore_do_fps
137 #ifdef WRITABLE_COLORS
138 # undef WRITABLE_COLORS
139 # define WRITABLE_COLORS 1
141 # define WRITABLE_COLORS 0
144 #if defined(UNIFORM_COLORS)
145 # define XLOCKMORE_COLOR_SCHEME color_scheme_uniform
146 #elif defined(SMOOTH_COLORS)
147 # define XLOCKMORE_COLOR_SCHEME color_scheme_smooth
148 #elif defined(BRIGHT_COLORS)
149 # define XLOCKMORE_COLOR_SCHEME color_scheme_bright
151 # define XLOCKMORE_COLOR_SCHEME color_scheme_default
154 /* This is the macro that links this program in with the rest of
155 xscreensaver. For example:
157 XSCREENSAVER_MODULE ("Atlantis", atlantis)
158 XSCREENSAVER_MODULE_2 ("GLMatrix", glmatrix, matrix)
160 CLASS: a string, the class name for resources.
161 NAME: a token, the name of the executable. Should be the same
162 as CLASS, but downcased.
163 PREFIX: the symbol used in the function names, e.g., `draw_atlantis'.
165 NAME and PREFIX are usually the same. If they are not, use
166 XSCREENSAVER_MODULE_2() instead of XSCREENSAVER_MODULE().
168 #define XSCREENSAVER_MODULE_2(CLASS,NAME,PREFIX) \
170 static struct xlockmore_function_table \
171 NAME ## _xlockmore_function_table = { \
175 XLOCKMORE_COLOR_SCHEME, \
178 reshape_ ## PREFIX, \
179 refresh_ ## PREFIX, \
180 release_ ## PREFIX, \
181 PREFIX ## _handle_event, \
186 struct xscreensaver_function_table \
187 NAME ## _xscreensaver_function_table = { \
190 & NAME ## _xlockmore_function_table, \
193 xlockmore_pick_gl_visual, \
194 xlockmore_validate_gl_visual }; \
196 XSCREENSAVER_LINK (NAME ## _xscreensaver_function_table)
198 #define XSCREENSAVER_MODULE(CLASS,PREFIX) \
199 XSCREENSAVER_MODULE_2(CLASS,PREFIX,PREFIX)