diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 6a866ded..70058ca9 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -138,14 +138,7 @@ struct PointInfo { namespace { constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF; constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000; - constexpr float DEFAULT_SPLIT_RATIO = 0.5; - constexpr uint32_t DIVIDER_WIDTH = 8; constexpr uint32_t INVALID_WINDOW_ID = 0; - constexpr uint32_t HOTZONE = 40; - constexpr uint32_t MIN_VERTICAL_FLOATING_WIDTH = 240; - constexpr uint32_t MIN_VERTICAL_FLOATING_HEIGHT = 426; - constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 426; - constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 426; } struct SystemBarProperty { diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index f521d3be..9e822ae0 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -17,6 +17,7 @@ #define OHOS_WM_INCLUDE_WM_HELPER_H #include +#include namespace OHOS { namespace Rosen { @@ -79,15 +80,18 @@ public: return (r.posX_ == 0 && r.posY_ == 0 && r.width_ == 0 && r.height_ == 0); } - static Rect GetFixedWindowRectByMinRect(const Rect& oriDstRect, const Rect& lastRect, bool isVertical) + static Rect GetFixedWindowRectByMinRect(const Rect& oriDstRect, const Rect& lastRect, bool isVertical, + float virtualPixelRatio) { + uint32_t minVerticalFloatingW = static_cast(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio); + uint32_t minVerticalFloatingH = static_cast(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio); Rect dstRect = oriDstRect; if (isVertical) { - dstRect.width_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, oriDstRect.width_); - dstRect.height_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, oriDstRect.height_); + dstRect.width_ = std::max(minVerticalFloatingW, oriDstRect.width_); + dstRect.height_ = std::max(minVerticalFloatingH, oriDstRect.height_); } else { - dstRect.width_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, oriDstRect.width_); - dstRect.height_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, oriDstRect.height_); + dstRect.width_ = std::max(minVerticalFloatingH, oriDstRect.width_); + dstRect.height_ = std::max(minVerticalFloatingW, oriDstRect.height_); } // limit position by fixed width or height diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index fda04fe8..369fd40d 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -44,6 +44,18 @@ enum class WindowUpdateReason : uint32_t { UPDATE_TYPE, UPDATE_OTHER_PROPS, }; +namespace { + constexpr float DEFAULT_SPLIT_RATIO = 0.5; + constexpr uint32_t DIVIDER_WIDTH = 8; + constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 48; + constexpr uint32_t WINDOW_FRAME_WIDTH = 4; + constexpr uint32_t HOTZONE = 40; + constexpr uint32_t DIV_HOTZONE = 20; + constexpr uint32_t MIN_VERTICAL_FLOATING_WIDTH = 240; + constexpr uint32_t MIN_VERTICAL_FLOATING_HEIGHT = 426; + constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 426; + constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 426; +} } } #endif // OHOS_ROSEN_WM_COMMON_INNER_H \ No newline at end of file diff --git a/wm/test/systemtest/window_layout_test.cpp b/wm/test/systemtest/window_layout_test.cpp index 9b5b381e..6bb5c15a 100644 --- a/wm/test/systemtest/window_layout_test.cpp +++ b/wm/test/systemtest/window_layout_test.cpp @@ -32,6 +32,7 @@ public: DisplayId displayId_ = 0; std::vector> activeWindows_; static vector fullScreenExpecteds_; + static inline float virtualPixelRatio_ = 0.0; }; vector WindowLayoutTest::fullScreenExpecteds_; @@ -47,6 +48,9 @@ void WindowLayoutTest::SetUpTestCase() } Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; utils::InitByDisplayRect(displayRect); + + virtualPixelRatio_ = WindowTestUtils::GetVirtualPixelRatio(0); + // calc expected rects Rect expected = { // 0. only statusBar 0, @@ -110,7 +114,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow02, Function | MediumTest | Level3) activeWindows_.push_back(window); ASSERT_EQ(WMError::WM_OK, window->Show()); - ASSERT_TRUE(utils::RectEqualTo(window, utils::GetFloatingLimitedRect(utils::customAppRect_))); + ASSERT_TRUE(utils::RectEqualTo(window, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_))); ASSERT_EQ(WMError::WM_OK, window->Hide()); } @@ -140,12 +144,12 @@ HWTEST_F(WindowLayoutTest, LayoutWindow04, Function | MediumTest | Level3) activeWindows_.push_back(statBar); ASSERT_EQ(WMError::WM_OK, appWin->Show()); - ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_))); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_))); ASSERT_EQ(WMError::WM_OK, statBar->Show()); - ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_))); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_))); ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_)); ASSERT_EQ(WMError::WM_OK, statBar->Hide()); - ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_))); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_))); } /** @@ -277,7 +281,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow09, Function | MediumTest | Level3) ASSERT_EQ(WMError::WM_OK, window->Resize(2u, 2u)); // 2: custom min size Rect finalExcept = { expect.posX_, expect.posY_, 2u, 2u}; // 2: custom min size - finalExcept = utils::GetFloatingLimitedRect(finalExcept); + finalExcept = utils::GetFloatingLimitedRect(finalExcept, virtualPixelRatio_); ASSERT_TRUE(utils::RectEqualTo(window, finalExcept)); ASSERT_EQ(WMError::WM_OK, window->Hide()); } diff --git a/wm/test/systemtest/window_move_drag_test.cpp b/wm/test/systemtest/window_move_drag_test.cpp index 38783803..fc033776 100644 --- a/wm/test/systemtest/window_move_drag_test.cpp +++ b/wm/test/systemtest/window_move_drag_test.cpp @@ -18,6 +18,7 @@ #include "pointer_event.h" #include "window_helper.h" #include "window_test_utils.h" +#include "wm_common_inner.h" using namespace testing; using namespace testing::ext; @@ -54,6 +55,8 @@ private: static inline Rect startPointRect_ = {0, 0, 0, 0}; static inline Rect expectRect_ = {0, 0, 0, 0}; static inline sptr window_ = nullptr; + static inline float virtualPixelRatio_ = 0.0; + static inline uint32_t hotZone_ = 0; }; void WindowMoveDragTest::SetUpTestCase() @@ -83,6 +86,9 @@ void WindowMoveDragTest::SetUp() Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; utils::InitByDisplayRect(displayRect); + virtualPixelRatio_ = WindowTestUtils::GetVirtualPixelRatio(0); + hotZone_ = static_cast(HOTZONE * virtualPixelRatio_); + winInfo_ = { .name = "Floating", .rect = {0, 0, 0, 0}, @@ -174,7 +180,7 @@ void WindowMoveDragTest::CalExpectRects() } } bool isVertical = (utils::displayRect_.width_ < utils::displayRect_.height_) ? true : false; - expectRect_ = WindowHelper::GetFixedWindowRectByMinRect(oriRect, startPointRect_, isVertical); + expectRect_ = WindowHelper::GetFixedWindowRectByMinRect(oriRect, startPointRect_, isVertical, virtualPixelRatio_); } namespace { @@ -188,10 +194,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow01, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ - HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ - hotZone_ * POINT_HOTZONE_RATIO; startPointY_ = startPointRect_.posY_ + startPointRect_.height_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + HOTZONE * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + hotZone_ * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -206,11 +212,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow02, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ - HOTZONE * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ - HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ - hotZone_ * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ - hotZone_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + HOTZONE * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + hotZone_ * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -225,11 +231,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow03, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ - HOTZONE * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ - hotZone_ * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + HOTZONE * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + hotZone_ * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -244,10 +250,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow04, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * POINT_HOTZONE_RATIO; startPointY_ = startPointRect_.posY_ + startPointRect_.height_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * DRAG_HOTZONE_RATIO; pointY_ = startPointRect_.posY_ + startPointRect_.height_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); @@ -263,11 +269,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow05, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ - HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ - hotZone_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -282,11 +288,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow06, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -302,10 +308,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow07, Function | MediumTest | Level3) ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); startPointX_ = startPointRect_.posX_ + startPointRect_.width_ * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ - HOTZONE * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ - hotZone_ * POINT_HOTZONE_RATIO; pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ - HOTZONE * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ - hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -321,10 +327,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow08, Function | MediumTest | Level3) ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); startPointX_ = startPointRect_.posX_ + startPointRect_.width_ * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * POINT_HOTZONE_RATIO; pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -343,7 +349,7 @@ HWTEST_F(WindowMoveDragTest, DragWindow09, Function | MediumTest | Level3) startPointY_ = startPointRect_.posY_ + 1; pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -362,7 +368,7 @@ HWTEST_F(WindowMoveDragTest, DragWindow10, Function | MediumTest | Level3) startPointY_ = startPointRect_.posY_ + 1; pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO; window_->StartMove(); hasStartMove_ = true; DoMoveOrDrag(); diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp index 23fa2b83..3f7b91dd 100644 --- a/wm/test/systemtest/window_test_utils.cpp +++ b/wm/test/systemtest/window_test_utils.cpp @@ -15,6 +15,7 @@ #include "window_test_utils.h" #include +#include "wm_common_inner.h" namespace OHOS { namespace Rosen { namespace { @@ -123,13 +124,18 @@ Rect WindowTestUtils::GetDefaultFoatingRect(const sptr& window) return resRect; } -Rect WindowTestUtils::GetLimitedDecoRect(const Rect& rect) +Rect WindowTestUtils::GetLimitedDecoRect(const Rect& rect, float virtualPixelRatio) { - constexpr uint32_t winFrameH = 52u; - constexpr uint32_t winFrameW = 8u; + constexpr uint32_t windowTitleBarHeight = 48; + constexpr uint32_t windowFrameWidth = 4; + uint32_t winFrameH = static_cast((windowTitleBarHeight + windowFrameWidth) * virtualPixelRatio); + uint32_t winFrameW = static_cast((windowFrameWidth + windowFrameWidth) * virtualPixelRatio); + uint32_t minVerticalFloatingW = static_cast(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio); + uint32_t minVerticalFloatingH = static_cast(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio); + bool vertical = displayRect_.width_ < displayRect_.height_; - uint32_t minFloatingW = vertical ? MIN_VERTICAL_FLOATING_WIDTH : MIN_VERTICAL_FLOATING_HEIGHT; - uint32_t minFloatingH = vertical ? MIN_VERTICAL_FLOATING_HEIGHT : MIN_VERTICAL_FLOATING_WIDTH; + uint32_t minFloatingW = vertical ? minVerticalFloatingW : minVerticalFloatingH; + uint32_t minFloatingH = vertical ? minVerticalFloatingH : minVerticalFloatingW; Rect resRect = { rect.posX_, rect.posY_, @@ -139,11 +145,14 @@ Rect WindowTestUtils::GetLimitedDecoRect(const Rect& rect) return resRect; } -Rect WindowTestUtils::GetFloatingLimitedRect(const Rect& rect) +Rect WindowTestUtils::GetFloatingLimitedRect(const Rect& rect, float virtualPixelRatio) { + uint32_t minVerticalFloatingW = static_cast(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio); + uint32_t minVerticalFloatingH = static_cast(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio); bool vertical = displayRect_.width_ < displayRect_.height_; - uint32_t minFloatingW = vertical ? MIN_VERTICAL_FLOATING_WIDTH : MIN_VERTICAL_FLOATING_HEIGHT; - uint32_t minFloatingH = vertical ? MIN_VERTICAL_FLOATING_HEIGHT : MIN_VERTICAL_FLOATING_WIDTH; + + uint32_t minFloatingW = vertical ? minVerticalFloatingW : minVerticalFloatingH; + uint32_t minFloatingH = vertical ? minVerticalFloatingH : minVerticalFloatingW; Rect resRect = { rect.posX_, rect.posY_, @@ -257,18 +266,21 @@ void WindowTestUtils::InitSplitRects() displayRect_ = displayRect; limitDisplayRect_ = displayRect; + float virtualPixelRatio = WindowTestUtils::GetVirtualPixelRatio(0); + uint32_t dividerWidth = static_cast(DIVIDER_WIDTH * virtualPixelRatio); + if (displayRect_.width_ < displayRect_.height_) { isVerticalDisplay_ = true; } if (isVerticalDisplay_) { splitRects_.dividerRect = { 0, - static_cast((displayRect_.height_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), + static_cast((displayRect_.height_ - dividerWidth) * DEFAULT_SPLIT_RATIO), displayRect_.width_, - DIVIDER_WIDTH, }; + dividerWidth, }; } else { - splitRects_.dividerRect = { static_cast((displayRect_.width_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), + splitRects_.dividerRect = { static_cast((displayRect_.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO), 0, - DIVIDER_WIDTH, + dividerWidth, displayRect_.height_ }; } } @@ -374,5 +386,17 @@ void WindowTestUtils::UpdateLimitSplitRect(Rect& limitSplitRect) curLimitRect.posY_ + curLimitRect.height_) - limitSplitRect.posY_; } + +float WindowTestUtils::GetVirtualPixelRatio(DisplayId displayId) +{ + auto display = DisplayManager::GetInstance().GetDisplayById(displayId); + if (display == nullptr) { + WLOGFE("GetVirtualPixel fail. Get display fail. displayId:%{public}" PRIu64", vpr:%{public}f", displayId, 0.0); + return 0.0; + } + float virtualPixelRatio = display->GetVirtualPixelRatio(); + WLOGFI("GetVirtualPixel success. displayId:%{public}" PRIu64", vpr:%{public}f", displayId, virtualPixelRatio); + return virtualPixelRatio; +} } // namespace ROSEN } // namespace OHOS diff --git a/wm/test/systemtest/window_test_utils.h b/wm/test/systemtest/window_test_utils.h index 2742aa30..5234262b 100644 --- a/wm/test/systemtest/window_test_utils.h +++ b/wm/test/systemtest/window_test_utils.h @@ -66,9 +66,10 @@ public: static void UpdateSplitRects(const sptr& window); static bool RectEqualToRect(const Rect& l, const Rect& r); static Rect GetDefaultFoatingRect(const sptr& window); - static Rect GetLimitedDecoRect(const Rect& rect); - static Rect GetFloatingLimitedRect(const Rect& rect); + static Rect GetLimitedDecoRect(const Rect& rect, float virtualPixelRatio); + static Rect GetFloatingLimitedRect(const Rect& rect, float virtualPixelRatio); static void InitTileWindowRects(const sptr& window); + static float GetVirtualPixelRatio(DisplayId displayId); private: void UpdateLimitDisplayRect(Rect& avoidRect); diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 1f438fb3..7224420b 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -75,6 +75,7 @@ ohos_shared_library("libwms") { ":window_divider_image", "//foundation/ace/ace_engine/build/external_config/flutter/skia:ace_skia_ohos", "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index d2b0fc7a..20738683 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -50,6 +50,7 @@ public: virtual void UpdateWindowNode(sptr& node); virtual void UpdateLayoutRect(sptr& node) = 0; void UpdateDefaultFoatingRect(); + float GetVirtualPixelRatio() const; protected: const Rect& displayRect_; @@ -66,6 +67,7 @@ protected: void UpdateLimitRect(const sptr& node, Rect& limitRect); virtual void LayoutWindowNode(sptr& node); AvoidPosType GetAvoidPosType(const Rect& rect); + void CalcAndSetNodeHotZone(Rect layoutOutRect, sptr& node); void LimitWindowSize(const sptr& node, const Rect& displayRect, Rect& winRect); void SetRectForFloating(const sptr& node); Rect ComputeDecoratedWindowRect(const Rect& winRect); diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index 863b89eb..00cdf28b 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -42,6 +42,7 @@ public: void SetDisplayId(DisplayId displayId); void SetLayoutRect(const Rect& rect); + void SetHotZoneRect(const Rect& rect); void SetWindowRect(const Rect& rect); void SetWindowProperty(const sptr& property); void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); @@ -81,6 +82,7 @@ private: sptr property_; sptr windowToken_; Rect layoutRect_ { 0, 0, 0, 0 }; + Rect hotZoneRect_ { 0, 0, 0, 0 }; int32_t callingPid_; int32_t callingUid_; WindowSizeChangeReason windowSizeChangeReason_ {WindowSizeChangeReason::UNDEFINED}; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index e345ecaf..6dc7ef72 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -66,6 +66,7 @@ public: sptr GetBelowAppWindowNode() const; sptr GetAppWindowNode() const; sptr GetAboveAppWindowNode() const; + float GetVirtualPixelRatio() const; private: void AssignZOrder(sptr& node); diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 4cd0b5f3..b1525014 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -62,6 +62,7 @@ public: void NotifyDisplayDestory(DisplayId displayId); void NotifySystemBarTints(); WMError RaiseZOrderForAppWindow(sptr& node); + float GetVirtualPixelRatio(DisplayId displayId) const; private: void OnRemoteDied(const sptr& remoteObject); diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 6300f04f..7faa0cd5 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -140,8 +140,9 @@ WMError WindowController::ResizeRect(uint32_t windowId, const Rect& rect, Window } else if (reason == WindowSizeChangeReason::DRAG) { if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { // fix rect in case of moving window when dragging - newRect = WindowHelper::GetFixedWindowRectByMinRect(rect, - property->GetWindowRect(), windowRoot_->isVerticalDisplay(node)); + float virtualPixelRatio = windowRoot_->GetVirtualPixelRatio(node->GetDisplayId()); + newRect = WindowHelper::GetFixedWindowRectByMinRect(rect, property->GetWindowRect(), + windowRoot_->isVerticalDisplay(node), virtualPixelRatio); } else { newRect = rect; } @@ -274,7 +275,7 @@ void WindowController::ProcessDisplayChange(DisplayId displayId, DisplayStateCha WLOGFE("get display failed displayId:%{public}" PRId64 "", displayId); return; } - + switch (type) { case DisplayStateChangeType::UPDATE_ROTATION: { windowRoot_->NotifyDisplayChange(abstractDisplay); diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 3ec0e274..a3ccfb89 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -14,16 +14,16 @@ */ #include "window_layout_policy.h" +#include "display_manager.h" #include "window_helper.h" #include "window_manager_hilog.h" +#include "wm_common_inner.h" #include "wm_trace.h" namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowLayoutPolicy"}; - constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 48; - constexpr uint32_t WINDOW_FRAME_WIDTH = 4; } WindowLayoutPolicy::WindowLayoutPolicy(const Rect& displayRect, const uint64_t& screenId, sptr& belowAppNode, sptr& appNode, sptr& aboveAppNode) @@ -115,11 +115,14 @@ void WindowLayoutPolicy::UpdateDefaultFoatingRect() void WindowLayoutPolicy::SetRectForFloating(const sptr& node) { + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t winFrameW = static_cast(WINDOW_FRAME_WIDTH * virtualPixelRatio); + uint32_t winTitleBarH = static_cast(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio); // deduct decor size Rect rect = defaultFloatingRect_; if (node->GetWindowProperty()->GetDecorEnable()) { - rect.width_ -= (WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH); - rect.height_ -= (WINDOW_TITLE_BAR_HEIGHT + WINDOW_FRAME_WIDTH); + rect.width_ -= (winFrameW + winFrameW); + rect.height_ -= (winTitleBarH + winFrameW); } node->SetWindowRect(rect); @@ -174,11 +177,15 @@ void WindowLayoutPolicy::UpdateFloatingLayoutRect(Rect& limitRect, Rect& winRect Rect WindowLayoutPolicy::ComputeDecoratedWindowRect(const Rect& winRect) { + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t winFrameW = static_cast(WINDOW_FRAME_WIDTH * virtualPixelRatio); + uint32_t winTitleBarH = static_cast(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio); + Rect rect; rect.posX_ = winRect.posX_; rect.posY_ = winRect.posY_; - rect.width_ = winRect.width_ + WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH; - rect.height_ = winRect.height_ + WINDOW_TITLE_BAR_HEIGHT + WINDOW_FRAME_WIDTH; + rect.width_ = winRect.width_ + winFrameW + winFrameW; + rect.height_ = winRect.height_ + winTitleBarH + winFrameW; return rect; } @@ -221,14 +228,44 @@ void WindowLayoutPolicy::UpdateLayoutRect(sptr& node) LimitWindowSize(node, displayRect, winRect); node->SetLayoutRect(winRect); + CalcAndSetNodeHotZone(winRect, node); if (!(lastRect == winRect)) { node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason()); node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); } } +void WindowLayoutPolicy::CalcAndSetNodeHotZone(Rect layoutOutRect, sptr& node) +{ + Rect rect = layoutOutRect; + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t hotZone = static_cast(HOTZONE * virtualPixelRatio); + uint32_t divHotZone = static_cast(DIV_HOTZONE * virtualPixelRatio); + + if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { + if (rect.width_ < rect.height_) { + rect.posX_ -= divHotZone; + rect.width_ += (divHotZone + divHotZone); + } else { + rect.posY_ -= divHotZone; + rect.height_ += (divHotZone + divHotZone); + } + } else if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { + rect.posX_ -= hotZone; + rect.posY_ -= hotZone; + rect.width_ += (hotZone + hotZone); + rect.height_ += (hotZone + hotZone); + } + node->SetHotZoneRect(rect); +} + void WindowLayoutPolicy::LimitWindowSize(const sptr& node, const Rect& displayRect, Rect& winRect) { + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t minVerticalFloatingW = static_cast(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio); + uint32_t minVerticalFloatingH = static_cast(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio); + uint32_t windowTitleBarH = static_cast(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio); + WindowType windowType = node->GetWindowType(); WindowMode windowMode = node->GetWindowMode(); bool isVertical = (displayRect.height_ > displayRect.width_) ? true : false; @@ -238,16 +275,16 @@ void WindowLayoutPolicy::LimitWindowSize(const sptr& node, const Rec } if ((windowMode == WindowMode::WINDOW_MODE_FLOATING) && !WindowHelper::IsSystemWindow(windowType)) { if (isVertical) { - winRect.width_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, winRect.width_); - winRect.height_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, winRect.height_); + winRect.width_ = std::max(minVerticalFloatingW, winRect.width_); + winRect.height_ = std::max(minVerticalFloatingH, winRect.height_); } else { - winRect.width_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, winRect.width_); - winRect.height_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, winRect.height_); + winRect.width_ = std::max(minVerticalFloatingH, winRect.width_); + winRect.height_ = std::max(minVerticalFloatingW, winRect.height_); } } if (WindowHelper::IsMainFloatingWindow(windowType, windowMode)) { winRect.posY_ = std::max(limitRect_.posY_, winRect.posY_); - winRect.posY_ = std::min(limitRect_.posY_ + static_cast(limitRect_.height_ - WINDOW_TITLE_BAR_HEIGHT), + winRect.posY_ = std::min(limitRect_.posY_ + static_cast(limitRect_.height_ - windowTitleBarH), winRect.posY_); } } @@ -314,5 +351,17 @@ void WindowLayoutPolicy::UpdateLimitRect(const sptr& node, Rect& lim void WindowLayoutPolicy::Reset() { } + +float WindowLayoutPolicy::GetVirtualPixelRatio() const +{ + auto display = DisplayManager::GetInstance().GetDisplayById(screenId_); + if (display == nullptr) { + WLOGFE("GetVirtualPixel fail. Get display fail. displayId:%{public}" PRIu64", use Default vpr:1.0", screenId_); + return 1.0; // Use DefaultVPR 1.0 + } + float virtualPixelRatio = display->GetVirtualPixelRatio(); + WLOGFI("GetVirtualPixel success. displayId:%{public}" PRIu64", vpr:%{public}f", screenId_, virtualPixelRatio); + return virtualPixelRatio; +} } } diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index 490449df..3854543b 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -17,6 +17,7 @@ #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" +#include "wm_common_inner.h" #include "wm_trace.h" namespace OHOS { @@ -130,19 +131,23 @@ static bool IsLayoutChanged(const Rect& l, const Rect& r) void WindowLayoutPolicyCascade::LimitMoveBounds(Rect& rect) { + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t minHorizontalSplitW = static_cast(MIN_HORIZONTAL_SPLIT_WIDTH * virtualPixelRatio); + uint32_t minVerticalSplitH = static_cast(MIN_VERTICAL_SPLIT_HEIGHT * virtualPixelRatio); + if (rect.width_ < rect.height_) { - if (rect.posX_ < (limitRect_.posX_ + static_cast(MIN_HORIZONTAL_SPLIT_WIDTH))) { - rect.posX_ = limitRect_.posX_ + static_cast(MIN_HORIZONTAL_SPLIT_WIDTH); + if (rect.posX_ < (limitRect_.posX_ + static_cast(minHorizontalSplitW))) { + rect.posX_ = limitRect_.posX_ + static_cast(minHorizontalSplitW); } else if (rect.posX_ > - (limitRect_.posX_ + limitRect_.width_ - static_cast(MIN_HORIZONTAL_SPLIT_WIDTH))) { - rect.posX_ = limitRect_.posX_ + static_cast(limitRect_.width_ - MIN_HORIZONTAL_SPLIT_WIDTH); + (limitRect_.posX_ + limitRect_.width_ - static_cast(minHorizontalSplitW))) { + rect.posX_ = limitRect_.posX_ + static_cast(limitRect_.width_ - minHorizontalSplitW); } } else { - if (rect.posY_ < (limitRect_.posY_ + static_cast(MIN_VERTICAL_SPLIT_HEIGHT))) { - rect.posY_ = limitRect_.posY_ + static_cast(MIN_VERTICAL_SPLIT_HEIGHT); + if (rect.posY_ < (limitRect_.posY_ + static_cast(minVerticalSplitH))) { + rect.posY_ = limitRect_.posY_ + static_cast(minVerticalSplitH); } else if (rect.posY_ > - (limitRect_.posY_ + static_cast(limitRect_.height_ - MIN_VERTICAL_SPLIT_HEIGHT))) { - rect.posY_ = limitRect_.posY_ + static_cast(limitRect_.height_ - MIN_VERTICAL_SPLIT_HEIGHT); + (limitRect_.posY_ + static_cast(limitRect_.height_ - minVerticalSplitH))) { + rect.posY_ = limitRect_.posY_ + static_cast(limitRect_.height_ - minVerticalSplitH); } } } @@ -215,6 +220,7 @@ void WindowLayoutPolicyCascade::UpdateLayoutRect(sptr& node) } node->SetLayoutRect(winRect); + CalcAndSetNodeHotZone(winRect, node); if (IsLayoutChanged(lastRect, winRect)) { node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason()); node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); @@ -265,12 +271,15 @@ void WindowLayoutPolicyCascade::UpdateSplitLimitRect(const Rect& limitRect, Rect void WindowLayoutPolicyCascade::InitSplitRects() { + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t dividerWidth = static_cast(DIVIDER_WIDTH * virtualPixelRatio); + if (!IsVertical()) { - dividerRect_ = { static_cast((displayRect_.width_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), 0, - DIVIDER_WIDTH, displayRect_.height_ }; + dividerRect_ = { static_cast((displayRect_.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO), 0, + dividerWidth, displayRect_.height_ }; } else { - dividerRect_ = { 0, static_cast((displayRect_.height_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), - displayRect_.width_, DIVIDER_WIDTH }; + dividerRect_ = { 0, static_cast((displayRect_.height_ - dividerWidth) * DEFAULT_SPLIT_RATIO), + displayRect_.width_, dividerWidth }; } WLOGFI("init dividerRect :[%{public}d, %{public}d, %{public}u, %{public}u]", dividerRect_.posX_, dividerRect_.posY_, dividerRect_.width_, dividerRect_.height_); diff --git a/wmserver/src/window_layout_policy_tile.cpp b/wmserver/src/window_layout_policy_tile.cpp index 073ada6a..9c24ada2 100644 --- a/wmserver/src/window_layout_policy_tile.cpp +++ b/wmserver/src/window_layout_policy_tile.cpp @@ -99,6 +99,7 @@ void WindowLayoutPolicyTile::LayoutForegroundNodeQueue() Rect lastRect = node->GetLayoutRect(); Rect winRect = node->GetWindowProperty()->GetWindowRect(); node->SetLayoutRect(winRect); + CalcAndSetNodeHotZone(winRect, node); if (!(lastRect == winRect)) { node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason()); node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); @@ -204,6 +205,7 @@ void WindowLayoutPolicyTile::UpdateLayoutRect(sptr& node) } LimitWindowSize(node, displayRect, winRect); node->SetLayoutRect(winRect); + CalcAndSetNodeHotZone(winRect, node); if (!(lastRect == winRect)) { node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason()); node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index 44d6ef9d..23d8f4dd 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -32,6 +32,11 @@ void WindowNode::SetLayoutRect(const Rect& rect) layoutRect_ = rect; } +void WindowNode::SetHotZoneRect(const Rect& rect) +{ + hotZoneRect_ = rect; +} + void WindowNode::SetWindowRect(const Rect& rect) { property_->SetWindowRect(rect); @@ -128,23 +133,7 @@ const Rect& WindowNode::GetLayoutRect() const Rect WindowNode::GetHotZoneRect() const { - Rect rect = layoutRect_; - if (GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { - const int32_t divHotZone = 20; - if (rect.width_ < rect.height_) { - rect.posX_ -= divHotZone; - rect.width_ += (divHotZone + divHotZone); - } else { - rect.posY_ -= divHotZone; - rect.height_ += (divHotZone + divHotZone); - } - } else if (WindowHelper::IsMainFloatingWindow(GetWindowType(), GetWindowMode())) { - rect.posX_ -= HOTZONE; - rect.posY_ -= HOTZONE; - rect.width_ += (HOTZONE + HOTZONE); - rect.height_ += (HOTZONE + HOTZONE); - } - return rect; + return hotZoneRect_; } WindowType WindowNode::GetWindowType() const diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index b247eb22..776e34f8 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -29,6 +29,7 @@ #include "window_manager_agent_controller.h" #include "window_manager_hilog.h" #include "wm_common.h" +#include "wm_common_inner.h" #include "wm_trace.h" namespace OHOS { @@ -1061,6 +1062,11 @@ sptr WindowNodeContainer::GetAboveAppWindowNode() const return aboveAppWindowNode_; } +float WindowNodeContainer::GetVirtualPixelRatio() const +{ + return layoutPolicy_->GetVirtualPixelRatio(); +} + namespace { const char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_animation"; } diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 49d1646b..5a18a646 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -477,5 +477,11 @@ void WindowRoot::NotifyDisplayDestory(DisplayId expandDisplayId) defaultDisplaycontainer->MoveWindowNode(expandDisplaycontainer); NotifyDisplayRemoved(expandDisplayId); } + +float WindowRoot::GetVirtualPixelRatio(DisplayId displayId) const +{ + auto container = const_cast(this)->GetOrCreateWindowNodeContainer(displayId); + return container->GetVirtualPixelRatio(); +} } }