Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | namespace android { |
| 26 | |
Prabir Pradhan | e3da4bb | 2023-04-05 23:51:23 +0000 | [diff] [blame] | 27 | /* Describes a change in any of the connected input devices. */ |
| 28 | struct 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 Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 39 | NotifyInputDevicesChangedArgs& operator=(const NotifyInputDevicesChangedArgs&) = default; |
Prabir Pradhan | e3da4bb | 2023-04-05 23:51:23 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 42 | /* Describes a key event. */ |
| 43 | struct NotifyKeyArgs { |
| 44 | int32_t id; |
| 45 | nsecs_t eventTime; |
| 46 | |
| 47 | int32_t deviceId; |
| 48 | uint32_t source; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 49 | ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID}; |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 50 | 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 Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 62 | 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 Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 65 | |
| 66 | bool operator==(const NotifyKeyArgs& rhs) const = default; |
| 67 | |
| 68 | NotifyKeyArgs(const NotifyKeyArgs& other) = default; |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 69 | NotifyKeyArgs& operator=(const NotifyKeyArgs&) = default; |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* Describes a motion event. */ |
| 73 | struct NotifyMotionArgs { |
| 74 | int32_t id; |
| 75 | nsecs_t eventTime; |
| 76 | |
| 77 | int32_t deviceId; |
| 78 | uint32_t source; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 79 | ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID}; |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 80 | 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 Vishniakou | 3218fc0 | 2023-06-15 20:41:02 -0700 | [diff] [blame] | 92 | // Vectors 'pointerProperties' and 'pointerCoords' must always have the same number of elements |
| 93 | std::vector<PointerProperties> pointerProperties; |
| 94 | std::vector<PointerCoords> pointerCoords; |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 95 | 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 Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 111 | 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 Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 117 | const std::vector<TouchVideoFrame>& videoFrames); |
| 118 | |
Siarhei Vishniakou | 3218fc0 | 2023-06-15 20:41:02 -0700 | [diff] [blame] | 119 | NotifyMotionArgs(const NotifyMotionArgs& other) = default; |
Michael Wright | 1f2db4f | 2022-11-24 16:47:38 +0000 | [diff] [blame] | 120 | NotifyMotionArgs& operator=(const android::NotifyMotionArgs&) = default; |
| 121 | |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 122 | bool operator==(const NotifyMotionArgs& rhs) const; |
| 123 | |
Siarhei Vishniakou | 3218fc0 | 2023-06-15 20:41:02 -0700 | [diff] [blame] | 124 | inline size_t getPointerCount() const { return pointerProperties.size(); } |
| 125 | |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 126 | std::string dump() const; |
| 127 | }; |
| 128 | |
| 129 | /* Describes a sensor event. */ |
| 130 | struct 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 Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 149 | NotifySensorArgs& operator=(const NotifySensorArgs&) = default; |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | /* Describes a switch event. */ |
| 153 | struct 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 Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 167 | NotifySwitchArgs& operator=(const NotifySwitchArgs&) = default; |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 168 | |
| 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. */ |
| 174 | struct 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 Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 185 | NotifyDeviceResetArgs& operator=(const NotifyDeviceResetArgs&) = default; |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 186 | |
| 187 | bool operator==(const NotifyDeviceResetArgs& rhs) const = default; |
| 188 | }; |
| 189 | |
| 190 | /* Describes a change in the state of Pointer Capture. */ |
| 191 | struct NotifyPointerCaptureChangedArgs { |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 192 | 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 Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 202 | NotifyPointerCaptureChangedArgs& operator=(const NotifyPointerCaptureChangedArgs&) = default; |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | /* Describes a vibrator state event. */ |
| 206 | struct 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 Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 218 | NotifyVibratorStateArgs& operator=(const NotifyVibratorStateArgs&) = default; |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
Prabir Pradhan | e3da4bb | 2023-04-05 23:51:23 +0000 | [diff] [blame] | 221 | using NotifyArgs = |
Liana Kazanova | 5b8217b | 2024-07-18 17:44:51 +0000 | [diff] [blame] | 222 | std::variant<NotifyInputDevicesChangedArgs, NotifyKeyArgs, NotifyMotionArgs, |
| 223 | NotifySensorArgs, NotifySwitchArgs, NotifyDeviceResetArgs, |
Prabir Pradhan | e3da4bb | 2023-04-05 23:51:23 +0000 | [diff] [blame] | 224 | NotifyPointerCaptureChangedArgs, NotifyVibratorStateArgs>; |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 225 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 226 | const char* toString(const NotifyArgs& args); |
| 227 | |
Siarhei Vishniakou | 7851303 | 2022-09-15 18:42:05 -0700 | [diff] [blame] | 228 | } // namespace android |