blob: 14487fe04e4401e1ee01527963f057e88263b970 [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 key event. */
43struct NotifyKeyArgs {
44 int32_t id;
45 nsecs_t eventTime;
46
47 int32_t deviceId;
48 uint32_t source;
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -070049 ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID};
Siarhei Vishniakou78513032022-09-15 18:42:05 -070050 uint32_t policyFlags;
51 int32_t action;
52 int32_t flags;
53 int32_t keyCode;
54 int32_t scanCode;
55 int32_t metaState;
56 nsecs_t downTime;
57 nsecs_t readTime;
58
59 inline NotifyKeyArgs() {}
60
61 NotifyKeyArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
Linnan Li13bf76a2024-05-05 19:18:02 +080062 uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags,
63 int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
64 int32_t metaState, nsecs_t downTime);
Siarhei Vishniakou78513032022-09-15 18:42:05 -070065
66 bool operator==(const NotifyKeyArgs& rhs) const = default;
67
68 NotifyKeyArgs(const NotifyKeyArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +000069 NotifyKeyArgs& operator=(const NotifyKeyArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -070070};
71
72/* Describes a motion event. */
73struct NotifyMotionArgs {
74 int32_t id;
75 nsecs_t eventTime;
76
77 int32_t deviceId;
78 uint32_t source;
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -070079 ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID};
Siarhei Vishniakou78513032022-09-15 18:42:05 -070080 uint32_t policyFlags;
81 int32_t action;
82 int32_t actionButton;
83 int32_t flags;
84 int32_t metaState;
85 int32_t buttonState;
86 /**
87 * Classification of the current touch gesture
88 */
89 MotionClassification classification;
90 int32_t edgeFlags;
91
Siarhei Vishniakou3218fc02023-06-15 20:41:02 -070092 // Vectors 'pointerProperties' and 'pointerCoords' must always have the same number of elements
93 std::vector<PointerProperties> pointerProperties;
94 std::vector<PointerCoords> pointerCoords;
Siarhei Vishniakou78513032022-09-15 18:42:05 -070095 float xPrecision;
96 float yPrecision;
97 /**
98 * Mouse cursor position when this event is reported relative to the origin of the specified
99 * display. Only valid if this is a mouse event (originates from a mouse or from a trackpad in
100 * gestures enabled mode.
101 */
102 float xCursorPosition;
103 float yCursorPosition;
104 nsecs_t downTime;
105 nsecs_t readTime;
106 std::vector<TouchVideoFrame> videoFrames;
107
108 inline NotifyMotionArgs() {}
109
110 NotifyMotionArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
Linnan Li13bf76a2024-05-05 19:18:02 +0800111 uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags,
112 int32_t action, int32_t actionButton, int32_t flags, int32_t metaState,
113 int32_t buttonState, MotionClassification classification, int32_t edgeFlags,
114 uint32_t pointerCount, const PointerProperties* pointerProperties,
115 const PointerCoords* pointerCoords, float xPrecision, float yPrecision,
116 float xCursorPosition, float yCursorPosition, nsecs_t downTime,
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700117 const std::vector<TouchVideoFrame>& videoFrames);
118
Siarhei Vishniakou3218fc02023-06-15 20:41:02 -0700119 NotifyMotionArgs(const NotifyMotionArgs& other) = default;
Michael Wright1f2db4f2022-11-24 16:47:38 +0000120 NotifyMotionArgs& operator=(const android::NotifyMotionArgs&) = default;
121
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700122 bool operator==(const NotifyMotionArgs& rhs) const;
123
Siarhei Vishniakou3218fc02023-06-15 20:41:02 -0700124 inline size_t getPointerCount() const { return pointerProperties.size(); }
125
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700126 std::string dump() const;
127};
128
129/* Describes a sensor event. */
130struct NotifySensorArgs {
131 int32_t id;
132 nsecs_t eventTime;
133
134 int32_t deviceId;
135 uint32_t source;
136 InputDeviceSensorType sensorType;
137 InputDeviceSensorAccuracy accuracy;
138 bool accuracyChanged;
139 nsecs_t hwTimestamp;
140 std::vector<float> values;
141
142 inline NotifySensorArgs() {}
143
144 NotifySensorArgs(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source,
145 InputDeviceSensorType sensorType, InputDeviceSensorAccuracy accuracy,
146 bool accuracyChanged, nsecs_t hwTimestamp, std::vector<float> values);
147
148 NotifySensorArgs(const NotifySensorArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000149 NotifySensorArgs& operator=(const NotifySensorArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700150};
151
152/* Describes a switch event. */
153struct NotifySwitchArgs {
154 int32_t id;
155 nsecs_t eventTime;
156
157 uint32_t policyFlags;
158 uint32_t switchValues;
159 uint32_t switchMask;
160
161 inline NotifySwitchArgs() {}
162
163 NotifySwitchArgs(int32_t id, nsecs_t eventTime, uint32_t policyFlags, uint32_t switchValues,
164 uint32_t switchMask);
165
166 NotifySwitchArgs(const NotifySwitchArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000167 NotifySwitchArgs& operator=(const NotifySwitchArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700168
169 bool operator==(const NotifySwitchArgs& rhs) const = default;
170};
171
172/* Describes a device reset event, such as when a device is added,
173 * reconfigured, or removed. */
174struct NotifyDeviceResetArgs {
175 int32_t id;
176 nsecs_t eventTime;
177
178 int32_t deviceId;
179
180 inline NotifyDeviceResetArgs() {}
181
182 NotifyDeviceResetArgs(int32_t id, nsecs_t eventTime, int32_t deviceId);
183
184 NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000185 NotifyDeviceResetArgs& operator=(const NotifyDeviceResetArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700186
187 bool operator==(const NotifyDeviceResetArgs& rhs) const = default;
188};
189
190/* Describes a change in the state of Pointer Capture. */
191struct NotifyPointerCaptureChangedArgs {
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700192 int32_t id;
193 nsecs_t eventTime;
194
195 PointerCaptureRequest request;
196
197 inline NotifyPointerCaptureChangedArgs() {}
198
199 NotifyPointerCaptureChangedArgs(int32_t id, nsecs_t eventTime, const PointerCaptureRequest&);
200
201 NotifyPointerCaptureChangedArgs(const NotifyPointerCaptureChangedArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000202 NotifyPointerCaptureChangedArgs& operator=(const NotifyPointerCaptureChangedArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700203};
204
205/* Describes a vibrator state event. */
206struct NotifyVibratorStateArgs {
207 int32_t id;
208 nsecs_t eventTime;
209
210 int32_t deviceId;
211 bool isOn;
212
213 inline NotifyVibratorStateArgs() {}
214
215 NotifyVibratorStateArgs(int32_t id, nsecs_t eventTIme, int32_t deviceId, bool isOn);
216
217 NotifyVibratorStateArgs(const NotifyVibratorStateArgs& other) = default;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000218 NotifyVibratorStateArgs& operator=(const NotifyVibratorStateArgs&) = default;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700219};
220
Prabir Pradhane3da4bb2023-04-05 23:51:23 +0000221using NotifyArgs =
Liana Kazanova5b8217b2024-07-18 17:44:51 +0000222 std::variant<NotifyInputDevicesChangedArgs, NotifyKeyArgs, NotifyMotionArgs,
223 NotifySensorArgs, NotifySwitchArgs, NotifyDeviceResetArgs,
Prabir Pradhane3da4bb2023-04-05 23:51:23 +0000224 NotifyPointerCaptureChangedArgs, NotifyVibratorStateArgs>;
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700225
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700226const char* toString(const NotifyArgs& args);
227
Siarhei Vishniakou78513032022-09-15 18:42:05 -0700228} // namespace android