Harry Cutts | 79cc9fa | 2022-10-28 15:32:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 19 | #include <list> |
Harry Cutts | 1f48a44 | 2022-11-15 17:38:36 +0000 | [diff] [blame] | 20 | #include <memory> |
Harry Cutts | a34de52 | 2023-06-06 15:52:54 +0000 | [diff] [blame] | 21 | #include <set> |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 22 | #include <vector> |
Harry Cutts | 1f48a44 | 2022-11-15 17:38:36 +0000 | [diff] [blame] | 23 | |
Harry Cutts | 7423554 | 2022-11-24 15:52:53 +0000 | [diff] [blame] | 24 | #include <PointerControllerInterface.h> |
Harry Cutts | bb24e27 | 2023-03-21 10:49:47 +0000 | [diff] [blame] | 25 | #include <utils/Timers.h> |
Harry Cutts | 7423554 | 2022-11-24 15:52:53 +0000 | [diff] [blame] | 26 | |
Harry Cutts | bb24e27 | 2023-03-21 10:49:47 +0000 | [diff] [blame] | 27 | #include "CapturedTouchpadEventConverter.h" |
Harry Cutts | 79cc9fa | 2022-10-28 15:32:39 +0000 | [diff] [blame] | 28 | #include "EventHub.h" |
| 29 | #include "InputDevice.h" |
| 30 | #include "InputMapper.h" |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 31 | #include "InputReaderBase.h" |
Harry Cutts | 79cc9fa | 2022-10-28 15:32:39 +0000 | [diff] [blame] | 32 | #include "NotifyArgs.h" |
Harry Cutts | bb24e27 | 2023-03-21 10:49:47 +0000 | [diff] [blame] | 33 | #include "accumulator/MultiTouchMotionAccumulator.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 34 | #include "gestures/GestureConverter.h" |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 35 | #include "gestures/HardwareStateConverter.h" |
Harry Cutts | 1b21791 | 2023-01-03 17:13:19 +0000 | [diff] [blame] | 36 | #include "gestures/PropertyProvider.h" |
Harry Cutts | 8c7cb59 | 2023-08-23 17:20:13 +0000 | [diff] [blame] | 37 | #include "gestures/TimerProvider.h" |
Harry Cutts | 1f48a44 | 2022-11-15 17:38:36 +0000 | [diff] [blame] | 38 | |
| 39 | #include "include/gestures.h" |
Harry Cutts | 79cc9fa | 2022-10-28 15:32:39 +0000 | [diff] [blame] | 40 | |
| 41 | namespace android { |
| 42 | |
| 43 | class TouchpadInputMapper : public InputMapper { |
| 44 | public: |
Arpit Singh | e08bdbd | 2023-04-26 15:20:33 +0000 | [diff] [blame] | 45 | template <class T, class... Args> |
| 46 | friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext, |
| 47 | const InputReaderConfiguration& readerConfig, |
| 48 | Args... args); |
Harry Cutts | 7423554 | 2022-11-24 15:52:53 +0000 | [diff] [blame] | 49 | ~TouchpadInputMapper(); |
Harry Cutts | 79cc9fa | 2022-10-28 15:32:39 +0000 | [diff] [blame] | 50 | |
Harry Cutts | 1f48a44 | 2022-11-15 17:38:36 +0000 | [diff] [blame] | 51 | uint32_t getSources() const override; |
Harry Cutts | d02ea10 | 2023-03-17 18:21:30 +0000 | [diff] [blame] | 52 | void populateDeviceInfo(InputDeviceInfo& deviceInfo) override; |
Harry Cutts | ea73eaa | 2023-01-16 17:55:46 +0000 | [diff] [blame] | 53 | void dump(std::string& dump) override; |
| 54 | |
Arpit Singh | 4be4eef | 2023-03-28 14:26:01 +0000 | [diff] [blame] | 55 | [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, |
Arpit Singh | ed6c3de | 2023-04-05 19:24:37 +0000 | [diff] [blame] | 56 | const InputReaderConfiguration& config, |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 57 | ConfigurationChanges changes) override; |
Harry Cutts | 1f48a44 | 2022-11-15 17:38:36 +0000 | [diff] [blame] | 58 | [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; |
Harry Cutts | a32a119 | 2024-06-04 15:10:31 +0000 | [diff] [blame] | 59 | [[nodiscard]] std::list<NotifyArgs> process(const RawEvent& rawEvent) override; |
Harry Cutts | 8c7cb59 | 2023-08-23 17:20:13 +0000 | [diff] [blame] | 60 | [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when) override; |
Harry Cutts | 1f48a44 | 2022-11-15 17:38:36 +0000 | [diff] [blame] | 61 | |
Harry Cutts | 7423554 | 2022-11-24 15:52:53 +0000 | [diff] [blame] | 62 | void consumeGesture(const Gesture* gesture); |
| 63 | |
Harry Cutts | a34de52 | 2023-06-06 15:52:54 +0000 | [diff] [blame] | 64 | // A subset of InputDeviceIdentifier used for logging metrics, to avoid storing a copy of the |
| 65 | // strings in that bigger struct. |
| 66 | using MetricsIdentifier = std::tuple<uint16_t /*busId*/, uint16_t /*vendorId*/, |
| 67 | uint16_t /*productId*/, uint16_t /*version*/>; |
| 68 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 69 | std::optional<ui::LogicalDisplayId> getAssociatedDisplayId() override; |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 70 | |
Harry Cutts | 1f48a44 | 2022-11-15 17:38:36 +0000 | [diff] [blame] | 71 | private: |
Harry Cutts | bb24e27 | 2023-03-21 10:49:47 +0000 | [diff] [blame] | 72 | void resetGestureInterpreter(nsecs_t when); |
Arpit Singh | e08bdbd | 2023-04-26 15:20:33 +0000 | [diff] [blame] | 73 | explicit TouchpadInputMapper(InputDeviceContext& deviceContext, |
| 74 | const InputReaderConfiguration& readerConfig); |
Harry Cutts | a34de52 | 2023-06-06 15:52:54 +0000 | [diff] [blame] | 75 | void updatePalmDetectionMetrics(); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 76 | [[nodiscard]] std::list<NotifyArgs> sendHardwareState(nsecs_t when, nsecs_t readTime, |
| 77 | SelfContainedHardwareState schs); |
Harry Cutts | 7423554 | 2022-11-24 15:52:53 +0000 | [diff] [blame] | 78 | [[nodiscard]] std::list<NotifyArgs> processGestures(nsecs_t when, nsecs_t readTime); |
Harry Cutts | 1f48a44 | 2022-11-15 17:38:36 +0000 | [diff] [blame] | 79 | |
| 80 | std::unique_ptr<gestures::GestureInterpreter, void (*)(gestures::GestureInterpreter*)> |
| 81 | mGestureInterpreter; |
| 82 | |
Harry Cutts | 1b21791 | 2023-01-03 17:13:19 +0000 | [diff] [blame] | 83 | PropertyProvider mPropertyProvider; |
Harry Cutts | 8c7cb59 | 2023-08-23 17:20:13 +0000 | [diff] [blame] | 84 | TimerProvider mTimerProvider; |
Harry Cutts | 1b21791 | 2023-01-03 17:13:19 +0000 | [diff] [blame] | 85 | |
Harry Cutts | bb24e27 | 2023-03-21 10:49:47 +0000 | [diff] [blame] | 86 | // The MultiTouchMotionAccumulator is shared between the HardwareStateConverter and |
| 87 | // CapturedTouchpadEventConverter, so that if the touchpad is captured or released while touches |
| 88 | // are down, the relevant converter can still benefit from the current axis values stored in the |
| 89 | // accumulator. |
| 90 | MultiTouchMotionAccumulator mMotionAccumulator; |
| 91 | |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 92 | HardwareStateConverter mStateConverter; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 93 | GestureConverter mGestureConverter; |
Harry Cutts | bb24e27 | 2023-03-21 10:49:47 +0000 | [diff] [blame] | 94 | CapturedTouchpadEventConverter mCapturedEventConverter; |
Harry Cutts | 7423554 | 2022-11-24 15:52:53 +0000 | [diff] [blame] | 95 | |
Harry Cutts | bb24e27 | 2023-03-21 10:49:47 +0000 | [diff] [blame] | 96 | bool mPointerCaptured = false; |
Harry Cutts | bb24e27 | 2023-03-21 10:49:47 +0000 | [diff] [blame] | 97 | bool mResettingInterpreter = false; |
Harry Cutts | 7423554 | 2022-11-24 15:52:53 +0000 | [diff] [blame] | 98 | std::vector<Gesture> mGesturesToProcess; |
Harry Cutts | a34de52 | 2023-06-06 15:52:54 +0000 | [diff] [blame] | 99 | |
| 100 | static MetricsIdentifier metricsIdFromInputDeviceIdentifier(const InputDeviceIdentifier& id) { |
| 101 | return std::make_tuple(id.bus, id.vendor, id.product, id.version); |
| 102 | } |
| 103 | const MetricsIdentifier mMetricsId; |
| 104 | // Tracking IDs for touches on the pad in the last evdev frame. |
| 105 | std::set<int32_t> mLastFrameTrackingIds; |
| 106 | // Tracking IDs for touches that have at some point been reported as palms by the touchpad. |
| 107 | std::set<int32_t> mPalmTrackingIds; |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 108 | |
| 109 | // The display that events generated by this mapper should target. This can be set to |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 110 | // LogicalDisplayId::INVALID to target the focused display. If there is no display target (i.e. |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 111 | // std::nullopt), all events will be ignored. |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 112 | std::optional<ui::LogicalDisplayId> mDisplayId; |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 113 | |
| 114 | nsecs_t mGestureStartTime{0}; |
Harry Cutts | 79cc9fa | 2022-10-28 15:32:39 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | } // namespace android |