Loading services/inputflinger/PointerChoreographer.cpp +34 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #if defined(__ANDROID__) #include <gui/SurfaceComposerClient.h> #endif #include <input/Keyboard.h> #include <input/PrintTools.h> #include <unordered_set> Loading Loading @@ -137,6 +138,7 @@ PointerChoreographer::PointerChoreographer( mNotifiedPointerDisplayId(ui::LogicalDisplayId::INVALID), mShowTouchesEnabled(false), mStylusPointerIconEnabled(false), mCurrentFocusedDisplay(ui::LogicalDisplayId::DEFAULT), mRegisterListener(registerListener), mUnregisterListener(unregisterListener) {} Loading Loading @@ -168,6 +170,7 @@ void PointerChoreographer::notifyConfigurationChanged(const NotifyConfigurationC } void PointerChoreographer::notifyKey(const NotifyKeyArgs& args) { fadeMouseCursorOnKeyPress(args); mNextListener.notify(args); } Loading @@ -177,6 +180,32 @@ void PointerChoreographer::notifyMotion(const NotifyMotionArgs& args) { mNextListener.notify(newArgs); } void PointerChoreographer::fadeMouseCursorOnKeyPress(const android::NotifyKeyArgs& args) { if (args.action == AKEY_EVENT_ACTION_UP || isMetaKey(args.keyCode)) { return; } // Meta state for these keys is ignored for dismissing cursor while typing constexpr static int32_t ALLOW_FADING_META_STATE_MASK = AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON | AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_RIGHT_ON | AMETA_SHIFT_ON; if (args.metaState & ~ALLOW_FADING_META_STATE_MASK) { // Do not fade if any other meta state is active return; } if (!mPolicy.isInputMethodConnectionActive()) { return; } std::scoped_lock _l(mLock); ui::LogicalDisplayId targetDisplay = args.displayId; if (targetDisplay == ui::LogicalDisplayId::INVALID) { targetDisplay = mCurrentFocusedDisplay; } auto it = mMousePointersByDisplay.find(targetDisplay); if (it != mMousePointersByDisplay.end()) { it->second->fade(PointerControllerInterface::Transition::GRADUAL); } } NotifyMotionArgs PointerChoreographer::processMotion(const NotifyMotionArgs& args) { std::scoped_lock _l(mLock); Loading Loading @@ -806,6 +835,11 @@ void PointerChoreographer::setPointerIconVisibility(ui::LogicalDisplayId display } } void PointerChoreographer::setFocusedDisplay(ui::LogicalDisplayId displayId) { std::scoped_lock lock(mLock); mCurrentFocusedDisplay = displayId; } PointerChoreographer::ControllerConstructor PointerChoreographer::getMouseControllerConstructor( ui::LogicalDisplayId displayId) { std::function<std::shared_ptr<PointerControllerInterface>()> ctor = Loading services/inputflinger/PointerChoreographer.h +8 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,11 @@ public: */ virtual void setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible) = 0; /** * Used by Dispatcher to notify changes in the current focused display. */ virtual void setFocusedDisplay(ui::LogicalDisplayId displayId) = 0; /** * This method may be called on any thread (usually by the input manager on a binder thread). */ Loading @@ -97,6 +102,7 @@ public: bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, ui::LogicalDisplayId displayId, DeviceId deviceId) override; void setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible) override; void setFocusedDisplay(ui::LogicalDisplayId displayId) override; void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override; void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override; Loading Loading @@ -124,6 +130,7 @@ private: InputDeviceInfo* findInputDeviceLocked(DeviceId deviceId) REQUIRES(mLock); bool canUnfadeOnDisplay(ui::LogicalDisplayId displayId) REQUIRES(mLock); void fadeMouseCursorOnKeyPress(const NotifyKeyArgs& args); NotifyMotionArgs processMotion(const NotifyMotionArgs& args); NotifyMotionArgs processMouseEventLocked(const NotifyMotionArgs& args) REQUIRES(mLock); NotifyMotionArgs processTouchpadEventLocked(const NotifyMotionArgs& args) REQUIRES(mLock); Loading Loading @@ -192,6 +199,7 @@ private: bool mShowTouchesEnabled GUARDED_BY(mLock); bool mStylusPointerIconEnabled GUARDED_BY(mLock); std::set<ui::LogicalDisplayId /*displayId*/> mDisplaysWithPointersHidden; ui::LogicalDisplayId mCurrentFocusedDisplay GUARDED_BY(mLock); protected: using WindowListenerRegisterConsumer = std::function<std::vector<gui::WindowInfo>( Loading services/inputflinger/dispatcher/InputDispatcher.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -5526,6 +5526,13 @@ void InputDispatcher::setFocusedDisplay(ui::LogicalDisplayId displayId) { synthesizeCancelationEventsForWindowLocked(windowHandle, options); } mFocusedDisplayId = displayId; // Enqueue a command to run outside the lock to tell the policy that the focused display // changed. auto command = [this]() REQUIRES(mLock) { scoped_unlock unlock(mLock); mPolicy.notifyFocusedDisplayChanged(mFocusedDisplayId); }; postCommandLocked(std::move(command)); // Only a window on the focused display can have Pointer Capture, so disable the active // Pointer Capture session if there is one, since the focused display changed. Loading services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h +5 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,11 @@ public: InputDeviceSensorAccuracy accuracy) = 0; virtual void notifyVibratorState(int32_t deviceId, bool isOn) = 0; /* * Notifies the system that focused display has changed. */ virtual void notifyFocusedDisplayChanged(ui::LogicalDisplayId displayId) = 0; /* Filters an input event. * Return true to dispatch the event unmodified, false to consume the event. * A filter can also transform and inject events later by passing POLICY_FLAG_FILTERED Loading services/inputflinger/include/NotifyArgsBuilders.h +7 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include <attestation/HmacKeyManager.h> #include <input/Input.h> #include <input/InputEventBuilders.h> #include <input/Keyboard.h> #include <utils/Timers.h> // for nsecs_t, systemTime #include <vector> Loading Loading @@ -206,6 +207,12 @@ public: return *this; } KeyArgsBuilder& metaState(int32_t metaState) { mMetaState |= metaState; mMetaState = normalizeMetaState(/*oldMetaState=*/mMetaState); return *this; } NotifyKeyArgs build() const { return {mEventId, mEventTime, Loading Loading
services/inputflinger/PointerChoreographer.cpp +34 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #if defined(__ANDROID__) #include <gui/SurfaceComposerClient.h> #endif #include <input/Keyboard.h> #include <input/PrintTools.h> #include <unordered_set> Loading Loading @@ -137,6 +138,7 @@ PointerChoreographer::PointerChoreographer( mNotifiedPointerDisplayId(ui::LogicalDisplayId::INVALID), mShowTouchesEnabled(false), mStylusPointerIconEnabled(false), mCurrentFocusedDisplay(ui::LogicalDisplayId::DEFAULT), mRegisterListener(registerListener), mUnregisterListener(unregisterListener) {} Loading Loading @@ -168,6 +170,7 @@ void PointerChoreographer::notifyConfigurationChanged(const NotifyConfigurationC } void PointerChoreographer::notifyKey(const NotifyKeyArgs& args) { fadeMouseCursorOnKeyPress(args); mNextListener.notify(args); } Loading @@ -177,6 +180,32 @@ void PointerChoreographer::notifyMotion(const NotifyMotionArgs& args) { mNextListener.notify(newArgs); } void PointerChoreographer::fadeMouseCursorOnKeyPress(const android::NotifyKeyArgs& args) { if (args.action == AKEY_EVENT_ACTION_UP || isMetaKey(args.keyCode)) { return; } // Meta state for these keys is ignored for dismissing cursor while typing constexpr static int32_t ALLOW_FADING_META_STATE_MASK = AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON | AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_RIGHT_ON | AMETA_SHIFT_ON; if (args.metaState & ~ALLOW_FADING_META_STATE_MASK) { // Do not fade if any other meta state is active return; } if (!mPolicy.isInputMethodConnectionActive()) { return; } std::scoped_lock _l(mLock); ui::LogicalDisplayId targetDisplay = args.displayId; if (targetDisplay == ui::LogicalDisplayId::INVALID) { targetDisplay = mCurrentFocusedDisplay; } auto it = mMousePointersByDisplay.find(targetDisplay); if (it != mMousePointersByDisplay.end()) { it->second->fade(PointerControllerInterface::Transition::GRADUAL); } } NotifyMotionArgs PointerChoreographer::processMotion(const NotifyMotionArgs& args) { std::scoped_lock _l(mLock); Loading Loading @@ -806,6 +835,11 @@ void PointerChoreographer::setPointerIconVisibility(ui::LogicalDisplayId display } } void PointerChoreographer::setFocusedDisplay(ui::LogicalDisplayId displayId) { std::scoped_lock lock(mLock); mCurrentFocusedDisplay = displayId; } PointerChoreographer::ControllerConstructor PointerChoreographer::getMouseControllerConstructor( ui::LogicalDisplayId displayId) { std::function<std::shared_ptr<PointerControllerInterface>()> ctor = Loading
services/inputflinger/PointerChoreographer.h +8 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,11 @@ public: */ virtual void setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible) = 0; /** * Used by Dispatcher to notify changes in the current focused display. */ virtual void setFocusedDisplay(ui::LogicalDisplayId displayId) = 0; /** * This method may be called on any thread (usually by the input manager on a binder thread). */ Loading @@ -97,6 +102,7 @@ public: bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, ui::LogicalDisplayId displayId, DeviceId deviceId) override; void setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible) override; void setFocusedDisplay(ui::LogicalDisplayId displayId) override; void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override; void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override; Loading Loading @@ -124,6 +130,7 @@ private: InputDeviceInfo* findInputDeviceLocked(DeviceId deviceId) REQUIRES(mLock); bool canUnfadeOnDisplay(ui::LogicalDisplayId displayId) REQUIRES(mLock); void fadeMouseCursorOnKeyPress(const NotifyKeyArgs& args); NotifyMotionArgs processMotion(const NotifyMotionArgs& args); NotifyMotionArgs processMouseEventLocked(const NotifyMotionArgs& args) REQUIRES(mLock); NotifyMotionArgs processTouchpadEventLocked(const NotifyMotionArgs& args) REQUIRES(mLock); Loading Loading @@ -192,6 +199,7 @@ private: bool mShowTouchesEnabled GUARDED_BY(mLock); bool mStylusPointerIconEnabled GUARDED_BY(mLock); std::set<ui::LogicalDisplayId /*displayId*/> mDisplaysWithPointersHidden; ui::LogicalDisplayId mCurrentFocusedDisplay GUARDED_BY(mLock); protected: using WindowListenerRegisterConsumer = std::function<std::vector<gui::WindowInfo>( Loading
services/inputflinger/dispatcher/InputDispatcher.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -5526,6 +5526,13 @@ void InputDispatcher::setFocusedDisplay(ui::LogicalDisplayId displayId) { synthesizeCancelationEventsForWindowLocked(windowHandle, options); } mFocusedDisplayId = displayId; // Enqueue a command to run outside the lock to tell the policy that the focused display // changed. auto command = [this]() REQUIRES(mLock) { scoped_unlock unlock(mLock); mPolicy.notifyFocusedDisplayChanged(mFocusedDisplayId); }; postCommandLocked(std::move(command)); // Only a window on the focused display can have Pointer Capture, so disable the active // Pointer Capture session if there is one, since the focused display changed. Loading
services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h +5 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,11 @@ public: InputDeviceSensorAccuracy accuracy) = 0; virtual void notifyVibratorState(int32_t deviceId, bool isOn) = 0; /* * Notifies the system that focused display has changed. */ virtual void notifyFocusedDisplayChanged(ui::LogicalDisplayId displayId) = 0; /* Filters an input event. * Return true to dispatch the event unmodified, false to consume the event. * A filter can also transform and inject events later by passing POLICY_FLAG_FILTERED Loading
services/inputflinger/include/NotifyArgsBuilders.h +7 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include <attestation/HmacKeyManager.h> #include <input/Input.h> #include <input/InputEventBuilders.h> #include <input/Keyboard.h> #include <utils/Timers.h> // for nsecs_t, systemTime #include <vector> Loading Loading @@ -206,6 +207,12 @@ public: return *this; } KeyArgsBuilder& metaState(int32_t metaState) { mMetaState |= metaState; mMetaState = normalizeMetaState(/*oldMetaState=*/mMetaState); return *this; } NotifyKeyArgs build() const { return {mEventId, mEventTime, Loading