1 /* xscreensaver, Copyright (c) 1991-2010 Jamie Zawinski <jwz@jwz.org>
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
14 But it's a bunch of function definitions that bear some resemblance to
15 Xlib and that do Cocoa-ish things that bear some resemblance to the
16 things that Xlib might have done.
24 typedef void * XPointer;
25 typedef unsigned long Time;
26 typedef unsigned int KeySym;
27 typedef unsigned int KeyCode;
28 typedef unsigned int VisualID;
30 typedef struct jwxyz_Display Display;
31 typedef struct jwxyz_Screen Screen;
32 typedef struct jwxyz_Visual Visual;
33 typedef struct jwxyz_Drawable * Drawable;
34 typedef struct jwxyz_Colormap * Colormap;
35 typedef struct jwxyz_GC * GC;
36 typedef struct jwxyz_XColor XColor;
37 typedef struct jwxyz_XGCValues XGCValues;
38 typedef struct jwxyz_XPoint XPoint;
39 typedef struct jwxyz_XSegment XSegment;
40 typedef struct jwxyz_XRectangle XRectangle;
41 typedef struct jwxyz_XArc XArc;
42 typedef struct jwxyz_XWindowAttributes XWindowAttributes;
43 typedef struct jwxyz_XrmOptionDescRec XrmOptionDescRec;
44 typedef struct jwxyz_XrmDatabase * XrmDatabase;
45 typedef struct jwxyz_XImage XImage;
46 typedef struct jwxyz_XFontStruct XFontStruct;
47 typedef struct jwxyz_Font * Font;
48 typedef struct jwxyz_XCharStruct XCharStruct;
49 typedef struct jwxyz_XComposeStatus XComposeStatus;
50 typedef struct jwxyz_XPixmapFormatValues XPixmapFormatValues;
52 typedef union jwxyz_XEvent XEvent;
53 typedef struct jwxyz_XAnyEvent XAnyEvent;
54 typedef struct jwxyz_XKeyEvent XKeyEvent;
55 typedef struct jwxyz_XMotionEvent XMotionEvent;
56 typedef struct jwxyz_XButtonEvent XButtonEvent;
57 typedef XKeyEvent XKeyPressedEvent;
58 typedef XKeyEvent XKeyReleasedEvent;
59 typedef XMotionEvent XPointerMovedEvent;
60 typedef XButtonEvent XButtonPressedEvent;
61 typedef XButtonEvent XButtonReleasedEvent;
64 /* Not technically Xlib... */
65 typedef struct jwxyz_GLXContext * GLXContext;
66 typedef struct jwxyz_XtAppContext * XtAppContext;
67 typedef struct jwxyz_XtIntervalId * XtIntervalId;
68 typedef struct jwxyz_XtInputId * XtInputId;
69 typedef void * XtPointer;
70 #define XtInputReadMask (1L<<0)
71 #define XtInputWriteMask (1L<<1)
72 #define XtInputExceptMask (1L<<2)
80 #define Window Drawable
81 #define Pixmap Drawable
83 #define XrmoptionNoArg 0
84 #define XrmoptionSepArg 1
86 #define CoordModeOrigin 0
87 #define CoordModePrevious 1
90 #define LineOnOffDash 1
91 #define LineDoubleDash 2
96 #define CapProjecting 3
104 #define FillStippled 2
105 #define FillOpaqueStippled 3
107 #define EvenOddRule 0
108 #define WindingRule 1
123 #define StaticColor 2
124 #define PseudoColor 3
126 #define DirectColor 5
132 #define DoGreen (1<<1)
133 #define DoBlue (1<<2)
135 #define GCFunction (1L<<0)
136 #define GCPlaneMask (1L<<1)
137 #define GCForeground (1L<<2)
138 #define GCBackground (1L<<3)
139 #define GCLineWidth (1L<<4)
140 #define GCLineStyle (1L<<5)
141 #define GCCapStyle (1L<<6)
142 #define GCJoinStyle (1L<<7)
143 #define GCFillStyle (1L<<8)
144 #define GCFillRule (1L<<9)
145 #define GCTile (1L<<10)
146 #define GCStipple (1L<<11)
147 #define GCTileStipXOrigin (1L<<12)
148 #define GCTileStipYOrigin (1L<<13)
149 #define GCFont (1L<<14)
150 #define GCSubwindowMode (1L<<15)
151 #define GCGraphicsExposures (1L<<16)
152 #define GCClipXOrigin (1L<<17)
153 #define GCClipYOrigin (1L<<18)
154 #define GCClipMask (1L<<19)
155 #define GCDashOffset (1L<<20)
156 #define GCDashList (1L<<21)
157 #define GCArcMode (1L<<22)
161 #define ButtonPress 4
162 #define ButtonRelease 5
163 #define MotionNotify 6
165 #define GraphicsExpose 13
167 #define VisibilityNotify 15
169 #define ClipByChildren 0
170 #define IncludeInferiors 1
172 #define KeyPressMask (1L<<0)
173 #define KeyReleaseMask (1L<<1)
174 #define ButtonPressMask (1L<<2)
175 #define ButtonReleaseMask (1L<<3)
176 #define PointerMotionMask (1L<<6)
184 #define ShiftMask (1<<0)
185 #define LockMask (1<<1)
186 #define ControlMask (1<<2)
187 #define Mod1Mask (1<<3)
188 #define Mod2Mask (1<<4)
189 #define Mod3Mask (1<<5)
190 #define Mod4Mask (1<<6)
191 #define Mod5Mask (1<<7)
192 #define Button1Mask (1<<8)
193 #define Button2Mask (1<<9)
194 #define Button3Mask (1<<10)
195 #define Button4Mask (1<<11)
196 #define Button5Mask (1<<12)
198 #define GXclear 0x0 /* 0 */
199 #define GXand 0x1 /* src AND dst */
200 // #define GXandReverse 0x2 /* src AND NOT dst */
201 #define GXcopy 0x3 /* src */
202 // #define GXandInverted 0x4 /* NOT src AND dst */
203 // #define GXnoop 0x5 /* dst */
204 #define GXxor 0x6 /* src XOR dst */
205 #define GXor 0x7 /* src OR dst */
206 // #define GXnor 0x8 /* NOT src AND NOT dst */
207 // #define GXequiv 0x9 /* NOT src XOR dst */
208 // #define GXinvert 0xa /* NOT dst */
209 // #define GXorReverse 0xb /* src OR NOT dst */
210 // #define GXcopyInverted 0xc /* NOT src */
211 // #define GXorInverted 0xd /* NOT src OR dst */
212 // #define GXnand 0xe /* NOT src OR NOT dst */
213 #define GXset 0xf /* 1 */
215 #define DefaultScreen(dpy) (0)
216 #define BlackPixelOfScreen(s) (0xFF000000)
217 #define WhitePixelOfScreen(s) (0xFFFFFFFF)
218 #define BlackPixel(dpy,n) BlackPixelOfScreen(0)
219 #define WhitePixel(dpy,n) WhitePixelOfScreen(0)
220 #define CellsOfScreen(s) (0x00FFFFFF)
221 #define XFree(x) free(x)
222 #define BitmapPad(dpy) (8)
223 #define BitmapBitOrder(dpy) (MSBFirst)
224 #define ImageByteOrder(dpy) (MSBFirst)
225 #define DisplayOfScreen XDisplayOfScreen
226 #define DefaultScreenOfDisplay XDefaultScreenOfDisplay
227 #define ScreenOfDisplay(dpy,n) DefaultScreenOfDisplay(dpy)
228 #define DefaultVisualOfScreen XDefaultVisualOfScreen
229 #define DefaultColormapOfScreen(s) (0)
230 #define RootWindow XRootWindow
231 #define RootWindowOfScreen(s) RootWindow(DisplayOfScreen(s),0)
232 #define DisplayWidth XDisplayWidth
233 #define DisplayHeight XDisplayHeight
234 #define XMaxRequestSize(dpy) (65535)
236 extern Display *jwxyz_make_display (void *nsview);
237 extern void jwxyz_free_display (Display *);
238 extern void *jwxyz_window_view (Window);
239 extern void jwxyz_window_resized (Display *, Window w);
241 extern Window XRootWindow (Display *, int screen);
242 extern Screen *XDefaultScreenOfDisplay (Display *);
243 extern Visual *XDefaultVisualOfScreen (Screen *);
244 extern Display *XDisplayOfScreen (Screen *);
245 extern int XDisplayNumberOfScreen (Screen *);
246 extern int XScreenNumberOfScreen (Screen *);
247 extern int XDisplayWidth (Display *, int);
248 extern int XDisplayHeight (Display *, int);
250 extern int XDrawPoint (Display *, Drawable, GC, int x, int y);
251 extern int XDrawPoints (Display *, Drawable, GC, XPoint *, int n, int mode);
252 extern int XDrawSegments (Display *, Drawable, GC, XSegment *, int n);
254 extern GC XCreateGC (Display *, Drawable, unsigned long mask, XGCValues *);
255 extern int XChangeGC (Display *, GC, unsigned long mask, XGCValues *);
256 extern int XFreeGC (Display *, GC);
258 extern int XClearWindow (Display *, Window);
259 extern int XClearArea (Display *, Window, int x, int y, int w, int h,Bool exp);
260 extern int XSetWindowBackground (Display *, Window, unsigned long);
261 extern Status XGetWindowAttributes (Display *, Window, XWindowAttributes *);
262 extern Status XGetGeometry (Display *, Drawable, Window *root_ret,
263 int *x_ret, int *y_ret,
264 unsigned int *w_ret, unsigned int *h_ret,
265 unsigned int *bw_ret, unsigned int *depth_ret);
266 extern Status XAllocColor (Display *, Colormap, XColor *);
267 extern Status XAllocColorCells (Display *, Colormap, Bool contig,
268 unsigned long *pmret, unsigned int npl,
269 unsigned long *pxret, unsigned int npx);
270 extern int XStoreColors (Display *, Colormap, XColor *, int n);
271 extern int XStoreColor (Display *, Colormap, XColor *);
272 extern Status XParseColor(Display *, Colormap, const char *spec, XColor *ret);
273 extern Status XAllocNamedColor (Display *, Colormap, char *name,
274 XColor *screen_ret, XColor *exact_ret);
275 extern int XQueryColor (Display *, Colormap, XColor *);
276 extern int XQueryColors(Display *, Colormap colormap, XColor *, int ncolors);
278 extern int XSetForeground (Display *, GC, unsigned long);
279 extern int XSetBackground (Display *, GC, unsigned long);
280 extern int XSetFunction (Display *, GC, int);
281 extern int XSetSubwindowMode (Display *, GC, int);
282 extern int XSetLineAttributes (Display *, GC, unsigned int line_width,
283 int line_style, int cap_style, int join_style);
284 extern int XSetClipMask (Display *, GC, Pixmap);
285 extern int XSetClipOrigin (Display *, GC, int x, int y);
286 extern int jwxyz_XSetAlphaAllowed (Display *, GC, Bool);
287 extern int jwxyz_XSetAntiAliasing (Display *, GC, Bool);
289 extern int XFlush (Display *);
290 extern int XSync (Display *, Bool);
291 extern int XFreeColors (Display *, Colormap, unsigned long *px, int n,
292 unsigned long planes);
293 extern int XFillPolygon (Display *, Drawable, GC,
294 XPoint * points, int npoints, int shape, int mode);
295 extern int XCopyArea (Display *, Drawable src, Drawable dest, GC,
296 int src_x, int src_y,
297 unsigned int width, unsigned int height,
298 int dest_x, int dest_y);
299 extern int XCopyPlane (Display *, Drawable, Drawable, GC,
300 int src_x, int src_y,
301 unsigned width, int height,
302 int dest_x, int dest_y,
303 unsigned long plane);
305 extern int XDrawLine (Display *, Drawable, GC, int x1, int y1, int x2, int y2);
306 extern int XDrawLines (Display *, Drawable, GC, XPoint *, int n, int mode);
307 extern int XDrawArc (Display *, Drawable, GC, int x, int y,
308 unsigned int width, unsigned int height,
309 int angle1, int angle2);
310 extern int XFillArc (Display *, Drawable, GC, int x, int y,
311 unsigned int width, unsigned int height,
312 int angle1, int angle2);
313 extern int XDrawArcs (Display *, Drawable, GC, XArc *arcs, int narcs);
314 extern int XFillArcs (Display *, Drawable, GC, XArc *arcs, int narcs);
315 extern int XDrawRectangle (Display *, Drawable, GC, int x, int y,
316 unsigned int width, unsigned int height);
317 extern int XFillRectangle (Display *, Drawable, GC, int x, int y,
318 unsigned int width, unsigned int height);
319 extern int XFillRectangles (Display *, Drawable, GC, XRectangle *, int n);
321 extern int XDrawString (Display *, Drawable, GC, int x, int y, const char *,
323 extern int XDrawImageString (Display *, Drawable, GC, int x, int y,
324 const char *, int len);
326 extern Bool XQueryPointer (Display *, Window, Window *root_ret,
328 int *root_x_ret, int *root_y_ret,
329 int *win_x_ret, int *win_y_ret,
330 unsigned int *mask_ret);
331 extern int XLookupString (XKeyEvent *, char *ret, int size, KeySym *ks_ret,
333 extern KeySym XKeycodeToKeysym (Display *, KeyCode, int index);
335 extern Status XInitImage (XImage *);
336 extern XImage *XCreateImage (Display *, Visual *, unsigned int depth,
337 int format, int offset, char *data,
338 unsigned int width, unsigned int height,
339 int bitmap_pad, int bytes_per_line);
340 extern XImage *XSubImage (XImage *, int x, int y,
341 unsigned int w, unsigned int h);
343 extern unsigned long XGetPixel (XImage *, int x, int y);
344 extern int XPutPixel (XImage *, int x, int y, unsigned long);
345 extern int XDestroyImage (XImage *);
346 extern int XPutImage (Display *, Drawable, GC, XImage *,
347 int src_x, int src_y, int dest_x, int dest_y,
348 unsigned int w, unsigned int h);
349 extern XImage *XGetImage (Display *, Drawable, int x, int y,
350 unsigned int w, unsigned int h,
351 unsigned long pm, int fmt);
352 extern Pixmap XCreatePixmapFromBitmapData (Display *, Drawable,
354 unsigned int w, unsigned int h,
358 extern XPixmapFormatValues *XListPixmapFormats (Display *, int *count_ret);
360 extern void jwxyz_draw_NSImage_or_CGImage (Display *, Drawable,
361 Bool nsimg_p, void *NSImage_arg,
362 XRectangle *geom_ret,
365 extern int XSetGraphicsExposures (Display *, GC, Bool);
366 extern Bool XTranslateCoordinates (Display *, Window src_w, Window dest_w,
367 int src_x, int src_y,
368 int *dest_x_ret, int *dest_y_ret,
371 extern Font XLoadFont (Display *, const char *);
372 extern XFontStruct * XQueryFont (Display *, Font);
373 extern XFontStruct * XLoadQueryFont (Display *, const char *);
374 extern int XFreeFontInfo (char **names, XFontStruct *info, int n);
375 extern int XFreeFont (Display *, XFontStruct *);
376 extern int XUnloadFont (Display *, Font);
377 extern int XTextExtents (XFontStruct *, const char *, int length,
378 int *dir_ret, int *ascent_ret, int *descent_ret,
379 XCharStruct *overall_ret);
380 extern int XTextWidth (XFontStruct *, const char *, int length);
381 extern int XSetFont (Display *, GC, Font);
383 extern Pixmap XCreatePixmap (Display *, Drawable,
384 unsigned int width, unsigned int height,
386 extern int XFreePixmap (Display *, Pixmap);
389 extern XtAppContext XtDisplayToApplicationContext (Display *);
390 typedef void (*XtTimerCallbackProc) (XtPointer closure, XtIntervalId *);
391 typedef void (*XtInputCallbackProc) (XtPointer closure, int *fd, XtInputId *);
392 extern XtIntervalId XtAppAddTimeOut (XtAppContext, unsigned long usecs,
393 XtTimerCallbackProc, XtPointer closure);
394 extern void XtRemoveTimeOut (XtIntervalId);
395 extern XtInputId XtAppAddInput (XtAppContext, int fd, XtPointer flags,
396 XtInputCallbackProc, XtPointer closure);
397 extern void XtRemoveInput (XtInputId);
398 extern struct jwxyz_sources_data *display_sources_data (Display *);
400 // Some GLX stuff that also doesn't technically belong here...
401 // from XScreenSaverGLView.m
402 extern void glXSwapBuffers (Display *, Window);
403 extern void glXMakeCurrent (Display *, Window, GLXContext);
405 // also declared in utils/visual.h
406 extern int has_writable_cells (Screen *, Visual *);
407 extern int visual_depth (Screen *, Visual *);
408 extern int visual_cells (Screen *, Visual *);
409 extern int visual_class (Screen *, Visual *);
411 // also declared in utils/grabclient.h
412 extern Bool use_subwindow_mode_p (Screen *, Window);
414 struct jwxyz_Visual {
415 VisualID visualid; /* visual id of this visual */
416 int class; /* class of screen (monochrome, etc.) */
417 unsigned long red_mask, green_mask, blue_mask; /* mask values */
418 int bits_per_rgb; /* log base 2 of distinct color values */
419 // int map_entries; /* color map entries */
422 struct jwxyz_XGCValues {
423 int function; /* logical operation */
425 unsigned long plane_mask;/* plane mask */
427 unsigned long foreground;/* foreground pixel */
428 unsigned long background;/* background pixel */
429 int line_width; /* line width */
431 int line_style; /* LineSolid, LineOnOffDash, LineDoubleDash */
433 int cap_style; /* CapNotLast, CapButt, CapRound, CapProjecting */
434 int join_style; /* JoinMiter, JoinRound, JoinBevel */
436 int fill_style; /* FillSolid, FillTiled,
437 FillStippled, FillOpaeueStippled */
439 int fill_rule; /* EvenOddRule, WindingRule */
441 int arc_mode; /* ArcChord, ArcPieSlice */
442 Pixmap tile; /* tile pixmap for tiling operations */
443 Pixmap stipple; /* stipple 1 plane pixmap for stipping */
444 int ts_x_origin; /* offset for tile or stipple operations */
447 Font font; /* default text font for text operations */
448 int subwindow_mode; /* ClipByChildren, IncludeInferiors */
450 Bool graphics_exposures;/* boolean, should exposures be generated */
452 int clip_x_origin; /* origin for clipping */
454 Pixmap clip_mask; /* bitmap clipping; other calls for rects */
456 int dash_offset; /* patterned/dashed line information */
460 Bool alpha_allowed_p; /* jwxyz extension: whether pixel values may have
461 a non-opaque alpha component. */
462 Bool antialias_p; /* jwxyz extension: whether Quartz should draw
463 with antialiasing. */
466 struct jwxyz_XWindowAttributes {
467 int x, y; /* location of window */
468 int width, height; /* width and height of window */
469 int border_width; /* border width of window */
470 int depth; /* depth of window */
471 Visual *visual; /* the associated visual structure */
473 Window root; /* root of screen containing window */
474 int class; /* InputOutput, InputOnly*/
475 int bit_gravity; /* one of bit gravity values */
476 int win_gravity; /* one of the window gravity values */
477 int backing_store; /* NotUseful, WhenMapped, Always */
478 unsigned long backing_planes;/* planes to be preserved if possible */
479 unsigned long backing_pixel;/* value to be used when restoring planes */
480 Bool save_under; /* boolean, should bits under be saved? */
482 Colormap colormap; /* color map to be associated with window */
484 Bool map_installed; /* boolean, is color map currently installed*/
485 int map_state; /* IsUnmapped, IsUnviewable, IsViewable */
486 long all_event_masks; /* set of events all people have interest in*/
487 long your_event_mask; /* my event mask */
488 long do_not_propagate_mask; /* set of events that should not propagate */
489 Bool override_redirect; /* boolean value for override-redirect */
491 Screen *screen; /* back pointer to correct screen */
494 struct jwxyz_XColor {
496 unsigned short red, green, blue;
497 char flags; /* do_red, do_green, do_blue */
501 struct jwxyz_XPoint {
505 struct jwxyz_XSegment {
506 short x1, y1, x2, y2;
509 struct jwxyz_XRectangle {
511 unsigned short width, height;
516 unsigned short width, height;
517 short angle1, angle2;
521 struct jwxyz_XrmOptionDescRec {
528 struct jwxyz_XAnyEvent {
531 unsigned long serial;
538 struct jwxyz_XKeyEvent {
541 unsigned long serial;
552 unsigned int keycode;
558 struct jwxyz_XButtonEvent {
561 unsigned long serial;
580 struct jwxyz_XMotionEvent {
583 unsigned long serial;
606 XButtonEvent xbutton;
607 XMotionEvent xmotion;
610 struct jwxyz_XImage {
611 int width, height; /* size of image */
612 int xoffset; /* number of pixels offset in X direction */
613 int format; /* XYBitmap, XYPixmap, ZPixmap */
614 char *data; /* pointer to image data */
615 int byte_order; /* data byte order, LSBFirst, MSBFirst */
616 int bitmap_unit; /* quant. of scanline 8, 16, 32 */
617 int bitmap_bit_order; /* LSBFirst, MSBFirst */
618 int bitmap_pad; /* 8, 16, 32 either XY or ZPixmap */
619 int depth; /* depth of image */
620 int bytes_per_line; /* accelarator to next line */
621 int bits_per_pixel; /* bits per pixel (ZPixmap) */
622 unsigned long red_mask; /* bits in z arrangment */
623 unsigned long green_mask;
624 unsigned long blue_mask;
625 // XPointer obdata; /* hook for the object routines to hang on */
626 struct funcs { /* image manipulation routines */
628 XImage *(*create_image)(
629 Display* /* display */,
630 Visual* /* visual */,
631 unsigned int /* depth */,
635 unsigned int /* width */,
636 unsigned int /* height */,
637 int /* bitmap_pad */,
638 int /* bytes_per_line */);
639 int (*destroy_image) (XImage *);
641 unsigned long (*get_pixel) (XImage *, int, int);
642 int (*put_pixel) (XImage *, int, int, unsigned long);
644 XImage *(*sub_image) (XImage *, int, int, unsigned int, unsigned int);
645 int (*add_pixel) (XImage *, long);
650 struct jwxyz_XCharStruct {
651 short lbearing; /* origin to left edge of raster */
652 short rbearing; /* origin to right edge of raster */
653 short width; /* advance to next char's origin */
654 short ascent; /* baseline to top edge of raster */
655 short descent; /* baseline to bottom edge of raster */
657 unsigned short attributes; /* per char flags (not predefined) */
661 struct jwxyz_XFontStruct {
663 XExtData *ext_data; /* hook for extension to hang data */
665 Font fid; /* Font id for this font */
667 unsigned direction; /* hint about direction the font is painted */
669 unsigned min_char_or_byte2; /* first character */
670 unsigned max_char_or_byte2; /* last character */
672 unsigned min_byte1; /* first row that exists */
673 unsigned max_byte1; /* last row that exists */
674 Bool all_chars_exist; /* flag if all characters have non-zero size*/
676 unsigned default_char; /* char to print for undefined character */
678 int n_properties; /* how many properties there are */
679 XFontProp *properties; /* pointer to array of additional properties*/
681 XCharStruct min_bounds; /* minimum bounds over all existing char*/
682 XCharStruct max_bounds; /* maximum bounds over all existing char*/
683 XCharStruct *per_char; /* first_char to last_char information */
684 int ascent; /* log. extent above baseline for spacing */
685 int descent; /* log. descent below baseline for spacing */
688 struct jwxyz_XComposeStatus {
692 struct jwxyz_XPixmapFormatValues {
698 #endif /* __JWXYZ_H__ */