Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | #ifndef _LIBINPUT_INPUT_H |
| 18 | #define _LIBINPUT_INPUT_H |
| 19 | |
Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 20 | #pragma GCC system_header |
| 21 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Native input event structures. |
| 24 | */ |
| 25 | |
| 26 | #include <android/input.h> |
Siarhei Vishniakou | 509724f | 2021-06-16 04:09:35 +0000 | [diff] [blame] | 27 | #ifdef __linux__ |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 28 | #include <android/os/IInputConstants.h> |
Siarhei Vishniakou | 509724f | 2021-06-16 04:09:35 +0000 | [diff] [blame] | 29 | #endif |
Garfield Tan | ab0ab9c | 2019-07-10 18:58:28 -0700 | [diff] [blame] | 30 | #include <math.h> |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 31 | #include <stdint.h> |
chaviw | fd9c1ed | 2020-07-01 10:57:59 -0700 | [diff] [blame] | 32 | #include <ui/Transform.h> |
Michael Wright | d0bd391 | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 33 | #include <utils/BitSet.h> |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 34 | #include <utils/RefBase.h> |
Michael Wright | d0bd391 | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 35 | #include <utils/Timers.h> |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 36 | #include <array> |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 37 | #include <limits> |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 38 | #include <queue> |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 39 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Additional private constants not defined in ndk/ui/input.h. |
| 42 | */ |
| 43 | enum { |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 44 | #ifdef __linux__ |
| 45 | /* This event was generated or modified by accessibility service. */ |
| 46 | AKEY_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = |
| 47 | android::os::IInputConstants::INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT, // 0x800, |
| 48 | #else |
Diego Perez | cf43a95 | 2021-07-02 12:13:41 +0100 | [diff] [blame] | 49 | AKEY_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = 0x800, |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 50 | #endif |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 51 | /* Signifies that the key is being predispatched */ |
| 52 | AKEY_EVENT_FLAG_PREDISPATCH = 0x20000000, |
| 53 | |
| 54 | /* Private control to determine when an app is tracking a key sequence. */ |
| 55 | AKEY_EVENT_FLAG_START_TRACKING = 0x40000000, |
| 56 | |
| 57 | /* Key event is inconsistent with previously sent key events. */ |
| 58 | AKEY_EVENT_FLAG_TAINTED = 0x80000000, |
| 59 | }; |
| 60 | |
| 61 | enum { |
Michael Wright | cdcd8f2 | 2016-03-22 16:52:13 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * This flag indicates that the window that received this motion event is partly |
| 65 | * or wholly obscured by another visible window above it. This flag is set to true |
| 66 | * even if the event did not directly pass through the obscured area. |
| 67 | * A security sensitive application can check this flag to identify situations in which |
| 68 | * a malicious application may have covered up part of its content for the purpose |
| 69 | * of misleading the user or hijacking touches. An appropriate response might be |
| 70 | * to drop the suspect touches or to take additional precautions to confirm the user's |
| 71 | * actual intent. |
| 72 | */ |
| 73 | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2, |
| 74 | |
Prabir Pradhan | 141a986 | 2018-11-19 14:35:56 -0800 | [diff] [blame] | 75 | /** |
| 76 | * This flag indicates that the event has been generated by a gesture generator. It |
| 77 | * provides a hint to the GestureDetector to not apply any touch slop. |
| 78 | */ |
| 79 | AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE = 0x8, |
| 80 | |
Prabir Pradhan | 47cf0a0 | 2021-03-11 20:30:57 -0800 | [diff] [blame] | 81 | /** |
| 82 | * This flag indicates that the event will not cause a focus change if it is directed to an |
| 83 | * unfocused window, even if it an ACTION_DOWN. This is typically used with pointer |
| 84 | * gestures to allow the user to direct gestures to an unfocused window without bringing it |
| 85 | * into focus. |
| 86 | */ |
| 87 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE = 0x40, |
| 88 | |
Siarhei Vishniakou | 6dbd0ce | 2022-01-13 01:24:14 -0800 | [diff] [blame] | 89 | #if defined(__linux__) |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 90 | /** |
| 91 | * This event was generated or modified by accessibility service. |
| 92 | */ |
| 93 | AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = |
| 94 | android::os::IInputConstants::INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT, // 0x800, |
| 95 | #else |
Diego Perez | ba0ce7d | 2021-07-06 12:35:16 +0100 | [diff] [blame] | 96 | AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = 0x800, |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 97 | #endif |
| 98 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 99 | /* Motion event is inconsistent with previously sent motion events. */ |
| 100 | AMOTION_EVENT_FLAG_TAINTED = 0x80000000, |
| 101 | }; |
| 102 | |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 103 | /** |
| 104 | * Allowed VerifiedKeyEvent flags. All other flags from KeyEvent do not get verified. |
| 105 | * These values must be kept in sync with VerifiedKeyEvent.java |
| 106 | */ |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 107 | constexpr int32_t VERIFIED_KEY_EVENT_FLAGS = |
| 108 | AKEY_EVENT_FLAG_CANCELED | AKEY_EVENT_FLAG_IS_ACCESSIBILITY_EVENT; |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * Allowed VerifiedMotionEventFlags. All other flags from MotionEvent do not get verified. |
| 112 | * These values must be kept in sync with VerifiedMotionEvent.java |
| 113 | */ |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 114 | constexpr int32_t VERIFIED_MOTION_EVENT_FLAGS = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED | |
| 115 | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED | AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT; |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 116 | |
arthurhung | cc7f980 | 2020-04-30 17:55:40 +0800 | [diff] [blame] | 117 | /** |
| 118 | * This flag indicates that the point up event has been canceled. |
| 119 | * Typically this is used for palm event when the user has accidental touches. |
| 120 | * TODO: Adjust flag to public api |
| 121 | */ |
| 122 | constexpr int32_t AMOTION_EVENT_FLAG_CANCELED = 0x20; |
| 123 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 124 | enum { |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 125 | /* |
| 126 | * Indicates that an input device has switches. |
| 127 | * This input source flag is hidden from the API because switches are only used by the system |
| 128 | * and applications have no way to interact with them. |
| 129 | */ |
| 130 | AINPUT_SOURCE_SWITCH = 0x80000000, |
| 131 | }; |
| 132 | |
Michael Wright | 962a108 | 2013-10-17 17:35:53 -0700 | [diff] [blame] | 133 | enum { |
| 134 | /** |
| 135 | * Constants for LEDs. Hidden from the API since we don't actually expose a way to interact |
| 136 | * with LEDs to developers |
| 137 | * |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 138 | * NOTE: If you add LEDs here, you must also add them to InputEventLabels.h |
Michael Wright | 962a108 | 2013-10-17 17:35:53 -0700 | [diff] [blame] | 139 | */ |
| 140 | |
| 141 | ALED_NUM_LOCK = 0x00, |
| 142 | ALED_CAPS_LOCK = 0x01, |
| 143 | ALED_SCROLL_LOCK = 0x02, |
| 144 | ALED_COMPOSE = 0x03, |
| 145 | ALED_KANA = 0x04, |
| 146 | ALED_SLEEP = 0x05, |
| 147 | ALED_SUSPEND = 0x06, |
| 148 | ALED_MUTE = 0x07, |
| 149 | ALED_MISC = 0x08, |
| 150 | ALED_MAIL = 0x09, |
| 151 | ALED_CHARGING = 0x0a, |
| 152 | ALED_CONTROLLER_1 = 0x10, |
| 153 | ALED_CONTROLLER_2 = 0x11, |
| 154 | ALED_CONTROLLER_3 = 0x12, |
| 155 | ALED_CONTROLLER_4 = 0x13, |
| 156 | }; |
| 157 | |
Michael Wright | 9b04f86 | 2013-10-18 17:53:50 -0700 | [diff] [blame] | 158 | /* Maximum number of controller LEDs we support */ |
| 159 | #define MAX_CONTROLLER_LEDS 4 |
| 160 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 161 | /* |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 162 | * Maximum number of pointers supported per motion event. |
| 163 | * Smallest number of pointers is 1. |
| 164 | * (We want at least 10 but some touch controllers obstensibly configured for 10 pointers |
| 165 | * will occasionally emit 11. There is not much harm making this constant bigger.) |
| 166 | */ |
Siarhei Vishniakou | 0174738 | 2022-01-20 13:23:27 -0800 | [diff] [blame] | 167 | static constexpr size_t MAX_POINTERS = 16; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 168 | |
| 169 | /* |
Flanker | 552a8a5 | 2015-09-07 15:28:58 +0800 | [diff] [blame] | 170 | * Maximum number of samples supported per motion event. |
| 171 | */ |
| 172 | #define MAX_SAMPLES UINT16_MAX |
| 173 | |
| 174 | /* |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 175 | * Maximum pointer id value supported in a motion event. |
| 176 | * Smallest pointer id is 0. |
| 177 | * (This is limited by our use of BitSet32 to track pointer assignments.) |
| 178 | */ |
| 179 | #define MAX_POINTER_ID 31 |
| 180 | |
| 181 | /* |
| 182 | * Declare a concrete type for the NDK's input event forward declaration. |
| 183 | */ |
| 184 | struct AInputEvent { |
| 185 | virtual ~AInputEvent() { } |
| 186 | }; |
| 187 | |
| 188 | /* |
| 189 | * Declare a concrete type for the NDK's input device forward declaration. |
| 190 | */ |
| 191 | struct AInputDevice { |
| 192 | virtual ~AInputDevice() { } |
| 193 | }; |
| 194 | |
| 195 | |
| 196 | namespace android { |
| 197 | |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 198 | #ifdef __linux__ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 199 | class Parcel; |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 200 | #endif |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 201 | |
Prabir Pradhan | de69f8a | 2021-11-18 16:40:34 +0000 | [diff] [blame] | 202 | /* |
| 203 | * Apply the given transform to the point without applying any translation/offset. |
| 204 | */ |
| 205 | vec2 transformWithoutTranslation(const ui::Transform& transform, const vec2& xy); |
| 206 | |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 207 | const char* inputEventTypeToString(int32_t type); |
| 208 | |
Siarhei Vishniakou | d948957 | 2021-11-12 20:08:38 -0800 | [diff] [blame] | 209 | std::string inputEventSourceToString(int32_t source); |
| 210 | |
| 211 | bool isFromSource(uint32_t source, uint32_t test); |
| 212 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 213 | /* |
| 214 | * Flags that flow alongside events in the input dispatch system to help with certain |
| 215 | * policy decisions such as waking from device sleep. |
| 216 | * |
| 217 | * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java. |
| 218 | */ |
| 219 | enum { |
| 220 | /* These flags originate in RawEvents and are generally set in the key map. |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 221 | * NOTE: If you want a flag to be able to set in a keylayout file, then you must add it to |
| 222 | * InputEventLabels.h as well. */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 223 | |
Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 224 | // Indicates that the event should wake the device. |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 225 | POLICY_FLAG_WAKE = 0x00000001, |
Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 226 | |
| 227 | // Indicates that the key is virtual, such as a capacitive button, and should |
| 228 | // generate haptic feedback. Virtual keys may be suppressed for some time |
| 229 | // after a recent touch to prevent accidental activation of virtual keys adjacent |
| 230 | // to the touch screen during an edge swipe. |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 231 | POLICY_FLAG_VIRTUAL = 0x00000002, |
Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 232 | |
| 233 | // Indicates that the key is the special function modifier. |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 234 | POLICY_FLAG_FUNCTION = 0x00000004, |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 235 | |
Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 236 | // Indicates that the key represents a special gesture that has been detected by |
| 237 | // the touch firmware or driver. Causes touch events from the same device to be canceled. |
| 238 | POLICY_FLAG_GESTURE = 0x00000008, |
| 239 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 240 | POLICY_FLAG_RAW_MASK = 0x0000ffff, |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 241 | |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 242 | #ifdef __linux__ |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 243 | POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY = |
| 244 | android::os::IInputConstants::POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY, |
Siarhei Vishniakou | 509724f | 2021-06-16 04:09:35 +0000 | [diff] [blame] | 245 | #else |
Siarhei Vishniakou | 509724f | 2021-06-16 04:09:35 +0000 | [diff] [blame] | 246 | POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY = 0x20000, |
| 247 | #endif |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 248 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 249 | /* These flags are set by the input dispatcher. */ |
| 250 | |
| 251 | // Indicates that the input event was injected. |
| 252 | POLICY_FLAG_INJECTED = 0x01000000, |
| 253 | |
| 254 | // Indicates that the input event is from a trusted source such as a directly attached |
| 255 | // input device or an application with system-wide event injection permission. |
| 256 | POLICY_FLAG_TRUSTED = 0x02000000, |
| 257 | |
| 258 | // Indicates that the input event has passed through an input filter. |
| 259 | POLICY_FLAG_FILTERED = 0x04000000, |
| 260 | |
| 261 | // Disables automatic key repeating behavior. |
| 262 | POLICY_FLAG_DISABLE_KEY_REPEAT = 0x08000000, |
| 263 | |
| 264 | /* These flags are set by the input reader policy as it intercepts each event. */ |
| 265 | |
Jeff Brown | db19e46 | 2014-04-08 19:55:38 -0700 | [diff] [blame] | 266 | // Indicates that the device was in an interactive state when the |
| 267 | // event was intercepted. |
| 268 | POLICY_FLAG_INTERACTIVE = 0x20000000, |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 269 | |
| 270 | // Indicates that the event should be dispatched to applications. |
| 271 | // The input event should still be sent to the InputDispatcher so that it can see all |
| 272 | // input events received include those that it will not deliver. |
| 273 | POLICY_FLAG_PASS_TO_USER = 0x40000000, |
| 274 | }; |
| 275 | |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 276 | /** |
| 277 | * Classifications of the current gesture, if available. |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 278 | */ |
| 279 | enum class MotionClassification : uint8_t { |
| 280 | /** |
| 281 | * No classification is available. |
| 282 | */ |
Vaibhav | 8576dd7 | 2022-02-11 18:19:06 +0530 | [diff] [blame] | 283 | NONE = AMOTION_EVENT_CLASSIFICATION_NONE, |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 284 | /** |
| 285 | * Too early to classify the current gesture. Need more events. Look for changes in the |
| 286 | * upcoming motion events. |
| 287 | */ |
Vaibhav | 8576dd7 | 2022-02-11 18:19:06 +0530 | [diff] [blame] | 288 | AMBIGUOUS_GESTURE = AMOTION_EVENT_CLASSIFICATION_AMBIGUOUS_GESTURE, |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 289 | /** |
| 290 | * The current gesture likely represents a user intentionally exerting force on the touchscreen. |
| 291 | */ |
Vaibhav | 8576dd7 | 2022-02-11 18:19:06 +0530 | [diff] [blame] | 292 | DEEP_PRESS = AMOTION_EVENT_CLASSIFICATION_DEEP_PRESS, |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 293 | }; |
| 294 | |
Siarhei Vishniakou | 16a2e30 | 2019-01-14 19:21:45 -0800 | [diff] [blame] | 295 | /** |
| 296 | * String representation of MotionClassification |
| 297 | */ |
| 298 | const char* motionClassificationToString(MotionClassification classification); |
| 299 | |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 300 | /** |
Siarhei Vishniakou | f94ae02 | 2021-02-04 01:23:17 +0000 | [diff] [blame] | 301 | * Portion of FrameMetrics timeline of interest to input code. |
| 302 | */ |
| 303 | enum GraphicsTimeline : size_t { |
| 304 | /** Time when the app sent the buffer to SurfaceFlinger. */ |
| 305 | GPU_COMPLETED_TIME = 0, |
| 306 | |
| 307 | /** Time when the frame was presented on the display */ |
| 308 | PRESENT_TIME = 1, |
| 309 | |
| 310 | /** Total size of the 'GraphicsTimeline' array. Must always be last. */ |
| 311 | SIZE = 2 |
| 312 | }; |
| 313 | |
| 314 | /** |
Garfield Tan | 84b087e | 2020-01-23 10:49:05 -0800 | [diff] [blame] | 315 | * Generator of unique numbers used to identify input events. |
| 316 | * |
| 317 | * Layout of ID: |
| 318 | * |--------------------------|---------------------------| |
| 319 | * | 2 bits for source | 30 bits for random number | |
| 320 | * |--------------------------|---------------------------| |
| 321 | */ |
| 322 | class IdGenerator { |
| 323 | private: |
| 324 | static constexpr uint32_t SOURCE_SHIFT = 30; |
| 325 | |
| 326 | public: |
| 327 | // Used to divide integer space to ensure no conflict among these sources./ |
| 328 | enum class Source : int32_t { |
Garfield Tan | 750c7f4 | 2020-05-18 17:41:46 -0700 | [diff] [blame] | 329 | INPUT_READER = static_cast<int32_t>(0x0u << SOURCE_SHIFT), |
| 330 | INPUT_DISPATCHER = static_cast<int32_t>(0x1u << SOURCE_SHIFT), |
| 331 | OTHER = static_cast<int32_t>(0x3u << SOURCE_SHIFT), // E.g. app injected events |
Garfield Tan | 84b087e | 2020-01-23 10:49:05 -0800 | [diff] [blame] | 332 | }; |
| 333 | IdGenerator(Source source); |
| 334 | |
| 335 | int32_t nextId() const; |
| 336 | |
| 337 | // Extract source from given id. |
| 338 | static inline Source getSource(int32_t id) { return static_cast<Source>(SOURCE_MASK & id); } |
| 339 | |
| 340 | private: |
| 341 | const Source mSource; |
| 342 | |
Garfield Tan | 750c7f4 | 2020-05-18 17:41:46 -0700 | [diff] [blame] | 343 | static constexpr int32_t SOURCE_MASK = static_cast<int32_t>(0x3u << SOURCE_SHIFT); |
Garfield Tan | 84b087e | 2020-01-23 10:49:05 -0800 | [diff] [blame] | 344 | }; |
| 345 | |
| 346 | /** |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 347 | * Invalid value for cursor position. Used for non-mouse events, tests and injected events. Don't |
| 348 | * use it for direct comparison with any other value, because NaN isn't equal to itself according to |
| 349 | * IEEE 754. Use isnan() instead to check if a cursor position is valid. |
| 350 | */ |
| 351 | constexpr float AMOTION_EVENT_INVALID_CURSOR_POSITION = std::numeric_limits<float>::quiet_NaN(); |
| 352 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 353 | /* |
| 354 | * Pointer coordinate data. |
| 355 | */ |
| 356 | struct PointerCoords { |
Michael Wright | 8f6710f | 2014-06-09 18:56:43 -0700 | [diff] [blame] | 357 | enum { MAX_AXES = 30 }; // 30 so that sizeof(PointerCoords) == 128 |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 358 | |
| 359 | // Bitfield of axes that are present in this structure. |
Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 360 | uint64_t bits __attribute__((aligned(8))); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 361 | |
| 362 | // Values of axes that are stored in this structure packed in order by axis id |
| 363 | // for each axis that is present in the structure according to 'bits'. |
| 364 | float values[MAX_AXES]; |
| 365 | |
| 366 | inline void clear() { |
Michael Wright | d0bd391 | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 367 | BitSet64::clear(bits); |
| 368 | } |
| 369 | |
| 370 | bool isEmpty() const { |
| 371 | return BitSet64::isEmpty(bits); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | float getAxisValue(int32_t axis) const; |
| 375 | status_t setAxisValue(int32_t axis, float value); |
| 376 | |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 377 | // Scale the pointer coordinates according to a global scale and a |
| 378 | // window scale. The global scale will be applied to TOUCH/TOOL_MAJOR/MINOR |
| 379 | // axes, however the window scaling will not. |
| 380 | void scale(float globalScale, float windowXScale, float windowYScale); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 381 | |
chaviw | c01e137 | 2020-07-01 12:37:31 -0700 | [diff] [blame] | 382 | void transform(const ui::Transform& transform); |
| 383 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 384 | inline float getX() const { |
| 385 | return getAxisValue(AMOTION_EVENT_AXIS_X); |
| 386 | } |
| 387 | |
| 388 | inline float getY() const { |
| 389 | return getAxisValue(AMOTION_EVENT_AXIS_Y); |
| 390 | } |
| 391 | |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 392 | vec2 getXYValue() const { return vec2(getX(), getY()); } |
| 393 | |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 394 | #ifdef __linux__ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 395 | status_t readFromParcel(Parcel* parcel); |
| 396 | status_t writeToParcel(Parcel* parcel) const; |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 397 | #endif |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 398 | |
| 399 | bool operator==(const PointerCoords& other) const; |
| 400 | inline bool operator!=(const PointerCoords& other) const { |
| 401 | return !(*this == other); |
| 402 | } |
| 403 | |
| 404 | void copyFrom(const PointerCoords& other); |
| 405 | |
| 406 | private: |
| 407 | void tooManyAxes(int axis); |
| 408 | }; |
| 409 | |
| 410 | /* |
| 411 | * Pointer property data. |
| 412 | */ |
| 413 | struct PointerProperties { |
| 414 | // The id of the pointer. |
| 415 | int32_t id; |
| 416 | |
| 417 | // The pointer tool type. |
| 418 | int32_t toolType; |
| 419 | |
| 420 | inline void clear() { |
| 421 | id = -1; |
| 422 | toolType = 0; |
| 423 | } |
| 424 | |
| 425 | bool operator==(const PointerProperties& other) const; |
| 426 | inline bool operator!=(const PointerProperties& other) const { |
| 427 | return !(*this == other); |
| 428 | } |
| 429 | |
| 430 | void copyFrom(const PointerProperties& other); |
| 431 | }; |
| 432 | |
| 433 | /* |
| 434 | * Input events. |
| 435 | */ |
| 436 | class InputEvent : public AInputEvent { |
| 437 | public: |
| 438 | virtual ~InputEvent() { } |
| 439 | |
| 440 | virtual int32_t getType() const = 0; |
| 441 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 442 | inline int32_t getId() const { return mId; } |
| 443 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 444 | inline int32_t getDeviceId() const { return mDeviceId; } |
| 445 | |
Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 446 | inline uint32_t getSource() const { return mSource; } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 447 | |
Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 448 | inline void setSource(uint32_t source) { mSource = source; } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 449 | |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 450 | inline int32_t getDisplayId() const { return mDisplayId; } |
| 451 | |
| 452 | inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; } |
| 453 | |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 454 | inline std::array<uint8_t, 32> getHmac() const { return mHmac; } |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 455 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 456 | static int32_t nextId(); |
| 457 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 458 | protected: |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 459 | void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 460 | std::array<uint8_t, 32> hmac); |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 461 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 462 | void initialize(const InputEvent& from); |
| 463 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 464 | int32_t mId; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 465 | int32_t mDeviceId; |
Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 466 | uint32_t mSource; |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 467 | int32_t mDisplayId; |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 468 | std::array<uint8_t, 32> mHmac; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 469 | }; |
| 470 | |
| 471 | /* |
| 472 | * Key events. |
| 473 | */ |
| 474 | class KeyEvent : public InputEvent { |
| 475 | public: |
| 476 | virtual ~KeyEvent() { } |
| 477 | |
| 478 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; } |
| 479 | |
| 480 | inline int32_t getAction() const { return mAction; } |
| 481 | |
| 482 | inline int32_t getFlags() const { return mFlags; } |
| 483 | |
| 484 | inline void setFlags(int32_t flags) { mFlags = flags; } |
| 485 | |
| 486 | inline int32_t getKeyCode() const { return mKeyCode; } |
| 487 | |
| 488 | inline int32_t getScanCode() const { return mScanCode; } |
| 489 | |
| 490 | inline int32_t getMetaState() const { return mMetaState; } |
| 491 | |
| 492 | inline int32_t getRepeatCount() const { return mRepeatCount; } |
| 493 | |
| 494 | inline nsecs_t getDownTime() const { return mDownTime; } |
| 495 | |
| 496 | inline nsecs_t getEventTime() const { return mEventTime; } |
| 497 | |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 498 | static const char* getLabel(int32_t keyCode); |
| 499 | static int32_t getKeyCodeFromLabel(const char* label); |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 500 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 501 | void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 502 | std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, |
| 503 | int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, |
| 504 | nsecs_t eventTime); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 505 | void initialize(const KeyEvent& from); |
| 506 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 507 | static const char* actionToString(int32_t action); |
| 508 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 509 | protected: |
| 510 | int32_t mAction; |
| 511 | int32_t mFlags; |
| 512 | int32_t mKeyCode; |
| 513 | int32_t mScanCode; |
| 514 | int32_t mMetaState; |
| 515 | int32_t mRepeatCount; |
| 516 | nsecs_t mDownTime; |
| 517 | nsecs_t mEventTime; |
| 518 | }; |
| 519 | |
| 520 | /* |
| 521 | * Motion events. |
| 522 | */ |
| 523 | class MotionEvent : public InputEvent { |
| 524 | public: |
| 525 | virtual ~MotionEvent() { } |
| 526 | |
| 527 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; } |
| 528 | |
| 529 | inline int32_t getAction() const { return mAction; } |
| 530 | |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 531 | static int32_t getActionMasked(int32_t action) { return action & AMOTION_EVENT_ACTION_MASK; } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 532 | |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 533 | inline int32_t getActionMasked() const { return getActionMasked(mAction); } |
| 534 | |
Siarhei Vishniakou | ba0a875 | 2021-09-14 14:43:25 -0700 | [diff] [blame] | 535 | static uint8_t getActionIndex(int32_t action) { |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 536 | return (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> |
| 537 | AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 540 | inline int32_t getActionIndex() const { return getActionIndex(mAction); } |
| 541 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 542 | inline void setAction(int32_t action) { mAction = action; } |
| 543 | |
| 544 | inline int32_t getFlags() const { return mFlags; } |
| 545 | |
| 546 | inline void setFlags(int32_t flags) { mFlags = flags; } |
| 547 | |
| 548 | inline int32_t getEdgeFlags() const { return mEdgeFlags; } |
| 549 | |
| 550 | inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; } |
| 551 | |
| 552 | inline int32_t getMetaState() const { return mMetaState; } |
| 553 | |
| 554 | inline void setMetaState(int32_t metaState) { mMetaState = metaState; } |
| 555 | |
| 556 | inline int32_t getButtonState() const { return mButtonState; } |
| 557 | |
Michael Wright | 6db5879 | 2016-09-14 19:53:37 +0100 | [diff] [blame] | 558 | inline void setButtonState(int32_t buttonState) { mButtonState = buttonState; } |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 559 | |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 560 | inline MotionClassification getClassification() const { return mClassification; } |
| 561 | |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 562 | inline int32_t getActionButton() const { return mActionButton; } |
| 563 | |
Michael Wright | 21957b9 | 2015-06-17 21:06:54 +0100 | [diff] [blame] | 564 | inline void setActionButton(int32_t button) { mActionButton = button; } |
| 565 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 566 | inline float getXOffset() const { return mTransform.tx(); } |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 567 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 568 | inline float getYOffset() const { return mTransform.ty(); } |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 569 | |
Prabir Pradhan | 5beda76 | 2021-12-10 09:30:08 +0000 | [diff] [blame] | 570 | inline const ui::Transform& getTransform() const { return mTransform; } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 571 | |
Prabir Pradhan | 092f3a9 | 2021-11-25 10:53:27 -0800 | [diff] [blame] | 572 | int getSurfaceRotation() const; |
| 573 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 574 | inline float getXPrecision() const { return mXPrecision; } |
| 575 | |
| 576 | inline float getYPrecision() const { return mYPrecision; } |
| 577 | |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 578 | inline float getRawXCursorPosition() const { return mRawXCursorPosition; } |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 579 | |
| 580 | float getXCursorPosition() const; |
| 581 | |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 582 | inline float getRawYCursorPosition() const { return mRawYCursorPosition; } |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 583 | |
| 584 | float getYCursorPosition() const; |
| 585 | |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 586 | void setCursorPosition(float x, float y); |
| 587 | |
Prabir Pradhan | 5beda76 | 2021-12-10 09:30:08 +0000 | [diff] [blame] | 588 | inline const ui::Transform& getRawTransform() const { return mRawTransform; } |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 589 | |
Garfield Tan | ab0ab9c | 2019-07-10 18:58:28 -0700 | [diff] [blame] | 590 | static inline bool isValidCursorPosition(float x, float y) { return !isnan(x) && !isnan(y); } |
| 591 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 592 | inline nsecs_t getDownTime() const { return mDownTime; } |
| 593 | |
| 594 | inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; } |
| 595 | |
| 596 | inline size_t getPointerCount() const { return mPointerProperties.size(); } |
| 597 | |
| 598 | inline const PointerProperties* getPointerProperties(size_t pointerIndex) const { |
| 599 | return &mPointerProperties[pointerIndex]; |
| 600 | } |
| 601 | |
| 602 | inline int32_t getPointerId(size_t pointerIndex) const { |
| 603 | return mPointerProperties[pointerIndex].id; |
| 604 | } |
| 605 | |
| 606 | inline int32_t getToolType(size_t pointerIndex) const { |
| 607 | return mPointerProperties[pointerIndex].toolType; |
| 608 | } |
| 609 | |
| 610 | inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; } |
| 611 | |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 612 | /** |
| 613 | * The actual raw pointer coords: whatever comes from the input device without any external |
| 614 | * transforms applied. |
| 615 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 616 | const PointerCoords* getRawPointerCoords(size_t pointerIndex) const; |
| 617 | |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 618 | /** |
| 619 | * This is the raw axis value. However, for X/Y axes, this currently applies a "compat-raw" |
| 620 | * transform because many apps (incorrectly) assumed that raw == oriented-screen-space. |
| 621 | * "compat raw" is raw coordinates with screen rotation applied. |
| 622 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 623 | float getRawAxisValue(int32_t axis, size_t pointerIndex) const; |
| 624 | |
| 625 | inline float getRawX(size_t pointerIndex) const { |
| 626 | return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex); |
| 627 | } |
| 628 | |
| 629 | inline float getRawY(size_t pointerIndex) const { |
| 630 | return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex); |
| 631 | } |
| 632 | |
| 633 | float getAxisValue(int32_t axis, size_t pointerIndex) const; |
| 634 | |
Siarhei Vishniakou | 69e4d0f | 2020-09-14 19:53:29 -0500 | [diff] [blame] | 635 | /** |
| 636 | * Get the X coordinate of the latest sample in this MotionEvent for pointer 'pointerIndex'. |
| 637 | * Identical to calling getHistoricalX(pointerIndex, getHistorySize()). |
| 638 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 639 | inline float getX(size_t pointerIndex) const { |
| 640 | return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex); |
| 641 | } |
| 642 | |
Siarhei Vishniakou | 69e4d0f | 2020-09-14 19:53:29 -0500 | [diff] [blame] | 643 | /** |
| 644 | * Get the Y coordinate of the latest sample in this MotionEvent for pointer 'pointerIndex'. |
| 645 | * Identical to calling getHistoricalX(pointerIndex, getHistorySize()). |
| 646 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 647 | inline float getY(size_t pointerIndex) const { |
| 648 | return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex); |
| 649 | } |
| 650 | |
| 651 | inline float getPressure(size_t pointerIndex) const { |
| 652 | return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex); |
| 653 | } |
| 654 | |
| 655 | inline float getSize(size_t pointerIndex) const { |
| 656 | return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex); |
| 657 | } |
| 658 | |
| 659 | inline float getTouchMajor(size_t pointerIndex) const { |
| 660 | return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex); |
| 661 | } |
| 662 | |
| 663 | inline float getTouchMinor(size_t pointerIndex) const { |
| 664 | return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex); |
| 665 | } |
| 666 | |
| 667 | inline float getToolMajor(size_t pointerIndex) const { |
| 668 | return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex); |
| 669 | } |
| 670 | |
| 671 | inline float getToolMinor(size_t pointerIndex) const { |
| 672 | return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex); |
| 673 | } |
| 674 | |
| 675 | inline float getOrientation(size_t pointerIndex) const { |
| 676 | return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex); |
| 677 | } |
| 678 | |
| 679 | inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; } |
| 680 | |
| 681 | inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const { |
| 682 | return mSampleEventTimes[historicalIndex]; |
| 683 | } |
| 684 | |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 685 | /** |
| 686 | * The actual raw pointer coords: whatever comes from the input device without any external |
| 687 | * transforms applied. |
| 688 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 689 | const PointerCoords* getHistoricalRawPointerCoords( |
| 690 | size_t pointerIndex, size_t historicalIndex) const; |
| 691 | |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 692 | /** |
| 693 | * This is the raw axis value. However, for X/Y axes, this currently applies a "compat-raw" |
| 694 | * transform because many apps (incorrectly) assumed that raw == oriented-screen-space. |
| 695 | * "compat raw" is raw coordinates with screen rotation applied. |
| 696 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 697 | float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex, |
| 698 | size_t historicalIndex) const; |
| 699 | |
| 700 | inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const { |
| 701 | return getHistoricalRawAxisValue( |
| 702 | AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex); |
| 703 | } |
| 704 | |
| 705 | inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const { |
| 706 | return getHistoricalRawAxisValue( |
| 707 | AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex); |
| 708 | } |
| 709 | |
| 710 | float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const; |
| 711 | |
| 712 | inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const { |
| 713 | return getHistoricalAxisValue( |
| 714 | AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex); |
| 715 | } |
| 716 | |
| 717 | inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const { |
| 718 | return getHistoricalAxisValue( |
| 719 | AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex); |
| 720 | } |
| 721 | |
| 722 | inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const { |
| 723 | return getHistoricalAxisValue( |
| 724 | AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex); |
| 725 | } |
| 726 | |
| 727 | inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const { |
| 728 | return getHistoricalAxisValue( |
| 729 | AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex); |
| 730 | } |
| 731 | |
| 732 | inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const { |
| 733 | return getHistoricalAxisValue( |
| 734 | AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex); |
| 735 | } |
| 736 | |
| 737 | inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const { |
| 738 | return getHistoricalAxisValue( |
| 739 | AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex); |
| 740 | } |
| 741 | |
| 742 | inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const { |
| 743 | return getHistoricalAxisValue( |
| 744 | AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex); |
| 745 | } |
| 746 | |
| 747 | inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const { |
| 748 | return getHistoricalAxisValue( |
| 749 | AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex); |
| 750 | } |
| 751 | |
| 752 | inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const { |
| 753 | return getHistoricalAxisValue( |
| 754 | AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex); |
| 755 | } |
| 756 | |
| 757 | ssize_t findPointerIndex(int32_t pointerId) const; |
| 758 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 759 | void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 760 | std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, |
| 761 | int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 762 | MotionClassification classification, const ui::Transform& transform, |
| 763 | float xPrecision, float yPrecision, float rawXCursorPosition, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 764 | float rawYCursorPosition, const ui::Transform& rawTransform, nsecs_t downTime, |
| 765 | nsecs_t eventTime, size_t pointerCount, |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 766 | const PointerProperties* pointerProperties, const PointerCoords* pointerCoords); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 767 | |
| 768 | void copyFrom(const MotionEvent* other, bool keepHistory); |
| 769 | |
| 770 | void addSample( |
| 771 | nsecs_t eventTime, |
| 772 | const PointerCoords* pointerCoords); |
| 773 | |
| 774 | void offsetLocation(float xOffset, float yOffset); |
| 775 | |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 776 | void scale(float globalScaleFactor); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 777 | |
Evan Rosky | d4d4d80 | 2021-05-03 20:12:21 -0700 | [diff] [blame] | 778 | // Set 3x3 perspective matrix transformation. |
Jeff Brown | 5a2f68e | 2013-07-15 17:28:19 -0700 | [diff] [blame] | 779 | // Matrix is in row-major form and compatible with SkMatrix. |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 780 | void transform(const std::array<float, 9>& matrix); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 781 | |
Evan Rosky | d4d4d80 | 2021-05-03 20:12:21 -0700 | [diff] [blame] | 782 | // Apply 3x3 perspective matrix transformation only to content (do not modify mTransform). |
| 783 | // Matrix is in row-major form and compatible with SkMatrix. |
| 784 | void applyTransform(const std::array<float, 9>& matrix); |
| 785 | |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 786 | #ifdef __linux__ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 787 | status_t readFromParcel(Parcel* parcel); |
| 788 | status_t writeToParcel(Parcel* parcel) const; |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 789 | #endif |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 790 | |
Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 791 | static bool isTouchEvent(uint32_t source, int32_t action); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 792 | inline bool isTouchEvent() const { |
| 793 | return isTouchEvent(mSource, mAction); |
| 794 | } |
| 795 | |
| 796 | // Low-level accessors. |
| 797 | inline const PointerProperties* getPointerProperties() const { |
Siarhei Vishniakou | 6dbd0ce | 2022-01-13 01:24:14 -0800 | [diff] [blame] | 798 | return mPointerProperties.data(); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 799 | } |
Siarhei Vishniakou | 46a2774 | 2020-09-09 13:57:28 -0500 | [diff] [blame] | 800 | inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.data(); } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 801 | inline const PointerCoords* getSamplePointerCoords() const { |
Siarhei Vishniakou | 6dbd0ce | 2022-01-13 01:24:14 -0800 | [diff] [blame] | 802 | return mSamplePointerCoords.data(); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 805 | static const char* getLabel(int32_t axis); |
| 806 | static int32_t getAxisFromLabel(const char* label); |
| 807 | |
Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 808 | static std::string actionToString(int32_t action); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 809 | |
Prabir Pradhan | 7e1ee56 | 2021-10-26 10:19:49 -0700 | [diff] [blame] | 810 | // MotionEvent will transform various axes in different ways, based on the source. For |
| 811 | // example, the x and y axes will not have any offsets/translations applied if it comes from a |
| 812 | // relative mouse device (since SOURCE_RELATIVE_MOUSE is a non-pointer source). These methods |
| 813 | // are used to apply these transformations for different axes. |
Prabir Pradhan | b5cb957 | 2021-09-24 06:35:16 -0700 | [diff] [blame] | 814 | static vec2 calculateTransformedXY(uint32_t source, const ui::Transform&, const vec2& xy); |
Prabir Pradhan | 9eb02c0 | 2021-10-19 14:02:20 -0700 | [diff] [blame] | 815 | static float calculateTransformedAxisValue(int32_t axis, uint32_t source, const ui::Transform&, |
| 816 | const PointerCoords&); |
Prabir Pradhan | 8e6ce22 | 2022-02-24 09:08:54 -0800 | [diff] [blame] | 817 | static PointerCoords calculateTransformedCoords(uint32_t source, const ui::Transform&, |
| 818 | const PointerCoords&); |
Prabir Pradhan | 9eb02c0 | 2021-10-19 14:02:20 -0700 | [diff] [blame] | 819 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 820 | protected: |
| 821 | int32_t mAction; |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 822 | int32_t mActionButton; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 823 | int32_t mFlags; |
| 824 | int32_t mEdgeFlags; |
| 825 | int32_t mMetaState; |
| 826 | int32_t mButtonState; |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 827 | MotionClassification mClassification; |
chaviw | fd9c1ed | 2020-07-01 10:57:59 -0700 | [diff] [blame] | 828 | ui::Transform mTransform; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 829 | float mXPrecision; |
| 830 | float mYPrecision; |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 831 | float mRawXCursorPosition; |
| 832 | float mRawYCursorPosition; |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 833 | ui::Transform mRawTransform; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 834 | nsecs_t mDownTime; |
Siarhei Vishniakou | 6dbd0ce | 2022-01-13 01:24:14 -0800 | [diff] [blame] | 835 | std::vector<PointerProperties> mPointerProperties; |
Siarhei Vishniakou | 46a2774 | 2020-09-09 13:57:28 -0500 | [diff] [blame] | 836 | std::vector<nsecs_t> mSampleEventTimes; |
Siarhei Vishniakou | 6dbd0ce | 2022-01-13 01:24:14 -0800 | [diff] [blame] | 837 | std::vector<PointerCoords> mSamplePointerCoords; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 838 | }; |
| 839 | |
Siarhei Vishniakou | 4ded0b0 | 2022-05-26 00:36:48 +0000 | [diff] [blame] | 840 | std::ostream& operator<<(std::ostream& out, const MotionEvent& event); |
| 841 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 842 | /* |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 843 | * Focus events. |
| 844 | */ |
| 845 | class FocusEvent : public InputEvent { |
| 846 | public: |
| 847 | virtual ~FocusEvent() {} |
| 848 | |
| 849 | virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_FOCUS; } |
| 850 | |
| 851 | inline bool getHasFocus() const { return mHasFocus; } |
| 852 | |
Antonio Kantek | 3cfec7b | 2021-11-05 18:26:17 -0700 | [diff] [blame] | 853 | void initialize(int32_t id, bool hasFocus); |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 854 | |
| 855 | void initialize(const FocusEvent& from); |
| 856 | |
| 857 | protected: |
| 858 | bool mHasFocus; |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 859 | }; |
| 860 | |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 861 | /* |
| 862 | * Capture events. |
| 863 | */ |
| 864 | class CaptureEvent : public InputEvent { |
| 865 | public: |
| 866 | virtual ~CaptureEvent() {} |
| 867 | |
| 868 | virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_CAPTURE; } |
| 869 | |
| 870 | inline bool getPointerCaptureEnabled() const { return mPointerCaptureEnabled; } |
| 871 | |
| 872 | void initialize(int32_t id, bool pointerCaptureEnabled); |
| 873 | |
| 874 | void initialize(const CaptureEvent& from); |
| 875 | |
| 876 | protected: |
| 877 | bool mPointerCaptureEnabled; |
| 878 | }; |
| 879 | |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 880 | /* |
| 881 | * Drag events. |
| 882 | */ |
| 883 | class DragEvent : public InputEvent { |
| 884 | public: |
| 885 | virtual ~DragEvent() {} |
| 886 | |
| 887 | virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_DRAG; } |
| 888 | |
| 889 | inline bool isExiting() const { return mIsExiting; } |
| 890 | |
| 891 | inline float getX() const { return mX; } |
| 892 | |
| 893 | inline float getY() const { return mY; } |
| 894 | |
| 895 | void initialize(int32_t id, float x, float y, bool isExiting); |
| 896 | |
| 897 | void initialize(const DragEvent& from); |
| 898 | |
| 899 | protected: |
| 900 | bool mIsExiting; |
| 901 | float mX, mY; |
| 902 | }; |
| 903 | |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 904 | /* |
| 905 | * Touch mode events. |
| 906 | */ |
| 907 | class TouchModeEvent : public InputEvent { |
| 908 | public: |
| 909 | virtual ~TouchModeEvent() {} |
| 910 | |
| 911 | virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_TOUCH_MODE; } |
| 912 | |
| 913 | inline bool isInTouchMode() const { return mIsInTouchMode; } |
| 914 | |
| 915 | void initialize(int32_t id, bool isInTouchMode); |
| 916 | |
| 917 | void initialize(const TouchModeEvent& from); |
| 918 | |
| 919 | protected: |
| 920 | bool mIsInTouchMode; |
| 921 | }; |
| 922 | |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 923 | /** |
| 924 | * Base class for verified events. |
| 925 | * Do not create a VerifiedInputEvent explicitly. |
| 926 | * Use helper functions to create them from InputEvents. |
| 927 | */ |
| 928 | struct __attribute__((__packed__)) VerifiedInputEvent { |
| 929 | enum class Type : int32_t { |
| 930 | KEY = AINPUT_EVENT_TYPE_KEY, |
| 931 | MOTION = AINPUT_EVENT_TYPE_MOTION, |
| 932 | }; |
| 933 | |
| 934 | Type type; |
| 935 | int32_t deviceId; |
| 936 | nsecs_t eventTimeNanos; |
| 937 | uint32_t source; |
| 938 | int32_t displayId; |
| 939 | }; |
| 940 | |
| 941 | /** |
| 942 | * Same as KeyEvent, but only contains the data that can be verified. |
| 943 | * If you update this class, you must also update VerifiedKeyEvent.java |
| 944 | */ |
| 945 | struct __attribute__((__packed__)) VerifiedKeyEvent : public VerifiedInputEvent { |
| 946 | int32_t action; |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 947 | int32_t flags; |
Siarhei Vishniakou | f355bf9 | 2021-12-09 10:43:21 -0800 | [diff] [blame] | 948 | nsecs_t downTimeNanos; |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 949 | int32_t keyCode; |
| 950 | int32_t scanCode; |
| 951 | int32_t metaState; |
| 952 | int32_t repeatCount; |
| 953 | }; |
| 954 | |
| 955 | /** |
| 956 | * Same as MotionEvent, but only contains the data that can be verified. |
| 957 | * If you update this class, you must also update VerifiedMotionEvent.java |
| 958 | */ |
| 959 | struct __attribute__((__packed__)) VerifiedMotionEvent : public VerifiedInputEvent { |
| 960 | float rawX; |
| 961 | float rawY; |
| 962 | int32_t actionMasked; |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 963 | int32_t flags; |
Siarhei Vishniakou | f355bf9 | 2021-12-09 10:43:21 -0800 | [diff] [blame] | 964 | nsecs_t downTimeNanos; |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 965 | int32_t metaState; |
| 966 | int32_t buttonState; |
| 967 | }; |
| 968 | |
| 969 | VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event); |
| 970 | VerifiedMotionEvent verifiedMotionEventFromMotionEvent(const MotionEvent& event); |
| 971 | |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 972 | /* |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 973 | * Input event factory. |
| 974 | */ |
| 975 | class InputEventFactoryInterface { |
| 976 | protected: |
| 977 | virtual ~InputEventFactoryInterface() { } |
| 978 | |
| 979 | public: |
| 980 | InputEventFactoryInterface() { } |
| 981 | |
| 982 | virtual KeyEvent* createKeyEvent() = 0; |
| 983 | virtual MotionEvent* createMotionEvent() = 0; |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 984 | virtual FocusEvent* createFocusEvent() = 0; |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 985 | virtual CaptureEvent* createCaptureEvent() = 0; |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 986 | virtual DragEvent* createDragEvent() = 0; |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 987 | virtual TouchModeEvent* createTouchModeEvent() = 0; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 988 | }; |
| 989 | |
| 990 | /* |
| 991 | * A simple input event factory implementation that uses a single preallocated instance |
| 992 | * of each type of input event that are reused for each request. |
| 993 | */ |
| 994 | class PreallocatedInputEventFactory : public InputEventFactoryInterface { |
| 995 | public: |
| 996 | PreallocatedInputEventFactory() { } |
| 997 | virtual ~PreallocatedInputEventFactory() { } |
| 998 | |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 999 | virtual KeyEvent* createKeyEvent() override { return &mKeyEvent; } |
| 1000 | virtual MotionEvent* createMotionEvent() override { return &mMotionEvent; } |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 1001 | virtual FocusEvent* createFocusEvent() override { return &mFocusEvent; } |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 1002 | virtual CaptureEvent* createCaptureEvent() override { return &mCaptureEvent; } |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 1003 | virtual DragEvent* createDragEvent() override { return &mDragEvent; } |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 1004 | virtual TouchModeEvent* createTouchModeEvent() override { return &mTouchModeEvent; } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1005 | |
| 1006 | private: |
| 1007 | KeyEvent mKeyEvent; |
| 1008 | MotionEvent mMotionEvent; |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 1009 | FocusEvent mFocusEvent; |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 1010 | CaptureEvent mCaptureEvent; |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 1011 | DragEvent mDragEvent; |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 1012 | TouchModeEvent mTouchModeEvent; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1013 | }; |
| 1014 | |
| 1015 | /* |
| 1016 | * An input event factory implementation that maintains a pool of input events. |
| 1017 | */ |
| 1018 | class PooledInputEventFactory : public InputEventFactoryInterface { |
| 1019 | public: |
Chih-Hung Hsieh | f43b02c | 2018-12-20 15:45:56 -0800 | [diff] [blame] | 1020 | explicit PooledInputEventFactory(size_t maxPoolSize = 20); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1021 | virtual ~PooledInputEventFactory(); |
| 1022 | |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 1023 | virtual KeyEvent* createKeyEvent() override; |
| 1024 | virtual MotionEvent* createMotionEvent() override; |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 1025 | virtual FocusEvent* createFocusEvent() override; |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 1026 | virtual CaptureEvent* createCaptureEvent() override; |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 1027 | virtual DragEvent* createDragEvent() override; |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 1028 | virtual TouchModeEvent* createTouchModeEvent() override; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1029 | |
| 1030 | void recycle(InputEvent* event); |
| 1031 | |
| 1032 | private: |
| 1033 | const size_t mMaxPoolSize; |
| 1034 | |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 1035 | std::queue<std::unique_ptr<KeyEvent>> mKeyEventPool; |
| 1036 | std::queue<std::unique_ptr<MotionEvent>> mMotionEventPool; |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 1037 | std::queue<std::unique_ptr<FocusEvent>> mFocusEventPool; |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 1038 | std::queue<std::unique_ptr<CaptureEvent>> mCaptureEventPool; |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 1039 | std::queue<std::unique_ptr<DragEvent>> mDragEventPool; |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 1040 | std::queue<std::unique_ptr<TouchModeEvent>> mTouchModeEventPool; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1041 | }; |
| 1042 | |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 1043 | /* |
| 1044 | * Describes a unique request to enable or disable Pointer Capture. |
| 1045 | */ |
| 1046 | struct PointerCaptureRequest { |
| 1047 | public: |
| 1048 | inline PointerCaptureRequest() : enable(false), seq(0) {} |
| 1049 | inline PointerCaptureRequest(bool enable, uint32_t seq) : enable(enable), seq(seq) {} |
| 1050 | inline bool operator==(const PointerCaptureRequest& other) const { |
| 1051 | return enable == other.enable && seq == other.seq; |
| 1052 | } |
| 1053 | explicit inline operator bool() const { return enable; } |
| 1054 | |
| 1055 | // True iff this is a request to enable Pointer Capture. |
| 1056 | bool enable; |
| 1057 | |
| 1058 | // The sequence number for the request. |
| 1059 | uint32_t seq; |
| 1060 | }; |
| 1061 | |
Brandon Pollack | 44c6cc8 | 2022-06-02 01:43:46 +0000 | [diff] [blame^] | 1062 | /* Pointer icon styles. |
| 1063 | * Must match the definition in android.view.PointerIcon. |
| 1064 | */ |
| 1065 | enum { |
| 1066 | POINTER_ICON_STYLE_CUSTOM = -1, |
| 1067 | POINTER_ICON_STYLE_NULL = 0, |
| 1068 | POINTER_ICON_STYLE_ARROW = 1000, |
| 1069 | POINTER_ICON_STYLE_CONTEXT_MENU = 1001, |
| 1070 | POINTER_ICON_STYLE_HAND = 1002, |
| 1071 | POINTER_ICON_STYLE_HELP = 1003, |
| 1072 | POINTER_ICON_STYLE_WAIT = 1004, |
| 1073 | POINTER_ICON_STYLE_CELL = 1006, |
| 1074 | POINTER_ICON_STYLE_CROSSHAIR = 1007, |
| 1075 | POINTER_ICON_STYLE_TEXT = 1008, |
| 1076 | POINTER_ICON_STYLE_VERTICAL_TEXT = 1009, |
| 1077 | POINTER_ICON_STYLE_ALIAS = 1010, |
| 1078 | POINTER_ICON_STYLE_COPY = 1011, |
| 1079 | POINTER_ICON_STYLE_NO_DROP = 1012, |
| 1080 | POINTER_ICON_STYLE_ALL_SCROLL = 1013, |
| 1081 | POINTER_ICON_STYLE_HORIZONTAL_DOUBLE_ARROW = 1014, |
| 1082 | POINTER_ICON_STYLE_VERTICAL_DOUBLE_ARROW = 1015, |
| 1083 | POINTER_ICON_STYLE_TOP_RIGHT_DOUBLE_ARROW = 1016, |
| 1084 | POINTER_ICON_STYLE_TOP_LEFT_DOUBLE_ARROW = 1017, |
| 1085 | POINTER_ICON_STYLE_ZOOM_IN = 1018, |
| 1086 | POINTER_ICON_STYLE_ZOOM_OUT = 1019, |
| 1087 | POINTER_ICON_STYLE_GRAB = 1020, |
| 1088 | POINTER_ICON_STYLE_GRABBING = 1021, |
| 1089 | |
| 1090 | POINTER_ICON_STYLE_SPOT_HOVER = 2000, |
| 1091 | POINTER_ICON_STYLE_SPOT_TOUCH = 2001, |
| 1092 | POINTER_ICON_STYLE_SPOT_ANCHOR = 2002, |
| 1093 | }; |
| 1094 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1095 | } // namespace android |
| 1096 | |
| 1097 | #endif // _LIBINPUT_INPUT_H |