blob: 865f3d03024160895fd1c64a85a42038d25d2f4a [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;
Linnan Li13bf76a2024-05-05 19:18:02 +080064 ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE};
Siarhei Vishniakou78513032022-09-15 18:42:05 -070065 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,
Linnan Li13bf76a2024-05-05 19:18:02 +080077 uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags,
78 int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
79 int32_t metaState, nsecs_t downTime);
Siarhei Vishniakou78513032022-09-15 18:42:05 -070080
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;
Linnan Li13bf76a2024-05-05 19:18:02 +080094 ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE};
Siarhei Vishniakou78513032022-09-15 18:42:05 -070095 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
Siarhei Vishniakou3218fc02023-06-15 20:41:02 -0700107 // Vectors 'pointerProperties' and 'pointerCoords' must always have the same number of elements
108 std::vector<PointerProperties> pointerProperties;
109 std::vector<PointerCoords> pointerCoords;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700110 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,
Linnan Li13bf76a2024-05-05 19:18:02 +0800126 uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags,
127 int32_t action, int32_t actionButton, int32_t flags, int32_t metaState,
128 int32_t buttonState, MotionClassification classification, int32_t edgeFlags,
129 uint32_t pointerCount, const PointerProperties* pointerProperties,
130 const PointerCoords* pointerCoords, float xPrecision, float yPrecision,
131 float xCursorPosition, float yCursorPosition, nsecs_t downTime,
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700132 const std::vector<TouchVideoFrame>& videoFrames);
133
Siarhei Vishniakou3218fc02023-06-15 20:41:02 -0700134 NotifyMotionArgs(const NotifyMotionArgs& other) = default;
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
Siarhei Vishniakou3218fc02023-06-15 20:41:02 -0700139 inline size_t getPointerCount() const { return pointerProperties.size(); }
140
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700141 std::string dump() const;
142};
143
144/* Describes a sensor event. */
145struct NotifySensorArgs {
146 int32_t id;
147 nsecs_t eventTime;
148
149 int32_t deviceId;
150 uint32_t source;
151 InputDeviceSensorType sensorType;
152 InputDeviceSensorAccuracy accuracy;
153 bool accuracyChanged;
154 nsecs_t hwTimestamp;
155 std::vector<float> values;
156
157 inline NotifySensorArgs() {}
158
159 NotifySensorArgs(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source,
160 InputDeviceSensorType sensorType, InputDeviceSensorAccuracy accuracy,
161 bool accuracyChanged, nsecs_t hwTimestamp, std::vector<float> values);
162
163 NotifySensorArgs(const NotifySensorArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000164 NotifySensorArgs& operator=(const NotifySensorArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700165};
166
167/* Describes a switch event. */
168struct NotifySwitchArgs {
169 int32_t id;
170 nsecs_t eventTime;
171
172 uint32_t policyFlags;
173 uint32_t switchValues;
174 uint32_t switchMask;
175
176 inline NotifySwitchArgs() {}
177
178 NotifySwitchArgs(int32_t id, nsecs_t eventTime, uint32_t policyFlags, uint32_t switchValues,
179 uint32_t switchMask);
180
181 NotifySwitchArgs(const NotifySwitchArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000182 NotifySwitchArgs& operator=(const NotifySwitchArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700183
184 bool operator==(const NotifySwitchArgs& rhs) const = default;
185};
186
187/* Describes a device reset event, such as when a device is added,
188 * reconfigured, or removed. */
189struct NotifyDeviceResetArgs {
190 int32_t id;
191 nsecs_t eventTime;
192
193 int32_t deviceId;
194
195 inline NotifyDeviceResetArgs() {}
196
197 NotifyDeviceResetArgs(int32_t id, nsecs_t eventTime, int32_t deviceId);
198
199 NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000200 NotifyDeviceResetArgs& operator=(const NotifyDeviceResetArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700201
202 bool operator==(const NotifyDeviceResetArgs& rhs) const = default;
203};
204
205/* Describes a change in the state of Pointer Capture. */
206struct NotifyPointerCaptureChangedArgs {
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700207 int32_t id;
208 nsecs_t eventTime;
209
210 PointerCaptureRequest request;
211
212 inline NotifyPointerCaptureChangedArgs() {}
213
214 NotifyPointerCaptureChangedArgs(int32_t id, nsecs_t eventTime, const PointerCaptureRequest&);
215
216 NotifyPointerCaptureChangedArgs(const NotifyPointerCaptureChangedArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000217 NotifyPointerCaptureChangedArgs& operator=(const NotifyPointerCaptureChangedArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700218};
219
220/* Describes a vibrator state event. */
221struct NotifyVibratorStateArgs {
222 int32_t id;
223 nsecs_t eventTime;
224
225 int32_t deviceId;
226 bool isOn;
227
228 inline NotifyVibratorStateArgs() {}
229
230 NotifyVibratorStateArgs(int32_t id, nsecs_t eventTIme, int32_t deviceId, bool isOn);
231
232 NotifyVibratorStateArgs(const NotifyVibratorStateArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000233 NotifyVibratorStateArgs& operator=(const NotifyVibratorStateArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700234};
235
Prabir Pradhane3da4bb2023-04-05 23:51:23 +0000236using NotifyArgs =
237 std::variant<NotifyInputDevicesChangedArgs, NotifyConfigurationChangedArgs, NotifyKeyArgs,
238 NotifyMotionArgs, NotifySensorArgs, NotifySwitchArgs, NotifyDeviceResetArgs,
239 NotifyPointerCaptureChangedArgs, NotifyVibratorStateArgs>;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700240
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700241const char* toString(const NotifyArgs& args);
242
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700243} // namespace android