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

Commit 092f3a9b authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Add getSurfaceRotation API to MotionEvent

Add an API to get the current rotation value of the transform of the
MotionEvent.

Bug: 207771136
Test: atest MotionEventTest
Change-Id: I05fb4455d0dcfc0de8c8564473ee8d43ac86c0bd
parent 48579875
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -574,6 +574,8 @@ public:

    inline ui::Transform getTransform() const { return mTransform; }

    int getSurfaceRotation() const;

    inline float getXPrecision() const { return mXPrecision; }

    inline float getYPrecision() const { return mYPrecision; }
+19 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@

#include <android-base/stringprintf.h>
#include <gui/constants.h>
#include <input/DisplayViewport.h>
#include <input/Input.h>
#include <input/InputDevice.h>
#include <input/InputEventLabels.h>
@@ -506,6 +507,24 @@ void MotionEvent::addSample(
    mSamplePointerCoords.appendArray(pointerCoords, getPointerCount());
}

int MotionEvent::getSurfaceRotation() const {
    // The surface rotation is the rotation from the window's coordinate space to that of the
    // display. Since the event's transform takes display space coordinates to window space, the
    // returned surface rotation is the inverse of the rotation for the surface.
    switch (mTransform.getOrientation()) {
        case ui::Transform::ROT_0:
            return DISPLAY_ORIENTATION_0;
        case ui::Transform::ROT_90:
            return DISPLAY_ORIENTATION_270;
        case ui::Transform::ROT_180:
            return DISPLAY_ORIENTATION_180;
        case ui::Transform::ROT_270:
            return DISPLAY_ORIENTATION_90;
        default:
            return -1;
    }
}

float MotionEvent::getXCursorPosition() const {
    vec2 vals = mTransform.transform(getRawXCursorPosition(), getRawYCursorPosition());
    return vals.x;