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