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