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