From 4b19bd0d193d0fa06212d2e96f3971daed01b6e3 Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Tue, 1 Jun 2021 17:34:59 -0700 Subject: MotionEvent: Transform mouse cursor position When calling MotionEvent::applyTransform, the x/y coordinates for all PointerCoords are transformed accordingly. When this happens, we also need to transform the mouse cursor position. Bug: 179274888 Test: atest InputShellCommandTest (when the display is rotated to different orientations) Change-Id: I10db8238150b1bd20f3f53c3a7514a111e362adb --- libs/input/Input.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libs/input/Input.cpp') diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index f1ccce1b9f..266d7a3c87 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -630,6 +630,13 @@ void MotionEvent::applyTransform(const std::array& matrix) { // Apply the transformation to all samples. std::for_each(mSamplePointerCoords.begin(), mSamplePointerCoords.end(), [&transform](PointerCoords& c) { c.transform(transform); }); + + if (mRawXCursorPosition != AMOTION_EVENT_INVALID_CURSOR_POSITION && + mRawYCursorPosition != AMOTION_EVENT_INVALID_CURSOR_POSITION) { + const vec2 cursor = transform.transform(mRawXCursorPosition, mRawYCursorPosition); + mRawXCursorPosition = cursor.x; + mRawYCursorPosition = cursor.y; + } } #ifdef __linux__ -- cgit v1.2.3-59-g8ed1b