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