blob: 7d29dd9cb2d051f9ce699beaefa0acef552e85e8 [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
Prabir Pradhane3da4bb2023-04-05 23:51:23 +000027/* Describes a change in any of the connected input devices. */
28struct NotifyInputDevicesChangedArgs {
29 int32_t id;
30 std::vector<InputDeviceInfo> inputDeviceInfos;
31
32 inline NotifyInputDevicesChangedArgs() {}
33
34 NotifyInputDevicesChangedArgs(int32_t id, std::vector<InputDeviceInfo> infos);
35
36 bool operator==(const NotifyInputDevicesChangedArgs& rhs) const = default;
37
38 NotifyInputDevicesChangedArgs(const NotifyInputDevicesChangedArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +000039 NotifyInputDevicesChangedArgs& operator=(const NotifyInputDevicesChangedArgs&) = default;
Prabir Pradhane3da4bb2023-04-05 23:51:23 +000040};
41
Siarhei Vishniakou78513032022-09-15 18:42:05 -070042/* Describes a configuration change event. */
43struct NotifyConfigurationChangedArgs {
44 int32_t id;
45 nsecs_t eventTime;
46
47 inline NotifyConfigurationChangedArgs() {}
48
49 NotifyConfigurationChangedArgs(int32_t id, nsecs_t eventTime);
50
51 bool operator==(const NotifyConfigurationChangedArgs& rhs) const = default;
52
53 NotifyConfigurationChangedArgs(const NotifyConfigurationChangedArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +000054 NotifyConfigurationChangedArgs& operator=(const NotifyConfigurationChangedArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -070055};
56
57/* Describes a key event. */
58struct NotifyKeyArgs {
59 int32_t id;
60 nsecs_t eventTime;
61
62 int32_t deviceId;
63 uint32_t source;
64 int32_t displayId;
65 uint32_t policyFlags;
66 int32_t action;
67 int32_t flags;
68 int32_t keyCode;
69 int32_t scanCode;
70 int32_t metaState;
71 nsecs_t downTime;
72 nsecs_t readTime;
73
74 inline NotifyKeyArgs() {}
75
76 NotifyKeyArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
77 uint32_t source, int32_t displayId, uint32_t policyFlags, int32_t action,
78 int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState,
79 nsecs_t downTime);
80
81 bool operator==(const NotifyKeyArgs& rhs) const = default;
82
83 NotifyKeyArgs(const NotifyKeyArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +000084 NotifyKeyArgs& operator=(const NotifyKeyArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -070085};
86
87/* Describes a motion event. */
88struct NotifyMotionArgs {
89 int32_t id;
90 nsecs_t eventTime;
91
92 int32_t deviceId;
93 uint32_t source;
94 int32_t displayId;
95 uint32_t policyFlags;
96 int32_t action;
97 int32_t actionButton;
98 int32_t flags;
99 int32_t metaState;
100 int32_t buttonState;
101 /**
102 * Classification of the current touch gesture
103 */
104 MotionClassification classification;
105 int32_t edgeFlags;
106
107 uint32_t pointerCount;
108 PointerProperties pointerProperties[MAX_POINTERS];
109 PointerCoords pointerCoords[MAX_POINTERS];
110 float xPrecision;
111 float yPrecision;
112 /**
113 * Mouse cursor position when this event is reported relative to the origin of the specified
114 * display. Only valid if this is a mouse event (originates from a mouse or from a trackpad in
115 * gestures enabled mode.
116 */
117 float xCursorPosition;
118 float yCursorPosition;
119 nsecs_t downTime;
120 nsecs_t readTime;
121 std::vector<TouchVideoFrame> videoFrames;
122
123 inline NotifyMotionArgs() {}
124
125 NotifyMotionArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
126 uint32_t source, int32_t displayId, uint32_t policyFlags, int32_t action,
127 int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState,
128 MotionClassification classification, int32_t edgeFlags, uint32_t pointerCount,
129 const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
130 float xPrecision, float yPrecision, float xCursorPosition,
131 float yCursorPosition, nsecs_t downTime,
132 const std::vector<TouchVideoFrame>& videoFrames);
133
134 NotifyMotionArgs(const NotifyMotionArgs& other);
Michael Wright1f2db4f2022-11-24 16:47:38 +0000135 NotifyMotionArgs& operator=(const android::NotifyMotionArgs&) = default;
136
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700137 bool operator==(const NotifyMotionArgs& rhs) const;
138
139 std::string dump() const;
140};
141
142/* Describes a sensor event. */
143struct NotifySensorArgs {
144 int32_t id;
145 nsecs_t eventTime;
146
147 int32_t deviceId;
148 uint32_t source;
149 InputDeviceSensorType sensorType;
150 InputDeviceSensorAccuracy accuracy;
151 bool accuracyChanged;
152 nsecs_t hwTimestamp;
153 std::vector<float> values;
154
155 inline NotifySensorArgs() {}
156
157 NotifySensorArgs(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source,
158 InputDeviceSensorType sensorType, InputDeviceSensorAccuracy accuracy,
159 bool accuracyChanged, nsecs_t hwTimestamp, std::vector<float> values);
160
161 NotifySensorArgs(const NotifySensorArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000162 NotifySensorArgs& operator=(const NotifySensorArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700163};
164
165/* Describes a switch event. */
166struct NotifySwitchArgs {
167 int32_t id;
168 nsecs_t eventTime;
169
170 uint32_t policyFlags;
171 uint32_t switchValues;
172 uint32_t switchMask;
173
174 inline NotifySwitchArgs() {}
175
176 NotifySwitchArgs(int32_t id, nsecs_t eventTime, uint32_t policyFlags, uint32_t switchValues,
177 uint32_t switchMask);
178
179 NotifySwitchArgs(const NotifySwitchArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000180 NotifySwitchArgs& operator=(const NotifySwitchArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700181
182 bool operator==(const NotifySwitchArgs& rhs) const = default;
183};
184
185/* Describes a device reset event, such as when a device is added,
186 * reconfigured, or removed. */
187struct NotifyDeviceResetArgs {
188 int32_t id;
189 nsecs_t eventTime;
190
191 int32_t deviceId;
192
193 inline NotifyDeviceResetArgs() {}
194
195 NotifyDeviceResetArgs(int32_t id, nsecs_t eventTime, int32_t deviceId);
196
197 NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000198 NotifyDeviceResetArgs& operator=(const NotifyDeviceResetArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700199
200 bool operator==(const NotifyDeviceResetArgs& rhs) const = default;
201};
202
203/* Describes a change in the state of Pointer Capture. */
204struct NotifyPointerCaptureChangedArgs {
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700205 int32_t id;
206 nsecs_t eventTime;
207
208 PointerCaptureRequest request;
209
210 inline NotifyPointerCaptureChangedArgs() {}
211
212 NotifyPointerCaptureChangedArgs(int32_t id, nsecs_t eventTime, const PointerCaptureRequest&);
213
214 NotifyPointerCaptureChangedArgs(const NotifyPointerCaptureChangedArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000215 NotifyPointerCaptureChangedArgs& operator=(const NotifyPointerCaptureChangedArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700216};
217
218/* Describes a vibrator state event. */
219struct NotifyVibratorStateArgs {
220 int32_t id;
221 nsecs_t eventTime;
222
223 int32_t deviceId;
224 bool isOn;
225
226 inline NotifyVibratorStateArgs() {}
227
228 NotifyVibratorStateArgs(int32_t id, nsecs_t eventTIme, int32_t deviceId, bool isOn);
229
230 NotifyVibratorStateArgs(const NotifyVibratorStateArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000231 NotifyVibratorStateArgs& operator=(const NotifyVibratorStateArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700232};
233
Prabir Pradhane3da4bb2023-04-05 23:51:23 +0000234using NotifyArgs =
235 std::variant<NotifyInputDevicesChangedArgs, NotifyConfigurationChangedArgs, NotifyKeyArgs,
236 NotifyMotionArgs, NotifySensorArgs, NotifySwitchArgs, NotifyDeviceResetArgs,
237 NotifyPointerCaptureChangedArgs, NotifyVibratorStateArgs>;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700238
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700239const char* toString(const NotifyArgs& args);
240
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700241} // namespace android