diff options
author | 2022-10-28 15:32:39 +0000 | |
---|---|---|
committer | 2022-12-01 15:56:20 +0000 | |
commit | 79cc9fa5f0d40938bdfcd971d5af9a0bcc8b440c (patch) | |
tree | 9bc4bba7070905717ec37b8c9b9556aebdb68be7 | |
parent | 4bd381e26966219eaaa776473a762a1ae7b8acf3 (diff) |
Add new `TouchpadInputMapper` class
This will replace `MultiTouchInputMapper` and `SingleTouchInputMapper`
for touchpad devices, and will be the wrapper for the gestures library.
Bug: 251196347
Test: connect Apple Magic Trackpad 2 to device, check logs come out
Test: atest inputflinger_tests
Change-Id: Ia8ee1779a40c6c6f98373e114c040bf13b7f213d
-rw-r--r-- | services/inputflinger/reader/Android.bp | 1 | ||||
-rw-r--r-- | services/inputflinger/reader/EventHub.cpp | 4 | ||||
-rw-r--r-- | services/inputflinger/reader/InputDevice.cpp | 7 | ||||
-rw-r--r-- | services/inputflinger/reader/include/EventHub.h | 5 | ||||
-rw-r--r-- | services/inputflinger/reader/mapper/TouchpadInputMapper.cpp | 36 | ||||
-rw-r--r-- | services/inputflinger/reader/mapper/TouchpadInputMapper.h | 34 |
6 files changed, 85 insertions, 2 deletions
diff --git a/services/inputflinger/reader/Android.bp b/services/inputflinger/reader/Android.bp index 46e86de84c..551ad7a398 100644 --- a/services/inputflinger/reader/Android.bp +++ b/services/inputflinger/reader/Android.bp @@ -51,6 +51,7 @@ filegroup { "mapper/SingleTouchInputMapper.cpp", "mapper/SwitchInputMapper.cpp", "mapper/TouchInputMapper.cpp", + "mapper/TouchpadInputMapper.cpp", "mapper/VibratorInputMapper.cpp", "mapper/accumulator/CursorButtonAccumulator.cpp", "mapper/accumulator/CursorScrollAccumulator.cpp", diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp index 0aaef53c0d..f2ea90c291 100644 --- a/services/inputflinger/reader/EventHub.cpp +++ b/services/inputflinger/reader/EventHub.cpp @@ -2215,6 +2215,10 @@ void EventHub::openDeviceLocked(const std::string& devicePath) { // a touch screen. if (device->keyBitmask.test(BTN_TOUCH) || !haveGamepadButtons) { device->classes |= (InputDeviceClass::TOUCH | InputDeviceClass::TOUCH_MT); + if (device->propBitmask.test(INPUT_PROP_POINTER) && + !device->keyBitmask.any(BTN_TOOL_PEN, BTN_TOOL_FINGER) && !haveStylusButtons) { + device->classes |= InputDeviceClass::TOUCHPAD; + } } // Is this an old style single-touch driver? } else if (device->keyBitmask.test(BTN_TOUCH) && device->absBitmask.test(ABS_X) && diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp index e6ab8722f6..6ca629835d 100644 --- a/services/inputflinger/reader/InputDevice.cpp +++ b/services/inputflinger/reader/InputDevice.cpp @@ -33,6 +33,7 @@ #include "SensorInputMapper.h" #include "SingleTouchInputMapper.h" #include "SwitchInputMapper.h" +#include "TouchpadInputMapper.h" #include "VibratorInputMapper.h" using android::hardware::input::InputDeviceCountryCode; @@ -208,7 +209,11 @@ void InputDevice::addEventHubDevice(int32_t eventHubId, bool populateMappers) { } // Touchscreens and touchpad devices. - if (classes.test(InputDeviceClass::TOUCH_MT)) { + // TODO(b/251196347): replace this with a proper flag. + constexpr bool ENABLE_NEW_TOUCHPAD_STACK = false; + if (ENABLE_NEW_TOUCHPAD_STACK && classes.test(InputDeviceClass::TOUCHPAD)) { + mappers.push_back(std::make_unique<TouchpadInputMapper>(*contextPtr)); + } else if (classes.test(InputDeviceClass::TOUCH_MT)) { mappers.push_back(std::make_unique<MultiTouchInputMapper>(*contextPtr)); } else if (classes.test(InputDeviceClass::TOUCH)) { mappers.push_back(std::make_unique<SingleTouchInputMapper>(*contextPtr)); diff --git a/services/inputflinger/reader/include/EventHub.h b/services/inputflinger/reader/include/EventHub.h index 8e5f15f338..42ca482a68 100644 --- a/services/inputflinger/reader/include/EventHub.h +++ b/services/inputflinger/reader/include/EventHub.h @@ -94,7 +94,7 @@ enum class InputDeviceClass : uint32_t { /* The input device is a cursor device such as a trackball or mouse. */ CURSOR = 0x00000008, - /* The input device is a multi-touch touchscreen. */ + /* The input device is a multi-touch touchscreen or touchpad. */ TOUCH_MT = 0x00000010, /* The input device is a directional pad (implies keyboard, has DPAD keys). */ @@ -130,6 +130,9 @@ enum class InputDeviceClass : uint32_t { /* The input device has sysfs controllable lights */ LIGHT = 0x00008000, + /* The input device is a touchpad, requiring an on-screen cursor. */ + TOUCHPAD = 0x00010000, + /* The input device is virtual (not a real device, not part of UI configuration). */ VIRTUAL = 0x40000000, diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp new file mode 100644 index 0000000000..3ad1de4cd4 --- /dev/null +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp @@ -0,0 +1,36 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../Macros.h" + +#include "TouchpadInputMapper.h" + +namespace android { + +TouchpadInputMapper::TouchpadInputMapper(InputDeviceContext& deviceContext) + : InputMapper(deviceContext) {} + +uint32_t TouchpadInputMapper::getSources() const { + return AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD; +} + +std::list<NotifyArgs> TouchpadInputMapper::process(const RawEvent* rawEvent) { + ALOGD("TODO: process event type=0x%x code=0x%x value=0x%x", rawEvent->type, rawEvent->code, + rawEvent->value); + return {}; +} + +} // namespace android diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.h b/services/inputflinger/reader/mapper/TouchpadInputMapper.h new file mode 100644 index 0000000000..81a76d27be --- /dev/null +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.h @@ -0,0 +1,34 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "EventHub.h" +#include "InputDevice.h" +#include "InputMapper.h" +#include "NotifyArgs.h" + +namespace android { + +class TouchpadInputMapper : public InputMapper { +public: + explicit TouchpadInputMapper(InputDeviceContext& deviceContext); + + virtual uint32_t getSources() const override; + [[nodiscard]] virtual std::list<NotifyArgs> process(const RawEvent* rawEvent) override; +}; + +} // namespace android |