blob: c46f90501f8744a3c68d9404f438bbf87861e3aa [file] [log] [blame]
Siarhei Vishniakou78513032022-09-15 18:42:05 -07001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <vector>
20
21#include <input/Input.h>
22#include <input/InputDevice.h>
23#include <input/TouchVideoFrame.h>
24
25namespace android {
26
27/* Describes a configuration change event. */
28struct NotifyConfigurationChangedArgs {
29 int32_t id;
30 nsecs_t eventTime;
31
32 inline NotifyConfigurationChangedArgs() {}
33
34 NotifyConfigurationChangedArgs(int32_t id, nsecs_t eventTime);
35
36 bool operator==(const NotifyConfigurationChangedArgs& rhs) const = default;
37
38 NotifyConfigurationChangedArgs(const NotifyConfigurationChangedArgs& other) = default;
39};
40
41/* Describes a key event. */
42struct NotifyKeyArgs {
43 int32_t id;
44 nsecs_t eventTime;
45
46 int32_t deviceId;
47 uint32_t source;
48 int32_t displayId;
49 uint32_t policyFlags;
50 int32_t action;
51 int32_t flags;
52 int32_t keyCode;
53 int32_t scanCode;
54 int32_t metaState;
55 nsecs_t downTime;
56 nsecs_t readTime;
57
58 inline NotifyKeyArgs() {}
59
60 NotifyKeyArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
61 uint32_t source, int32_t displayId, uint32_t policyFlags, int32_t action,
62 int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState,
63 nsecs_t downTime);
64
65 bool operator==(const NotifyKeyArgs& rhs) const = default;
66
67 NotifyKeyArgs(const NotifyKeyArgs& other) = default;
68};
69
70/* Describes a motion event. */
71struct NotifyMotionArgs {
72 int32_t id;
73 nsecs_t eventTime;
74
75 int32_t deviceId;
76 uint32_t source;
77 int32_t displayId;
78 uint32_t policyFlags;
79 int32_t action;
80 int32_t actionButton;
81 int32_t flags;
82 int32_t metaState;
83 int32_t buttonState;
84 /**
85 * Classification of the current touch gesture
86 */
87 MotionClassification classification;
88 int32_t edgeFlags;
89
90 uint32_t pointerCount;
91 PointerProperties pointerProperties[MAX_POINTERS];
92 PointerCoords pointerCoords[MAX_POINTERS];
93 float xPrecision;
94 float yPrecision;
95 /**
96 * Mouse cursor position when this event is reported relative to the origin of the specified
97 * display. Only valid if this is a mouse event (originates from a mouse or from a trackpad in
98 * gestures enabled mode.
99 */
100 float xCursorPosition;
101 float yCursorPosition;
102 nsecs_t downTime;
103 nsecs_t readTime;
104 std::vector<TouchVideoFrame> videoFrames;
105
106 inline NotifyMotionArgs() {}
107
108 NotifyMotionArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
109 uint32_t source, int32_t displayId, uint32_t policyFlags, int32_t action,
110 int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState,
111 MotionClassification classification, int32_t edgeFlags, uint32_t pointerCount,
112 const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
113 float xPrecision, float yPrecision, float xCursorPosition,
114 float yCursorPosition, nsecs_t downTime,
115 const std::vector<TouchVideoFrame>& videoFrames);
116
117 NotifyMotionArgs(const NotifyMotionArgs& other);
118
Michael Wright1f2db4f2022-11-24 16:47:38 +0000119 NotifyMotionArgs& operator=(const android::NotifyMotionArgs&) = default;
120
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700121 bool operator==(const NotifyMotionArgs& rhs) const;
122
123 std::string dump() const;
124};
125
126/* Describes a sensor event. */
127struct NotifySensorArgs {
128 int32_t id;
129 nsecs_t eventTime;
130
131 int32_t deviceId;
132 uint32_t source;
133 InputDeviceSensorType sensorType;
134 InputDeviceSensorAccuracy accuracy;
135 bool accuracyChanged;
136 nsecs_t hwTimestamp;
137 std::vector<float> values;
138
139 inline NotifySensorArgs() {}
140
141 NotifySensorArgs(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source,
142 InputDeviceSensorType sensorType, InputDeviceSensorAccuracy accuracy,
143 bool accuracyChanged, nsecs_t hwTimestamp, std::vector<float> values);
144
145 NotifySensorArgs(const NotifySensorArgs& other) = default;
146};
147
148/* Describes a switch event. */
149struct NotifySwitchArgs {
150 int32_t id;
151 nsecs_t eventTime;
152
153 uint32_t policyFlags;
154 uint32_t switchValues;
155 uint32_t switchMask;
156
157 inline NotifySwitchArgs() {}
158
159 NotifySwitchArgs(int32_t id, nsecs_t eventTime, uint32_t policyFlags, uint32_t switchValues,
160 uint32_t switchMask);
161
162 NotifySwitchArgs(const NotifySwitchArgs& other) = default;
163
164 bool operator==(const NotifySwitchArgs& rhs) const = default;
165};
166
167/* Describes a device reset event, such as when a device is added,
168 * reconfigured, or removed. */
169struct NotifyDeviceResetArgs {
170 int32_t id;
171 nsecs_t eventTime;
172
173 int32_t deviceId;
174
175 inline NotifyDeviceResetArgs() {}
176
177 NotifyDeviceResetArgs(int32_t id, nsecs_t eventTime, int32_t deviceId);
178
179 NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) = default;
180
181 bool operator==(const NotifyDeviceResetArgs& rhs) const = default;
182};
183
184/* Describes a change in the state of Pointer Capture. */
185struct NotifyPointerCaptureChangedArgs {
186 // The sequence number of the Pointer Capture request, if enabled.
187 int32_t id;
188 nsecs_t eventTime;
189
190 PointerCaptureRequest request;
191
192 inline NotifyPointerCaptureChangedArgs() {}
193
194 NotifyPointerCaptureChangedArgs(int32_t id, nsecs_t eventTime, const PointerCaptureRequest&);
195
196 NotifyPointerCaptureChangedArgs(const NotifyPointerCaptureChangedArgs& other) = default;
197};
198
199/* Describes a vibrator state event. */
200struct NotifyVibratorStateArgs {
201 int32_t id;
202 nsecs_t eventTime;
203
204 int32_t deviceId;
205 bool isOn;
206
207 inline NotifyVibratorStateArgs() {}
208
209 NotifyVibratorStateArgs(int32_t id, nsecs_t eventTIme, int32_t deviceId, bool isOn);
210
211 NotifyVibratorStateArgs(const NotifyVibratorStateArgs& other) = default;
212};
213
214using NotifyArgs = std::variant<NotifyConfigurationChangedArgs, NotifyKeyArgs, NotifyMotionArgs,
215 NotifySensorArgs, NotifySwitchArgs, NotifyDeviceResetArgs,
216 NotifyPointerCaptureChangedArgs, NotifyVibratorStateArgs>;
217
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700218const char* toString(const NotifyArgs& args);
219
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700220} // namespace android