diff options
| author | 2023-01-06 18:02:18 +0000 | |
|---|---|---|
| committer | 2023-01-06 18:02:18 +0000 | |
| commit | 94f5bd52952e4c909278e5290310ef3d749f569e (patch) | |
| tree | 092820fc1639545e095bab98e59b1b3d3ee97fba | |
| parent | 2e2c00f8df0e2bfcadc0b2df544065c82cd42cb9 (diff) | |
TouchpadInputMapper: rotate multi-finger swipes with display
Or more specifically, rotate the fake fingers for them — the
`GESTURE_{X,Y}_OFFSET` axes are unaffected by the screen rotation.
Bug: 263378323
Test: Rotate device to landscape, check multi-finger swipe pointers are rotated
Test: atest inputflinger_tests
Change-Id: I376588f3574f6cd6ba54b5d84a6da3d76b4159f4
| -rw-r--r-- | services/inputflinger/reader/mapper/gestures/GestureConverter.cpp | 12 | ||||
| -rw-r--r-- | services/inputflinger/tests/GestureConverter_test.cpp | 77 |
2 files changed, 85 insertions, 4 deletions
diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp index ffc0523e97..b438b00dfe 100644 --- a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp +++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp @@ -216,12 +216,16 @@ std::list<NotifyArgs> GestureConverter::handleButtonsChange(nsecs_t when, nsecs_ yCursorPosition)); } } + // TODO(b/251196347): Set the gesture properties appropriately to avoid needing to negate the Y + // values. + float rotatedDeltaX = dx, rotatedDeltaY = -dy; + rotateDelta(mOrientation, &rotatedDeltaX, &rotatedDeltaY); for (size_t i = 0; i < mSwipeFingerCount; i++) { PointerCoords& coords = mFakeFingerCoords[i]; - coords.setAxisValue(AMOTION_EVENT_AXIS_X, coords.getAxisValue(AMOTION_EVENT_AXIS_X) + dx); - // TODO(b/251196347): Set the gesture properties appropriately to avoid needing to negate - // the Y values. - coords.setAxisValue(AMOTION_EVENT_AXIS_Y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y) - dy); + coords.setAxisValue(AMOTION_EVENT_AXIS_X, + coords.getAxisValue(AMOTION_EVENT_AXIS_X) + rotatedDeltaX); + coords.setAxisValue(AMOTION_EVENT_AXIS_Y, + coords.getAxisValue(AMOTION_EVENT_AXIS_Y) + rotatedDeltaY); } float xOffset = dx / (mXAxisInfo.maxValue - mXAxisInfo.minValue); // TODO(b/251196347): Set the gesture properties appropriately to avoid needing to negate the Y diff --git a/services/inputflinger/tests/GestureConverter_test.cpp b/services/inputflinger/tests/GestureConverter_test.cpp index 1c7ec7665a..3b54de52a9 100644 --- a/services/inputflinger/tests/GestureConverter_test.cpp +++ b/services/inputflinger/tests/GestureConverter_test.cpp @@ -353,6 +353,83 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); } +TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { + InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); + GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); + converter.setOrientation(ui::ROTATION_90); + + Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, + /* dy= */ 10); + std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); + ASSERT_EQ(4u, args.size()); + + // Three fake fingers should be created. We don't actually care where they are, so long as they + // move appropriately. + NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), + WithPointerCount(1u))); + PointerCoords finger0Start = arg.pointerCoords[0]; + args.pop_front(); + arg = std::get<NotifyMotionArgs>(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); + PointerCoords finger1Start = arg.pointerCoords[1]; + args.pop_front(); + arg = std::get<NotifyMotionArgs>(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | + 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); + PointerCoords finger2Start = arg.pointerCoords[2]; + args.pop_front(); + + arg = std::get<NotifyMotionArgs>(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), + WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); + EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10); + EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10); + EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10); + EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); + EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); + EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); + + Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, + /* dx= */ 0, /* dy= */ 5); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); + ASSERT_EQ(1u, args.size()); + arg = std::get<NotifyMotionArgs>(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), + WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u))); + EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15); + EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15); + EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15); + EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); + EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); + EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); + + Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); + ASSERT_EQ(3u, args.size()); + ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | + 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); + args.pop_front(); + ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); + args.pop_front(); + ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), + WithPointerCount(1u))); +} + TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |