Apply translation/offset to events from pointer sources only
Non-pointer events from a relative motion device such as a trackball or
relative mouse (Pointer Capture) should be oriented in the same way as
the window it is directed to. We want them to be rotated if the window
transform has a rotation applied to it, but these relative events should
not be translated.
We only apply window translation to events from pointer sources because
they are the only ones that refer to absolute coordinates on the
display. We apply rotation for all motion events.
Bug: 179274888
Test: atest inputflinger_tests
Test: manual with test app
Change-Id: I8170697119d3d8e121b7b86de3201bac0edaaed9
diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp
index 32b72ba..97fe9c1 100644
--- a/libs/input/tests/InputEvent_test.cpp
+++ b/libs/input/tests/InputEvent_test.cpp
@@ -588,7 +588,7 @@
}
MotionEvent event;
ui::Transform identityTransform;
- event.initialize(InputEvent::nextId(), 0 /*deviceId*/, AINPUT_SOURCE_UNKNOWN, DISPLAY_ID,
+ event.initialize(InputEvent::nextId(), 0 /*deviceId*/, AINPUT_SOURCE_TOUCHSCREEN, DISPLAY_ID,
INVALID_HMAC, AMOTION_EVENT_ACTION_MOVE, 0 /*actionButton*/, 0 /*flags*/,
AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, 0 /*buttonState*/,
MotionClassification::NONE, identityTransform, 0 /*xPrecision*/,
@@ -683,6 +683,26 @@
ASSERT_NEAR(event.getY(0), changedEvent.getY(0), 0.001);
}
+TEST_F(MotionEventTest, NonPointerSourcesAreNotTranslated) {
+ constexpr static auto NON_POINTER_SOURCES = {AINPUT_SOURCE_TRACKBALL,
+ AINPUT_SOURCE_MOUSE_RELATIVE,
+ AINPUT_SOURCE_JOYSTICK};
+ for (uint32_t source : NON_POINTER_SOURCES) {
+ // Create a rotate-90 transform with an offset (like a window which isn't fullscreen).
+ ui::Transform xform(ui::Transform::ROT_90, 800, 400);
+ xform.set(xform.tx() + 20, xform.ty() + 40);
+ MotionEvent event = createTouchDownEvent(60, 100, xform);
+ event.setSource(source);
+
+ // Since this event comes from a non-pointer source, it should include rotation but not
+ // translation/offset.
+ ASSERT_EQ(-100, event.getX(0));
+ ASSERT_EQ(60, event.getY(0));
+ ASSERT_EQ(event.getRawX(0), event.getX(0));
+ ASSERT_EQ(event.getRawY(0), event.getY(0));
+ }
+}
+
TEST_F(MotionEventTest, RawCompatTransform) {
{
// Make sure raw is raw regardless of transform translation.