upload tizen2.0 source
[framework/uifw/xorg/proto/x11proto-input.git] / specs / XI2proto.txt
1 The X Input Extension 2.x
2 =========================
3 :toc:
4 :numbered:
5
6 Authors:
7
8 - Peter Hutterer (Red Hat) <peter.hutterer@redhat.com>
9 - Daniel Stone (Collabora Ltd.) <daniel@fooishbar.org>
10 - Chase Douglas (Canonical, Ltd.) <chase.douglas@canonical.com>
11
12 [[history]]
13 History 
14 -------
15
16 - v2.2, March 2012: Multitouch support added
17 - v2.1, December 2011: new raw event behaviour, smooth scrolling support
18   added
19 - v2.0, October 2009: Initial release of XI2 protocol
20
21 [[intro-xi20]]
22 Introduction
23 ------------
24
25 The X Input Extension version 2.0 (XI2) is the second major release of the X
26 Input Extension.
27
28 XI2 provides a number of enhancements over version 1.5, including:
29
30 - use of XGE and GenericEvents. GenericEvents are of flexible length with a
31   minimum length of 32 bytes.
32 - explicit device hierarchy of master and slave devices. See Section
33 <<hierarchy,The Master/Slave device hierarchy>>.
34 - use of multiple independent master devices (Multi-Poiner X or MPX).
35 - the ability for devices to change capabilities at runtime.
36 - raw device events
37
38 XI2's intent is to replace both core input processing and prior versions of
39 the X Input Extension. Historically, the majority of applications employed the
40 core protocol requests and events to handle user input. The core protocol does
41 not provide information about which device generated the event. The X Input
42 Extension version up to 1.5 requires the differentiation between core and
43 extended devices. Extended devices may not be core devices and thus cannot be
44 used on applications employing the core protocol. XI2 addresses both of these
45 issues by enabling devices to be both extended and core devices and providing
46 device information in each event (with the exception of core events).
47
48 Changes in version 2.1
49 ----------------------
50
51 - RawEvents are sent regardless of the grab state.
52 - Addition of the ScrollClass for smooth scrolling
53
54 Changes in version 2.2
55 ----------------------
56
57 - Multitouch support added
58
59
60 //                            ❧❧❧❧❧❧❧❧❧❧❧
61
62 Notations used in this document
63 -------------------------------
64
65 Notation for requests:
66
67     ┌───
68         Name of request
69             name of request field:       type of request field
70             name of request field:       type of request field
71             ▶
72             name of reply field:         type of reply field
73     └───
74
75 Notation for events:
76
77     ┌───
78         Name of event
79             name of field:               type of field
80             name of field:               type of field
81     └───
82
83 Complex fields are specified in the following notation:
84
85           name of field:                  COMPLEXFIELDTYPE
86
87 or, if multiple of these fields exist:
88
89           name of field:                  LISTofCOMPLEXFIELDTYPE
90
91     COMPLEXFIELDTYPE:  { name of subfield:   type of subfield,
92                          name of subfield:   type of subfield }
93
94 //                            ❧❧❧❧❧❧❧❧❧❧❧
95
96 Interoperability between version 1.x and 2.0
97 --------------------------------------------
98
99 There is little interaction between 1.x and 2.x versions of the X Input
100 Extension. Clients are requested to avoid mixing XI1.x and XI2 code as much as
101 possible. Several direct incompatibilities are observable:
102
103 [[interop-xi1-limitations]]
104 Limitations resulting from different variable ranges
105 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106
107 XI2 provides a larger range for some fields than XI1. As a result, XI1 clients
108 may not receive data an XI2 client receives.
109 These fields include:
110
111 - devices with a deviceid of greater than 127 are invisible to XI1 clients.
112 - key events and key grabs featuring larger than 255 can only be sent to XI2
113   clients.
114 - no subpixel information is available to XI1 clients. If motion events are in
115   a subpixel range only, the server may omit these events and an XI 1.x client
116   will not receive events until the pixel boundary is crossed.
117
118
119 [[interop-xi1-grabs]]
120 Blocking of grabs
121 ~~~~~~~~~~~~~~~~~
122
123 XI1 grabs are different to XI2 grab and a device may not be grabbed through an
124 XI2 grab if an XI1 grab is currently active on this device or vice versa.
125 Likewise, a keycode or button already grabbed by an XI 1.x or XI2 client may
126 not be grabbed with the same modifier combination by an XI2 or XI 1.x client,
127 respectively.
128
129 [[interop-xi1-device-list]]
130 Invisibility of Master Devices
131 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132
133 XI 1.x was not designed with support for multiple master devices. As a
134 result, only the first master pointer and master keyboard are visible to XI
135 1.x clients; all other master devices are invisible and cannot be accessed
136 from XI 1.x calls.
137
138 Smooth scrolling
139 ~~~~~~~~~~~~~~~~
140
141 Historically, X implemented scrolling events by using button press events:
142 button 4 was one “click” of the scroll wheel upwards, button 5 was downwards,
143 button 6 was one unit of scrolling left, and button 7 was one unit of scrolling
144 right.  This is insufficient for e.g. touchpads which are able to provide
145 scrolling events through multi-finger drag gestures, or simply dragging your
146 finger along a designated strip along the side of the touchpad.
147
148 Newer X servers may provide scrolling information through valuators to
149 provide clients with more precision than the legacy button events. This
150 scrolling information is part of the valuator data in device events.
151 Scrolling events do not have a specific event type.
152
153 Valuators for axes sending scrolling information must have one
154 ScrollClass for each scrolling axis. If scrolling valuators are present on a
155 device, the server must provide two-way emulation between these valuators
156 and the legacy button events for each delta unit of scrolling.
157
158 One unit of scrolling in either direction is considered to be equivalent to
159 one button event, e.g. for a unit size of 1.0, -2.0 on an valuator type
160 Vertical sends two button press/release events for button 4. Likewise, a
161 button press event for button 7 generates an event on the Horizontal
162 valuator with a value of +1.0. The server may accumulate deltas of less than
163 one unit of scrolling.
164
165 Any server providing this behaviour marks emulated button or valuator events
166 with the XIPointerEmulated flag for DeviceEvents, and the XIRawEmulated flag
167 for raw events, to hint at applications which event is a hardware event.
168
169 If more than one scroll valuator of the same type is present on a device,
170 the valuator marked with Preferred for the same scroll direction is used to
171 convert legacy button events into scroll valuator events. If no valuator is
172 marked Preferred or more than one valuator is marked with Preferred for this
173 scroll direction, this should be considered a driver bug and the behaviour
174 is implementation-dependent.
175
176 [[hierarchy]]
177 The Master/Slave device hierarchy
178 ---------------------------------
179
180 XI2 introduces a device hierarchy split up into so-called Master Devices (MD)
181 and Slave Devices (SD).
182
183 [[hierarchy-master]]
184 Master devices
185 ~~~~~~~~~~~~~~
186 An MD is a virtual device created and managed by the server. MDs may send core
187 events and XI events. However, an MD does not represent a physical device and
188 relies on SDs for event generation. MDs come in two forms: as master pointers
189 or as master keyboards. A master pointer is represented by a visible cursor on
190 the screen. A master keyboard is represented by a keyboard focus.
191
192 Each master pointer is paired with the respective master keyboard and vice
193 versa, and this pairing is constant for the lifetime of both input devices.
194 Clients can use this pairing behaviour to implement input paradigms that
195 require pointer and keyboard interation (e.g. SHIFT + Click).
196
197 [[hierarchy-slave]]
198 Slave devices
199 ~~~~~~~~~~~~~
200 An SD is usually a physical device configured in the server. SDs are not
201 represented by a cursor or keyboard focus and may be attached to a master
202 pointer or master keyboard. SDs can only be attached to any master of the same
203 type (e.g. a physical pointer device can be attached to any master pointer).
204
205 If an event is generated by an SD
206
207 - if the SD is attached to a master pointer, it changes the position and/or
208   button state of the master pointer.
209 - if the SD is attached to a master keyboard, it sends events to this
210   keyboard's focus window (if applicable) and/or changes the modifier state of
211   this keyboard.
212 - if the SD is not attached to an MD ("floating"), it does not change
213   any master device. The SD has its own (invisible) sprite and its own focus.
214   Both the sprite and the focus must be managed explicitly by the client
215   program.
216
217 [[hierarchy-dcce]]
218 Event processing for attached slave devices
219 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220
221 Whenever an SD changes its logical state,
222
223 - the event is delivered as an XI event to any interested clients. If the
224   device is floating, event processing stops.
225   Otherwise, if the device is attached,
226 - the master device changes its classes to reflect the SD's capabilities. All
227   interested clients are notified of this device change.
228 - then, the event is delivered as an XI event from the MD to any interested
229   clients. If the event has been delivered, event processing stops.
230   Otherwise,
231 - the event is delivered as a core event to any interested clients.
232
233 Given that W is the event window, and P the parent window of W, event delivery
234 to P is only attempted if neither the XI event, nor the core event has been
235 delivered on W. Once an event has been delivered as either XI or core event,
236 event processing stops.
237
238 [[clientpointer]]
239 The ClientPointer principle
240 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
241
242 Many core protocol and some extension requests are ambiguous when multiple
243 master devices are available (e.g. QueryPointer does not specify which pointer).
244 The X server does not have the knowledge to chose the contextually correct
245 master device. For each client, one master pointer is designated as this
246 clients's "ClientPointer". Whenever a client sends an ambiguous request (e.g.
247 QueryPointer), the ClientPointer or the keyboard paired with the ClientPointer
248 is chosen to provide the data for this request.
249
250 This ClientPointer may be explicitly assigned to a client with the
251 SetClientPointer call. If no ClientPointer is set when a client issues an
252 ambiguous request, the server choses one device as the ClientPointer. The
253 method of chosing a ClientPointer from the available master pointers is
254 implementation-specific.
255
256 If the master pointer currently set as ClientPointer for one or more clients is
257 removed, the server may either unset the ClientPointer setting or change the
258 ClientPointer to a different master pointer.
259
260 [[multitouch]]
261 Touch device support
262 --------------------
263
264 XI 2.2 introduces support for multi-touch devices. The traditional
265 pointer/keyboard approach enforced by XI 2.0 with the master/slave device
266 hierarchy is not always suitable for multi-touch devices that can provide a
267 dynamic number of touchpoints per physical device; it is not known without
268 client-specific interpretation whether the touchpoints must be considered
269 separately or grouped together.
270
271 The additions in XI 2.2 aim to:
272
273 - support a dynamic number of simultaneous touch points,
274 - support devices that are both multi-touch and traditional pointer devices,
275 - allow touchpoints to be either grouped together or handled separately,
276 - be backwards-compatible to pre-XI 2.2 clients through emulation of XI 2.x/XI 1.x and core
277   pointer events.
278
279 Touch events are only available to clients supporting version 2.2 or later of
280 the X Input Extension. Clients must use the XIQueryVersion request to announce
281 support for this version. Touch devices may generate emulated pointer events
282 alongside XI 2.2 touch events to support older clients; see Section
283 <<multitouch-processing,Touch event delivery>>.
284
285 Touch event processing differs from normal event processing in a few ways.
286 The most notable differences are that touch events are processed partially
287 out-of-band from pointer and keyboard events, and that touch events may be
288 sent to multiple clients simultaneously. For more details see Section
289 <<multitouch-processing, Touch event delivery>>.
290
291 [[multitouch-lifecycle]]
292 Touch event sequences
293 ~~~~~~~~~~~~~~~~~~~~~
294
295 Touch input follows a three-stage cycle:
296
297         begin - update - update - ... - end
298
299 i.e. “begin” the sequence by touching the device, “update” the current
300 touch location or properties any number of times, and finally “end” the
301 sequence by ceasing to touch the device.  Within this document, the term
302 "touch sequence" is used to describe the above sequence of events.
303 In the protocol, the three stages are represented with the event
304 types TouchBegin, TouchUpdate, and TouchEnd, respectively. A touch sequence
305 always generates TouchBegin and TouchEnd events, and may also generate
306 TouchUpdate events.  Clients must select for all three of these events
307 simultaneously.
308
309 When a touch starts, clients are sent a TouchBegin event
310 detailing the position of the touchpoint, as well as the
311 initial properties of the touchpoint.  Note that the logical state of the
312 device (as seen through the input protocol) may lag the physical state if event
313 processing is affected by grabs.  Multiple touchpoints may be active on the
314 same device at any time, potentially owned by and/or delivered to a different
315 set of clients.
316
317 Whenever the touch position or any other property of the touchpoint changes,
318 a TouchUpdate event is sent to all clients listening
319 to events for that touchpoint with the updated information.
320
321 When the touch has physically ended, or a client will otherwise not receive
322 any more events for a given touchpoint, a TouchEnd event will be sent to
323 that client.
324
325 Passive touch grabs are similar to standard input event grabs in that they
326 take precedence over event selections and are searched from the root window
327 to the child window (as opposed to selections, which start their search at the
328 child window and continue up to the root window).  When a touch grab activates,
329 the client whose grab activates becomes the “owner” of this touch sequence,
330 and must decide what to do with it, as per Section
331 <<multitouch-ownership,Ownership of touch sequences>>.  See the
332 <<requests-passivegrabdevice,XIPassiveGrabDevice>> request
333 documentation for more information on passive grab activation.
334
335 Only one client may select for touch events from a given device on a window.
336
337 [[multitouch-ownership]]
338 Ownership of touch sequences
339 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
340
341 Once a grabbing client becomes the owner of a touch, it must either “accept” or
342 "reject" the touch sequence using the XIAllowEvents request. If a touch sequence
343 is rejected, a TouchEnd event is sent to the rejecting client, and it will not
344 receive any more events for this touch.  The server then looks to the next
345 window in the stack for another passive grab, and attempts to pass ownership
346 on to the next candidate for a passive grab (i.e. the next window towards
347 the final child window with a matching grab), or to the first applicable
348 event selection if there are no more grabs.
349
350 If a touch sequence is accepted by its owner, all other clients receive
351 TouchEnd events, and the touch sequence is exclusively delivered to the
352 owner from that point on.
353
354 If the touch sequence physically ends while the owner of the touch sequence
355 has not yet accepted or rejected ownership, the owner receives a TouchEnd
356 event and all other clients receive a TouchUpdate event with the
357 TouchPendingEnd flag set. The owner must still accept or reject the sequence
358 nonetheless. If the owner rejects the touch sequence, the server will still
359 attempt to exhaust all other passive grabs and/or event selections looking
360 for a final owner.
361
362 If the touch sequence has not physically ended yet and the owner of the
363 touch sequence rejects, the owner receives a TouchEnd event and ownership is
364 passed to the next client.
365
366 Clients may opt for touch events to be delivered before they become the
367 owner of the touch sequence. In this case, the logical state of the device (as
368 seen by means of the protocol) always matches the physical state of the device.
369 Clients must use caution if they opt for this feature; any action taken must be
370 undone if the touch sequence ends without the client becoming the owner.
371
372 To select for touch events regardless of ownership, a client must set the
373 TouchOwnership event mask in addition to the
374 TouchBegin, TouchUpdate and TouchEnd mask. When selected, a client will receive
375 touch events as they occur on the device. If and when the client
376 becomes the owner of a touch sequence, a TouchOwnership event is sent to the
377 client. If the client is the initial owner of the sequence, the TouchBegin is
378 immediately followed by the TouchOwnership event. Otherwise, TouchUpdate events
379 may preceed a TouchOwnership event. A client is not guaranteed to become the
380 owner of any given touch sequence.
381
382 The server delivers touch events to all clients that have selected for
383 TouchOwnership and to the current owner of the sequence in parallel.
384
385 If a client has selected for TouchOwnership and is not the current owner of
386 the sequence and the current owner accepts the sequence, the client receives
387 a TouchEnd event and no further events from this sequence are sent to this
388 client.
389
390 If a client has selected for TouchOwnership and the physical touch ends
391 before the current owner has accepted or rejected the sequence, the client
392 receives a TouchUpdate event with the TouchPendingEnd flag set. No further
393 TouchUpdate events will be sent for this sequence. If the current owner
394 accepts the sequence, the client receives a TouchEnd event. Otherwise, if
395 the current owner rejects the sequence, the client may become 
396 the owner of the touch sequence and receive a TouchOwnership event and a
397 TouchEnd event.
398
399 [[multitouch-device-modes]]
400 Touch device modes
401 ~~~~~~~~~~~~~~~~~~
402
403 Touch devices come in many different forms with varying capabilities. The
404 following device modes are defined for this protocol:
405
406 'DirectTouch':
407     These devices map their input region to a subset of the screen region. Touch
408     events are delivered to window at the location of the touch. "direct"
409     here refers to the user manipulating objects at their screen location.
410     An example of a DirectTouch device is a touchscreen.
411
412 'DependentTouch':
413     These devices do not have a direct correlation between a touch location and
414     a position on the screen. Touch events are delivered according to the
415     location of the device's cursor and often need to be interpreted
416     relative to the current position of that cursor. Such interactions are
417     usually the result of a gesture performed on the device, rather than
418     direct manipulation. An example of a DependentTouch device is a
419     trackpad.
420
421 A device is identified as only one of the device modes above at any time, and
422 the touch mode may change at any time. If a device's touch mode changes, an
423 XIDeviceChangedEvent is generated.
424
425 [[multitouch-processing]]
426 Touch event delivery
427 ~~~~~~~~~~~~~~~~~~~~
428
429 For direct touch devices, the window set for event propagation is the set of
430 windows from the root window to the topmost window lying at the co-ordinates
431 of the touch.
432
433 For dependent devices, the window set for event propagation is the set of
434 windows from the root window to the window that contains the device's
435 pointer. A dependent device may only have one window set at a time, for all
436 touches. Any future touch sequence will use the same window set. The window set
437 is cleared when all touch sequences on the device end.
438
439 A window set is calculated on TouchBegin and remains constant until the end
440 of the sequence. Modifications to the window hierarchy, new grabs or changed
441 event selection do not affect the window set.
442
443 Pointer control of dependent devices
444 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
445 On a dependent device, the device may differ between a pointer-controlling
446 touch and a non-pointer-controlling touch. For example, on a touchpad the
447 first touch is pointer-controlling (i.e. serves only to move the visible
448 pointer). Multi-finger gestures on a touchpad cause all touches to be
449 non-pointer-controlling.
450
451 For pointer-controlling touches, no touch events are sent; the touch
452 generates regular pointer events instead. Non-pointer-controlling touches
453 send touch events. A touch may change from pointer-controlling to
454 non-pointer-controlling, or vice versa.
455
456 - If a touch changes from pointer-controlling to non-pointer-controlling,
457  a new touch ID is assigned and a TouchBegin is sent for the last known
458  position of the touch. Further events are sent as TouchUpdate events, or as
459  TouchEnd event if the touch terminates.
460
461 - If a touch changes from non-pointer-controlling to pointer-controlling, a
462   TouchEnd is sent for that touch at the last known position of the touch.
463   Further events are sent as pointer events.
464
465 The conditions to switch from pointer-controlling to non-pointer-controlling
466 touch is implementation-dependent. A device may support touches that are
467 both pointer-controlling and a touch event.
468
469 In the dependent touch example event sequence below, touches are marked when
470 switching to pointer-controlling (pc) or to non-pointer-controlling (np).
471
472 .Dependent touch example event sequence on a touchpad
473 [width="50%", options="header"]
474 |====================================================
475 | Finger 1 | Finger 2 | Event generated(touchid)
476 |  down    |          | Motion
477 |  move    |          | Motion
478 |  move    |          | Motion
479 |  (np)    |   down   | TouchBegin(0), TouchBegin(1)
480 |  move    |    --    | TouchUpdate(0)
481 |   --     |   move   | TouchUpdate(1)
482 |   up     |   (pc)   | TouchEnd(0), TouchEnd(1)
483 |          |   move   | Motion
484 |  down    |   (np)   | TouchBegin(2), TouchBegin(3)
485 |  move    |    --    | TouchUpdate(2)
486 |   up     |   (pc)   | TouchEnd(2), TouchEnd(3)
487 |          |    up    | Motion
488 |  down    |          | Motion
489 |  (np)    |   down   | TouchBegin(4), TouchBegin(5)
490 |  (pc)    |    up    | TouchEnd(4), TouchEnd(5)
491 |  move    |          | Motion
492 |   up     |          | Motion
493 |====================================================
494
495
496 [[multitouch-emulation]]
497 Pointer emulation from multitouch events
498 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
499
500 Touch sequences from direct touch devices may emulate pointer events. Only one
501 touch sequence from a device may emulate pointer events at a time; which touch
502 sequence emulates pointer events is implementation-dependent.
503
504 Pointer events are emulated as follows:
505
506 - A TouchBegin event generates a pointer motion event to the location of the
507   touch with the same axis values of the touch event, followed by a button press
508   event for button 1.
509 - A TouchUpdate event generates a pointer motion event to the location of the
510   touch and/or to update axis values of the pointer device. The button state
511   as seen from the protocol includes button 1 set.
512 - A TouchEnd event generates a pointer motion event to the location of the touch
513   and/or to update the axis values if either have changed, followed by a button
514   release event for button 1. The button state as seen from the protocol
515   includes button 1 set.
516
517 If a touch sequence emulates pointer events and an emulated pointer event
518 triggers the activation of a passive grab, the grabbing client becomes the
519 owner of the touch sequence.
520
521 The touch sequence is considered to have been accepted if
522
523 - the grab mode is asynchronous, or
524 - the grab mode is synchronous and the device is thawed as a result of
525   AllowEvents with AsyncPointer or AsyncDevice
526
527 Otherwise, if the button press is replayed by the client, the touch sequence
528 is considered to be rejected.
529
530 Touch event delivery precedes pointer event delivery. A touch event emulating
531 pointer events is delivered:
532
533 - as a touch event to the top-most window of the current window set if a
534   client has a touch grab on this window,
535 - otherwise, as a pointer event to the top-most window of the current window
536   set if a client has a pointer grab on this window,
537 - otherwise, to the next child window in the window set until a grab has been
538   found.
539
540 If no touch or pointer grab on any window is active and the last window in the
541 window set has been reached, the event is delivered:
542
543 - as a touch event to the window if a client has selected for touch events
544   on this window
545 - otherwise, as a pointer event to the window if a client has selected for
546   pointer events.
547 - otherwise, to the next parent window in the window set until a selection has
548   been found.
549
550 Emulated pointer events will have the PointerEmulated flag set. A touch
551 event that emulates pointer events has the TouchEmulatingPointer flag set.
552
553 [[glossary-notations]]
554 Notations used in this document
555 -------------------------------
556
557 Notation for requests:
558
559     ┌───
560         Name of request
561             name of request field:       type of request field
562             name of request field:       type of request field
563             ▶
564             name of reply field:         type of reply field
565     └───
566
567 Notation for events:
568
569     ┌───
570         Name of event
571             name of field:               type of field
572             name of field:               type of field
573     └───
574
575 Complex fields are specified in the following notation:
576
577           name of field:                  COMPLEXFIELDTYPE
578
579 or, if multiple of these fields exist:
580
581           name of field:                  LISTofCOMPLEXFIELDTYPE
582
583     COMPLEXFIELDTYPE:  { name of subfield:   type of subfield,
584                          name of subfield:   type of subfield }
585
586
587 [[glossary-datatypes]]
588 Data types
589 ----------
590
591     BUTTONMASK
592             A binary mask defined as (1 << button number).
593             A SETofBUTTONMASK is a binary OR of zero or more BUTTONMASK.
594
595     DEVICE { DEVICEID, AllDevices, AllMasterDevices }
596             A DEVICE specifies either a DEVICEID or AllDevices or
597             AllMasterDevices.
598
599     DEVICEID { CARD16 }
600             A DEVICEID is a numerical ID for a device currently available in the
601             server. The server may re-use a device ID after a device's removal.
602             The device IDs 0 and 1 are reserved.
603             AllDevices ........ 0
604             AllMasterDevices .. 1
605
606     DEVICEUSE { MasterPointer, MasterKeyboard, SlavePointer,
607                 SlaveKeyboard, FloatingSlave }
608             A DEVICEUSE field specifies the current use of a device in the MD/SD
609             device hierarchy. See Section "The Master/Slave device hierarchy"
610             for more information.
611
612     EVENTMASK
613             An EVENTMASK is a binary mask defined as (1 << event type).
614             A SETofEVENTMASK is a binary OR of zero or more EVENTMASK.
615
616     FP1616
617             Fixed point decimal in 16.16 format as one INT16 and one CARD16.
618             The INT16 contains the integral part, the CARD32 the decimal fraction
619             shifted by 16.
620
621     FP3232
622             Fixed point decimal in 32.32 format as one INT32 and one CARD32.
623             The INT32 contains the integral part, the CARD32 the decimal fraction
624             shifted by 32.
625
626     VALUATORMASK
627             A binary mask defined as (1 << valuator number).
628             A SETofVALUATORMASK is a binary OR of zero or more VALUATORMASK.
629
630
631 [[errors]]
632 Errors
633 ------
634
635 Errors are sent using core X error reports.
636
637     Device
638             A value for a DEVICE argument does not specify a valid DEVICE.
639
640
641 [[requests]]
642 Requests:
643 ---------
644
645 The server does not guarantee that the length of a reply remains constant in
646 future revisions of XI2. A client must always retrieve the exact length of the
647 protocol reply from the connection, even if the reply is longer than defined
648 for the XI2 version supported by the client.
649 Additional bytes in a request may include data supported in later versions of
650 XI2. Clients should ignore this data. Padding bytes in XI2 protocol requests
651 are required to be 0.
652
653 [[requests-xi20]]
654 Requests introduced in version 2.0
655 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
656
657 [[requests-queryversion]]
658     ┌───
659         XIQueryVersion
660         major_version:          CARD16
661         minor_version:          CARD16
662         ▶
663         major_version:          CARD16
664         minor_version:          CARD16
665     └───
666
667 The client sends the highest supported version to the server and the
668 server sends the highest version it supports, but no higher than the
669 requested version. Major versions changes can introduce incompatibilities
670 in existing functionality, minor version changes introduce only backward
671 compatible changes.  It is the client's responsibility to ensure that the
672 server supports a version which is compatible with its expectations.
673
674     major_version
675         Major XI2 version.
676     minor_version
677         Minor XI2 version.
678
679 If major_version is less than 2, a BadValue error occurs.
680
681 [[requests-querydevice]]
682     ┌───
683         XIQueryDevice
684         DEVICE                  deviceid
685         ▶
686         num_devices:            CARD16
687         deviceinfo:             LISTofDEVICEINFO
688     └───
689
690     DEVICEINFO { deviceid:              DEVICEID
691                  use:                   DEVICEUSE
692                  attachment:            DEVICEID
693                  enabled:               BOOL
694                  num_classes:           CARD16
695                  name_len:              CARD16
696                  name:                  LISTofCHAR8
697                  classes:               LISTofCLASS }
698
699     CLASS { BUTTONCLASS, KEYCLASS, AXISCLASS, SCROLLCLASS, TOUCHCLASS }
700
701     BUTTONCLASS { type:                 ButtonClass
702                   length:               CARD16
703                   sourceid:             CARD16
704                   buttons_len:          CARD16
705                   state:                SETofBUTTONMASK
706                   labels:               LISTofATOM }
707
708     KEYCLASS    { type:                 KeyClass
709                   length:               CARD16
710                   sourceid:             CARD16
711                   num_keys:             CARD16
712                   keys:                 LISTofCARD32 }
713
714     AXISCLASS   { type:                 AxisClass
715                   length:               CARD16
716                   sourceid:             CARD16
717                   axisnumber:           CARD16
718                   label:                ATOM
719                   min:                  FP3232
720                   max:                  FP3232
721                   value:                FP3232
722                   resolution:           CARD32
723                   mode:                 CARD8 }
724
725     SCROLLCLASS¹ {type:                 ScrollClass
726                   length:               CARD16
727                   sourceid:             CARD16
728                   axisnumber:           CARD16
729                   scroll_type:          SCROLLTYPE
730                   flags:                SETofSCROLLFLAGS
731                   increment:            FP3232 }
732
733     SCROLLTYPE { Vertical, Horizontal }
734
735     SCROLLFLAGS { NoEmulation, Preferred }
736
737     TOUCHCLASS² { type:                 TouchClass
738                   length:               CARD16
739                   sourceid:             CARD16
740                   mode:                 TOUCHMODE
741                   num_touches:          CARD16 }
742
743     TOUCHMODE { DirectTouch, DependentTouch }
744
745     ¹ since XI 2.1
746     ² since XI 2.2
747
748 XIQueryDevice details information about the requested input devices.
749
750     devices
751         The device to list. If devices is AllDevices, all enabled and
752         disabled devices are listed. If devices is AllMasterDevices, all
753         enabled and disabled master devices are listed. If devices is a
754         valid DEVICE, only this DEVICE is listed and num_devices is 1.
755     num_devices
756         The number of deviceinfos returned.
757
758 Each deviceinfo is detailed as follows:
759
760     deviceid
761         The unique ID of the device. Device IDs may get re-used when a device
762         is removed.
763     use
764         If the device is a master pointer, use is MasterPointer.
765         If the device is a master keyboard, use is MasterKeyboard.
766         If the device is a slave pointer, use is SlavePointer.
767         If the device is a slave keyboard, use is SlaveKeyboard.
768         If the device is a floating slave, use is FloatingSlave.
769     attachment
770         If the device is a master pointer or a master keyboard, attachment
771         specifies the paired master keyboard, or the paired master pointer,
772         respectively.  If the device is a non-floating slave device
773         attachment specifies the master device this device is attached to.
774         If the device is a floating slave, attachment is undefined.
775     enabled
776         Zero if the device is disabled, non-zero otherwise.
777     num_classes
778         Number of classes provided.
779     name_len
780         Length of the name in bytes not including padding.
781     classes
782         Details the available classes provided by the device in an undefined
783         order.
784     name
785         The device's name. padded to a multiple of 4 bytes.
786
787 For all classes, type specifies the device class. Clients are required
788 to ignore unknown device classes. The length field specifies the length
789 of the class in 4 byte units.
790 The following classes may occur only once: ButtonClass, KeyClass
791
792     ButtonClass:
793     type
794         Always ButtonClass.
795     length
796         Length in 4 byte units.
797     sourceid
798         The device this class originates from.
799     num_buttons
800         Number of buttons provided by the device.
801     labels
802         List of Atoms specifying the label for each button. An Atom of None
803         specifies an unlabeled button. Buttons are listed in the device-native
804         order regardless of the current button mapping.
805     state
806         The current button mask for this device after button mapping is
807         applied. Each bit representing a button is 1 if this button is
808         logically down, or 0 otherwise. State is a multiple of 4-byte units
809         and always contains at least num_buttons bits.
810
811     KeyClass:
812     type
813         Always KeyClass.
814     length
815         Length in 4 byte units.
816     sourceid
817         The device this class originates from.
818     num_keys
819         Number of keycodes provided by the device.
820     keys
821         List of keycodes provided.
822
823     AxisClass:
824     type
825         Always AxisClass.
826     length
827         Length in 4 byte units.
828     sourceid
829         The device this class originates from.
830     axisnumber
831         Axis number of this axis. The axis number is in device-native
832         order and potential axis mappings are ignored.
833     label
834         Atom specifying the axis name. An Atom of None specifies an unlabeled
835         axis.
836     min
837         Minimum value.
838     max
839         Minimum value.
840     resolution
841         Resolution in counts/meter.
842     mode
843         Relative or Absolute.
844     value
845         Last published axis value (if mode is absolute).
846
847 An axis in Relative mode may specify min and max as a hint to the
848 client. If no min and max information is available, both must be 0.
849
850     ScrollClass:
851     type
852         Always ScrollClass.
853     axisnumber
854         Axis number that is referred to. This axis number must be listed in
855         the ValuatorClassInfo.
856     scroll_type:
857         Vertical for a vertical scrolling axis, Horizontal for a horizontal
858         scrolling axis.
859     flags:
860         A set of flags that apply to this scroll axis.
861         NoEmulation: no legacy scroll button events are generated for events
862                      on this scrolling axis.
863         Preferred: This axis is the preferred axis for emulating valuator
864                    events from legacy scroll button events.
865     increment:
866         The valuator delta equivalent to one positive unit of scrolling.
867
868 A ScrollClass may only exist if the device has at least one ValuatorClass
869 and each axisnumber listed in any ScrollClass. Only one ScrollClass may
870 exist per ValuatorClass.
871
872     TouchClass:
873     type
874         Always TouchClass.
875     length
876         Length in 4 byte units.
877     sourceid
878         The device this class originates from.
879     mode
880         The device type of the touch device.  This mode may change at runtime.
881     num_touches
882         The maximum number of simultaneous touchpoints the device may send.
883         If num_touches is 0, the number of supported touches is unknown or
884         unlimited.
885
886 Devices with a TouchClass emit touch events with the same axes as pointer
887 events.
888
889 [[requests-selectevents]]
890     ┌───
891         XISelectEvents
892             window:         Window
893             num_masks:      CARD16
894             masks:          LISTofEVENTMASK
895
896     └───
897
898     EVENTMASK { deviceid:          DEVICE,
899                 mask_len:          CARD16,
900                 mask:              SETofEVENTMASK
901
902     window
903         The window to select the events on.
904     num_masks
905         Number of items in masks.
906     deviceid
907         Numerical deviceid, or AllDevices, or AllMasterDevices.
908     mask_len
909         Length of mask in 4 byte units.
910     mask
911         Event mask. An event mask for an event type T is defined as (1 << T).
912
913 XISelectEvents selects for XI2 events on window.
914
915 If num_masks is 0, a BadValue error occurs.
916
917 Each mask sets the (and overwrites a previous) event mask for the DEVICE
918 specified through deviceid. The device AllDevices or
919 AllMasterDevices is treated as a separate device by server. A client's
920 event mask is the union of AllDevices, AllMasterDevices and the
921 per-device event mask.
922 The removal of device from the server unsets the event masks for the
923 device. If an event mask is set for AllDevices or AllMasterDevices, the
924 event mask is not cleared on device removal and affects all future
925 devices.
926
927 If mask_len is 0, the event mask for the given device is cleared.
928
929 The mask for XIHierarchyEvents may only be selected for XIAllDevices.
930 Setting it for any other device results in a BadValue error.
931
932 A client selecting for any of XI_TouchBegin, XI_TouchUpdate, or XI_TouchEnd
933 must select for all three events at the same time, else a BadValue error
934 will be generated. A client selecting for XI_TouchOwnership must select for
935 all three of the other touch events. If the selection for these touch events
936 overlaps a current selection by another client (e.g. selecting for a
937 specific device when another client has a selection for XIAllDevices), a
938 BadAccess error occurs.
939
940 [[requests-getselectedevents]]
941     ┌───
942         XIGetSelectedEvents
943             window:         Window
944             ▶
945             num_masks:      CARD16
946             masks:          LISTofEVENTMASK
947     └───
948
949     window
950         The window to select the events on.
951     num_masks
952         Number of items in masks.
953     masks
954         Selected event masks by this client.
955
956 Masks are returned on a per-device basis, with masks for AllDevices and
957 AllMasterDevices returned separately. A client can calculate the
958 effective mask for a device with a bitwise OR of the AllDevices, the
959 AllMasterDevices and the device-specific mask.
960
961 If num_masks is 0, no events have been selected by this client on the
962 given window.
963
964 [[requests-querypointer]]
965     ┌───
966         XIQueryPointer
967             window:         Window
968             deviceid:       DEVICEID
969             ▶
970             root:           Window
971             child:          Window
972             root_x:         FP1616
973             root_y:         FP1616
974             win_x:          FP1616
975             win_y:          FP1616
976             same_screen:    BOOL
977             mods:           MODIFIERINFO
978             group:          GROUPINFO
979             buttons_len:    CARD16
980             buttons:        SETofBUTTONMASK
981     └───
982
983 Query a master pointer device for its current position.
984
985     root
986         The root window the pointer is logically on.
987     child
988         The child window of window that contains the pointer or None.
989     root_x
990     root_y
991         Pointer position relative to the root window's origin.
992     win_x
993     win_y
994         Pointer position relative to window or 0 if same_screen is false.
995     same_screen
996         True if window is on the same screen as the pointer.
997     mods
998         XKB modifier state on the paired device.
999     group
1000         XKB group state on the paired device.
1001     buttons_len
1002         The length of buttons in 4 byte units.
1003     buttons
1004         Button state.
1005
1006 If the device is not a master pointer device or not a floating slave
1007 pointer, a BadDevice error results.
1008
1009 [[requests-warppointer]]
1010     ┌───
1011         XIWarpPointer
1012             src_win:         Window
1013             dst_win:         Window
1014             src_x:           FP1616
1015             src_y:           FP1616
1016             src_width:       INT16
1017             src_height:      INT16
1018             dst_x:           FP1616
1019             dst_y:           FP1616
1020             deviceid:        DEVICEID
1021     └───
1022
1023 WarpPointer moves the pointer of deviceid as if the user had moved
1024 the pointer. WarpPointer can only be called for MasterPointer and
1025 FloatingSlave devices.
1026
1027     src_win
1028        If src_window is not None, the move only takes place if src_window
1029        contains the pointer and the pointer is contained in the specified
1030        rectangle of src_window.
1031     dst_win
1032        If dst_win is None, this request moves the pointer by offsets
1033        dst_x/dst_y relative to the current position of the pointer. If
1034         dst_window is a window, this request moves the pointer to
1035        dst_x/dst_y relative to dst_win's origin.
1036     src_x
1037     src_y
1038     src_width
1039     src_height
1040        Specifies the source window rectangle.
1041     dst_x
1042     dst_y
1043         The relative coordinates to move the pointer if dst_win is None, or
1044         the absolute coordinates if dst_win is a window.
1045     deviceid
1046         The device to warp.
1047
1048 This request cannot be used to move the pointer outside the confine-to
1049 window of an active pointer grab. An attempt will only move the pointer as
1050 far as the closest edge of the confine-to window.
1051
1052 This request will generate events just as if the user had instantaneously
1053 moved the pointer.
1054
1055 [[requests-changecursor]]
1056     ┌───
1057         XIChangeCursor
1058             win:             Window
1059             cursor:          Cursor
1060             deviceid:        DEVICEID
1061     └───
1062
1063 Change a master pointer's cursor on the specified window.
1064
1065     window
1066         The window.
1067     cursor
1068         The new cursor or None.
1069     deviceid
1070         The master pointer device.
1071
1072 Whenever device enters a window W, the cursor shape is selected in the
1073 following order:
1074
1075 - if the current window has a device cursor C(d) defined for device,
1076   display this cursor C(d).
1077 - otherwise, if the current window has a cursor C(w) defined in the core
1078   protocol's window attributes, display cursor C(w).
1079 - repeat on parent window until a cursor has been found.
1080
1081 The device cursor for a given window is reset once the window is destroyed
1082 or the device is removed, whichever comes earlier.
1083
1084 If deviceid does not specify a master pointer, a BadDevice error
1085 is returned.
1086
1087 [[requests-changehierarchy]]
1088     ┌───
1089         XIChangeHierarchy
1090             num_changes:     CARD8
1091             changes:         LISTofHIERARCHYCHANGES
1092     └───
1093
1094     HIERARCHYCHANGE { ADDMASTER, REMOVEMASTER, ATTACHSLAVE, DETACHSLAVE }
1095
1096     HIERARCHYCHANGETYPE { AddMaster, RemoveMaster, AttachSlave, DetachSlave }
1097
1098     CHANGEMODE { Float, Attach }
1099
1100     ADDMASTER { type:        HIERARCHYCHANGETYPE
1101                 length:      CARD16
1102                 name_len:    CARD16
1103                 send_core:   BOOL
1104                 enable:      BOOL
1105                 name:        LISTofCHAR8 }
1106
1107     REMOVEMASTER { type:            HIERARCHYCHANGETYPE
1108                    length:          CARD16
1109                    deviceid:        DEVICEID
1110                    return_mode:     CHANGEMODE
1111                    return_pointer:  DEVICEID
1112                    return_keyboard: DEVICEID }
1113
1114     ATTACHSLAVE   { type:        HIERARCHYCHANGETYPE
1115                     length:      CARD16
1116                     deviceid:    DEVICEID
1117                     master:      DEVICEID }
1118
1119     DETACHSLAVE { type:       HIERARCHYCHANGETYPE
1120                   length:     CARD16
1121                   deviceid:   DEVICEID }
1122
1123 XIChangeHierarchy allows a client to modify the
1124 <<hierarchy,Master/Slave device hierarchy>>.
1125
1126     num_changes
1127         The number of changes to apply to the current hierarchy.
1128     changes
1129         The list of changes.
1130
1131 The server processes the changes in the order received from the client and
1132 applies each requested change immediately. If an error occurs, processing
1133 stops at the current change and returns the number of successfully applied
1134 changes in the error.
1135
1136     ADDMASTER creates a pair of master devices.
1137     type
1138         Always AddMaster.
1139     length
1140         Length in 4 byte units.
1141     name_len
1142         Length of name in bytes.
1143     send_core
1144         True if the device should send core events.
1145     enable
1146         True if the device is to be enabled immediately.
1147     name
1148         The name for the new master devices. The master pointer's name is
1149         automatically appended with " pointer", the master keyboard's name is
1150         automatically appended with " keyboard".
1151
1152     REMOVEMASTER removes an existing master device.
1153     type
1154         Always RemoveMaster.
1155     length
1156         Length in 4 byte units.
1157     deviceid
1158         The device to remove.
1159     return_mode
1160         Return mode for attached slave devices.
1161         If return_mode is Float, all slave devices are set to floating.
1162         If return_mode is Attach, slave pointers are attached to
1163         return_pointer and slave keyboards are attached to
1164         return_keyboard.
1165     return_pointer
1166     return_keyboard
1167         The master pointer and master keyboard to attach slave devices to, if
1168         return_mode is Attach. If return_mode is Float, return_pointer
1169         and return_keyboard are undefined.
1170
1171 Removing a master pointer removes the paired master keyboard and vice
1172 versa.
1173
1174     ATTACHSLAVE attaches a slave device to a given master device.
1175     type
1176         Always ChangeAttachment.
1177     length
1178         Length in 4 byte units.
1179     deviceid
1180         Deviceid of the slave device.
1181     master
1182         The new master device to attach this slave device to.
1183
1184 If any clients are selecting for touch events from the slave device, their
1185 selection will be canceled.
1186
1187     DETACHSLAVE detaches a slave device from its current master device.
1188     type
1189         Always ChangeAttachment.
1190     length
1191         Length in 4 byte units.
1192     deviceid
1193         Deviceid of the slave device.
1194
1195 [[requests-setclientpointer]]
1196     ┌───
1197         XISetClientPointer
1198             win:             Window
1199             deviceid:        DEVICEID
1200     └───
1201
1202 Set the ClientPointer for the client owning win to the given device.
1203
1204     win
1205          Window or client ID.
1206     deviceid
1207          The master pointer or master keyboard that acts as ClientPointer.
1208
1209 Some protocol requests are ambiguous and the server has to choose a device
1210 to provide data for a request or a reply. By default, the server will
1211 choose a client's ClientPointer device to provide the data, unless the
1212 client currently has a grab on another device. See section
1213 <<clientpointer,The ClientPointer principle>> for more details.
1214
1215 If win is None, the ClientPointer for this client is set to the given
1216 device. Otherwise, if win is a valid window, the ClientPointer for the
1217 client owning this window is set to the given device. Otherwise, if win is
1218 not a valid window but a client with the client mask equal to win exists,
1219 this client's ClientPointer is set to the given device.
1220
1221 If deviceid does not specify a master pointer or master keyboard, a
1222 BadDevice error is returned.
1223
1224 If window does not specify a valid window or client ID and is not None, a
1225 BadWindow error is returned.
1226
1227 [[requests-getclientpointer]]
1228     ┌───
1229         XIGetClientPointer
1230             win:             Window
1231             ▶
1232             set:             BOOL
1233             deviceid:        DEVICEID
1234     └───
1235
1236 Query the ClientPointer for the client owning win.
1237
1238     win
1239         The window or client ID.
1240     set
1241         True if the client has a ClientPointer set.
1242     deviceid
1243         The master pointer that acts as a ClientPointer if set is True.
1244
1245 No difference is made between a ClientPointer set explicitly through
1246 XISetClientPointer and a ClientPointer implicitly assigned by the server
1247 in response to an ambiguous request.
1248
1249 [[requests-setfocus]]
1250     ┌───
1251         XISetFocus
1252             focus:           Window
1253             deviceid:        DEVICEID
1254             time:            Time
1255     └───
1256
1257 Set the focus for the given device to the given window. Future key events
1258 from this device are sent to this window.
1259 This request generates FocusIn and FocusOut events.
1260
1261     focus
1262         A viewable window or None.
1263     deviceid
1264         The device to modify the focus window for.
1265     time
1266         Specifies the time to change the focus or CurrentTime.
1267
1268 If focus is None, key events from this device are discarded until a new
1269 focus window is set. If focus is a viewable window, key events from this
1270 device are sent to this window. If the window becomes unviewable, the
1271 window's first viewable ancestor automatically becomes the focus window
1272 and FocusIn and FocusOut events are sent as if a client had changed the
1273 focus window.
1274 This is equivalent to RevertToParent in the core XSetInputFocus window.
1275
1276 This request has no effect if the specified time is earlier than the
1277 current last-focus-change time or is later than the current X server time.
1278 Otherwise, the last-focus-change time is set to the specified time.
1279
1280 [[requests-getfocus]]
1281     ┌───
1282         XIGetFocus
1283             deviceid:        DEVICEID
1284             ▶
1285             focus:           Window
1286     └───
1287
1288 Return the current focus window for the given device.
1289
1290 [[requests-grabdevice]]
1291     ┌───
1292         XIGrabDevice
1293             deviceid:        DEVICEID
1294             grab_window:     Window
1295             owner_events:    BOOL
1296             grab_mode:       { Synchronous, Asynchronous }
1297             paired_device_mode: { Synchronous, Asynchronous }
1298             time:            TIMESTAMP or CurrentTime
1299             cursor:          Cursor
1300             mask_len:        CARD16
1301             masks:           SETofEVENTMASK
1302             ▶
1303             status:          Success, AlreadyGrabbed, Frozen, InvalidTime, NotViewable
1304     └───
1305
1306 This request actively grabs control of the specified input device. Further
1307 input events from this device are reported only to the grabbing client.
1308 This request overides any previous active grab by this client for this
1309 device.  This request does not affect the processing of XI 2.2
1310 touch events.
1311
1312     deviceid
1313         The device to grab.
1314     grab_window
1315         Events are reported relative to the grab window.
1316     owner_events
1317         Specifies whether event will be reported normally or relative to the
1318         grab window.
1319     grab_mode
1320         Specifies if this device will be frozen as a result of the grab.
1321     paired_device_mode
1322         Specifies if the master device paired with this device will be frozen
1323         as a result of the grab.
1324     time
1325         A valid server time or CurrentTime.
1326     cursor
1327         The cursor to display for the duration of the grab or None.
1328     mask_len
1329         Length of mask in 4 byte units.
1330     mask
1331         Event mask. An event mask for an event type T is defined as (1 << T).
1332     status
1333         Success or the reason why the grab could not be established.
1334
1335 The masks parameter specifies which events the client wishes to receive
1336 while the device is grabbed.
1337
1338 If owner-events is False, input events generated from this device are
1339 reported with respect to grab-window, and are only reported if selected by
1340 being included in the event-list.  If owner-events is True, then if a
1341 generated event would normally be reported to this client, it is reported
1342 normally, otherwise the event is reported with respect to the grab-window,
1343 and is only reported if selected by being included in the event-list. For
1344 either value of owner-events, unreported events are discarded.
1345
1346 If grab-mode is Asynchronous, device event processing continues normally.
1347 If the device is currently frozen by this client, then processing of
1348 device events is resumed. If grab-mode is Synchronous, the state of the
1349 grabbed device (as seen by means of the protocol) appears to freeze,
1350 and no further device events are generated by the server until the
1351 grabbing client issues a releasing XIAllowEvents request or until the
1352 device grab is released. Actual device input events are not lost while the
1353 device is frozen; they are simply queued for later processing.
1354
1355 If the device is a slave device, the paired-device-mode is ignored.
1356 Otherwise, if this device is a master device and paired-device-mode is
1357 Asynchronous, event processing is unaffected by activation of the grab. If
1358 this device is a master device and paired-device-mode is Synchronous, the
1359 state of the master device paired with this device (as seen by means of the
1360 protocol) appears to freeze, and no further events are generated by the
1361 server until the grabbing client issues a releasing XIAllowEvents request
1362 or until the device grab is released. Actual events are not lost while the
1363 devices are frozen; they are simply queued for later processing.
1364
1365 If the cursor is not None and the device is a master pointer device, the
1366 cursor will be displayed until the device is ungrabbed.
1367
1368 This request fails and returns:
1369
1370     AlreadyGrabbed: If the device is actively grabbed by some other client.
1371     NotViewable: If grab-window is not viewable.
1372     InvalidTime: If the specified time is earlier than the last-grab-time for
1373                  the specified device or later than the current X server time.
1374                  Otherwise, the last-grab-time for the specified device is set
1375                  to the specified time and CurrentTime is replaced by the
1376                  current X server time.
1377     Frozen: If the device is frozen by an active grab of another client.
1378
1379 To release a grab of a device, use XIUngrabDevice.
1380
1381 [[requests-ungrabdevice]]
1382     ┌───
1383         XIUngrabDevice
1384             deviceid:        DEVICEID
1385             time:            TIMESTAMP or CurrentTime
1386     └───
1387
1388 This request releases the device if this client has it actively grabbed
1389 (from either XIGrabDevice or  XIPassiveGrabDevice) and
1390 releases any queued events. If any devices were frozen by the grab,
1391 XIUngrabDevice thaws them.
1392
1393     deviceid
1394         The device to grab.
1395     time
1396         A valid server time or CurrentTime.
1397
1398 The request has no effect if the specified time is earlier than the
1399 last-device-grab time or is later than the current server time.
1400 This request generates FocusIn and FocusOut events.
1401 An XIUngrabDevice is performed automatically if the event window for an
1402 active device grab becomes not viewable.
1403
1404 [[requests-allowevents]]
1405     ┌───
1406         XIAllowEvents:
1407             deviceid:        DEVICEID
1408             time:            TIMESTAMP or CurrentTime
1409             event_mode:      { AsyncDevice, SyncDevice,
1410                                AsyncPairedDevice, SyncPairedDevice,
1411                                ReplayDevice, AsyncPair, SyncPair,
1412                                AcceptTouch¹, RejectTouch¹ }
1413             touchid¹:        CARD32
1414             grab_window¹:    Window
1415     └───
1416
1417     ¹ since XI 2.2
1418
1419 The XIAllowEvents request releases some queued events if the client
1420 has caused a device to freeze. It also is used to handle touch grab and
1421 ownership processing.
1422
1423     deviceid
1424         The device to grab.
1425     time
1426         A valid server time or CurrentTime.
1427     event_mode
1428         Specifies whether a device is to be thawed and events are to be
1429         replayed, or how to handle a grabbed touch sequence.
1430     touchid
1431         The ID of the touch sequence to accept or reject. The value is undefined
1432         for event modes other than AcceptTouch and RejectTouch.
1433     grab_window
1434         The window on which to accept or reject a touch sequence grab. The value
1435         is undefined for event modes other than AcceptTouch and RejectTouch.
1436
1437 The request has no effect if the specified time is earlier than the last-grab
1438 time of the most recent active grab for the client, or if the specified time is
1439 later than the current X server time. The time parameter must be CurrentTime for
1440 requests with event modes of AcceptTouch and RejectTouch.
1441
1442 When event-mode is AcceptTouch, a BadValue error occurs if the touch ID is
1443 invalid. A BadAccess error occurs if this client is not the current or potential
1444 owner of the specified touch ID.
1445
1446 The following describes the processing that occurs depending on what constant
1447 you pass to the event-mode argument:
1448
1449     AsyncDevice:
1450         If the specified device is frozen by the client, event processing for that
1451         device continues as usual. If the device is frozen multiple times  by the
1452         client on behalf of multiple separate grabs, AsyncDevice thaws for
1453         all.
1454         AsyncDevice has no effect if the specified device is not frozen by the
1455         client, but the device need not be grabbed by the client.
1456     SyncDevice:
1457         If the specified device is frozen and actively grabbed by the client,
1458         event processing for that device continues normally until the next
1459         event is reported to the client. At this time, the specified device
1460         again appears to freeze. However, if the reported event causes the
1461         grab to be released, the specified device does not freeze.
1462         SyncDevice has no effect if the specified device is not frozen by the
1463         client or is not grabbed by the client.
1464      ReplayDevice:
1465         If the specified device is actively grabbed by the client and is frozen
1466         as the result of an event having been sent to the client (either from
1467         the activation of a XIGrabButton or from a previous XIAllowEvents with
1468         mode SyncDevice, but not from a Grab), the grab is released and
1469         that event is completely reprocessed.  This time, however, the request
1470         ignores any passive grabs at or above (towards the root) the
1471         grab-window of the grab just released.
1472         The request has no effect if the specified device is not grabbed by
1473         the client or if it is not frozen as the result of an event.
1474      AsyncPairedDevice
1475         If the paired master device is frozen by the client, event processing
1476         for it continues as usual. If the paired device is frozen multiple
1477         times by the client on behalf of multiple separate grabs,
1478         AsyncPairedDevice thaws for all.
1479         AsyncPairedDevice has no effect if the device is not frozen by the
1480         client, but those devices need not be grabbed by the client.
1481         AsyncPairedDevice has no effect if deviceid specifies a slave device.
1482      SyncPairedDevice
1483         If the paired master device is frozen by the client, event processing (for
1484         the paired master device) continues normally until the next button or key
1485         event is reported to the client for the grabbed device (button event for
1486         the grabbed device, key or motion event for the device), at which time
1487         the device again appears to freeze. However, if the reported event causes
1488         the grab to be released, then the device does not freeze.
1489         SyncPairedDevice has no effect if the specified device is not grabbed
1490         by the client or if it is no frozen as the result of an event.
1491         SyncPairedDevice has no effect if deviceid specifies a slave device.
1492      SyncPair
1493         If both the device and the paired master device are frozen by the
1494         client, event processing (for both devices) continues normally until
1495         the next XIButtonPress, XIButtonRelease, XIKeyPress, or XIKeyRelease
1496         event is reported to the client for a grabbed device (button event for
1497         a pointer, key event for a keyboard), at which time the devices again
1498         appear to freeze. However, if the reported event causes the grab to be
1499         released, then the devices do not freeze (but if the other device is
1500         still grabbed, then a subsequent event for it will still cause both
1501         devices to freeze).
1502         SyncPair has no effect unless both the device and the paired master
1503         device are frozen by the client. If the device or paired master device
1504         is frozen twice by the client on behalf of two separate grabs,
1505         SyncPair thaws for both (but a subsequent freeze for SyncPair will
1506         only freeze each device once).
1507         SyncPair has no effect if deviceid specifies a slave device.
1508      AsyncPair
1509         If the device and the paired master device are frozen by the client,
1510         event processing for both devices continues normally. If a device is
1511         frozen twice by the client on behalf of two separate grabs, AsyncBoth
1512         thaws for both. AsyncPair has no effect unless both the device and the
1513         paired master device frozen by the client.
1514         AsyncPair has no effect if deviceid specifies a slave device.
1515      AcceptTouch
1516         The client is deemed to have taken control of the touch sequence once it
1517         owns the sequence. TouchEnd events will be sent to all clients listening
1518         to the touch sequence that have either grabbed the touch sequence on a
1519         child window of the grab_window or have received events for the touch
1520         sequence through event selection. These clients will no longer receive
1521         any TouchUpdate events.
1522      RejectTouch
1523         The client is no longer interested in the touch sequence, and will
1524         receive a TouchEnd event. If the client is the current owner of the
1525         sequence, ownership will be passed on to the next listener.
1526
1527 [[requests-passivegrabdevice]]
1528     ┌───
1529         XIPassiveGrabDevice
1530             deviceid:        DEVICE
1531             detail:          CARD32
1532             grab_type:       GRABTYPE
1533             grab_window:     Window
1534             cursor:          Cursor
1535             owner_events:    Bool
1536             grab_mode:       { Synchronous, Asynchronous, Touch¹ }
1537             paired_device_mode: { Synchronous, Asynchronous }
1538             num_modifiers:   INT16
1539             mask_len:        CARD16
1540             masks:           SETofEVENTMASK
1541             modifiers:       CARD32 or GrabAnyModifier
1542             ▶
1543             num_modifiers_return:    INT16
1544             modifiers_return:        GRABMODIFIERINFO
1545     └───
1546
1547         GRABTYPE         { GrabtypeButton, GrabtypeKeycode, GrabtypeEnter,
1548                            GrabtypeFocusIn, GrabtypeTouchBegin¹ }
1549
1550         GRABMODIFIERINFO {   status:    Access
1551                              modifiers: CARD32 }
1552
1553     ¹ since XI 2.2
1554
1555 Establish an explicit passive grab for a button or keycode
1556 on the specified input device.
1557
1558         cursor
1559             The cursor to display for the duration of the grab. If grab_type
1560             is not GrabtypeButton, this argument is ignored.
1561         deviceid
1562             The device to establish the passive grab on or AllDevices or
1563             AllMasterDevices.
1564         detail
1565             The button number, or key symbol to grab for.
1566             Must be 0 for GrabtypeEnter, GrabtypeFocusIn, and
1567             GrabtypeTouchBegin.
1568         grab_type
1569             The type of grab to establish.
1570         grab_window
1571             Events are reported relative to the grab window.
1572         grab_mode
1573             If grab-mode is Asynchronous, device event processing continues
1574             normally.  If the device is currently frozen by this client, then
1575             processing of device events is resumed. If grab-mode is
1576             Synchronous, the state of the grabbed device (as seen by means of
1577             the protocol) appears to freeze, and no further device events are
1578             generated by the server until the grabbing client issues a
1579             releasing XIAllowEvents request or until the device grab is
1580             released. Actual device input events are not lost while the device
1581             is frozen; they are simply queued for later processing. If grab_type
1582             is GrabtypeTouchBegin, grab_mode must be set to Touch.
1583         mask_len
1584             Length of mask in 4 byte units.
1585         mask
1586             Event mask. An event mask for an event type T is defined as (1 << T).
1587         modifiers
1588             XKB modifier state to activate this passive grab.
1589         num_modifiers
1590             Number of elements in modifiers.
1591         owner_events
1592             Specifies whether event will be reported normally or relative to the
1593             grab window.
1594         num_modifiers_return
1595             Number of elements in modifiers_return
1596         modifiers_return
1597             XKB modifier state that could not be grabbed.
1598
1599 If owner-events is False, input events generated from this device are
1600 reported with respect to grab-window, and are only reported if
1601 selected by being included in the event-list.  If owner-events is
1602 True, then if a generated event would normally be reported to this
1603 client, it is reported normally, otherwise the event is reported
1604 with respect to the grab-window, and is only reported if selected
1605 by being included in the event-list. For either value of
1606 owner-events, unreported events are discarded.
1607
1608 If deviceid specifies a master pointer, the modifiers of the paired
1609 master keyboard are used. If deviceid specifies a slave pointer
1610 the modifiers of the master keyboard paired with the attached master
1611 pointers are used. If deviceid specifies a slave keyboard, the
1612 modifiers of the attached master keyboard are used. Note that
1613 activating a grab on a slave device detaches the device from its
1614 master. In this case, the modifiers after activation of the grab are
1615 from the slave device only and may be different to the modifier state
1616 when the grab was triggered.
1617
1618 In the future, if grab_type is GrabtypeButton or GrabtypeKeyboard, the
1619 device is actively grabbed if:
1620
1621         - the device is not grabbed, and
1622         - the specified modifier keys are down, and
1623         - the grab_type is GrabtypeButton and the button specified in detail
1624           is logically pressed or the grab_type is GrabtypeKeycode and the
1625           keycode specified in detail is logically pressed, and
1626         - the grab_window contains the pointer, and
1627         - a passive grab on the same button/keycode + modifier
1628           combination does not exist on an ancestor of grab_window.
1629
1630 Otherwise, if grab_type is GrabtypeEnter or GrabtypeFocusIn, the
1631 device is actively grabbed if:
1632
1633         - the device is not actively grabbed, and
1634         - the specified modifier keys are down, and
1635         - the grab_type is GrabtypeEnter and the device's pointer has moved
1636           into grab_window or a descendant of grab_window, or the grab_type is
1637           GrabtypeFocusIn and the device's focus has been set to the
1638           grab_window or a descendant of grab_window, and
1639         - a passive grab of the same grab_type + modifier combination does not
1640           does not exist on an ancestor of grab_window.
1641
1642 Otherwise, if grab_type is GrabtypeTouchBegin, a touch grab begins if:
1643
1644         - the device is not actively grabbed, and
1645         - the specified modifier keys are down
1646         - a touch begins in grab_window or a descendant of grab_window, and
1647         - a passive grab of the same grab_type + modifier combination does not
1648           does not exist on an ancestor of grab_window.
1649
1650 Ownership of the touch sequence is granted to the grabbing client if:
1651
1652         - a TouchBegin or pointer grab for an emulated touch sequence of a
1653           direct touch device with the same modifier set does not exist on
1654           an ancestor of grab_window, or all applicable grabs have released
1655           ownership.
1656
1657 A modifier of GrabAnyModifier is equivalent to issuing the request for
1658 all possible modifier combinations (including no modifiers). A client
1659 may request a grab for GrabAnyModifier and explicit modifier
1660 combinations in the same request.
1661
1662 A GrabtypeButton or GrabtypeKeyboard grab is released when all buttons
1663 or keycode are released, independent of the state of modifier keys.
1664 A GrabtypeEnter or GrabtypeFocusIn grab is released when the
1665 pointer or focus leaves the window and all of its descendants,
1666 independent of the state of modifier keys.
1667 A GrabtypeTouchBegin grab is released when the touch sequence ends or
1668 the client uses XIAllowEvents with mode RejectTouch.
1669 Note that the logical state of a device (as seen by means of the
1670 protocol) may lag the physical state if device event processing is
1671 frozen.
1672
1673 This request overrides all previous passive grabs by the same
1674 client on the same button/key/enter/focus in + modifier combinations
1675 on the same window.
1676
1677 If some other client already has issued a XIPassiveGrabDevice request
1678 with the same button or keycode and modifier combination, the
1679 failed modifier combinations is returned in modifiers_return. If some
1680 other client already has issued an XIPassiveGrabDevice request of
1681 grab_type XIGrabtypeEnter, XIGrabtypeFocusIn, or
1682 XIGrabtypeTouchBegin with the same grab_window and the same
1683 modifier combination, the failed modifier combinations are returned
1684 in modifiers_return. If num_modifiers_return is zero, all passive
1685 grabs have been successful.
1686
1687 If a button grab or enter grab activates, EnterNotify and LeaveNotify
1688 events with mode Grab are generated as if the pointer were to suddenly
1689 warp from its current position some position in the grab_window.
1690 However, the pointer does not warp, and the pointer position is used
1691 as both the initial and final positions for the events.
1692
1693 If a keycode grab or focus grab activates, FocusIn and FocusOut events
1694 with mode Grab are generated as if the focus were to change from the
1695 current window to the grab_window.
1696
1697 If an enter or focus in grab activates, additional EnterNotify events
1698 with mode XIPassiveGrabNotify are generated as if the pointer or focus
1699 were to suddenly warp from its current position to some position in
1700 the grab window.  These events are sent to the grabbing client only
1701 and only if the grab event mask has selected for it. If such a passive
1702 grab deactivates, addional LeaveNotify events with mode
1703 XIPassiveUngrabNotify are generated and sent to the grabbing client
1704 before the grab deactivates.
1705
1706 For GrabtypeTouchBegin, grab_mode must be Touch or a BadValue error
1707 is generated.
1708
1709 See section <<multitouch-ownership, Ownership of touch sequences>> for
1710 additional notes on touch grabs, as they do not behave like traditional
1711 grabs: in particular, they do not freeze the device, and delivery of touch
1712 events continues even if the device is frozen due to a grab by another
1713 client.
1714
1715 [[requests-passiveungrabdevice]]
1716     ┌───
1717         XIPassiveUngrabDevice
1718             deviceid:        DEVICEID
1719             detail:          CARD32
1720             grab_type:       GRABTYPE
1721             grab_window:     Window
1722             num_modifiers:   INT16
1723             modifiers:       MODIFIERINFO
1724     └───
1725
1726 Release an explicit passive grab on the specified input device.
1727
1728         deviceid
1729             The device to establish the passive grab on.
1730         detail
1731             The button number or key symbol to ungrab.
1732             Must be 0 for GrabtypeEnter, GrabtypeFocusIn, and
1733             GrabtypeTouchBegin.
1734         grab_type
1735             The type of grab to establish.
1736         grab_window
1737             Events are reported relative to the grab window.
1738         modifiers
1739             XKB modifier state to activate this passive grab.
1740         num_modifiers
1741             Number of elements in modifiers.
1742
1743 This request has no effect if the client does not have a passive grab
1744 of the same type, same button or keycode (if applicable) and modifier
1745 combination on the grab_window.
1746
1747 [[requests-listproperties]]
1748     ┌───
1749         XIListProperties
1750             deviceid:        DEVICEID
1751             ▶
1752             num_properties:  INT16
1753             properties:      LISTofATOM
1754     └───
1755
1756 List the properties associated with the given device.
1757
1758         deviceid
1759             The device to list the properties for.
1760         num_atoms
1761             Number of atoms in the reply
1762         atoms
1763             All properties on the device.
1764
1765 [[requests-changeproperty]]
1766     ┌───
1767         XIChangeProperty
1768             deviceid:        DEVICEID
1769             property:        ATOM
1770             type:            ATOM
1771             format:          { 8, 16, 32 }
1772             mode:            { Append, Prepend, Replace }
1773             num_items:       CARD32
1774             data:            LISTofINT8, or LISTofINT16, or LISTofINT32
1775     └───
1776
1777 Change the given property on the given device.
1778
1779         deviceid
1780             The device to change the property on.
1781         property
1782             The property to modify.
1783         type
1784             The property's type.
1785         mode
1786             One of Append, Prepend, or Replace
1787         num_items
1788             Number of items following this request.
1789         data
1790             Property data (nitems * format/8 bytes)
1791
1792 The type is uninterpreted by the server. The format specifies whether
1793 the data should be viewed as a list of 8-bit, 16-bit, or 32-bit
1794 quantities so that the server can correctly byte-swap as necessary.
1795
1796 If the mode is Replace, the previous propert y value is discarded.  If
1797 the mode is Prepend or Append, then the type and format must match the
1798 existing property value (or a Match error results). If the property is
1799 undefined, it is treated as defined with the correct type and format
1800 with zero-length data. For Prepend, the data is tacked on to the
1801 beginning of the existing data, and for Append, it is tacked on to the
1802 end of the existing data.
1803
1804 The lifetime of a property is not tied to the storing client. Properties
1805 remain until explicitly deleted, until the device is removed, or
1806 until server reset.
1807
1808 A property cannot be deleted by setting nitems to zero. To delete a
1809 property, use XIDeleteProperty.
1810
1811 This request generates an XIPropertyEvent.
1812
1813 [[requests-deleteproperty]]
1814     ┌───
1815         XIDeleteProperty
1816             deviceid:        DEVICEID
1817             property:        ATOM
1818     └───
1819
1820 Deletes the given property on the given device.
1821
1822         deviceid
1823             The device to delete the property on.
1824         property
1825             The property to delete.
1826
1827 If the property is deleted, an XIPropertyEvent is generated on the device.
1828 If the property does not exist, this request does nothing.
1829
1830 [[requests-getproperty]]
1831     ┌───
1832         XIGetProperty
1833             deviceid:        DEVICEID
1834             property:        ATOM
1835             type:            Atom or AnyPropertyType
1836             offset:          CARD32
1837             len:             CARD32
1838             delete:          BOOL
1839             ▶
1840             type:            Atom
1841             bytes_after:     CARD32
1842             num_items:       CARD32
1843             format:          { 8, 16, 32 }
1844             data:            LISTofINT8, or LISTofINT16, or LISTofINT32
1845     └───
1846
1847 Get the data for the given property on the given device.
1848
1849         deviceid
1850             The device to retrieve the property data from.
1851         property
1852             The property to retrieve the data from..
1853         type
1854             The property type to retrieve or AnyPropertyType
1855         offset
1856             The offset in 4-byte units.
1857         len
1858             Number of bytes to receive in 4-byte units.
1859         delete
1860             Delete the property after retrieving the data.
1861         bytes_after
1862             Number of unread bytes in the stored property
1863         num_items
1864             Number of items in data
1865         format
1866             8, 16, or 32
1867         data
1868             Property data (nitems * format/8 bytes)
1869
1870 If the specified property does not exist for the specified device, then
1871 the return type is None, the format and bytes-after are zero, and the value is
1872 empty. The delete argument is ignored in this case. If the specified property
1873 exists but its type does not match the specified type, then the return
1874 type is the actual type of the property, the format is the actual format of the
1875 property (never zero), the bytes-after is the length of the property in bytes
1876 (even if the format is 16 or 32), and the value is empty. The delete
1877 argument is ignored in this case. If the specified property exists and
1878 either AnyPropertyType is specified or the specified type matches the actual
1879 type of the property, then the return type is the actual type of the property,
1880 the format is the actual format of the property
1881 (never zero), and the bytes-after and value are as follows, given:
1882          N = actual length of the stored property in bytes
1883             (even if the format is 16 or 32)
1884          I = 4 * long-offset
1885          T = N−I
1886          L = MINIMUM(T, 4 * long-length)
1887          A = N − (I + L)
1888 The returned value starts at byte index I in the property (indexing
1889 from 0), and its length in bytes is L. However, it is a Value error if
1890 offset is given such that L is negative. The value of bytes_after is A,
1891 giving the number of trailing unread bytes in the stored property. If
1892 delete is True and the bytes_after is zero, the property is also
1893 deleted from the device, and a XIPropertyNotify event is generated on
1894 the device.  
1895      
1896 [[events]]
1897 Events
1898 ------
1899
1900 An event specifies its length in 4-byte units after the initial 32 bytes.
1901 Future versions of the protocol may provide additional information
1902 in the same event, thus increasing the event size. Clients are required to
1903 always read the number of bytes specified by the event, not the size of the
1904 event they may have been compiled against.
1905
1906
1907 The following event types are available in XI2.
1908
1909 Version 2.0:
1910
1911         - HierarchyChanged
1912         - DeviceChanged
1913         - KeyPress
1914         - KeyRelease
1915         - ButtonPress
1916         - ButtonRelease
1917         - Motion
1918         - RawKeyPress
1919         - RawKeyRelease
1920         - RawButtonPress
1921         - RawButtonRelease
1922         - RawMotion
1923         - Enter
1924         - Leave
1925         - FocusIn
1926         - FocusOut
1927         - PropertyEvent
1928
1929 Version 2.2:
1930
1931         - TouchBegin
1932         - TouchUpdate
1933         - TouchOwnership
1934         - TouchEnd
1935         - RawTouchBegin
1936         - RawTouchUpdate
1937         - RawTouchEnd
1938
1939 All events have a set of common fields specified as EVENTHEADER.
1940
1941
1942     EVENTHEADER { type:                       BYTE
1943                   extension:                  BYTE
1944                   sequenceNumber:             CARD16
1945                   length:                     CARD32
1946                   evtype:                     CARD16
1947                   deviceid:                   DEVICEID
1948                   time:                       Time }
1949
1950     type
1951         Always GenericEvent.
1952     extension
1953         Always the X Input extension offset.
1954     sequenceNumber
1955         Sequence number of last request processed by the server.
1956     length
1957         Length in 4-byte units after the initial 32 bytes.
1958     evtype
1959         XI-specific event type.
1960     deviceid
1961         Numerical device id for a device.
1962     time
1963         Time in ms when the event occurred.
1964
1965
1966 [[events-xi20]]
1967 Events introduced in version 2.0
1968 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1969
1970 [[events-hierarchyevent]]
1971     ┌───
1972         HierarchyEvent:
1973             EVENTHEADER
1974             flags:                      SETofHIERARCHYMASK
1975             num_info:                   CARD16
1976             info:                       LISTofHIERARCHYINFO
1977     └───
1978
1979
1980     HIERARCHYMASK { MasterAdded, MasterRemoved, SlaveAttached, SlaveDetached,
1981                     SlaveAdded, SlaveRemoved, DeviceEnabled, DeviceDisabled }
1982
1983     HIERARCHYINFO { deviceid:           DEVICEID,
1984                     attachment:         DEVICEID,
1985                     type:               DEVICEUSE
1986                     enabled:            BOOL
1987                     flags:              SETofHIERARCHYMASK}
1988
1989     flags
1990         Set of the changes that have occured, causing this event.
1991     num_info
1992         The number of device info structs following the request.
1993     info:
1994         The current hierarchy information.
1995
1996 An XIHierarchyEvent is sent whenever the device hierarchy been
1997 changed. The flags specify all types of hierarchy modifiations that have
1998 occured.
1999 For all devices, info details the hierarchy information after the
2000 modification of the hierarchy has occured. For each device specified with
2001 deviceid:
2002
2003 - if type is MasterPointer or MasterKeyboard, attachment decribes the
2004   pairing of this device.
2005 - if type is SlavePointer or SlaveKeyboard, attachment describes the
2006   master device this device is attached to.
2007 - if type is FloatingSlave device, attachment is undefined.
2008
2009     enabled
2010          True if the device is enabled and can send events. A disabled master
2011          device will not forward events from an attached, enabled slave
2012          device.
2013
2014 Note: Multiple devices may be affected in one hierarchy change,
2015 deviceid in an XIHierarchyEvent is always the first affected
2016 device. Clients should ignore deviceid and instead use the devices list.
2017
2018 [[events-devicechangedevent]]
2019     ┌───
2020         DeviceChangedEvent:
2021             EVENTHEADER
2022             reason:                CHANGEREASON
2023             source:                DEVICEID
2024             num_classes:           CARD16
2025             classes:               LISTofCLASS
2026     └───
2027
2028     CHANGEREASON { SlaveSwitch, DeviceChange }
2029
2030 A DeviceChangeEvent is sent whenever a device changes it's capabilities.
2031 This can happen either by a new slave device sending events through a
2032 master device, or by a physical device changing capabilities at runtime.
2033
2034     reason
2035         The reason for generating this event.
2036         If reason is SlaveSwitch, the slave device sending events through
2037         this device has changed and source specifies the new slave device.
2038         A SlaveSwitch reason can only occur on a master device.
2039         If reason is DeviceChange, the device itself has changed through
2040         other means (e.g. a physical device change) and source is
2041         the device itself.
2042     source
2043         The source of the new classes.
2044     num_classes
2045         Number of classes provided.
2046     classes
2047         Details the available classes provided by the device.  The order the
2048         classes are provided in is undefined.
2049
2050 For a detailed description of classes, see the XIQueryDevice request.
2051
2052 [[events-deviceevent]]
2053     ┌───
2054         DeviceEvent:
2055             EVENTHEADER
2056             detail:                     CARD32
2057             root:                       Window
2058             event:                      Window
2059             child:                      Window
2060             root_x:                     FP1616
2061             root_y:                     FP1616
2062             event_x:                    FP1616
2063             event_y:                    FP1616
2064             buttons_len:                CARD16
2065             valuators_len:              CARD16
2066             sourceid:                   DEVICEID
2067             mods:                       MODIFIERINFO
2068             group:                      GROUPINFO
2069             flags:                      DEVICEEEVENTFLAGS
2070             buttons:                    SETofBUTTONMASK
2071             valuators:                  SETofVALUATORMASK
2072             axisvalues:                 LISTofFP3232
2073     └───
2074
2075     BUTTONBIT { (1 << Button1), (1 << Button2), ... , (1 << ButtonN) }
2076     VALUATORBIT { (1 << 1), ( 1 << 2), ... ( 1 << n) }
2077
2078     MODIFIERINFO  { base_mods:           CARD32,
2079                     latched_mods:        CARD32,
2080                     locked_mods:         CARD32,
2081                     effective_mods:      CARD32}
2082     GROUPINFO     { base_group:          CARD8,
2083                     latched_group:       CARD8,
2084                     locked_group:        CARD8,
2085                     effective_group:     CARD8}
2086
2087     DEVICEEVENTFLAGS (all events): none
2088     DEVICEEVENTFLAGS (key events only): { KeyRepeat }
2089     DEVICEEVENTFLAGS (pointer events only): { PointerEmulated }
2090     DEVICEEVENTFLAGS (touch events only): { TouchPendingEnd,
2091                                             TouchEmulatingPointer }
2092
2093 An XIDeviceEvent is generated whenever the logical state of a device
2094 changes in response to a button press, a button release, a motion, a key
2095 press or a key release. The event type may be one of KeyPress,
2096 KeyRelease, ButtonPress, ButtonRelease, Motion.
2097
2098 XI 2.2: The event type may also be TouchBegin, TouchUpdate, or TouchEnd.
2099
2100     detail
2101         The button number, key code, touch ID, or 0.
2102     root
2103     event
2104     child
2105         The root window, event window or subwindow, respectively. See core
2106         protocol specification for more detail.
2107     root_x
2108     root_y
2109         The position of the pointer in screen coordinates (16.16 fixed point).
2110     event_x
2111     event_y
2112         The position of the pointer in screen coordinates relative to the
2113         event window (16.16 fixed point).
2114
2115     buttons_len
2116         The length of buttons in 4 byte units.
2117     valuators_len
2118         The length of valuators in 4 byte units.
2119     sourceid
2120         The source device that originally generated the event.
2121     mods
2122         XKB modifier state before the event occured.
2123     group
2124         XKB group state before the event.
2125     buttons
2126         Button state before the event.
2127     valuators
2128         Bitmask of valuators provided in axisvalues.
2129     axisvalues
2130         Valuator data in device-native resolution.
2131     flags
2132         Miscellaneous information about this event; the union of the
2133         common flag set and either the key or pointer flag set,
2134         depending on the event type.
2135         KeyRepeat means that this event is for repeating purposes, and
2136         the physical state of the key has not changed.  This is only
2137         valid for KeyPress events.
2138         PointerEmulated signals that the event has been emulated from another
2139         XI 2.x event for legacy client support, and that this event should
2140         be ignored if the client listens for these events.  This flag is
2141         set on scroll ButtonPress and RawButtonPress events (buttons 4, 5, 6
2142         and 7) if a smooth-scrolling event on the Rel Vert Scroll or
2143         Rel Horiz Scroll axes was also generated. It is also set on Motion,
2144         ButtonPress, and ButtonRelease events generated by direct touch devices.
2145         TouchPendingEnd (for touch events only) means that the touch
2146         has physically ended, however another client still holds a grab, so the
2147         touch should be considered alive until all grabbing clients have
2148         accepted or passed on ownership.  The touch will not generate any
2149         further TouchUpdate events once an event with TouchPendingEnd has been
2150         received.
2151         TouchEmulatingPointer is set on touch events that emulate pointer
2152         events.
2153
2154 Modifier state in mods is detailed as follows:
2155
2156     base_mods
2157         XKB base modifier state.
2158     latched_mods
2159         XKB latched modifier state.
2160     locked_mods
2161         XKB locked modifier state.
2162
2163     Group state in group is detailed as follows:
2164     base_group
2165         XKB base group state.
2166     latched_group
2167         XKB latched group state.
2168     locked_group
2169         XKB locked group state.
2170
2171 In servers supporting XI 2.2, a TouchBegin event is generated whenever a new
2172 touch sequence initializes.
2173 A TouchEnd event is generated whenever a touch sequence ceases. A
2174 TouchUpdate event is generated whenever a valuator value changes, or a flag
2175 flag (e.g. pending end) has changed for that touch sequence; this may result
2176 in a TouchUpdate event being sent with zero valuators.
2177
2178 The average finger size is significantly larger than one pixel. The
2179 selection of the hotspot of a touchpoint is implementation dependent and
2180 may not be the logical center of the touch.
2181
2182 Touch tracking IDs are provided in the detail field of touch events. Its
2183 value is always provided in every touch event. Tracking IDs are
2184 represented as unsigned 32-bit values and increase strictly monotonically in
2185 value for each new touch, wrapping back to 0 upon reaching the numerical limit
2186 of IDs. The increment between two touch IDs is indeterminate. Clients may not
2187 assume that any future touches will have specific touch IDs. IDs are globally
2188 unique.
2189
2190 The button state in touch events represents the state of the device's
2191 physical buttons only, even if that sequence is emulating pointer events.
2192
2193 Touch events do not generate enter/leave events.
2194
2195 [[events-rawevent]]
2196     ┌───
2197         RawEvent
2198             EVENTHEADER
2199             detail:                    CARD32
2200             sourceid¹:                 DEVICEID
2201             flags:                     DEVICEEVENTFLAGS
2202             valuators_len:             CARD16
2203             valuators:                 SETofVALUATORMASK
2204             axisvalues:                LISTofFP3232
2205             axisvalues_raw:            LISTofFP3232
2206     └───
2207
2208     ¹ since XI 2.1
2209
2210 A RawEvent provides the information provided by the driver to the
2211 client. RawEvent provides both the raw data as supplied by the driver and
2212 transformed data as used in the server. Transformations include, but are
2213 not limited to, axis clipping and acceleration.
2214 Transformed valuator data may be equivalent to raw data. In this case,
2215 both raw and transformed valuator data is provided.
2216 RawEvents are sent exclusively to all root windows.
2217 Clients supporting XI 2.0 receive raw events when the device is not grabbed,
2218 or when the device is grabbed by the client but not when the device is
2219 grabbed by another client.
2220 Clients supporting XI 2.1 or later receive raw events at all times, even
2221 when the device is grabbed by another client.
2222
2223
2224     eventtype
2225         The type of event that occured on the device.
2226     detail
2227         The button number, keycode or touch ID¹.
2228     sourceid
2229         The source device that originally generated the event. The sourceid
2230         is undefined for clients not supporting XI 2.1.
2231     flags
2232         Flags as described in DeviceEvent.
2233     valuators_len
2234         The length of valuators in 4 byte units.
2235     valuators
2236         Bitmask of valuators provided in axisvalues and axisvalues_raw.
2237     axisvalues
2238         Valuator data in device-native resolution.
2239     axisvalues_raw
2240         Untransformed valuator data in device-native resolution.
2241
2242     ¹ since XI 2.2
2243
2244 [[events-enterleave]]
2245     ┌───
2246         Enter or Leave or FocusIn or FocusOut
2247             EVENTHEADER
2248             root:               Window
2249             event:              Window
2250             child:              Window
2251             sourceid:           DEVICEID
2252             root_x:             FP1616
2253             root_y:             FP1616
2254             event_x             FP1616
2255             event_y:            FP1616
2256             mode:               NOTIFYMODE
2257             detail:             NOTIFYDETAIL
2258             same_screen:        BOOL
2259             focus:              BOOL
2260             mods:               MODIFIERINFO
2261             group:              GROUPINFO
2262             buttons_len:        CARD16
2263             buttons:            SETofBUTTONMASK
2264     └───
2265
2266     NOTIFYMODE { Normal, Grab, Ungrab }
2267     NOTIFYDETAIL { Ancestor, Virtual, Inferior, Nonlinear, NonlinearVirtual,
2268                    Pointer, PointerRoot, None }
2269
2270 Enter or Leave events are sent whenever a device's pointer enters or
2271 leaves a window.
2272 FocusIn or FocusOut events are sent whenever a device's focus is set to or
2273 away from a window.
2274 The enter/leave and focus in/out model is described in the core protocol
2275 specification, Section 11. (EnterNotify, LeaveNotify events).
2276
2277 For enter and leave events, the modifier and group state is the state of
2278 the paired master device if the device is a master device, or the state of
2279 the attached master keyboard if the device is an attached slave device, or
2280 zero if the device is a floating slave device.
2281
2282 For focus in and out events, the button state is the state of the paired
2283 master device if the device is a master device, or the state of the
2284 attached master keyboard if the device is an attached slave device, or
2285 zero if the device is a floating slave device.
2286
2287     root
2288     event
2289     child
2290         The root window, event window, and child window, respectively. See the
2291         core protocol specification for more detail.
2292     sourceid
2293         The device that caused the pointer to move.
2294     root_x
2295     root_y
2296         The pointer coordinates relative to the root window.
2297     event_x
2298     event_y
2299         The pointer coordinates relative to the event window.
2300     mode
2301         Normal pointer motion events have mode Normal. Pseudo-motion events
2302         when a grab activates have mode Grab, and pseudo-motion events when a
2303         grab deactivates have mode Ungrab. Pseudo-motion events caused by the
2304         activation or deactivation of a passive enter or focus in grab have mode
2305         XIPassiveGrabNotify or XIPassiveUngrabNotify.
2306     detail
2307         Specifies the relation of the event window to the window the pointer
2308         entered or left. See the core protocol spec for details.
2309     same_screen
2310         True if the event window is on the same screen as the pointer's root
2311         window.
2312     focus
2313         If the event window is the focus window or an inferior of the focus
2314         window, then focus is True. Otherwise, focus is False. This field is
2315         unspecified for focus in/out events.
2316     mods
2317         XKB modifier state before the event occured.
2318     group
2319         XKB group state before the event.
2320     buttons_len
2321         The length of buttons in 4 byte units.
2322     buttons
2323         Button state before the event.
2324
2325 [[events-propertyevent]]
2326     ┌───
2327         XIPropertyEvent
2328             EVENTHEADER
2329             property:           ATOM
2330             what:               { PropertyCreated, PropertyDeleted, PropertyModified }
2331     └───
2332
2333 XIPropertyEvents are sent whenever a device property is created, deleted or
2334 modified by a client.
2335
2336     property
2337         The property that has been created, deleted, or modified
2338     what
2339         Specifies what has been changed.
2340      
2341 [[events-xi22]]
2342 Events introduced in version 2.2
2343 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2344
2345 [[events-touchownershipevent]]
2346     ┌───
2347         TouchOwnershipEvent
2348             EVENTHEADER
2349             touchid:                    CARD32
2350             root:                       Window
2351             event:                      Window
2352             child:                      Window
2353             sourceid:                   DEVICEID
2354             flags:                      SETofTOUCHOWNERSHIPFLAGS
2355     └───
2356
2357     TOUCHOWNERSHIPFLAGS:    (none currently defined)
2358
2359 A TouchOwnershipEvent indicates that ownership has changed, and the client
2360 is now the owner of the touch sequence specified by touchid.
2361
2362     touchid
2363         The identifier of the touch sequence.
2364     root
2365     event
2366     child
2367         The root window, event window, and child window, respectively. See the
2368         core protocol specification for more detail.
2369     sourceid
2370         The source device that originally generated the event.
2371     flags
2372         A bitmask of flags for this event.
2373
2374
2375 :numbered!:
2376 [[xi22-usecases]]
2377 [appendix]
2378 XI 2.2 Use-cases
2379 ----------------
2380
2381 All use-cases that include the receiving and processing of touch events
2382 require the client to announce XI 2.2 support in the XIQueryVersion request.
2383
2384 Client C wants to process touch events from a device D on window W.
2385 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2386 * C calls XISelectEvent for XI_Touch{Begin|Update|End} from D on W.
2387 * C receives TouchBegin whenever a touch sequence starts within W's borders.
2388 * C receives TouchUpdate events whenever an axis valuator value changes for a
2389    touch sequence it received a TouchBegin event for.
2390 * C receives TouchEnd whenever a touch it received a TouchBegin event for
2391    ceases.
2392
2393 While client I wants to pre-process touch events from device D on the parent window  of W.
2394 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2395 * C calls XISelectEvent for XI_Touch{Begin|Update|Ownership|End} from D on W.
2396 * I calls XIPassiveGrab for XI_Touch{Begin|Update|Ownership|End} from D on a
2397    parent window of W.
2398 * I receives TouchBegin whenever a touch begins within window W, as well as a
2399    TouchOwnership event indicating that it currently owns the touch sequence.
2400    C receives a TouchBegin event as well, but without TouchOwnership.
2401 * When an axis valuator changes in this touch sequence, both I and C receive a
2402    TouchUpdate event.  I may process the event to determine if it is going to
2403    accept or reject the touch, whereas C may perform reversible processing.
2404 * If I decides it is going to claim the touch sequence for its exclusive
2405    processing, it calls XIAllowEvents with an event mode of XIAcceptTouch; at
2406    this point, C receives a TouchEnd event, and undoes any processing it has
2407    already performed due to the touch sequence.  Further TouchUpdate events are
2408    delivered only to I.
2409 * Alternatively, if I decides it does not want to receive further events
2410    from this touch sequence, it calls XIAllowEvents with an event mode of
2411    XIRejectTouch; at this point, I receives a TouchEnd event confirming that it
2412    has rejected the touch.  C receives a TouchOwnership event confirming that it
2413    is now the new owner of the touch, and further TouchUpdate events are
2414    delivered only to C.  As C now owns the touch, it is free to perform
2415    irreversible processing of the sequence.
2416 * When the touch physically ceases, a TouchEnd event is sent to C.
2417
2418 While client I wants to process pointer events on window W's parent, window Y.
2419 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2420 * I calls XIPassiveGrab for XI_{ButtonPress,MotionNotify,ButtonRelease} to
2421    create a synchronous pointer grab from D on Y.
2422 * C calls XISelectEvent for XI_Touch{Begin|Update|Ownership|End} from D on W.
2423 * I receives a ButtonPress event whenever a touch begins within W, and is
2424    considered the owner of the event.  C receives a TouchBegin event, but does
2425    not receive a TouchOwnership event.
2426 * When the touchpoint moves, C will receive a TouchUpdate event.  Event
2427    delivery to I is subject to the synchronous delivery mechanism. The
2428    emulated motion notify event is queued in the server while the device is
2429    frozen.
2430 * I may assert ownership by calling XIAllowEvents on Y with any mode other
2431    than ReplayDevice, which will cause all further events to be sent only to I,
2432    with a TouchEnd event being sent to C.
2433 * Alternatively, I may reject the touch sequence by calling XIAllowEvents on
2434    Y with mode ReplayDevice, which will cause no further events from that touch
2435    to be sent to I, and a TouchOwnership event to be sent to C, with subsequent
2436    motion events being sent as TouchUpdate events.
2437
2438 Driver DRV provides touch support from tracked device D:
2439 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2440 * DRV initializes a TouchClass for the device.
2441 * DRV parses D's device protocol and selects one touch sequence to be emulated
2442    as pointer event.
2443 * DRV calls the respective input driver API with the touch sequence data. The
2444    touch sequence emulating a pointer has the respective flag set. DRV does not
2445    submit pointer data for any touchpoint.