Loading services/inputflinger/reader/mapper/TouchpadInputMapper.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -16,11 +16,14 @@ #include "../Macros.h" #include <optional> #include <android/input.h> #include <linux/input-event-codes.h> #include <log/log_main.h> #include "TouchCursorInputMapperCommon.h" #include "TouchpadInputMapper.h" #include "ui/Rotation.h" namespace android { Loading Loading @@ -111,6 +114,22 @@ uint32_t TouchpadInputMapper::getSources() const { return AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD; } std::list<NotifyArgs> TouchpadInputMapper::configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes) { if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) { std::optional<int32_t> displayId = mPointerController->getDisplayId(); ui::Rotation orientation = ui::ROTATION_0; if (displayId.has_value()) { if (auto viewport = config->getDisplayViewportById(*displayId); viewport) { orientation = getInverseRotation(viewport->orientation); } } mGestureConverter.setOrientation(orientation); } return {}; } std::list<NotifyArgs> TouchpadInputMapper::reset(nsecs_t when) { mStateConverter.reset(); mGestureConverter.reset(); Loading services/inputflinger/reader/mapper/TouchpadInputMapper.h +4 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include "EventHub.h" #include "InputDevice.h" #include "InputMapper.h" #include "InputReaderBase.h" #include "NotifyArgs.h" #include "gestures/GestureConverter.h" #include "gestures/HardwareStateConverter.h" Loading @@ -39,6 +40,9 @@ public: ~TouchpadInputMapper(); uint32_t getSources() const override; [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes) override; [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; Loading services/inputflinger/reader/mapper/gestures/GestureConverter.cpp +7 −3 Original line number Diff line number Diff line Loading @@ -72,8 +72,12 @@ NotifyArgs GestureConverter::handleMove(nsecs_t when, nsecs_t readTime, const Ge props.id = 0; props.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; float deltaX = gesture.details.move.dx; float deltaY = gesture.details.move.dy; rotateDelta(mOrientation, &deltaX, &deltaY); mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER); mPointerController->move(gesture.details.move.dx, gesture.details.move.dy); mPointerController->move(deltaX, deltaY); mPointerController->unfade(PointerControllerInterface::Transition::IMMEDIATE); float xCursorPosition, yCursorPosition; mPointerController->getPosition(&xCursorPosition, &yCursorPosition); Loading @@ -82,8 +86,8 @@ NotifyArgs GestureConverter::handleMove(nsecs_t when, nsecs_t readTime, const Ge coords.clear(); coords.setAxisValue(AMOTION_EVENT_AXIS_X, xCursorPosition); coords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition); coords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, gesture.details.move.dx); coords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, gesture.details.move.dy); coords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX); coords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY); const bool down = isPointerDown(mButtonState); coords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, down ? 1.0f : 0.0f); Loading services/inputflinger/reader/mapper/gestures/GestureConverter.h +3 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include "InputReaderContext.h" #include "NotifyArgs.h" #include "ui/Rotation.h" #include "include/gestures.h" Loading @@ -35,6 +36,7 @@ class GestureConverter { public: GestureConverter(InputReaderContext& readerContext, int32_t deviceId); void setOrientation(ui::Rotation orientation) { mOrientation = orientation; } void reset(); [[nodiscard]] std::list<NotifyArgs> handleGesture(nsecs_t when, nsecs_t readTime, Loading @@ -56,6 +58,7 @@ private: InputReaderContext& mReaderContext; std::shared_ptr<PointerControllerInterface> mPointerController; ui::Rotation mOrientation = ui::ROTATION_0; // The current button state according to the gestures library, but converted into MotionEvent // button values (AMOTION_EVENT_BUTTON_...). uint32_t mButtonState = 0; Loading services/inputflinger/tests/GestureConverter_test.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include "TestInputListener.h" #include "TestInputListenerMatchers.h" #include "include/gestures.h" #include "ui/Rotation.h" namespace android { Loading Loading @@ -77,6 +78,23 @@ TEST_F(GestureConverterTest, Move) { ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(95, 210)); } TEST_F(GestureConverterTest, Move_Rotated) { GestureConverter converter(*mReader->getContext(), DEVICE_ID); converter.setOrientation(ui::ROTATION_90); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); ASSERT_EQ(1u, args.size()); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(POINTER_X + 10, POINTER_Y + 5), WithRelativeMotion(10, 5), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithButtonState(0), WithPressure(0.0f))); ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(110, 205)); } TEST_F(GestureConverterTest, ButtonsChange) { GestureConverter converter(*mReader->getContext(), DEVICE_ID); Loading Loading
services/inputflinger/reader/mapper/TouchpadInputMapper.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -16,11 +16,14 @@ #include "../Macros.h" #include <optional> #include <android/input.h> #include <linux/input-event-codes.h> #include <log/log_main.h> #include "TouchCursorInputMapperCommon.h" #include "TouchpadInputMapper.h" #include "ui/Rotation.h" namespace android { Loading Loading @@ -111,6 +114,22 @@ uint32_t TouchpadInputMapper::getSources() const { return AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD; } std::list<NotifyArgs> TouchpadInputMapper::configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes) { if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) { std::optional<int32_t> displayId = mPointerController->getDisplayId(); ui::Rotation orientation = ui::ROTATION_0; if (displayId.has_value()) { if (auto viewport = config->getDisplayViewportById(*displayId); viewport) { orientation = getInverseRotation(viewport->orientation); } } mGestureConverter.setOrientation(orientation); } return {}; } std::list<NotifyArgs> TouchpadInputMapper::reset(nsecs_t when) { mStateConverter.reset(); mGestureConverter.reset(); Loading
services/inputflinger/reader/mapper/TouchpadInputMapper.h +4 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include "EventHub.h" #include "InputDevice.h" #include "InputMapper.h" #include "InputReaderBase.h" #include "NotifyArgs.h" #include "gestures/GestureConverter.h" #include "gestures/HardwareStateConverter.h" Loading @@ -39,6 +40,9 @@ public: ~TouchpadInputMapper(); uint32_t getSources() const override; [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes) override; [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; Loading
services/inputflinger/reader/mapper/gestures/GestureConverter.cpp +7 −3 Original line number Diff line number Diff line Loading @@ -72,8 +72,12 @@ NotifyArgs GestureConverter::handleMove(nsecs_t when, nsecs_t readTime, const Ge props.id = 0; props.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; float deltaX = gesture.details.move.dx; float deltaY = gesture.details.move.dy; rotateDelta(mOrientation, &deltaX, &deltaY); mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER); mPointerController->move(gesture.details.move.dx, gesture.details.move.dy); mPointerController->move(deltaX, deltaY); mPointerController->unfade(PointerControllerInterface::Transition::IMMEDIATE); float xCursorPosition, yCursorPosition; mPointerController->getPosition(&xCursorPosition, &yCursorPosition); Loading @@ -82,8 +86,8 @@ NotifyArgs GestureConverter::handleMove(nsecs_t when, nsecs_t readTime, const Ge coords.clear(); coords.setAxisValue(AMOTION_EVENT_AXIS_X, xCursorPosition); coords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition); coords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, gesture.details.move.dx); coords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, gesture.details.move.dy); coords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX); coords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY); const bool down = isPointerDown(mButtonState); coords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, down ? 1.0f : 0.0f); Loading
services/inputflinger/reader/mapper/gestures/GestureConverter.h +3 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include "InputReaderContext.h" #include "NotifyArgs.h" #include "ui/Rotation.h" #include "include/gestures.h" Loading @@ -35,6 +36,7 @@ class GestureConverter { public: GestureConverter(InputReaderContext& readerContext, int32_t deviceId); void setOrientation(ui::Rotation orientation) { mOrientation = orientation; } void reset(); [[nodiscard]] std::list<NotifyArgs> handleGesture(nsecs_t when, nsecs_t readTime, Loading @@ -56,6 +58,7 @@ private: InputReaderContext& mReaderContext; std::shared_ptr<PointerControllerInterface> mPointerController; ui::Rotation mOrientation = ui::ROTATION_0; // The current button state according to the gestures library, but converted into MotionEvent // button values (AMOTION_EVENT_BUTTON_...). uint32_t mButtonState = 0; Loading
services/inputflinger/tests/GestureConverter_test.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include "TestInputListener.h" #include "TestInputListenerMatchers.h" #include "include/gestures.h" #include "ui/Rotation.h" namespace android { Loading Loading @@ -77,6 +78,23 @@ TEST_F(GestureConverterTest, Move) { ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(95, 210)); } TEST_F(GestureConverterTest, Move_Rotated) { GestureConverter converter(*mReader->getContext(), DEVICE_ID); converter.setOrientation(ui::ROTATION_90); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); ASSERT_EQ(1u, args.size()); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(POINTER_X + 10, POINTER_Y + 5), WithRelativeMotion(10, 5), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithButtonState(0), WithPressure(0.0f))); ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(110, 205)); } TEST_F(GestureConverterTest, ButtonsChange) { GestureConverter converter(*mReader->getContext(), DEVICE_ID); Loading