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

Commit c5a36422 authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Automerger Merge Worker
Browse files

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

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/14530414

Change-Id: I26c79aa7ca3858f14fe5e1ed7ae2aff3f2fcfbe0
parents 0692ea02 accebe0f
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