Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 18 | |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 21 | #include "CursorButtonAccumulator.h" |
| 22 | #include "CursorScrollAccumulator.h" |
| 23 | #include "EventHub.h" |
| 24 | #include "InputMapper.h" |
| 25 | #include "InputReaderBase.h" |
| 26 | #include "TouchButtonAccumulator.h" |
| 27 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | |
| 30 | /* Raw axis information from the driver. */ |
| 31 | struct RawPointerAxes { |
| 32 | RawAbsoluteAxisInfo x; |
| 33 | RawAbsoluteAxisInfo y; |
| 34 | RawAbsoluteAxisInfo pressure; |
| 35 | RawAbsoluteAxisInfo touchMajor; |
| 36 | RawAbsoluteAxisInfo touchMinor; |
| 37 | RawAbsoluteAxisInfo toolMajor; |
| 38 | RawAbsoluteAxisInfo toolMinor; |
| 39 | RawAbsoluteAxisInfo orientation; |
| 40 | RawAbsoluteAxisInfo distance; |
| 41 | RawAbsoluteAxisInfo tiltX; |
| 42 | RawAbsoluteAxisInfo tiltY; |
| 43 | RawAbsoluteAxisInfo trackingId; |
| 44 | RawAbsoluteAxisInfo slot; |
| 45 | |
| 46 | RawPointerAxes(); |
| 47 | inline int32_t getRawWidth() const { return x.maxValue - x.minValue + 1; } |
| 48 | inline int32_t getRawHeight() const { return y.maxValue - y.minValue + 1; } |
| 49 | void clear(); |
| 50 | }; |
| 51 | |
| 52 | /* Raw data for a collection of pointers including a pointer id mapping table. */ |
| 53 | struct RawPointerData { |
| 54 | struct Pointer { |
| 55 | uint32_t id; |
| 56 | int32_t x; |
| 57 | int32_t y; |
| 58 | int32_t pressure; |
| 59 | int32_t touchMajor; |
| 60 | int32_t touchMinor; |
| 61 | int32_t toolMajor; |
| 62 | int32_t toolMinor; |
| 63 | int32_t orientation; |
| 64 | int32_t distance; |
| 65 | int32_t tiltX; |
| 66 | int32_t tiltY; |
| 67 | int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant |
| 68 | bool isHovering; |
| 69 | }; |
| 70 | |
| 71 | uint32_t pointerCount; |
| 72 | Pointer pointers[MAX_POINTERS]; |
arthurhung | cc7f980 | 2020-04-30 17:55:40 +0800 | [diff] [blame] | 73 | BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 74 | uint32_t idToIndex[MAX_POINTER_ID + 1]; |
| 75 | |
| 76 | RawPointerData(); |
| 77 | void clear(); |
| 78 | void copyFrom(const RawPointerData& other); |
| 79 | void getCentroidOfTouchingPointers(float* outX, float* outY) const; |
| 80 | |
| 81 | inline void markIdBit(uint32_t id, bool isHovering) { |
| 82 | if (isHovering) { |
| 83 | hoveringIdBits.markBit(id); |
| 84 | } else { |
| 85 | touchingIdBits.markBit(id); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | inline void clearIdBits() { |
| 90 | hoveringIdBits.clear(); |
| 91 | touchingIdBits.clear(); |
arthurhung | cc7f980 | 2020-04-30 17:55:40 +0800 | [diff] [blame] | 92 | canceledIdBits.clear(); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | inline const Pointer& pointerForId(uint32_t id) const { return pointers[idToIndex[id]]; } |
| 96 | |
| 97 | inline bool isHovering(uint32_t pointerIndex) { return pointers[pointerIndex].isHovering; } |
| 98 | }; |
| 99 | |
| 100 | /* Cooked data for a collection of pointers including a pointer id mapping table. */ |
| 101 | struct CookedPointerData { |
| 102 | uint32_t pointerCount; |
| 103 | PointerProperties pointerProperties[MAX_POINTERS]; |
| 104 | PointerCoords pointerCoords[MAX_POINTERS]; |
Nathaniel R. Lewis | adb58ea | 2019-08-21 04:46:29 +0000 | [diff] [blame] | 105 | BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits, validIdBits; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 106 | uint32_t idToIndex[MAX_POINTER_ID + 1]; |
| 107 | |
| 108 | CookedPointerData(); |
| 109 | void clear(); |
| 110 | void copyFrom(const CookedPointerData& other); |
| 111 | |
| 112 | inline const PointerCoords& pointerCoordsForId(uint32_t id) const { |
| 113 | return pointerCoords[idToIndex[id]]; |
| 114 | } |
| 115 | |
| 116 | inline PointerCoords& editPointerCoordsWithId(uint32_t id) { |
| 117 | return pointerCoords[idToIndex[id]]; |
| 118 | } |
| 119 | |
| 120 | inline PointerProperties& editPointerPropertiesWithId(uint32_t id) { |
| 121 | return pointerProperties[idToIndex[id]]; |
| 122 | } |
| 123 | |
| 124 | inline bool isHovering(uint32_t pointerIndex) const { |
| 125 | return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id); |
| 126 | } |
| 127 | |
| 128 | inline bool isTouching(uint32_t pointerIndex) const { |
| 129 | return touchingIdBits.hasBit(pointerProperties[pointerIndex].id); |
| 130 | } |
Nathaniel R. Lewis | adb58ea | 2019-08-21 04:46:29 +0000 | [diff] [blame] | 131 | |
| 132 | inline bool hasPointerCoordsForId(uint32_t id) const { return validIdBits.hasBit(id); } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | class TouchInputMapper : public InputMapper { |
| 136 | public: |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 137 | explicit TouchInputMapper(InputDeviceContext& deviceContext); |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 138 | ~TouchInputMapper() override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 139 | |
Philip Junker | 4af3b3d | 2021-12-14 10:36:55 +0100 | [diff] [blame] | 140 | uint32_t getSources() const override; |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 141 | void populateDeviceInfo(InputDeviceInfo* deviceInfo) override; |
| 142 | void dump(std::string& dump) override; |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 143 | [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when, |
| 144 | const InputReaderConfiguration* config, |
| 145 | uint32_t changes) override; |
| 146 | [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; |
| 147 | [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 148 | |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 149 | int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) override; |
| 150 | int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override; |
Siarhei Vishniakou | 7400794 | 2022-06-13 13:57:47 -0700 | [diff] [blame] | 151 | bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes, |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 152 | uint8_t* outFlags) override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 153 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 154 | [[nodiscard]] std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime) override; |
| 155 | [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when) override; |
| 156 | [[nodiscard]] std::list<NotifyArgs> updateExternalStylusState( |
| 157 | const StylusState& state) override; |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 158 | std::optional<int32_t> getAssociatedDisplayId() override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 159 | |
| 160 | protected: |
| 161 | CursorButtonAccumulator mCursorButtonAccumulator; |
| 162 | CursorScrollAccumulator mCursorScrollAccumulator; |
| 163 | TouchButtonAccumulator mTouchButtonAccumulator; |
| 164 | |
| 165 | struct VirtualKey { |
| 166 | int32_t keyCode; |
| 167 | int32_t scanCode; |
| 168 | uint32_t flags; |
| 169 | |
| 170 | // computed hit box, specified in touch screen coords based on known display size |
| 171 | int32_t hitLeft; |
| 172 | int32_t hitTop; |
| 173 | int32_t hitRight; |
| 174 | int32_t hitBottom; |
| 175 | |
| 176 | inline bool isHit(int32_t x, int32_t y) const { |
| 177 | return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom; |
| 178 | } |
| 179 | }; |
| 180 | |
| 181 | // Input sources and device mode. |
| 182 | uint32_t mSource; |
| 183 | |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 184 | enum class DeviceMode { |
| 185 | DISABLED, // input is disabled |
| 186 | DIRECT, // direct mapping (touchscreen) |
| 187 | UNSCALED, // unscaled mapping (touchpad) |
| 188 | NAVIGATION, // unscaled mapping with assist gesture (touch navigation) |
| 189 | POINTER, // pointer mapping (pointer) |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 190 | |
| 191 | ftl_last = POINTER |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 192 | }; |
| 193 | DeviceMode mDeviceMode; |
| 194 | |
| 195 | // The reader's configuration. |
| 196 | InputReaderConfiguration mConfig; |
| 197 | |
| 198 | // Immutable configuration parameters. |
| 199 | struct Parameters { |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 200 | enum class DeviceType { |
| 201 | TOUCH_SCREEN, |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 202 | TOUCH_NAVIGATION, |
| 203 | POINTER, |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 204 | |
| 205 | ftl_last = POINTER |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | DeviceType deviceType; |
| 209 | bool hasAssociatedDisplay; |
| 210 | bool associatedDisplayIsExternal; |
| 211 | bool orientationAware; |
Prabir Pradhan | ac1c74f | 2021-08-20 16:09:32 -0700 | [diff] [blame] | 212 | |
| 213 | enum class Orientation : int32_t { |
| 214 | ORIENTATION_0 = DISPLAY_ORIENTATION_0, |
| 215 | ORIENTATION_90 = DISPLAY_ORIENTATION_90, |
| 216 | ORIENTATION_180 = DISPLAY_ORIENTATION_180, |
| 217 | ORIENTATION_270 = DISPLAY_ORIENTATION_270, |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 218 | |
| 219 | ftl_last = ORIENTATION_270 |
Prabir Pradhan | ac1c74f | 2021-08-20 16:09:32 -0700 | [diff] [blame] | 220 | }; |
| 221 | Orientation orientation; |
| 222 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 223 | bool hasButtonUnderPad; |
| 224 | std::string uniqueDisplayId; |
| 225 | |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 226 | enum class GestureMode { |
| 227 | SINGLE_TOUCH, |
| 228 | MULTI_TOUCH, |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 229 | |
| 230 | ftl_last = MULTI_TOUCH |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 231 | }; |
| 232 | GestureMode gestureMode; |
| 233 | |
| 234 | bool wake; |
| 235 | } mParameters; |
| 236 | |
| 237 | // Immutable calibration parameters in parsed form. |
| 238 | struct Calibration { |
| 239 | // Size |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 240 | enum class SizeCalibration { |
| 241 | DEFAULT, |
| 242 | NONE, |
| 243 | GEOMETRIC, |
| 244 | DIAMETER, |
| 245 | BOX, |
| 246 | AREA, |
Siarhei Vishniakou | 4e837cc | 2021-12-20 23:24:33 -0800 | [diff] [blame] | 247 | ftl_last = AREA |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | SizeCalibration sizeCalibration; |
| 251 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 252 | std::optional<float> sizeScale; |
| 253 | std::optional<float> sizeBias; |
| 254 | std::optional<bool> sizeIsSummed; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 255 | |
| 256 | // Pressure |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 257 | enum class PressureCalibration { |
| 258 | DEFAULT, |
| 259 | NONE, |
| 260 | PHYSICAL, |
| 261 | AMPLITUDE, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | PressureCalibration pressureCalibration; |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 265 | std::optional<float> pressureScale; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 266 | |
| 267 | // Orientation |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 268 | enum class OrientationCalibration { |
| 269 | DEFAULT, |
| 270 | NONE, |
| 271 | INTERPOLATED, |
| 272 | VECTOR, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | OrientationCalibration orientationCalibration; |
| 276 | |
| 277 | // Distance |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 278 | enum class DistanceCalibration { |
| 279 | DEFAULT, |
| 280 | NONE, |
| 281 | SCALED, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 282 | }; |
| 283 | |
| 284 | DistanceCalibration distanceCalibration; |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 285 | std::optional<float> distanceScale; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 286 | |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 287 | enum class CoverageCalibration { |
| 288 | DEFAULT, |
| 289 | NONE, |
| 290 | BOX, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
| 293 | CoverageCalibration coverageCalibration; |
| 294 | |
Siarhei Vishniakou | 0724734 | 2022-07-15 14:27:37 -0700 | [diff] [blame] | 295 | inline void applySizeScaleAndBias(float& outSize) const { |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 296 | if (sizeScale) { |
Siarhei Vishniakou | 0724734 | 2022-07-15 14:27:37 -0700 | [diff] [blame] | 297 | outSize *= *sizeScale; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 298 | } |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 299 | if (sizeBias) { |
Siarhei Vishniakou | 0724734 | 2022-07-15 14:27:37 -0700 | [diff] [blame] | 300 | outSize += *sizeBias; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 301 | } |
Siarhei Vishniakou | 0724734 | 2022-07-15 14:27:37 -0700 | [diff] [blame] | 302 | if (outSize < 0) { |
| 303 | outSize = 0; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | } mCalibration; |
| 307 | |
| 308 | // Affine location transformation/calibration |
| 309 | struct TouchAffineTransformation mAffineTransform; |
| 310 | |
| 311 | RawPointerAxes mRawPointerAxes; |
| 312 | |
| 313 | struct RawState { |
| 314 | nsecs_t when; |
Siarhei Vishniakou | 58ba3d1 | 2021-02-11 01:31:07 +0000 | [diff] [blame] | 315 | nsecs_t readTime; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 316 | |
| 317 | // Raw pointer sample data. |
| 318 | RawPointerData rawPointerData; |
| 319 | |
| 320 | int32_t buttonState; |
| 321 | |
| 322 | // Scroll state. |
| 323 | int32_t rawVScroll; |
| 324 | int32_t rawHScroll; |
| 325 | |
Prabir Pradhan | afabcde | 2022-09-27 19:32:43 +0000 | [diff] [blame] | 326 | explicit inline RawState() { clear(); } |
| 327 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 328 | void copyFrom(const RawState& other) { |
| 329 | when = other.when; |
Siarhei Vishniakou | 58ba3d1 | 2021-02-11 01:31:07 +0000 | [diff] [blame] | 330 | readTime = other.readTime; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 331 | rawPointerData.copyFrom(other.rawPointerData); |
| 332 | buttonState = other.buttonState; |
| 333 | rawVScroll = other.rawVScroll; |
| 334 | rawHScroll = other.rawHScroll; |
| 335 | } |
| 336 | |
| 337 | void clear() { |
| 338 | when = 0; |
Siarhei Vishniakou | 58ba3d1 | 2021-02-11 01:31:07 +0000 | [diff] [blame] | 339 | readTime = 0; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 340 | rawPointerData.clear(); |
| 341 | buttonState = 0; |
| 342 | rawVScroll = 0; |
| 343 | rawHScroll = 0; |
| 344 | } |
| 345 | }; |
| 346 | |
| 347 | struct CookedState { |
| 348 | // Cooked pointer sample data. |
| 349 | CookedPointerData cookedPointerData; |
| 350 | |
| 351 | // Id bits used to differentiate fingers, stylus and mouse tools. |
| 352 | BitSet32 fingerIdBits; |
| 353 | BitSet32 stylusIdBits; |
| 354 | BitSet32 mouseIdBits; |
| 355 | |
| 356 | int32_t buttonState; |
| 357 | |
| 358 | void copyFrom(const CookedState& other) { |
| 359 | cookedPointerData.copyFrom(other.cookedPointerData); |
| 360 | fingerIdBits = other.fingerIdBits; |
| 361 | stylusIdBits = other.stylusIdBits; |
| 362 | mouseIdBits = other.mouseIdBits; |
| 363 | buttonState = other.buttonState; |
| 364 | } |
| 365 | |
| 366 | void clear() { |
| 367 | cookedPointerData.clear(); |
| 368 | fingerIdBits.clear(); |
| 369 | stylusIdBits.clear(); |
| 370 | mouseIdBits.clear(); |
| 371 | buttonState = 0; |
| 372 | } |
| 373 | }; |
| 374 | |
| 375 | std::vector<RawState> mRawStatesPending; |
| 376 | RawState mCurrentRawState; |
| 377 | CookedState mCurrentCookedState; |
| 378 | RawState mLastRawState; |
| 379 | CookedState mLastCookedState; |
| 380 | |
| 381 | // State provided by an external stylus |
| 382 | StylusState mExternalStylusState; |
| 383 | int64_t mExternalStylusId; |
| 384 | nsecs_t mExternalStylusFusionTimeout; |
| 385 | bool mExternalStylusDataPending; |
| 386 | |
| 387 | // True if we sent a HOVER_ENTER event. |
| 388 | bool mSentHoverEnter; |
| 389 | |
| 390 | // Have we assigned pointer IDs for this stream |
| 391 | bool mHavePointerIds; |
| 392 | |
| 393 | // Is the current stream of direct touch events aborted |
| 394 | bool mCurrentMotionAborted; |
| 395 | |
| 396 | // The time the primary pointer last went down. |
| 397 | nsecs_t mDownTime; |
| 398 | |
| 399 | // The pointer controller, or null if the device is not a pointer. |
Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 400 | std::shared_ptr<PointerControllerInterface> mPointerController; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 401 | |
| 402 | std::vector<VirtualKey> mVirtualKeys; |
| 403 | |
| 404 | virtual void configureParameters(); |
| 405 | virtual void dumpParameters(std::string& dump); |
| 406 | virtual void configureRawPointerAxes(); |
| 407 | virtual void dumpRawPointerAxes(std::string& dump); |
Prabir Pradhan | 1728b21 | 2021-10-19 16:00:03 -0700 | [diff] [blame] | 408 | virtual void configureInputDevice(nsecs_t when, bool* outResetNeeded); |
| 409 | virtual void dumpDisplay(std::string& dump); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 410 | virtual void configureVirtualKeys(); |
| 411 | virtual void dumpVirtualKeys(std::string& dump); |
| 412 | virtual void parseCalibration(); |
| 413 | virtual void resolveCalibration(); |
| 414 | virtual void dumpCalibration(std::string& dump); |
| 415 | virtual void updateAffineTransformation(); |
| 416 | virtual void dumpAffineTransformation(std::string& dump); |
| 417 | virtual void resolveExternalStylusPresence(); |
| 418 | virtual bool hasStylus() const = 0; |
| 419 | virtual bool hasExternalStylus() const; |
| 420 | |
| 421 | virtual void syncTouch(nsecs_t when, RawState* outState) = 0; |
| 422 | |
| 423 | private: |
| 424 | // The current viewport. |
| 425 | // The components of the viewport are specified in the display's rotated orientation. |
| 426 | DisplayViewport mViewport; |
| 427 | |
Prabir Pradhan | 1728b21 | 2021-10-19 16:00:03 -0700 | [diff] [blame] | 428 | // The width and height are obtained from the viewport and are specified |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 429 | // in the natural orientation. |
Prabir Pradhan | 1728b21 | 2021-10-19 16:00:03 -0700 | [diff] [blame] | 430 | int32_t mDisplayWidth; |
| 431 | int32_t mDisplayHeight; |
Arthur Hung | 4197f6b | 2020-03-16 15:39:59 +0800 | [diff] [blame] | 432 | |
Prabir Pradhan | 1728b21 | 2021-10-19 16:00:03 -0700 | [diff] [blame] | 433 | // The physical frame is the rectangle in the display's coordinate space that maps to the |
| 434 | // the logical display frame. |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 435 | int32_t mPhysicalWidth; |
| 436 | int32_t mPhysicalHeight; |
| 437 | int32_t mPhysicalLeft; |
| 438 | int32_t mPhysicalTop; |
| 439 | |
Prabir Pradhan | 1728b21 | 2021-10-19 16:00:03 -0700 | [diff] [blame] | 440 | // The orientation of the input device relative to that of the display panel. It specifies |
| 441 | // the rotation of the input device coordinates required to produce the display panel |
| 442 | // orientation, so it will depend on whether the device is orientation aware. |
| 443 | int32_t mInputDeviceOrientation; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 444 | |
| 445 | // Translation and scaling factors, orientation-independent. |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 446 | float mXScale; |
| 447 | float mXPrecision; |
| 448 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 449 | float mYScale; |
| 450 | float mYPrecision; |
| 451 | |
| 452 | float mGeometricScale; |
| 453 | |
| 454 | float mPressureScale; |
| 455 | |
| 456 | float mSizeScale; |
| 457 | |
| 458 | float mOrientationScale; |
| 459 | |
| 460 | float mDistanceScale; |
| 461 | |
| 462 | bool mHaveTilt; |
| 463 | float mTiltXCenter; |
| 464 | float mTiltXScale; |
| 465 | float mTiltYCenter; |
| 466 | float mTiltYScale; |
| 467 | |
| 468 | bool mExternalStylusConnected; |
| 469 | |
| 470 | // Oriented motion ranges for input device info. |
| 471 | struct OrientedRanges { |
| 472 | InputDeviceInfo::MotionRange x; |
| 473 | InputDeviceInfo::MotionRange y; |
| 474 | InputDeviceInfo::MotionRange pressure; |
| 475 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 476 | std::optional<InputDeviceInfo::MotionRange> size; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 477 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 478 | std::optional<InputDeviceInfo::MotionRange> touchMajor; |
| 479 | std::optional<InputDeviceInfo::MotionRange> touchMinor; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 480 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 481 | std::optional<InputDeviceInfo::MotionRange> toolMajor; |
| 482 | std::optional<InputDeviceInfo::MotionRange> toolMinor; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 483 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 484 | std::optional<InputDeviceInfo::MotionRange> orientation; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 485 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 486 | std::optional<InputDeviceInfo::MotionRange> distance; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 487 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 488 | std::optional<InputDeviceInfo::MotionRange> tilt; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 489 | |
| 490 | void clear() { |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 491 | size = std::nullopt; |
| 492 | touchMajor = std::nullopt; |
| 493 | touchMinor = std::nullopt; |
| 494 | toolMajor = std::nullopt; |
| 495 | toolMinor = std::nullopt; |
| 496 | orientation = std::nullopt; |
| 497 | distance = std::nullopt; |
| 498 | tilt = std::nullopt; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 499 | } |
| 500 | } mOrientedRanges; |
| 501 | |
| 502 | // Oriented dimensions and precision. |
| 503 | float mOrientedXPrecision; |
| 504 | float mOrientedYPrecision; |
| 505 | |
| 506 | struct CurrentVirtualKeyState { |
| 507 | bool down; |
| 508 | bool ignored; |
| 509 | nsecs_t downTime; |
| 510 | int32_t keyCode; |
| 511 | int32_t scanCode; |
| 512 | } mCurrentVirtualKey; |
| 513 | |
| 514 | // Scale factor for gesture or mouse based pointer movements. |
| 515 | float mPointerXMovementScale; |
| 516 | float mPointerYMovementScale; |
| 517 | |
| 518 | // Scale factor for gesture based zooming and other freeform motions. |
| 519 | float mPointerXZoomScale; |
| 520 | float mPointerYZoomScale; |
| 521 | |
HQ Liu | e6983c7 | 2022-04-19 22:14:56 +0000 | [diff] [blame] | 522 | // The maximum swipe width between pointers to detect a swipe gesture |
| 523 | // in the number of pixels.Touches that are wider than this are translated |
| 524 | // into freeform gestures. |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 525 | float mPointerGestureMaxSwipeWidth; |
| 526 | |
| 527 | struct PointerDistanceHeapElement { |
| 528 | uint32_t currentPointerIndex : 8; |
| 529 | uint32_t lastPointerIndex : 8; |
| 530 | uint64_t distance : 48; // squared distance |
| 531 | }; |
| 532 | |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 533 | enum class PointerUsage { |
| 534 | NONE, |
| 535 | GESTURES, |
| 536 | STYLUS, |
| 537 | MOUSE, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 538 | }; |
| 539 | PointerUsage mPointerUsage; |
| 540 | |
| 541 | struct PointerGesture { |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 542 | enum class Mode { |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 543 | // No fingers, button is not pressed. |
| 544 | // Nothing happening. |
| 545 | NEUTRAL, |
| 546 | |
| 547 | // No fingers, button is not pressed. |
| 548 | // Tap detected. |
| 549 | // Emits DOWN and UP events at the pointer location. |
| 550 | TAP, |
| 551 | |
| 552 | // Exactly one finger dragging following a tap. |
| 553 | // Pointer follows the active finger. |
| 554 | // Emits DOWN, MOVE and UP events at the pointer location. |
| 555 | // |
| 556 | // Detect double-taps when the finger goes up while in TAP_DRAG mode. |
| 557 | TAP_DRAG, |
| 558 | |
| 559 | // Button is pressed. |
| 560 | // Pointer follows the active finger if there is one. Other fingers are ignored. |
| 561 | // Emits DOWN, MOVE and UP events at the pointer location. |
| 562 | BUTTON_CLICK_OR_DRAG, |
| 563 | |
| 564 | // Exactly one finger, button is not pressed. |
| 565 | // Pointer follows the active finger. |
| 566 | // Emits HOVER_MOVE events at the pointer location. |
| 567 | // |
| 568 | // Detect taps when the finger goes up while in HOVER mode. |
| 569 | HOVER, |
| 570 | |
| 571 | // Exactly two fingers but neither have moved enough to clearly indicate |
| 572 | // whether a swipe or freeform gesture was intended. We consider the |
| 573 | // pointer to be pressed so this enables clicking or long-pressing on buttons. |
| 574 | // Pointer does not move. |
| 575 | // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate. |
| 576 | PRESS, |
| 577 | |
| 578 | // Exactly two fingers moving in the same direction, button is not pressed. |
| 579 | // Pointer does not move. |
| 580 | // Emits DOWN, MOVE and UP events with a single pointer coordinate that |
| 581 | // follows the midpoint between both fingers. |
| 582 | SWIPE, |
| 583 | |
| 584 | // Two or more fingers moving in arbitrary directions, button is not pressed. |
| 585 | // Pointer does not move. |
| 586 | // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow |
| 587 | // each finger individually relative to the initial centroid of the finger. |
| 588 | FREEFORM, |
| 589 | |
| 590 | // Waiting for quiet time to end before starting the next gesture. |
| 591 | QUIET, |
| 592 | }; |
| 593 | |
Prabir Pradhan | 47cf0a0 | 2021-03-11 20:30:57 -0800 | [diff] [blame] | 594 | // When a gesture is sent to an unfocused window, return true if it can bring that window |
| 595 | // into focus, false otherwise. |
| 596 | static bool canGestureAffectWindowFocus(Mode mode) { |
| 597 | switch (mode) { |
| 598 | case Mode::TAP: |
| 599 | case Mode::TAP_DRAG: |
| 600 | case Mode::BUTTON_CLICK_OR_DRAG: |
| 601 | // Taps can affect window focus. |
| 602 | return true; |
| 603 | case Mode::FREEFORM: |
| 604 | case Mode::HOVER: |
| 605 | case Mode::NEUTRAL: |
| 606 | case Mode::PRESS: |
| 607 | case Mode::QUIET: |
| 608 | case Mode::SWIPE: |
| 609 | // Most gestures can be performed on an unfocused window, so they should not |
| 610 | // not affect window focus. |
| 611 | return false; |
| 612 | } |
| 613 | } |
| 614 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 615 | // Time the first finger went down. |
| 616 | nsecs_t firstTouchTime; |
| 617 | |
| 618 | // The active pointer id from the raw touch data. |
| 619 | int32_t activeTouchId; // -1 if none |
| 620 | |
| 621 | // The active pointer id from the gesture last delivered to the application. |
| 622 | int32_t activeGestureId; // -1 if none |
| 623 | |
| 624 | // Pointer coords and ids for the current and previous pointer gesture. |
| 625 | Mode currentGestureMode; |
| 626 | BitSet32 currentGestureIdBits; |
| 627 | uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1]; |
| 628 | PointerProperties currentGestureProperties[MAX_POINTERS]; |
| 629 | PointerCoords currentGestureCoords[MAX_POINTERS]; |
| 630 | |
| 631 | Mode lastGestureMode; |
| 632 | BitSet32 lastGestureIdBits; |
| 633 | uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1]; |
| 634 | PointerProperties lastGestureProperties[MAX_POINTERS]; |
| 635 | PointerCoords lastGestureCoords[MAX_POINTERS]; |
| 636 | |
| 637 | // Time the pointer gesture last went down. |
| 638 | nsecs_t downTime; |
| 639 | |
| 640 | // Time when the pointer went down for a TAP. |
| 641 | nsecs_t tapDownTime; |
| 642 | |
| 643 | // Time when the pointer went up for a TAP. |
| 644 | nsecs_t tapUpTime; |
| 645 | |
| 646 | // Location of initial tap. |
| 647 | float tapX, tapY; |
| 648 | |
| 649 | // Time we started waiting for quiescence. |
| 650 | nsecs_t quietTime; |
| 651 | |
| 652 | // Reference points for multitouch gestures. |
| 653 | float referenceTouchX; // reference touch X/Y coordinates in surface units |
| 654 | float referenceTouchY; |
| 655 | float referenceGestureX; // reference gesture X/Y coordinates in pixels |
| 656 | float referenceGestureY; |
| 657 | |
| 658 | // Distance that each pointer has traveled which has not yet been |
| 659 | // subsumed into the reference gesture position. |
| 660 | BitSet32 referenceIdBits; |
| 661 | struct Delta { |
| 662 | float dx, dy; |
| 663 | }; |
| 664 | Delta referenceDeltas[MAX_POINTER_ID + 1]; |
| 665 | |
| 666 | // Describes how touch ids are mapped to gesture ids for freeform gestures. |
| 667 | uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1]; |
| 668 | |
| 669 | // A velocity tracker for determining whether to switch active pointers during drags. |
| 670 | VelocityTracker velocityTracker; |
| 671 | |
| 672 | void reset() { |
| 673 | firstTouchTime = LLONG_MIN; |
| 674 | activeTouchId = -1; |
| 675 | activeGestureId = -1; |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 676 | currentGestureMode = Mode::NEUTRAL; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 677 | currentGestureIdBits.clear(); |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 678 | lastGestureMode = Mode::NEUTRAL; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 679 | lastGestureIdBits.clear(); |
| 680 | downTime = 0; |
| 681 | velocityTracker.clear(); |
| 682 | resetTap(); |
| 683 | resetQuietTime(); |
| 684 | } |
| 685 | |
| 686 | void resetTap() { |
| 687 | tapDownTime = LLONG_MIN; |
| 688 | tapUpTime = LLONG_MIN; |
| 689 | } |
| 690 | |
| 691 | void resetQuietTime() { quietTime = LLONG_MIN; } |
| 692 | } mPointerGesture; |
| 693 | |
| 694 | struct PointerSimple { |
| 695 | PointerCoords currentCoords; |
| 696 | PointerProperties currentProperties; |
| 697 | PointerCoords lastCoords; |
| 698 | PointerProperties lastProperties; |
| 699 | |
| 700 | // True if the pointer is down. |
| 701 | bool down; |
| 702 | |
| 703 | // True if the pointer is hovering. |
| 704 | bool hovering; |
| 705 | |
| 706 | // Time the pointer last went down. |
| 707 | nsecs_t downTime; |
| 708 | |
| 709 | void reset() { |
| 710 | currentCoords.clear(); |
| 711 | currentProperties.clear(); |
| 712 | lastCoords.clear(); |
| 713 | lastProperties.clear(); |
| 714 | down = false; |
| 715 | hovering = false; |
| 716 | downTime = 0; |
| 717 | } |
| 718 | } mPointerSimple; |
| 719 | |
| 720 | // The pointer and scroll velocity controls. |
| 721 | VelocityControl mPointerVelocityControl; |
| 722 | VelocityControl mWheelXVelocityControl; |
| 723 | VelocityControl mWheelYVelocityControl; |
| 724 | |
| 725 | std::optional<DisplayViewport> findViewport(); |
| 726 | |
| 727 | void resetExternalStylus(); |
| 728 | void clearStylusDataPendingFlags(); |
| 729 | |
Siarhei Vishniakou | 12c0fcb | 2021-12-17 13:40:44 -0800 | [diff] [blame] | 730 | int32_t clampResolution(const char* axisName, int32_t resolution) const; |
Siarhei Vishniakou | 4e837cc | 2021-12-20 23:24:33 -0800 | [diff] [blame] | 731 | void initializeOrientedRanges(); |
| 732 | void initializeSizeRanges(); |
| 733 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 734 | [[nodiscard]] std::list<NotifyArgs> sync(nsecs_t when, nsecs_t readTime); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 735 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 736 | [[nodiscard]] std::list<NotifyArgs> consumeRawTouches(nsecs_t when, nsecs_t readTime, |
| 737 | uint32_t policyFlags, bool& outConsumed); |
| 738 | [[nodiscard]] std::list<NotifyArgs> processRawTouches(bool timeout); |
| 739 | [[nodiscard]] std::list<NotifyArgs> cookAndDispatch(nsecs_t when, nsecs_t readTime); |
| 740 | [[nodiscard]] NotifyKeyArgs dispatchVirtualKey(nsecs_t when, nsecs_t readTime, |
| 741 | uint32_t policyFlags, int32_t keyEventAction, |
| 742 | int32_t keyEventFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 743 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 744 | [[nodiscard]] std::list<NotifyArgs> dispatchTouches(nsecs_t when, nsecs_t readTime, |
| 745 | uint32_t policyFlags); |
| 746 | [[nodiscard]] std::list<NotifyArgs> dispatchHoverExit(nsecs_t when, nsecs_t readTime, |
| 747 | uint32_t policyFlags); |
| 748 | [[nodiscard]] std::list<NotifyArgs> dispatchHoverEnterAndMove(nsecs_t when, nsecs_t readTime, |
| 749 | uint32_t policyFlags); |
| 750 | [[nodiscard]] std::list<NotifyArgs> dispatchButtonRelease(nsecs_t when, nsecs_t readTime, |
| 751 | uint32_t policyFlags); |
| 752 | [[nodiscard]] std::list<NotifyArgs> dispatchButtonPress(nsecs_t when, nsecs_t readTime, |
| 753 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 754 | const BitSet32& findActiveIdBits(const CookedPointerData& cookedPointerData); |
| 755 | void cookPointerData(); |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 756 | [[nodiscard]] std::list<NotifyArgs> abortTouches(nsecs_t when, nsecs_t readTime, |
| 757 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 758 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 759 | [[nodiscard]] std::list<NotifyArgs> dispatchPointerUsage(nsecs_t when, nsecs_t readTime, |
| 760 | uint32_t policyFlags, |
| 761 | PointerUsage pointerUsage); |
| 762 | [[nodiscard]] std::list<NotifyArgs> abortPointerUsage(nsecs_t when, nsecs_t readTime, |
| 763 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 764 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 765 | [[nodiscard]] std::list<NotifyArgs> dispatchPointerGestures(nsecs_t when, nsecs_t readTime, |
| 766 | uint32_t policyFlags, |
| 767 | bool isTimeout); |
| 768 | [[nodiscard]] std::list<NotifyArgs> abortPointerGestures(nsecs_t when, nsecs_t readTime, |
| 769 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 770 | bool preparePointerGestures(nsecs_t when, bool* outCancelPreviousGesture, |
| 771 | bool* outFinishPreviousGesture, bool isTimeout); |
| 772 | |
Harry Cutts | 714d1ad | 2022-08-24 16:36:43 +0000 | [diff] [blame] | 773 | // Moves the on-screen mouse pointer based on the movement of the pointer of the given ID |
| 774 | // between the last and current events. Uses a relative motion. |
| 775 | void moveMousePointerFromPointerDelta(nsecs_t when, uint32_t pointerId); |
| 776 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 777 | [[nodiscard]] std::list<NotifyArgs> dispatchPointerStylus(nsecs_t when, nsecs_t readTime, |
| 778 | uint32_t policyFlags); |
| 779 | [[nodiscard]] std::list<NotifyArgs> abortPointerStylus(nsecs_t when, nsecs_t readTime, |
| 780 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 781 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 782 | [[nodiscard]] std::list<NotifyArgs> dispatchPointerMouse(nsecs_t when, nsecs_t readTime, |
| 783 | uint32_t policyFlags); |
| 784 | [[nodiscard]] std::list<NotifyArgs> abortPointerMouse(nsecs_t when, nsecs_t readTime, |
| 785 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 786 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 787 | [[nodiscard]] std::list<NotifyArgs> dispatchPointerSimple(nsecs_t when, nsecs_t readTime, |
| 788 | uint32_t policyFlags, bool down, |
| 789 | bool hovering); |
| 790 | [[nodiscard]] std::list<NotifyArgs> abortPointerSimple(nsecs_t when, nsecs_t readTime, |
| 791 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 792 | |
| 793 | bool assignExternalStylusId(const RawState& state, bool timeout); |
| 794 | void applyExternalStylusButtonState(nsecs_t when); |
| 795 | void applyExternalStylusTouchState(nsecs_t when); |
| 796 | |
| 797 | // Dispatches a motion event. |
| 798 | // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the |
| 799 | // method will take care of setting the index and transmuting the action to DOWN or UP |
| 800 | // it is the first / last pointer to go down / up. |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 801 | [[nodiscard]] NotifyMotionArgs dispatchMotion( |
| 802 | nsecs_t when, nsecs_t readTime, uint32_t policyFlags, uint32_t source, int32_t action, |
| 803 | int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState, |
| 804 | int32_t edgeFlags, const PointerProperties* properties, const PointerCoords* coords, |
| 805 | const uint32_t* idToIndex, BitSet32 idBits, int32_t changedId, float xPrecision, |
| 806 | float yPrecision, nsecs_t downTime, MotionClassification classification); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 807 | |
| 808 | // Updates pointer coords and properties for pointers with specified ids that have moved. |
| 809 | // Returns true if any of them changed. |
| 810 | bool updateMovedPointers(const PointerProperties* inProperties, const PointerCoords* inCoords, |
| 811 | const uint32_t* inIdToIndex, PointerProperties* outProperties, |
| 812 | PointerCoords* outCoords, const uint32_t* outIdToIndex, |
| 813 | BitSet32 idBits) const; |
| 814 | |
Garfield Tan | c734e4f | 2021-01-15 20:01:39 -0800 | [diff] [blame] | 815 | // Returns if this touch device is a touch screen with an associated display. |
| 816 | bool isTouchScreen(); |
| 817 | // Updates touch spots if they are enabled. Should only be used when this device is a |
| 818 | // touchscreen. |
| 819 | void updateTouchSpots(); |
| 820 | |
Prabir Pradhan | 1728b21 | 2021-10-19 16:00:03 -0700 | [diff] [blame] | 821 | bool isPointInsidePhysicalFrame(int32_t x, int32_t y) const; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 822 | const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y); |
| 823 | |
Siarhei Vishniakou | 5747998 | 2021-03-03 01:32:21 +0000 | [diff] [blame] | 824 | static void assignPointerIds(const RawState& last, RawState& current); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 825 | |
| 826 | const char* modeToString(DeviceMode deviceMode); |
Prabir Pradhan | 1728b21 | 2021-10-19 16:00:03 -0700 | [diff] [blame] | 827 | void rotateAndScale(float& x, float& y) const; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 828 | }; |
| 829 | |
| 830 | } // namespace android |