diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index e20e0f7b..4ba32e0a 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -45,11 +45,6 @@ public: virtual void OnSizeChange(Rect rect) = 0; }; -class IWindowSystemBarChangeListener : public RefBase { -public: - virtual void OnSystemBarPropertyChange(uint32_t displayId, WindowType type, const SystemBarProperty& prop) = 0; -}; - class Window : public RefBase { public: static sptr Create(const std::string& windowName, @@ -89,7 +84,6 @@ public: virtual void RegisterLifeCycleListener(sptr& listener) = 0; virtual void RegisterWindowChangeListener(sptr& listener) = 0; - virtual void RegisterWindowSystemBarChangeListener(sptr& listener) = 0; virtual WMError SetUIContent(std::shared_ptr context, std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0; virtual const std::string& GetContentInfo() = 0; diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index 8572d2fb..66538d75 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -34,12 +34,19 @@ public: WindowType windowType, int32_t displayId) = 0; }; +class ISystemBarChangedListener : public RefBase { +public: + virtual void OnSystemBarPropertyChange(uint64_t displayId, const SystemBarProps& props) = 0; +}; + class WindowManager : public RefBase { WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManager); friend class WindowManagerAgent; public: void RegisterFocusChangedListener(const sptr& listener); void UnregisterFocusChangedListener(const sptr& listener); + void RegisterSystemBarChangedListener(const sptr& listener); + void UnregisterSystemBarChangedListener(const sptr& listener); private: WindowManager(); @@ -49,6 +56,7 @@ private: void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) const; + void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) const; }; } // namespace Rosen } // namespace OHOS diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 388086cd..f281ede7 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -93,6 +93,13 @@ enum class WindowFlag : uint32_t { WINDOW_FLAG_END = 1 << 2, }; +struct Rect { + int32_t posX_; + int32_t posY_; + uint32_t width_; + uint32_t height_; +}; + namespace { constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF; constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000; @@ -111,12 +118,7 @@ struct SystemBarProperty { } }; -struct Rect { - int32_t posX_; - int32_t posY_; - uint32_t width_; - uint32_t height_; -}; +using SystemBarProps = std::vector>; } } #endif // OHOS_ROSEN_WM_COMMON_H diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 836a7cae..66cc0dc8 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -47,8 +47,10 @@ public: virtual WMError SetWindowFlags(uint32_t windowId, uint32_t flags); virtual WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); - virtual void RegisterFocusChangedListener(const sptr& windowManagerAgent); - virtual void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + virtual void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); + virtual void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); virtual void ClearWindowAdapter(); private: diff --git a/wm/include/window_agent.h b/wm/include/window_agent.h index 60130bdb..31bd1ccd 100644 --- a/wm/include/window_agent.h +++ b/wm/include/window_agent.h @@ -30,7 +30,6 @@ public: void UpdateWindowRect(const struct Rect& rect) override; void UpdateWindowMode(WindowMode mode) override; void UpdateFocusStatus(bool focused) override; - void UpdateSystemBarProperty(const SystemBarProperty& prop) override; private: sptr window_; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 53e19417..8e8480bc 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -71,7 +71,6 @@ public: virtual void RegisterLifeCycleListener(sptr& listener) override; virtual void RegisterWindowChangeListener(sptr& listener) override; - virtual void RegisterWindowSystemBarChangeListener(sptr& listener) override; void UpdateRect(const struct Rect& rect); void UpdateMode(WindowMode mode); @@ -79,7 +78,6 @@ public: virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) override; virtual void RequestFrame() override; void UpdateFocusStatus(bool focused); - void UpdateSystemBarProperty(const SystemBarProperty& prop); virtual void UpdateConfiguration(const std::shared_ptr& configuration) override; virtual WMError SetUIContent(std::shared_ptr context, @@ -130,7 +128,6 @@ private: WindowState state_ { STATE_INITIAL }; sptr lifecycleListener_; sptr windowChangeListener_; - sptr systemBarChangeListener_; std::shared_ptr surfaceNode_; std::string name_; std::unique_ptr uiContent_; diff --git a/wm/include/window_interface.h b/wm/include/window_interface.h index f3f03c0f..846ded86 100644 --- a/wm/include/window_interface.h +++ b/wm/include/window_interface.h @@ -30,14 +30,12 @@ public: TRANS_ID_UPDATE_WINDOW_RECT, TRANS_ID_UPDATE_WINDOW_MODE, TRANS_ID_UPDATE_FOCUS_STATUS, - TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, }; virtual void UpdateWindowProperty(const WindowProperty& windowProperty) = 0; virtual void UpdateWindowRect(const struct Rect& rect) = 0; virtual void UpdateWindowMode(WindowMode mode) = 0; virtual void UpdateFocusStatus(bool focused) = 0; - virtual void UpdateSystemBarProperty(const SystemBarProperty& prop) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/window_manager_agent.h b/wm/include/window_manager_agent.h index 60318d51..dd4717b4 100644 --- a/wm/include/window_manager_agent.h +++ b/wm/include/window_manager_agent.h @@ -27,6 +27,7 @@ public: void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) override; + void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) override; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/window_proxy.h b/wm/include/window_proxy.h index b7675950..8e1ea4a5 100644 --- a/wm/include/window_proxy.h +++ b/wm/include/window_proxy.h @@ -31,7 +31,6 @@ public: void UpdateWindowRect(const struct Rect& rect) override; void UpdateWindowMode(WindowMode mode) override; void UpdateFocusStatus(bool focused) override; - void UpdateSystemBarProperty(const SystemBarProperty& prop) override; private: static inline BrokerDelegator delegator_; diff --git a/wm/include/zidl/window_manager_agent_interface.h b/wm/include/zidl/window_manager_agent_interface.h index 5f12fc61..2ea31279 100644 --- a/wm/include/zidl/window_manager_agent_interface.h +++ b/wm/include/zidl/window_manager_agent_interface.h @@ -21,16 +21,23 @@ namespace OHOS { namespace Rosen { +enum class WindowManagerAgentType : uint32_t { + WINDOW_MANAGER_AGENT_TYPE_FOCUS, + WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, +}; + class IWindowManagerAgent : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManagerAgent"); enum { TRANS_ID_UPDATE_FOCUS_STATUS = 1, + TRANS_ID_UPDATE_SYSTEM_BAR_PROPS = 2, }; virtual void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) = 0; + virtual void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/zidl/window_manager_agent_proxy.h b/wm/include/zidl/window_manager_agent_proxy.h index 4798dde4..e3011faa 100644 --- a/wm/include/zidl/window_manager_agent_proxy.h +++ b/wm/include/zidl/window_manager_agent_proxy.h @@ -29,6 +29,7 @@ public: void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) override; + void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) override; private: static inline BrokerDelegator delegator_; diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 08d1f93c..7e68e1ce 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -126,24 +126,26 @@ WMError WindowAdapter::SetSystemBarProperty(uint32_t windowId, WindowType type, return windowManagerServiceProxy_->SetSystemBarProperty(windowId, type, property); } -void WindowAdapter::RegisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowAdapter::RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return; } - return windowManagerServiceProxy_->RegisterFocusChangedListener(windowManagerAgent); + return windowManagerServiceProxy_->RegisterWindowManagerAgent(type, windowManagerAgent); } -void WindowAdapter::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowAdapter::UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return; } - return windowManagerServiceProxy_->UnregisterFocusChangedListener(windowManagerAgent); + return windowManagerServiceProxy_->UnregisterWindowManagerAgent(type, windowManagerAgent); } bool WindowAdapter::InitWMSProxyLocked() diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp index ad337d12..79f7a285 100644 --- a/wm/src/window_agent.cpp +++ b/wm/src/window_agent.cpp @@ -57,14 +57,5 @@ void WindowAgent::UpdateFocusStatus(bool focused) } window_->UpdateFocusStatus(focused); } - -void WindowAgent::UpdateSystemBarProperty(const SystemBarProperty& prop) -{ - if (window_ == nullptr) { - WLOGFE("window_ is nullptr"); - return; - } - window_->UpdateSystemBarProperty(prop); -} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index e58209c8..bf220791 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -455,10 +455,6 @@ void WindowImpl::RegisterWindowChangeListener(sptr& liste windowChangeListener_ = listener; } -void WindowImpl::RegisterWindowSystemBarChangeListener(sptr& listener) -{ - systemBarChangeListener_ = listener; -} void WindowImpl::UpdateRect(const struct Rect& rect) { WLOGFI("winId:%{public}d, rect[%{public}d, %{public}d, %{public}d, %{public}d]", GetWindowId(), rect.posX_, @@ -539,16 +535,6 @@ void WindowImpl::UpdateFocusStatus(bool focused) } } -void WindowImpl::UpdateSystemBarProperty(const SystemBarProperty& prop) -{ - WLOGFI("winId:%{public}d, enable:%{public}d, backgroundColor:%{public}x, contentColor:%{public}x", GetWindowId(), - prop.enable_, prop.backgroundColor_, prop.contentColor_); - if (systemBarChangeListener_ != nullptr) { - systemBarChangeListener_->OnSystemBarPropertyChange(property_->GetDisplayId(), - property_->GetWindowType(), prop); - } -} - void WindowImpl::UpdateConfiguration(const std::shared_ptr& configuration) { if (uiContent_ != nullptr) { diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index 45713eb6..6753df7a 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -32,12 +32,14 @@ public: WindowType windowType, int32_t displayId) const; void NotifyUnfocused(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId) const; - + void NotifySystemBarChanged(uint64_t displayId, const SystemBarProps& props) const; static inline SingletonDelegator delegator_; std::mutex mutex_; std::vector> focusChangedListeners_; sptr focusChangedListenerAgent_; + std::vector> systemBarChangedListeners_; + sptr systemBarChangedListenerAgent_; }; void WindowManager::Impl::NotifyFocused(uint32_t windowId, const sptr& abilityToken, @@ -60,6 +62,18 @@ void WindowManager::Impl::NotifyUnfocused(uint32_t windowId, const sptrOnSystemBarPropertyChange(displayId, props); + } +} + WindowManager::WindowManager() : pImpl_(std::make_unique()) { } @@ -79,7 +93,8 @@ void WindowManager::RegisterFocusChangedListener(const sptrfocusChangedListeners_.push_back(listener); if (pImpl_->focusChangedListenerAgent_ == nullptr) { pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent(); - SingletonContainer::Get().RegisterFocusChangedListener(pImpl_->focusChangedListenerAgent_); + SingletonContainer::Get().RegisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); } } @@ -98,7 +113,45 @@ void WindowManager::UnregisterFocusChangedListener(const sptrfocusChangedListeners_.erase(iter); if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) { - SingletonContainer::Get().UnregisterFocusChangedListener(pImpl_->focusChangedListenerAgent_); + SingletonContainer::Get().UnregisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); + } +} + +void WindowManager::RegisterSystemBarChangedListener(const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return; + } + + std::lock_guard lock(pImpl_->mutex_); + pImpl_->systemBarChangedListeners_.push_back(listener); + if (pImpl_->systemBarChangedListenerAgent_ == nullptr) { + pImpl_->systemBarChangedListenerAgent_ = new WindowManagerAgent(); + SingletonContainer::Get().RegisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_); + } +} + +void WindowManager::UnregisterSystemBarChangedListener(const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return; + } + + std::lock_guard lock(pImpl_->mutex_); + auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(), + listener); + if (iter == pImpl_->systemBarChangedListeners_.end()) { + WLOGFE("could not find this listener"); + return; + } + pImpl_->systemBarChangedListeners_.erase(iter); + if (pImpl_->systemBarChangedListeners_.empty() && pImpl_->systemBarChangedListenerAgent_ != nullptr) { + SingletonContainer::Get().UnregisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_); } } @@ -112,5 +165,11 @@ void WindowManager::UpdateFocusStatus(uint32_t windowId, const sptrNotifyUnfocused(windowId, abilityToken, windowType, displayId); } } + +void WindowManager::UpdateSystemBarProperties(uint64_t displayId, + const SystemBarProps& props) const +{ + pImpl_->NotifySystemBarChanged(displayId, props); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wm/src/window_manager_agent.cpp b/wm/src/window_manager_agent.cpp index 83c13348..6767bb60 100644 --- a/wm/src/window_manager_agent.cpp +++ b/wm/src/window_manager_agent.cpp @@ -24,5 +24,10 @@ void WindowManagerAgent::UpdateFocusStatus(uint32_t windowId, const sptr().UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); } + +void WindowManagerAgent::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) +{ + SingletonContainer::Get().UpdateSystemBarProperties(displayId, props); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_property.cpp b/wm/src/window_property.cpp index 6b22e7cb..b8253ef5 100644 --- a/wm/src/window_property.cpp +++ b/wm/src/window_property.cpp @@ -168,7 +168,7 @@ bool WindowProperty::MapMarshalling(Parcel& parcel) const if (!parcel.WriteUint32(static_cast(it.first))) { return false; } - // write val(UIState) + // write val(sysBarProps) if (!(parcel.WriteBool(it.second.enable_) && parcel.WriteUint32(it.second.backgroundColor_) && parcel.WriteUint32(it.second.contentColor_))) { return false; diff --git a/wm/src/window_proxy.cpp b/wm/src/window_proxy.cpp index fe12a88f..7334d6bb 100644 --- a/wm/src/window_proxy.cpp +++ b/wm/src/window_proxy.cpp @@ -53,26 +53,6 @@ void WindowProxy::UpdateWindowRect(const struct Rect& rect) return; } -void WindowProxy::UpdateSystemBarProperty(const SystemBarProperty& prop) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("WriteInterfaceToken failed"); - return; - } - if (!(data.WriteBool(prop.enable_) && data.WriteUint32(prop.backgroundColor_) && - data.WriteUint32(prop.contentColor_))) { - WLOGFE("Write property failed"); - return; - } - if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, data, reply, option) != ERR_NONE) { - WLOGFE("SendRequest failed"); - } - return; -} - void WindowProxy::UpdateWindowMode(WindowMode mode) { MessageParcel data; diff --git a/wm/src/window_stub.cpp b/wm/src/window_stub.cpp index c0b6485f..06e9b8bd 100644 --- a/wm/src/window_stub.cpp +++ b/wm/src/window_stub.cpp @@ -49,11 +49,6 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce UpdateFocusStatus(focused); break; } - case TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY: { - SystemBarProperty property = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() }; - UpdateSystemBarProperty(property); - break; - } default: break; } diff --git a/wm/src/zidl/window_manager_agent_proxy.cpp b/wm/src/zidl/window_manager_agent_proxy.cpp index eea58411..774ae60c 100644 --- a/wm/src/zidl/window_manager_agent_proxy.cpp +++ b/wm/src/zidl/window_manager_agent_proxy.cpp @@ -62,6 +62,44 @@ void WindowManagerAgentProxy::UpdateFocusStatus(uint32_t windowId, const sptr(size))) { + WLOGFE("Write vector size failed"); + return; + } + for (auto it : props) { + // write key(type) + if (!data.WriteUint32(static_cast(it.first))) { + WLOGFE("Write type failed"); + return; + } + // write val(sysBarProps) + if (!(data.WriteBool(it.second.enable_) && data.WriteUint32(it.second.backgroundColor_) && + data.WriteUint32(it.second.contentColor_))) { + WLOGFE("Write sysBarProp failed"); + return; + } + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPS, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/zidl/window_manager_agent_stub.cpp b/wm/src/zidl/window_manager_agent_stub.cpp index 9ac69ed9..943aa26a 100644 --- a/wm/src/zidl/window_manager_agent_stub.cpp +++ b/wm/src/zidl/window_manager_agent_stub.cpp @@ -42,6 +42,19 @@ int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data, UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); break; } + case TRANS_ID_UPDATE_SYSTEM_BAR_PROPS: { + uint64_t displayId = data.ReadUint64(); + SystemBarProps props; + uint32_t size = data.ReadUint32(); + for (uint32_t i = 0; i < size; i++) { + WindowType type = static_cast(data.ReadUint32()); + SystemBarProperty prop = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() }; + std::pair item = { type, prop }; + props.emplace_back(item); + } + UpdateSystemBarProperties(displayId, props); + break; + } default: break; } diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index f54f7c07..016102da 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -41,8 +41,10 @@ public: WMError SetWindowFlags(uint32_t windowId, uint32_t flags); WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); - void RegisterFocusChangedListener(const sptr& windowManagerAgent); - void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); + void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); private: uint32_t GenWindowId(); diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index 0e10802a..e24deb66 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -50,13 +50,11 @@ private: sptr appWindowNode_ = new WindowNode(); sptr aboveAppWindowNode_ = new WindowNode(); Rect limitRect_ = {0, 0, 0, 0}; - std::map> avoidNodes_; const std::set avoidTypes_ { WindowType::WINDOW_TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR, }; void UpdateLimitRect(const sptr& node); - void RecordAvoidRect(const sptr& node); void UpdateLayoutRect(sptr& node); void LayoutWindowTree(); void LayoutWindowNode(sptr& node); diff --git a/wmserver/include/window_manager_interface.h b/wmserver/include/window_manager_interface.h index 4285e240..b32c8689 100644 --- a/wmserver/include/window_manager_interface.h +++ b/wmserver/include/window_manager_interface.h @@ -41,8 +41,8 @@ public: TRANS_ID_UPDATE_FLAGS, TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, TRANS_ID_SEND_ABILITY_TOKEN, - TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER, - TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER, + TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT, + TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT, }; virtual WMError CreateWindow(sptr& window, sptr& property, const std::shared_ptr& surfaceNode, uint32_t& windowId) = 0; @@ -58,8 +58,10 @@ public: virtual WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) = 0; virtual WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) = 0; - virtual void RegisterFocusChangedListener(const sptr& windowManagerAgent) = 0; - virtual void UnregisterFocusChangedListener(const sptr& windowManagerAgent) = 0; + virtual void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) = 0; + virtual void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) = 0; }; } } diff --git a/wmserver/include/window_manager_proxy.h b/wmserver/include/window_manager_proxy.h index fbca792c..64694bb3 100644 --- a/wmserver/include/window_manager_proxy.h +++ b/wmserver/include/window_manager_proxy.h @@ -41,8 +41,10 @@ public: WMError SetWindowFlags(uint32_t windowId, uint32_t flags) override; WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override; - void RegisterFocusChangedListener(const sptr& windowManagerAgent) override; - void UnregisterFocusChangedListener(const sptr& windowManagerAgent) override; + void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) override; + void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) override; private: static inline BrokerDelegator delegator_; diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 05e9306b..3f542222 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -54,8 +54,10 @@ public: WMError SetWindowFlags(uint32_t windowId, uint32_t flags) override; WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override; - void RegisterFocusChangedListener(const sptr& windowManagerAgent) override; - void UnregisterFocusChangedListener(const sptr& windowManagerAgent) override; + void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) override; + void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) override; // Inner interfaces WMError NotifyDisplaySuspend(); diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 04430981..4051cce4 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -26,10 +26,16 @@ namespace OHOS { namespace Rosen { using UpdateFocusStatusFunc = std::function& abilityToken, WindowType windowType, int32_t displayId, bool focused)>; +using UpdateSystemBarPropsFunc = std::function; + +struct WindowNodeContainerCallbacks { + UpdateFocusStatusFunc focusStatusCallBack_; + UpdateSystemBarPropsFunc systemBarChangedCallBack_; +}; class WindowNodeContainer : public RefBase { public: - WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, UpdateFocusStatusFunc callback); + WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, WindowNodeContainerCallbacks callbacks); ~WindowNodeContainer(); WMError AddWindowNode(sptr& node, sptr& parentNode); WMError RemoveWindowNode(sptr& node); @@ -75,7 +81,7 @@ private: uint32_t focusedWindow_ { 0 }; Rect displayRect_; uint64_t screenId_ = 0; - UpdateFocusStatusFunc focusStatusCallBack_; + WindowNodeContainerCallbacks callbacks_; void DumpScreenWindowTree(); }; } diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index d2f79b03..55f43d75 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -68,17 +68,20 @@ public: WMError RequestFocus(uint32_t windowId); WMError MinimizeOtherFullScreenAbility(sptr& node); - void RegisterFocusChangedListener(const sptr& windowManagerAgent); - void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); + void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); std::shared_ptr GetSurfaceNodeByAbilityToken(const sptr& abilityToken) const; private: void OnRemoteDied(const sptr& remoteObject); void ClearWindowManagerAgent(const sptr& remoteObject); - void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + void UnregisterWindowManagerAgent(const sptr& object); void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused); + void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props); WMError DestroyWindowInner(sptr& node); std::recursive_mutex& mutex_; @@ -86,7 +89,7 @@ private: std::map> windowNodeMap_; std::map, uint32_t> windowIdMap_; - std::vector> focusChangedListenerAgents_; + std::map>> windowManagerAgents_; sptr windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::OnRemoteDied, this, std::placeholders::_1)); diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index a26a7fd8..ade350d9 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -211,14 +211,16 @@ WMError WindowController::SetSystemBarProperty(uint32_t windowId, WindowType typ return res; } -void WindowController::RegisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowController::RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { - windowRoot_->RegisterFocusChangedListener(windowManagerAgent); + windowRoot_->RegisterWindowManagerAgent(type, windowManagerAgent); } -void WindowController::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowController::UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { - windowRoot_->UnregisterFocusChangedListener(windowManagerAgent); + windowRoot_->UnregisterWindowManagerAgent(type, windowManagerAgent); } } } diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index b9d3c90e..b9c1b6ab 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -36,13 +36,11 @@ void WindowLayoutPolicy::UpdateDisplayInfo(const Rect& displayRect) { displayRect_ = displayRect; limitRect_ = displayRect_; - avoidNodes_.clear(); } void WindowLayoutPolicy::LayoutWindowTree() { limitRect_ = displayRect_; - avoidNodes_.clear(); std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; for (auto& node : rootNodes) { // ensure that the avoid area windows are traversed first LayoutWindowNode(node); @@ -61,7 +59,7 @@ void WindowLayoutPolicy::LayoutWindowNode(sptr& node) } UpdateLayoutRect(node); if (avoidTypes_.find(node->GetWindowType()) != avoidTypes_.end()) { - RecordAvoidRect(node); + UpdateLimitRect(node); } } for (auto& childNode : node->children_) { @@ -80,7 +78,7 @@ void WindowLayoutPolicy::RemoveWindowNode(sptr& node) WM_FUNCTION_TRACE(); auto type = node->GetWindowType(); // affect other windows, trigger off global layout - if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + if (avoidTypes_.find(type) != avoidTypes_.end()) { LayoutWindowTree(); } else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode // TODO: change split screen @@ -93,7 +91,7 @@ void WindowLayoutPolicy::UpdateWindowNode(sptr& node) WM_FUNCTION_TRACE(); auto type = node->GetWindowType(); // affect other windows, trigger off global layout - if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + if (avoidTypes_.find(type) != avoidTypes_.end()) { LayoutWindowTree(); } else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode // TODO: change split screen @@ -210,20 +208,5 @@ void WindowLayoutPolicy::UpdateLimitRect(const sptr& node) WLOGFI("Type: %{public}d, limitRect: %{public}d %{public}d %{public}d %{public}d", node->GetWindowType(), limitRect_.posX_, limitRect_.posY_, limitRect_.width_, limitRect_.height_); } - -void WindowLayoutPolicy::RecordAvoidRect(const sptr& node) -{ - uint32_t id = node->GetWindowId(); - if (avoidNodes_.find(id) == avoidNodes_.end()) { // new avoid rect - avoidNodes_.insert(std::pair>(id, node)); - UpdateLimitRect(node); - } else { // update existing avoid rect - limitRect_ = displayRect_; - avoidNodes_[id] = node; - for (auto item : avoidNodes_) { - UpdateLimitRect(item.second); - } - } -} } } diff --git a/wmserver/src/window_manager_proxy.cpp b/wmserver/src/window_manager_proxy.cpp index 04270b7b..d3e9625c 100644 --- a/wmserver/src/window_manager_proxy.cpp +++ b/wmserver/src/window_manager_proxy.cpp @@ -348,7 +348,8 @@ WMError WindowManagerProxy::SaveAbilityToken(const sptr& abilityT return static_cast(ret); } -void WindowManagerProxy::RegisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { MessageParcel data; MessageParcel reply; @@ -358,17 +359,23 @@ void WindowManagerProxy::RegisterFocusChangedListener(const sptr(type))) { + WLOGFE("Write type failed"); + return; + } + if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { WLOGFE("Write IWindowManagerAgent failed"); return; } - if (Remote()->SendRequest(TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) { + if (Remote()->SendRequest(TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT, data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); } } -void WindowManagerProxy::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { MessageParcel data; MessageParcel reply; @@ -378,12 +385,17 @@ void WindowManagerProxy::UnregisterFocusChangedListener(const sptr(type))) { + WLOGFE("Write type failed"); + return; + } + if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { WLOGFE("Write IWindowManagerAgent failed"); return; } - if (Remote()->SendRequest(TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) { + if (Remote()->SendRequest(TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT, data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); } } diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index c62b771f..7b847858 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -205,24 +205,25 @@ WMError WindowManagerService::SaveAbilityToken(const sptr& abilit return windowController_->SaveAbilityToken(abilityToken, windowId); } -void WindowManagerService::RegisterFocusChangedListener(const sptr& windowManagerAgent) -{ - if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) { - WLOGFE("failed to get window manager agent"); - return; - } - std::lock_guard lock(mutex_); - windowController_->RegisterFocusChangedListener(windowManagerAgent); -} - -void WindowManagerService::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) { WLOGFE("windowManagerAgent is null"); return; } std::lock_guard lock(mutex_); - windowController_->UnregisterFocusChangedListener(windowManagerAgent); + windowController_->RegisterWindowManagerAgent(type, windowManagerAgent); +} +void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) +{ + if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) { + WLOGFE("windowManagerAgent is null"); + return; + } + std::lock_guard lock(mutex_); + windowController_->UnregisterWindowManagerAgent(type, windowManagerAgent); } void WindowManagerService::OnWindowEvent(Event event, uint32_t windowId) diff --git a/wmserver/src/window_manager_stub.cpp b/wmserver/src/window_manager_stub.cpp index 795f0469..a321f55c 100644 --- a/wmserver/src/window_manager_stub.cpp +++ b/wmserver/src/window_manager_stub.cpp @@ -118,18 +118,20 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } - case TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER: { + case TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT: { sptr windowManagerAgentObject = data.ReadRemoteObject(); + WindowManagerAgentType type = static_cast(data.ReadUint32()); sptr windowManagerAgentProxy = iface_cast(windowManagerAgentObject); - RegisterFocusChangedListener(windowManagerAgentProxy); + RegisterWindowManagerAgent(type, windowManagerAgentProxy); break; } - case TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER: { + case TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT: { sptr windowManagerAgentObject = data.ReadRemoteObject(); + WindowManagerAgentType type = static_cast(data.ReadUint32()); sptr windowManagerAgentProxy = iface_cast(windowManagerAgentObject); - UnregisterFocusChangedListener(windowManagerAgentProxy); + UnregisterWindowManagerAgent(type, windowManagerAgentProxy); break; } default: diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index ec268097..94b11f3f 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -30,7 +30,8 @@ namespace { } WindowNodeContainer::WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, - UpdateFocusStatusFunc callback) : screenId_(screenId), focusStatusCallBack_(callback) + WindowNodeContainerCallbacks callbacks) + : screenId_(screenId), callbacks_(callbacks) { struct RSDisplayNodeConfig config = {screenId}; displayNode_ = RSDisplayNode::Create(config); @@ -279,7 +280,7 @@ void WindowNodeContainer::UpdateFocusStatus(uint32_t id, bool focused) const if (node->abilityToken_ == nullptr) { WLOGFI("abilityToken is null, window : %{public}d", id); } - focusStatusCallBack_(node->GetWindowId(), node->abilityToken_, node->GetWindowType(), + callbacks_.focusStatusCallBack_(node->GetWindowId(), node->abilityToken_, node->GetWindowType(), node->GetDisplayId(), focused); } } @@ -364,17 +365,19 @@ void WindowNodeContainer::NotifySystemBarIfChanged() { DumpScreenWindowTree(); auto node = GetTopImmersiveNode(); + SystemBarProps props; if (node == nullptr) { // use default system bar + WLOGFI("no immersive window on top"); for (auto it : sysBarPropMap_) { if (it.second == SystemBarProperty()) { continue; } sysBarPropMap_[it.first] = SystemBarProperty(); - if (sysBarNodeMap_[it.first] != nullptr) { - sysBarNodeMap_[it.first]->GetWindowToken()->UpdateSystemBarProperty(SystemBarProperty()); - } + std::pair item = { it.first, SystemBarProperty() }; + props.emplace_back(item); } } else { // use node-defined system bar + WLOGFI("top immersive window id: %{public}d", node->GetWindowId()); auto& sysBarPropMap = node->GetSystemBarProperty(); for (auto it : sysBarPropMap_) { if (sysBarPropMap.find(it.first) == sysBarPropMap.end()) { @@ -389,11 +392,11 @@ void WindowNodeContainer::NotifySystemBarIfChanged() node->GetWindowId(), static_cast(it.first), prop.enable_, prop.backgroundColor_, prop.contentColor_); sysBarPropMap_[it.first] = prop; - if (sysBarNodeMap_[it.first] != nullptr) { - sysBarNodeMap_[it.first]->GetWindowToken()->UpdateSystemBarProperty(prop); - } + std::pair item = { it.first, prop }; + props.emplace_back(item); } } + callbacks_.systemBarChangedCallBack_(screenId_, props); } void WindowNodeContainer::TraverseContainer(std::vector>& windowNodes) diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index e726dae0..eb1c2be8 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -41,9 +41,15 @@ sptr WindowRoot::GetOrCreateWindowNodeContainer(int32_t dis UpdateFocusStatusFunc focusStatusFunc = std::bind(&WindowRoot::UpdateFocusStatus, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5); + UpdateSystemBarPropsFunc sysBarUpdateFunc = std::bind(&WindowRoot::UpdateSystemBarProperties, this, + std::placeholders::_1, std::placeholders::_2); + WindowNodeContainerCallbacks callbacks = { + focusStatusFunc, + sysBarUpdateFunc + }; sptr container = new WindowNodeContainer(abstractDisplay->GetId(), static_cast(abstractDisplay->GetWidth()), static_cast(abstractDisplay->GetHeight()), - focusStatusFunc); + callbacks); windowNodeContainerMap_.insert({ displayId, container }); return container; } @@ -215,9 +221,10 @@ WMError WindowRoot::RequestFocus(uint32_t windowId) return container->SetFocusWindow(windowId); } -void WindowRoot::RegisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowRoot::RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { - focusChangedListenerAgents_.push_back(windowManagerAgent); + windowManagerAgents_[type].push_back(windowManagerAgent); if (windowManagerAgentDeath_ == nullptr) { WLOGFI("failed to create death Recipient ptr WindowManagerAgentDeathRecipient"); return; @@ -227,21 +234,24 @@ void WindowRoot::RegisterFocusChangedListener(const sptr& w } } -void WindowRoot::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowRoot::UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { - auto iter = std::find(focusChangedListenerAgents_.begin(), focusChangedListenerAgents_.end(), windowManagerAgent); - if (iter == focusChangedListenerAgents_.end()) { + auto iter = std::find(windowManagerAgents_[type].begin(), windowManagerAgents_[type].end(), windowManagerAgent); + if (iter == windowManagerAgents_[type].end()) { WLOGFE("could not find this listener"); return; } - focusChangedListenerAgents_.erase(iter); + windowManagerAgents_[type].erase(iter); } -void WindowRoot::UnregisterFocusChangedListener(const sptr& object) +void WindowRoot::UnregisterWindowManagerAgent(const sptr& object) { - for (auto iter = focusChangedListenerAgents_.begin(); iter < focusChangedListenerAgents_.end(); ++iter) { - if ((*iter)->AsObject() != nullptr && (*iter)->AsObject() == object) { - iter = focusChangedListenerAgents_.erase(iter); + for (auto agents : windowManagerAgents_) { + for (auto iter = agents.second.begin(); iter < agents.second.end(); ++iter) { + if ((*iter)->AsObject() != nullptr && (*iter)->AsObject() == object) { + iter = agents.second.erase(iter); + } } } } @@ -249,7 +259,7 @@ void WindowRoot::UnregisterFocusChangedListener(const sptr& objec void WindowRoot::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) { - for (auto& windowManagerAgent : focusChangedListenerAgents_) { + for (auto& windowManagerAgent : windowManagerAgents_[WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS]) { windowManagerAgent->UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); } } @@ -266,6 +276,16 @@ std::shared_ptr WindowRoot::GetSurfaceNodeByAbilityToken(const sp return nullptr; } +void WindowRoot::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) +{ + if (props.empty()) { + return; + } + for (auto& agent : windowManagerAgents_[WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR]) { + agent->UpdateSystemBarProperties(displayId, props); + } +} + void WindowRoot::OnRemoteDied(const sptr& remoteObject) { std::lock_guard lock(mutex_); @@ -285,7 +305,7 @@ void WindowRoot::ClearWindowManagerAgent(const sptr& remoteObject return; } std::lock_guard lock(mutex_); - UnregisterFocusChangedListener(remoteObject); + UnregisterWindowManagerAgent(remoteObject); remoteObject->RemoveDeathRecipient(windowManagerAgentDeath_); }