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

Commit accebe0f authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

CursorInputMapper: Rotate cursor position for per-window-input-rotation

When per-window-input-rotation is enabled, InputReader works in the
un-rotated display coordinate space while the PointerController works in
the rotated coordinate space.

This means when we obtain the cursor position in CursorInputMapper, it
is in the rotated coordinate space. So we need to convert it to the
unrotated coordinate space.

Bug: 179274888
Test: atest inputflinger_tests
Test: manual with a mouse device while rotating phone
Change-Id: Ide81ac902606e6ec6c4f8fa1d8bbfd5aa3a49b8e
parent f5334b8e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -188,6 +188,8 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*

    if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
        mOrientation = DISPLAY_ORIENTATION_0;
        mDisplayWidth = 0;
        mDisplayHeight = 0;
        const bool isOrientedDevice =
                (mParameters.orientationAware && mParameters.hasAssociatedDisplay);

@@ -202,6 +204,8 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*
                        config->getDisplayViewportByType(ViewportType::INTERNAL);
                if (internalViewport) {
                    mOrientation = getInverseRotation(internalViewport->orientation);
                    mDisplayWidth = internalViewport->deviceWidth;
                    mDisplayHeight = internalViewport->deviceHeight;
                }
            }
        } else {
@@ -360,6 +364,12 @@ void CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) {
        }

        mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
        if (isPerWindowInputRotationEnabled()) {
            // Rotate the cursor position that is in PointerController's rotated coordinate space
            // to InputReader's un-rotated coordinate space.
            rotatePoint(mOrientation, xCursorPosition /*byRef*/, yCursorPosition /*byRef*/,
                        mDisplayWidth, mDisplayHeight);
        }
        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, xCursorPosition);
        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition);
        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX);
+2 −0
Original line number Diff line number Diff line
@@ -105,6 +105,8 @@ private:
    VelocityControl mWheelYVelocityControl;

    int32_t mOrientation;
    int32_t mDisplayWidth;
    int32_t mDisplayHeight;

    std::shared_ptr<PointerControllerInterface> mPointerController;

+23 −0
Original line number Diff line number Diff line
@@ -68,6 +68,29 @@ static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) {
            *deltaX = -*deltaY;
            *deltaY = temp;
            break;

        default:
            break;
    }
}

// Rotates the given point (x, y) by the supplied orientation. The width and height are the
// dimensions of the surface prior to this rotation being applied.
static void rotatePoint(int32_t orientation, float& x, float& y, int32_t width, int32_t height) {
    rotateDelta(orientation, &x, &y);
    switch (orientation) {
        case DISPLAY_ORIENTATION_90:
            y += width;
            break;
        case DISPLAY_ORIENTATION_180:
            x += width;
            y += height;
            break;
        case DISPLAY_ORIENTATION_270:
            x += height;
            break;
        default:
            break;
    }
}

+0 −24
Original line number Diff line number Diff line
@@ -28,30 +28,6 @@

namespace android {

namespace {

// Rotates the given point (x, y) by the supplied orientation. The width and height are the
// dimensions of the surface prior to this rotation being applied.
void rotatePoint(int32_t orientation, float& x, float& y, int32_t width, int32_t height) {
    rotateDelta(orientation, &x, &y);
    switch (orientation) {
        case DISPLAY_ORIENTATION_90:
            y += width;
            break;
        case DISPLAY_ORIENTATION_180:
            x += width;
            y += height;
            break;
        case DISPLAY_ORIENTATION_270:
            x += height;
            break;
        default:
            break;
    }
}

} // namespace

// --- Constants ---

// Maximum amount of latency to add to touch events while waiting for data from an