1 /* xscreensaver, Copyright (c) 1991-2008 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 (Display *, Drawable, void *NSImage_arg,
361 XRectangle *geom_ret, int exif_rotation);
363 extern int XSetGraphicsExposures (Display *, GC, Bool);
364 extern Bool XTranslateCoordinates (Display *, Window src_w, Window dest_w,
365 int src_x, int src_y,
366 int *dest_x_ret, int *dest_y_ret,
369 extern Font XLoadFont (Display *, const char *);
370 extern XFontStruct * XQueryFont (Display *, Font);
371 extern XFontStruct * XLoadQueryFont (Display *, const char *);
372 extern int XFreeFontInfo (char **names, XFontStruct *info, int n);
373 extern int XFreeFont (Display *, XFontStruct *);
374 extern int XUnloadFont (Display *, Font);
375 extern int XTextExtents (XFontStruct *, const char *, int length,
376 int *dir_ret, int *ascent_ret, int *descent_ret,
377 XCharStruct *overall_ret);
378 extern int XTextWidth (XFontStruct *, const char *, int length);
379 extern int XSetFont (Display *, GC, Font);
381 extern Pixmap XCreatePixmap (Display *, Drawable,
382 unsigned int width, unsigned int height,
384 extern int XFreePixmap (Display *, Pixmap);
387 extern XtAppContext XtDisplayToApplicationContext (Display *);
388 typedef void (*XtTimerCallbackProc) (XtPointer closure, XtIntervalId *);
389 typedef void (*XtInputCallbackProc) (XtPointer closure, int *fd, XtInputId *);
390 extern XtIntervalId XtAppAddTimeOut (XtAppContext, unsigned long usecs,
391 XtTimerCallbackProc, XtPointer closure);
392 extern void XtRemoveTimeOut (XtIntervalId);
393 extern XtInputId XtAppAddInput (XtAppContext, int fd, XtPointer flags,
394 XtInputCallbackProc, XtPointer closure);
395 extern void XtRemoveInput (XtInputId);
396 extern struct jwxyz_sources_data *display_sources_data (Display *);
398 // Some GLX stuff that also doesn't technically belong here...
399 // from XScreenSaverGLView.m
400 extern void glXSwapBuffers (Display *, Window);
401 extern void glXMakeCurrent (Display *, Window, GLXContext);
403 // also declared in utils/visual.h
404 extern int has_writable_cells (Screen *, Visual *);
405 extern int visual_depth (Screen *, Visual *);
406 extern int visual_cells (Screen *, Visual *);
407 extern int visual_class (Screen *, Visual *);
409 // also declared in utils/grabclient.h
410 extern Bool use_subwindow_mode_p (Screen *, Window);
413 extern int jwxyz_font_info (Font, int *size_ret, int *face_ret);
416 struct jwxyz_Visual {
417 VisualID visualid; /* visual id of this visual */
418 int class; /* class of screen (monochrome, etc.) */
419 unsigned long red_mask, green_mask, blue_mask; /* mask values */
420 int bits_per_rgb; /* log base 2 of distinct color values */
421 // int map_entries; /* color map entries */
424 struct jwxyz_XGCValues {
425 int function; /* logical operation */
427 unsigned long plane_mask;/* plane mask */
429 unsigned long foreground;/* foreground pixel */
430 unsigned long background;/* background pixel */
431 int line_width; /* line width */
433 int line_style; /* LineSolid, LineOnOffDash, LineDoubleDash */
435 int cap_style; /* CapNotLast, CapButt, CapRound, CapProjecting */
436 int join_style; /* JoinMiter, JoinRound, JoinBevel */
438 int fill_style; /* FillSolid, FillTiled,
439 FillStippled, FillOpaeueStippled */
441 int fill_rule; /* EvenOddRule, WindingRule */
443 int arc_mode; /* ArcChord, ArcPieSlice */
444 Pixmap tile; /* tile pixmap for tiling operations */
445 Pixmap stipple; /* stipple 1 plane pixmap for stipping */
446 int ts_x_origin; /* offset for tile or stipple operations */
449 Font font; /* default text font for text operations */
450 int subwindow_mode; /* ClipByChildren, IncludeInferiors */
452 Bool graphics_exposures;/* boolean, should exposures be generated */
454 int clip_x_origin; /* origin for clipping */
456 Pixmap clip_mask; /* bitmap clipping; other calls for rects */
458 int dash_offset; /* patterned/dashed line information */
462 Bool alpha_allowed_p; /* jwxyz extension: whether pixel values may have
463 a non-opaque alpha component. */
464 Bool antialias_p; /* jwxyz extension: whether Quartz should draw
465 with antialiasing. */
468 struct jwxyz_XWindowAttributes {
469 int x, y; /* location of window */
470 int width, height; /* width and height of window */
471 int border_width; /* border width of window */
472 int depth; /* depth of window */
473 Visual *visual; /* the associated visual structure */
475 Window root; /* root of screen containing window */
476 int class; /* InputOutput, InputOnly*/
477 int bit_gravity; /* one of bit gravity values */
478 int win_gravity; /* one of the window gravity values */
479 int backing_store; /* NotUseful, WhenMapped, Always */
480 unsigned long backing_planes;/* planes to be preserved if possible */
481 unsigned long backing_pixel;/* value to be used when restoring planes */
482 Bool save_under; /* boolean, should bits under be saved? */
484 Colormap colormap; /* color map to be associated with window */
486 Bool map_installed; /* boolean, is color map currently installed*/
487 int map_state; /* IsUnmapped, IsUnviewable, IsViewable */
488 long all_event_masks; /* set of events all people have interest in*/
489 long your_event_mask; /* my event mask */
490 long do_not_propagate_mask; /* set of events that should not propagate */
491 Bool override_redirect; /* boolean value for override-redirect */
493 Screen *screen; /* back pointer to correct screen */
496 struct jwxyz_XColor {
498 unsigned short red, green, blue;
499 char flags; /* do_red, do_green, do_blue */
503 struct jwxyz_XPoint {
507 struct jwxyz_XSegment {
508 short x1, y1, x2, y2;
511 struct jwxyz_XRectangle {
513 unsigned short width, height;
518 unsigned short width, height;
519 short angle1, angle2;
523 struct jwxyz_XrmOptionDescRec {
530 struct jwxyz_XAnyEvent {
533 unsigned long serial;
540 struct jwxyz_XKeyEvent {
543 unsigned long serial;
554 unsigned int keycode;
560 struct jwxyz_XButtonEvent {
563 unsigned long serial;
582 struct jwxyz_XMotionEvent {
585 unsigned long serial;
608 XButtonEvent xbutton;
609 XMotionEvent xmotion;
612 struct jwxyz_XImage {
613 int width, height; /* size of image */
614 int xoffset; /* number of pixels offset in X direction */
615 int format; /* XYBitmap, XYPixmap, ZPixmap */
616 char *data; /* pointer to image data */
617 int byte_order; /* data byte order, LSBFirst, MSBFirst */
618 int bitmap_unit; /* quant. of scanline 8, 16, 32 */
619 int bitmap_bit_order; /* LSBFirst, MSBFirst */
620 int bitmap_pad; /* 8, 16, 32 either XY or ZPixmap */
621 int depth; /* depth of image */
622 int bytes_per_line; /* accelarator to next line */
623 int bits_per_pixel; /* bits per pixel (ZPixmap) */
624 unsigned long red_mask; /* bits in z arrangment */
625 unsigned long green_mask;
626 unsigned long blue_mask;
627 // XPointer obdata; /* hook for the object routines to hang on */
628 struct funcs { /* image manipulation routines */
630 XImage *(*create_image)(
631 Display* /* display */,
632 Visual* /* visual */,
633 unsigned int /* depth */,
637 unsigned int /* width */,
638 unsigned int /* height */,
639 int /* bitmap_pad */,
640 int /* bytes_per_line */);
641 int (*destroy_image) (XImage *);
643 unsigned long (*get_pixel) (XImage *, int, int);
644 int (*put_pixel) (XImage *, int, int, unsigned long);
646 XImage *(*sub_image) (XImage *, int, int, unsigned int, unsigned int);
647 int (*add_pixel) (XImage *, long);
652 struct jwxyz_XCharStruct {
653 short lbearing; /* origin to left edge of raster */
654 short rbearing; /* origin to right edge of raster */
655 short width; /* advance to next char's origin */
656 short ascent; /* baseline to top edge of raster */
657 short descent; /* baseline to bottom edge of raster */
659 unsigned short attributes; /* per char flags (not predefined) */
663 struct jwxyz_XFontStruct {
665 XExtData *ext_data; /* hook for extension to hang data */
667 Font fid; /* Font id for this font */
669 unsigned direction; /* hint about direction the font is painted */
671 unsigned min_char_or_byte2; /* first character */
672 unsigned max_char_or_byte2; /* last character */
674 unsigned min_byte1; /* first row that exists */
675 unsigned max_byte1; /* last row that exists */
676 Bool all_chars_exist; /* flag if all characters have non-zero size*/
678 unsigned default_char; /* char to print for undefined character */
680 int n_properties; /* how many properties there are */
681 XFontProp *properties; /* pointer to array of additional properties*/
683 XCharStruct min_bounds; /* minimum bounds over all existing char*/
684 XCharStruct max_bounds; /* maximum bounds over all existing char*/
685 XCharStruct *per_char; /* first_char to last_char information */
686 int ascent; /* log. extent above baseline for spacing */
687 int descent; /* log. descent below baseline for spacing */
690 struct jwxyz_XComposeStatus {
694 struct jwxyz_XPixmapFormatValues {
700 #endif /* __JWXYZ_H__ */