From http://www.jwz.org/xscreensaver/xscreensaver-5.39.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(linked_point * root);
477 extern void draw_three_vertices(linked_point * a, Bool triangle);
478 extern double compute_edge_length(linked_point * a, linked_point * b);
479 extern double get_angle(double a, double b, double c);
480 extern Bool is_same_slope(linked_point * a);
481 extern Bool is_an_ear(linked_point * a);
482 extern Bool is_three_point_loop(linked_point * head);
483
484 extern int draw_arc_gl(Display *dpy, Drawable d, GC gc, int x, int y,
485                    unsigned int width, unsigned int height,
486                    int angle1, int angle2, Bool fill_p);
487
488 // Log()/Logv(), for debugging JWXYZ. Screenhacks should still use
489 // fprintf(stderr, ...).
490 extern void Log(const char *format, ...)
491 #if defined __GNUC__ || defined __clang__
492   __attribute__((format(printf, 1, 2)))
493 #endif
494   ;
495
496 extern void jwxyz_logv(Bool error, const char *fmt, va_list args);
497 #define Logv(format, args) (jwxyz_logv(False, format, args))
498
499 // Xt timers and fds
500 extern XtAppContext XtDisplayToApplicationContext (Display *);
501 typedef void (*XtTimerCallbackProc) (XtPointer closure, XtIntervalId *);
502 typedef void (*XtInputCallbackProc) (XtPointer closure, int *fd, XtInputId *);
503 extern XtIntervalId XtAppAddTimeOut (XtAppContext, unsigned long usecs,
504                                      XtTimerCallbackProc, XtPointer closure);
505 extern void XtRemoveTimeOut (XtIntervalId);
506 extern XtInputId XtAppAddInput (XtAppContext, int fd, XtPointer flags,
507                                XtInputCallbackProc, XtPointer closure);
508 extern void XtRemoveInput (XtInputId);
509 extern XtInputMask XtAppPending (XtAppContext);
510 extern void XtAppProcessEvent (XtAppContext, XtInputMask);
511
512 // Some GLX stuff that also doesn't technically belong here...
513 // from XScreenSaverGLView.m
514 extern void glXSwapBuffers (Display *, Window);
515 extern void glXMakeCurrent (Display *, Window, GLXContext);
516
517 // also declared in utils/visual.h
518 extern int has_writable_cells (Screen *, Visual *);
519 extern int visual_depth (Screen *, Visual *);
520 extern int visual_pixmap_depth (Screen *, Visual *);
521 extern int visual_cells (Screen *, Visual *);
522 extern int visual_class (Screen *, Visual *);
523 extern void visual_rgb_masks (Screen *screen, Visual *visual,
524                               unsigned long *red_mask,
525                               unsigned long *green_mask,
526                               unsigned long *blue_mask);
527 extern int screen_number (Screen *);
528
529 // also declared in utils/grabclient.h
530 extern Bool use_subwindow_mode_p (Screen *, Window);
531
532 // also declared in xlockmoreI.h
533 extern void clear_gl_error (void);
534 extern void check_gl_error (const char *type);
535
536 // A Visual is supposed to be an opaque type, even though Xlib.h defines it.
537 // Only utils/xft.c uses this, out of necessity.
538 struct jwxyz_Visual {
539   int class;            /* class of screen (monochrome, etc.) */
540   unsigned long rgba_masks[4];  /* mask values */
541 };
542
543 struct jwxyz_XGCValues {
544   int function;         /* logical operation */
545 #if 0
546   unsigned long plane_mask;/* plane mask */
547 #endif
548   unsigned long foreground;/* foreground pixel */
549   unsigned long background;/* background pixel */
550   int line_width;       /* line width */
551 #if 0
552   int line_style;       /* LineSolid, LineOnOffDash, LineDoubleDash */
553 #endif
554   int cap_style;        /* CapNotLast, CapButt, CapRound, CapProjecting */
555   int join_style;       /* JoinMiter, JoinRound, JoinBevel */
556 #if 0
557   int fill_style;       /* FillSolid, FillTiled, 
558                            FillStippled, FillOpaeueStippled */
559 #endif
560   int fill_rule;        /* EvenOddRule, WindingRule */
561 #if 0
562   int arc_mode;         /* ArcChord, ArcPieSlice */
563   Pixmap tile;          /* tile pixmap for tiling operations */
564   Pixmap stipple;       /* stipple 1 plane pixmap for stipping */
565   int ts_x_origin;      /* offset for tile or stipple operations */
566   int ts_y_origin;
567 #endif
568   Font font;            /* default text font for text operations */
569   int subwindow_mode;     /* ClipByChildren, IncludeInferiors */
570 #if 0
571   Bool graphics_exposures;/* boolean, should exposures be generated */
572 #endif
573   int clip_x_origin;    /* origin for clipping */
574   int clip_y_origin;
575   Pixmap clip_mask;     /* bitmap clipping; other calls for rects */
576 #if 0
577   int dash_offset;      /* patterned/dashed line information */
578   char dashes;
579 #endif
580
581   Bool alpha_allowed_p; /* jwxyz extension: whether pixel values may have
582                            a non-opaque alpha component. */
583   Bool antialias_p;     /* jwxyz extension: whether Quartz should draw
584                            with antialiasing. */
585 };
586
587 struct jwxyz_XWindowAttributes {
588     int x, y;                   /* location of window */
589     int width, height;          /* width and height of window */
590     int border_width;           /* border width of window */
591     int depth;                  /* depth of window */
592     Visual *visual;             /* the associated visual structure */
593 #if 0
594     Window root;                /* root of screen containing window */
595     int class;                  /* InputOutput, InputOnly*/
596     int bit_gravity;            /* one of bit gravity values */
597     int win_gravity;            /* one of the window gravity values */
598     int backing_store;          /* NotUseful, WhenMapped, Always */
599     unsigned long backing_planes;/* planes to be preserved if possible */
600     unsigned long backing_pixel;/* value to be used when restoring planes */
601     Bool save_under;            /* boolean, should bits under be saved? */
602 #endif
603     Colormap colormap;          /* color map to be associated with window */
604 #if 0
605     Bool map_installed;         /* boolean, is color map currently installed*/
606     int map_state;              /* IsUnmapped, IsUnviewable, IsViewable */
607     long all_event_masks;       /* set of events all people have interest in*/
608     long your_event_mask;       /* my event mask */
609     long do_not_propagate_mask; /* set of events that should not propagate */
610     Bool override_redirect;     /* boolean value for override-redirect */
611 #endif
612     Screen *screen;             /* back pointer to correct screen */
613 };
614
615 struct jwxyz_XColor {
616   unsigned long pixel;
617   unsigned short red, green, blue;
618   char flags;  /* do_red, do_green, do_blue */
619   char pad;
620 };
621
622 struct jwxyz_XPoint {
623   short x, y;
624 };
625
626 struct jwxyz_XSegment {
627   short x1, y1, x2, y2;
628 };
629
630 struct jwxyz_XRectangle {
631   short x, y;
632   unsigned short width, height;
633 };
634
635 struct jwxyz_XArc {
636   short x, y;
637   unsigned short width, height;
638   short angle1, angle2;
639 };
640
641
642 struct jwxyz_XrmOptionDescRec {
643   char *option;
644   char *specifier;
645   int argKind;
646   void *value;
647 };
648
649 struct jwxyz_XAnyEvent {
650   int type;
651 #if 0
652   unsigned long serial;
653   Bool send_event;
654   Display *display;
655   Window window;
656 #endif
657 };
658
659 struct jwxyz_XKeyEvent {
660   int type;
661 #if 0
662   unsigned long serial;
663   Bool send_event;
664   Display *display;
665   Window window;
666   Window root;
667   Window subwindow;
668   Time time;
669   int x, y;
670   int x_root, y_root;
671 #endif
672   unsigned int state;
673   unsigned int keycode;
674 #if 0
675   Bool same_screen;
676 #endif
677 };
678
679 struct jwxyz_XButtonEvent {
680   int type;
681 #if 0
682   unsigned long serial;
683   Bool send_event;
684   Display *display;
685   Window window;
686   Window root;
687   Window subwindow;
688   Time time;
689 #endif
690   int x, y;
691 #if 0
692   int x_root, y_root;
693 #endif
694   unsigned int state;
695   unsigned int button;
696 #if 0
697   Bool same_screen;
698 #endif
699 };
700
701 struct jwxyz_XMotionEvent {
702   int type;
703 #if 0
704   unsigned long serial;
705   Bool send_event;
706   Display *display;
707   Window window;
708   Window root;
709   Window subwindow;
710   Time time;
711 #endif
712   int x, y;
713 #if 0
714   int x_root, y_root;
715 #endif
716   unsigned int state;
717 #if 0
718   char is_hint;
719   Bool same_screen;
720 #endif
721 };
722
723 union jwxyz_XEvent {
724   int type;
725   XAnyEvent xany;
726   XKeyEvent xkey;
727   XButtonEvent xbutton;
728   XMotionEvent xmotion;
729 };
730
731 struct jwxyz_XImage {
732     int width, height;          /* size of image */
733     int xoffset;                /* number of pixels offset in X direction */
734     int format;                 /* XYBitmap, XYPixmap, ZPixmap */
735     char *data;                 /* pointer to image data */
736     int byte_order;             /* data byte order, LSBFirst, MSBFirst */
737     int bitmap_unit;            /* quant. of scanline 8, 16, 32 */
738     int bitmap_bit_order;       /* LSBFirst, MSBFirst */
739     int bitmap_pad;             /* 8, 16, 32 either XY or ZPixmap */
740     int depth;                  /* depth of image */
741     int bytes_per_line;         /* accelarator to next line */
742     int bits_per_pixel;         /* bits per pixel (ZPixmap) */
743     unsigned long red_mask;     /* bits in z arrangment */
744     unsigned long green_mask;
745     unsigned long blue_mask;
746 //  XPointer obdata;            /* hook for the object routines to hang on */
747     struct funcs {              /* image manipulation routines */
748 #if 0
749       XImage *(*create_image)(
750                 Display*        /* display */,
751                 Visual*         /* visual */,
752                 unsigned int    /* depth */,
753                 int             /* format */,
754                 int             /* offset */,
755                 char*           /* data */,
756                 unsigned int    /* width */,
757                 unsigned int    /* height */,
758                 int             /* bitmap_pad */,
759                 int             /* bytes_per_line */);
760         int (*destroy_image)        (XImage *);
761 #endif
762         unsigned long (*get_pixel)  (XImage *, int, int);
763         int (*put_pixel)            (XImage *, int, int, unsigned long);
764 #if 0
765         XImage *(*sub_image)        (XImage *, int, int, unsigned int, unsigned int);
766         int (*add_pixel)            (XImage *, long);
767 #endif
768     } f;
769 };
770
771 struct jwxyz_XCharStruct {
772   short lbearing;       /* origin to left edge of ink */
773   short rbearing;       /* origin to right edge of ink */
774   short width;          /* advance to next char's origin */
775   short ascent;         /* baseline to top edge of ink */
776   short descent;        /* baseline to bottom edge of ink */
777 #if 0
778   unsigned short attributes;    /* per char flags (not predefined) */
779 #endif
780 };
781
782 struct jwxyz_XFontProp {
783   Atom          name;
784   unsigned long card32; /* Careful: This holds (32- or 64-bit) pointers. */
785 };
786
787 struct jwxyz_XFontStruct {
788 #if 0
789   XExtData      *ext_data;      /* hook for extension to hang data */
790 #endif
791   Font          fid;            /* Font id for this font */
792 #if 0
793   unsigned      direction;      /* hint about direction the font is painted */
794 #endif
795   unsigned      min_char_or_byte2;      /* first character */
796   unsigned      max_char_or_byte2;      /* last character */
797 #if 0
798   unsigned      min_byte1;      /* first row that exists */
799   unsigned      max_byte1;      /* last row that exists */
800   Bool  all_chars_exist;        /* flag if all characters have non-zero size*/
801 #endif
802   unsigned      default_char;   /* char to print for undefined character */
803   int         n_properties;   /* how many properties there are */
804   XFontProp     *properties;    /* pointer to array of additional properties*/
805   XCharStruct   min_bounds;     /* minimum bounds over all existing char*/
806   XCharStruct   max_bounds;     /* maximum bounds over all existing char*/
807   XCharStruct   *per_char;      /* first_char to last_char information */
808   int           ascent;         /* log. extent above baseline for spacing */
809   int           descent;        /* log. descent below baseline for spacing */
810 };
811
812 struct jwxyz_XComposeStatus {
813   char dummy;
814 };
815
816 struct  jwxyz_XPixmapFormatValues {
817   int depth;
818   int bits_per_pixel;
819   int scanline_pad;
820 };
821
822 struct jwxyz_XChar2b {
823   unsigned char byte1;
824   unsigned char byte2;
825 };
826
827
828 struct jwxyz_vtbl {
829   Window (*root) (Display *);
830   Visual *(*visual) (Display *);
831   struct jwxyz_sources_data *(*display_sources_data) (Display *);
832
833   unsigned long *(*window_background) (Display *);
834   int (*draw_arc) (Display *dpy, Drawable d, GC gc, int x, int y,
835                    unsigned int width, unsigned int height,
836                    int angle1, int angle2, Bool fill_p);
837   void (*fill_rects) (Display *dpy, Drawable d, GC gc,
838                       const XRectangle *rectangles,
839                       unsigned long nrects, unsigned long pixel);
840   XGCValues *(*gc_gcv) (GC gc);
841   unsigned int (*gc_depth) (GC gc);
842   int (*draw_string) (Display *dpy, Drawable d, GC gc, int x, int y,
843                       const char *str, size_t len, Bool utf8);
844
845   void (*copy_area) (Display *dpy, Drawable src, Drawable dst, GC gc,
846                      int src_x, int src_y,
847                      unsigned int width, unsigned int height,
848                      int dst_x, int dst_y);
849
850   int (*DrawPoints) (Display *, Drawable, GC, XPoint *, int n, int mode);
851   int (*DrawSegments) (Display *, Drawable, GC, XSegment *, int n);
852   GC (*CreateGC) (Display *, Drawable, unsigned long mask, XGCValues *);
853   int (*FreeGC) (Display *, GC);
854   int (*ClearWindow) (Display *, Window);
855   int (*SetClipMask) (Display *, GC, Pixmap);
856   int (*SetClipOrigin) (Display *, GC, int x, int y);
857   int (*FillPolygon) (Display *, Drawable, GC,
858                       XPoint * points, int npoints, int shape, int mode);
859   int (*DrawLines) (Display *, Drawable, GC, XPoint *, int n, int mode);
860
861   int (*PutImage) (Display *, Drawable, GC, XImage *,
862                     int src_x, int src_y, int dest_x, int dest_y,
863                     unsigned int w, unsigned int h);
864   XImage *(*GetSubImage) (Display *dpy, Drawable d, int x, int y,
865                           unsigned int width, unsigned int height,
866                           unsigned long plane_mask, int format,
867                           XImage *dest_image, int dest_x, int dest_y);
868 };
869
870 #define JWXYZ_VTBL(dpy) (*(struct jwxyz_vtbl **)(dpy))
871
872 #define XRootWindow(dpy, screen) \
873   ((dpy) ? JWXYZ_VTBL(dpy)->root(dpy) : 0)
874 #define XDefaultVisualOfScreen(screen) \
875   ((screen) ? JWXYZ_VTBL(screen)->visual(screen) : 0)
876
877 #define XDrawPoints(dpy, d, gc, points, n, mode) \
878   (JWXYZ_VTBL(dpy)->DrawPoints (dpy, d, gc, points, n, mode))
879 #define XDrawSegments(dpy, d, gc, segments, n) \
880   (JWXYZ_VTBL(dpy)->DrawSegments (dpy, d, gc, segments, n))
881 #define XCreateGC(dpy, d, mask, gcv) \
882   (JWXYZ_VTBL(dpy)->CreateGC (dpy, d, mask, gcv))
883 #define XFreeGC(dpy, gc) \
884   (JWXYZ_VTBL(dpy)->FreeGC (dpy, gc))
885 #define XClearWindow(dpy, win) \
886   (JWXYZ_VTBL(dpy)->ClearWindow(dpy, win))
887 #define XSetClipMask(dpy, gc, m) \
888   (JWXYZ_VTBL(dpy)->SetClipMask (dpy, gc, m))
889 #define XSetClipOrigin(dpy, gc, x, y) \
890   (JWXYZ_VTBL(dpy)->SetClipOrigin (dpy, gc, x, y))
891 #define XFillPolygon(dpy, d, gc, points, npoints, shape, mode) \
892   (JWXYZ_VTBL(dpy)->FillPolygon (dpy, d, gc, points, npoints, shape, mode))
893 #define XDrawLines(dpy, d, gc, points, n, mode) \
894   (JWXYZ_VTBL(dpy)->DrawLines (dpy, d, gc, points, n, mode))
895 #define XPutImage(dpy, d, gc, image, src_x, src_y, dest_x, dest_y, w, h) \
896   (JWXYZ_VTBL(dpy)->PutImage (dpy, d, gc, image, src_x, src_y, \
897                               dest_x, dest_y, w, h))
898 #define XGetSubImage(dpy, d, x, y, width, height, plane_mask, \
899                      format, dest_image, dest_x, dest_y) \
900   (JWXYZ_VTBL(dpy)->GetSubImage (dpy, d, x, y, width, height, plane_mask, \
901                                  format, dest_image, dest_x, dest_y))
902
903
904 #endif /* __JWXYZ_H__ */