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

Commit 7dc91bb2 authored by Hiroki Sato's avatar Hiroki Sato
Browse files

Implement PointerController#getPositionInLogicalDisplay

PointerController#getPosition returns the pointer position in display
absolute coordinate. Recently we're adding more usages of pointers in
logical pointer coordinates.

Currently, PointerController internally stores the position in logical
coordinate, and getPosition returns the value applying the inverse
display transform. When the user needs it in the logical coordinates,
they reapply the transform to get the logical pointer position.
Applying transform and inverse is unnecessary, and it is easily
avoided by letting PointerController directly return the internal
position.

With this change, PointerController now has two methods for getting
display absolute and logical positions.

Bug: 431622043
Test: PointerChoreographerTest
Test: PointerControllerTest
Flag: EXEMPT refactor
Change-Id: If8ab1ec94528f7fd203ae918bb0b684b1350f7b0
parent 4dd6608a
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -316,14 +316,13 @@ void PointerChoreographer::processPointerDeviceMotionEventLocked(NotifyMotionArg

void PointerChoreographer::handleUnconsumedDeltaLocked(PointerControllerInterface& pc,
                                                       const vec2& unconsumedDelta) {
    // Display topology is in rotated coordinate space and Pointer controller returns and expects
    // Display topology is in rotated coordinate space and PointerController expects
    // values in the un-rotated coordinate space. So we need to transform delta and cursor position
    // back to the rotated coordinate space to lookup adjacent display in the display topology.
    const auto& sourceDisplayTransform = pc.getDisplayTransform();
    const vec2 rotatedUnconsumedDelta =
            transformWithoutTranslation(sourceDisplayTransform, unconsumedDelta);
    const vec2 cursorPosition = pc.getPosition();
    const vec2 rotatedCursorPosition = sourceDisplayTransform.transform(cursorPosition);
    const vec2 rotatedCursorPosition = pc.getPositionInLogicalDisplay();

    // To find out the boundary that cursor is crossing we are checking delta in x and y direction
    // respectively. This prioritizes x direction over y.
@@ -1070,10 +1069,10 @@ vec2 PointerChoreographer::filterPointerMotionForAccessibilityLocked(
        return delta;
    }

    // PointerController.getPosition and mouse delta are both in physical display coordinates.
    // PointerController expects coordinates in physical display coordinates.
    // PointerMotionFilter in Java expects coordinates in logical display coordinates.
    const auto& displayTransform = pc.getDisplayTransform();
    const vec2 current = displayTransform.transform(pc.getPosition());
    const vec2 current = pc.getPositionInLogicalDisplay();
    const vec2 deltaInDisplay = transformWithoutTranslation(displayTransform, delta);
    const ui::LogicalDisplayId displayId = pc.getDisplayId();
    const std::optional<vec2> filterResult =
+6 −2
Original line number Diff line number Diff line
@@ -60,17 +60,21 @@ public:

    /* Move the pointer and return unconsumed delta if the pointer has crossed the current
     * viewport bounds.
     * The movement should be in the display physical coordinates.
     *
     * Return value may be used to move pointer to corresponding adjacent display, if it exists in
     * the display-topology */
    [[nodiscard]] virtual vec2 move(float deltaX, float deltaY) = 0;

    /* Sets the absolute location of the pointer. */
    /* Sets the display physical location of the pointer. */
    virtual void setPosition(float x, float y) = 0;

    /* Gets the absolute location of the pointer. */
    /* Gets the display physical location of the pointer. */
    virtual vec2 getPosition() const = 0;

    /* Gets the display logical location of the pointer. */
    virtual vec2 getPositionInLogicalDisplay() const = 0;

    enum class Transition {
        // Fade/unfade immediately.
        IMMEDIATE,
+8 −0
Original line number Diff line number Diff line
@@ -55,6 +55,14 @@ vec2 FakePointerController::getPosition() const {
    return {mX, mY};
}

vec2 FakePointerController::getPositionInLogicalDisplay() const {
    if (!mEnabled) {
        return {0, 0};
    }

    return mTransform.transform(mX, mY);
}

ui::LogicalDisplayId FakePointerController::getDisplayId() const {
    if (!mEnabled || !mDisplayId) {
        return ui::LogicalDisplayId::INVALID;
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ public:

    void setPosition(float x, float y) override;
    vec2 getPosition() const override;
    vec2 getPositionInLogicalDisplay() const override;
    ui::LogicalDisplayId getDisplayId() const override;
    void setDisplayViewport(const DisplayViewport& viewport) override;
    void updatePointerIcon(PointerIconStyle iconId) override;