From fac4d25226b0dae77758fc71ffc78de2b024a47e Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Thu, 13 Feb 2025 20:59:39 +0000 Subject: 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 --- services/inputflinger/PointerChoreographer.cpp | 8 +++++++ .../tests/PointerChoreographer_test.cpp | 28 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'services/inputflinger') diff --git a/services/inputflinger/PointerChoreographer.cpp b/services/inputflinger/PointerChoreographer.cpp index 3140dc86e9..a062f28587 100644 --- a/services/inputflinger/PointerChoreographer.cpp +++ b/services/inputflinger/PointerChoreographer.cpp @@ -501,6 +501,14 @@ void PointerChoreographer::processStylusHoverEventLocked(const NotifyMotionArgs& << args.dump(); } + // Fade the mouse pointer on the display if there is one when the stylus starts hovering. + if (args.action == AMOTION_EVENT_ACTION_HOVER_ENTER) { + if (const auto it = mMousePointersByDisplay.find(args.displayId); + it != mMousePointersByDisplay.end()) { + it->second->fade(PointerControllerInterface::Transition::GRADUAL); + } + } + // Get the stylus pointer controller for the device, or create one if it doesn't exist. auto [it, controllerAdded] = mStylusPointersByDevice.try_emplace(args.deviceId, diff --git a/services/inputflinger/tests/PointerChoreographer_test.cpp b/services/inputflinger/tests/PointerChoreographer_test.cpp index 1286a3675c..c5de9f0515 100644 --- a/services/inputflinger/tests/PointerChoreographer_test.cpp +++ b/services/inputflinger/tests/PointerChoreographer_test.cpp @@ -1008,6 +1008,34 @@ TEST_F(PointerChoreographerTest, ShowTouchesOverridesUnspecifiedStylusIcon) { pc->assertPointerIconSet(PointerIconStyle::TYPE_SPOT_HOVER); } +TEST_F(PointerChoreographerTest, StylusHoverEnterFadesMouseOnDisplay) { + // Make sure there are PointerControllers for a mouse and a stylus. + mChoreographer.setStylusPointerIconEnabled(true); + mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); + mChoreographer.notifyInputDevicesChanged( + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID), + generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_STYLUS, DISPLAY_ID)}}); + mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); + mChoreographer.notifyMotion( + MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) + .pointer(MOUSE_POINTER) + .deviceId(DEVICE_ID) + .displayId(ui::LogicalDisplayId::INVALID) + .build()); + auto mousePc = assertPointerControllerCreated(ControllerType::MOUSE); + ASSERT_TRUE(mousePc->isPointerShown()); + + // Start hovering with a stylus. This should fade the mouse cursor. + mChoreographer.notifyMotion( + MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) + .pointer(STYLUS_POINTER) + .deviceId(SECOND_DEVICE_ID) + .displayId(DISPLAY_ID) + .build()); + ASSERT_FALSE(mousePc->isPointerShown()); +} + using StylusFixtureParam = std::tuple; -- cgit v1.2.3-59-g8ed1b