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