Loading services/inputflinger/PointerChoreographer.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -874,6 +874,15 @@ std::optional<vec2> PointerChoreographer::getMouseCursorPosition(ui::LogicalDisp return std::nullopt; } std::optional<vec2> PointerChoreographer::getMouseCursorPositionInLogicalDisplay( ui::LogicalDisplayId displayId) { std::scoped_lock _l(getLock()); if (auto it = mMousePointersByDisplay.find(displayId); it != mMousePointersByDisplay.end()) { return it->second->getPositionInLogicalDisplay(); } return std::nullopt; } void PointerChoreographer::setShowTouchesEnabled(bool enabled) { PointerDisplayChange pointerDisplayChange; Loading services/inputflinger/PointerChoreographer.h +15 −1 Original line number Diff line number Diff line Loading @@ -61,7 +61,8 @@ public: virtual std::optional<DisplayViewport> getViewportForPointerDevice( ui::LogicalDisplayId associatedDisplayId = ui::LogicalDisplayId::INVALID) = 0; /** * Gets the current position of the mouse cursor on the specified display. * Gets the current position of the mouse cursor on the specified display in the display * physical coordinates. * * Returns optional.empty if no cursor is available, or if existing cursor is not on * supplied `displayId`. Loading @@ -69,6 +70,17 @@ public: * This method is inherently racy, and should only be used for test purposes. */ virtual std::optional<vec2> getMouseCursorPosition(ui::LogicalDisplayId displayId) = 0; /** * Gets the current position of the mouse cursor on the specified display in the display logical * coordinates. * * Returns optional.empty if no cursor is available, or if existing cursor is not on * supplied `displayId`. * * This method is inherently racy, and should only be used for test purposes. */ virtual std::optional<vec2> getMouseCursorPositionInLogicalDisplay( ui::LogicalDisplayId displayId) = 0; virtual void setShowTouchesEnabled(bool enabled) = 0; virtual void setStylusPointerIconEnabled(bool enabled) = 0; /** Loading Loading @@ -116,6 +128,8 @@ public: std::optional<DisplayViewport> getViewportForPointerDevice( ui::LogicalDisplayId associatedDisplayId) override; std::optional<vec2> getMouseCursorPosition(ui::LogicalDisplayId displayId) override; std::optional<vec2> getMouseCursorPositionInLogicalDisplay( ui::LogicalDisplayId displayId) override; void setShowTouchesEnabled(bool enabled) override; void setStylusPointerIconEnabled(bool enabled) override; bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, Loading services/inputflinger/tests/PointerChoreographer_test.cpp +24 −0 Original line number Diff line number Diff line Loading @@ -2579,6 +2579,30 @@ TEST_F(PointerChoreographerTest, MouseAndDrawingTabletReportMouseEvents) { assertPointerControllerRemoved(pc); } TEST_F(PointerChoreographerTest, GetMouseCursorPosition) { mChoreographer.setDisplayViewports( {createViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_90)}); setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->setTransform(ui::Transform(ui::Transform::toRotationFlags(ui::ROTATION_90), DISPLAY_HEIGHT, DISPLAY_WIDTH)); pc->setPosition(150, 350); // (450, 150) in logical coordinates auto position = mChoreographer.getMouseCursorPosition(DISPLAY_ID); ASSERT_TRUE(position.has_value()); ASSERT_EQ(150, position->x); ASSERT_EQ(350, position->y); auto positionInLogical = mChoreographer.getMouseCursorPositionInLogicalDisplay(DISPLAY_ID); ASSERT_TRUE(position.has_value()); ASSERT_EQ(450, positionInLogical->x); ASSERT_EQ(150, positionInLogical->y); } using PointerVisibilityAndTouchpadTapStateOnKeyPressTestFixtureParam = std::tuple<std::string_view /*name*/, uint32_t /*source*/>; Loading Loading
services/inputflinger/PointerChoreographer.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -874,6 +874,15 @@ std::optional<vec2> PointerChoreographer::getMouseCursorPosition(ui::LogicalDisp return std::nullopt; } std::optional<vec2> PointerChoreographer::getMouseCursorPositionInLogicalDisplay( ui::LogicalDisplayId displayId) { std::scoped_lock _l(getLock()); if (auto it = mMousePointersByDisplay.find(displayId); it != mMousePointersByDisplay.end()) { return it->second->getPositionInLogicalDisplay(); } return std::nullopt; } void PointerChoreographer::setShowTouchesEnabled(bool enabled) { PointerDisplayChange pointerDisplayChange; Loading
services/inputflinger/PointerChoreographer.h +15 −1 Original line number Diff line number Diff line Loading @@ -61,7 +61,8 @@ public: virtual std::optional<DisplayViewport> getViewportForPointerDevice( ui::LogicalDisplayId associatedDisplayId = ui::LogicalDisplayId::INVALID) = 0; /** * Gets the current position of the mouse cursor on the specified display. * Gets the current position of the mouse cursor on the specified display in the display * physical coordinates. * * Returns optional.empty if no cursor is available, or if existing cursor is not on * supplied `displayId`. Loading @@ -69,6 +70,17 @@ public: * This method is inherently racy, and should only be used for test purposes. */ virtual std::optional<vec2> getMouseCursorPosition(ui::LogicalDisplayId displayId) = 0; /** * Gets the current position of the mouse cursor on the specified display in the display logical * coordinates. * * Returns optional.empty if no cursor is available, or if existing cursor is not on * supplied `displayId`. * * This method is inherently racy, and should only be used for test purposes. */ virtual std::optional<vec2> getMouseCursorPositionInLogicalDisplay( ui::LogicalDisplayId displayId) = 0; virtual void setShowTouchesEnabled(bool enabled) = 0; virtual void setStylusPointerIconEnabled(bool enabled) = 0; /** Loading Loading @@ -116,6 +128,8 @@ public: std::optional<DisplayViewport> getViewportForPointerDevice( ui::LogicalDisplayId associatedDisplayId) override; std::optional<vec2> getMouseCursorPosition(ui::LogicalDisplayId displayId) override; std::optional<vec2> getMouseCursorPositionInLogicalDisplay( ui::LogicalDisplayId displayId) override; void setShowTouchesEnabled(bool enabled) override; void setStylusPointerIconEnabled(bool enabled) override; bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, Loading
services/inputflinger/tests/PointerChoreographer_test.cpp +24 −0 Original line number Diff line number Diff line Loading @@ -2579,6 +2579,30 @@ TEST_F(PointerChoreographerTest, MouseAndDrawingTabletReportMouseEvents) { assertPointerControllerRemoved(pc); } TEST_F(PointerChoreographerTest, GetMouseCursorPosition) { mChoreographer.setDisplayViewports( {createViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_90)}); setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->setTransform(ui::Transform(ui::Transform::toRotationFlags(ui::ROTATION_90), DISPLAY_HEIGHT, DISPLAY_WIDTH)); pc->setPosition(150, 350); // (450, 150) in logical coordinates auto position = mChoreographer.getMouseCursorPosition(DISPLAY_ID); ASSERT_TRUE(position.has_value()); ASSERT_EQ(150, position->x); ASSERT_EQ(350, position->y); auto positionInLogical = mChoreographer.getMouseCursorPositionInLogicalDisplay(DISPLAY_ID); ASSERT_TRUE(position.has_value()); ASSERT_EQ(450, positionInLogical->x); ASSERT_EQ(150, positionInLogical->y); } using PointerVisibilityAndTouchpadTapStateOnKeyPressTestFixtureParam = std::tuple<std::string_view /*name*/, uint32_t /*source*/>; Loading