]> gitweb.factorcode.org Git - factor.git/blob - basis/x11/xlib/xlib.factor
07872fe576d363282e87fa53500a5b4c1125b291
[factor.git] / basis / x11 / xlib / xlib.factor
1 ! Copyright (C) 2005, 2006 Eduardo Cavazos
2 ! See http://factorcode.org/license.txt for BSD license.
3 !
4 ! The most popular guides to programming the X Window System are
5 ! the series from Oreilly. For programming with Xlib, there is
6 ! the reference manual and the programmers guide. However, a
7 ! lesser known manual is the free Xlib manual that comes with
8 ! the MIT X distribution. The arrangement and order of these
9 ! bindings follows the structure of the free Xlib manual. If you
10 ! add to this library and are wondering what part of the file to
11 ! modify, just find the function or data structure in the manual
12 ! and note the section.
13
14 USING: kernel arrays alien alien.c-types alien.strings
15 alien.syntax math math.bitwise words sequences namespaces
16 continuations io io.encodings.ascii alias ;
17 IN: x11.xlib
18
19 LIBRARY: xlib
20
21 TYPEDEF: ulong XID
22 TYPEDEF: XID Window
23 TYPEDEF: XID Drawable
24 TYPEDEF: XID Font
25 TYPEDEF: XID Pixmap
26 TYPEDEF: XID Cursor
27 TYPEDEF: XID Colormap
28 TYPEDEF: XID GContext
29 TYPEDEF: XID KeySym
30
31 TYPEDEF: ulong Atom
32
33 TYPEDEF: char* XPointer
34 TYPEDEF: void* Screen*
35 TYPEDEF: void* GC
36 TYPEDEF: void* Visual*
37 TYPEDEF: void* XExtData*
38 TYPEDEF: void* XFontProp*
39 TYPEDEF: void* XComposeStatus*
40 TYPEDEF: void* XIM
41 TYPEDEF: void* XIC
42
43 TYPEDEF: int Status
44
45 TYPEDEF: int Bool
46
47 TYPEDEF: ulong VisualID
48 TYPEDEF: ulong Time
49
50 TYPEDEF: void* Window**
51 TYPEDEF: void* Atom**
52
53 ALIAS: <XID> <ulong>
54 ALIAS: <Window> <XID>
55 ALIAS: <Drawable> <XID>
56 ALIAS: <KeySym> <XID>
57 ALIAS: <Atom> <ulong>
58
59 ALIAS: *XID *ulong
60 ALIAS: *Window *XID
61 ALIAS: *Drawable *XID
62 ALIAS: *KeySym *XID
63 ALIAS: *Atom *ulong
64 !
65 ! 2 - Display Functions
66 !
67
68 ! This struct is incomplete
69 C-STRUCT: Display
70 { "void*" "ext_data" }
71 { "void*" "free_funcs" }
72 { "int" "fd" } ;
73
74 FUNCTION: Display* XOpenDisplay ( void* display_name ) ;
75
76 ! 2.2 Obtaining Information about the Display, Image Formats, or Screens
77
78 FUNCTION: ulong XBlackPixel ( Display* display, int screen_number ) ;
79 FUNCTION: ulong XWhitePixel ( Display* display, int screen_number ) ;
80 FUNCTION: Colormap XDefaultColormap ( Display* display, int screen_number ) ;
81 FUNCTION: int XDefaultDepth ( Display* display, int screen_number ) ;
82 FUNCTION: GC XDefaultGC ( Display* display, int screen_number ) ;
83 FUNCTION: int XDefaultScreen ( Display* display ) ;
84 FUNCTION: Window XRootWindow ( Display* display, int screen_number ) ;
85 FUNCTION: Window XDefaultRootWindow ( Display* display ) ;
86 FUNCTION: int XProtocolVersion ( Display* display ) ;
87 FUNCTION: int XProtocolRevision ( Display* display ) ;
88 FUNCTION: int XQLength ( Display* display ) ;
89 FUNCTION: int XScreenCount ( Display* display ) ;
90 FUNCTION: int XConnectionNumber ( Display* display ) ;
91
92 ! 2.5 Closing the Display
93 FUNCTION: int XCloseDisplay ( Display* display ) ;
94
95 !
96 ! 3 - Window Functions
97 !
98
99 ! 3.2 - Window Attributes
100
101 : CWBackPixmap       ( -- n ) 0 2^ ; inline
102 : CWBackPixel        ( -- n ) 1 2^ ; inline
103 : CWBorderPixmap     ( -- n ) 2 2^ ; inline
104 : CWBorderPixel      ( -- n ) 3 2^ ; inline
105 : CWBitGravity       ( -- n ) 4 2^ ; inline
106 : CWWinGravity       ( -- n ) 5 2^ ; inline
107 : CWBackingStore     ( -- n ) 6 2^ ; inline
108 : CWBackingPlanes    ( -- n ) 7 2^ ; inline
109 : CWBackingPixel     ( -- n ) 8 2^ ; inline
110 : CWOverrideRedirect ( -- n ) 9 2^ ; inline
111 : CWSaveUnder        ( -- n ) 10 2^ ; inline
112 : CWEventMask        ( -- n ) 11 2^ ; inline
113 : CWDontPropagate    ( -- n ) 12 2^ ; inline
114 : CWColormap         ( -- n ) 13 2^ ; inline
115 : CWCursor           ( -- n ) 14 2^ ; inline
116
117 C-STRUCT: XSetWindowAttributes
118         { "Pixmap" "background_pixmap" }
119         { "ulong" "background_pixel" }
120         { "Pixmap" "border_pixmap" }
121         { "ulong" "border_pixel" }
122         { "int" "bit_gravity" }
123         { "int" "win_gravity" }
124         { "int" "backing_store" }
125         { "ulong" "backing_planes" }
126         { "ulong" "backing_pixel" }
127         { "Bool" "save_under" }
128         { "long" "event_mask" }
129         { "long" "do_not_propagate_mask" }
130         { "Bool" "override_redirect" }
131         { "Colormap" "colormap" }
132         { "Cursor" "cursor" } ;
133
134 : UnmapGravity          0 ; inline
135
136 : ForgetGravity         0 ; inline
137 : NorthWestGravity      1 ; inline
138 : NorthGravity          2 ; inline
139 : NorthEastGravity      3 ; inline
140 : WestGravity           4 ; inline
141 : CenterGravity         5 ; inline
142 : EastGravity           6 ; inline
143 : SouthWestGravity      7 ; inline
144 : SouthGravity          8 ; inline
145 : SouthEastGravity      9 ; inline
146 : StaticGravity         10 ; inline
147
148 ! 3.3 - Creating Windows
149
150 FUNCTION: Window XCreateWindow ( Display* display, Window parent, int x, int y, uint width, uint height, uint border_width, int depth, uint class, Visual* visual, ulong valuemask, XSetWindowAttributes* attributes ) ;
151 FUNCTION: Window XCreateSimpleWindow ( Display* display, Window parent, int x, int y, uint width, uint height, uint border_width, ulong border, ulong background ) ;
152 FUNCTION: Status XDestroyWindow ( Display* display, Window w ) ;
153 FUNCTION: Status XMapWindow ( Display* display, Window window ) ;
154 FUNCTION: Status XMapSubwindows ( Display* display, Window window ) ;
155 FUNCTION: Status XUnmapWindow ( Display* display, Window w ) ;
156 FUNCTION: Status XUnmapSubwindows ( Display* display, Window w ) ;
157
158 ! 3.5 Mapping Windows
159
160 FUNCTION: int XMapRaised ( Display* display, Window w ) ;
161
162 ! 3.7 - Configuring Windows
163
164 : CWX           ( -- n ) 0 2^ ; inline
165 : CWY           ( -- n ) 1 2^ ; inline
166 : CWWidth       ( -- n ) 2 2^ ; inline
167 : CWHeight      ( -- n ) 3 2^ ; inline
168 : CWBorderWidth ( -- n ) 4 2^ ; inline
169 : CWSibling     ( -- n ) 5 2^ ; inline
170 : CWStackMode   ( -- n ) 6 2^ ; inline
171
172 C-STRUCT: XWindowChanges
173         { "int" "x" }
174         { "int" "y" }
175         { "int" "width" }
176         { "int" "height" }
177         { "int" "border_width" }
178         { "Window" "sibling" }
179         { "int" "stack_mode" } ;
180
181 FUNCTION: Status XConfigureWindow ( Display* display, Window w, uint value_mask, XWindowChanges* values ) ;
182 FUNCTION: Status XMoveWindow ( Display* display, Window w, int x, int y ) ;
183 FUNCTION: Status XResizeWindow ( Display* display, Window w, uint width, uint height ) ;
184 FUNCTION: Status XSetWindowBorderWidth ( Display* display, ulong w, uint width ) ;
185
186
187 ! 3.8 Changing Window Stacking Order
188
189 FUNCTION: Status XRaiseWindow ( Display* display, Window w ) ;
190 FUNCTION: Status XLowerWindow ( Display* display, Window w ) ;
191
192 ! 3.9 - Changing Window Attributes
193
194 FUNCTION: Status XChangeWindowAttributes (
195   Display* display, Window w, ulong valuemask, XSetWindowAttributes* attr ) ;
196 FUNCTION: Status XSetWindowBackground (
197   Display* display, Window w, ulong background_pixel ) ;
198 FUNCTION: Status XDefineCursor ( Display* display, Window w, Cursor cursor ) ;
199 FUNCTION: Status XUndefineCursor ( Display* display, Window w ) ;
200
201 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
202 ! 4 - Window Information Functions
203 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
204
205 ! 4.1 - Obtaining Window Information
206
207 FUNCTION: Status XQueryTree (
208   Display* display,
209   Window w,
210   Window* root_return,
211   Window* parent_return,
212   Window** children_return, uint* nchildren_return ) ;
213
214 C-STRUCT: XWindowAttributes
215         { "int" "x" }
216         { "int" "y" }
217         { "int" "width" }
218         { "int" " height" }
219         { "int" "border_width" }
220         { "int" "depth" }
221         { "Visual*" "visual" }
222         { "Window" "root" }
223         { "int" "class" }
224         { "int" "bit_gravity" }
225         { "int" "win_gravity" }
226         { "int" "backing_store" }
227         { "ulong" "backing_planes" }
228         { "ulong" "backing_pixel" }
229         { "Bool" "save_under" }
230         { "Colormap" "colormap" }
231         { "Bool" "map_installed" }
232         { "int" "map_state" }
233         { "long" "all_event_masks" }
234         { "long" "your_event_mask" }
235         { "long" "do_not_propagate_mask" }
236         { "Bool" "override_redirect" }
237         { "Screen*" "screen" } ;
238
239 FUNCTION: Status XGetWindowAttributes ( Display* display, Window w, XWindowAttributes* attr ) ;
240
241 : IsUnmapped            0 ; inline
242 : IsUnviewable          1 ; inline
243 : IsViewable            2 ; inline
244
245 FUNCTION: Status XGetGeometry (
246   Display* display,
247   Drawable d,
248   Window* root_return,
249   int* x_return,
250   int* y_return,
251   uint* width_return,
252   uint* height_return,
253   uint* border_width_return,
254   uint* depth_return ) ;
255
256 ! 4.2 - Translating Screen Coordinates
257
258 FUNCTION: Bool XQueryPointer ( Display* display, Window w, Window* root_return, Window* child_return, int* root_x_return, int* root_y_return, int* win_x_return, int* win_y_return, uint* mask_return ) ;
259
260 ! 4.3 - Properties and Atoms
261
262 FUNCTION: Atom XInternAtom ( Display* display, char* atom_name, Bool only_if_exists ) ;
263
264 FUNCTION: char* XGetAtomName ( Display* display, Atom atom ) ;
265
266 ! 4.4 - Obtaining and Changing Window Properties
267
268 FUNCTION: int XGetWindowProperty ( Display* display, Window w, Atom property, long long_offset, long long_length, Bool delete, Atom req_type, Atom* actual_type_return, int* actual_format_return, ulong* nitems_return, ulong* bytes_after_return, char** prop_return ) ;
269
270 FUNCTION: int XChangeProperty ( Display* display, Window w, Atom property, Atom type, int format, int mode, void* data, int nelements ) ;
271
272 ! 4.5 Selections
273
274 FUNCTION: int XSetSelectionOwner ( Display* display, Atom selection, Window owner, Time time ) ;
275
276 FUNCTION: Window XGetSelectionOwner ( Display* display, Atom selection ) ;
277
278 FUNCTION: int XConvertSelection ( Display* display, Atom selection, Atom target, Atom property, Window requestor, Time time ) ;
279
280
281 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
282 ! 5 - Pixmap and Cursor Functions
283 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
284
285 ! 5.1 - Creating and Freeing Pixmaps
286
287 FUNCTION: Pixmap XCreatePixmap ( Display* display, Drawable d, uint width, uint height, uint depth ) ;
288 FUNCTION: int XFreePixmap ( Display* display, Pixmap pixmap ) ;
289
290
291 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
292 ! 6 - Color Management Functions
293 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
294
295 C-STRUCT: XColor
296         { "ulong" "pixel" }
297         { "ushort" "red" }
298         { "ushort" "green" }
299         { "ushort" "blue" }
300         { "char" "flags" }
301         { "char" "pad" } ;
302
303 FUNCTION: Status XLookupColor ( Display* display, Colormap colormap, char* color_name, XColor* exact_def_return, XColor* screen_def_return ) ;
304 FUNCTION: Status XAllocColor ( Display* display, Colormap colormap, XColor* screen_in_out ) ;
305 FUNCTION: Status XQueryColor ( Display* display, Colormap colormap, XColor* def_in_out ) ;
306
307 ! 6.4 Creating, Copying, and Destroying Colormaps
308
309 FUNCTION: Colormap XCreateColormap ( Display* display, Window w, Visual* visual, int alloc ) ;
310
311 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
312 ! 7 - Graphics Context Functions
313 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
314
315 : GCFunction          ( -- n ) 0 2^ ; inline
316 : GCPlaneMask         ( -- n ) 1 2^ ; inline
317 : GCForeground        ( -- n ) 2 2^ ; inline
318 : GCBackground        ( -- n ) 3 2^ ; inline
319 : GCLineWidth         ( -- n ) 4 2^ ; inline
320 : GCLineStyle         ( -- n ) 5 2^ ; inline
321 : GCCapStyle          ( -- n ) 6 2^ ; inline
322 : GCJoinStyle         ( -- n ) 7 2^ ; inline
323 : GCFillStyle         ( -- n ) 8 2^ ; inline
324 : GCFillRule          ( -- n ) 9 2^ ; inline
325 : GCTile              ( -- n ) 10 2^ ; inline
326 : GCStipple           ( -- n ) 11 2^ ; inline
327 : GCTileStipXOrigin   ( -- n ) 12 2^ ; inline
328 : GCTileStipYOrigin   ( -- n ) 13 2^ ; inline
329 : GCFont              ( -- n ) 14 2^ ; inline
330 : GCSubwindowMode     ( -- n ) 15 2^ ; inline
331 : GCGraphicsExposures ( -- n ) 16 2^ ; inline
332 : GCClipXOrigin       ( -- n ) 17 2^ ; inline
333 : GCClipYOrigin       ( -- n ) 18 2^ ; inline
334 : GCClipMask          ( -- n ) 19 2^ ; inline
335 : GCDashOffset        ( -- n ) 20 2^ ; inline
336 : GCDashList          ( -- n ) 21 2^ ; inline
337 : GCArcMode           ( -- n ) 22 2^ ; inline
338
339 : GXclear               HEX: 0 ; inline
340 : GXand                 HEX: 1 ; inline
341 : GXandReverse          HEX: 2 ; inline
342 : GXcopy                HEX: 3 ; inline
343 : GXandInverted         HEX: 4 ; inline
344 : GXnoop                HEX: 5 ; inline
345 : GXxor                 HEX: 6 ; inline
346 : GXor                  HEX: 7 ; inline
347 : GXnor                 HEX: 8 ; inline
348 : GXequiv               HEX: 9 ; inline
349 : GXinvert              HEX: a ; inline
350 : GXorReverse           HEX: b ; inline
351 : GXcopyInverted        HEX: c ; inline
352 : GXorInverted          HEX: d ; inline
353 : GXnand                HEX: e ; inline
354 : GXset                 HEX: f ; inline
355
356 C-STRUCT: XGCValues
357         { "int" "function" }
358         { "ulong" "plane_mask" }
359         { "ulong" "foreground" }
360         { "ulong" "background" }
361         { "int" "line_width" }
362         { "int" "line_style" }
363         { "int" "cap_style" }
364         { "int" "join_style" }
365         { "int" "fill_style" }
366         { "int" "fill_rule" }
367         { "int" "arc_mode" }
368         { "Pixmap" "tile" }
369         { "Pixmap" "stipple" }
370         { "int" "ts_x_origin" }
371         { "int" "ts_y_origin" }
372         { "Font" "font" }
373         { "int" "subwindow_mode" }
374         { "Bool" "graphics_exposures" }
375         { "int" "clip_x_origin" }
376         { "int" "clip_y_origin" }
377         { "Pixmap" "clip_mask" }
378         { "int" "dash_offset" }
379         { "char" "dashes" } ;
380
381 FUNCTION: GC XCreateGC ( Display* display, Window d, ulong valuemask, XGCValues* values ) ;
382 FUNCTION: int XChangeGC ( Display* display, GC gc, ulong valuemask, XGCValues* values ) ;
383 FUNCTION: Status XGetGCValues ( Display* display, GC gc, ulong valuemask, XGCValues* values_return ) ;
384 FUNCTION: Status XSetForeground ( Display* display, GC gc, ulong foreground ) ;
385 FUNCTION: Status XSetBackground ( Display* display, GC gc, ulong background ) ;
386 FUNCTION: Status XSetFunction ( Display* display, GC gc, int function ) ;
387 FUNCTION: Status XSetSubwindowMode ( Display* display, GC gc, int subwindow_mode ) ;
388
389 FUNCTION: GContext XGContextFromGC ( GC gc ) ;
390
391 FUNCTION: Status XSetFont ( Display* display, GC gc, Font font ) ;
392
393 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
394 ! 8 - Graphics Functions
395 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
396
397 FUNCTION: Status XClearWindow ( Display* display, Window w ) ;
398 FUNCTION: Status XDrawPoint ( Display* display, Drawable d, GC gc, int x, int y ) ;
399 FUNCTION: Status XDrawLine ( Display* display, Drawable d, GC gc, int x1, int y1, int x2, int y2 ) ;
400 FUNCTION: Status XDrawArc ( Display* display, Drawable d, GC gc, int x, int y, uint width, uint height, int angle1, int angle2 ) ;
401 FUNCTION: Status XFillArc ( Display* display, Drawable d, GC gc, int x, int y, uint width, uint height, int angle1, int angle2 ) ;
402
403 ! 8.5 - Font Metrics
404
405 C-STRUCT: XCharStruct
406         { "short" "lbearing" }
407         { "short" "rbearing" }
408         { "short" "width" }
409         { "short" "ascent" }
410         { "short" "descent" }
411         { "ushort" "attributes" } ;
412
413 FUNCTION: Font XLoadFont ( Display* display, char* name ) ;
414 FUNCTION: XFontStruct* XQueryFont ( Display* display, XID font_ID ) ;
415 FUNCTION: XFontStruct* XLoadQueryFont ( Display* display, char* name ) ;
416
417 C-STRUCT: XFontStruct
418         { "XExtData*" "ext_data" }
419         { "Font" "fid" }
420         { "uint" "direction" }
421         { "uint" "min_char_or_byte2" }
422         { "uint" "max_char_or_byte2" }
423         { "uint" "min_byte1" }
424         { "uint" "max_byte1" }
425         { "Bool" "all_chars_exist" }
426         { "uint" "default_char" }
427         { "int" "n_properties" }
428         { "XFontProp*" "properties" }
429         { "XCharStruct" "min_bounds" }
430         { "XCharStruct" "max_bounds" }
431         { "XCharStruct*" "per_char" }
432         { "int" "ascent" }
433         { "int" "descent" } ;
434
435 FUNCTION: int XTextWidth ( XFontStruct* font_struct, char* string, int count ) ;
436
437 ! 8.6 - Drawing Text
438
439 FUNCTION: Status XDrawString (
440         Display* display,
441         Drawable d,
442         GC gc,
443         int x,
444         int y,
445         char* string,
446         int length ) ;
447
448 ! 8.7 - Transferring Images between Client and Server
449
450 : XYBitmap 0 ; inline
451 : XYPixmap 1 ; inline
452 : ZPixmap  2 ; inline
453 : AllPlanes -1 ; inline
454
455 C-STRUCT: XImage-funcs
456     { "void*" "create_image" }
457     { "void*" "destroy_image" }
458     { "void*" "get_pixel" }
459     { "void*" "put_pixel" }
460     { "void*" "sub_image" }
461     { "void*" "add_pixel" } ;
462
463 C-STRUCT: XImage
464     { "int"          "width" }
465     { "int"          "height" }
466     { "int"          "xoffset" }
467     { "int"          "format" }
468     { "char*"        "data" }
469     { "int"          "byte_order" }
470     { "int"          "bitmap_unit" }
471     { "int"          "bitmap_bit_order" }
472     { "int"          "bitmap_pad" }
473     { "int"          "depth" }
474     { "int"          "bytes_per_line" }
475     { "int"          "bits_per_pixel" }
476     { "ulong"        "red_mask" }
477     { "ulong"        "green_mask" }
478     { "ulong"        "blue_mask" }
479     { "XPointer"     "obdata" }
480     { "XImage-funcs" "f" } ;
481
482 FUNCTION: XImage* XGetImage ( Display* display, Drawable d, int x, int y, uint width, uint height, ulong plane_mask, int format ) ;
483 FUNCTION: int XDestroyImage ( XImage *ximage ) ;
484
485 : XImage-size ( ximage -- size )
486     [ XImage-height ] [ XImage-bytes_per_line ] bi * ;
487
488 : XImage-pixels ( ximage -- byte-array )
489     [ XImage-data ] [ XImage-size ] bi memory>byte-array ;
490
491 !
492 ! 9 - Window and Session Manager Functions
493 !
494
495 FUNCTION: Status XReparentWindow ( Display* display, Window w, Window parent, int x, int y ) ;
496 FUNCTION: Status XAddToSaveSet ( Display* display, Window w ) ;
497 FUNCTION: Status XRemoveFromSaveSet ( Display* display, Window w ) ;
498 FUNCTION: Status XGrabServer ( Display* display ) ;
499 FUNCTION: Status XUngrabServer ( Display* display ) ;
500 FUNCTION: Status XKillClient ( Display* display, XID resource ) ;
501
502 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
503 ! 10 - Events
504 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
505
506 ! 10.3 - Event Masks
507
508 : NoEventMask              ( -- n ) 0 ; inline
509 : KeyPressMask             ( -- n ) 0 2^ ; inline
510 : KeyReleaseMask           ( -- n ) 1 2^ ; inline
511 : ButtonPressMask          ( -- n ) 2 2^ ; inline
512 : ButtonReleaseMask        ( -- n ) 3 2^ ; inline
513 : EnterWindowMask          ( -- n ) 4 2^ ; inline
514 : LeaveWindowMask          ( -- n ) 5 2^ ; inline
515 : PointerMotionMask        ( -- n ) 6 2^ ; inline
516 : PointerMotionHintMask    ( -- n ) 7 2^ ; inline
517 : Button1MotionMask        ( -- n ) 8 2^ ; inline
518 : Button2MotionMask        ( -- n ) 9 2^ ; inline
519 : Button3MotionMask        ( -- n ) 10 2^ ; inline
520 : Button4MotionMask        ( -- n ) 11 2^ ; inline
521 : Button5MotionMask        ( -- n ) 12 2^ ; inline
522 : ButtonMotionMask         ( -- n ) 13 2^ ; inline
523 : KeymapStateMask          ( -- n ) 14 2^ ; inline
524 : ExposureMask             ( -- n ) 15 2^ ; inline
525 : VisibilityChangeMask     ( -- n ) 16 2^ ; inline
526 : StructureNotifyMask      ( -- n ) 17 2^ ; inline
527 : ResizeRedirectMask       ( -- n ) 18 2^ ; inline
528 : SubstructureNotifyMask   ( -- n ) 19 2^ ; inline
529 : SubstructureRedirectMask ( -- n ) 20 2^ ; inline
530 : FocusChangeMask          ( -- n ) 21 2^ ; inline
531 : PropertyChangeMask       ( -- n ) 22 2^ ; inline
532 : ColormapChangeMask       ( -- n ) 23 2^ ; inline
533 : OwnerGrabButtonMask      ( -- n ) 24 2^ ; inline
534
535 : KeyPress              2 ; inline
536 : KeyRelease            3 ; inline
537 : ButtonPress           4 ; inline
538 : ButtonRelease         5 ; inline
539 : MotionNotify          6 ; inline
540 : EnterNotify           7 ; inline
541 : LeaveNotify           8 ; inline
542 : FocusIn                       9 ; inline
543 : FocusOut              10 ; inline
544 : KeymapNotify          11 ; inline
545 : Expose                        12 ; inline
546 : GraphicsExpose                13 ; inline
547 : NoExpose              14 ; inline
548 : VisibilityNotify      15 ; inline
549 : CreateNotify          16 ; inline
550 : DestroyNotify         17 ; inline
551 : UnmapNotify           18 ; inline
552 : MapNotify             19 ; inline
553 : MapRequest            20 ; inline
554 : ReparentNotify                21 ; inline
555 : ConfigureNotify               22 ; inline
556 : ConfigureRequest      23 ; inline
557 : GravityNotify         24 ; inline
558 : ResizeRequest         25 ; inline
559 : CirculateNotify               26 ; inline
560 : CirculateRequest      27 ; inline
561 : PropertyNotify                28 ; inline
562 : SelectionClear                29 ; inline
563 : SelectionRequest      30 ; inline
564 : SelectionNotify               31 ; inline
565 : ColormapNotify                32 ; inline
566 : ClientMessage         33 ; inline
567 : MappingNotify         34 ; inline
568 : LASTEvent             35 ; inline
569
570 C-STRUCT: XAnyEvent
571         { "int" "type" }
572         { "ulong" "serial" }
573         { "Bool" "send_event" }
574         { "Display*" "display" }
575         { "Window" "window" } ;
576
577 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
578
579 ! 10.5 Keyboard and Pointer Events
580
581 : Button1 1 ; inline
582 : Button2 2 ; inline
583 : Button3 3 ; inline
584 : Button4 4 ; inline
585 : Button5 5 ; inline
586
587 : Button1Mask ( -- n ) 1 8  shift ; inline
588 : Button2Mask ( -- n ) 1 9  shift ; inline
589 : Button3Mask ( -- n ) 1 10 shift ; inline
590 : Button4Mask ( -- n ) 1 11 shift ; inline
591 : Button5Mask ( -- n ) 1 12 shift ; inline
592
593 : ShiftMask   ( -- n ) 1 0 shift ; inline
594 : LockMask    ( -- n ) 1 1 shift ; inline
595 : ControlMask ( -- n ) 1 2 shift ; inline
596 : Mod1Mask    ( -- n ) 1 3 shift ; inline
597 : Mod2Mask    ( -- n ) 1 4 shift ; inline
598 : Mod3Mask    ( -- n ) 1 5 shift ; inline
599 : Mod4Mask    ( -- n ) 1 6 shift ; inline
600 : Mod5Mask    ( -- n ) 1 7 shift ; inline
601
602 C-STRUCT: XButtonEvent
603         { "int" "type" }
604         { "ulong" "serial" }
605         { "Bool" "send_event" }
606         { "Display*" "display" }
607         { "Window" "window" }
608         { "Window" "root" }
609         { "Window" "subwindow" }
610         { "Time" "time" }
611         { "int" "x" }
612         { "int" "y" }
613         { "int" "x_root" }
614         { "int" "y_root" }
615         { "uint" "state" }
616         { "uint" "button" }
617         { "Bool" "same_screen" } ;
618
619 TYPEDEF: XButtonEvent XButtonPressedEvent
620 TYPEDEF: XButtonEvent XButtonReleasedEvent
621
622
623 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
624
625 C-STRUCT: XKeyEvent
626         { "int" "type" }
627         { "ulong" "serial" }
628         { "Bool" "send_event" }
629         { "Display*" "display" }
630         { "Window" "window" }
631         { "Window" "root" }
632         { "Window" "subwindow" }
633         { "Time" "time" }
634         { "int" "x" }
635         { "int" "y" }
636         { "int" "x_root" }
637         { "int" "y_root" }
638         { "uint" "state" }
639         { "uint" "keycode" }
640         { "Bool" "same_screen" } ;
641
642 TYPEDEF: XKeyEvent XKeyPressedEvent
643 TYPEDEF: XKeyEvent XKeyReleasedEvent
644
645 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
646
647 C-STRUCT: XMotionEvent
648         { "int" "type" }
649         { "ulong" "serial" }
650         { "Bool" "send_event" }
651         { "Display*" "display" }
652         { "Window" "window" }
653         { "Window" "root" }
654         { "Window" "subwindow" }
655         { "Time" "time" }
656         { "int" "x" }
657         { "int" "y" }
658         { "int" "x_root" }
659         { "int" "y_root" }
660         { "uint" "state" }
661         { "char" "is_hint" }
662         { "Bool" "same_screen" } ;
663
664 TYPEDEF: XMotionEvent XPointerMovedEvent
665
666 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
667
668 C-STRUCT: XCrossingEvent
669         { "int" "type" }
670         { "ulong" "serial" }
671         { "Bool" "send_event" }
672         { "Display*" "display" }
673         { "Window" "window" }
674         { "Window" "root" }
675         { "Window" "subwindow" }
676         { "Time" "time" }
677         { "int" "x" }
678         { "int" "y" }
679         { "int" "x_root" }
680         { "int" "y_root" }
681         { "int" "mode" }
682         { "int" "detail" }
683         { "Bool" "same_screen" }
684         { "Bool" "focus" }
685         { "uint" "state" } ;
686
687 TYPEDEF: XCrossingEvent XEnterWindowEvent
688 TYPEDEF: XCrossingEvent XLeaveWindowEvent
689
690 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
691
692 C-STRUCT: XFocusChangeEvent
693         { "int" "type" }
694         { "ulong" "serial" }
695         { "Bool" "send_event" }
696         { "Display*" "display" }
697         { "Window" "window" }
698         { "int" "mode" }
699         { "int" "detail" } ;
700
701 TYPEDEF: XFocusChangeEvent XFocusInEvent
702 TYPEDEF: XFocusChangeEvent XFocusOutEvent
703
704 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
705
706 C-STRUCT: XExposeEvent
707         { "int" "type" }
708         { "ulong" "serial" }
709         { "Bool" "send_event" }
710         { "Display*" "display" }
711         { "Window" "window" }
712         { "int" "x" }
713         { "int" "y" }
714         { "int" "width" }
715         { "int" "height" }
716         { "int" "count" } ;
717
718 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
719
720 C-STRUCT: XGraphicsExposeEvent
721         { "int" "type" }
722         { "ulong" "serial" }
723         { "Bool" "send_event" }
724         { "Display*" "display" }
725         { "Drawable" "drawable" }
726         { "int" "x" }
727         { "int" "y" }
728         { "int" "width" }
729         { "int" "height" }
730         { "int" "count" }
731         { "int" "major_code" }
732         { "int" "minor_code" } ;
733
734 C-STRUCT: XNoExposeEvent
735         { "int" "type" }
736         { "ulong" "serial" }
737         { "Bool" "send_event" }
738         { "Display*" "display" }
739         { "Drawable" "drawable" }
740         { "int" "major_code" }
741         { "int" "minor_code" } ;
742
743 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
744
745 C-STRUCT: XVisibilityEvent
746         { "int" "type" }
747         { "ulong" "serial" }
748         { "Bool" "send_event" }
749         { "Display*" "display" }
750         { "Window" "window" }
751         { "int" "state" } ;
752
753 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
754
755 C-STRUCT: XCreateWindowEvent
756         { "int" "type" }
757         { "ulong" "serial" }
758         { "Bool" "send_event" }
759         { "Display*" "display" }
760         { "Window" "parent" }
761         { "Window" "window" }
762         { "int" "x" }
763         { "int" "y" }
764         { "int" "width" }
765         { "int" "height" }
766         { "int" "border_width" }
767         { "Bool" "override_redirect" } ;
768
769 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
770
771 C-STRUCT: XDestroyWindowEvent
772         { "int" "type" }
773         { "ulong" "serial" }
774         { "Bool" "send_event" }
775         { "Display*" "display" }
776         { "Window" "event" }
777         { "Window" "window" } ;
778
779 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
780
781 C-STRUCT: XUnmapEvent
782         { "int" "type" }
783         { "ulong" "serial" }
784         { "Bool" "send_event" }
785         { "Display*" "display" }
786         { "Window" "event" }
787         { "Window" "window" }
788         { "Bool" "from_configure" } ;
789
790 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
791
792 C-STRUCT: XMapEvent
793         { "int" "type" }
794         { "ulong" "serial" }
795         { "Bool" "send_event" }
796         { "Display*" "display" }
797         { "Window" "event" }
798         { "Window" "window" }
799         { "Bool" "override_redirect" } ;
800
801 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
802
803 C-STRUCT: XMapRequestEvent
804         { "int" "type" }
805         { "ulong" "serial" }
806         { "Bool" "send_event" }
807         { "Display*" "display" }
808         { "Window" "parent" }
809         { "Window" "window" } ;
810
811 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
812
813 C-STRUCT: XReparentEvent
814         { "int" "type" }
815         { "ulong" "serial" }
816         { "Bool" "send_event" }
817         { "Display*" "display" }
818         { "Window" "event" }
819         { "Window" "window" }
820         { "Window" "parent" }
821         { "int" "x" }
822         { "int" "y" }
823         { "Bool" "override_redirect" } ;
824
825 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
826
827 C-STRUCT: XConfigureEvent
828         { "int" "type" }
829         { "ulong" "serial" }
830         { "Bool" "send_event" }
831         { "Display*" "display" }
832         { "Window" "event" }
833         { "Window" "window" }
834         { "int" "x" }
835         { "int" "y" }
836         { "int" "width" }
837         { "int" "height" }
838         { "int" "border_width" }
839         { "Window" "above" }
840         { "Bool" "override_redirect" } ;
841
842 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
843
844 C-STRUCT: XGravityEvent
845         { "int" "type" }
846         { "ulong" "serial" }
847         { "Bool" "send_event" }
848         { "Display*" "display" }
849         { "Window" "event" }
850         { "Window" "window" }
851         { "int" "x" }
852         { "int" "y" } ;
853
854 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
855
856 C-STRUCT: XResizeRequestEvent
857         { "int" "type" }
858         { "ulong" "serial" }
859         { "Bool" "send_event" }
860         { "Display*" "display" }
861         { "Window" "window" }
862         { "int" "width" }
863         { "int" "height" } ;
864
865 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
866
867 C-STRUCT: XConfigureRequestEvent
868         { "int" "type" }
869         { "ulong" "serial" }
870         { "Bool" "send_event" }
871         { "Display*" "display" }
872         { "Window" "parent" }
873         { "Window" "window" }
874         { "int" "x" }
875         { "int" "y" }
876         { "int" "width" }
877         { "int" "height" }
878         { "int" "border_width" }
879         { "Window" "above" }
880         { "int" "detail" }
881         { "ulong" "value_mask" } ;
882
883 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
884
885 C-STRUCT: XCirculateEvent
886         { "int" "type" }
887         { "ulong" "serial" }
888         { "Bool" "send_event" }
889         { "Display*" "display" }
890         { "Window" "event" }
891         { "Window" "window" }
892         { "int" "place" } ;
893
894 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
895
896 C-STRUCT: XCirculateRequestEvent
897         { "int" "type" }
898         { "ulong" "serial" }
899         { "Bool" "send_event" }
900         { "Display*" "display" }
901         { "Window" "parent" }
902         { "Window" "window" }
903         { "int" "place" } ;
904
905 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
906
907 C-STRUCT: XPropertyEvent
908         { "int" "type" }
909         { "ulong" "serial" }
910         { "Bool" "send_event" }
911         { "Display*" "display" }
912         { "Window" "window" }
913         { "Atom" "atom" }
914         { "Time" "time" }
915         { "int" "state" } ;
916
917 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
918
919 C-STRUCT: XSelectionClearEvent
920         { "int" "type" }
921         { "ulong" "serial" }
922         { "Bool" "send_event" }
923         { "Display*" "display" }
924         { "Window" "window" }
925         { "Atom" "selection" }
926         { "Time" "time" } ;
927
928 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
929
930 C-STRUCT: XSelectionRequestEvent
931         { "int" "type" }
932         { "ulong" "serial" }
933         { "Bool" "send_event" }
934         { "Display*" "display" }
935         { "Window" "owner" }
936         { "Window" "requestor" }
937         { "Atom" "selection" }
938         { "Atom" "target" }
939         { "Atom" "property" }
940         { "Time" "time" } ;
941
942 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
943
944 C-STRUCT: XSelectionEvent
945         { "int" "type" }
946         { "ulong" "serial" }
947         { "Bool" "send_event" }
948         { "Display*" "display" }
949         { "Window" "requestor" }
950         { "Atom" "selection" }
951         { "Atom" "target" }
952         { "Atom" "property" }
953         { "Time" "time" } ;
954
955 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
956
957 C-STRUCT: XColormapEvent
958         { "int" "type" }
959         { "ulong" "serial" }
960         { "Bool" "send_event" }
961         { "Display*" "display" }
962         { "Window" "window" }
963         { "Colormap" "colormap" }
964         { "Bool" "new" }
965         { "int" "state" } ;
966
967 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
968
969 C-STRUCT: XClientMessageEvent
970         { "int" "type" }
971         { "ulong" "serial" }
972         { "Bool" "send_event" }
973         { "Display*" "display" }
974         { "Window" "window" }
975         { "Atom" "message_type" }
976         { "int" "format" }
977         { "long" "data0" }
978         { "long" "data1" }
979         { "long" "data2" }
980         { "long" "data3" }
981         { "long" "data4" }
982 !       union {
983 !               char  b[20];
984 !               short s[10];
985 !               long  l[5];
986 !       } data;
987 ;
988
989 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
990
991 C-STRUCT: XMappingEvent
992         { "int" "type" }
993         { "ulong" "serial" }
994         { "Bool" "send_event" }
995         { "Display*" "display" }
996         { "Window" "window" }
997         { "int" "request" }
998         { "int" "first_keycode" }
999         { "int" "count" } ;
1000
1001 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1002
1003 C-STRUCT: XErrorEvent
1004         { "int" "type" }
1005         { "Display*" "display" }
1006         { "XID" "resourceid" }
1007         { "ulong" "serial" }
1008         { "uchar" "error_code" }
1009         { "uchar" "request_code" }
1010         { "uchar" "minor_code" } ;
1011
1012 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1013
1014 C-STRUCT: XKeymapEvent
1015         { "int" "type" }
1016         { "ulong" "serial" }
1017         { "Bool" "send_event" }
1018         { "Display*" "display" }
1019         { "Window" "window" }
1020         ! char key_vector[32];
1021         { "int" "pad" }
1022         { "int" "pad" }
1023         { "int" "pad" }
1024         { "int" "pad" }
1025         { "int" "pad" }
1026         { "int" "pad" }
1027         { "int" "pad" }
1028         { "int" "pad" } ;
1029
1030 C-UNION: XEvent
1031         "int"
1032         "XAnyEvent"
1033         "XKeyEvent"
1034         "XButtonEvent"
1035         "XMotionEvent"
1036         "XCrossingEvent"
1037         "XFocusChangeEvent"
1038         "XExposeEvent"
1039         "XGraphicsExposeEvent"
1040         "XNoExposeEvent"
1041         "XVisibilityEvent"
1042         "XCreateWindowEvent"
1043         "XDestroyWindowEvent"
1044         "XUnmapEvent"
1045         "XMapEvent"
1046         "XMapRequestEvent"
1047         "XReparentEvent"
1048         "XConfigureEvent"
1049         "XGravityEvent"
1050         "XResizeRequestEvent"
1051         "XConfigureRequestEvent"
1052         "XCirculateEvent"
1053         "XCirculateRequestEvent"
1054         "XPropertyEvent"
1055         "XSelectionClearEvent"
1056         "XSelectionRequestEvent"
1057         "XSelectionEvent"
1058         "XColormapEvent"
1059         "XClientMessageEvent"
1060         "XMappingEvent"
1061         "XErrorEvent"
1062         "XKeymapEvent"
1063         { "long" 24 } ;
1064
1065 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1066 ! 11 - Event Handling Functions
1067 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1068
1069 FUNCTION: Status XSelectInput ( Display* display, Window w, long event_mask ) ;
1070 FUNCTION: Status XFlush ( Display* display ) ;
1071 FUNCTION: Status XSync ( Display* display, int discard ) ;
1072 FUNCTION: Status XNextEvent ( Display* display, XEvent* event ) ;
1073 FUNCTION: Status XMaskEvent ( Display* display, long event_mask, XEvent* event_return ) ;
1074
1075 ! 11.3 - Event Queue Management
1076
1077 : QueuedAlready 0 ; inline
1078 : QueuedAfterReading 1 ; inline
1079 : QueuedAfterFlush 2 ; inline
1080
1081 FUNCTION: int XEventsQueued ( Display* display, int mode ) ;
1082 FUNCTION: int XPending ( Display* display ) ;
1083
1084 ! 11.6 - Sending Events to Other Applications
1085
1086 FUNCTION: Status XSendEvent ( Display* display, Window w, Bool propagate, long event_mask, XEvent* event_send ) ;
1087
1088 ! 11.8 - Handling Protocol Errors
1089
1090 FUNCTION: int XSetErrorHandler ( void* handler ) ;
1091
1092 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1093 ! 12 - Input Device Functions
1094 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1095
1096 : None 0 ; inline
1097
1098 FUNCTION: int XGrabPointer (
1099   Display* display,
1100   Window grab_window,
1101   Bool owner_events,
1102   uint event_mask,
1103   int pointer_mode,
1104   int keyboard_mode,
1105   Window confine_to,
1106   Cursor cursor,
1107   Time time ) ;
1108
1109 FUNCTION: Status XUngrabPointer ( Display* display, Time time ) ;
1110 FUNCTION: Status XChangeActivePointerGrab ( Display* display, uint event_mask, Cursor cursor, Time time ) ;
1111 FUNCTION: Status XGrabKey ( Display* display, int keycode, uint modifiers, Window grab_window, Bool owner_events, int pointer_mode, int keyboard_mode ) ;
1112 FUNCTION: Status XSetInputFocus ( Display* display, Window focus, int revert_to, Time time ) ;
1113
1114 FUNCTION: Status XGetInputFocus ( Display* display,
1115                                   Window*  focus_return,
1116                                   int*     revert_to_return ) ;
1117
1118 FUNCTION: Status XWarpPointer ( Display* display, Window src_w, Window dest_w, int src_x, int src_y, uint src_width, uint src_height, int dest_x, int dest_y ) ;
1119
1120 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1121 ! 14 - Inter-Client Communication Functions
1122 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1123
1124 ! 14.1 Client to Window Manager Communication
1125
1126 FUNCTION: Status XFetchName ( Display* display, Window w, char** window_name_return ) ;
1127 FUNCTION: Status XGetTransientForHint ( Display* display, Window w, Window* prop_window_return ) ;
1128
1129 ! 14.1.1.  Manipulating Top-Level Windows
1130
1131 FUNCTION: Status XIconifyWindow (
1132         Display* display, Window w, int screen_number ) ;
1133
1134 FUNCTION: Status XWithdrawWindow (
1135         Display* display, Window w, int screen_number ) ;
1136
1137 ! 14.1.6 - Setting and Reading the WM_HINTS Property
1138
1139 ! 17.1.7 - Setting and Reading the WM_NORMAL_HINTS Property
1140
1141 : USPosition   ( -- n ) 0 2^ ; inline
1142 : USSize       ( -- n ) 1 2^ ; inline
1143 : PPosition    ( -- n ) 2 2^ ; inline
1144 : PSize        ( -- n ) 3 2^ ; inline
1145 : PMinSize     ( -- n ) 4 2^ ; inline
1146 : PMaxSize     ( -- n ) 5 2^ ; inline
1147 : PResizeInc   ( -- n ) 6 2^ ; inline
1148 : PAspect      ( -- n ) 7 2^ ; inline
1149 : PBaseSize    ( -- n ) 8 2^ ; inline
1150 : PWinGravity  ( -- n ) 9 2^ ; inline
1151 : PAllHints    ( -- n )
1152     { PPosition PSize PMinSize PMaxSize PResizeInc PAspect } flags ; foldable
1153
1154 C-STRUCT: XSizeHints
1155     { "long" "flags" }
1156     { "int" "x" }
1157     { "int" "y" }
1158     { "int" "width" }
1159     { "int" "height" }
1160     { "int" "min_width" }
1161     { "int" "min_height" }
1162     { "int" "max_width" }
1163     { "int" "max_height" }
1164     { "int" "width_inc" }
1165     { "int" "height_inc" }
1166     { "int" "min_aspect_x" }
1167     { "int" "min_aspect_y" }
1168     { "int" "max_aspect_x" }
1169     { "int" "max_aspect_y" }
1170     { "int" "base_width" }
1171     { "int" "base_height" }
1172     { "int" "win_gravity" } ;
1173
1174 ! 14.1.10.  Setting and Reading the WM_PROTOCOLS Property
1175
1176 FUNCTION: Status XSetWMProtocols (
1177         Display* display, Window w, Atom* protocols, int count ) ;
1178
1179 FUNCTION: Status XGetWMProtocols (
1180         Display* display,
1181         Window w,
1182         Atom** protocols_return,
1183         int* count_return ) ;
1184
1185 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1186 ! 16 - Application Utility Functions
1187 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1188
1189 ! 16.1 Keyboard Utility Functions
1190
1191 FUNCTION: KeySym XLookupKeysym ( XKeyEvent* key_event, int index ) ;
1192
1193 FUNCTION: int XLookupString (
1194         XKeyEvent* event_struct,
1195         void* buffer_return,
1196         int bytes_buffer,
1197         KeySym* keysym_return,
1198         XComposeStatus* status_in_out ) ;
1199
1200 ! 16.7 Determining the Appropriate Visual Type
1201
1202 : VisualNoMask                  HEX: 0 ; inline
1203 : VisualIDMask                  HEX: 1 ; inline
1204 : VisualScreenMask              HEX: 2 ; inline
1205 : VisualDepthMask               HEX: 4 ; inline
1206 : VisualClassMask               HEX: 8 ; inline
1207 : VisualRedMaskMask             HEX: 10 ; inline
1208 : VisualGreenMaskMask           HEX: 20 ; inline
1209 : VisualBlueMaskMask            HEX: 40 ; inline
1210 : VisualColormapSizeMask        HEX: 80 ; inline
1211 : VisualBitsPerRGBMask          HEX: 100 ; inline
1212 : VisualAllMask                 HEX: 1FF ; inline
1213
1214 C-STRUCT: XVisualInfo
1215         { "Visual*" "visual" }
1216         { "VisualID" "visualid" }
1217         { "int" "screen" }
1218         { "uint" "depth" }
1219         { "int" "class" }
1220         { "ulong" "red_mask" }
1221         { "ulong" "green_mask" }
1222         { "ulong" "blue_mask" }
1223         { "int" "colormap_size" }
1224         { "int" "bits_per_rgb" } ;
1225
1226 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1227 ! Appendix D - Compatibility Functions
1228 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1229
1230 FUNCTION: Status XSetStandardProperties (
1231         Display* display,
1232         Window w,
1233         char* window_name,
1234         char* icon_name,
1235         Pixmap icon_pixmap,
1236         char** argv,
1237         int argc,
1238         XSizeHints* hints ) ;
1239
1240 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1241
1242 : XA_PRIMARY  1 ; inline
1243 : XA_SECONDARY 2 ; inline
1244 : XA_ARC 3 ; inline
1245 : XA_ATOM 4 ; inline
1246 : XA_BITMAP 5 ; inline
1247 : XA_CARDINAL 6 ; inline
1248 : XA_COLORMAP 7 ; inline
1249 : XA_CURSOR 8 ; inline
1250 : XA_CUT_BUFFER0 9 ; inline
1251 : XA_CUT_BUFFER1 10 ; inline
1252 : XA_CUT_BUFFER2 11 ; inline
1253 : XA_CUT_BUFFER3 12 ; inline
1254 : XA_CUT_BUFFER4 13 ; inline
1255 : XA_CUT_BUFFER5 14 ; inline
1256 : XA_CUT_BUFFER6 15 ; inline
1257 : XA_CUT_BUFFER7 16 ; inline
1258 : XA_DRAWABLE 17 ; inline
1259 : XA_FONT 18 ; inline
1260 : XA_INTEGER 19 ; inline
1261 : XA_PIXMAP 20 ; inline
1262 : XA_POINT 21 ; inline
1263 : XA_RECTANGLE 22 ; inline
1264 : XA_RESOURCE_MANAGER 23 ; inline
1265 : XA_RGB_COLOR_MAP 24 ; inline
1266 : XA_RGB_BEST_MAP 25 ; inline
1267 : XA_RGB_BLUE_MAP 26 ; inline
1268 : XA_RGB_DEFAULT_MAP 27 ; inline
1269 : XA_RGB_GRAY_MAP 28 ; inline
1270 : XA_RGB_GREEN_MAP 29 ; inline
1271 : XA_RGB_RED_MAP 30 ; inline
1272 : XA_STRING 31 ; inline
1273 : XA_VISUALID 32 ; inline
1274 : XA_WINDOW 33 ; inline
1275 : XA_WM_COMMAND 34 ; inline
1276 : XA_WM_HINTS 35 ; inline
1277 : XA_WM_CLIENT_MACHINE 36 ; inline
1278 : XA_WM_ICON_NAME 37 ; inline
1279 : XA_WM_ICON_SIZE 38 ; inline
1280 : XA_WM_NAME 39 ; inline
1281 : XA_WM_NORMAL_HINTS 40 ; inline
1282 : XA_WM_SIZE_HINTS 41 ; inline
1283 : XA_WM_ZOOM_HINTS 42 ; inline
1284 : XA_MIN_SPACE 43 ; inline
1285 : XA_NORM_SPACE 44 ; inline
1286 : XA_MAX_SPACE 45 ; inline
1287 : XA_END_SPACE 46 ; inline
1288 : XA_SUPERSCRIPT_X 47 ; inline
1289 : XA_SUPERSCRIPT_Y 48 ; inline
1290 : XA_SUBSCRIPT_X 49 ; inline
1291 : XA_SUBSCRIPT_Y 50 ; inline
1292 : XA_UNDERLINE_POSITION 51 ; inline
1293 : XA_UNDERLINE_THICKNESS 52 ; inline
1294 : XA_STRIKEOUT_ASCENT 53 ; inline
1295 : XA_STRIKEOUT_DESCENT 54 ; inline
1296 : XA_ITALIC_ANGLE 55 ; inline
1297 : XA_X_HEIGHT 56 ; inline
1298 : XA_QUAD_WIDTH 57 ; inline
1299 : XA_WEIGHT 58 ; inline
1300 : XA_POINT_SIZE 59 ; inline
1301 : XA_RESOLUTION 60 ; inline
1302 : XA_COPYRIGHT 61 ; inline
1303 : XA_NOTICE 62 ; inline
1304 : XA_FONT_NAME 63 ; inline
1305 : XA_FAMILY_NAME 64 ; inline
1306 : XA_FULL_NAME 65 ; inline
1307 : XA_CAP_HEIGHT 66 ; inline
1308 : XA_WM_CLASS 67 ; inline
1309 : XA_WM_TRANSIENT_FOR 68 ; inline
1310
1311 : XA_LAST_PREDEFINED 68 ; inline
1312     
1313 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1314 ! The rest of the stuff is not from the book.
1315 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1316
1317 FUNCTION: void XFree ( void* data ) ;
1318 FUNCTION: int XStoreName ( Display* display, Window w, char* window_name ) ;
1319 FUNCTION: void XSetWMNormalHints ( Display* display, Window w, XSizeHints* hints ) ;
1320 FUNCTION: int XBell ( Display* display, int percent ) ;
1321
1322 ! !!! INPUT METHODS
1323
1324 : XIMPreeditArea      HEX: 0001 ; inline
1325 : XIMPreeditCallbacks HEX: 0002 ; inline
1326 : XIMPreeditPosition  HEX: 0004 ; inline
1327 : XIMPreeditNothing   HEX: 0008 ; inline
1328 : XIMPreeditNone      HEX: 0010 ; inline
1329 : XIMStatusArea       HEX: 0100 ; inline
1330 : XIMStatusCallbacks  HEX: 0200 ; inline
1331 : XIMStatusNothing    HEX: 0400 ; inline
1332 : XIMStatusNone       HEX: 0800 ; inline
1333
1334 : XNVaNestedList "XNVaNestedList" ;
1335 : XNQueryInputStyle "queryInputStyle" ;
1336 : XNClientWindow "clientWindow" ;
1337 : XNInputStyle "inputStyle" ;
1338 : XNFocusWindow "focusWindow" ;
1339 : XNResourceName "resourceName" ;
1340 : XNResourceClass "resourceClass" ;
1341 : XNGeometryCallback "geometryCallback" ;
1342 : XNDestroyCallback "destroyCallback" ;
1343 : XNFilterEvents "filterEvents" ;
1344 : XNPreeditStartCallback "preeditStartCallback" ;
1345 : XNPreeditDoneCallback "preeditDoneCallback" ;
1346 : XNPreeditDrawCallback "preeditDrawCallback" ;
1347 : XNPreeditCaretCallback "preeditCaretCallback" ;
1348 : XNPreeditStateNotifyCallback "preeditStateNotifyCallback" ;
1349 : XNPreeditAttributes "preeditAttributes" ;
1350 : XNStatusStartCallback "statusStartCallback" ;
1351 : XNStatusDoneCallback "statusDoneCallback" ;
1352 : XNStatusDrawCallback "statusDrawCallback" ;
1353 : XNStatusAttributes "statusAttributes" ;
1354 : XNArea "area" ;
1355 : XNAreaNeeded "areaNeeded" ;
1356 : XNSpotLocation "spotLocation" ;
1357 : XNColormap "colorMap" ;
1358 : XNStdColormap "stdColorMap" ;
1359 : XNForeground "foreground" ;
1360 : XNBackground "background" ;
1361 : XNBackgroundPixmap "backgroundPixmap" ;
1362 : XNFontSet "fontSet" ;
1363 : XNLineSpace "lineSpace" ;
1364 : XNCursor "cursor" ;
1365
1366 : XNQueryIMValuesList "queryIMValuesList" ;
1367 : XNQueryICValuesList "queryICValuesList" ;
1368 : XNVisiblePosition "visiblePosition" ;
1369 : XNR6PreeditCallback "r6PreeditCallback" ;
1370 : XNStringConversionCallback "stringConversionCallback" ;
1371 : XNStringConversion "stringConversion" ;
1372 : XNResetState "resetState" ;
1373 : XNHotKey "hotKey" ;
1374 : XNHotKeyState "hotKeyState" ;
1375 : XNPreeditState "preeditState" ;
1376 : XNSeparatorofNestedList "separatorofNestedList" ;
1377
1378 : XBufferOverflow -1 ;
1379 : XLookupNone      1 ;
1380 : XLookupChars     2 ;
1381 : XLookupKeySym    3 ;
1382 : XLookupBoth      4 ;
1383
1384 FUNCTION: Bool XFilterEvent ( XEvent* event, Window w ) ;
1385
1386 FUNCTION: XIM XOpenIM ( Display* dpy, void* rdb, char* res_name, char* res_class ) ;
1387
1388 FUNCTION: Status XCloseIM ( XIM im ) ;
1389
1390 FUNCTION: XIC XCreateIC ( XIM im, char* key1, Window value1, char* key2, Window value2, char* key3, int value3, char* key4, char* value4, char* key5, char* value5, int key6 ) ;
1391
1392 FUNCTION: void XDestroyIC ( XIC ic ) ;
1393
1394 FUNCTION: void XSetICFocus ( XIC ic ) ;
1395         
1396 FUNCTION: void XUnsetICFocus ( XIC ic ) ;
1397
1398 FUNCTION: int XwcLookupString ( XIC ic, XKeyPressedEvent* event, ulong* buffer_return, int bytes_buffer, KeySym* keysym_return, Status* status_return ) ;
1399
1400 FUNCTION: int Xutf8LookupString ( XIC ic, XKeyPressedEvent* event, char* buffer_return, int bytes_buffer, KeySym* keysym_return, Status* status_return ) ;
1401
1402 ! !!! category of setlocale
1403 : LC_ALL      0 ; inline
1404 : LC_COLLATE  1 ; inline
1405 : LC_CTYPE    2 ; inline
1406 : LC_MONETARY 3 ; inline
1407 : LC_NUMERIC  4 ; inline
1408 : LC_TIME     5 ; inline
1409
1410 FUNCTION: char* setlocale ( int category, char* name ) ;
1411
1412 FUNCTION: Bool XSupportsLocale ( ) ;
1413
1414 FUNCTION: char* XSetLocaleModifiers ( char* modifier_list ) ;
1415
1416 SYMBOL: dpy
1417 SYMBOL: scr
1418 SYMBOL: root
1419
1420 : init-locale ( -- )
1421    LC_ALL "" setlocale [ "setlocale() failed" print flush ] unless
1422    XSupportsLocale [ "XSupportsLocale() failed" print flush ] unless ;
1423
1424 : flush-dpy ( -- ) dpy get XFlush drop ;
1425
1426 : x-atom ( string -- atom ) dpy get swap 0 XInternAtom ;
1427
1428 : check-display ( alien -- alien' )
1429     [
1430         "Cannot connect to X server - check $DISPLAY" throw
1431     ] unless* ;
1432
1433 : initialize-x ( display-string -- )
1434     init-locale
1435     dup [ ascii string>alien ] when
1436     XOpenDisplay check-display dpy set-global
1437     dpy get XDefaultScreen scr set-global
1438     dpy get scr get XRootWindow root set-global ;
1439
1440 : close-x ( -- ) dpy get XCloseDisplay drop ;
1441
1442 : with-x ( display-string quot -- )
1443     [ initialize-x ] dip [ close-x ] [ ] cleanup ;