]> gitweb.factorcode.org Git - factor.git/blob - basis/x11/X/X.factor
Switch to https urls
[factor.git] / basis / x11 / X / X.factor
1 ! Copyright (C) 2005, 2006 Eduardo Cavazos and Alex Chapman, 2016 Björn Lindqvist
2 ! https://factorcode.org/license.txt for BSD license.
3
4 ! Selected parts of /usr/include/X11/X.h
5 USING: alien.c-types alien.syntax math ;
6 IN: x11.X
7
8 ! Resources
9 TYPEDEF: ulong XID
10 TYPEDEF: ulong Mask
11 TYPEDEF: ulong Atom
12 TYPEDEF: XID Window
13 TYPEDEF: XID Drawable
14 TYPEDEF: XID Font
15 TYPEDEF: XID Pixmap
16 TYPEDEF: XID Cursor
17 TYPEDEF: XID Colormap
18 TYPEDEF: XID GContext
19 TYPEDEF: XID KeySym
20
21 TYPEDEF: uchar KeyCode
22
23 ! Reserved resource and constant definitions
24 CONSTANT: ParentRelative 1
25 CONSTANT: CopyFromParent 0
26 CONSTANT: PointerWindow 0
27 CONSTANT: InputFocus 1
28 CONSTANT: PointerRoot 1
29 CONSTANT: AnyPropertyType 0
30 CONSTANT: AnyKey 0
31 CONSTANT: AnyButton 0
32 CONSTANT: AllTemporary 0
33 CONSTANT: CurrentTime 0
34 CONSTANT: NoSymbol 0
35
36 CONSTANT: None 0
37
38 ! Input Event Masks. Used as event-mask window attribute and as
39 ! arguments to Grab requests. Not to be confused with event names.
40 : NoEventMask              ( -- n ) 0 ; inline
41 : KeyPressMask             ( -- n ) 0 2^ ; inline
42 : KeyReleaseMask           ( -- n ) 1 2^ ; inline
43 : ButtonPressMask          ( -- n ) 2 2^ ; inline
44 : ButtonReleaseMask        ( -- n ) 3 2^ ; inline
45 : EnterWindowMask          ( -- n ) 4 2^ ; inline
46 : LeaveWindowMask          ( -- n ) 5 2^ ; inline
47 : PointerMotionMask        ( -- n ) 6 2^ ; inline
48 : PointerMotionHintMask    ( -- n ) 7 2^ ; inline
49 : Button1MotionMask        ( -- n ) 8 2^ ; inline
50 : Button2MotionMask        ( -- n ) 9 2^ ; inline
51 : Button3MotionMask        ( -- n ) 10 2^ ; inline
52 : Button4MotionMask        ( -- n ) 11 2^ ; inline
53 : Button5MotionMask        ( -- n ) 12 2^ ; inline
54 : ButtonMotionMask         ( -- n ) 13 2^ ; inline
55 : KeymapStateMask          ( -- n ) 14 2^ ; inline
56 : ExposureMask             ( -- n ) 15 2^ ; inline
57 : VisibilityChangeMask     ( -- n ) 16 2^ ; inline
58 : StructureNotifyMask      ( -- n ) 17 2^ ; inline
59 : ResizeRedirectMask       ( -- n ) 18 2^ ; inline
60 : SubstructureNotifyMask   ( -- n ) 19 2^ ; inline
61 : SubstructureRedirectMask ( -- n ) 20 2^ ; inline
62 : FocusChangeMask          ( -- n ) 21 2^ ; inline
63 : PropertyChangeMask       ( -- n ) 22 2^ ; inline
64 : ColormapChangeMask       ( -- n ) 23 2^ ; inline
65 : OwnerGrabButtonMask      ( -- n ) 24 2^ ; inline
66
67 ! Event names. Used in "type" field in XEvent structures. Not to be
68 ! confused with event masks above. They start from 2 because 0 and 1
69 ! are reserved in the protocol for errors and replies.
70 CONSTANT: KeyPress              2
71 CONSTANT: KeyRelease            3
72 CONSTANT: ButtonPress           4
73 CONSTANT: ButtonRelease         5
74 CONSTANT: MotionNotify          6
75 CONSTANT: EnterNotify           7
76 CONSTANT: LeaveNotify           8
77 CONSTANT: FocusIn               9
78 CONSTANT: FocusOut              10
79 CONSTANT: KeymapNotify          11
80 CONSTANT: Expose                12
81 CONSTANT: GraphicsExpose        13
82 CONSTANT: NoExpose              14
83 CONSTANT: VisibilityNotify      15
84 CONSTANT: CreateNotify          16
85 CONSTANT: DestroyNotify         17
86 CONSTANT: UnmapNotify           18
87 CONSTANT: MapNotify             19
88 CONSTANT: MapRequest            20
89 CONSTANT: ReparentNotify        21
90 CONSTANT: ConfigureNotify       22
91 CONSTANT: ConfigureRequest      23
92 CONSTANT: GravityNotify         24
93 CONSTANT: ResizeRequest         25
94 CONSTANT: CirculateNotify       26
95 CONSTANT: CirculateRequest      27
96 CONSTANT: PropertyNotify        28
97 CONSTANT: SelectionClear        29
98 CONSTANT: SelectionRequest      30
99 CONSTANT: SelectionNotify       31
100 CONSTANT: ColormapNotify        32
101 CONSTANT: ClientMessage         33
102 CONSTANT: MappingNotify         34
103 CONSTANT: GenericEvent          35
104 CONSTANT: LASTEvent             36
105
106 ! Key masks. Used as modifiers to GrabButton and GrabKey, results of
107 ! QueryPointer, state in various key-, mouse-, and button-related
108 ! events.
109 : ShiftMask   ( -- n ) 1 0 shift ; inline
110 : LockMask    ( -- n ) 1 1 shift ; inline
111 : ControlMask ( -- n ) 1 2 shift ; inline
112 : Mod1Mask    ( -- n ) 1 3 shift ; inline
113 : Mod2Mask    ( -- n ) 1 4 shift ; inline
114 : Mod3Mask    ( -- n ) 1 5 shift ; inline
115 : Mod4Mask    ( -- n ) 1 6 shift ; inline
116 : Mod5Mask    ( -- n ) 1 7 shift ; inline
117
118 ! modifier names.  Used to build a SetModifierMapping request or
119 ! to read a GetModifierMapping request.  These correspond to the
120 ! masks defined above.
121 CONSTANT: ShiftMapIndex 0
122 CONSTANT: LockMapIndex 1
123 CONSTANT: ControlMapIndex 2
124 CONSTANT: Mod1MapIndex 3
125 CONSTANT: Mod2MapIndex 4
126 CONSTANT: Mod3MapIndex 5
127 CONSTANT: Mod4MapIndex 6
128 CONSTANT: Mod5MapIndex 7
129
130 ! button masks. Used in same manner as Key masks above. Not to be
131 ! confused with button names below.
132 : Button1Mask ( -- n ) 1 8  shift ; inline
133 : Button2Mask ( -- n ) 1 9  shift ; inline
134 : Button3Mask ( -- n ) 1 10 shift ; inline
135 : Button4Mask ( -- n ) 1 11 shift ; inline
136 : Button5Mask ( -- n ) 1 12 shift ; inline
137
138 : AnyModifier          ( -- n ) 15 2^ ; ! used in GrabButton, GrabKey
139
140 ! button names. Used as arguments to GrabButton and as detail in
141 ! ButtonPress and ButtonRelease events.  Not to be confused with
142 ! button masks above. Note that 0 is already defined above as
143 ! "AnyButton".  */
144 CONSTANT: Button1 1
145 CONSTANT: Button2 2
146 CONSTANT: Button3 3
147 CONSTANT: Button4 4
148 CONSTANT: Button5 5
149
150 ! Notify modes
151
152 CONSTANT: NotifyNormal 0
153 CONSTANT: NotifyGrab 1
154 CONSTANT: NotifyUngrab 2
155 CONSTANT: NotifyWhileGrabbed 3
156
157 CONSTANT: NotifyHint 1 ! for MotionNotify events
158
159 ! Notify detail
160
161 CONSTANT: NotifyAncestor 0
162 CONSTANT: NotifyVirtual 1
163 CONSTANT: NotifyInferior 2
164 CONSTANT: NotifyNonlinear 3
165 CONSTANT: NotifyNonlinearVirtual 4
166 CONSTANT: NotifyPointer 5
167 CONSTANT: NotifyPointerRoot 6
168 CONSTANT: NotifyDetailNone 7
169
170 ! Visibility notify
171
172 CONSTANT: VisibilityUnobscured 0
173 CONSTANT: VisibilityPartiallyObscured 1
174 CONSTANT: VisibilityFullyObscured 2
175
176 ! Circulation request
177
178 CONSTANT: PlaceOnTop 0
179 CONSTANT: PlaceOnBottom 1
180
181 ! protocol families
182
183 CONSTANT: FamilyInternet 0     ! IPv4
184 CONSTANT: FamilyDECnet 1
185 CONSTANT: FamilyChaos 2
186 CONSTANT: FamilyInternet6 6     ! IPv6
187
188 ! authentication families not tied to a specific protocol
189 CONSTANT: FamilyServerInterpreted 5
190
191 ! Property notification
192
193 CONSTANT: PropertyNewValue 0
194 CONSTANT: PropertyDelete 1
195
196 ! Color Map notification
197
198 CONSTANT: ColormapUninstalled 0
199 CONSTANT: ColormapInstalled 1
200
201 ! GrabPointer, GrabButton, GrabKeyboard, GrabKey Modes
202
203 CONSTANT: GrabModeSync 0
204 CONSTANT: GrabModeAsync 1
205
206 ! GrabPointer, GrabKeyboard reply status
207
208 CONSTANT: GrabSuccess 0
209 CONSTANT: AlreadyGrabbed 1
210 CONSTANT: GrabInvalidTime 2
211 CONSTANT: GrabNotViewable 3
212 CONSTANT: GrabFrozen 4
213
214 ! AllowEvents modes
215
216 CONSTANT: AsyncPointer 0
217 CONSTANT: SyncPointer 1
218 CONSTANT: ReplayPointer 2
219 CONSTANT: AsyncKeyboard 3
220 CONSTANT: SyncKeyboard 4
221 CONSTANT: ReplayKeyboard 5
222 CONSTANT: AsyncBoth 6
223 CONSTANT: SyncBoth 7
224
225 ! Used in SetInputFocus, GetInputFocus
226
227 : RevertToNone         ( -- n ) None ;
228 : RevertToPointerRoot  ( -- n ) PointerRoot ;
229 CONSTANT: RevertToParent 2
230
231 ! *****************************************************************
232 ! * ERROR CODES
233 ! *****************************************************************
234
235 CONSTANT: Success 0         ! everything's okay
236 CONSTANT: BadRequest 1      ! bad request code
237 CONSTANT: BadValue 2        ! int parameter out of range
238 CONSTANT: BadWindow 3       ! parameter not a Window
239 CONSTANT: BadPixmap 4       ! parameter not a Pixmap
240 CONSTANT: BadAtom 5         ! parameter not an Atom
241 CONSTANT: BadCursor 6       ! parameter not a Cursor
242 CONSTANT: BadFont 7         ! parameter not a Font
243 CONSTANT: BadMatch 8        ! parameter mismatch
244 CONSTANT: BadDrawable 9     ! parameter not a Pixmap or Window
245 CONSTANT: BadAccess 10      ! depending on context:
246                             !         - key/button already grabbed
247                             !         - attempt to free an illegal
248                             !           cmap entry
249                             !        - attempt to store into a read-only
250                             !           color map entry.
251                             !        - attempt to modify the access control
252                             !           list from other than the local host.
253 CONSTANT: BadAlloc 11       ! insufficient resources
254 CONSTANT: BadColor 12       ! no such colormap
255 CONSTANT: BadGC 13          ! parameter not a GC
256 CONSTANT: BadIDChoice 14    ! choice not in range or already used
257 CONSTANT: BadName 15        ! font or color name doesn't exist
258 CONSTANT: BadLength 16      ! Request length incorrect
259 CONSTANT: BadImplementation 17  ! server is defective
260
261 CONSTANT: FirstExtensionError 128
262 CONSTANT: LastExtensionError 255
263
264 ! *****************************************************************
265 ! * WINDOW DEFINITIONS
266 ! *****************************************************************
267
268 ! Window classes used by CreateWindow
269 ! Note that CopyFromParent is already defined as 0 above
270
271 CONSTANT: InputOutput 1
272 CONSTANT: InputOnly 2
273
274 ! ConfigureWindow structure
275 : CWX           ( -- n ) 0 2^ ; inline
276 : CWY           ( -- n ) 1 2^ ; inline
277 : CWWidth       ( -- n ) 2 2^ ; inline
278 : CWHeight      ( -- n ) 3 2^ ; inline
279 : CWBorderWidth ( -- n ) 4 2^ ; inline
280 : CWSibling     ( -- n ) 5 2^ ; inline
281 : CWStackMode   ( -- n ) 6 2^ ; inline
282
283 ! Bit Gravity
284
285 CONSTANT: ForgetGravity         0
286 CONSTANT: NorthWestGravity      1
287 CONSTANT: NorthGravity          2
288 CONSTANT: NorthEastGravity      3
289 CONSTANT: WestGravity           4
290 CONSTANT: CenterGravity         5
291 CONSTANT: EastGravity           6
292 CONSTANT: SouthWestGravity      7
293 CONSTANT: SouthGravity          8
294 CONSTANT: SouthEastGravity      9
295 CONSTANT: StaticGravity         10
296
297 ! Window gravity + bit gravity above
298
299 CONSTANT: UnmapGravity          0
300
301 ! Used in CreateWindow for backing-store hint
302
303 CONSTANT: NotUseful 0
304 CONSTANT: WhenMapped 1
305 CONSTANT: Always 2
306
307 ! Used in GetWindowAttributes reply
308 CONSTANT: IsUnmapped            0
309 CONSTANT: IsUnviewable          1
310 CONSTANT: IsViewable            2
311
312
313 ! Used in ChangeSaveSet
314
315 CONSTANT: SetModeInsert 0
316 CONSTANT: SetModeDelete 1
317
318 ! Used in ChangeCloseDownMode
319
320 CONSTANT: DestroyAll 0
321 CONSTANT: RetainPermanent 1
322 CONSTANT: RetainTemporary 2
323
324 ! Window stacking method (in configureWindow)
325
326 CONSTANT: Above 0
327 CONSTANT: Below 1
328 CONSTANT: TopIf 2
329 CONSTANT: BottomIf 3
330 CONSTANT: Opposite 4
331
332 ! Circulation direction
333
334 CONSTANT: RaiseLowest 0
335 CONSTANT: LowerHighest 1
336
337 ! Property modes
338
339 CONSTANT: PropModeReplace 0
340 CONSTANT: PropModePrepend 1
341 CONSTANT: PropModeAppend 2
342
343 ! *****************************************************************
344 ! * GRAPHICS DEFINITIONS
345 ! *****************************************************************
346
347 ! graphics functions, as in GC.alu
348
349 CONSTANT: GXclear               0x0
350 CONSTANT: GXand                 0x1
351 CONSTANT: GXandReverse          0x2
352 CONSTANT: GXcopy                0x3
353 CONSTANT: GXandInverted         0x4
354 CONSTANT: GXnoop                0x5
355 CONSTANT: GXxor                 0x6
356 CONSTANT: GXor                  0x7
357 CONSTANT: GXnor                 0x8
358 CONSTANT: GXequiv               0x9
359 CONSTANT: GXinvert              0xa
360 CONSTANT: GXorReverse           0xb
361 CONSTANT: GXcopyInverted        0xc
362 CONSTANT: GXorInverted          0xd
363 CONSTANT: GXnand                0xe
364 CONSTANT: GXset                 0xf
365
366 ! LineStyle
367
368 CONSTANT: LineSolid 0
369 CONSTANT: LineOnOffDash 1
370 CONSTANT: LineDoubleDash 2
371
372 ! capStyle
373
374 CONSTANT: CapNotLast 0
375 CONSTANT: CapButt 1
376 CONSTANT: CapRound 2
377 CONSTANT: CapProjecting 3
378
379 ! joinStyle
380
381 CONSTANT: JoinMiter 0
382 CONSTANT: JoinRound 1
383 CONSTANT: JoinBevel 2
384
385 ! fillStyle
386
387 CONSTANT: FillSolid 0
388 CONSTANT: FillTiled 1
389 CONSTANT: FillStippled 2
390 CONSTANT: FillOpaqueStippled 3
391
392 ! fillRule
393
394 CONSTANT: EvenOddRule 0
395 CONSTANT: WindingRule 1
396
397 ! subwindow mode
398
399 CONSTANT: ClipByChildren 0
400 CONSTANT: IncludeInferiors 1
401
402 ! SetClipRectangles ordering
403
404 CONSTANT: Unsorted 0
405 CONSTANT: YSorted 1
406 CONSTANT: YXSorted 2
407 CONSTANT: YXBanded 3
408
409 ! CoordinateMode for drawing routines
410
411 CONSTANT: CoordModeOrigin 0     ! relative to the origin
412 CONSTANT: CoordModePrevious 1   ! relative to previous point
413
414 ! Polygon shapes
415
416 CONSTANT: Complex 0 ! paths may intersect
417 CONSTANT: Nonconvex 1 ! no paths intersect, but not convex
418 CONSTANT: Convex 2 ! wholly convex
419
420 ! Arc modes for PolyFillArc
421
422 CONSTANT: ArcChord 0 ! join endpoints of arc
423 CONSTANT: ArcPieSlice 1 ! join endpoints to center of arc
424
425 ! GC components: masks used in CreateGC, CopyGC, ChangeGC, OR'ed into
426 ! GC.stateChanges
427
428 : GCFunction          ( -- n ) 0 2^ ; inline
429 : GCPlaneMask         ( -- n ) 1 2^ ; inline
430 : GCForeground        ( -- n ) 2 2^ ; inline
431 : GCBackground        ( -- n ) 3 2^ ; inline
432 : GCLineWidth         ( -- n ) 4 2^ ; inline
433 : GCLineStyle         ( -- n ) 5 2^ ; inline
434 : GCCapStyle          ( -- n ) 6 2^ ; inline
435 : GCJoinStyle         ( -- n ) 7 2^ ; inline
436 : GCFillStyle         ( -- n ) 8 2^ ; inline
437 : GCFillRule          ( -- n ) 9 2^ ; inline
438 : GCTile              ( -- n ) 10 2^ ; inline
439 : GCStipple           ( -- n ) 11 2^ ; inline
440 : GCTileStipXOrigin   ( -- n ) 12 2^ ; inline
441 : GCTileStipYOrigin   ( -- n ) 13 2^ ; inline
442 : GCFont              ( -- n ) 14 2^ ; inline
443 : GCSubwindowMode     ( -- n ) 15 2^ ; inline
444 : GCGraphicsExposures ( -- n ) 16 2^ ; inline
445 : GCClipXOrigin       ( -- n ) 17 2^ ; inline
446 : GCClipYOrigin       ( -- n ) 18 2^ ; inline
447 : GCClipMask          ( -- n ) 19 2^ ; inline
448 : GCDashOffset        ( -- n ) 20 2^ ; inline
449 : GCDashList          ( -- n ) 21 2^ ; inline
450 : GCArcMode           ( -- n ) 22 2^ ; inline
451
452 ! *****************************************************************
453 ! * FONTS
454 ! *****************************************************************
455
456 ! used in QueryFont -- draw direction
457
458 CONSTANT: FontLeftToRight 0
459 CONSTANT: FontRightToLeft 1
460
461 CONSTANT: FontChange 255
462
463 ! *****************************************************************
464 ! *  IMAGING
465 ! *****************************************************************
466
467 ! ImageFormat -- PutImage, GetImage
468
469 CONSTANT: XYBitmap 0    ! depth 1, XYFormat
470 CONSTANT: XYPixmap 1    ! depth == drawable depth
471 CONSTANT: ZPixmap 2     ! depth == drawable depth
472
473 ! *****************************************************************
474 ! *  COLOR MAP STUFF
475 ! *****************************************************************
476
477 ! For CreateColormap
478
479 CONSTANT: AllocNone 0   ! create map with no entries
480 CONSTANT: AllocAll 1    ! allocate entire map writeable
481
482
483 ! Flags used in StoreNamedColor, StoreColors
484
485 : DoRed        ( -- n ) 0 2^ ;
486 : DoGreen      ( -- n ) 1 2^ ;
487 : DoBlue       ( -- n ) 2 2^ ;
488
489 ! *****************************************************************
490 ! * CURSOR STUFF
491 ! *****************************************************************
492
493 ! QueryBestSize Class
494
495 CONSTANT: CursorShape 0     ! largest size that can be displayed
496 CONSTANT: TileShape 1       ! size tiled fastest
497 CONSTANT: StippleShape 2    ! size stippled fastest
498
499 ! *****************************************************************
500 ! * KEYBOARD/POINTER STUFF
501 ! *****************************************************************
502
503 CONSTANT: AutoRepeatModeOff 0
504 CONSTANT: AutoRepeatModeOn 1
505 CONSTANT: AutoRepeatModeDefault 2
506
507 CONSTANT: LedModeOff 0
508 CONSTANT: LedModeOn 1
509
510 ! masks for ChangeKeyboardControl
511
512 : KBKeyClickPercent    ( -- n ) 0 2^ ;
513 : KBBellPercent        ( -- n ) 1 2^ ;
514 : KBBellPitch          ( -- n ) 2 2^ ;
515 : KBBellDuration       ( -- n ) 3 2^ ;
516 : KBLed                ( -- n ) 4 2^ ;
517 : KBLedMode            ( -- n ) 5 2^ ;
518 : KBKey                ( -- n ) 6 2^ ;
519 : KBAutoRepeatMode     ( -- n ) 7 2^ ;
520
521 CONSTANT: MappingSuccess 0
522 CONSTANT: MappingBusy 1
523 CONSTANT: MappingFailed 2
524
525 CONSTANT: MappingModifier 0
526 CONSTANT: MappingKeyboard 1
527 CONSTANT: MappingPointer 2
528
529 ! *****************************************************************
530 ! * SCREEN SAVER STUFF
531 ! *****************************************************************
532
533 CONSTANT: DontPreferBlanking 0
534 CONSTANT: PreferBlanking 1
535 CONSTANT: DefaultBlanking 2
536
537 CONSTANT: DisableScreenSaver 0
538 CONSTANT: DisableScreenInterval 0
539
540 CONSTANT: DontAllowExposures 0
541 CONSTANT: AllowExposures 1
542 CONSTANT: DefaultExposures 2
543
544 ! for ForceScreenSaver
545
546 CONSTANT: ScreenSaverReset 0
547 CONSTANT: ScreenSaverActive 1
548
549 ! *****************************************************************
550 ! * HOSTS AND CONNECTIONS
551 ! *****************************************************************
552
553 ! for ChangeHosts
554
555 CONSTANT: HostInsert 0
556 CONSTANT: HostDelete 1
557
558 ! for ChangeAccessControl
559
560 CONSTANT: EnableAccess 1
561 CONSTANT: DisableAccess 0
562
563 ! Display classes  used in opening the connection
564 ! Note that the statically allocated ones are even numbered and the
565 ! dynamically changeable ones are odd numbered
566
567 CONSTANT: StaticGray 0
568 CONSTANT: GrayScale 1
569 CONSTANT: StaticColor 2
570 CONSTANT: PseudoColor 3
571 CONSTANT: TrueColor 4
572 CONSTANT: DirectColor 5
573
574 ! Byte order  used in imageByteOrder and bitmapBitOrder
575
576 CONSTANT: LSBFirst 0
577 CONSTANT: MSBFirst 1