blob: 8bfc159d56ae4724eef1f530c6671bfa9662384a [file] [log] [blame]
Harry Cutts79cc9fa2022-10-28 15:32:39 +00001/*
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 Cutts4fb941a2022-12-14 19:14:04 +000019#include <list>
Harry Cutts1f48a442022-11-15 17:38:36 +000020#include <memory>
Harry Cuttsa34de522023-06-06 15:52:54 +000021#include <set>
Harry Cutts47db1c72022-12-13 19:20:47 +000022#include <vector>
Harry Cutts1f48a442022-11-15 17:38:36 +000023
Harry Cutts74235542022-11-24 15:52:53 +000024#include <PointerControllerInterface.h>
Harry Cuttsbb24e272023-03-21 10:49:47 +000025#include <utils/Timers.h>
Harry Cutts74235542022-11-24 15:52:53 +000026
Harry Cuttsbb24e272023-03-21 10:49:47 +000027#include "CapturedTouchpadEventConverter.h"
Harry Cutts79cc9fa2022-10-28 15:32:39 +000028#include "EventHub.h"
29#include "InputDevice.h"
30#include "InputMapper.h"
Harry Cuttsedf6ce72023-01-04 12:15:53 +000031#include "InputReaderBase.h"
Harry Cutts79cc9fa2022-10-28 15:32:39 +000032#include "NotifyArgs.h"
Harry Cuttsbb24e272023-03-21 10:49:47 +000033#include "accumulator/MultiTouchMotionAccumulator.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000034#include "gestures/GestureConverter.h"
Harry Cutts47db1c72022-12-13 19:20:47 +000035#include "gestures/HardwareStateConverter.h"
Harry Cutts1b217912023-01-03 17:13:19 +000036#include "gestures/PropertyProvider.h"
Harry Cutts8c7cb592023-08-23 17:20:13 +000037#include "gestures/TimerProvider.h"
Harry Cutts1f48a442022-11-15 17:38:36 +000038
39#include "include/gestures.h"
Harry Cutts79cc9fa2022-10-28 15:32:39 +000040
41namespace android {
42
43class TouchpadInputMapper : public InputMapper {
44public:
Arpit Singhe08bdbd2023-04-26 15:20:33 +000045 template <class T, class... Args>
46 friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
47 const InputReaderConfiguration& readerConfig,
48 Args... args);
Harry Cutts74235542022-11-24 15:52:53 +000049 ~TouchpadInputMapper();
Harry Cutts79cc9fa2022-10-28 15:32:39 +000050
Harry Cutts1f48a442022-11-15 17:38:36 +000051 uint32_t getSources() const override;
Harry Cuttsd02ea102023-03-17 18:21:30 +000052 void populateDeviceInfo(InputDeviceInfo& deviceInfo) override;
Harry Cuttsea73eaa2023-01-16 17:55:46 +000053 void dump(std::string& dump) override;
54
Arpit Singh4be4eef2023-03-28 14:26:01 +000055 [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when,
Arpit Singhed6c3de2023-04-05 19:24:37 +000056 const InputReaderConfiguration& config,
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000057 ConfigurationChanges changes) override;
Harry Cutts1f48a442022-11-15 17:38:36 +000058 [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override;
Harry Cuttsa32a1192024-06-04 15:10:31 +000059 [[nodiscard]] std::list<NotifyArgs> process(const RawEvent& rawEvent) override;
Harry Cutts8c7cb592023-08-23 17:20:13 +000060 [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when) override;
Harry Cutts1f48a442022-11-15 17:38:36 +000061
Harry Cutts74235542022-11-24 15:52:53 +000062 void consumeGesture(const Gesture* gesture);
63
Harry Cuttsa34de522023-06-06 15:52:54 +000064 // 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 Li13bf76a2024-05-05 19:18:02 +080069 std::optional<ui::LogicalDisplayId> getAssociatedDisplayId() override;
Josep del Riod0746382023-07-29 13:18:25 +000070
Omar Abdelmonem5e70e962024-08-06 09:38:42 +000071 std::optional<HardwareProperties> getTouchpadHardwareProperties() override;
72
Harry Cutts1f48a442022-11-15 17:38:36 +000073private:
Harry Cuttsbb24e272023-03-21 10:49:47 +000074 void resetGestureInterpreter(nsecs_t when);
Arpit Singhe08bdbd2023-04-26 15:20:33 +000075 explicit TouchpadInputMapper(InputDeviceContext& deviceContext,
76 const InputReaderConfiguration& readerConfig);
Harry Cuttsa34de522023-06-06 15:52:54 +000077 void updatePalmDetectionMetrics();
Harry Cutts47db1c72022-12-13 19:20:47 +000078 [[nodiscard]] std::list<NotifyArgs> sendHardwareState(nsecs_t when, nsecs_t readTime,
79 SelfContainedHardwareState schs);
Harry Cutts74235542022-11-24 15:52:53 +000080 [[nodiscard]] std::list<NotifyArgs> processGestures(nsecs_t when, nsecs_t readTime);
Harry Cutts1f48a442022-11-15 17:38:36 +000081
82 std::unique_ptr<gestures::GestureInterpreter, void (*)(gestures::GestureInterpreter*)>
83 mGestureInterpreter;
84
Harry Cutts1b217912023-01-03 17:13:19 +000085 PropertyProvider mPropertyProvider;
Harry Cutts8c7cb592023-08-23 17:20:13 +000086 TimerProvider mTimerProvider;
Harry Cutts1b217912023-01-03 17:13:19 +000087
Harry Cuttsbb24e272023-03-21 10:49:47 +000088 // The MultiTouchMotionAccumulator is shared between the HardwareStateConverter and
89 // CapturedTouchpadEventConverter, so that if the touchpad is captured or released while touches
90 // are down, the relevant converter can still benefit from the current axis values stored in the
91 // accumulator.
92 MultiTouchMotionAccumulator mMotionAccumulator;
93
Harry Cutts47db1c72022-12-13 19:20:47 +000094 HardwareStateConverter mStateConverter;
Harry Cutts4fb941a2022-12-14 19:14:04 +000095 GestureConverter mGestureConverter;
Harry Cuttsbb24e272023-03-21 10:49:47 +000096 CapturedTouchpadEventConverter mCapturedEventConverter;
Omar Abdelmonem5e70e962024-08-06 09:38:42 +000097 HardwareProperties mHardwareProperties;
Harry Cutts74235542022-11-24 15:52:53 +000098
Harry Cuttsbb24e272023-03-21 10:49:47 +000099 bool mPointerCaptured = false;
Harry Cuttsbb24e272023-03-21 10:49:47 +0000100 bool mResettingInterpreter = false;
Harry Cutts74235542022-11-24 15:52:53 +0000101 std::vector<Gesture> mGesturesToProcess;
Harry Cuttsa34de522023-06-06 15:52:54 +0000102
103 static MetricsIdentifier metricsIdFromInputDeviceIdentifier(const InputDeviceIdentifier& id) {
104 return std::make_tuple(id.bus, id.vendor, id.product, id.version);
105 }
106 const MetricsIdentifier mMetricsId;
107 // Tracking IDs for touches on the pad in the last evdev frame.
108 std::set<int32_t> mLastFrameTrackingIds;
109 // Tracking IDs for touches that have at some point been reported as palms by the touchpad.
110 std::set<int32_t> mPalmTrackingIds;
Josep del Riod0746382023-07-29 13:18:25 +0000111
112 // The display that events generated by this mapper should target. This can be set to
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700113 // LogicalDisplayId::INVALID to target the focused display. If there is no display target (i.e.
Josep del Riod0746382023-07-29 13:18:25 +0000114 // std::nullopt), all events will be ignored.
Linnan Li13bf76a2024-05-05 19:18:02 +0800115 std::optional<ui::LogicalDisplayId> mDisplayId;
Arpit Singh33a10a62023-10-12 13:06:54 +0000116
117 nsecs_t mGestureStartTime{0};
Harry Cutts79cc9fa2022-10-28 15:32:39 +0000118};
119
120} // namespace android