diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index 57012a4dd2da1d0ed647aaaa1ee92dceda802db2..533a2790fb89352a56d757eac68c18856fa93d8f 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -88,6 +88,12 @@ public: || type == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); } + static inline bool IsRotatableWindow(WindowType type, WindowMode mode) + { + return WindowHelper::IsMainFullScreenWindow(type, mode) || type == WindowType::WINDOW_TYPE_KEYGUARD || + type == WindowType::WINDOW_TYPE_DESKTOP; + } + static inline bool IsFullScreenWindow(WindowMode mode) { return mode == WindowMode::WINDOW_MODE_FULLSCREEN; @@ -120,15 +126,6 @@ public: return r.width_ > r.height_; } - static inline bool HasOverlap(const Rect& r1, const Rect& r2) - { - int32_t r1XEnd = r1.posX_ + r1.width_; - int32_t r1YEnd = r1.posY_ + r1.height_; - int32_t r2XEnd = r2.posX_ + r2.width_; - int32_t r2YEnd = r2.posY_ + r2.height_; - return !(r1XEnd < r2.posX_ || r1.posX_ > r2XEnd || r1YEnd < r2.posY_ || r1.posY_ > r2YEnd); - } - static Rect GetOverlap(const Rect& rect1, const Rect& rect2, const int offsetX, const int offsetY) { int32_t x_begin = std::max(rect1.posX_, rect2.posX_); diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index b3374e97339c72514f94f66f8f700e93e330bb84..4f53ec208e732192217e62d8d528b61d0ada3580 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -103,7 +103,7 @@ private: WMError DestroyWindowInner(sptr& node); void UpdateFocusWindowWithWindowRemoved(const sptr& node, const sptr& container) const; - void UpdateActiveWindowWithWindowRemoved(const sptr& node, + sptr UpdateActiveWindowWithWindowRemoved(const sptr& node, const sptr& container) const; void UpdateBrightnessWithWindowRemoved(uint32_t windowId, const sptr& container) const; std::string GenAllWindowsLogInfo() const; diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 91ec6603785544a0a7bdf81b0d9ef99090fc9b05..d85899754e1dc704bfe95f69a2965b4e2141247e 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -868,7 +868,7 @@ WMError WindowController::UpdateProperty(sptr& property, Propert } case PropertyChangeAction::ACTION_UPDATE_ORIENTATION: { node->SetRequestedOrientation(property->GetRequestedOrientation()); - if (WindowHelper::IsMainFullScreenWindow(node->GetWindowType(), node->GetWindowMode())) { + if (WindowHelper::IsRotatableWindow(node->GetWindowType(), node->GetWindowMode())) { DisplayManagerServiceInner::GetInstance(). SetOrientationFromWindow(node->GetDisplayId(), property->GetRequestedOrientation()); } diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index dc5cffb4036fb084d29366634983be48fce17da4..1badb5802aa28b0c726197e74da165cdac59ac97 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -454,8 +454,24 @@ void WindowNodeContainer::RecoverScreenDefaultOrientationIfNeed(DisplayId displa { if (displayGroupController_->displayGroupWindowTree_[displayId][WindowRootNodeType::APP_WINDOW_NODE]->empty()) { WLOGFI("appWindowNode_ child is empty in display %{public}" PRIu64"", displayId); - DisplayManagerServiceInner::GetInstance(). - SetOrientationFromWindow(displayId, Orientation::UNSPECIFIED); + auto aboveWindows = + *displayGroupController_->displayGroupWindowTree_[displayId][WindowRootNodeType::ABOVE_WINDOW_NODE]; + for (auto iter = aboveWindows.begin(); iter != aboveWindows.end(); iter++) { + auto windowMode = (*iter)->GetWindowMode(); + if (WindowHelper::IsFullScreenWindow(windowMode) || WindowHelper::IsSplitWindowMode(windowMode)) { + return; + } + } + auto belowWindows = + *displayGroupController_->displayGroupWindowTree_[displayId][WindowRootNodeType::BELOW_WINDOW_NODE]; + Orientation targetOrientation = Orientation::UNSPECIFIED; + for (auto iter = belowWindows.begin(); iter != belowWindows.end(); iter++) { + if ((*iter)->GetWindowType() == WindowType::WINDOW_TYPE_DESKTOP) { + targetOrientation = (*iter)->GetRequestedOrientation(); + break; + } + } + DisplayManagerServiceInner::GetInstance().SetOrientationFromWindow(displayId, targetOrientation); } } @@ -869,7 +885,7 @@ void WindowNodeContainer::NotifyIfKeyboardRegionChanged(const sptr& callingWindowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { const Rect keyRect = node->GetWindowRect(); const Rect callingRect = callingWindow->GetWindowRect(); - if (!WindowHelper::HasOverlap(callingRect, keyRect)) { + if (WindowHelper::IsEmptyRect(WindowHelper::GetOverlap(callingRect, keyRect, 0, 0))) { WLOGFD("no overlap between two windows"); return; } diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 5946f97feaf81ce795650087b0708dba7dc2f77f..c33611d91da7e3166617e74d5f8131fe5c21dcc9 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -443,8 +443,7 @@ WMError WindowRoot::PostProcessAddWindowNode(sptr& node, sptrGetWindowId(), node->GetWindowName().c_str(), static_cast(node->GetRequestedOrientation()), node->GetWindowType(), WindowHelper::IsMainWindow(node->GetWindowType())); - if (WindowHelper::IsMainWindow(node->GetWindowType()) && - node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { + if (WindowHelper::IsRotatableWindow(node->GetWindowType(), node->GetWindowMode())) { DisplayManagerServiceInner::GetInstance(). SetOrientationFromWindow(node->GetDisplayId(), node->GetRequestedOrientation()); } @@ -536,7 +535,7 @@ WMError WindowRoot::RemoveWindowNode(uint32_t windowId) } container->DropShowWhenLockedWindowIfNeeded(node); UpdateFocusWindowWithWindowRemoved(node, container); - UpdateActiveWindowWithWindowRemoved(node, container); + auto nextOrientationWindow = UpdateActiveWindowWithWindowRemoved(node, container); UpdateBrightnessWithWindowRemoved(windowId, container); WMError res = container->RemoveWindowNode(node); if (res == WMError::WM_OK) { @@ -548,6 +547,14 @@ WMError WindowRoot::RemoveWindowNode(uint32_t windowId) } HandleKeepScreenOn(windowId, false); } + while (nextOrientationWindow != nullptr && !WindowHelper::IsMainWindow(nextOrientationWindow->GetWindowType())) { + nextOrientationWindow = nextOrientationWindow->parent_; + } + if (nextOrientationWindow != nullptr && WindowHelper::IsRotatableWindow( + nextOrientationWindow->GetWindowType(), nextOrientationWindow->GetWindowMode())) { + DisplayManagerServiceInner::GetInstance().SetOrientationFromWindow(nextOrientationWindow->GetDisplayId(), + nextOrientationWindow->GetRequestedOrientation()); + } return res; } @@ -654,7 +661,12 @@ WMError WindowRoot::SetWindowMode(sptr& node, WindowMode dstMode) WLOGFE("set window mode failed, window container could not be found"); return WMError::WM_ERROR_NULLPTR; } - return container->SetWindowMode(node, dstMode); + auto res = container->SetWindowMode(node, dstMode); + if (WindowHelper::IsRotatableWindow(node->GetWindowType(), node->GetWindowMode())) { + DisplayManagerServiceInner::GetInstance(). + SetOrientationFromWindow(node->GetDisplayId(), node->GetRequestedOrientation()); + } + return res; } WMError WindowRoot::DestroyWindow(uint32_t windowId, bool onlySelf) @@ -786,12 +798,12 @@ void WindowRoot::UpdateFocusWindowWithWindowRemoved(const sptr& node } } -void WindowRoot::UpdateActiveWindowWithWindowRemoved(const sptr& node, +sptr WindowRoot::UpdateActiveWindowWithWindowRemoved(const sptr& node, const sptr& container) const { if (node == nullptr || container == nullptr) { WLOGFE("window is invalid"); - return; + return nullptr; } uint32_t windowId = node->GetWindowId(); uint32_t activeWindowId = container->GetActiveWindow(); @@ -803,7 +815,7 @@ void WindowRoot::UpdateActiveWindowWithWindowRemoved(const sptr& nod return node->GetWindowId() == activeWindowId; }); if (iter == node->children_.end()) { - return; + return nullptr; } } if (!node->children_.empty()) { @@ -814,7 +826,7 @@ void WindowRoot::UpdateActiveWindowWithWindowRemoved(const sptr& nod } } else { if (windowId != activeWindowId) { - return; + return nullptr; } } auto nextActiveWindow = container->GetNextActiveWindow(windowId); @@ -822,6 +834,7 @@ void WindowRoot::UpdateActiveWindowWithWindowRemoved(const sptr& nod WLOGFI("adjust active window, next active window id: %{public}u", nextActiveWindow->GetWindowId()); container->SetActiveWindow(nextActiveWindow->GetWindowId(), true); } + return nextActiveWindow; } void WindowRoot::UpdateBrightnessWithWindowRemoved(uint32_t windowId, const sptr& container) const @@ -884,8 +897,8 @@ WMError WindowRoot::RequestActiveWindow(uint32_t windowId) WLOGFI("windowId:%{public}u, name:%{public}s, orientation:%{public}u, type:%{public}u, isMainWindow:%{public}d", windowId, node->GetWindowName().c_str(), static_cast(node->GetRequestedOrientation()), node->GetWindowType(), WindowHelper::IsMainWindow(node->GetWindowType())); - if (res == WMError::WM_OK && WindowHelper::IsMainWindow(node->GetWindowType()) && - node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { + if (res == WMError::WM_OK && + WindowHelper::IsRotatableWindow(node->GetWindowType(), node->GetWindowMode())) { DisplayManagerServiceInner::GetInstance(). SetOrientationFromWindow(node->GetDisplayId(), node->GetRequestedOrientation()); }