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