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 | */ |
| 167 | #define MAX_POINTERS 16 |
| 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. |
| 278 | * |
| 279 | * The following values must be kept in sync with MotionEvent.java |
| 280 | */ |
| 281 | enum class MotionClassification : uint8_t { |
| 282 | /** |
| 283 | * No classification is available. |
| 284 | */ |
| 285 | NONE = 0, |
| 286 | /** |
| 287 | * Too early to classify the current gesture. Need more events. Look for changes in the |
| 288 | * upcoming motion events. |
| 289 | */ |
| 290 | AMBIGUOUS_GESTURE = 1, |
| 291 | /** |
| 292 | * The current gesture likely represents a user intentionally exerting force on the touchscreen. |
| 293 | */ |
| 294 | DEEP_PRESS = 2, |
| 295 | }; |
| 296 | |
Siarhei Vishniakou | 16a2e30 | 2019-01-14 19:21:45 -0800 | [diff] [blame] | 297 | /** |
| 298 | * String representation of MotionClassification |
| 299 | */ |
| 300 | const char* motionClassificationToString(MotionClassification classification); |
| 301 | |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 302 | /** |
Siarhei Vishniakou | f94ae02 | 2021-02-04 01:23:17 +0000 | [diff] [blame] | 303 | * Portion of FrameMetrics timeline of interest to input code. |
| 304 | */ |
| 305 | enum GraphicsTimeline : size_t { |
| 306 | /** Time when the app sent the buffer to SurfaceFlinger. */ |
| 307 | GPU_COMPLETED_TIME = 0, |
| 308 | |
| 309 | /** Time when the frame was presented on the display */ |
| 310 | PRESENT_TIME = 1, |
| 311 | |
| 312 | /** Total size of the 'GraphicsTimeline' array. Must always be last. */ |
| 313 | SIZE = 2 |
| 314 | }; |
| 315 | |
| 316 | /** |
Garfield Tan | 84b087e | 2020-01-23 10:49:05 -0800 | [diff] [blame] | 317 | * Generator of unique numbers used to identify input events. |
| 318 | * |
| 319 | * Layout of ID: |
| 320 | * |--------------------------|---------------------------| |
| 321 | * | 2 bits for source | 30 bits for random number | |
| 322 | * |--------------------------|---------------------------| |
| 323 | */ |
| 324 | class IdGenerator { |
| 325 | private: |
| 326 | static constexpr uint32_t SOURCE_SHIFT = 30; |
| 327 | |
| 328 | public: |
| 329 | // Used to divide integer space to ensure no conflict among these sources./ |
| 330 | enum class Source : int32_t { |
Garfield Tan | 750c7f4 | 2020-05-18 17:41:46 -0700 | [diff] [blame] | 331 | INPUT_READER = static_cast<int32_t>(0x0u << SOURCE_SHIFT), |
| 332 | INPUT_DISPATCHER = static_cast<int32_t>(0x1u << SOURCE_SHIFT), |
| 333 | 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] | 334 | }; |
| 335 | IdGenerator(Source source); |
| 336 | |
| 337 | int32_t nextId() const; |
| 338 | |
| 339 | // Extract source from given id. |
| 340 | static inline Source getSource(int32_t id) { return static_cast<Source>(SOURCE_MASK & id); } |
| 341 | |
| 342 | private: |
| 343 | const Source mSource; |
| 344 | |
Garfield Tan | 750c7f4 | 2020-05-18 17:41:46 -0700 | [diff] [blame] | 345 | 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] | 346 | }; |
| 347 | |
| 348 | /** |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 349 | * Invalid value for cursor position. Used for non-mouse events, tests and injected events. Don't |
| 350 | * use it for direct comparison with any other value, because NaN isn't equal to itself according to |
| 351 | * IEEE 754. Use isnan() instead to check if a cursor position is valid. |
| 352 | */ |
| 353 | constexpr float AMOTION_EVENT_INVALID_CURSOR_POSITION = std::numeric_limits<float>::quiet_NaN(); |
| 354 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 355 | /* |
| 356 | * Pointer coordinate data. |
| 357 | */ |
| 358 | struct PointerCoords { |
Michael Wright | 8f6710f | 2014-06-09 18:56:43 -0700 | [diff] [blame] | 359 | enum { MAX_AXES = 30 }; // 30 so that sizeof(PointerCoords) == 128 |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 360 | |
| 361 | // Bitfield of axes that are present in this structure. |
Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 362 | uint64_t bits __attribute__((aligned(8))); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 363 | |
| 364 | // Values of axes that are stored in this structure packed in order by axis id |
| 365 | // for each axis that is present in the structure according to 'bits'. |
| 366 | float values[MAX_AXES]; |
| 367 | |
| 368 | inline void clear() { |
Michael Wright | d0bd391 | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 369 | BitSet64::clear(bits); |
| 370 | } |
| 371 | |
| 372 | bool isEmpty() const { |
| 373 | return BitSet64::isEmpty(bits); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | float getAxisValue(int32_t axis) const; |
| 377 | status_t setAxisValue(int32_t axis, float value); |
| 378 | |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 379 | // Scale the pointer coordinates according to a global scale and a |
| 380 | // window scale. The global scale will be applied to TOUCH/TOOL_MAJOR/MINOR |
| 381 | // axes, however the window scaling will not. |
| 382 | void scale(float globalScale, float windowXScale, float windowYScale); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 383 | |
chaviw | c01e137 | 2020-07-01 12:37:31 -0700 | [diff] [blame] | 384 | void transform(const ui::Transform& transform); |
| 385 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 386 | inline float getX() const { |
| 387 | return getAxisValue(AMOTION_EVENT_AXIS_X); |
| 388 | } |
| 389 | |
| 390 | inline float getY() const { |
| 391 | return getAxisValue(AMOTION_EVENT_AXIS_Y); |
| 392 | } |
| 393 | |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 394 | vec2 getXYValue() const { return vec2(getX(), getY()); } |
| 395 | |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 396 | #ifdef __linux__ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 397 | status_t readFromParcel(Parcel* parcel); |
| 398 | status_t writeToParcel(Parcel* parcel) const; |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 399 | #endif |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 400 | |
| 401 | bool operator==(const PointerCoords& other) const; |
| 402 | inline bool operator!=(const PointerCoords& other) const { |
| 403 | return !(*this == other); |
| 404 | } |
| 405 | |
| 406 | void copyFrom(const PointerCoords& other); |
| 407 | |
| 408 | private: |
| 409 | void tooManyAxes(int axis); |
| 410 | }; |
| 411 | |
| 412 | /* |
| 413 | * Pointer property data. |
| 414 | */ |
| 415 | struct PointerProperties { |
| 416 | // The id of the pointer. |
| 417 | int32_t id; |
| 418 | |
| 419 | // The pointer tool type. |
| 420 | int32_t toolType; |
| 421 | |
| 422 | inline void clear() { |
| 423 | id = -1; |
| 424 | toolType = 0; |
| 425 | } |
| 426 | |
| 427 | bool operator==(const PointerProperties& other) const; |
| 428 | inline bool operator!=(const PointerProperties& other) const { |
| 429 | return !(*this == other); |
| 430 | } |
| 431 | |
| 432 | void copyFrom(const PointerProperties& other); |
| 433 | }; |
| 434 | |
| 435 | /* |
| 436 | * Input events. |
| 437 | */ |
| 438 | class InputEvent : public AInputEvent { |
| 439 | public: |
| 440 | virtual ~InputEvent() { } |
| 441 | |
| 442 | virtual int32_t getType() const = 0; |
| 443 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 444 | inline int32_t getId() const { return mId; } |
| 445 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 446 | inline int32_t getDeviceId() const { return mDeviceId; } |
| 447 | |
Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 448 | inline uint32_t getSource() const { return mSource; } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 449 | |
Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 450 | inline void setSource(uint32_t source) { mSource = source; } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 451 | |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 452 | inline int32_t getDisplayId() const { return mDisplayId; } |
| 453 | |
| 454 | inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; } |
| 455 | |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 456 | inline std::array<uint8_t, 32> getHmac() const { return mHmac; } |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 457 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 458 | static int32_t nextId(); |
| 459 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 460 | protected: |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 461 | 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] | 462 | std::array<uint8_t, 32> hmac); |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 463 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 464 | void initialize(const InputEvent& from); |
| 465 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 466 | int32_t mId; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 467 | int32_t mDeviceId; |
Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 468 | uint32_t mSource; |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 469 | int32_t mDisplayId; |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 470 | std::array<uint8_t, 32> mHmac; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 471 | }; |
| 472 | |
| 473 | /* |
| 474 | * Key events. |
| 475 | */ |
| 476 | class KeyEvent : public InputEvent { |
| 477 | public: |
| 478 | virtual ~KeyEvent() { } |
| 479 | |
| 480 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; } |
| 481 | |
| 482 | inline int32_t getAction() const { return mAction; } |
| 483 | |
| 484 | inline int32_t getFlags() const { return mFlags; } |
| 485 | |
| 486 | inline void setFlags(int32_t flags) { mFlags = flags; } |
| 487 | |
| 488 | inline int32_t getKeyCode() const { return mKeyCode; } |
| 489 | |
| 490 | inline int32_t getScanCode() const { return mScanCode; } |
| 491 | |
| 492 | inline int32_t getMetaState() const { return mMetaState; } |
| 493 | |
| 494 | inline int32_t getRepeatCount() const { return mRepeatCount; } |
| 495 | |
| 496 | inline nsecs_t getDownTime() const { return mDownTime; } |
| 497 | |
| 498 | inline nsecs_t getEventTime() const { return mEventTime; } |
| 499 | |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 500 | static const char* getLabel(int32_t keyCode); |
| 501 | static int32_t getKeyCodeFromLabel(const char* label); |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 502 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 503 | 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] | 504 | std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, |
| 505 | int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, |
| 506 | nsecs_t eventTime); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 507 | void initialize(const KeyEvent& from); |
| 508 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 509 | static const char* actionToString(int32_t action); |
| 510 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 511 | protected: |
| 512 | int32_t mAction; |
| 513 | int32_t mFlags; |
| 514 | int32_t mKeyCode; |
| 515 | int32_t mScanCode; |
| 516 | int32_t mMetaState; |
| 517 | int32_t mRepeatCount; |
| 518 | nsecs_t mDownTime; |
| 519 | nsecs_t mEventTime; |
| 520 | }; |
| 521 | |
| 522 | /* |
| 523 | * Motion events. |
| 524 | */ |
| 525 | class MotionEvent : public InputEvent { |
| 526 | public: |
| 527 | virtual ~MotionEvent() { } |
| 528 | |
| 529 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; } |
| 530 | |
| 531 | inline int32_t getAction() const { return mAction; } |
| 532 | |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 533 | 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] | 534 | |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 535 | inline int32_t getActionMasked() const { return getActionMasked(mAction); } |
| 536 | |
| 537 | static int32_t getActionIndex(int32_t action) { |
| 538 | return (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> |
| 539 | AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 542 | inline int32_t getActionIndex() const { return getActionIndex(mAction); } |
| 543 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 544 | inline void setAction(int32_t action) { mAction = action; } |
| 545 | |
| 546 | inline int32_t getFlags() const { return mFlags; } |
| 547 | |
| 548 | inline void setFlags(int32_t flags) { mFlags = flags; } |
| 549 | |
| 550 | inline int32_t getEdgeFlags() const { return mEdgeFlags; } |
| 551 | |
| 552 | inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; } |
| 553 | |
| 554 | inline int32_t getMetaState() const { return mMetaState; } |
| 555 | |
| 556 | inline void setMetaState(int32_t metaState) { mMetaState = metaState; } |
| 557 | |
| 558 | inline int32_t getButtonState() const { return mButtonState; } |
| 559 | |
Michael Wright | 6db5879 | 2016-09-14 19:53:37 +0100 | [diff] [blame] | 560 | inline void setButtonState(int32_t buttonState) { mButtonState = buttonState; } |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 561 | |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 562 | inline MotionClassification getClassification() const { return mClassification; } |
| 563 | |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 564 | inline int32_t getActionButton() const { return mActionButton; } |
| 565 | |
Michael Wright | 21957b9 | 2015-06-17 21:06:54 +0100 | [diff] [blame] | 566 | inline void setActionButton(int32_t button) { mActionButton = button; } |
| 567 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 568 | inline float getXOffset() const { return mTransform.tx(); } |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 569 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 570 | inline float getYOffset() const { return mTransform.ty(); } |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 571 | |
Prabir Pradhan | 5beda76 | 2021-12-10 09:30:08 +0000 | [diff] [blame] | 572 | inline const ui::Transform& getTransform() const { return mTransform; } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 573 | |
Prabir Pradhan | 092f3a9 | 2021-11-25 10:53:27 -0800 | [diff] [blame] | 574 | int getSurfaceRotation() const; |
| 575 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 576 | inline float getXPrecision() const { return mXPrecision; } |
| 577 | |
| 578 | inline float getYPrecision() const { return mYPrecision; } |
| 579 | |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 580 | inline float getRawXCursorPosition() const { return mRawXCursorPosition; } |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 581 | |
| 582 | float getXCursorPosition() const; |
| 583 | |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 584 | inline float getRawYCursorPosition() const { return mRawYCursorPosition; } |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 585 | |
| 586 | float getYCursorPosition() const; |
| 587 | |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 588 | void setCursorPosition(float x, float y); |
| 589 | |
Prabir Pradhan | 5beda76 | 2021-12-10 09:30:08 +0000 | [diff] [blame] | 590 | inline const ui::Transform& getRawTransform() const { return mRawTransform; } |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 591 | |
Garfield Tan | ab0ab9c | 2019-07-10 18:58:28 -0700 | [diff] [blame] | 592 | static inline bool isValidCursorPosition(float x, float y) { return !isnan(x) && !isnan(y); } |
| 593 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 594 | inline nsecs_t getDownTime() const { return mDownTime; } |
| 595 | |
| 596 | inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; } |
| 597 | |
| 598 | inline size_t getPointerCount() const { return mPointerProperties.size(); } |
| 599 | |
| 600 | inline const PointerProperties* getPointerProperties(size_t pointerIndex) const { |
| 601 | return &mPointerProperties[pointerIndex]; |
| 602 | } |
| 603 | |
| 604 | inline int32_t getPointerId(size_t pointerIndex) const { |
| 605 | return mPointerProperties[pointerIndex].id; |
| 606 | } |
| 607 | |
| 608 | inline int32_t getToolType(size_t pointerIndex) const { |
| 609 | return mPointerProperties[pointerIndex].toolType; |
| 610 | } |
| 611 | |
| 612 | inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; } |
| 613 | |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 614 | /** |
| 615 | * The actual raw pointer coords: whatever comes from the input device without any external |
| 616 | * transforms applied. |
| 617 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 618 | const PointerCoords* getRawPointerCoords(size_t pointerIndex) const; |
| 619 | |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 620 | /** |
| 621 | * This is the raw axis value. However, for X/Y axes, this currently applies a "compat-raw" |
| 622 | * transform because many apps (incorrectly) assumed that raw == oriented-screen-space. |
| 623 | * "compat raw" is raw coordinates with screen rotation applied. |
| 624 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 625 | float getRawAxisValue(int32_t axis, size_t pointerIndex) const; |
| 626 | |
| 627 | inline float getRawX(size_t pointerIndex) const { |
| 628 | return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex); |
| 629 | } |
| 630 | |
| 631 | inline float getRawY(size_t pointerIndex) const { |
| 632 | return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex); |
| 633 | } |
| 634 | |
| 635 | float getAxisValue(int32_t axis, size_t pointerIndex) const; |
| 636 | |
Siarhei Vishniakou | 69e4d0f | 2020-09-14 19:53:29 -0500 | [diff] [blame] | 637 | /** |
| 638 | * Get the X coordinate of the latest sample in this MotionEvent for pointer 'pointerIndex'. |
| 639 | * Identical to calling getHistoricalX(pointerIndex, getHistorySize()). |
| 640 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 641 | inline float getX(size_t pointerIndex) const { |
| 642 | return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex); |
| 643 | } |
| 644 | |
Siarhei Vishniakou | 69e4d0f | 2020-09-14 19:53:29 -0500 | [diff] [blame] | 645 | /** |
| 646 | * Get the Y coordinate of the latest sample in this MotionEvent for pointer 'pointerIndex'. |
| 647 | * Identical to calling getHistoricalX(pointerIndex, getHistorySize()). |
| 648 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 649 | inline float getY(size_t pointerIndex) const { |
| 650 | return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex); |
| 651 | } |
| 652 | |
| 653 | inline float getPressure(size_t pointerIndex) const { |
| 654 | return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex); |
| 655 | } |
| 656 | |
| 657 | inline float getSize(size_t pointerIndex) const { |
| 658 | return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex); |
| 659 | } |
| 660 | |
| 661 | inline float getTouchMajor(size_t pointerIndex) const { |
| 662 | return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex); |
| 663 | } |
| 664 | |
| 665 | inline float getTouchMinor(size_t pointerIndex) const { |
| 666 | return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex); |
| 667 | } |
| 668 | |
| 669 | inline float getToolMajor(size_t pointerIndex) const { |
| 670 | return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex); |
| 671 | } |
| 672 | |
| 673 | inline float getToolMinor(size_t pointerIndex) const { |
| 674 | return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex); |
| 675 | } |
| 676 | |
| 677 | inline float getOrientation(size_t pointerIndex) const { |
| 678 | return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex); |
| 679 | } |
| 680 | |
| 681 | inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; } |
| 682 | |
| 683 | inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const { |
| 684 | return mSampleEventTimes[historicalIndex]; |
| 685 | } |
| 686 | |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 687 | /** |
| 688 | * The actual raw pointer coords: whatever comes from the input device without any external |
| 689 | * transforms applied. |
| 690 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 691 | const PointerCoords* getHistoricalRawPointerCoords( |
| 692 | size_t pointerIndex, size_t historicalIndex) const; |
| 693 | |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 694 | /** |
| 695 | * This is the raw axis value. However, for X/Y axes, this currently applies a "compat-raw" |
| 696 | * transform because many apps (incorrectly) assumed that raw == oriented-screen-space. |
| 697 | * "compat raw" is raw coordinates with screen rotation applied. |
| 698 | */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 699 | float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex, |
| 700 | size_t historicalIndex) const; |
| 701 | |
| 702 | inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const { |
| 703 | return getHistoricalRawAxisValue( |
| 704 | AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex); |
| 705 | } |
| 706 | |
| 707 | inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const { |
| 708 | return getHistoricalRawAxisValue( |
| 709 | AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex); |
| 710 | } |
| 711 | |
| 712 | float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const; |
| 713 | |
| 714 | inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const { |
| 715 | return getHistoricalAxisValue( |
| 716 | AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex); |
| 717 | } |
| 718 | |
| 719 | inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const { |
| 720 | return getHistoricalAxisValue( |
| 721 | AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex); |
| 722 | } |
| 723 | |
| 724 | inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const { |
| 725 | return getHistoricalAxisValue( |
| 726 | AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex); |
| 727 | } |
| 728 | |
| 729 | inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const { |
| 730 | return getHistoricalAxisValue( |
| 731 | AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex); |
| 732 | } |
| 733 | |
| 734 | inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const { |
| 735 | return getHistoricalAxisValue( |
| 736 | AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex); |
| 737 | } |
| 738 | |
| 739 | inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const { |
| 740 | return getHistoricalAxisValue( |
| 741 | AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex); |
| 742 | } |
| 743 | |
| 744 | inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const { |
| 745 | return getHistoricalAxisValue( |
| 746 | AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex); |
| 747 | } |
| 748 | |
| 749 | inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const { |
| 750 | return getHistoricalAxisValue( |
| 751 | AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex); |
| 752 | } |
| 753 | |
| 754 | inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const { |
| 755 | return getHistoricalAxisValue( |
| 756 | AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex); |
| 757 | } |
| 758 | |
| 759 | ssize_t findPointerIndex(int32_t pointerId) const; |
| 760 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 761 | 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] | 762 | std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, |
| 763 | int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 764 | MotionClassification classification, const ui::Transform& transform, |
| 765 | float xPrecision, float yPrecision, float rawXCursorPosition, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 766 | float rawYCursorPosition, const ui::Transform& rawTransform, nsecs_t downTime, |
| 767 | nsecs_t eventTime, size_t pointerCount, |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 768 | const PointerProperties* pointerProperties, const PointerCoords* pointerCoords); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 769 | |
| 770 | void copyFrom(const MotionEvent* other, bool keepHistory); |
| 771 | |
| 772 | void addSample( |
| 773 | nsecs_t eventTime, |
| 774 | const PointerCoords* pointerCoords); |
| 775 | |
| 776 | void offsetLocation(float xOffset, float yOffset); |
| 777 | |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 778 | void scale(float globalScaleFactor); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 779 | |
Evan Rosky | d4d4d80 | 2021-05-03 20:12:21 -0700 | [diff] [blame] | 780 | // Set 3x3 perspective matrix transformation. |
Jeff Brown | 5a2f68e | 2013-07-15 17:28:19 -0700 | [diff] [blame] | 781 | // Matrix is in row-major form and compatible with SkMatrix. |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 782 | void transform(const std::array<float, 9>& matrix); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 783 | |
Evan Rosky | d4d4d80 | 2021-05-03 20:12:21 -0700 | [diff] [blame] | 784 | // Apply 3x3 perspective matrix transformation only to content (do not modify mTransform). |
| 785 | // Matrix is in row-major form and compatible with SkMatrix. |
| 786 | void applyTransform(const std::array<float, 9>& matrix); |
| 787 | |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 788 | #ifdef __linux__ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 789 | status_t readFromParcel(Parcel* parcel); |
| 790 | status_t writeToParcel(Parcel* parcel) const; |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 791 | #endif |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 792 | |
Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 793 | static bool isTouchEvent(uint32_t source, int32_t action); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 794 | inline bool isTouchEvent() const { |
| 795 | return isTouchEvent(mSource, mAction); |
| 796 | } |
| 797 | |
| 798 | // Low-level accessors. |
| 799 | inline const PointerProperties* getPointerProperties() const { |
Siarhei Vishniakou | 6dbd0ce | 2022-01-13 01:24:14 -0800 | [diff] [blame^] | 800 | return mPointerProperties.data(); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 801 | } |
Siarhei Vishniakou | 46a2774 | 2020-09-09 13:57:28 -0500 | [diff] [blame] | 802 | inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.data(); } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 803 | inline const PointerCoords* getSamplePointerCoords() const { |
Siarhei Vishniakou | 6dbd0ce | 2022-01-13 01:24:14 -0800 | [diff] [blame^] | 804 | return mSamplePointerCoords.data(); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 807 | static const char* getLabel(int32_t axis); |
| 808 | static int32_t getAxisFromLabel(const char* label); |
| 809 | |
Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 810 | static std::string actionToString(int32_t action); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 811 | |
Prabir Pradhan | 7e1ee56 | 2021-10-26 10:19:49 -0700 | [diff] [blame] | 812 | // MotionEvent will transform various axes in different ways, based on the source. For |
| 813 | // example, the x and y axes will not have any offsets/translations applied if it comes from a |
| 814 | // relative mouse device (since SOURCE_RELATIVE_MOUSE is a non-pointer source). These methods |
| 815 | // are used to apply these transformations for different axes. |
Prabir Pradhan | b5cb957 | 2021-09-24 06:35:16 -0700 | [diff] [blame] | 816 | static vec2 calculateTransformedXY(uint32_t source, const ui::Transform&, const vec2& xy); |
Prabir Pradhan | 9eb02c0 | 2021-10-19 14:02:20 -0700 | [diff] [blame] | 817 | static float calculateTransformedAxisValue(int32_t axis, uint32_t source, const ui::Transform&, |
| 818 | const PointerCoords&); |
| 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 | |
| 840 | /* |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 841 | * Focus events. |
| 842 | */ |
| 843 | class FocusEvent : public InputEvent { |
| 844 | public: |
| 845 | virtual ~FocusEvent() {} |
| 846 | |
| 847 | virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_FOCUS; } |
| 848 | |
| 849 | inline bool getHasFocus() const { return mHasFocus; } |
| 850 | |
Antonio Kantek | 3cfec7b | 2021-11-05 18:26:17 -0700 | [diff] [blame] | 851 | void initialize(int32_t id, bool hasFocus); |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 852 | |
| 853 | void initialize(const FocusEvent& from); |
| 854 | |
| 855 | protected: |
| 856 | bool mHasFocus; |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 857 | }; |
| 858 | |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 859 | /* |
| 860 | * Capture events. |
| 861 | */ |
| 862 | class CaptureEvent : public InputEvent { |
| 863 | public: |
| 864 | virtual ~CaptureEvent() {} |
| 865 | |
| 866 | virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_CAPTURE; } |
| 867 | |
| 868 | inline bool getPointerCaptureEnabled() const { return mPointerCaptureEnabled; } |
| 869 | |
| 870 | void initialize(int32_t id, bool pointerCaptureEnabled); |
| 871 | |
| 872 | void initialize(const CaptureEvent& from); |
| 873 | |
| 874 | protected: |
| 875 | bool mPointerCaptureEnabled; |
| 876 | }; |
| 877 | |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 878 | /* |
| 879 | * Drag events. |
| 880 | */ |
| 881 | class DragEvent : public InputEvent { |
| 882 | public: |
| 883 | virtual ~DragEvent() {} |
| 884 | |
| 885 | virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_DRAG; } |
| 886 | |
| 887 | inline bool isExiting() const { return mIsExiting; } |
| 888 | |
| 889 | inline float getX() const { return mX; } |
| 890 | |
| 891 | inline float getY() const { return mY; } |
| 892 | |
| 893 | void initialize(int32_t id, float x, float y, bool isExiting); |
| 894 | |
| 895 | void initialize(const DragEvent& from); |
| 896 | |
| 897 | protected: |
| 898 | bool mIsExiting; |
| 899 | float mX, mY; |
| 900 | }; |
| 901 | |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 902 | /* |
| 903 | * Touch mode events. |
| 904 | */ |
| 905 | class TouchModeEvent : public InputEvent { |
| 906 | public: |
| 907 | virtual ~TouchModeEvent() {} |
| 908 | |
| 909 | virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_TOUCH_MODE; } |
| 910 | |
| 911 | inline bool isInTouchMode() const { return mIsInTouchMode; } |
| 912 | |
| 913 | void initialize(int32_t id, bool isInTouchMode); |
| 914 | |
| 915 | void initialize(const TouchModeEvent& from); |
| 916 | |
| 917 | protected: |
| 918 | bool mIsInTouchMode; |
| 919 | }; |
| 920 | |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 921 | /** |
| 922 | * Base class for verified events. |
| 923 | * Do not create a VerifiedInputEvent explicitly. |
| 924 | * Use helper functions to create them from InputEvents. |
| 925 | */ |
| 926 | struct __attribute__((__packed__)) VerifiedInputEvent { |
| 927 | enum class Type : int32_t { |
| 928 | KEY = AINPUT_EVENT_TYPE_KEY, |
| 929 | MOTION = AINPUT_EVENT_TYPE_MOTION, |
| 930 | }; |
| 931 | |
| 932 | Type type; |
| 933 | int32_t deviceId; |
| 934 | nsecs_t eventTimeNanos; |
| 935 | uint32_t source; |
| 936 | int32_t displayId; |
| 937 | }; |
| 938 | |
| 939 | /** |
| 940 | * Same as KeyEvent, but only contains the data that can be verified. |
| 941 | * If you update this class, you must also update VerifiedKeyEvent.java |
| 942 | */ |
| 943 | struct __attribute__((__packed__)) VerifiedKeyEvent : public VerifiedInputEvent { |
| 944 | int32_t action; |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 945 | int32_t flags; |
Siarhei Vishniakou | f355bf9 | 2021-12-09 10:43:21 -0800 | [diff] [blame] | 946 | nsecs_t downTimeNanos; |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 947 | int32_t keyCode; |
| 948 | int32_t scanCode; |
| 949 | int32_t metaState; |
| 950 | int32_t repeatCount; |
| 951 | }; |
| 952 | |
| 953 | /** |
| 954 | * Same as MotionEvent, but only contains the data that can be verified. |
| 955 | * If you update this class, you must also update VerifiedMotionEvent.java |
| 956 | */ |
| 957 | struct __attribute__((__packed__)) VerifiedMotionEvent : public VerifiedInputEvent { |
| 958 | float rawX; |
| 959 | float rawY; |
| 960 | int32_t actionMasked; |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 961 | int32_t flags; |
Siarhei Vishniakou | f355bf9 | 2021-12-09 10:43:21 -0800 | [diff] [blame] | 962 | nsecs_t downTimeNanos; |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 963 | int32_t metaState; |
| 964 | int32_t buttonState; |
| 965 | }; |
| 966 | |
| 967 | VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event); |
| 968 | VerifiedMotionEvent verifiedMotionEventFromMotionEvent(const MotionEvent& event); |
| 969 | |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 970 | /* |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 971 | * Input event factory. |
| 972 | */ |
| 973 | class InputEventFactoryInterface { |
| 974 | protected: |
| 975 | virtual ~InputEventFactoryInterface() { } |
| 976 | |
| 977 | public: |
| 978 | InputEventFactoryInterface() { } |
| 979 | |
| 980 | virtual KeyEvent* createKeyEvent() = 0; |
| 981 | virtual MotionEvent* createMotionEvent() = 0; |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 982 | virtual FocusEvent* createFocusEvent() = 0; |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 983 | virtual CaptureEvent* createCaptureEvent() = 0; |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 984 | virtual DragEvent* createDragEvent() = 0; |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 985 | virtual TouchModeEvent* createTouchModeEvent() = 0; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 986 | }; |
| 987 | |
| 988 | /* |
| 989 | * A simple input event factory implementation that uses a single preallocated instance |
| 990 | * of each type of input event that are reused for each request. |
| 991 | */ |
| 992 | class PreallocatedInputEventFactory : public InputEventFactoryInterface { |
| 993 | public: |
| 994 | PreallocatedInputEventFactory() { } |
| 995 | virtual ~PreallocatedInputEventFactory() { } |
| 996 | |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 997 | virtual KeyEvent* createKeyEvent() override { return &mKeyEvent; } |
| 998 | virtual MotionEvent* createMotionEvent() override { return &mMotionEvent; } |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 999 | virtual FocusEvent* createFocusEvent() override { return &mFocusEvent; } |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 1000 | virtual CaptureEvent* createCaptureEvent() override { return &mCaptureEvent; } |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 1001 | virtual DragEvent* createDragEvent() override { return &mDragEvent; } |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 1002 | virtual TouchModeEvent* createTouchModeEvent() override { return &mTouchModeEvent; } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1003 | |
| 1004 | private: |
| 1005 | KeyEvent mKeyEvent; |
| 1006 | MotionEvent mMotionEvent; |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 1007 | FocusEvent mFocusEvent; |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 1008 | CaptureEvent mCaptureEvent; |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 1009 | DragEvent mDragEvent; |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 1010 | TouchModeEvent mTouchModeEvent; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1011 | }; |
| 1012 | |
| 1013 | /* |
| 1014 | * An input event factory implementation that maintains a pool of input events. |
| 1015 | */ |
| 1016 | class PooledInputEventFactory : public InputEventFactoryInterface { |
| 1017 | public: |
Chih-Hung Hsieh | f43b02c | 2018-12-20 15:45:56 -0800 | [diff] [blame] | 1018 | explicit PooledInputEventFactory(size_t maxPoolSize = 20); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1019 | virtual ~PooledInputEventFactory(); |
| 1020 | |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 1021 | virtual KeyEvent* createKeyEvent() override; |
| 1022 | virtual MotionEvent* createMotionEvent() override; |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 1023 | virtual FocusEvent* createFocusEvent() override; |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 1024 | virtual CaptureEvent* createCaptureEvent() override; |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 1025 | virtual DragEvent* createDragEvent() override; |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 1026 | virtual TouchModeEvent* createTouchModeEvent() override; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1027 | |
| 1028 | void recycle(InputEvent* event); |
| 1029 | |
| 1030 | private: |
| 1031 | const size_t mMaxPoolSize; |
| 1032 | |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 1033 | std::queue<std::unique_ptr<KeyEvent>> mKeyEventPool; |
| 1034 | std::queue<std::unique_ptr<MotionEvent>> mMotionEventPool; |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 1035 | std::queue<std::unique_ptr<FocusEvent>> mFocusEventPool; |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 1036 | std::queue<std::unique_ptr<CaptureEvent>> mCaptureEventPool; |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 1037 | std::queue<std::unique_ptr<DragEvent>> mDragEventPool; |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 1038 | std::queue<std::unique_ptr<TouchModeEvent>> mTouchModeEventPool; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1039 | }; |
| 1040 | |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 1041 | /* |
| 1042 | * Describes a unique request to enable or disable Pointer Capture. |
| 1043 | */ |
| 1044 | struct PointerCaptureRequest { |
| 1045 | public: |
| 1046 | inline PointerCaptureRequest() : enable(false), seq(0) {} |
| 1047 | inline PointerCaptureRequest(bool enable, uint32_t seq) : enable(enable), seq(seq) {} |
| 1048 | inline bool operator==(const PointerCaptureRequest& other) const { |
| 1049 | return enable == other.enable && seq == other.seq; |
| 1050 | } |
| 1051 | explicit inline operator bool() const { return enable; } |
| 1052 | |
| 1053 | // True iff this is a request to enable Pointer Capture. |
| 1054 | bool enable; |
| 1055 | |
| 1056 | // The sequence number for the request. |
| 1057 | uint32_t seq; |
| 1058 | }; |
| 1059 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1060 | } // namespace android |
| 1061 | |
| 1062 | #endif // _LIBINPUT_INPUT_H |