Skip to content

Commit fac4d25

Browse files
committed
PointerChoreographer: Starting stylus hover gesture should fade mouse
This is a small UX improvement that fades the mouse when the stylus starts hovering to avoid showing multiple cursors on the screen when the mouse isn't used. Bug: 335849698 Flag: EXEMPT bug fix Test: Presbumit Change-Id: I5849a4e4a8a41201e1e5fd1164214226142625b5
1 parent 8e94d30 commit fac4d25

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
@@ -501,6 +501,14 @@ void PointerChoreographer::processStylusHoverEventLocked(const NotifyMotionArgs&
501501
<< args.dump();
502502
}
503503

504+
// Fade the mouse pointer on the display if there is one when the stylus starts hovering.
505+
if (args.action == AMOTION_EVENT_ACTION_HOVER_ENTER) {
506+
if (const auto it = mMousePointersByDisplay.find(args.displayId);
507+
it != mMousePointersByDisplay.end()) {
508+
it->second->fade(PointerControllerInterface::Transition::GRADUAL);
509+
}
510+
}
511+
504512
// Get the stylus pointer controller for the device, or create one if it doesn't exist.
505513
auto [it, controllerAdded] =
506514
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)