From http://www.jwz.org/xscreensaver/xscreensaver-5.40.tar.gz
[xscreensaver] / jwxyz / jwxyz.h
1 /* xscreensaver, Copyright (c) 1991-2018 Jamie Zawinski <jwz@jwz.org>
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 /* JWXYZ Is Not Xlib.
13
14    But it's a bunch of function definitions that bear some resemblance to
15    Xlib and that do Cocoa-ish or OpenGL-ish things that bear some resemblance
16    to the things that Xlib might have done.
17  */
18
19 #ifndef __JWXYZ_H__
20 #define __JWXYZ_H__
21
22 #include <stdlib.h> /* For abort(). */
23 #include <stdarg.h>
24
25 #if defined __FreeBSD__ || defined __MACH__ && defined __APPLE__
26 # include <sys/cdefs.h>
27 #endif
28
29 #ifndef __dead2
30 /* __dead2 is an undocumented FreeBSD-ism (and by extension, an OSX-ism),
31    normally #defined in <sys/cdefs.h>.
32  */
33 # if defined __GNUC__ || defined __clang__
34 #  define __dead2 __attribute__((__noreturn__))
35 # else
36 #  define __dead2
37 # endif
38 #endif
39
40 extern void jwxyz_abort(const char *fmt, ...) __dead2;
41 #define abort() jwxyz_abort("abort in %s:%d", __FUNCTION__, __LINE__)
42
43 typedef int Bool;
44 typedef int Status;
45 typedef void * XPointer;
46 typedef unsigned long Time;
47 typedef unsigned int KeySym;
48 typedef unsigned int KeyCode;
49 typedef unsigned long Atom; /* Must be as large as a char *. */
50
51 typedef struct jwxyz_Display            Display;
52 typedef struct jwxyz_Display            Screen;
53 typedef struct jwxyz_Visual             Visual;
54 typedef struct jwxyz_Drawable *         Drawable;
55 typedef struct jwxyz_Colormap *         Colormap;
56 typedef struct jwxyz_GC *               GC;
57 typedef struct jwxyz_XColor             XColor;
58 typedef struct jwxyz_XGCValues          XGCValues;
59 typedef struct jwxyz_XPoint             XPoint;
60 typedef struct jwxyz_XSegment           XSegment;
61 typedef struct jwxyz_XRectangle         XRectangle;
62 typedef struct jwxyz_XArc               XArc;
63 typedef struct jwxyz_XWindowAttributes  XWindowAttributes;
64 typedef struct jwxyz_XrmOptionDescRec   XrmOptionDescRec;
65 typedef struct jwxyz_XrmDatabase *      XrmDatabase;
66 typedef struct jwxyz_XImage             XImage;
67 typedef struct jwxyz_XFontProp          XFontProp;
68 typedef struct jwxyz_XFontStruct        XFontStruct;
69 typedef struct jwxyz_Font *             Font;
70 typedef struct jwxyz_XFontSet *         XFontSet;
71 typedef struct jwxyz_XCharStruct        XCharStruct;
72 typedef struct jwxyz_XComposeStatus     XComposeStatus;
73 typedef struct jwxyz_XPixmapFormatValues XPixmapFormatValues;
74 typedef struct jwxyz_XChar2b            XChar2b;
75
76 typedef union  jwxyz_XEvent             XEvent;
77 typedef struct jwxyz_XAnyEvent          XAnyEvent;
78 typedef struct jwxyz_XKeyEvent          XKeyEvent;
79 typedef struct jwxyz_XMotionEvent       XMotionEvent;
80 typedef struct jwxyz_XButtonEvent       XButtonEvent;
81 typedef XKeyEvent                       XKeyPressedEvent;
82 typedef XKeyEvent                       XKeyReleasedEvent;
83 typedef XMotionEvent                    XPointerMovedEvent;
84 typedef XButtonEvent                    XButtonPressedEvent;
85 typedef XButtonEvent                    XButtonReleasedEvent;
86
87
88 /* Not technically Xlib... */
89 typedef struct jwxyz_GLXContext *       GLXContext;
90 typedef struct jwxyz_XtAppContext *     XtAppContext;
91 typedef struct jwxyz_XtIntervalId *     XtIntervalId;
92 typedef struct jwxyz_XtInputId *        XtInputId;
93 typedef void *                          XtPointer;
94 typedef unsigned long                   XtInputMask;
95 typedef struct jwxyz_linked_point       linked_point;
96
97 #define XtInputReadMask                 (1L<<0)
98 #define XtInputWriteMask                (1L<<1)
99 #define XtInputExceptMask               (1L<<2)
100 #define XtIMXEvent                      1
101 #define XtIMTimer                       2
102 #define XtIMAlternateInput              4
103 #define XtIMSignal                      8
104 #define XtIMAll (XtIMXEvent | XtIMTimer | XtIMAlternateInput | XtIMSignal)
105
106 #define True 1
107 #define TRUE 1
108 #define False 0
109 #define FALSE 0
110 #define None 0
111
112 #define Window Drawable
113 #define Pixmap Drawable
114
115 #define XrmoptionNoArg  0
116 #define XrmoptionSepArg 1
117
118 #define CoordModeOrigin         0
119 #define CoordModePrevious       1
120
121 #define LineSolid               0
122 #define LineOnOffDash           1
123 #define LineDoubleDash          2
124
125 #define CapNotLast              0
126 #define CapButt                 1
127 #define CapRound                2
128 #define CapProjecting           3
129
130 #define JoinMiter               0
131 #define JoinRound               1
132 #define JoinBevel               2
133
134 #define FillSolid               0
135 #define FillTiled               1
136 #define FillStippled            2
137 #define FillOpaqueStippled      3
138
139 #define EvenOddRule             0
140 #define WindingRule             1
141
142 #define Complex                 0
143 #define Nonconvex               1
144 #define Convex                  2
145
146 #define XYBitmap                0
147 #define XYPixmap                1
148 #define ZPixmap                 2
149
150 #define AllocNone               0
151 #define AllocAll                1
152
153 #define StaticGray              0
154 #define GrayScale               1
155 #define StaticColor             2
156 #define PseudoColor             3
157 #define TrueColor               4
158 #define DirectColor             5
159
160 #define LSBFirst                0
161 #define MSBFirst                1
162
163 #define DoRed                   (1<<0)
164 #define DoGreen                 (1<<1)
165 #define DoBlue                  (1<<2)
166
167 #define GCFunction              (1L<<0)
168 #define GCPlaneMask             (1L<<1)
169 #define GCForeground            (1L<<2)
170 #define GCBackground            (1L<<3)
171 #define GCLineWidth             (1L<<4)
172 #define GCLineStyle             (1L<<5)
173 #define GCCapStyle              (1L<<6)
174 #define GCJoinStyle             (1L<<7)
175 #define GCFillStyle             (1L<<8)
176 #define GCFillRule              (1L<<9) 
177 #define GCTile                  (1L<<10)
178 #define GCStipple               (1L<<11)
179 #define GCTileStipXOrigin       (1L<<12)
180 #define GCTileStipYOrigin       (1L<<13)
181 #define GCFont                  (1L<<14)
182 #define GCSubwindowMode         (1L<<15)
183 #define GCGraphicsExposures     (1L<<16)
184 #define GCClipXOrigin           (1L<<17)
185 #define GCClipYOrigin           (1L<<18)
186 #define GCClipMask              (1L<<19)
187 #define GCDashOffset            (1L<<20)
188 #define GCDashList              (1L<<21)
189 #define GCArcMode               (1L<<22)
190
191 #define KeyPress                2
192 #define KeyRelease              3
193 #define ButtonPress             4
194 #define ButtonRelease           5
195 #define MotionNotify            6
196 #define Expose                  12
197 #define GraphicsExpose          13
198 #define NoExpose                14
199 #define VisibilityNotify        15
200
201 #define ClipByChildren          0
202 #define IncludeInferiors        1
203
204 #define KeyPressMask            (1L<<0)
205 #define KeyReleaseMask          (1L<<1)
206 #define ButtonPressMask         (1L<<2)
207 #define ButtonReleaseMask       (1L<<3)
208 #define PointerMotionMask       (1L<<6)
209
210 #define Button1                 1
211 #define Button2                 2
212 #define Button3                 3
213 #define Button4                 4
214 #define Button5                 5
215
216 #define ShiftMask               (1<<0)
217 #define LockMask                (1<<1)
218 #define ControlMask             (1<<2)
219 #define Mod1Mask                (1<<3)
220 #define Mod2Mask                (1<<4)
221 #define Mod3Mask                (1<<5)
222 #define Mod4Mask                (1<<6)
223 #define Mod5Mask                (1<<7)
224 #define Button1Mask             (1<<8)
225 #define Button2Mask             (1<<9)
226 #define Button3Mask             (1<<10)
227 #define Button4Mask             (1<<11)
228 #define Button5Mask             (1<<12)
229
230 #define XK_Shift_L              0xFFE1
231 #define XK_Shift_R              0xFFE2
232 #define XK_Control_L            0xFFE3
233 #define XK_Control_R            0xFFE4
234 #define XK_Caps_Lock            0xFFE5
235 #define XK_Shift_Lock           0xFFE6
236 #define XK_Meta_L               0xFFE7
237 #define XK_Meta_R               0xFFE8
238 #define XK_Alt_L                0xFFE9
239 #define XK_Alt_R                0xFFEA
240 #define XK_Super_L              0xFFEB
241 #define XK_Super_R              0xFFEC
242 #define XK_Hyper_L              0xFFED
243 #define XK_Hyper_R              0xFFEE
244
245 #define XK_Home                 0xFF50
246 #define XK_Left                 0xFF51
247 #define XK_Up                   0xFF52
248 #define XK_Right                0xFF53
249 #define XK_Down                 0xFF54
250 #define XK_Prior                0xFF55
251 #define XK_Page_Up              0xFF55
252 #define XK_Next                 0xFF56
253 #define XK_Page_Down            0xFF56
254 #define XK_End                  0xFF57
255 #define XK_Begin                0xFF58
256
257 #define XK_F1                   0xFFBE
258 #define XK_F2                   0xFFBF
259 #define XK_F3                   0xFFC0
260 #define XK_F4                   0xFFC1
261 #define XK_F5                   0xFFC2
262 #define XK_F6                   0xFFC3
263 #define XK_F7                   0xFFC4
264 #define XK_F8                   0xFFC5
265 #define XK_F9                   0xFFC6
266 #define XK_F10                  0xFFC7
267 #define XK_F11                  0xFFC8
268 #define XK_F12                  0xFFC9
269
270
271 #define GXclear                 0x0             /* 0 */
272 #define GXand                   0x1             /* src AND dst */
273 // #define GXandReverse         0x2             /* src AND NOT dst */
274 #define GXcopy                  0x3             /* src */
275 // #define GXandInverted        0x4             /* NOT src AND dst */
276 // #define GXnoop               0x5             /* dst */
277 #define GXxor                   0x6             /* src XOR dst */
278 #define GXor                    0x7             /* src OR dst */
279 // #define GXnor                0x8             /* NOT src AND NOT dst */
280 // #define GXequiv              0x9             /* NOT src XOR dst */
281 // #define GXinvert             0xa             /* NOT dst */
282 // #define GXorReverse          0xb             /* src OR NOT dst */
283 // #define GXcopyInverted       0xc             /* NOT src */
284 // #define GXorInverted         0xd             /* NOT src OR dst */
285 // #define GXnand               0xe             /* NOT src OR NOT dst */
286 #define GXset                   0xf             /* 1 */
287
288 #define XA_FONT                 18
289
290 #define DefaultScreen(dpy) (0)
291 #define BlackPixelOfScreen XBlackPixelOfScreen
292 #define WhitePixelOfScreen XWhitePixelOfScreen
293 #define BlackPixel(dpy,n) BlackPixelOfScreen(ScreenOfDisplay(dpy,n))
294 #define WhitePixel(dpy,n) WhitePixelOfScreen(ScreenOfDisplay(dpy,n))
295 #define CellsOfScreen XCellsOfScreen
296 #define XFree(x) free(x)
297 #define BitmapPad(dpy) (8)
298 #define BitmapBitOrder(dpy) (MSBFirst)
299 #define ImageByteOrder(dpy) (MSBFirst)
300 #define DisplayOfScreen XDisplayOfScreen
301 #define DefaultScreenOfDisplay XDefaultScreenOfDisplay
302 #define ScreenOfDisplay(dpy,n) DefaultScreenOfDisplay(dpy)
303 #define DefaultVisualOfScreen XDefaultVisualOfScreen
304 #define DefaultColormapOfScreen(s) (0)
305 #define RootWindow XRootWindow
306 #define RootWindowOfScreen(s) RootWindow(DisplayOfScreen(s),0)
307 #define DisplayWidth XDisplayWidth
308 #define DisplayHeight XDisplayHeight
309 #define XMaxRequestSize(dpy) (65535)
310 #define XWidthOfScreen(s) (DisplayWidth(DisplayOfScreen(s),0))
311 #define XHeightOfScreen(s) (DisplayHeight(DisplayOfScreen(s),0))
312 #define XWidthMMOfScreen(s) (XDisplayWidthMM(DisplayOfScreen(s),0))
313 #define XHeightMMOfScreen(s) (XDisplayHeightMM(DisplayOfScreen(s),0))
314 #define XDefaultScreenOfDisplay(d) (d)
315 #define XDisplayOfScreen(s) (s)
316 #define XDisplayNumberOfScreen(s) 0
317 #define XScreenNumberOfScreen(s) 0
318
319 extern int XDisplayWidth (Display *, int);
320 extern int XDisplayHeight (Display *, int);
321 extern int XDisplayWidthMM (Display *, int);
322 extern int XDisplayHeightMM (Display *, int);
323
324 unsigned long XBlackPixelOfScreen(Screen *);
325 unsigned long XWhitePixelOfScreen(Screen *);
326 unsigned long XCellsOfScreen(Screen *);
327
328 extern int XDrawPoint (Display *, Drawable, GC, int x, int y);
329
330 extern int XChangeGC (Display *, GC, unsigned long mask, XGCValues *);
331
332 extern int XClearArea (Display *, Window, int x, int y, int w, int h,Bool exp);
333 extern int XSetWindowBackground (Display *, Window, unsigned long);
334 extern Status XGetWindowAttributes (Display *, Window, XWindowAttributes *);
335 extern Status XGetGeometry (Display *, Drawable, Window *root_ret,
336                             int *x_ret, int *y_ret, 
337                             unsigned int *w_ret, unsigned int *h_ret,
338                             unsigned int *bw_ret, unsigned int *depth_ret);
339 extern Status XAllocColor (Display *, Colormap, XColor *);
340 extern Status XAllocColorCells (Display *, Colormap, Bool contig,
341                                 unsigned long *pmret, unsigned int npl,
342                                 unsigned long *pxret, unsigned int npx);
343 extern int XStoreColors (Display *, Colormap, XColor *, int n);
344 extern int XStoreColor (Display *, Colormap, XColor *);
345 extern Status XParseColor(Display *, Colormap, const char *spec, XColor *ret);
346 extern Status XAllocNamedColor (Display *, Colormap, char *name,
347                                 XColor *screen_ret, XColor *exact_ret);
348 extern int XQueryColor (Display *, Colormap, XColor *);
349 extern int XQueryColors(Display *, Colormap colormap, XColor *, int ncolors);
350
351 extern int XSetForeground (Display *, GC, unsigned long);
352 extern int XSetBackground (Display *, GC, unsigned long);
353 extern int XSetFunction (Display *, GC, int);
354 extern int XSetSubwindowMode (Display *, GC, int);
355 extern int XSetLineAttributes (Display *, GC, unsigned int line_width,
356                                int line_style, int cap_style, int join_style);
357 extern int jwxyz_XSetAlphaAllowed (Display *, GC, Bool);
358 extern int jwxyz_XSetAntiAliasing (Display *, GC, Bool);
359
360 extern int XFlush (Display *);
361 extern int XSync (Display *, Bool);
362 extern int XFreeColors (Display *, Colormap, unsigned long *px, int n,
363                         unsigned long planes);
364 extern int XCopyArea (Display *, Drawable src, Drawable dest, GC, 
365                       int src_x, int src_y, 
366                       unsigned int width, unsigned int height, 
367                       int dest_x, int dest_y);
368 extern int XCopyPlane (Display *, Drawable, Drawable, GC,
369                        int src_x, int src_y,
370                        unsigned width, int height,
371                        int dest_x, int dest_y,
372                        unsigned long plane);
373
374 extern int XDrawLine (Display *, Drawable, GC, int x1, int y1, int x2, int y2);
375 extern int XDrawArc (Display *, Drawable, GC, int x, int y, 
376                      unsigned int width, unsigned int height,
377                      int angle1, int angle2);
378 extern int XFillArc (Display *, Drawable, GC, int x, int y, 
379                      unsigned int width, unsigned int height,
380                      int angle1, int angle2);
381 extern int XDrawArcs (Display *, Drawable, GC, XArc *arcs, int narcs);
382 extern int XFillArcs (Display *, Drawable, GC, XArc *arcs, int narcs);
383 extern int XDrawRectangle (Display *, Drawable, GC, int x, int y, 
384                            unsigned int width, unsigned int height);
385 extern int XFillRectangle (Display *, Drawable, GC, int x, int y, 
386                            unsigned int width, unsigned int height);
387 extern int XFillRectangles (Display *, Drawable, GC, XRectangle *, int n);
388
389 extern int XDrawString (Display *, Drawable, GC, int x, int y, const char *,
390                         int len);
391 extern int XDrawImageString (Display *, Drawable, GC, int x, int y, 
392                              const char *, int len);
393 extern int XDrawString16 (Display *, Drawable, GC, int x, int y,
394                           const XChar2b *, int len);
395
396 extern Bool XQueryPointer (Display *, Window, Window *root_ret,
397                            Window *child_ret,
398                            int *root_x_ret, int *root_y_ret,
399                            int *win_x_ret, int *win_y_ret,
400                            unsigned int *mask_ret);
401 extern int XLookupString (XKeyEvent *, char *ret, int size, KeySym *ks_ret,
402                           XComposeStatus *);
403 extern KeySym XKeycodeToKeysym (Display *, KeyCode, int index);
404
405 extern Status XInitImage (XImage *);
406 extern XImage *XCreateImage (Display *, Visual *, unsigned int depth,
407                              int format, int offset, char *data,
408                              unsigned int width, unsigned int height,
409                              int bitmap_pad, int bytes_per_line);
410 extern XImage *XSubImage (XImage *, int x, int y, 
411                           unsigned int w, unsigned int h);
412
413 extern unsigned long XGetPixel (XImage *, int x, int y);
414 extern int XPutPixel (XImage *, int x, int y, unsigned long);
415 extern int XDestroyImage (XImage *);
416 extern XImage *XGetImage (Display *, Drawable, int x, int y,
417                           unsigned int w, unsigned int h,
418                           unsigned long pm, int fmt);
419 extern Pixmap XCreatePixmapFromBitmapData (Display *, Drawable,
420                                            const char *data,
421                                            unsigned int w, unsigned int h,
422                                            unsigned long fg,
423                                            unsigned long bg,
424                                            unsigned int depth);
425 extern XPixmapFormatValues *XListPixmapFormats (Display *, int *count_ret);
426
427 extern void jwxyz_draw_NSImage_or_CGImage (Display *, Drawable, 
428                                            Bool nsimg_p, void *NSImage_arg,
429                                            XRectangle *geom_ret, 
430                                            int exif_rotation);
431 extern XImage *jwxyz_png_to_ximage (Display *, Visual *,
432                                     const unsigned char *, unsigned long size);
433
434 extern int XSetGraphicsExposures (Display *, GC, Bool);
435 extern Bool XTranslateCoordinates (Display *, Window src_w, Window dest_w,
436                                    int src_x, int src_y,
437                                    int *dest_x_ret, int *dest_y_ret,
438                                    Window *child_ret);
439
440 extern Font XLoadFont (Display *, const char *);
441 extern XFontStruct * XQueryFont (Display *, Font);
442 extern XFontStruct * XLoadQueryFont (Display *, const char *);
443 extern int XFreeFontInfo (char **names, XFontStruct *info, int n);
444 extern int XFreeFont (Display *, XFontStruct *);
445 extern int XUnloadFont (Display *, Font);
446 extern int XTextExtents (XFontStruct *, const char *, int length,
447                          int *dir_ret, int *ascent_ret, int *descent_ret,
448                          XCharStruct *overall_ret);
449 extern char * jwxyz_unicode_character_name (Display *, Font, unsigned long uc);
450 extern int XTextExtents16 (XFontStruct *, const XChar2b *, int length,
451                            int *dir_ret, int *ascent_ret, int *descent_ret,
452                            XCharStruct *overall_ret);
453 extern int XTextWidth (XFontStruct *, const char *, int length);
454 extern int XSetFont (Display *, GC, Font);
455
456 extern XFontSet XCreateFontSet (Display *, char *name, 
457                                 char ***missing_charset_list_return,
458                                 int *missing_charset_count_return,
459                                 char **def_string_return);
460 extern void XFreeFontSet (Display *, XFontSet);
461 extern void XFreeStringList (char **);
462 extern int Xutf8TextExtents (XFontSet, const char *, int num_bytes,
463                              XRectangle *overall_ink_return,
464                              XRectangle *overall_logical_return);
465 extern void Xutf8DrawString (Display *, Drawable, XFontSet, GC,
466                              int x, int y, const char *, int num_bytes);
467
468 extern Pixmap XCreatePixmap (Display *, Drawable,
469                              unsigned int width, unsigned int height,
470                              unsigned int depth);
471 extern int XFreePixmap (Display *, Pixmap);
472
473 extern char *XGetAtomName (Display *, Atom);
474
475 extern void set_points_list(XPoint *points, int npoints, linked_point *root);
476 extern void traverse_points_list(Display *dpy, linked_point * root);
477 extern void draw_three_vertices(Display *dpy, linked_point * a,
478                                 Bool triangle);
479 extern double compute_edge_length(linked_point * a, linked_point * b);
480 extern double get_angle(double a, double b, double c);
481 extern Bool is_same_slope(linked_point * a);
482 extern Bool is_an_ear(linked_point * a);
483 extern Bool is_three_point_loop(linked_point * head);
484
485 extern int draw_arc_gl(Display *dpy, Drawable d, GC gc, int x, int y,
486                    unsigned int width, unsigned int height,
487                    int angle1, int angle2, Bool fill_p);
488
489 // Log()/Logv(), for debugging JWXYZ. Screenhacks should still use
490 // fprintf(stderr, ...).
491 extern void Log(const char *format, ...)
492 #if defined __GNUC__ || defined __clang__
493   __attribute__((format(printf, 1, 2)))
494 #endif
495   ;
496
497 extern void jwxyz_logv(Bool error, const char *fmt, va_list args);
498 #define Logv(format, args) (jwxyz_logv(False, format, args))
499
500 // Xt timers and fds
501 extern XtAppContext XtDisplayToApplicationContext (Display *);
502 typedef void (*XtTimerCallbackProc) (XtPointer closure, XtIntervalId *);
503 typedef void (*XtInputCallbackProc) (XtPointer closure, int *fd, XtInputId *);
504 extern XtIntervalId XtAppAddTimeOut (XtAppContext, unsigned long usecs,
505                                      XtTimerCallbackProc, XtPointer closure);
506 extern void XtRemoveTimeOut (XtIntervalId);
507 extern XtInputId XtAppAddInput (XtAppContext, int fd, XtPointer flags,
508                                XtInputCallbackProc, XtPointer closure);
509 extern void XtRemoveInput (XtInputId);
510 extern XtInputMask XtAppPending (XtAppContext);
511 extern void XtAppProcessEvent (XtAppContext, XtInputMask);
512
513 // Some GLX stuff that also doesn't technically belong here...
514 // from XScreenSaverGLView.m
515 extern void glXSwapBuffers (Display *, Window);
516 extern void glXMakeCurrent (Display *, Window, GLXContext);
517
518 // also declared in utils/visual.h
519 extern int has_writable_cells (Screen *, Visual *);
520 extern int visual_depth (Screen *, Visual *);
521 extern int visual_pixmap_depth (Screen *, Visual *);
522 extern int visual_cells (Screen *, Visual *);
523 extern int visual_class (Screen *, Visual *);
524 extern void visual_rgb_masks (Screen *screen, Visual *visual,
525                               unsigned long *red_mask,
526                               unsigned long *green_mask,
527                               unsigned long *blue_mask);
528 extern int screen_number (Screen *);
529
530 // also declared in utils/grabclient.h
531 extern Bool use_subwindow_mode_p (Screen *, Window);
532
533 // also declared in xlockmoreI.h
534 extern void clear_gl_error (void);
535 extern void check_gl_error (const char *type);
536
537 // A Visual is supposed to be an opaque type, even though Xlib.h defines it.
538 // Only utils/xft.c uses this, out of necessity.
539 struct jwxyz_Visual {
540   int class;            /* class of screen (monochrome, etc.) */
541   unsigned long red_mask, green_mask, blue_mask;        /* same as Xlib.h */
542   unsigned long alpha_mask;                             /* new */
543 };
544
545 struct jwxyz_XGCValues {
546   int function;         /* logical operation */
547 #if 0
548   unsigned long plane_mask;/* plane mask */
549 #endif
550   unsigned long foreground;/* foreground pixel */
551   unsigned long background;/* background pixel */
552   int line_width;       /* line width */
553 #if 0
554   int line_style;       /* LineSolid, LineOnOffDash, LineDoubleDash */
555 #endif
556   int cap_style;        /* CapNotLast, CapButt, CapRound, CapProjecting */
557   int join_style;       /* JoinMiter, JoinRound, JoinBevel */
558 #if 0
559   int fill_style;       /* FillSolid, FillTiled, 
560                            FillStippled, FillOpaeueStippled */
561 #endif
562   int fill_rule;        /* EvenOddRule, WindingRule */
563 #if 0
564   int arc_mode;         /* ArcChord, ArcPieSlice */
565   Pixmap tile;          /* tile pixmap for tiling operations */
566   Pixmap stipple;       /* stipple 1 plane pixmap for stipping */
567   int ts_x_origin;      /* offset for tile or stipple operations */
568   int ts_y_origin;
569 #endif
570   Font font;            /* default text font for text operations */
571   int subwindow_mode;     /* ClipByChildren, IncludeInferiors */
572 #if 0
573   Bool graphics_exposures;/* boolean, should exposures be generated */
574 #endif
575   int clip_x_origin;    /* origin for clipping */
576   int clip_y_origin;
577   Pixmap clip_mask;     /* bitmap clipping; other calls for rects */
578 #if 0
579   int dash_offset;      /* patterned/dashed line information */
580   char dashes;
581 #endif
582
583   Bool alpha_allowed_p; /* jwxyz extension: whether pixel values may have
584                            a non-opaque alpha component. */
585   Bool antialias_p;     /* jwxyz extension: whether Quartz should draw
586                            with antialiasing. */
587 };
588
589 struct jwxyz_XWindowAttributes {
590     int x, y;                   /* location of window */
591     int width, height;          /* width and height of window */
592     int border_width;           /* border width of window */
593     int depth;                  /* depth of window */
594     Visual *visual;             /* the associated visual structure */
595 #if 0
596     Window root;                /* root of screen containing window */
597     int class;                  /* InputOutput, InputOnly*/
598     int bit_gravity;            /* one of bit gravity values */
599     int win_gravity;            /* one of the window gravity values */
600     int backing_store;          /* NotUseful, WhenMapped, Always */
601     unsigned long backing_planes;/* planes to be preserved if possible */
602     unsigned long backing_pixel;/* value to be used when restoring planes */
603     Bool save_under;            /* boolean, should bits under be saved? */
604 #endif
605     Colormap colormap;          /* color map to be associated with window */
606 #if 0
607     Bool map_installed;         /* boolean, is color map currently installed*/
608     int map_state;              /* IsUnmapped, IsUnviewable, IsViewable */
609     long all_event_masks;       /* set of events all people have interest in*/
610     long your_event_mask;       /* my event mask */
611     long do_not_propagate_mask; /* set of events that should not propagate */
612     Bool override_redirect;     /* boolean value for override-redirect */
613 #endif
614     Screen *screen;             /* back pointer to correct screen */
615 };
616
617 struct jwxyz_XColor {
618   unsigned long pixel;
619   unsigned short red, green, blue;
620   char flags;  /* do_red, do_green, do_blue */
621   char pad;
622 };
623
624 struct jwxyz_XPoint {
625   short x, y;
626 };
627
628 struct jwxyz_XSegment {
629   short x1, y1, x2, y2;
630 };
631
632 struct jwxyz_XRectangle {
633   short x, y;
634   unsigned short width, height;
635 };
636
637 struct jwxyz_XArc {
638   short x, y;
639   unsigned short width, height;
640   short angle1, angle2;
641 };
642
643
644 struct jwxyz_XrmOptionDescRec {
645   char *option;
646   char *specifier;
647   int argKind;
648   void *value;
649 };
650
651 struct jwxyz_XAnyEvent {
652   int type;
653 #if 0
654   unsigned long serial;
655   Bool send_event;
656   Display *display;
657   Window window;
658 #endif
659 };
660
661 struct jwxyz_XKeyEvent {
662   int type;
663 #if 0
664   unsigned long serial;
665   Bool send_event;
666   Display *display;
667   Window window;
668   Window root;
669   Window subwindow;
670   Time time;
671   int x, y;
672   int x_root, y_root;
673 #endif
674   unsigned int state;
675   unsigned int keycode;
676 #if 0
677   Bool same_screen;
678 #endif
679 };
680
681 struct jwxyz_XButtonEvent {
682   int type;
683 #if 0
684   unsigned long serial;
685   Bool send_event;
686   Display *display;
687   Window window;
688   Window root;
689   Window subwindow;
690   Time time;
691 #endif
692   int x, y;
693 #if 0
694   int x_root, y_root;
695 #endif
696   unsigned int state;
697   unsigned int button;
698 #if 0
699   Bool same_screen;
700 #endif
701 };
702
703 struct jwxyz_XMotionEvent {
704   int type;
705 #if 0
706   unsigned long serial;
707   Bool send_event;
708   Display *display;
709   Window window;
710   Window root;
711   Window subwindow;
712   Time time;
713 #endif
714   int x, y;
715 #if 0
716   int x_root, y_root;
717 #endif
718   unsigned int state;
719 #if 0
720   char is_hint;
721   Bool same_screen;
722 #endif
723 };
724
725 union jwxyz_XEvent {
726   int type;
727   XAnyEvent xany;
728   XKeyEvent xkey;
729   XButtonEvent xbutton;
730   XMotionEvent xmotion;
731 };
732
733 struct jwxyz_XImage {
734     int width, height;          /* size of image */
735     int xoffset;                /* number of pixels offset in X direction */
736     int format;                 /* XYBitmap, XYPixmap, ZPixmap */
737     char *data;                 /* pointer to image data */
738     int byte_order;             /* data byte order, LSBFirst, MSBFirst */
739     int bitmap_unit;            /* quant. of scanline 8, 16, 32 */
740     int bitmap_bit_order;       /* LSBFirst, MSBFirst */
741     int bitmap_pad;             /* 8, 16, 32 either XY or ZPixmap */
742     int depth;                  /* depth of image */
743     int bytes_per_line;         /* accelarator to next line */
744     int bits_per_pixel;         /* bits per pixel (ZPixmap) */
745     unsigned long red_mask;     /* bits in z arrangment */
746     unsigned long green_mask;
747     unsigned long blue_mask;
748 //  XPointer obdata;            /* hook for the object routines to hang on */
749     struct funcs {              /* image manipulation routines */
750 #if 0
751       XImage *(*create_image)(
752                 Display*        /* display */,
753                 Visual*         /* visual */,
754                 unsigned int    /* depth */,
755                 int             /* format */,
756                 int             /* offset */,
757                 char*           /* data */,
758                 unsigned int    /* width */,
759                 unsigned int    /* height */,
760                 int             /* bitmap_pad */,
761                 int             /* bytes_per_line */);
762         int (*destroy_image)        (XImage *);
763 #endif
764         unsigned long (*get_pixel)  (XImage *, int, int);
765         int (*put_pixel)            (XImage *, int, int, unsigned long);
766 #if 0
767         XImage *(*sub_image)        (XImage *, int, int, unsigned int, unsigned int);
768         int (*add_pixel)            (XImage *, long);
769 #endif
770     } f;
771 };
772
773 struct jwxyz_XCharStruct {
774   short lbearing;       /* origin to left edge of ink */
775   short rbearing;       /* origin to right edge of ink */
776   short width;          /* advance to next char's origin */
777   short ascent;         /* baseline to top edge of ink */
778   short descent;        /* baseline to bottom edge of ink */
779 #if 0
780   unsigned short attributes;    /* per char flags (not predefined) */
781 #endif
782 };
783
784 struct jwxyz_XFontProp {
785   Atom          name;
786   unsigned long card32; /* Careful: This holds (32- or 64-bit) pointers. */
787 };
788
789 struct jwxyz_XFontStruct {
790 #if 0
791   XExtData      *ext_data;      /* hook for extension to hang data */
792 #endif
793   Font          fid;            /* Font id for this font */
794 #if 0
795   unsigned      direction;      /* hint about direction the font is painted */
796 #endif
797   unsigned      min_char_or_byte2;      /* first character */
798   unsigned      max_char_or_byte2;      /* last character */
799 #if 0
800   unsigned      min_byte1;      /* first row that exists */
801   unsigned      max_byte1;      /* last row that exists */
802   Bool  all_chars_exist;        /* flag if all characters have non-zero size*/
803 #endif
804   unsigned      default_char;   /* char to print for undefined character */
805   int         n_properties;   /* how many properties there are */
806   XFontProp     *properties;    /* pointer to array of additional properties*/
807   XCharStruct   min_bounds;     /* minimum bounds over all existing char*/
808   XCharStruct   max_bounds;     /* maximum bounds over all existing char*/
809   XCharStruct   *per_char;      /* first_char to last_char information */
810   int           ascent;         /* log. extent above baseline for spacing */
811   int           descent;        /* log. descent below baseline for spacing */
812 };
813
814 struct jwxyz_XComposeStatus {
815   char dummy;
816 };
817
818 struct  jwxyz_XPixmapFormatValues {
819   int depth;
820   int bits_per_pixel;
821   int scanline_pad;
822 };
823
824 struct jwxyz_XChar2b {
825   unsigned char byte1;
826   unsigned char byte2;
827 };
828
829
830 struct jwxyz_vtbl {
831   Window (*root) (Display *);
832   Visual *(*visual) (Display *);
833   struct jwxyz_sources_data *(*display_sources_data) (Display *);
834
835   unsigned long *(*window_background) (Display *);
836   int (*draw_arc) (Display *dpy, Drawable d, GC gc, int x, int y,
837                    unsigned int width, unsigned int height,
838                    int angle1, int angle2, Bool fill_p);
839   void (*fill_rects) (Display *dpy, Drawable d, GC gc,
840                       const XRectangle *rectangles,
841                       unsigned long nrects, unsigned long pixel);
842   XGCValues *(*gc_gcv) (GC gc);
843   unsigned int (*gc_depth) (GC gc);
844   int (*draw_string) (Display *dpy, Drawable d, GC gc, int x, int y,
845                       const char *str, size_t len, Bool utf8);
846
847   void (*copy_area) (Display *dpy, Drawable src, Drawable dst, GC gc,
848                      int src_x, int src_y,
849                      unsigned int width, unsigned int height,
850                      int dst_x, int dst_y);
851
852   int (*DrawPoints) (Display *, Drawable, GC, XPoint *, int n, int mode);
853   int (*DrawSegments) (Display *, Drawable, GC, XSegment *, int n);
854   GC (*CreateGC) (Display *, Drawable, unsigned long mask, XGCValues *);
855   int (*FreeGC) (Display *, GC);
856   int (*ClearWindow) (Display *, Window);
857   int (*SetClipMask) (Display *, GC, Pixmap);
858   int (*SetClipOrigin) (Display *, GC, int x, int y);
859   int (*FillPolygon) (Display *, Drawable, GC,
860                       XPoint * points, int npoints, int shape, int mode);
861   int (*DrawLines) (Display *, Drawable, GC, XPoint *, int n, int mode);
862
863   int (*PutImage) (Display *, Drawable, GC, XImage *,
864                     int src_x, int src_y, int dest_x, int dest_y,
865                     unsigned int w, unsigned int h);
866   XImage *(*GetSubImage) (Display *dpy, Drawable d, int x, int y,
867                           unsigned int width, unsigned int height,
868                           unsigned long plane_mask, int format,
869                           XImage *dest_image, int dest_x, int dest_y);
870 };
871
872 #define JWXYZ_VTBL(dpy) (*(struct jwxyz_vtbl **)(dpy))
873
874 #define XRootWindow(dpy, screen) \
875   ((dpy) ? JWXYZ_VTBL(dpy)->root(dpy) : 0)
876 #define XDefaultVisualOfScreen(screen) \
877   ((screen) ? JWXYZ_VTBL(screen)->visual(screen) : 0)
878
879 #define XDrawPoints(dpy, d, gc, points, n, mode) \
880   (JWXYZ_VTBL(dpy)->DrawPoints (dpy, d, gc, points, n, mode))
881 #define XDrawSegments(dpy, d, gc, segments, n) \
882   (JWXYZ_VTBL(dpy)->DrawSegments (dpy, d, gc, segments, n))
883 #define XCreateGC(dpy, d, mask, gcv) \
884   (JWXYZ_VTBL(dpy)->CreateGC (dpy, d, mask, gcv))
885 #define XFreeGC(dpy, gc) \
886   (JWXYZ_VTBL(dpy)->FreeGC (dpy, gc))
887 #define XClearWindow(dpy, win) \
888   (JWXYZ_VTBL(dpy)->ClearWindow(dpy, win))
889 #define XSetClipMask(dpy, gc, m) \
890   (JWXYZ_VTBL(dpy)->SetClipMask (dpy, gc, m))
891 #define XSetClipOrigin(dpy, gc, x, y) \
892   (JWXYZ_VTBL(dpy)->SetClipOrigin (dpy, gc, x, y))
893 #define XFillPolygon(dpy, d, gc, points, npoints, shape, mode) \
894   (JWXYZ_VTBL(dpy)->FillPolygon (dpy, d, gc, points, npoints, shape, mode))
895 #define XDrawLines(dpy, d, gc, points, n, mode) \
896   (JWXYZ_VTBL(dpy)->DrawLines (dpy, d, gc, points, n, mode))
897 #define XPutImage(dpy, d, gc, image, src_x, src_y, dest_x, dest_y, w, h) \
898   (JWXYZ_VTBL(dpy)->PutImage (dpy, d, gc, image, src_x, src_y, \
899                               dest_x, dest_y, w, h))
900 #define XGetSubImage(dpy, d, x, y, width, height, plane_mask, \
901                      format, dest_image, dest_x, dest_y) \
902   (JWXYZ_VTBL(dpy)->GetSubImage (dpy, d, x, y, width, height, plane_mask, \
903                                  format, dest_image, dest_x, dest_y))
904
905
906 #endif /* __JWXYZ_H__ */