Pointer icon refactor for touchpad
With PointerChoreographer enabled, touchpads work similar to mice,
using MousePointerController of the associated display.
For some gestures like scroll or multi-finger swipes,
TouchpadInputMapper sets fake finger coordinates and
PointerChoreographer combines cursor position with them.
Test: atest inputflinger_tests
Bug: 293587049
Change-Id: I0f6588c79004284df98d99351ea3c3e64b636a74
diff --git a/services/inputflinger/PointerChoreographer.cpp b/services/inputflinger/PointerChoreographer.cpp
index e529bdd..f1faf69 100644
--- a/services/inputflinger/PointerChoreographer.cpp
+++ b/services/inputflinger/PointerChoreographer.cpp
@@ -31,6 +31,11 @@
args.pointerProperties[0].toolType == ToolType::MOUSE;
}
+bool isFromTouchpad(const NotifyMotionArgs& args) {
+ return isFromSource(args.source, AINPUT_SOURCE_MOUSE) &&
+ args.pointerProperties[0].toolType == ToolType::FINGER;
+}
+
bool isHoverAction(int32_t action) {
return action == AMOTION_EVENT_ACTION_HOVER_ENTER ||
action == AMOTION_EVENT_ACTION_HOVER_MOVE || action == AMOTION_EVENT_ACTION_HOVER_EXIT;
@@ -83,6 +88,8 @@
if (isFromMouse(args)) {
return processMouseEventLocked(args);
+ } else if (isFromTouchpad(args)) {
+ return processTouchpadEventLocked(args);
} else if (mStylusPointerIconEnabled && isStylusHoverEvent(args)) {
processStylusHoverEventLocked(args);
} else if (isFromSource(args.source, AINPUT_SOURCE_TOUCHSCREEN)) {
@@ -97,17 +104,7 @@
<< args.dump();
}
- const int32_t displayId = getTargetMouseDisplayLocked(args.displayId);
-
- // Get the mouse pointer controller for the display, or create one if it doesn't exist.
- auto [it, emplaced] =
- mMousePointersByDisplay.try_emplace(displayId,
- getMouseControllerConstructor(displayId));
- if (emplaced) {
- notifyPointerDisplayIdChangedLocked();
- }
-
- PointerControllerInterface& pc = *it->second;
+ auto [displayId, pc] = getDisplayIdAndMouseControllerLocked(args.displayId);
const float deltaX = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X);
const float deltaY = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y);
@@ -124,6 +121,40 @@
return newArgs;
}
+NotifyMotionArgs PointerChoreographer::processTouchpadEventLocked(const NotifyMotionArgs& args) {
+ auto [displayId, pc] = getDisplayIdAndMouseControllerLocked(args.displayId);
+
+ NotifyMotionArgs newArgs(args);
+ newArgs.displayId = displayId;
+ if (args.getPointerCount() == 1 && args.classification == MotionClassification::NONE) {
+ // This is a movement of the mouse pointer.
+ const float deltaX = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X);
+ const float deltaY = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y);
+ pc.move(deltaX, deltaY);
+ pc.unfade(PointerControllerInterface::Transition::IMMEDIATE);
+
+ const auto [x, y] = pc.getPosition();
+ newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
+ newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
+ newArgs.xCursorPosition = x;
+ newArgs.yCursorPosition = y;
+ } else {
+ // This is a trackpad gesture with fake finger(s) that should not move the mouse pointer.
+ pc.unfade(PointerControllerInterface::Transition::IMMEDIATE);
+
+ const auto [x, y] = pc.getPosition();
+ for (uint32_t i = 0; i < newArgs.getPointerCount(); i++) {
+ newArgs.pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X,
+ args.pointerCoords[i].getX() + x);
+ newArgs.pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y,
+ args.pointerCoords[i].getY() + y);
+ }
+ newArgs.xCursorPosition = x;
+ newArgs.yCursorPosition = y;
+ }
+ return newArgs;
+}
+
/**
* When screen is touched, fade the mouse pointer on that display. We only call fade for
* ACTION_DOWN events.This would allow both mouse and touch to be used at the same time if the
@@ -270,6 +301,21 @@
return associatedDisplayId == ADISPLAY_ID_NONE ? mDefaultMouseDisplayId : associatedDisplayId;
}
+std::pair<int32_t, PointerControllerInterface&>
+PointerChoreographer::getDisplayIdAndMouseControllerLocked(int32_t associatedDisplayId) {
+ const int32_t displayId = getTargetMouseDisplayLocked(associatedDisplayId);
+
+ // Get the mouse pointer controller for the display, or create one if it doesn't exist.
+ auto [it, emplaced] =
+ mMousePointersByDisplay.try_emplace(displayId,
+ getMouseControllerConstructor(displayId));
+ if (emplaced) {
+ notifyPointerDisplayIdChangedLocked();
+ }
+
+ return {displayId, *it->second};
+}
+
InputDeviceInfo* PointerChoreographer::findInputDeviceLocked(DeviceId deviceId) {
auto it = std::find_if(mInputDeviceInfos.begin(), mInputDeviceInfos.end(),
[deviceId](const auto& info) { return info.getId() == deviceId; });