diff --git a/dmserver/include/abstract_screen.h b/dmserver/include/abstract_screen.h index 3e5ed94b..01c73a7b 100644 --- a/dmserver/include/abstract_screen.h +++ b/dmserver/include/abstract_screen.h @@ -70,6 +70,7 @@ public: float virtualPixelRatio_ = { 1.0 }; Orientation orientation_ { Orientation::UNSPECIFIED }; Rotation rotation_ { Rotation::ROTATION_0 }; + Orientation screenRequestedOrientation_ { Orientation::UNSPECIFIED }; protected: void FillScreenInfo(sptr) const; const sptr screenController_; diff --git a/dmserver/include/abstract_screen_controller.h b/dmserver/include/abstract_screen_controller.h index 3677a03a..f81c2097 100644 --- a/dmserver/include/abstract_screen_controller.h +++ b/dmserver/include/abstract_screen_controller.h @@ -59,7 +59,7 @@ public: ScreenId CreateVirtualScreen(VirtualScreenOption option, const sptr& displayManagerAgent); DMError DestroyVirtualScreen(ScreenId screenId); DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface); - bool SetOrientation(ScreenId screenId, Orientation orientation); + bool SetOrientation(ScreenId screenId, Orientation orientation, bool isFromWindow); bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId); std::shared_ptr GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 4c2e83aa..4299df48 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -50,6 +50,7 @@ public: sptr GetDisplayInfoById(DisplayId displayId) override; sptr GetDisplayInfoByScreen(ScreenId screenId) override; bool SetOrientation(ScreenId screenId, Orientation orientation) override; + bool SetOrientationFromWindow(ScreenId screenId, Orientation orientation); std::shared_ptr GetDisplaySnapshot(DisplayId displayId) override; ScreenId GetRSScreenId(DisplayId displayId) const; diff --git a/dmserver/include/display_manager_service_inner.h b/dmserver/include/display_manager_service_inner.h index dc893703..ab8a0fc8 100644 --- a/dmserver/include/display_manager_service_inner.h +++ b/dmserver/include/display_manager_service_inner.h @@ -42,6 +42,7 @@ public: std::shared_ptr GetDisplaySnapshot(DisplayId) const; void UpdateRSTree(DisplayId displayId, std::shared_ptr& surfaceNode, bool isAdd); void RegisterDisplayChangeListener(sptr listener); + bool SetOrientationFromWindow(DisplayId displayId, Orientation orientation); }; } // namespace OHOS::Rosen diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index 312c6798..34086b79 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -597,7 +597,7 @@ DMError AbstractScreenController::SetVirtualScreenSurface(ScreenId screenId, spt return DMError::DM_OK; } -bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation newOrientation) +bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation newOrientation, bool isFromWindow) { WLOGD("set orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation); auto screen = GetAbstractScreen(screenId); @@ -609,6 +609,13 @@ bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation new WLOGE("cannot set orientation to the combination. screen: %{public}" PRIu64"", screenId); return false; } + if (isFromWindow) { + if (newOrientation == Orientation::UNSPECIFIED) { + newOrientation = screen->screenRequestedOrientation_; + } + } else { + screen->screenRequestedOrientation_ = newOrientation; + } if (screen->orientation_ == newOrientation) { WLOGI("skip setting orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation); return true; diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index eaf48086..cc2e510a 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -150,7 +150,13 @@ DMError DisplayManagerService::SetVirtualScreenSurface(ScreenId screenId, sptrSetOrientation(screenId, orientation); + return abstractScreenController_->SetOrientation(screenId, orientation, false); +} + +bool DisplayManagerService::SetOrientationFromWindow(ScreenId screenId, Orientation orientation) +{ + WM_SCOPED_TRACE("dms:SetOrientation(%" PRIu64")", screenId); + return abstractScreenController_->SetOrientation(screenId, orientation, true); } std::shared_ptr DisplayManagerService::GetDisplaySnapshot(DisplayId displayId) diff --git a/dmserver/src/display_manager_service_inner.cpp b/dmserver/src/display_manager_service_inner.cpp index 011accad..44576c5d 100644 --- a/dmserver/src/display_manager_service_inner.cpp +++ b/dmserver/src/display_manager_service_inner.cpp @@ -117,4 +117,14 @@ void DisplayManagerServiceInner::RegisterDisplayChangeListener(sptrGetScreenId(), orientation); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 500e80b5..f01d2407 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -191,6 +191,8 @@ public: virtual std::string GetContentInfo() = 0; virtual Ace::UIContent* GetUIContent() const = 0; virtual void OnNewWant(const AAFwk::Want& want) = 0; + virtual void SetRequestedOrientation(Orientation) = 0; + virtual Orientation GetRequestedOrientation() = 0; virtual bool IsDecorEnable() const = 0; virtual WMError Maximize() = 0; diff --git a/interfaces/innerkits/wm/window_option.h b/interfaces/innerkits/wm/window_option.h index 06908de7..fb2dd7ed 100644 --- a/interfaces/innerkits/wm/window_option.h +++ b/interfaces/innerkits/wm/window_option.h @@ -19,6 +19,7 @@ #include #include +#include "../dm/dm_common.h" #include "wm_common.h" namespace OHOS { @@ -67,6 +68,8 @@ public: const std::unordered_map& GetSystemBarProperty() const; const PointInfo& GetHitOffset() const; WindowTag GetWindowTag() const; + Orientation GetRequestedOrientation() const; + void SetRequestedOrientation(Orientation orientation); private: Rect windowRect_ { 0, 0, 0, 0 }; WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; @@ -89,6 +92,7 @@ private: { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, }; + Orientation requestedOrientation_ { Orientation::UNSPECIFIED }; }; } // namespace Rosen } // namespace OHOS diff --git a/utils/include/window_property.h b/utils/include/window_property.h index 3d2a5132..3232b00a 100644 --- a/utils/include/window_property.h +++ b/utils/include/window_property.h @@ -20,6 +20,9 @@ #include #include #include "parcel.h" + +#include "class_var_definition.h" +#include "dm_common.h" #include "wm_common.h" namespace OHOS { @@ -118,6 +121,7 @@ private: { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, }; bool isDecorEnable_ { false }; + DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED); }; } } diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index 479b43f8..dc438b9a 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -63,6 +63,7 @@ enum class PropertyChangeAction : uint32_t { ACTION_UPDATE_FOCUSABLE = 1 << 4, ACTION_UPDATE_TOUCHABLE = 1 << 5, ACTION_UPDATE_CALLING_WINDOW = 1 << 6, + ACTION_UPDATE_ORIENTATION = 1 << 7, }; namespace { diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index 1c423d78..7039ae51 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -324,7 +324,7 @@ bool WindowProperty::Marshalling(Parcel& parcel) const parcel.WriteUint32(parentId_) && MapMarshalling(parcel) && parcel.WriteBool(isDecorEnable_) && parcel.WriteInt32(hitOffset_.x) && parcel.WriteInt32(hitOffset_.y) && parcel.WriteUint32(animationFlag_) && parcel.WriteUint32(static_cast(windowSizeChangeReason_)) && parcel.WriteBool(tokenState_) && - parcel.WriteUint32(callingWindow_); + parcel.WriteUint32(callingWindow_) && parcel.WriteUint32(static_cast(requestedOrientation_)); } sptr WindowProperty::Unmarshalling(Parcel& parcel) @@ -356,6 +356,7 @@ sptr WindowProperty::Unmarshalling(Parcel& parcel) property->SetWindowSizeChangeReason(static_cast(parcel.ReadUint32())); property->SetTokenState(parcel.ReadBool()); property->SetCallingWindow(parcel.ReadUint32()); + property->SetRequestedOrientation(static_cast(parcel.ReadUint32())); return property; } @@ -385,6 +386,7 @@ void WindowProperty::CopyFrom(const sptr& property) isDecorEnable_ = property->isDecorEnable_; tokenState_ = property->tokenState_; callingWindow_ = property->callingWindow_; + requestedOrientation_ = property->requestedOrientation_; } } } diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 6ac5cd1c..45011a16 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -181,6 +181,8 @@ public: virtual const std::shared_ptr GetContext() const override; virtual Ace::UIContent* GetUIContent() const override; virtual void OnNewWant(const AAFwk::Want& want) override; + virtual void SetRequestedOrientation(Orientation) override; + virtual Orientation GetRequestedOrientation() override; // colorspace, gamut virtual bool IsSupportWideGamut() override; diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 562e52e6..58422a18 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -61,6 +61,7 @@ WindowImpl::WindowImpl(const sptr& option) property_->SetCallingWindow(option->GetCallingWindow()); property_->SetWindowFlags(option->GetWindowFlags()); property_->SetHitOffset(option->GetHitOffset()); + property_->SetRequestedOrientation(option->GetRequestedOrientation()); windowTag_ = option->GetWindowTag(); keepScreenOn_ = option->IsKeepScreenOn(); turnScreenOn_ = option->IsTurnScreenOn(); @@ -1723,5 +1724,19 @@ bool WindowImpl::IsFullScreen() const auto naviProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR); return (IsLayoutFullScreen() && !statusProperty.enable_ && !naviProperty.enable_); } + +void WindowImpl::SetRequestedOrientation(Orientation orientation) +{ + if (property_->GetRequestedOrientation() == orientation) { + return; + } + property_->SetRequestedOrientation(orientation); + UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ORIENTATION); +} + +Orientation WindowImpl::GetRequestedOrientation() +{ + return property_->GetRequestedOrientation(); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_option.cpp b/wm/src/window_option.cpp index ed3faad5..9c7011d2 100644 --- a/wm/src/window_option.cpp +++ b/wm/src/window_option.cpp @@ -222,6 +222,16 @@ uint32_t WindowOption::GetCallingWindow() const { return callingWindow_; } + +Orientation WindowOption::GetRequestedOrientation() const +{ + return requestedOrientation_; +} + +void WindowOption::SetRequestedOrientation(Orientation orientation) +{ + requestedOrientation_ = orientation; +} } // namespace Rosen } // namespace OHOS diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 71162535..e7d2da01 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -63,6 +63,7 @@ private: WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); WMError ResizeRect(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason); WMError SetWindowMode(uint32_t windowId, WindowMode dstMode); + void ReSizeSystemBarPropertySizeIfNeed(sptr& property); sptr windowRoot_; sptr inputWindowMonitor_; @@ -72,6 +73,8 @@ private: { WindowType::WINDOW_TYPE_STATUS_BAR, INVALID_WINDOW_ID }, { WindowType::WINDOW_TYPE_NAVIGATION_BAR, INVALID_WINDOW_ID }, }; + std::unordered_map>> systemBarRect_; + std::unordered_map> curDisplayInfo_; constexpr static float SYSTEM_BAR_HEIGHT_RATIO = 0.08; }; } diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index d5b9cc3c..9cd87024 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -55,6 +55,7 @@ public: void SetCallingWindow(uint32_t windowId); uint32_t GetCallingWindow() const; void SetWindowSizeChangeReason(WindowSizeChangeReason reason); + void SetRequestedOrientation(Orientation orientation); const sptr& GetWindowToken() const; uint32_t GetWindowId() const; uint32_t GetParentId() const; @@ -74,6 +75,7 @@ public: const std::unordered_map& GetSystemBarProperty() const; bool IsSplitMode() const; WindowSizeChangeReason GetWindowSizeChangeReason() const; + Orientation GetRequestedOrientation() const; void ResetWindowSizeChangeReason(); sptr parent_; diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 2818c465..0115db9f 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -59,6 +59,7 @@ WMError WindowController::AddWindowNode(sptr& property) WLOGFE("current window is visible, windowId: %{public}u", node->GetWindowId()); return WMError::WM_ERROR_INVALID_OPERATION; } + ReSizeSystemBarPropertySizeIfNeed(property); node->GetWindowProperty()->CopyFrom(property); // Need 'check permission' @@ -89,6 +90,29 @@ WMError WindowController::AddWindowNode(sptr& property) return WMError::WM_OK; } +void WindowController::ReSizeSystemBarPropertySizeIfNeed(sptr& property) +{ + auto displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(property->GetDisplayId()); + uint32_t displayWidth = static_cast(displayInfo->GetWidth()); + uint32_t displayHeight = static_cast(displayInfo->GetHeight()); + if (property->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR) { + auto statusBarRectIter = + systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].find(displayHeight); + if (statusBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].end()) { + property->SetWindowRect(statusBarRectIter->second); + } + } else if (property->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + auto navigationBarRectIter = + systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].find(displayHeight); + if (navigationBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].end()) { + property->SetWindowRect(navigationBarRectIter->second); + } + } + if (curDisplayInfo_.find(displayInfo->GetDisplayId()) == curDisplayInfo_.end()) { + curDisplayInfo_[displayInfo->GetDisplayId()] = displayInfo; + } +} + WMError WindowController::RemoveWindowNode(uint32_t windowId) { WMError res = windowRoot_->RemoveWindowNode(windowId); @@ -296,14 +320,39 @@ void WindowController::ProcessDisplayChange(DisplayId displayId, DisplayStateCha switch (type) { case DisplayStateChangeType::SIZE_CHANGE: case DisplayStateChangeType::UPDATE_ROTATION: { + auto iter = curDisplayInfo_.find(displayId); + if (iter != curDisplayInfo_.end()) { + auto lastDisplayInfo = iter->second; + uint32_t lastDisplayWidth = static_cast(lastDisplayInfo->GetWidth()); + uint32_t lastDisplayHeight = static_cast(lastDisplayInfo->GetHeight()); + auto statusBarNode = windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR]); + auto navigationBarNode = + windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_NAVIGATION_BAR]); + systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][lastDisplayWidth][lastDisplayHeight] + = statusBarNode->GetWindowProperty()->GetWindowRect(); + systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][lastDisplayWidth][lastDisplayHeight] + = navigationBarNode->GetWindowProperty()->GetWindowRect(); + } + curDisplayInfo_[displayId] = displayInfo; windowRoot_->NotifyDisplayChange(displayInfo); - // Remove 'sysBarWinId_' after SystemUI resize 'systembar' uint32_t width = static_cast(displayInfo->GetWidth()); uint32_t height = static_cast(displayInfo->GetHeight() * SYSTEM_BAR_HEIGHT_RATIO); Rect newRect = { 0, 0, width, height }; + uint32_t displayWidth = static_cast(displayInfo->GetWidth()); + uint32_t displayHeight = static_cast(displayInfo->GetHeight()); + auto statusBarRectIter = + systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].find(displayHeight); + if (statusBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].end()) { + newRect = statusBarRectIter->second; + } ResizeRect(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR], newRect, WindowSizeChangeReason::DRAG); newRect = { 0, displayInfo->GetHeight() - static_cast(height), width, height }; + auto navigationBarRectIter = + systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].find(displayHeight); + if (navigationBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].end()) { + newRect = navigationBarRectIter->second; + } ResizeRect(sysBarWinId_[WindowType::WINDOW_TYPE_NAVIGATION_BAR], newRect, WindowSizeChangeReason::DRAG); break; } @@ -537,6 +586,12 @@ WMError WindowController::UpdateProperty(sptr& property, Propert node->SetCallingWindow(property->GetCallingWindow()); break; } + case PropertyChangeAction::ACTION_UPDATE_ORIENTATION: { + node->SetRequestedOrientation(property->GetRequestedOrientation()); + DisplayManagerServiceInner::GetInstance(). + SetOrientationFromWindow(node->GetDisplayId(), property->GetRequestedOrientation()); + break; + } default: break; } diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index 5c8f758f..697c72df 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -127,6 +127,11 @@ void WindowNode::SetWindowSizeChangeReason(WindowSizeChangeReason reason) windowSizeChangeReason_ = reason; } +void WindowNode::SetRequestedOrientation(Orientation orientation) +{ + property_->SetRequestedOrientation(orientation); +} + void WindowNode::ResetWindowSizeChangeReason() { windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED; @@ -227,5 +232,10 @@ WindowSizeChangeReason WindowNode::GetWindowSizeChangeReason() const { return windowSizeChangeReason_; } + +Orientation WindowNode::GetRequestedOrientation() const +{ + return property_->GetRequestedOrientation(); +} } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index cf8ca6d6..e41ed2e6 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -221,6 +221,14 @@ WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr& node) container->SetActiveWindow(node->GetWindowId(), false); NotifyKeyboardSizeChangeInfo(node, container, node->GetLayoutRect()); } + WLOGFI("windowId:%{public}u, name:%{public}s, orientation:%{public}u, type:%{public}u, isMainWindow:%{public}d", + node->GetWindowId(), 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) { + DisplayManagerServiceInner::GetInstance(). + SetOrientationFromWindow(node->GetDisplayId(), node->GetRequestedOrientation()); + } return res; } @@ -512,7 +520,16 @@ WMError WindowRoot::RequestActiveWindow(uint32_t windowId) WLOGFE("window container could not be found"); return WMError::WM_ERROR_NULLPTR; } - return container->SetActiveWindow(windowId, false); + auto res = container->SetActiveWindow(windowId, false); + 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) { + DisplayManagerServiceInner::GetInstance(). + SetOrientationFromWindow(node->GetDisplayId(), node->GetRequestedOrientation()); + } + return res; } std::shared_ptr WindowRoot::GetSurfaceNodeByAbilityToken(const sptr &abilityToken) const