mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-21 04:25:28 -04:00
@@ -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<Window> Create(const std::string& windowName,
|
||||
@@ -89,7 +84,6 @@ public:
|
||||
|
||||
virtual void RegisterLifeCycleListener(sptr<IWindowLifeCycle>& listener) = 0;
|
||||
virtual void RegisterWindowChangeListener(sptr<IWindowChangeListener>& listener) = 0;
|
||||
virtual void RegisterWindowSystemBarChangeListener(sptr<IWindowSystemBarChangeListener>& listener) = 0;
|
||||
virtual WMError SetUIContent(std::shared_ptr<AbilityRuntime::AbilityContext> context,
|
||||
std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0;
|
||||
virtual const std::string& GetContentInfo() = 0;
|
||||
|
||||
@@ -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<IFocusChangedListener>& listener);
|
||||
void UnregisterFocusChangedListener(const sptr<IFocusChangedListener>& listener);
|
||||
void RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener);
|
||||
void UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener);
|
||||
|
||||
private:
|
||||
WindowManager();
|
||||
@@ -49,6 +56,7 @@ private:
|
||||
|
||||
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
|
||||
int32_t displayId, bool focused) const;
|
||||
void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) const;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -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<std::pair<WindowType, SystemBarProperty>>;
|
||||
}
|
||||
}
|
||||
#endif // OHOS_ROSEN_WM_COMMON_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<IWindowManagerAgent>& windowManagerAgent);
|
||||
virtual void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
|
||||
virtual void RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent);
|
||||
virtual void UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent);
|
||||
|
||||
virtual void ClearWindowAdapter();
|
||||
private:
|
||||
|
||||
@@ -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<WindowImpl> window_;
|
||||
|
||||
@@ -71,7 +71,6 @@ public:
|
||||
|
||||
virtual void RegisterLifeCycleListener(sptr<IWindowLifeCycle>& listener) override;
|
||||
virtual void RegisterWindowChangeListener(sptr<IWindowChangeListener>& listener) override;
|
||||
virtual void RegisterWindowSystemBarChangeListener(sptr<IWindowSystemBarChangeListener>& listener) override;
|
||||
|
||||
void UpdateRect(const struct Rect& rect);
|
||||
void UpdateMode(WindowMode mode);
|
||||
@@ -79,7 +78,6 @@ public:
|
||||
virtual void ConsumePointerEvent(std::shared_ptr<MMI::PointerEvent>& inputEvent) override;
|
||||
virtual void RequestFrame() override;
|
||||
void UpdateFocusStatus(bool focused);
|
||||
void UpdateSystemBarProperty(const SystemBarProperty& prop);
|
||||
virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
|
||||
|
||||
virtual WMError SetUIContent(std::shared_ptr<AbilityRuntime::AbilityContext> context,
|
||||
@@ -130,7 +128,6 @@ private:
|
||||
WindowState state_ { STATE_INITIAL };
|
||||
sptr<IWindowLifeCycle> lifecycleListener_;
|
||||
sptr<IWindowChangeListener> windowChangeListener_;
|
||||
sptr<IWindowSystemBarChangeListener> systemBarChangeListener_;
|
||||
std::shared_ptr<RSSurfaceNode> surfaceNode_;
|
||||
std::string name_;
|
||||
std::unique_ptr<Ace::UIContent> uiContent_;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
|
||||
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
|
||||
int32_t displayId, bool focused) override;
|
||||
void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) override;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -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<WindowProxy> delegator_;
|
||||
|
||||
@@ -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<IRemoteObject>& abilityToken, WindowType windowType,
|
||||
int32_t displayId, bool focused) = 0;
|
||||
virtual void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) = 0;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
|
||||
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
|
||||
int32_t displayId, bool focused) override;
|
||||
void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<WindowManagerAgentProxy> delegator_;
|
||||
|
||||
@@ -126,24 +126,26 @@ WMError WindowAdapter::SetSystemBarProperty(uint32_t windowId, WindowType type,
|
||||
return windowManagerServiceProxy_->SetSystemBarProperty(windowId, type, property);
|
||||
}
|
||||
|
||||
void WindowAdapter::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
void WindowAdapter::RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
if (!InitWMSProxyLocked()) {
|
||||
return;
|
||||
}
|
||||
return windowManagerServiceProxy_->RegisterFocusChangedListener(windowManagerAgent);
|
||||
return windowManagerServiceProxy_->RegisterWindowManagerAgent(type, windowManagerAgent);
|
||||
}
|
||||
|
||||
void WindowAdapter::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
void WindowAdapter::UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
if (!InitWMSProxyLocked()) {
|
||||
return;
|
||||
}
|
||||
return windowManagerServiceProxy_->UnregisterFocusChangedListener(windowManagerAgent);
|
||||
return windowManagerServiceProxy_->UnregisterWindowManagerAgent(type, windowManagerAgent);
|
||||
}
|
||||
|
||||
bool WindowAdapter::InitWMSProxyLocked()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -455,10 +455,6 @@ void WindowImpl::RegisterWindowChangeListener(sptr<IWindowChangeListener>& liste
|
||||
windowChangeListener_ = listener;
|
||||
}
|
||||
|
||||
void WindowImpl::RegisterWindowSystemBarChangeListener(sptr<IWindowSystemBarChangeListener>& 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<AppExecFwk::Configuration>& configuration)
|
||||
{
|
||||
if (uiContent_ != nullptr) {
|
||||
|
||||
@@ -32,12 +32,14 @@ public:
|
||||
WindowType windowType, int32_t displayId) const;
|
||||
void NotifyUnfocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
|
||||
WindowType windowType, int32_t displayId) const;
|
||||
|
||||
void NotifySystemBarChanged(uint64_t displayId, const SystemBarProps& props) const;
|
||||
static inline SingletonDelegator<WindowManager> delegator_;
|
||||
|
||||
std::mutex mutex_;
|
||||
std::vector<sptr<IFocusChangedListener>> focusChangedListeners_;
|
||||
sptr<WindowManagerAgent> focusChangedListenerAgent_;
|
||||
std::vector<sptr<ISystemBarChangedListener>> systemBarChangedListeners_;
|
||||
sptr<WindowManagerAgent> systemBarChangedListenerAgent_;
|
||||
};
|
||||
|
||||
void WindowManager::Impl::NotifyFocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
|
||||
@@ -60,6 +62,18 @@ void WindowManager::Impl::NotifyUnfocused(uint32_t windowId, const sptr<IRemoteO
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::Impl::NotifySystemBarChanged(uint64_t displayId, const SystemBarProps& props) const
|
||||
{
|
||||
for (auto prop : props) {
|
||||
WLOGFI("type:%{public}d, enable:%{public}d," \
|
||||
"backgroundColor:%{public}x, contentColor:%{public}x",
|
||||
prop.first, prop.second.enable_, prop.second.backgroundColor_, prop.second.contentColor_);
|
||||
}
|
||||
for (auto& listener : systemBarChangedListeners_) {
|
||||
listener->OnSystemBarPropertyChange(displayId, props);
|
||||
}
|
||||
}
|
||||
|
||||
WindowManager::WindowManager() : pImpl_(std::make_unique<Impl>())
|
||||
{
|
||||
}
|
||||
@@ -79,7 +93,8 @@ void WindowManager::RegisterFocusChangedListener(const sptr<IFocusChangedListene
|
||||
pImpl_->focusChangedListeners_.push_back(listener);
|
||||
if (pImpl_->focusChangedListenerAgent_ == nullptr) {
|
||||
pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent();
|
||||
SingletonContainer::Get<WindowAdapter>().RegisterFocusChangedListener(pImpl_->focusChangedListenerAgent_);
|
||||
SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
|
||||
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +113,45 @@ void WindowManager::UnregisterFocusChangedListener(const sptr<IFocusChangedListe
|
||||
}
|
||||
pImpl_->focusChangedListeners_.erase(iter);
|
||||
if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) {
|
||||
SingletonContainer::Get<WindowAdapter>().UnregisterFocusChangedListener(pImpl_->focusChangedListenerAgent_);
|
||||
SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
|
||||
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
WLOGFE("listener could not be null");
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(pImpl_->mutex_);
|
||||
pImpl_->systemBarChangedListeners_.push_back(listener);
|
||||
if (pImpl_->systemBarChangedListenerAgent_ == nullptr) {
|
||||
pImpl_->systemBarChangedListenerAgent_ = new WindowManagerAgent();
|
||||
SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
|
||||
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
WLOGFE("listener could not be null");
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> 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<WindowAdapter>().UnregisterWindowManagerAgent(
|
||||
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,5 +165,11 @@ void WindowManager::UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObjec
|
||||
pImpl_->NotifyUnfocused(windowId, abilityToken, windowType, displayId);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::UpdateSystemBarProperties(uint64_t displayId,
|
||||
const SystemBarProps& props) const
|
||||
{
|
||||
pImpl_->NotifySystemBarChanged(displayId, props);
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -24,5 +24,10 @@ void WindowManagerAgent::UpdateFocusStatus(uint32_t windowId, const sptr<IRemote
|
||||
{
|
||||
SingletonContainer::Get<WindowManager>().UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused);
|
||||
}
|
||||
|
||||
void WindowManagerAgent::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props)
|
||||
{
|
||||
SingletonContainer::Get<WindowManager>().UpdateSystemBarProperties(displayId, props);
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -168,7 +168,7 @@ bool WindowProperty::MapMarshalling(Parcel& parcel) const
|
||||
if (!parcel.WriteUint32(static_cast<uint32_t>(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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -62,6 +62,44 @@ void WindowManagerAgentProxy::UpdateFocusStatus(uint32_t windowId, const sptr<IR
|
||||
WLOGFE("SendRequest failed");
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManagerAgentProxy::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteUint64(displayId)) {
|
||||
WLOGFE("Write displayId failed");
|
||||
return;
|
||||
}
|
||||
|
||||
auto size = props.size();
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(size))) {
|
||||
WLOGFE("Write vector size failed");
|
||||
return;
|
||||
}
|
||||
for (auto it : props) {
|
||||
// write key(type)
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(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
|
||||
|
||||
|
||||
@@ -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<WindowType>(data.ReadUint32());
|
||||
SystemBarProperty prop = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() };
|
||||
std::pair<WindowType, SystemBarProperty> item = { type, prop };
|
||||
props.emplace_back(item);
|
||||
}
|
||||
UpdateSystemBarProperties(displayId, props);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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<IWindowManagerAgent>& windowManagerAgent);
|
||||
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
|
||||
void RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent);
|
||||
void UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent);
|
||||
|
||||
private:
|
||||
uint32_t GenWindowId();
|
||||
|
||||
@@ -50,13 +50,11 @@ private:
|
||||
sptr<WindowNode> appWindowNode_ = new WindowNode();
|
||||
sptr<WindowNode> aboveAppWindowNode_ = new WindowNode();
|
||||
Rect limitRect_ = {0, 0, 0, 0};
|
||||
std::map<uint32_t, sptr<WindowNode>> avoidNodes_;
|
||||
const std::set<WindowType> avoidTypes_ {
|
||||
WindowType::WINDOW_TYPE_STATUS_BAR,
|
||||
WindowType::WINDOW_TYPE_NAVIGATION_BAR,
|
||||
};
|
||||
void UpdateLimitRect(const sptr<WindowNode>& node);
|
||||
void RecordAvoidRect(const sptr<WindowNode>& node);
|
||||
void UpdateLayoutRect(sptr<WindowNode>& node);
|
||||
void LayoutWindowTree();
|
||||
void LayoutWindowNode(sptr<WindowNode>& node);
|
||||
|
||||
@@ -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<IWindow>& window, sptr<WindowProperty>& property,
|
||||
const std::shared_ptr<RSSurfaceNode>& 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<IRemoteObject>& abilityToken, uint32_t windowId) = 0;
|
||||
|
||||
virtual void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
|
||||
virtual void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
|
||||
virtual void RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
|
||||
virtual void UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<IWindowManagerAgent>& windowManagerAgent) override;
|
||||
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) override;
|
||||
void RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
|
||||
void UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<WindowManagerProxy> delegator_;
|
||||
|
||||
@@ -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<IWindowManagerAgent>& windowManagerAgent) override;
|
||||
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) override;
|
||||
void RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
|
||||
void UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
|
||||
|
||||
// Inner interfaces
|
||||
WMError NotifyDisplaySuspend();
|
||||
|
||||
@@ -26,10 +26,16 @@ namespace OHOS {
|
||||
namespace Rosen {
|
||||
using UpdateFocusStatusFunc = std::function<void (uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
|
||||
WindowType windowType, int32_t displayId, bool focused)>;
|
||||
using UpdateSystemBarPropsFunc = std::function<void (uint64_t displayId, const SystemBarProps& props)>;
|
||||
|
||||
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<WindowNode>& node, sptr<WindowNode>& parentNode);
|
||||
WMError RemoveWindowNode(sptr<WindowNode>& node);
|
||||
@@ -75,7 +81,7 @@ private:
|
||||
uint32_t focusedWindow_ { 0 };
|
||||
Rect displayRect_;
|
||||
uint64_t screenId_ = 0;
|
||||
UpdateFocusStatusFunc focusStatusCallBack_;
|
||||
WindowNodeContainerCallbacks callbacks_;
|
||||
void DumpScreenWindowTree();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -68,17 +68,20 @@ public:
|
||||
WMError RequestFocus(uint32_t windowId);
|
||||
WMError MinimizeOtherFullScreenAbility(sptr<WindowNode>& node);
|
||||
|
||||
void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
|
||||
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
|
||||
void RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent);
|
||||
void UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent);
|
||||
|
||||
std::shared_ptr<RSSurfaceNode> GetSurfaceNodeByAbilityToken(const sptr<IRemoteObject>& abilityToken) const;
|
||||
|
||||
private:
|
||||
void OnRemoteDied(const sptr<IRemoteObject>& remoteObject);
|
||||
void ClearWindowManagerAgent(const sptr<IRemoteObject>& remoteObject);
|
||||
void UnregisterFocusChangedListener(const sptr<IRemoteObject>& windowManagerAgent);
|
||||
void UnregisterWindowManagerAgent(const sptr<IRemoteObject>& object);
|
||||
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
|
||||
int32_t displayId, bool focused);
|
||||
void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props);
|
||||
WMError DestroyWindowInner(sptr<WindowNode>& node);
|
||||
|
||||
std::recursive_mutex& mutex_;
|
||||
@@ -86,7 +89,7 @@ private:
|
||||
std::map<uint32_t, sptr<WindowNode>> windowNodeMap_;
|
||||
std::map<sptr<IRemoteObject>, uint32_t> windowIdMap_;
|
||||
|
||||
std::vector<sptr<IWindowManagerAgent>> focusChangedListenerAgents_;
|
||||
std::map<WindowManagerAgentType, std::vector<sptr<IWindowManagerAgent>>> windowManagerAgents_;
|
||||
|
||||
sptr<WindowDeathRecipient> windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::OnRemoteDied,
|
||||
this, std::placeholders::_1));
|
||||
|
||||
@@ -211,14 +211,16 @@ WMError WindowController::SetSystemBarProperty(uint32_t windowId, WindowType typ
|
||||
return res;
|
||||
}
|
||||
|
||||
void WindowController::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
void WindowController::RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
{
|
||||
windowRoot_->RegisterFocusChangedListener(windowManagerAgent);
|
||||
windowRoot_->RegisterWindowManagerAgent(type, windowManagerAgent);
|
||||
}
|
||||
|
||||
void WindowController::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
void WindowController::UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
{
|
||||
windowRoot_->UnregisterFocusChangedListener(windowManagerAgent);
|
||||
windowRoot_->UnregisterWindowManagerAgent(type, windowManagerAgent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<sptr<WindowNode>> 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<WindowNode>& 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<WindowNode>& 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<WindowNode>& 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<WindowNode>& 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<WindowNode>& node)
|
||||
{
|
||||
uint32_t id = node->GetWindowId();
|
||||
if (avoidNodes_.find(id) == avoidNodes_.end()) { // new avoid rect
|
||||
avoidNodes_.insert(std::pair<uint32_t, sptr<WindowNode>>(id, node));
|
||||
UpdateLimitRect(node);
|
||||
} else { // update existing avoid rect
|
||||
limitRect_ = displayRect_;
|
||||
avoidNodes_[id] = node;
|
||||
for (auto item : avoidNodes_) {
|
||||
UpdateLimitRect(item.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,7 +348,8 @@ WMError WindowManagerProxy::SaveAbilityToken(const sptr<IRemoteObject>& abilityT
|
||||
return static_cast<WMError>(ret);
|
||||
}
|
||||
|
||||
void WindowManagerProxy::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
void WindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@@ -358,17 +359,23 @@ void WindowManagerProxy::RegisterFocusChangedListener(const sptr<IWindowManagerA
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(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<IWindowManagerAgent>& windowManagerAgent)
|
||||
void WindowManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@@ -378,12 +385,17 @@ void WindowManagerProxy::UnregisterFocusChangedListener(const sptr<IWindowManage
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,24 +205,25 @@ WMError WindowManagerService::SaveAbilityToken(const sptr<IRemoteObject>& abilit
|
||||
return windowController_->SaveAbilityToken(abilityToken, windowId);
|
||||
}
|
||||
|
||||
void WindowManagerService::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
{
|
||||
if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
|
||||
WLOGFE("failed to get window manager agent");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
windowController_->RegisterFocusChangedListener(windowManagerAgent);
|
||||
}
|
||||
|
||||
void WindowManagerService::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
void WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
{
|
||||
if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
|
||||
WLOGFE("windowManagerAgent is null");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
windowController_->UnregisterFocusChangedListener(windowManagerAgent);
|
||||
windowController_->RegisterWindowManagerAgent(type, windowManagerAgent);
|
||||
}
|
||||
void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
{
|
||||
if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
|
||||
WLOGFE("windowManagerAgent is null");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
windowController_->UnregisterWindowManagerAgent(type, windowManagerAgent);
|
||||
}
|
||||
|
||||
void WindowManagerService::OnWindowEvent(Event event, uint32_t windowId)
|
||||
|
||||
@@ -118,18 +118,20 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M
|
||||
reply.WriteInt32(static_cast<int32_t>(errCode));
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER: {
|
||||
case TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT: {
|
||||
sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
|
||||
WindowManagerAgentType type = static_cast<WindowManagerAgentType>(data.ReadUint32());
|
||||
sptr<IWindowManagerAgent> windowManagerAgentProxy =
|
||||
iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
|
||||
RegisterFocusChangedListener(windowManagerAgentProxy);
|
||||
RegisterWindowManagerAgent(type, windowManagerAgentProxy);
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER: {
|
||||
case TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT: {
|
||||
sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
|
||||
WindowManagerAgentType type = static_cast<WindowManagerAgentType>(data.ReadUint32());
|
||||
sptr<IWindowManagerAgent> windowManagerAgentProxy =
|
||||
iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
|
||||
UnregisterFocusChangedListener(windowManagerAgentProxy);
|
||||
UnregisterWindowManagerAgent(type, windowManagerAgentProxy);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -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<WindowType, SystemBarProperty> 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<int32_t>(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<WindowType, SystemBarProperty> item = { it.first, prop };
|
||||
props.emplace_back(item);
|
||||
}
|
||||
}
|
||||
callbacks_.systemBarChangedCallBack_(screenId_, props);
|
||||
}
|
||||
|
||||
void WindowNodeContainer::TraverseContainer(std::vector<sptr<WindowNode>>& windowNodes)
|
||||
|
||||
@@ -41,9 +41,15 @@ sptr<WindowNodeContainer> 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<WindowNodeContainer> container = new WindowNodeContainer(abstractDisplay->GetId(),
|
||||
static_cast<uint32_t>(abstractDisplay->GetWidth()), static_cast<uint32_t>(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<IWindowManagerAgent>& windowManagerAgent)
|
||||
void WindowRoot::RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& 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<IWindowManagerAgent>& w
|
||||
}
|
||||
}
|
||||
|
||||
void WindowRoot::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
|
||||
void WindowRoot::UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& 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<IRemoteObject>& object)
|
||||
void WindowRoot::UnregisterWindowManagerAgent(const sptr<IRemoteObject>& 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<IRemoteObject>& objec
|
||||
void WindowRoot::UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& 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<RSSurfaceNode> 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<IRemoteObject>& remoteObject)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
@@ -285,7 +305,7 @@ void WindowRoot::ClearWindowManagerAgent(const sptr<IRemoteObject>& remoteObject
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
UnregisterFocusChangedListener(remoteObject);
|
||||
UnregisterWindowManagerAgent(remoteObject);
|
||||
remoteObject->RemoveDeathRecipient(windowManagerAgentDeath_);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user