diff options
| author | 2021-05-14 18:02:55 -0700 | |
|---|---|---|
| committer | 2021-06-21 14:18:05 -0700 | |
| commit | c652358755a933991bc8bf99b48d9c5f3df03907 (patch) | |
| tree | 1a103a18b67e29a2445260ebb054b00e55975c6f /libs/input/Input.cpp | |
| parent | 664834b64dc949cb5e1d33491ee07d0a0a6c3d51 (diff) | |
MotionEvent: Rotate relative axes according to window orientation
We rotate the X and Y coordinates of MotionEvents when the window
transform also contains a rotation. This means we should rotate the
relative axes (AXIS_RELATIVE_{X,Y}) as well, making sure not to
translate these relative values.
Bug: 179274888
Test: libinput_tests
Test: manual with test app
Change-Id: I8c716b14ee2b3cd5362f4e9f1554ee37d6875c2d
Diffstat (limited to 'libs/input/Input.cpp')
| -rw-r--r-- | libs/input/Input.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index e83341ac86..f1ccce1b9f 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -318,6 +318,8 @@ void PointerCoords::scale(float globalScaleFactor, float windowXScale, float win scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOUCH_MINOR, globalScaleFactor); scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MAJOR, globalScaleFactor); scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MINOR, globalScaleFactor); + scaleAxisValue(*this, AMOTION_EVENT_AXIS_RELATIVE_X, windowXScale); + scaleAxisValue(*this, AMOTION_EVENT_AXIS_RELATIVE_Y, windowYScale); } void PointerCoords::scale(float globalScaleFactor) { @@ -386,6 +388,15 @@ void PointerCoords::transform(const ui::Transform& transform) { setAxisValue(AMOTION_EVENT_AXIS_X, xy.x); setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y); + if (BitSet64::hasBit(bits, AMOTION_EVENT_AXIS_RELATIVE_X) || + BitSet64::hasBit(bits, AMOTION_EVENT_AXIS_RELATIVE_Y)) { + const ui::Transform rotation(transform.getOrientation()); + const vec2 relativeXy = rotation.transform(getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X), + getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y)); + setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, relativeXy.x); + setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, relativeXy.y); + } + if (BitSet64::hasBit(bits, AMOTION_EVENT_AXIS_ORIENTATION)) { const float val = getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION); setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, transformAngle(transform, val)); @@ -530,6 +541,15 @@ float MotionEvent::getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex, return xy[axis]; } + if (axis == AMOTION_EVENT_AXIS_RELATIVE_X || axis == AMOTION_EVENT_AXIS_RELATIVE_Y) { + // For compatibility, since we convert raw coordinates into "oriented screen space", we + // need to convert the relative axes into the same orientation for consistency. + const vec2 relativeXy = + rotatePoint(mTransform, coords->getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X), + coords->getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y)); + return axis == AMOTION_EVENT_AXIS_RELATIVE_X ? relativeXy.x : relativeXy.y; + } + return coords->getAxisValue(axis); } @@ -545,6 +565,16 @@ float MotionEvent::getHistoricalAxisValue(int32_t axis, size_t pointerIndex, return xy[axis]; } + if (axis == AMOTION_EVENT_AXIS_RELATIVE_X || axis == AMOTION_EVENT_AXIS_RELATIVE_Y) { + const vec2 relativeXy = + applyTransformWithoutTranslation(mTransform, + coords->getAxisValue( + AMOTION_EVENT_AXIS_RELATIVE_X), + coords->getAxisValue( + AMOTION_EVENT_AXIS_RELATIVE_Y)); + return axis == AMOTION_EVENT_AXIS_RELATIVE_X ? relativeXy.x : relativeXy.y; + } + return coords->getAxisValue(axis); } |