xf86-input-inputtest-protocol.h revision ed6184df
1/*
2 * Copyright © 2020 Povilas Kanapickas <povilas@radix.lt>
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of Red Hat
9 * not be used in advertising or publicity pertaining to distribution
10 * of the software without specific, written prior permission.  Red
11 * Hat makes no representations about the suitability of this software
12 * for any purpose.  It is provided "as is" without express or implied
13 * warranty.
14 *
15 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
24#ifndef XF86_INPUT_INPUTTEST_PROTOCOL_H_
25#define XF86_INPUT_INPUTTEST_PROTOCOL_H_
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include <stdint.h>
32
33#define XF86IT_PROTOCOL_VERSION_MAJOR 1
34#define XF86IT_PROTOCOL_VERSION_MINOR 1
35
36enum xf86ITResponseType {
37    XF86IT_RESPONSE_SERVER_VERSION,
38    XF86IT_RESPONSE_SYNC_FINISHED,
39};
40
41typedef struct {
42    uint32_t length; /* length of the whole event in bytes, including the header */
43    enum xf86ITResponseType type;
44} xf86ITResponseHeader;
45
46typedef struct {
47    xf86ITResponseHeader header;
48    uint16_t major;
49    uint16_t minor;
50} xf86ITResponseServerVersion;
51
52typedef struct {
53    xf86ITResponseHeader header;
54} xf86ITResponseSyncFinished;
55
56typedef union {
57    xf86ITResponseHeader header;
58    xf86ITResponseServerVersion version;
59} xf86ITResponseAny;
60
61/* We care more about preserving the binary input driver protocol more than the
62   size of the messages, so hardcode a larger valuator count than the server has */
63#define XF86IT_MAX_VALUATORS 64
64
65enum xf86ITEventType {
66    XF86IT_EVENT_CLIENT_VERSION,
67    XF86IT_EVENT_WAIT_FOR_SYNC,
68    XF86IT_EVENT_MOTION,
69    XF86IT_EVENT_PROXIMITY,
70    XF86IT_EVENT_BUTTON,
71    XF86IT_EVENT_KEY,
72    XF86IT_EVENT_TOUCH,
73    XF86IT_EVENT_GESTURE_PINCH,
74    XF86IT_EVENT_GESTURE_SWIPE,
75};
76
77typedef struct {
78    uint32_t length; /* length of the whole event in bytes, including the header */
79    enum xf86ITEventType type;
80} xf86ITEventHeader;
81
82typedef struct {
83    uint32_t has_unaccelerated;
84    uint8_t mask[(XF86IT_MAX_VALUATORS + 7) / 8];
85    double valuators[XF86IT_MAX_VALUATORS];
86    double unaccelerated[XF86IT_MAX_VALUATORS];
87} xf86ITValuatorData;
88
89typedef struct {
90    xf86ITEventHeader header;
91    uint16_t major;
92    uint16_t minor;
93} xf86ITEventClientVersion;
94
95typedef struct {
96    xf86ITEventHeader header;
97} xf86ITEventWaitForSync;
98
99typedef struct {
100    xf86ITEventHeader header;
101    uint32_t is_absolute;
102    xf86ITValuatorData valuators;
103} xf86ITEventMotion;
104
105typedef struct {
106    xf86ITEventHeader header;
107    uint32_t is_prox_in;
108    xf86ITValuatorData valuators;
109} xf86ITEventProximity;
110
111typedef struct {
112    xf86ITEventHeader header;
113    int32_t is_absolute;
114    int32_t button;
115    uint32_t is_press;
116    xf86ITValuatorData valuators;
117} xf86ITEventButton;
118
119typedef struct {
120    xf86ITEventHeader header;
121    int32_t key_code;
122    uint32_t is_press;
123} xf86ITEventKey;
124
125typedef struct {
126    xf86ITEventHeader header;
127    uint32_t touchid;
128    uint32_t touch_type;
129    xf86ITValuatorData valuators;
130} xf86ITEventTouch;
131
132typedef struct {
133    xf86ITEventHeader header;
134    uint16_t gesture_type;
135    uint16_t num_touches;
136    uint32_t flags;
137    double delta_x;
138    double delta_y;
139    double delta_unaccel_x;
140    double delta_unaccel_y;
141    double scale;
142    double delta_angle;
143} xf86ITEventGesturePinch;
144
145typedef struct {
146    xf86ITEventHeader header;
147    uint16_t gesture_type;
148    uint16_t num_touches;
149    uint32_t flags;
150    double delta_x;
151    double delta_y;
152    double delta_unaccel_x;
153    double delta_unaccel_y;
154} xf86ITEventGestureSwipe;
155
156typedef union {
157    xf86ITEventHeader header;
158    xf86ITEventClientVersion version;
159    xf86ITEventMotion motion;
160    xf86ITEventProximity proximity;
161    xf86ITEventButton button;
162    xf86ITEventKey key;
163    xf86ITEventTouch touch;
164    xf86ITEventGesturePinch pinch;
165    xf86ITEventGestureSwipe swipe;
166} xf86ITEventAny;
167
168#ifdef __cplusplus
169} /* extern "C" */
170#endif
171
172#endif /* XF86_INPUT_INPUTTEST_PROTOCOL_H_ */
173