1 /*
2  * Copyright © 2009 Red Hat, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  */
24 
25 /* Conventions for this file:
26  * Names:
27  * structs: always typedef'd, prefixed with xXI, CamelCase
28  * struct members: lower_case_with_underscores
29  *        Exceptions: reqType, ReqType, repType, RepType, sequenceNumber are
30  *        named as such for historical reasons.
31  * request opcodes: X_XIRequestName as CamelCase
32  * defines: defines used in client applications must go in XI2.h
33  *          defines used only in protocol handling: XISOMENAME
34  *
35  * Data types: unless there is a historical name for a datatype (e.g.
36  * Window), use stdint types specifying the size of the datatype.
37  * historical data type names must be defined and undefined at the top and
38  * end of the file.
39  *
40  * General:
41  * spaces, not tabs.
42  * structs specific to a request or reply added before the request
43  *      definition. structs used in more than one request, reply or event
44  *      appended to the common structs section before the definition of the
45  *      first request.
46  * members of structs vertically aligned on column 16 if datatypes permit.
47  *      otherwise aligned on next available 8n column.
48  */
49 
50 /**
51  * Protocol definitions for the XI2 protocol.
52  * This file should not be included by clients that merely use XI2, but do not
53  * need the wire protocol. Such clients should include XI2.h, or the matching
54  * header from the library.
55  *
56  */
57 #ifndef _XI2PROTO_H_
58 #define _XI2PROTO_H_
59 
60 #include <X11/Xproto.h>
61 #include <X11/X.h>
62 #include <X11/extensions/XI2.h>
63 #include <stdint.h>
64 
65 /* make sure types have right sizes for protocol structures. */
66 #define Window  uint32_t
67 #define Time    uint32_t
68 #define Atom    uint32_t
69 #define Cursor  uint32_t
70 #define Barrier uint32_t
71 
72 /**
73  * XI2 Request opcodes
74  */
75 #define X_XIQueryPointer                40
76 #define X_XIWarpPointer                 41
77 #define X_XIChangeCursor                42
78 #define X_XIChangeHierarchy             43
79 #define X_XISetClientPointer            44
80 #define X_XIGetClientPointer            45
81 #define X_XISelectEvents                46
82 #define X_XIQueryVersion                47
83 #define X_XIQueryDevice                 48
84 #define X_XISetFocus                    49
85 #define X_XIGetFocus                    50
86 #define X_XIGrabDevice                  51
87 #define X_XIUngrabDevice                52
88 #define X_XIAllowEvents                 53
89 #define X_XIPassiveGrabDevice           54
90 #define X_XIPassiveUngrabDevice         55
91 #define X_XIListProperties              56
92 #define X_XIChangeProperty              57
93 #define X_XIDeleteProperty              58
94 #define X_XIGetProperty                 59
95 #define X_XIGetSelectedEvents           60
96 #define X_XIBarrierReleasePointer       61
97 
98 /** Number of XI requests */
99 #define XI2REQUESTS (X_XIBarrierReleasePointer - X_XIQueryPointer + 1)
100 /** Number of XI2 events */
101 #define XI2EVENTS   (XI_LASTEVENT + 1)
102 
103 /*************************************************************************************
104  *                                                                                   *
105  *                               COMMON STRUCTS                                      *
106  *                                                                                   *
107  *************************************************************************************/
108 /** Fixed point 16.16 */
109 typedef int32_t FP1616;
110 
111 /** Fixed point 32.32 */
112 typedef struct {
113     int32_t     integral;
114     uint32_t    frac;
115 } FP3232;
116 
117 /**
118  * Struct to describe a device.
119  *
120  * For a MasterPointer or a MasterKeyboard, 'attachment' specifies the
121  * paired master device.
122  * For a SlaveKeyboard or SlavePointer, 'attachment' specifies the master
123  * device this device is attached to.
124  * For a FloatingSlave, 'attachment' is undefined.
125  */
126 typedef struct {
127     uint16_t    deviceid;
128     uint16_t    use;            /**< ::XIMasterPointer, ::XIMasterKeyboard,
129                                      ::XISlavePointer, ::XISlaveKeyboard,
130                                      ::XIFloatingSlave */
131     uint16_t    attachment;     /**< Current attachment or pairing.*/
132     uint16_t    num_classes;    /**< Number of classes following this struct. */
133     uint16_t    name_len;       /**< Length of name in bytes. */
134     uint8_t     enabled;        /**< TRUE if device is enabled. */
135     uint8_t     pad;
136 } xXIDeviceInfo;
137 
138 /**
139  * Default template for a device class.
140  * A device class is equivalent to a device's capabilities. Multiple classes
141  * are supported per device.
142  */
143 typedef struct {
144     uint16_t    type;           /**< One of *class */
145     uint16_t    length;         /**< Length in 4 byte units */
146     uint16_t    sourceid;       /**< source device for this class */
147     uint16_t    pad;
148 } xXIAnyInfo;
149 
150 /**
151  * Denotes button capability on a device.
152  * Struct is followed by a button bit-mask (padded to four byte chunks) and
153  * then num_buttons * Atom that names the buttons in the device-native setup
154  * (i.e.  ignoring button mappings).
155  */
156 typedef struct {
157     uint16_t    type;           /**< Always ButtonClass */
158     uint16_t    length;         /**< Length in 4 byte units */
159     uint16_t    sourceid;       /**< source device for this class */
160     uint16_t    num_buttons;    /**< Number of buttons provided */
161 } xXIButtonInfo;
162 
163 /**
164  * Denotes key capability on a device.
165  * Struct is followed by num_keys * CARD32 that lists the keycodes available
166  * on the device.
167  */
168 typedef struct {
169     uint16_t    type;           /**< Always KeyClass */
170     uint16_t    length;         /**< Length in 4 byte units */
171     uint16_t    sourceid;       /**< source device for this class */
172     uint16_t    num_keycodes;   /**< Number of keys provided */
173 } xXIKeyInfo;
174 
175 /**
176  * Denotes an valuator capability on a device.
177  * One XIValuatorInfo describes exactly one valuator (axis) on the device.
178  */
179 typedef struct {
180     uint16_t    type;           /**< Always ValuatorClass       */
181     uint16_t    length;         /**< Length in 4 byte units */
182     uint16_t    sourceid;       /**< source device for this class */
183     uint16_t    number;         /**< Valuator number            */
184     Atom        label;          /**< Axis label                 */
185     FP3232      min;            /**< Min value                  */
186     FP3232      max;            /**< Max value                  */
187     FP3232      value;          /**< Last published value       */
188     uint32_t    resolution;     /**< Resolutions in units/m     */
189     uint8_t     mode;           /**< ModeRelative or ModeAbsolute */
190     uint8_t     pad1;
191     uint16_t    pad2;
192 } xXIValuatorInfo;
193 
194 /***
195  * Denotes a scroll valuator on a device.
196  * One XIScrollInfo describes exactly one scroll valuator that must have a
197  * XIValuatorInfo struct.
198  */
199 typedef struct {
200     uint16_t    type;           /**< Always ValuatorClass         */
201     uint16_t    length;         /**< Length in 4 byte units       */
202     uint16_t    sourceid;       /**< source device for this class */
203     uint16_t    number;         /**< Valuator number              */
204     uint16_t    scroll_type;    /**< ::XIScrollTypeVertical, ::XIScrollTypeHorizontal */
205     uint16_t    pad0;
206     uint32_t    flags;          /**< ::XIScrollFlagEmulate, ::XIScrollFlagPreferred   */
207     FP3232      increment;      /**< Increment for one unit of scrolling              */
208 } xXIScrollInfo;
209 
210 /**
211  * Denotes multitouch capability on a device.
212  */
213 typedef struct {
214     uint16_t    type;           /**< Always TouchClass */
215     uint16_t    length;         /**< Length in 4 byte units */
216     uint16_t    sourceid;       /**< source device for this class */
217     uint8_t     mode;           /**< DirectTouch or DependentTouch */
218     uint8_t     num_touches;    /**< Maximum number of touches (0==unlimited) */
219 } xXITouchInfo;
220 
221 /**
222  * Denotes touchpad gesture capability on a device.
223  */
224 typedef struct {
225     uint16_t    type;           /**< Always GestureClass */
226     uint16_t    length;         /**< Length in 4 byte units */
227     uint16_t    sourceid;       /**< source device for this class */
228     uint8_t     num_touches;    /**< Maximum number of touches gesture supports (0==unlimited) */
229     uint8_t     pad0;
230 } xXIGestureInfo;
231 
232 /**
233  * Used to select for events on a given window.
234  * Struct is followed by (mask_len * CARD8), with each bit set representing
235  * the event mask for the given type. A mask bit represents an event type if
236  * (mask == (1 << type)).
237  */
238 typedef struct {
239     uint16_t    deviceid;       /**< Device id to select for        */
240     uint16_t    mask_len;       /**< Length of mask in 4 byte units */
241 } xXIEventMask;
242 
243 /**
244  * XKB modifier information.
245  * The effective modifier is a binary mask of base, latched, and locked
246  * modifiers.
247  */
248 typedef struct
249 {
250     uint32_t    base_mods;              /**< Logically pressed modifiers */
251     uint32_t    latched_mods;           /**< Logically latched modifiers */
252     uint32_t    locked_mods;            /**< Logically locked modifiers */
253     uint32_t    effective_mods;         /**< Effective modifiers */
254 } xXIModifierInfo;
255 
256 /**
257  * XKB group information.
258  * The effective group is the mathematical sum of base, latched, and locked
259  * group after group wrapping is taken into account.
260  */
261 typedef struct
262 {
263     uint8_t     base_group;             /**< Logically "pressed" group */
264     uint8_t     latched_group;          /**< Logically latched group */
265     uint8_t     locked_group;           /**< Logically locked group */
266     uint8_t     effective_group;        /**< Effective group */
267 } xXIGroupInfo;
268 
269 
270 /*************************************************************************************
271  *                                                                                   *
272  *                                   REQUESTS                                        *
273  *                                                                                   *
274  *************************************************************************************/
275 
276 /**
277  * Query the server for the supported X Input extension version.
278  */
279 
280 typedef struct {
281     uint8_t     reqType;                /**< Input extension major code */
282     uint8_t     ReqType;                /**< Always ::X_XIQueryVersion */
283     uint16_t    length;                 /**< Length in 4 byte units */
284     uint16_t    major_version;
285     uint16_t    minor_version;
286 } xXIQueryVersionReq;
287 #define sz_xXIQueryVersionReq                     8
288 
289 typedef struct {
290     uint8_t     repType;                /**< ::X_Reply */
291     uint8_t     RepType;                /**< Always ::X_XIQueryVersion */
292     uint16_t    sequenceNumber;
293     uint32_t    length;
294     uint16_t    major_version;
295     uint16_t    minor_version;
296     uint32_t    pad1;
297     uint32_t    pad2;
298     uint32_t    pad3;
299     uint32_t    pad4;
300     uint32_t    pad5;
301 } xXIQueryVersionReply;
302 #define sz_xXIQueryVersionReply             32
303 
304 /**
305  * Query the server for information about a specific device or all input
306  * devices.
307  */
308 typedef struct {
309     uint8_t     reqType;                /**< Input extension major code */
310     uint8_t     ReqType;                /**< Always ::X_XIQueryDevice */
311     uint16_t    length;                 /**< Length in 4 byte units */
312     uint16_t    deviceid;
313     uint16_t    pad;
314 } xXIQueryDeviceReq;
315 #define sz_xXIQueryDeviceReq                    8
316 
317 typedef struct {
318     uint8_t     repType;                /**< ::X_Reply */
319     uint8_t     RepType;                /**< Always ::X_XIQueryDevice */
320     uint16_t    sequenceNumber;
321     uint32_t    length;
322     uint16_t    num_devices;
323     uint16_t    pad0;
324     uint32_t    pad1;
325     uint32_t    pad2;
326     uint32_t    pad3;
327     uint32_t    pad4;
328     uint32_t    pad5;
329 } xXIQueryDeviceReply;
330 #define sz_xXIQueryDeviceReply                  32
331 
332 /**
333  * Select for events on a given window.
334  */
335 typedef struct {
336     uint8_t     reqType;                /**< Input extension major code */
337     uint8_t     ReqType;                /**< Always ::X_XISelectEvents */
338     uint16_t    length;                 /**< Length in 4 byte units */
339     Window      win;
340     uint16_t    num_masks;
341     uint16_t    pad;
342 } xXISelectEventsReq;
343 #define sz_xXISelectEventsReq                  12
344 
345 /**
346  * Query for selected events on a given window.
347  */
348 typedef struct {
349     uint8_t     reqType;                /**< Input extension major code */
350     uint8_t     ReqType;                /**< Always ::X_XIGetSelectedEvents */
351     uint16_t    length;                 /**< Length in 4 byte units */
352     Window      win;
353 } xXIGetSelectedEventsReq;
354 #define sz_xXIGetSelectedEventsReq              8
355 
356 typedef struct {
357     uint8_t     repType;                /**< Input extension major opcode */
358     uint8_t     RepType;                /**< Always ::X_XIGetSelectedEvents */
359     uint16_t    sequenceNumber;
360     uint32_t    length;
361     uint16_t    num_masks;              /**< Number of xXIEventMask structs
362                                              trailing the reply */
363     uint16_t    pad0;
364     uint32_t    pad1;
365     uint32_t    pad2;
366     uint32_t    pad3;
367     uint32_t    pad4;
368     uint32_t    pad5;
369 } xXIGetSelectedEventsReply;
370 #define sz_xXIGetSelectedEventsReply            32
371 
372 /**
373  * Query the given device's screen/window coordinates.
374  */
375 
376 typedef struct {
377     uint8_t     reqType;                /**< Input extension major code */
378     uint8_t     ReqType;                /**< Always ::X_XIQueryPointer */
379     uint16_t    length;                 /**< Length in 4 byte units */
380     Window      win;
381     uint16_t    deviceid;
382     uint16_t    pad1;
383 } xXIQueryPointerReq;
384 #define sz_xXIQueryPointerReq                   12
385 
386 
387 typedef struct {
388     uint8_t     repType;                /**< Input extension major opcode */
389     uint8_t     RepType;                /**< Always ::X_XIQueryPointer */
390     uint16_t    sequenceNumber;
391     uint32_t    length;
392     Window      root;
393     Window      child;
394     FP1616      root_x;
395     FP1616      root_y;
396     FP1616      win_x;
397     FP1616      win_y;
398     uint8_t     same_screen;
399     uint8_t     pad0;
400     uint16_t    buttons_len;
401     xXIModifierInfo mods;
402     xXIGroupInfo group;
403 } xXIQueryPointerReply;
404 #define sz_xXIQueryPointerReply                 56
405 
406 /**
407  * Warp the given device's pointer to the specified position.
408  */
409 
410 typedef struct {
411     uint8_t     reqType;                /**< Input extension major code */
412     uint8_t     ReqType;                /**< Always ::X_XIWarpPointer   */
413     uint16_t    length;                 /**< Length in 4 byte units */
414     Window      src_win;
415     Window      dst_win;
416     FP1616      src_x;
417     FP1616      src_y;
418     uint16_t    src_width;
419     uint16_t    src_height;
420     FP1616      dst_x;
421     FP1616      dst_y;
422     uint16_t    deviceid;
423     uint16_t    pad1;
424 } xXIWarpPointerReq;
425 #define sz_xXIWarpPointerReq                    36
426 
427 /**
428  * Change the given device's sprite to the given cursor.
429  */
430 
431 typedef struct {
432     uint8_t     reqType;                /**< Input extension major code */
433     uint8_t     ReqType;                /**< Always ::X_XIChangeCursor  */
434     uint16_t    length;                 /**< Length in 4 byte units */
435     Window      win;
436     Cursor      cursor;
437     uint16_t    deviceid;
438     uint16_t    pad1;
439 } xXIChangeCursorReq;
440 #define sz_xXIChangeCursorReq                           16
441 
442 /**
443  * Modify the device hierarchy.
444  */
445 
446 typedef struct {
447     uint8_t     reqType;                /**< Input extension major code */
448     uint8_t     ReqType;                /**< Always ::X_XIChangeHierarchy */
449     uint16_t    length;                 /**< Length in 4 byte units */
450     uint8_t     num_changes;
451     uint8_t     pad0;
452     uint16_t    pad1;
453 } xXIChangeHierarchyReq;
454 #define sz_xXIChangeHierarchyReq                        8
455 
456 /**
457  * Generic header for any hierarchy change.
458  */
459 typedef struct {
460     uint16_t    type;
461     uint16_t    length;                 /**< Length in 4 byte units */
462 } xXIAnyHierarchyChangeInfo;
463 
464 /**
465  * Create a new master device.
466  * Name of new master follows struct (4-byte padded)
467  */
468 typedef struct {
469     uint16_t    type;                   /**< Always ::XIAddMaster */
470     uint16_t    length;                 /**< 2 + (namelen + padding)/4 */
471     uint16_t    name_len;
472     uint8_t     send_core;
473     uint8_t     enable;
474 } xXIAddMasterInfo;
475 
476 /**
477  * Delete a master device. Will automatically delete the master device paired
478  * with the given master device.
479  */
480 typedef struct {
481     uint16_t    type;            /**< Always ::XIRemoveMaster */
482     uint16_t    length;          /**< 3 */
483     uint16_t    deviceid;
484     uint8_t     return_mode;     /**< ::XIAttachToMaster, ::XIFloating */
485     uint8_t     pad;
486     uint16_t    return_pointer;  /**< Pointer to attach slave ptr devices to */
487     uint16_t    return_keyboard; /**< keyboard to attach slave keybd devices to*/
488 } xXIRemoveMasterInfo;
489 
490 /**
491  * Attach an SD to a new device.
492  * NewMaster has to be of same type (pointer->pointer, keyboard->keyboard);
493  */
494 typedef struct {
495     uint16_t    type;           /**< Always ::XIAttachSlave */
496     uint16_t    length;         /**< 2 */
497     uint16_t    deviceid;
498     uint16_t    new_master;     /**< id of new master device */
499 } xXIAttachSlaveInfo;
500 
501 /**
502  * Detach an SD from its current master device.
503  */
504 typedef struct {
505     uint16_t    type;           /**< Always ::XIDetachSlave */
506     uint16_t    length;         /**< 2 */
507     uint16_t    deviceid;
508     uint16_t    pad;
509 } xXIDetachSlaveInfo;
510 
511 
512 /**
513  * Set the window/client's ClientPointer.
514  */
515 typedef struct {
516     uint8_t     reqType;
517     uint8_t     ReqType;                /**< Always ::X_XISetClientPointer */
518     uint16_t    length;                 /**< Length in 4 byte units */
519     Window      win;
520     uint16_t    deviceid;
521     uint16_t    pad1;
522 } xXISetClientPointerReq;
523 #define sz_xXISetClientPointerReq                 12
524 
525 /**
526  * Query the given window/client's ClientPointer setting.
527  */
528 typedef struct {
529     uint8_t     reqType;
530     uint8_t     ReqType;                /**< Always ::X_GetClientPointer */
531     uint16_t    length;                 /**< Length in 4 byte units */
532     Window      win;
533 } xXIGetClientPointerReq;
534 #define sz_xXIGetClientPointerReq                 8
535 
536 typedef struct {
537     uint8_t     repType;                /**< Input extension major opcode */
538     uint8_t     RepType;                /**< Always ::X_GetClientPointer */
539     uint16_t    sequenceNumber;
540     uint32_t    length;
541     BOOL        set;                    /**< client pointer is set? */
542     uint8_t     pad0;
543     uint16_t    deviceid;
544     uint32_t    pad1;
545     uint32_t    pad2;
546     uint32_t    pad3;
547     uint32_t    pad4;
548     uint32_t    pad5;
549 } xXIGetClientPointerReply;
550 #define sz_xXIGetClientPointerReply               32
551 
552 /**
553  * Set the input focus to the specified window.
554  */
555 typedef struct {
556     uint8_t     reqType;
557     uint8_t     ReqType;                /**< Always ::X_XISetFocus */
558     uint16_t    length;                 /**< Length in 4 byte units */
559     Window      focus;
560     Time        time;
561     uint16_t    deviceid;
562     uint16_t    pad0;
563 } xXISetFocusReq;
564 #define sz_xXISetFocusReq                       16
565 
566 /**
567  * Query the current input focus.
568  */
569 typedef struct {
570     uint8_t     reqType;
571     uint8_t     ReqType;                /**< Always ::X_XIGetDeviceFocus */
572     uint16_t    length;                 /**< Length in 4 byte units */
573     uint16_t    deviceid;
574     uint16_t    pad0;
575 } xXIGetFocusReq;
576 #define sz_xXIGetFocusReq                       8
577 
578 typedef struct {
579     uint8_t     repType;                /**< Input extension major opcode */
580     uint8_t     RepType;                /**< Always ::X_XIGetFocus */
581     uint16_t    sequenceNumber;
582     uint32_t    length;
583     Window      focus;
584     uint32_t    pad1;
585     uint32_t    pad2;
586     uint32_t    pad3;
587     uint32_t    pad4;
588     uint32_t    pad5;
589 } xXIGetFocusReply;
590 #define sz_xXIGetFocusReply                     32
591 
592 
593 /**
594  * Grab the given device.
595  */
596 typedef struct {
597     uint8_t     reqType;
598     uint8_t     ReqType;                /**< Always ::X_XIGrabDevice */
599     uint16_t    length;                 /**< Length in 4 byte units */
600     Window      grab_window;
601     Time        time;
602     Cursor      cursor;
603     uint16_t    deviceid;
604     uint8_t     grab_mode;
605     uint8_t     paired_device_mode;
606     uint8_t     owner_events;
607     uint8_t     pad;
608     uint16_t    mask_len;
609 } xXIGrabDeviceReq;
610 #define sz_xXIGrabDeviceReq                     24
611 
612 /**
613  * Return codes from a XIPassiveGrabDevice request.
614  */
615 typedef struct {
616     uint32_t    modifiers;              /**< Modifier state */
617     uint8_t     status;                 /**< Grab status code */
618     uint8_t     pad0;
619     uint16_t    pad1;
620 } xXIGrabModifierInfo;
621 
622 typedef struct {
623     uint8_t     repType;                /**< Input extension major opcode */
624     uint8_t     RepType;                /**< Always ::X_XIGrabDevice */
625     uint16_t    sequenceNumber;
626     uint32_t    length;
627     uint8_t     status;
628     uint8_t     pad0;
629     uint16_t    pad1;
630     uint32_t    pad2;
631     uint32_t    pad3;
632     uint32_t    pad4;
633     uint32_t    pad5;
634     uint32_t    pad6;
635 } xXIGrabDeviceReply;
636 #define sz_xXIGrabDeviceReply                  32
637 
638 /**
639  * Ungrab the specified device.
640  *
641  */
642 typedef struct {
643     uint8_t     reqType;
644     uint8_t     ReqType;                /**< Always ::X_XIUngrabDevice */
645     uint16_t    length;                 /**< Length in 4 byte units */
646     Time        time;
647     uint16_t    deviceid;
648     uint16_t    pad;
649 } xXIUngrabDeviceReq;
650 #define sz_xXIUngrabDeviceReq                   12
651 
652 
653 /**
654  * Allow or replay events on the specified grabbed device.
655  */
656 typedef struct {
657     uint8_t     reqType;
658     uint8_t     ReqType;                /**< Always ::X_XIAllowEvents */
659     uint16_t    length;                 /**< Length in 4 byte units */
660     Time        time;
661     uint16_t    deviceid;
662     uint8_t     mode;
663     uint8_t     pad;
664 } xXIAllowEventsReq;
665 #define sz_xXIAllowEventsReq                   12
666 
667 /**
668  * Allow or replay events on the specified grabbed device.
669  * Since XI 2.2
670  */
671 typedef struct {
672     uint8_t     reqType;
673     uint8_t     ReqType;                /**< Always ::X_XIAllowEvents */
674     uint16_t    length;                 /**< Length in 4 byte units */
675     Time        time;
676     uint16_t    deviceid;
677     uint8_t     mode;
678     uint8_t     pad;
679     uint32_t    touchid;                /**< Since XI 2.2 */
680     Window      grab_window;            /**< Since XI 2.2 */
681 } xXI2_2AllowEventsReq;
682 #define sz_xXI2_2AllowEventsReq                20
683 
684 
685 /**
686  * Passively grab the device.
687  */
688 typedef struct {
689     uint8_t     reqType;
690     uint8_t     ReqType;                /**< Always ::X_XIPassiveGrabDevice */
691     uint16_t    length;                 /**< Length in 4 byte units */
692     Time        time;
693     Window      grab_window;
694     Cursor      cursor;
695     uint32_t    detail;
696     uint16_t    deviceid;
697     uint16_t    num_modifiers;
698     uint16_t    mask_len;
699     uint8_t     grab_type;
700     uint8_t     grab_mode;
701     uint8_t     paired_device_mode;
702     uint8_t     owner_events;
703     uint16_t    pad1;
704 } xXIPassiveGrabDeviceReq;
705 #define sz_xXIPassiveGrabDeviceReq              32
706 
707 typedef struct {
708     uint8_t     repType;                /**< Input extension major opcode */
709     uint8_t     RepType;                /**< Always ::X_XIPassiveGrabDevice */
710     uint16_t    sequenceNumber;
711     uint32_t    length;
712     uint16_t    num_modifiers;
713     uint16_t    pad1;
714     uint32_t    pad2;
715     uint32_t    pad3;
716     uint32_t    pad4;
717     uint32_t    pad5;
718     uint32_t    pad6;
719 } xXIPassiveGrabDeviceReply;
720 #define sz_xXIPassiveGrabDeviceReply            32
721 
722 /**
723  * Delete a passive grab for the given device.
724  */
725 typedef struct {
726     uint8_t     reqType;
727     uint8_t     ReqType;                /**< Always ::X_XIPassiveUngrabDevice */
728     uint16_t    length;                 /**< Length in 4 byte units */
729     Window      grab_window;
730     uint32_t    detail;
731     uint16_t    deviceid;
732     uint16_t    num_modifiers;
733     uint8_t     grab_type;
734     uint8_t     pad0;
735     uint16_t    pad1;
736 } xXIPassiveUngrabDeviceReq;
737 #define sz_xXIPassiveUngrabDeviceReq            20
738 
739 /**
740  * List all device properties on the specified device.
741  */
742 typedef struct {
743     uint8_t     reqType;
744     uint8_t     ReqType;                /**< Always ::X_XIListProperties */
745     uint16_t    length;                 /**< Length in 4 byte units */
746     uint16_t    deviceid;
747     uint16_t    pad;
748 } xXIListPropertiesReq;
749 #define sz_xXIListPropertiesReq                 8
750 
751 typedef struct {
752     uint8_t     repType;                /**< Input extension major opcode */
753     uint8_t     RepType;                /**< Always ::X_XIListProperties */
754     uint16_t    sequenceNumber;
755     uint32_t    length;
756     uint16_t    num_properties;
757     uint16_t    pad0;
758     uint32_t    pad1;
759     uint32_t    pad2;
760     uint32_t    pad3;
761     uint32_t    pad4;
762     uint32_t    pad5;
763 } xXIListPropertiesReply;
764 #define sz_xXIListPropertiesReply               32
765 
766 /**
767  * Change a property on the specified device.
768  */
769 typedef struct {
770     uint8_t     reqType;
771     uint8_t     ReqType;                /**< Always ::X_XIChangeProperty */
772     uint16_t    length;                 /**< Length in 4 byte units */
773     uint16_t    deviceid;
774     uint8_t     mode;
775     uint8_t     format;
776     Atom        property;
777     Atom        type;
778     uint32_t    num_items;
779 } xXIChangePropertyReq;
780 #define sz_xXIChangePropertyReq                 20
781 
782 /**
783  * Delete the specified property.
784  */
785 typedef struct {
786     uint8_t     reqType;
787     uint8_t     ReqType;                /**< Always X_XIDeleteProperty */
788     uint16_t    length;                 /**< Length in 4 byte units */
789     uint16_t    deviceid;
790     uint16_t    pad0;
791     Atom        property;
792 } xXIDeletePropertyReq;
793 #define sz_xXIDeletePropertyReq                 12
794 
795 /**
796  * Query the specified property's values.
797  */
798 typedef struct {
799     uint8_t     reqType;
800     uint8_t     ReqType;                /**< Always X_XIGetProperty */
801     uint16_t    length;                 /**< Length in 4 byte units */
802     uint16_t    deviceid;
803 #if defined(__cplusplus) || defined(c_plusplus)
804     uint8_t     c_delete;
805 #else
806     uint8_t     delete;
807 #endif
808     uint8_t     pad0;
809     Atom        property;
810     Atom        type;
811     uint32_t    offset;
812     uint32_t    len;
813 } xXIGetPropertyReq;
814 #define sz_xXIGetPropertyReq                    24
815 
816 typedef struct {
817     uint8_t     repType;                /**< Input extension major opcode */
818     uint8_t     RepType;                /**< Always X_XIGetProperty */
819     uint16_t    sequenceNumber;
820     uint32_t    length;
821     Atom        type;
822     uint32_t    bytes_after;
823     uint32_t    num_items;
824     uint8_t     format;
825     uint8_t     pad0;
826     uint16_t    pad1;
827     uint32_t    pad2;
828     uint32_t    pad3;
829 } xXIGetPropertyReply;
830 #define sz_xXIGetPropertyReply               32
831 
832 typedef struct {
833     uint16_t    deviceid;
834     uint16_t    pad;
835     Barrier     barrier;
836     uint32_t    eventid;
837 } xXIBarrierReleasePointerInfo;
838 
839 typedef struct {
840     uint8_t     reqType;                /**< Input extension major opcode */
841     uint8_t     ReqType;                /**< Always X_XIBarrierReleasePointer */
842     uint16_t    length;
843     uint32_t    num_barriers;
844     /* array of xXIBarrierReleasePointerInfo */
845 } xXIBarrierReleasePointerReq;
846 #define sz_xXIBarrierReleasePointerReq       8
847 
848 /*************************************************************************************
849  *                                                                                   *
850  *                                      EVENTS                                       *
851  *                                                                                   *
852  *************************************************************************************/
853 
854 /**
855  * Generic XI2 event header. All XI2 events use the same header.
856  */
857 typedef struct
858 {
859     uint8_t     type;
860     uint8_t     extension;              /**< XI extension offset */
861     uint16_t    sequenceNumber;
862     uint32_t    length;
863     uint16_t    evtype;
864     uint16_t    deviceid;
865     Time        time;
866 } xXIGenericDeviceEvent;
867 
868 /**
869  * Device hierarchy information.
870  */
871 typedef struct
872 {
873     uint16_t    deviceid;
874     uint16_t    attachment;             /**< ID of master or paired device */
875     uint8_t     use;                    /**< ::XIMasterKeyboard,
876                                              ::XIMasterPointer,
877                                              ::XISlaveKeyboard,
878                                              ::XISlavePointer,
879                                              ::XIFloatingSlave */
880     BOOL        enabled;                /**< TRUE if the device is enabled */
881     uint16_t    pad;
882     uint32_t    flags;                  /**< ::XIMasterAdded, ::XIMasterRemoved,
883                                              ::XISlaveAttached, ::XISlaveDetached,
884                                              ::XISlaveAdded, ::XISlaveRemoved,
885                                              ::XIDeviceEnabled, ::XIDeviceDisabled */
886 } xXIHierarchyInfo;
887 
888 /**
889  * The device hierarchy has been modified. This event includes the device
890  * hierarchy after the modification has been applied.
891  */
892 typedef struct
893 {
894     uint8_t     type;                   /**< Always GenericEvent */
895     uint8_t     extension;              /**< XI extension offset */
896     uint16_t    sequenceNumber;
897     uint32_t    length;                 /**< Length in 4 byte units */
898     uint16_t    evtype;                 /**< ::XI_Hierarchy */
899     uint16_t    deviceid;
900     Time        time;
901     uint32_t    flags;                  /**< ::XIMasterAdded, ::XIMasterDeleted,
902                                              ::XISlaveAttached, ::XISlaveDetached,
903                                              ::XISlaveAdded, ::XISlaveRemoved,
904                                              ::XIDeviceEnabled, ::XIDeviceDisabled */
905     uint16_t    num_info;
906     uint16_t    pad0;
907     uint32_t    pad1;
908     uint32_t    pad2;
909 } xXIHierarchyEvent;
910 
911 /**
912  * A device has changed capabilities.
913  */
914 typedef struct
915 {
916     uint8_t     type;                   /**< Always GenericEvent */
917     uint8_t     extension;              /**< XI extension offset */
918     uint16_t    sequenceNumber;
919     uint32_t    length;                 /**< Length in 4 byte units */
920     uint16_t    evtype;                 /**< XI_DeviceChanged */
921     uint16_t    deviceid;               /**< Device that has changed */
922     Time        time;
923     uint16_t    num_classes;            /**< Number of classes that have changed */
924     uint16_t    sourceid;               /**< Source of the new classes */
925     uint8_t     reason;                 /**< ::XISlaveSwitch, ::XIDeviceChange */
926     uint8_t     pad0;
927     uint16_t    pad1;
928     uint32_t    pad2;
929     uint32_t    pad3;
930 } xXIDeviceChangedEvent;
931 
932 /**
933  * The owner of a touch stream has passed on ownership to another client.
934  */
935 typedef struct
936 {
937     uint8_t     type;               /**< Always GenericEvent */
938     uint8_t     extension;          /**< XI extension offset */
939     uint16_t    sequenceNumber;
940     uint32_t    length;             /**< Length in 4 byte units */
941     uint16_t    evtype;             /**< XI_TouchOwnership */
942     uint16_t    deviceid;           /**< Device that has changed */
943     Time        time;
944     uint32_t    touchid;
945     Window      root;
946     Window      event;
947     Window      child;
948 /* └──────── 32 byte boundary ────────┘ */
949     uint16_t    sourceid;
950     uint16_t    pad0;
951     uint32_t    flags;
952     uint32_t    pad1;
953     uint32_t    pad2;
954 } xXITouchOwnershipEvent;
955 
956 /**
957  * Default input event for pointer, keyboard or touch input.
958  */
959 typedef struct
960 {
961     uint8_t     type;                   /**< Always GenericEvent */
962     uint8_t     extension;              /**< XI extension offset */
963     uint16_t    sequenceNumber;
964     uint32_t    length;                 /**< Length in 4 byte uints */
965     uint16_t    evtype;
966     uint16_t    deviceid;
967     Time        time;
968     uint32_t    detail;                 /**< Keycode or button */
969     Window      root;
970     Window      event;
971     Window      child;
972 /* └──────── 32 byte boundary ────────┘ */
973     FP1616      root_x;                 /**< Always screen coords, 16.16 fixed point */
974     FP1616      root_y;
975     FP1616      event_x;                /**< Always screen coords, 16.16 fixed point */
976     FP1616      event_y;
977     uint16_t    buttons_len;            /**< Len of button flags in 4 b units */
978     uint16_t    valuators_len;          /**< Len of val. flags in 4 b units */
979     uint16_t    sourceid;               /**< The source device */
980     uint16_t    pad0;
981     uint32_t    flags;                  /**< ::XIKeyRepeat */
982     xXIModifierInfo     mods;
983     xXIGroupInfo        group;
984 } xXIDeviceEvent;
985 
986 
987 /**
988  * Sent when an input event is generated. RawEvents include valuator
989  * information in both device-specific data (i.e. unaccelerated) and
990  * processed data (i.e. accelerated, if applicable).
991  */
992 typedef struct
993 {
994     uint8_t     type;                   /**< Always GenericEvent */
995     uint8_t     extension;              /**< XI extension offset */
996     uint16_t    sequenceNumber;
997     uint32_t    length;                 /**< Length in 4 byte uints */
998     uint16_t    evtype;                 /**< ::XI_RawEvent */
999     uint16_t    deviceid;
1000     Time        time;
1001     uint32_t    detail;
1002     uint16_t    sourceid;               /**< The source device (XI 2.1) */
1003     uint16_t    valuators_len;          /**< Length of trailing valuator
1004                                              mask in 4 byte units */
1005     uint32_t    flags;                  /**< ::XIKeyRepeat */
1006     uint32_t    pad2;
1007 } xXIRawEvent;
1008 
1009 /**
1010  * Note that the layout of root, event, child, root_x, root_y, event_x,
1011  * event_y must be identical to the xXIDeviceEvent.
1012  */
1013 typedef struct
1014 {
1015     uint8_t     type;                   /**< Always GenericEvent */
1016     uint8_t     extension;              /**< XI extension offset */
1017     uint16_t    sequenceNumber;
1018     uint32_t    length;                 /**< Length in 4 byte uints */
1019     uint16_t    evtype;                 /**< ::XI_Enter */
1020     uint16_t    deviceid;
1021     Time        time;
1022     uint16_t    sourceid;
1023     uint8_t     mode;
1024     uint8_t     detail;
1025     Window      root;
1026     Window      event;
1027     Window      child;
1028 /* └──────── 32 byte boundary ────────┘ */
1029     FP1616      root_x;
1030     FP1616      root_y;
1031     FP1616      event_x;
1032     FP1616      event_y;
1033     BOOL        same_screen;
1034     BOOL        focus;
1035     uint16_t    buttons_len;            /**< Length of trailing button mask
1036                                              in 4 byte units */
1037     xXIModifierInfo     mods;
1038     xXIGroupInfo        group;
1039 } xXIEnterEvent;
1040 
1041 typedef xXIEnterEvent xXILeaveEvent;
1042 typedef xXIEnterEvent xXIFocusInEvent;
1043 typedef xXIEnterEvent xXIFocusOutEvent;
1044 
1045 /**
1046  * Sent when a device property is created, modified or deleted. Does not
1047  * include property data, the client is required to query the data.
1048  */
1049 typedef struct
1050 {
1051     uint8_t     type;                   /**< Always GenericEvent */
1052     uint8_t     extension;              /**< XI extension offset */
1053     uint16_t    sequenceNumber;
1054     uint32_t    length;                 /**< Length in 4 byte units */
1055     uint16_t    evtype;                 /**< ::XI_PropertyEvent */
1056     uint16_t    deviceid;
1057     Time        time;
1058     Atom        property;
1059     uint8_t     what;                   /**< ::XIPropertyDeleted,
1060                                              ::XIPropertyCreated,
1061                                              ::XIPropertyMotified */
1062     uint8_t     pad0;
1063     uint16_t    pad1;
1064     uint32_t    pad2;
1065     uint32_t    pad3;
1066 } xXIPropertyEvent;
1067 
1068 typedef struct
1069 {
1070     uint8_t     type;                   /**< Always GenericEvent */
1071     uint8_t     extension;              /**< XI extension offset */
1072     uint16_t    sequenceNumber;
1073     uint32_t    length;                 /**< Length in 4 byte units */
1074     uint16_t    evtype;                 /**< ::XI_BarrierHit or ::XI_BarrierLeave */
1075     uint16_t    deviceid;
1076     Time        time;
1077     uint32_t    eventid;
1078     Window      root;
1079     Window      event;
1080     Barrier     barrier;
1081 /* └──────── 32 byte boundary ────────┘ */
1082     uint32_t    dtime;
1083     uint32_t    flags;                  /**< ::XIBarrierPointerReleased
1084                                              ::XIBarrierDeviceIsGrabbed */
1085     uint16_t    sourceid;
1086     int16_t     pad;
1087     FP1616      root_x;
1088     FP1616      root_y;
1089     FP3232      dx;
1090     FP3232      dy;
1091 } xXIBarrierEvent;
1092 
1093 typedef xXIBarrierEvent xXIBarrierHitEvent;
1094 typedef xXIBarrierEvent xXIBarrierPointerReleasedEvent;
1095 typedef xXIBarrierEvent xXIBarrierLeaveEvent;
1096 
1097 /**
1098  * Event for touchpad gesture pinch input events
1099  */
1100 typedef struct
1101 {
1102     uint8_t     type;                   /**< Always GenericEvent */
1103     uint8_t     extension;              /**< XI extension offset */
1104     uint16_t    sequenceNumber;
1105     uint32_t    length;                 /**< Length in 4 byte uints */
1106     uint16_t    evtype;
1107     uint16_t    deviceid;
1108     Time        time;
1109     uint32_t    detail;                 /**< The number of touches in the gesture */
1110     Window      root;
1111     Window      event;
1112     Window      child;
1113 /* └──────── 32 byte boundary ────────┘ */
1114     FP1616      root_x;                 /**< Always screen coords, 16.16 fixed point */
1115     FP1616      root_y;
1116     FP1616      event_x;                /**< Always screen coords, 16.16 fixed point */
1117     FP1616      event_y;
1118     FP1616      delta_x;
1119     FP1616      delta_y;
1120     FP1616      delta_unaccel_x;
1121     FP1616      delta_unaccel_y;
1122     FP1616      scale;
1123     FP1616      delta_angle;
1124     uint16_t    sourceid;               /**< The source device */
1125     uint16_t    pad0;
1126     xXIModifierInfo     mods;
1127     xXIGroupInfo        group;
1128     uint32_t    flags;                  /**< ::XIGesturePinchEventCancelled */
1129 } xXIGesturePinchEvent;
1130 
1131 /**
1132  * Event for touchpad gesture swipe input events
1133  */
1134 typedef struct
1135 {
1136     uint8_t     type;                   /**< Always GenericEvent */
1137     uint8_t     extension;              /**< XI extension offset */
1138     uint16_t    sequenceNumber;
1139     uint32_t    length;                 /**< Length in 4 byte uints */
1140     uint16_t    evtype;
1141     uint16_t    deviceid;
1142     Time        time;
1143     uint32_t    detail;                 /**< The number of touches in the gesture */
1144     Window      root;
1145     Window      event;
1146     Window      child;
1147 /* └──────── 32 byte boundary ────────┘ */
1148     FP1616      root_x;                 /**< Always screen coords, 16.16 fixed point */
1149     FP1616      root_y;
1150     FP1616      event_x;                /**< Always screen coords, 16.16 fixed point */
1151     FP1616      event_y;
1152     FP1616      delta_x;
1153     FP1616      delta_y;
1154     FP1616      delta_unaccel_x;
1155     FP1616      delta_unaccel_y;
1156     uint16_t    sourceid;               /**< The source device */
1157     uint16_t    pad0;
1158     xXIModifierInfo     mods;
1159     xXIGroupInfo        group;
1160     uint32_t    flags;                  /**< ::XIGestureSwipeEventCancelled */
1161 } xXIGestureSwipeEvent;
1162 
1163 #undef Window
1164 #undef Time
1165 #undef Atom
1166 #undef Cursor
1167 #undef Barrier
1168 
1169 #endif /* _XI2PROTO_H_ */
1170