mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-28 01:21:13 +00:00
commit
ff34c72797
@ -146,14 +146,14 @@ private:
|
||||
|
||||
bool DisplayManager::Impl::CheckRectValid(const Media::Rect& rect, int32_t oriHeight, int32_t oriWidth) const
|
||||
{
|
||||
if (!((rect.left >= 0) and (rect.left < oriWidth) and (rect.top >= 0) and (rect.top < oriHeight))) {
|
||||
if (!((rect.left >= 0) && (rect.left < oriWidth) && (rect.top >= 0) && (rect.top < oriHeight))) {
|
||||
WLOGFE("rect left or top invalid!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!((rect.width > 0) and (rect.width <= (oriWidth - rect.left)) and
|
||||
(rect.height > 0) and (rect.height <= (oriHeight - rect.top)))) {
|
||||
if (!((rect.width == 0) and (rect.height == 0))) {
|
||||
if (!((rect.width > 0) && (rect.width <= (oriWidth - rect.left)) &&
|
||||
(rect.height > 0) && (rect.height <= (oriHeight - rect.top)))) {
|
||||
if (!((rect.width == 0) && (rect.height == 0))) {
|
||||
WLOGFE("rect height or width invalid!");
|
||||
return false;
|
||||
}
|
||||
@ -163,8 +163,8 @@ bool DisplayManager::Impl::CheckRectValid(const Media::Rect& rect, int32_t oriHe
|
||||
|
||||
bool DisplayManager::Impl::CheckSizeValid(const Media::Size& size, int32_t oriHeight, int32_t oriWidth) const
|
||||
{
|
||||
if (!((size.width > 0) and (size.height > 0))) {
|
||||
if (!((size.width == 0) and (size.height == 0))) {
|
||||
if (!((size.width > 0) && (size.height > 0))) {
|
||||
if (!((size.width == 0) && (size.height == 0))) {
|
||||
WLOGFE("width or height invalid!");
|
||||
return false;
|
||||
}
|
||||
|
@ -57,6 +57,9 @@ sptr<AbstractScreenGroup> AbstractScreen::GetGroup() const
|
||||
sptr<ScreenInfo> AbstractScreen::ConvertToScreenInfo() const
|
||||
{
|
||||
sptr<ScreenInfo> info = new ScreenInfo();
|
||||
if (info == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
FillScreenInfo(info);
|
||||
return info;
|
||||
}
|
||||
@ -259,6 +262,9 @@ AbstractScreenGroup::~AbstractScreenGroup()
|
||||
sptr<ScreenGroupInfo> AbstractScreenGroup::ConvertToScreenGroupInfo() const
|
||||
{
|
||||
sptr<ScreenGroupInfo> screenGroupInfo = new ScreenGroupInfo();
|
||||
if (screenGroupInfo == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
FillScreenInfo(screenGroupInfo);
|
||||
screenGroupInfo->combination_ = combination_;
|
||||
for (auto iter = abstractScreenMap_.begin(); iter != abstractScreenMap_.end(); iter++) {
|
||||
@ -271,6 +277,10 @@ sptr<ScreenGroupInfo> AbstractScreenGroup::ConvertToScreenGroupInfo() const
|
||||
|
||||
bool AbstractScreenGroup::SetRSDisplayNodeConfig(sptr<AbstractScreen>& dmsScreen, struct RSDisplayNodeConfig& config)
|
||||
{
|
||||
if (dmsScreen == nullptr) {
|
||||
WLOGE("dmsScreen is nullptr.");
|
||||
return false;
|
||||
}
|
||||
switch (combination_) {
|
||||
case ScreenCombination::SCREEN_ALONE:
|
||||
case ScreenCombination::SCREEN_EXPAND:
|
||||
@ -353,8 +363,7 @@ bool AbstractScreenGroup::RemoveChild(sptr<AbstractScreen>& dmsScreen)
|
||||
|
||||
bool AbstractScreenGroup::HasChild(ScreenId childScreen) const
|
||||
{
|
||||
auto iter = abstractScreenMap_.find(childScreen);
|
||||
return iter != abstractScreenMap_.end();
|
||||
return abstractScreenMap_.find(childScreen) != abstractScreenMap_.end();
|
||||
}
|
||||
|
||||
std::vector<sptr<AbstractScreen>> AbstractScreenGroup::GetChildren() const
|
||||
|
@ -122,6 +122,12 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool IsSwitchCascadeReason(WindowUpdateReason reason)
|
||||
{
|
||||
return (reason >= WindowUpdateReason::NEED_SWITCH_CASCADE_BASE) &&
|
||||
(reason < WindowUpdateReason::NEED_SWITCH_CASCADE_END);
|
||||
}
|
||||
|
||||
WindowHelper() = default;
|
||||
~WindowHelper() = default;
|
||||
};
|
||||
|
@ -37,11 +37,13 @@ enum class WindowStateChangeReason : uint32_t {
|
||||
};
|
||||
|
||||
enum class WindowUpdateReason : uint32_t {
|
||||
UPDATE_ALL,
|
||||
NEED_SWITCH_CASCADE_BASE,
|
||||
UPDATE_ALL = NEED_SWITCH_CASCADE_BASE,
|
||||
UPDATE_MODE,
|
||||
UPDATE_RECT,
|
||||
UPDATE_FLAGS,
|
||||
UPDATE_TYPE,
|
||||
NEED_SWITCH_CASCADE_END,
|
||||
UPDATE_OTHER_PROPS,
|
||||
};
|
||||
namespace {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -97,7 +97,7 @@ public:
|
||||
void WindowManager::Impl::NotifyFocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
|
||||
WindowType windowType, DisplayId displayId) const
|
||||
{
|
||||
WLOGFI("NotifyFocused [%{public}d; %{public}p; %{public}d; %{public}" PRIu64"]", windowId, abilityToken.GetRefPtr(),
|
||||
WLOGFI("NotifyFocused [%{public}u; %{public}p; %{public}d; %{public}" PRIu64"]", windowId, abilityToken.GetRefPtr(),
|
||||
static_cast<uint32_t>(windowType), displayId);
|
||||
for (auto& listener : focusChangedListeners_) {
|
||||
listener->OnFocused(windowId, abilityToken, windowType, displayId);
|
||||
@ -107,7 +107,7 @@ void WindowManager::Impl::NotifyFocused(uint32_t windowId, const sptr<IRemoteObj
|
||||
void WindowManager::Impl::NotifyUnfocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
|
||||
WindowType windowType, DisplayId displayId) const
|
||||
{
|
||||
WLOGFI("NotifyUnfocused [%{public}d; %{public}p; %{public}d; %{public}" PRIu64"]", windowId,
|
||||
WLOGFI("NotifyUnfocused [%{public}u; %{public}p; %{public}d; %{public}" PRIu64"]", windowId,
|
||||
abilityToken.GetRefPtr(), static_cast<uint32_t>(windowType), displayId);
|
||||
for (auto& listener : focusChangedListeners_) {
|
||||
listener->OnUnfocused(windowId, abilityToken, windowType, displayId);
|
||||
@ -240,7 +240,7 @@ void WindowManager::MinimizeAllAppWindows(DisplayId displayId)
|
||||
|
||||
WMError WindowManager::SetWindowLayoutMode(WindowLayoutMode mode, DisplayId displayId)
|
||||
{
|
||||
WLOGFI("set window layout mode: %{public}d, displayId %{public}" PRIu64"", mode, displayId);
|
||||
WLOGFI("set window layout mode: %{public}u, displayId %{public}" PRIu64"", mode, displayId);
|
||||
WMError ret = SingletonContainer::Get<WindowAdapter>().SetWindowLayoutMode(displayId, mode);
|
||||
if (ret != WMError::WM_OK) {
|
||||
WLOGFE("set layout mode failed");
|
||||
@ -322,7 +322,7 @@ void WindowManager::UnregisterVisibilityChangedListener(const sptr<IVisibilityCh
|
||||
void WindowManager::UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
|
||||
DisplayId displayId, bool focused) const
|
||||
{
|
||||
WLOGFI("window focus status: %{public}d, id: %{public}d", focused, windowId);
|
||||
WLOGFI("window focus status: %{public}d, id: %{public}u", focused, windowId);
|
||||
if (focused) {
|
||||
pImpl_->NotifyFocused(windowId, abilityToken, windowType, displayId);
|
||||
} else {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
@ -39,9 +39,8 @@ public:
|
||||
void UpdateLayoutRect(sptr<WindowNode>& node) override;
|
||||
|
||||
private:
|
||||
Rect singleRect_ = { 0, 0, 0, 0 };
|
||||
std::vector<Rect> doubleRects_ = std::vector<Rect>(2);
|
||||
std::vector<Rect> tripleRects_ = std::vector<Rect>(3);
|
||||
uint32_t maxTileWinNum_ = 1;
|
||||
std::vector<std::vector<Rect>> presetRects_;
|
||||
std::deque<sptr<WindowNode>> foregroundNodes_;
|
||||
void UpdateDisplayInfo() override;
|
||||
void InitTileWindowRects();
|
||||
|
@ -269,10 +269,6 @@ void WindowLayoutPolicy::LimitWindowSize(const sptr<WindowNode>& node, const Rec
|
||||
WindowType windowType = node->GetWindowType();
|
||||
WindowMode windowMode = node->GetWindowMode();
|
||||
bool isVertical = (displayRect.height_ > displayRect.width_) ? true : false;
|
||||
if (!WindowHelper::IsMainFloatingWindow(windowType, windowMode)) {
|
||||
winRect.width_ = std::min(displayRect.width_ - winRect.posX_, winRect.width_);
|
||||
winRect.height_ = std::min(displayRect.height_ - winRect.posY_, winRect.height_);
|
||||
}
|
||||
if ((windowMode == WindowMode::WINDOW_MODE_FLOATING) && !WindowHelper::IsSystemWindow(windowType)) {
|
||||
if (isVertical) {
|
||||
winRect.width_ = std::max(minVerticalFloatingW, winRect.width_);
|
||||
|
@ -36,9 +36,7 @@ WindowLayoutPolicyTile::WindowLayoutPolicyTile(const Rect& displayRect, const ui
|
||||
void WindowLayoutPolicyTile::Launch()
|
||||
{
|
||||
// compute limit rect
|
||||
limitRect_ = displayRect_;
|
||||
LayoutWindowNode(aboveAppWindowNode_);
|
||||
InitTileWindowRects();
|
||||
UpdateDisplayInfo();
|
||||
// select app min win in queue, and minimize others
|
||||
InitForegroundNodeQueue();
|
||||
AssignNodePropertyForTileWindows();
|
||||
@ -61,24 +59,26 @@ void WindowLayoutPolicyTile::InitTileWindowRects()
|
||||
constexpr float ratio = 0.75; // 0.75: default height/width ratio
|
||||
constexpr float edgeRatio = 0.125;
|
||||
constexpr int half = 2;
|
||||
maxTileWinNum_ = IsVertical() ? MAX_WIN_NUM_VERTICAL : MAX_WIN_NUM_HORIZONTAL;
|
||||
presetRects_.clear();
|
||||
int x = limitRect_.posX_ + (limitRect_.width_ * edgeRatio);
|
||||
int y = limitRect_.posY_ + (limitRect_.height_ * edgeRatio);
|
||||
uint32_t w = limitRect_.width_ * ratio;
|
||||
uint32_t h = limitRect_.height_ * ratio;
|
||||
singleRect_ = { x, y, w, h };
|
||||
WLOGFI("singleRect_: %{public}d %{public}d %{public}d %{public}d", x, y, w, h);
|
||||
x = edgeInterval;
|
||||
w = (limitRect_.width_ - edgeInterval * half - midInterval) / half;
|
||||
// calc doubleRect
|
||||
doubleRects_[0] = {x, y, w, h};
|
||||
doubleRects_[1] = {x + w + midInterval, y, w, h};
|
||||
WLOGFI("doubleRects_: %{public}d %{public}d %{public}d %{public}d", x, y, w, h);
|
||||
// calc tripleRect
|
||||
w = (limitRect_.width_ - edgeInterval * half - midInterval * half) / MAX_WIN_NUM_HORIZONTAL;
|
||||
tripleRects_[0] = {x, y, w, h};
|
||||
tripleRects_[1] = {x + w + midInterval, y, w, h};
|
||||
tripleRects_[2] = {x + w * half + midInterval * half, y, w, h}; // 2 is third index
|
||||
WLOGFI("tripleRects_: %{public}d %{public}d %{public}d %{public}d", x, y, w, h);
|
||||
std::vector<Rect> single = {{ x, y, w, h }};
|
||||
presetRects_.emplace_back(single);
|
||||
for (uint32_t num = 2; num <= maxTileWinNum_; num++) { // start calc preset with 2 windows
|
||||
w = (limitRect_.width_ - edgeInterval * half - midInterval * (num - 1)) / num;
|
||||
std::vector<Rect> curLevel;
|
||||
for (uint32_t i = 0; i < num; i++) {
|
||||
int curX = limitRect_.posX_ + edgeInterval + i * (w + midInterval);
|
||||
Rect curRect = { curX, y, w, h };
|
||||
WLOGFI("presetRects: level %{public}d, id %{public}d, [%{public}d %{public}d %{public}d %{public}d]",
|
||||
num, i, curX, y, w, h);
|
||||
curLevel.emplace_back(curRect);
|
||||
}
|
||||
presetRects_.emplace_back(curLevel);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowLayoutPolicyTile::AddWindowNode(sptr<WindowNode>& node)
|
||||
@ -143,8 +143,7 @@ void WindowLayoutPolicyTile::ForegroundNodeQueuePushBack(sptr<WindowNode>& node)
|
||||
return;
|
||||
}
|
||||
WLOGFI("add win in tile for win id: %{public}d", node->GetWindowId());
|
||||
uint32_t maxTileWinNum = IsVertical() ? MAX_WIN_NUM_VERTICAL : MAX_WIN_NUM_HORIZONTAL;
|
||||
while (foregroundNodes_.size() >= maxTileWinNum) {
|
||||
while (foregroundNodes_.size() >= maxTileWinNum_) {
|
||||
auto removeNode = foregroundNodes_.front();
|
||||
foregroundNodes_.pop_front();
|
||||
WLOGFI("pop win in queue head id: %{public}d, for add new win", removeNode->GetWindowId());
|
||||
@ -171,30 +170,26 @@ void WindowLayoutPolicyTile::ForegroundNodeQueueRemove(sptr<WindowNode>& node)
|
||||
void WindowLayoutPolicyTile::AssignNodePropertyForTileWindows()
|
||||
{
|
||||
// set rect for foreground windows
|
||||
int num = foregroundNodes_.size();
|
||||
if (num == 1) {
|
||||
WLOGFI("set rect for win id: %{public}d", foregroundNodes_.front()->GetWindowMode());
|
||||
foregroundNodes_.front()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
|
||||
foregroundNodes_.front()->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING);
|
||||
foregroundNodes_.front()->SetWindowRect(singleRect_);
|
||||
foregroundNodes_.front()->hasDecorated_ = true;
|
||||
WLOGFI("set rect for win id: %{public}d [%{public}d %{public}d %{public}d %{public}d]",
|
||||
foregroundNodes_.front()->GetWindowId(),
|
||||
singleRect_.posX_, singleRect_.posY_, singleRect_.width_, singleRect_.height_);
|
||||
} else if (num <= MAX_WIN_NUM_HORIZONTAL) {
|
||||
auto rit = (num == MAX_WIN_NUM_HORIZONTAL) ? tripleRects_.begin() : doubleRects_.begin();
|
||||
for (auto it : foregroundNodes_) {
|
||||
auto& rect = (*rit);
|
||||
it->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
|
||||
it->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING);
|
||||
it->SetWindowRect(rect);
|
||||
it->hasDecorated_ = true;
|
||||
WLOGFI("set rect for qwin id: %{public}d [%{public}d %{public}d %{public}d %{public}d]",
|
||||
it->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_);
|
||||
rit++;
|
||||
uint32_t num = foregroundNodes_.size();
|
||||
if (num > maxTileWinNum_ || num > presetRects_.size() || num == 0) {
|
||||
WLOGE("invalid tile queue");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
WLOGE("too many window node in tile queue");
|
||||
std::vector<Rect>& presetRect = presetRects_[num - 1];
|
||||
if (presetRect.size() != num) {
|
||||
WLOGE("invalid preset rects");
|
||||
return;
|
||||
}
|
||||
auto rectIt = presetRect.begin();
|
||||
for (auto node : foregroundNodes_) {
|
||||
auto& rect = (*rectIt);
|
||||
node->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
|
||||
node->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING);
|
||||
node->SetWindowRect(rect);
|
||||
node->hasDecorated_ = true;
|
||||
WLOGFI("set rect for qwin id: %{public}d [%{public}d %{public}d %{public}d %{public}d]",
|
||||
node->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_);
|
||||
rectIt++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ WMError WindowNodeContainer::UpdateWindowNode(sptr<WindowNode>& node, WindowUpda
|
||||
WLOGFE("surface node is nullptr!");
|
||||
return WMError::WM_ERROR_NULLPTR;
|
||||
}
|
||||
if (WindowHelper::IsMainWindow(node->GetWindowType()) && reason != WindowUpdateReason::UPDATE_OTHER_PROPS) {
|
||||
if (WindowHelper::IsMainWindow(node->GetWindowType()) && WindowHelper::IsSwitchCascadeReason(reason)) {
|
||||
SwitchLayoutPolicy(WindowLayoutMode::CASCADE);
|
||||
}
|
||||
layoutPolicy_->UpdateWindowNode(node);
|
||||
|
Loading…
Reference in New Issue
Block a user