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

Commit d2ed5d7f authored by Nergi Rahardi's avatar Nergi Rahardi Committed by Android (Google) Code Review
Browse files

Merge "Modify getCursorPosition to return null for display w/o cursor" into main

parents 501a6614 f4ebe2c7
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -867,14 +867,12 @@ std::optional<DisplayViewport> PointerChoreographer::getViewportForPointerDevice
    return std::nullopt;
}

vec2 PointerChoreographer::getMouseCursorPosition(ui::LogicalDisplayId displayId) {
std::optional<vec2> PointerChoreographer::getMouseCursorPosition(ui::LogicalDisplayId displayId) {
    std::scoped_lock _l(getLock());
    const ui::LogicalDisplayId resolvedDisplayId = getTargetMouseDisplayLocked(displayId);
    if (auto it = mMousePointersByDisplay.find(resolvedDisplayId);
        it != mMousePointersByDisplay.end()) {
    if (auto it = mMousePointersByDisplay.find(displayId); it != mMousePointersByDisplay.end()) {
        return it->second->getPosition();
    }
    return {AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION};
    return std::nullopt;
}

void PointerChoreographer::setShowTouchesEnabled(bool enabled) {
+10 −2
Original line number Diff line number Diff line
@@ -60,7 +60,15 @@ public:
    virtual void setDisplayViewports(const std::vector<DisplayViewport>& viewports) = 0;
    virtual std::optional<DisplayViewport> getViewportForPointerDevice(
            ui::LogicalDisplayId associatedDisplayId = ui::LogicalDisplayId::INVALID) = 0;
    virtual vec2 getMouseCursorPosition(ui::LogicalDisplayId displayId) = 0;
    /**
     * Gets the current position of the mouse cursor on the specified display.
     *
     * 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> getMouseCursorPosition(ui::LogicalDisplayId displayId) = 0;
    virtual void setShowTouchesEnabled(bool enabled) = 0;
    virtual void setStylusPointerIconEnabled(bool enabled) = 0;
    /**
@@ -107,7 +115,7 @@ public:
    void setDisplayViewports(const std::vector<DisplayViewport>& viewports) override;
    std::optional<DisplayViewport> getViewportForPointerDevice(
            ui::LogicalDisplayId associatedDisplayId) override;
    vec2 getMouseCursorPosition(ui::LogicalDisplayId displayId) override;
    std::optional<vec2> getMouseCursorPosition(ui::LogicalDisplayId displayId) override;
    void setShowTouchesEnabled(bool enabled) override;
    void setStylusPointerIconEnabled(bool enabled) override;
    bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon,
+45 −0
Original line number Diff line number Diff line
@@ -3184,6 +3184,51 @@ TEST_F(PointerChoreographerDisplayTopologyDefaultMouseDisplayTests,
    ASSERT_TRUE(pc->isPointerShown());
}

TEST_F(PointerChoreographerDisplayTopologyDefaultMouseDisplayTests,
       GetCursorPositionReturnValidPositionForDisplayWithCursor) {
    SCOPED_FLAG_OVERRIDE(connected_displays_cursor, true);
    SCOPED_FLAG_OVERRIDE(connected_displays_associated_display_cursor_bugfix, true);

    // Add two displays
    mChoreographer.setDisplayViewports(
            {createViewport(FIRST_DISPLAY_ID), createViewport(SECOND_DISPLAY_ID)});
    setDisplayTopologyWithDisplays(/*primaryDisplayId=*/FIRST_DISPLAY_ID,
                                   /*adjacentDisplays=*/{SECOND_DISPLAY_ID});

    mChoreographer.notifyInputDevicesChanged(
            {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, FIRST_DISPLAY_ID)}});

    auto pc = assertPointerControllerCreated(ControllerType::MOUSE);
    pc->assertViewportSet(FIRST_DISPLAY_ID);

    auto firstDisplayCursor = mChoreographer.getMouseCursorPosition(FIRST_DISPLAY_ID);
    // Valid
    ASSERT_TRUE(firstDisplayCursor.has_value());

    // Invalid, cursor is currently on first display
    auto secondDisplayCursor = mChoreographer.getMouseCursorPosition(SECOND_DISPLAY_ID);
    ASSERT_FALSE(secondDisplayCursor.has_value());

    // Move cursor to the secondary display
    auto pointerBuilder = PointerBuilder(/*id=*/0, ToolType::MOUSE)
                                  .axis(AMOTION_EVENT_AXIS_RELATIVE_X, /*x=*/100)
                                  .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, /*y=*/0);
    mChoreographer.notifyMotion(
            MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
                    .pointer(pointerBuilder)
                    .deviceId(DEVICE_ID)
                    .displayId(ui::LogicalDisplayId::INVALID)
                    .build());
    pc->assertViewportSet(SECOND_DISPLAY_ID);
    firstDisplayCursor = mChoreographer.getMouseCursorPosition(FIRST_DISPLAY_ID);
    // Invalid, cursor is currently on second display
    ASSERT_FALSE(firstDisplayCursor.has_value());

    // Valid
    secondDisplayCursor = mChoreographer.getMouseCursorPosition(SECOND_DISPLAY_ID);
    ASSERT_TRUE(secondDisplayCursor.has_value());
}

class PointerChoreographerWindowInfoListenerTest : public testing::Test {};

TEST_F(PointerChoreographerWindowInfoListenerTest,