Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a29f339a authored by Hiroki Sato's avatar Hiroki Sato
Browse files

Implement PointerChoreographer#getMouseCursorPositionInLogicalDisplay

In addition to the existing getMouseCursorPosition(), a new method is
optimized for getting the cursor position in logical display
coordinates.

Bug: 431622043
Test: PointerChoreographerTest
Test: MouseToTouchCompatTest
Flag: EXEMPT bugfix
Change-Id: Ia0a6a10376488017f92c9981fda3fb214a27466c
parent 7dc91bb2
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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;

+15 −1
Original line number Diff line number Diff line
@@ -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`.
@@ -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;
    /**
@@ -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,
+24 −0
Original line number Diff line number Diff line
@@ -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*/>;