Skip to content

Commit 2662709

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "PointerChoreographer: Starting stylus hover gesture should fade mouse" into main
2 parents f4fb328 + fac4d25 commit 2662709

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

services/inputflinger/PointerChoreographer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,14 @@ void PointerChoreographer::processStylusHoverEventLocked(const NotifyMotionArgs&
476476
<< args.dump();
477477
}
478478

479+
// Fade the mouse pointer on the display if there is one when the stylus starts hovering.
480+
if (args.action == AMOTION_EVENT_ACTION_HOVER_ENTER) {
481+
if (const auto it = mMousePointersByDisplay.find(args.displayId);
482+
it != mMousePointersByDisplay.end()) {
483+
it->second->fade(PointerControllerInterface::Transition::GRADUAL);
484+
}
485+
}
486+
479487
// Get the stylus pointer controller for the device, or create one if it doesn't exist.
480488
auto [it, controllerAdded] =
481489
mStylusPointersByDevice.try_emplace(args.deviceId,

services/inputflinger/tests/PointerChoreographer_test.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,34 @@ TEST_F(PointerChoreographerTest, ShowTouchesOverridesUnspecifiedStylusIcon) {
10081008
pc->assertPointerIconSet(PointerIconStyle::TYPE_SPOT_HOVER);
10091009
}
10101010

1011+
TEST_F(PointerChoreographerTest, StylusHoverEnterFadesMouseOnDisplay) {
1012+
// Make sure there are PointerControllers for a mouse and a stylus.
1013+
mChoreographer.setStylusPointerIconEnabled(true);
1014+
mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID);
1015+
mChoreographer.notifyInputDevicesChanged(
1016+
{/*id=*/0,
1017+
{generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID),
1018+
generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_STYLUS, DISPLAY_ID)}});
1019+
mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID}));
1020+
mChoreographer.notifyMotion(
1021+
MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
1022+
.pointer(MOUSE_POINTER)
1023+
.deviceId(DEVICE_ID)
1024+
.displayId(ui::LogicalDisplayId::INVALID)
1025+
.build());
1026+
auto mousePc = assertPointerControllerCreated(ControllerType::MOUSE);
1027+
ASSERT_TRUE(mousePc->isPointerShown());
1028+
1029+
// Start hovering with a stylus. This should fade the mouse cursor.
1030+
mChoreographer.notifyMotion(
1031+
MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS)
1032+
.pointer(STYLUS_POINTER)
1033+
.deviceId(SECOND_DEVICE_ID)
1034+
.displayId(DISPLAY_ID)
1035+
.build());
1036+
ASSERT_FALSE(mousePc->isPointerShown());
1037+
}
1038+
10111039
using StylusFixtureParam =
10121040
std::tuple</*name*/ std::string_view, /*source*/ uint32_t, ControllerType>;
10131041

0 commit comments

Comments
 (0)