From 8a11bf1aeee1ff899c8b83d5cc15d593c336a4fb Mon Sep 17 00:00:00 2001 From: l00574490 Date: Tue, 1 Mar 2022 16:47:15 +0800 Subject: [PATCH] modify drag area Change-Id: I95af39217bfc7b29f535a244d55c210a06a786df Signed-off-by: l00574490 --- utils/include/window_helper.h | 10 ++++----- utils/include/wm_common_inner.h | 4 ++-- wm/include/window_impl.h | 1 + wm/src/window_impl.cpp | 29 ++++++++++++++++++++++----- wmserver/src/drag_controller.cpp | 4 ++-- wmserver/src/window_layout_policy.cpp | 9 ++++----- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index a8091862..8c79e65e 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -111,12 +111,12 @@ public: return dstRect; } - static bool IsPointInWindow(int32_t pointPosX, int32_t pointPosY, Rect pointRect) + static bool IsPointInTargetRect(int32_t pointPosX, int32_t pointPosY, const Rect& targetRect) { - if ((pointPosX > pointRect.posX_) && - (pointPosX < (pointRect.posX_ + static_cast(pointRect.width_))) && - (pointPosY > pointRect.posY_) && - (pointPosY < (pointRect.posY_ + static_cast(pointRect.height_)))) { + if ((pointPosX > targetRect.posX_) && + (pointPosX < (targetRect.posX_ + static_cast(targetRect.width_))) && + (pointPosY > targetRect.posY_) && + (pointPosY < (targetRect.posY_ + static_cast(targetRect.height_)))) { return true; } return false; diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index 369fd40d..67540683 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -49,8 +49,8 @@ namespace { 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 WINDOW_FRAME_TOP_WIDTH = 1; // the frame width of top position + constexpr uint32_t 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; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 0e4fac89..3699979c 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -208,6 +208,7 @@ private: bool startMoveFlag_ = false; bool pointEventStarted_ = false; Rect startPointRect_ = { 0, 0, 0, 0 }; + Rect startRectExceptFrame_ = { 0, 0, 0, 0 }; }; } } diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 8f401138..697955f6 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -995,25 +995,25 @@ void WindowImpl::HandleDragEvent(int32_t posX, int32_t posY, int32_t pointId) int32_t diffX = posX - startPointPosX_; int32_t diffY = posY - startPointPosY_; Rect newRect = startPointRect_; - if (startPointPosX_ <= startPointRect_.posX_) { + if (startPointPosX_ <= startRectExceptFrame_.posX_) { if (diffX > static_cast(startPointRect_.width_)) { diffX = static_cast(startPointRect_.width_); } newRect.posX_ += diffX; newRect.width_ = static_cast(static_cast(newRect.width_) - diffX); - } else if (startPointPosX_ >= startPointRect_.posX_ + static_cast(startPointRect_.width_)) { + } else if (startPointPosX_ >= startRectExceptFrame_.posX_ + static_cast(startRectExceptFrame_.width_)) { if (diffX < 0 && (-diffX > static_cast(startPointRect_.width_))) { diffX = -(static_cast(startPointRect_.width_)); } newRect.width_ = static_cast(static_cast(newRect.width_) + diffX); } - if (startPointPosY_ <= startPointRect_.posY_) { + if (startPointPosY_ <= startRectExceptFrame_.posY_) { if (diffY > static_cast(startPointRect_.height_)) { diffY = static_cast(startPointRect_.height_); } newRect.posY_ += diffY; newRect.height_ = static_cast(static_cast(newRect.height_) - diffY); - } else if (startPointPosY_ >= startPointRect_.posY_ + static_cast(startPointRect_.height_)) { + } else if (startPointPosY_ >= startRectExceptFrame_.posY_ + static_cast(startRectExceptFrame_.height_)) { if (diffY < 0 && (-diffY > static_cast(startPointRect_.height_))) { diffY = -(static_cast(startPointRect_.height_)); } @@ -1046,9 +1046,28 @@ void WindowImpl::ReadyToMoveOrDragWindow(int32_t globalX, int32_t globalY, int32 startPointPosY_ = globalY; startPointerId_ = pointId; pointEventStarted_ = true; + + // calculate window inner rect except frame + auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId()); + if (display == nullptr) { + WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(), + property_->GetWindowId()); + return; + } + float virtualPixelRatio = display->GetVirtualPixelRatio(); + + startRectExceptFrame_.posX_ = startPointRect_.posX_ + + static_cast(WINDOW_FRAME_WIDTH * virtualPixelRatio); + startRectExceptFrame_.posY_ = startPointRect_.posY_ + + static_cast(WINDOW_FRAME_TOP_WIDTH * virtualPixelRatio); + startRectExceptFrame_.width_ = startPointRect_.width_ - + static_cast((WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH) * virtualPixelRatio); + startRectExceptFrame_.height_ = startPointRect_.height_ - + static_cast((WINDOW_FRAME_TOP_WIDTH + WINDOW_FRAME_WIDTH) * virtualPixelRatio); + if (GetType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { startMoveFlag_ = true; - } else if (!WindowHelper::IsPointInWindow(startPointPosX_, startPointPosY_, startPointRect_)) { + } else if (!WindowHelper::IsPointInTargetRect(startPointPosX_, startPointPosY_, startRectExceptFrame_)) { startDragFlag_ = true; } return; diff --git a/wmserver/src/drag_controller.cpp b/wmserver/src/drag_controller.cpp index 927cfb5e..a9f8d5df 100644 --- a/wmserver/src/drag_controller.cpp +++ b/wmserver/src/drag_controller.cpp @@ -88,7 +88,7 @@ void DragController::FinishDrag(uint32_t windowId) if (node->GetWindowType() != WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { return; } - + sptr hitWindow = windowRoot_->GetWindowNode(hitWindowId_); if (hitWindow != nullptr) { auto property = node->GetWindowProperty(); @@ -118,7 +118,7 @@ sptr DragController::GetHitWindow(DisplayId id, PointInfo point) if (windowNode->GetWindowType() >= WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { continue; } - if (WindowHelper::IsPointInWindow(point.x, point.y, windowNode->GetLayoutRect())) { + if (WindowHelper::IsPointInTargetRect(point.x, point.y, windowNode->GetLayoutRect())) { return windowNode; } } diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 6f3c98fb..e5ee4b66 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -241,15 +241,14 @@ void WindowLayoutPolicy::CalcAndSetNodeHotZone(Rect layoutOutRect, sptr(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); + rect.posX_ -= hotZone; + rect.width_ += (hotZone + hotZone); } else { - rect.posY_ -= divHotZone; - rect.height_ += (divHotZone + divHotZone); + rect.posY_ -= hotZone; + rect.height_ += (hotZone + hotZone); } } else if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { rect.posX_ -= hotZone;