diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index ddad754b..fede0a11 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -51,6 +51,11 @@ public: virtual void OnAvoidAreaChanged(std::vector avoidAreas) = 0; }; +class IWindowDragListener : virtual public RefBase { +public: + virtual void OnDrag(int32_t x, int32_t y, DragEvent event) = 0; +}; + class Window : public RefBase { public: static sptr Create(const std::string& windowName, @@ -99,6 +104,8 @@ public: virtual void RegisterWindowChangeListener(sptr& listener) = 0; virtual void RegisterAvoidAreaChangeListener(sptr& listener) = 0; virtual void UnregisterAvoidAreaChangeListener() = 0; + virtual void RegisterDragListener(sptr& listener) = 0; + virtual void UnregisterDragListener(sptr& listener) = 0; virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0; virtual std::string GetContentInfo() = 0; diff --git a/interfaces/innerkits/wm/window_option.h b/interfaces/innerkits/wm/window_option.h index afec542f..170e96ce 100644 --- a/interfaces/innerkits/wm/window_option.h +++ b/interfaces/innerkits/wm/window_option.h @@ -40,6 +40,7 @@ public: void RemoveWindowFlag(WindowFlag flag); void SetWindowFlags(uint32_t flags); void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); + void SetHitOffset(int32_t x, int32_t y); Rect GetWindowRect() const; WindowType GetWindowType() const; @@ -51,6 +52,7 @@ public: const std::string& GetWindowName() const; uint32_t GetWindowFlags() const; const std::unordered_map& GetSystemBarProperty() const; + const PointInfo& GetHitOffset() const; private: Rect windowRect_ { 0, 0, 0, 0 }; WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; @@ -61,6 +63,7 @@ private: std::string parentName_ { "" }; std::string windowName_ { "" }; uint32_t flags_ { 0 }; + PointInfo hitOffset_ { 0, 0 }; std::unordered_map sysBarPropMap_ { { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 125b06a7..ff73077f 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -95,6 +95,13 @@ enum class WindowLayoutMode : uint32_t { TILE = 1, }; +enum class DragEvent : uint32_t { + DRAG_EVENT_IN = 1, + DRAG_EVENT_OUT, + DRAG_EVENT_MOVE, + DRAG_EVENT_END, +}; + struct Rect { int32_t posX_; int32_t posY_; @@ -106,6 +113,11 @@ struct Rect { } }; +struct PointInfo { + int32_t x; + int32_t y; +}; + namespace { constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF; constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000; diff --git a/utils/include/window_property.h b/utils/include/window_property.h index 9533e433..2b073b92 100644 --- a/utils/include/window_property.h +++ b/utils/include/window_property.h @@ -47,6 +47,7 @@ public: void SetWindowFlags(uint32_t flags); void SetSystemBarProperty(WindowType type, const SystemBarProperty& state); void SetDecorEnable(bool decorEnable); + void SetHitOffset(const PointInfo& offset); const std::string& GetWindowName() const; Rect GetWindowRect() const; @@ -65,6 +66,7 @@ public: uint32_t GetWindowFlags() const; const std::unordered_map& GetSystemBarProperty() const; bool GetDecorEnable() const; + const PointInfo& GetHitOffset() const; virtual bool Marshalling(Parcel& parcel) const override; static sptr Unmarshalling(Parcel& parcel); @@ -85,6 +87,8 @@ private: DisplayId displayId_ { 0 }; uint32_t windowId_ { 0 }; uint32_t parentId_ { 0 }; + PointInfo hitOffset_ { 0, 0 }; + std::unordered_map sysBarPropMap_ { { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index 6aa3a62c..1c04172a 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -15,6 +15,7 @@ #include "window_property.h" #include "window_helper.h" +#include "wm_common.h" namespace OHOS { namespace Rosen { @@ -104,6 +105,11 @@ void WindowProperty::SetDecorEnable(bool decorEnable) isDecorEnable_ = decorEnable; } +void WindowProperty::SetHitOffset(const PointInfo& offset) +{ + hitOffset_ = offset; +} + void WindowProperty::ResumeLastWindowMode() { mode_ = lastMode_; @@ -202,6 +208,11 @@ uint32_t WindowProperty::GetParentId() const return parentId_; } +const PointInfo& WindowProperty::GetHitOffset() const +{ + return hitOffset_; +} + bool WindowProperty::MapMarshalling(Parcel& parcel) const { auto size = sysBarPropMap_.size(); @@ -315,6 +326,12 @@ bool WindowProperty::Marshalling(Parcel& parcel) const if (!parcel.WriteBool(isDecorEnable_)) { return false; } + + // write hitOffset_ + if (!(parcel.WriteInt32(hitOffset_.x) and parcel.WriteInt32(hitOffset_.y))) { + return false; + } + return true; } @@ -338,6 +355,8 @@ sptr WindowProperty::Unmarshalling(Parcel& parcel) property->SetParentId(parcel.ReadUint32()); MapUnmarshalling(parcel, property); property->SetDecorEnable(parcel.ReadBool()); + PointInfo offset = {parcel.ReadInt32(), parcel.ReadInt32()}; + property->SetHitOffset(offset); return property; } } diff --git a/wm/include/window_agent.h b/wm/include/window_agent.h index fcecb1c0..9f5846dc 100644 --- a/wm/include/window_agent.h +++ b/wm/include/window_agent.h @@ -19,6 +19,7 @@ #include "window_stub.h" #include "window_impl.h" #include "window_property.h" +#include "wm_common.h" namespace OHOS { namespace Rosen { @@ -32,7 +33,7 @@ public: void UpdateFocusStatus(bool focused) override; void UpdateAvoidArea(const std::vector& avoidAreas) override; void UpdateWindowState(WindowState state) override; - + void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) override; private: sptr window_; }; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 3b6af163..4e70de4b 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -29,6 +29,7 @@ #include "window.h" #include "window_property.h" #include "wm_common_inner.h" +#include "wm_common.h" namespace OHOS { namespace Rosen { @@ -95,6 +96,8 @@ public: virtual void RegisterWindowChangeListener(sptr& listener) override; virtual void RegisterAvoidAreaChangeListener(sptr& listener) override; virtual void UnregisterAvoidAreaChangeListener() override; + virtual void RegisterDragListener(sptr& listener) override; + virtual void UnregisterDragListener(sptr& listener) override; void UpdateRect(const struct Rect& rect); void UpdateMode(WindowMode mode); @@ -105,6 +108,7 @@ public: virtual void UpdateConfiguration(const std::shared_ptr& configuration) override; void UpdateAvoidArea(const std::vector& avoidAreas); void UpdateWindowState(WindowState state); + void UpdateDragEvent(const PointInfo& point, DragEvent event); virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) override; @@ -153,11 +157,13 @@ private: sptr lifecycleListener_; sptr windowChangeListener_; sptr avoidAreaChangeListener_; + std::vector> windowDragListeners_; std::shared_ptr surfaceNode_; std::string name_; std::unique_ptr uiContent_; std::shared_ptr abilityContext_; // give up when context offer getToken std::shared_ptr context_; + std::recursive_mutex mutex_; const float STATUS_BAR_RATIO = 0.07; const float NAVIGATION_BAR_RATIO = 0.07; const float SYSTEM_ALARM_WINDOW_WIDTH_RATIO = 0.8; diff --git a/wm/include/window_interface.h b/wm/include/window_interface.h index 3f724824..929ab449 100644 --- a/wm/include/window_interface.h +++ b/wm/include/window_interface.h @@ -18,6 +18,7 @@ #include "iremote_broker.h" #include "window_property.h" +#include "wm_common.h" #include "wm_common_inner.h" namespace OHOS { @@ -33,6 +34,7 @@ public: TRANS_ID_UPDATE_FOCUS_STATUS, TRANS_ID_UPDATE_AVOID_AREA, TRANS_ID_UPDATE_WINDOW_STATE, + TRANS_ID_UPDATE_DRAG_EVENT, }; virtual void UpdateWindowProperty(const WindowProperty& windowProperty) = 0; @@ -41,6 +43,7 @@ public: virtual void UpdateFocusStatus(bool focused) = 0; virtual void UpdateAvoidArea(const std::vector& avoidAreas) = 0; virtual void UpdateWindowState(WindowState state) = 0; + virtual void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/window_proxy.h b/wm/include/window_proxy.h index 870d5993..b6978f95 100644 --- a/wm/include/window_proxy.h +++ b/wm/include/window_proxy.h @@ -18,6 +18,7 @@ #include "window_interface.h" #include "iremote_proxy.h" +#include "wm_common.h" namespace OHOS { namespace Rosen { @@ -33,7 +34,7 @@ public: void UpdateFocusStatus(bool focused) override; void UpdateAvoidArea(const std::vector& avoidAreas) override; void UpdateWindowState(WindowState state) override; - + void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) override; private: static inline BrokerDelegator delegator_; }; diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp index 86f1066c..4868709f 100644 --- a/wm/src/window_agent.cpp +++ b/wm/src/window_agent.cpp @@ -15,6 +15,7 @@ #include "window_agent.h" #include "window_manager_hilog.h" +#include "wm_common.h" namespace OHOS { namespace Rosen { @@ -75,5 +76,14 @@ void WindowAgent::UpdateWindowState(WindowState state) } window_->UpdateWindowState(state); } + +void WindowAgent::UpdateWindowDragInfo(const PointInfo& piont, DragEvent event) +{ + if (window_ == nullptr) { + WLOGFE("window is nullptr"); + return; + } + window_->UpdateDragEvent(piont, event); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 59ccb012..5faa2da5 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -24,6 +24,7 @@ #include "window_agent.h" #include "window_helper.h" #include "window_manager_hilog.h" +#include "wm_common.h" #include @@ -48,6 +49,7 @@ WindowImpl::WindowImpl(const sptr& option) property_->SetTouchable(option->GetTouchable()); property_->SetDisplayId(option->GetDisplayId()); property_->SetWindowFlags(option->GetWindowFlags()); + property_->SetHitOffset(option->GetHitOffset()); auto& sysBarPropMap = option->GetSystemBarProperty(); for (auto it : sysBarPropMap) { property_->SetSystemBarProperty(it.first, it.second); @@ -686,6 +688,26 @@ void WindowImpl::UnregisterAvoidAreaChangeListener() avoidAreaChangeListener_ = nullptr; } +void WindowImpl::RegisterDragListener(sptr& listener) +{ + if (listener == nullptr) { + return; + } + std::lock_guard lock(mutex_); + windowDragListeners_.emplace_back(listener); +} + +void WindowImpl::UnregisterDragListener(sptr& listener) +{ + std::lock_guard lock(mutex_); + auto iter = std::find(windowDragListeners_.begin(), windowDragListeners_.end(), listener); + if (iter ==windowDragListeners_.end()) { + WLOGFE("could not find this listener"); + return; + } + windowDragListeners_.erase(iter); +} + void WindowImpl::UpdateRect(const struct Rect& rect) { auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId()); @@ -950,6 +972,14 @@ void WindowImpl::UpdateWindowState(WindowState state) } } +void WindowImpl::UpdateDragEvent(const PointInfo& point, DragEvent event) +{ + std::lock_guard lock(mutex_); + for (auto& iter : windowDragListeners_) { + iter->OnDrag(point.x, point.y, event); + } +} + void WindowImpl::SetDefaultOption() { auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId()); diff --git a/wm/src/window_option.cpp b/wm/src/window_option.cpp index f5062569..daf8cbff 100644 --- a/wm/src/window_option.cpp +++ b/wm/src/window_option.cpp @@ -15,6 +15,7 @@ #include "window_option.h" #include "window_helper.h" +#include "wm_common.h" namespace OHOS { namespace Rosen { @@ -133,6 +134,17 @@ uint32_t WindowOption::GetWindowFlags() const return flags_; } +void WindowOption::SetHitOffset(int32_t x, int32_t y) +{ + hitOffset_.x = x; + hitOffset_.y = y; +} + +const PointInfo& WindowOption::GetHitOffset() const +{ + return hitOffset_; +} + const std::unordered_map& WindowOption::GetSystemBarProperty() const { return sysBarPropMap_; diff --git a/wm/src/window_proxy.cpp b/wm/src/window_proxy.cpp index a2cf49fe..55bfab53 100644 --- a/wm/src/window_proxy.cpp +++ b/wm/src/window_proxy.cpp @@ -15,7 +15,9 @@ #include "window_proxy.h" #include +#include "message_option.h" #include "window_manager_hilog.h" +#include "wm_common.h" namespace OHOS { namespace Rosen { @@ -141,7 +143,29 @@ void WindowProxy::UpdateWindowState(WindowState state) if (Remote()->SendRequest(TRANS_ID_UPDATE_WINDOW_STATE, data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); } - return; +} + +void WindowProxy::UpdateWindowDragInfo(const PointInfo& point, DragEvent event) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!(data.WriteInt32(point.x) and data.WriteInt32(point.y))) { + WLOGFE("Write pos failed"); + return; + } + if (!data.WriteInt32(static_cast(event))) { + WLOGFE("Write event failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_DRAG_EVENT, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest TRANS_ID_UPDATE_DRAG_EVENT failed"); + } } } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_stub.cpp b/wm/src/window_stub.cpp index d0bcb542..fe165e0a 100644 --- a/wm/src/window_stub.cpp +++ b/wm/src/window_stub.cpp @@ -64,6 +64,14 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce UpdateWindowState(static_cast(data.ReadUint32())); break; } + case TRANS_ID_UPDATE_DRAG_EVENT: { + PointInfo point; + point.x = data.ReadInt32(); + point.y = data.ReadInt32(); + DragEvent event = static_cast (data.ReadUint32()); + UpdateWindowDragInfo(point, event); + break; + } default: break; } diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index ea74fb99..3dbefe48 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -61,6 +61,7 @@ ohos_shared_library("libwms") { "../wm/src/window_proxy.cpp", "../wm/src/zidl/window_manager_agent_proxy.cpp", "src/avoid_area_controller.cpp", + "src/drag_controller.cpp", "src/input_window_monitor.cpp", "src/window_controller.cpp", "src/window_inner_manager.cpp", diff --git a/wmserver/include/drag_controller.h b/wmserver/include/drag_controller.h new file mode 100644 index 00000000..f0a94f26 --- /dev/null +++ b/wmserver/include/drag_controller.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_DRAG_CONTROLLER_H +#define OHOS_ROSEN_DRAG_CONTROLLER_H + +#include + +#include "window_root.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class DragController : public RefBase { +public: + DragController(sptr& root) : windowRoot_(root) {} + ~DragController() = default; + void StartDrag(uint32_t windowId); + void UpdateDragInfo(uint32_t windowId); + void FinishDrag(uint32_t windowId); +private: + sptr GetHitWindow(PointInfo point); + bool GetHitPoint(uint32_t windowId, PointInfo& point); + sptr windowRoot_; + uint64_t hitWindowId_ = 0; +}; +} +} +#endif // OHOS_ROSEN_DRAG_CONTROLLER_H + diff --git a/wmserver/include/input_window_monitor.h b/wmserver/include/input_window_monitor.h index 606ebd65..36657492 100644 --- a/wmserver/include/input_window_monitor.h +++ b/wmserver/include/input_window_monitor.h @@ -36,7 +36,8 @@ private: sptr windowRoot_; std::vector physicalDisplays_; std::vector logicalDisplays_; - std::unordered_set windowTypeSkipped_ { WindowType::WINDOW_TYPE_POINTER }; + std::unordered_set windowTypeSkipped_ { WindowType::WINDOW_TYPE_POINTER, + WindowType::WINDOW_TYPE_DRAGGING_EFFECT }; const int INVALID_WINDOW_ID = -1; void TraverseWindowNodes(const std::vector>& windowNodes, std::vector::iterator& iter); diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 898e8d6b..0742ca61 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -24,6 +24,7 @@ #include #include #include "display_change_listener.h" +#include "drag_controller.h" #include "singleton_delegator.h" #include "wm_single_instance.h" #include "window_controller.h" @@ -88,6 +89,7 @@ private: sptr windowController_; sptr inputWindowMonitor_; sptr snapshotController_; + sptr dragController_; }; } } diff --git a/wmserver/src/drag_controller.cpp b/wmserver/src/drag_controller.cpp new file mode 100644 index 00000000..37e95d28 --- /dev/null +++ b/wmserver/src/drag_controller.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "drag_controller.h" + +#include + +#include "display.h" +#include "display_manager_service_inner.h" +#include "window_helper.h" +#include "window_manager_hilog.h" +#include "window_node.h" +#include "window_node_container.h" +#include "window_property.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DragController"}; +} + +void DragController::UpdateDragInfo(uint32_t windowId) +{ + PointInfo point; + if (!GetHitPoint(windowId, point)) { + return; + } + sptr hitWindowNode = GetHitWindow(point); + if (hitWindowNode == nullptr) { + WLOGFE("Get point failed %{public}d %{public}d", point.x, point.y); + return; + } + if (hitWindowNode->GetWindowId() == hitWindowId_) { + hitWindowNode->GetWindowToken()->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_MOVE); + return; + } + hitWindowNode->GetWindowToken()->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_IN); + sptr oldHitWindow = windowRoot_->GetWindowNode(hitWindowId_); + if (oldHitWindow != nullptr) { + oldHitWindow->GetWindowToken()->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_OUT); + } + hitWindowId_ = hitWindowNode->GetWindowId(); +} + +void DragController::StartDrag(uint32_t windowId) +{ + PointInfo point; + if (!GetHitPoint(windowId, point)) { + WLOGFE("Get hit point failed"); + return; + } + sptr hitWindow = GetHitWindow(point); + if (hitWindow == nullptr) { + WLOGFE("Get point failed %{public}d %{public}d", point.x, point.y); + return; + } + hitWindow->GetWindowToken()->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_IN); + hitWindowId_ = windowId; + WLOGFI("start Drag"); +} + +void DragController::FinishDrag(uint32_t windowId) +{ + sptr node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("get node failed"); + return; + } + if (node->GetWindowType() != WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { + return; + } + + sptr hitWindow = windowRoot_->GetWindowNode(hitWindowId_); + if (hitWindow != nullptr) { + auto property = node->GetWindowProperty(); + PointInfo point = {property->GetWindowRect().posX_ + property->GetHitOffset().x, + property->GetWindowRect().posY_ + property->GetHitOffset().y}; + hitWindow->GetWindowToken()->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_END); + } + WLOGFI("end drag"); +} + +sptr DragController::GetHitWindow(PointInfo point) +{ + // TODO get display by point + DisplayId id = DisplayManagerServiceInner::GetInstance().GetDefaultDisplayId(); + if (id == DISPLAY_ID_INVALD) { + WLOGFE("get invalid display"); + return nullptr; + } + + sptr container = windowRoot_->GetOrCreateWindowNodeContainer(id); + if (container == nullptr) { + WLOGFE("get container failed %{public}" PRIu64"", id); + return nullptr; + } + + std::vector> windowNodes; + container->TraverseContainer(windowNodes); + for (auto windowNode : windowNodes) { + if (windowNode->GetWindowType() >= WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { + continue; + } + if (WindowHelper::IsPointInWindow(point.x, point.y, windowNode->GetLayoutRect())) { + return windowNode; + } + } + return nullptr; +} + +bool DragController::GetHitPoint(uint32_t windowId, PointInfo& point) +{ + sptr windowNode = windowRoot_->GetWindowNode(windowId); + if (windowNode == nullptr || windowNode->GetWindowType() != WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { + WLOGFE("Get hit point failed"); + return false; + } + sptr property = windowNode->GetWindowProperty(); + point.x = property->GetWindowRect().posX_ + property->GetHitOffset().x; + point.y = property->GetWindowRect().posY_ + property->GetHitOffset().y; + return true; +} +} +} \ No newline at end of file diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 95cfa623..e252f19a 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -23,10 +23,12 @@ #include "dm_common.h" #include "display_manager_service_inner.h" +#include "drag_controller.h" #include "singleton_container.h" #include "window_manager_agent_controller.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" +#include "wm_common.h" #include "wm_trace.h" namespace OHOS { @@ -45,6 +47,7 @@ WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERV inputWindowMonitor_ = new InputWindowMonitor(windowRoot_); windowController_ = new WindowController(windowRoot_, inputWindowMonitor_); snapshotController_ = new SnapshotController(windowRoot_); + dragController_ = new DragController(windowRoot_); } void WindowManagerService::OnStart() @@ -124,14 +127,18 @@ WMError WindowManagerService::CreateWindow(sptr& window, sptr& property) { Rect rect = property->GetWindowRect(); + uint32_t windowId = property->GetWindowId(); WLOGFI("[WMS] Add: %{public}5d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \ - "%{public}4d %{public}4d]", property->GetWindowId(), property->GetWindowType(), property->GetWindowMode(), + "%{public}4d %{public}4d]", windowId, property->GetWindowType(), property->GetWindowMode(), property->GetWindowFlags(), rect.posX_, rect.posY_, rect.width_, rect.height_); - WM_SCOPED_TRACE("wms:AddWindow(%d)", property->GetWindowId()); + WM_SCOPED_TRACE("wms:AddWindow(%d)", windowId); std::lock_guard lock(mutex_); WMError res = windowController_->AddWindowNode(property); system::SetParameter("persist.window.boot.inited", "1"); + if (property->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { + dragController_->StartDrag(windowId); + } return res; } @@ -148,10 +155,9 @@ WMError WindowManagerService::DestroyWindow(uint32_t windowId) WLOGFI("[WMS] Destroy: %{public}d", windowId); WM_SCOPED_TRACE("wms:DestroyWindow(%d)", windowId); std::lock_guard lock(mutex_); - DisplayId displayId = DISPLAY_ID_INVALD; auto node = windowRoot_->GetWindowNode(windowId); - if (node != nullptr) { - displayId = node->GetDisplayId(); + if (node != nullptr && node->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { + dragController_->FinishDrag(windowId); } return windowController_->DestroyWindow(windowId); } @@ -161,7 +167,12 @@ WMError WindowManagerService::MoveTo(uint32_t windowId, int32_t x, int32_t y) WLOGFI("[WMS] MoveTo: %{public}d [%{public}d, %{public}d]", windowId, x, y); WM_SCOPED_TRACE("wms:MoveTo"); std::lock_guard lock(mutex_); - return windowController_->MoveTo(windowId, x, y); + + WMError res = windowController_->MoveTo(windowId, x, y); + if (res == WMError::WM_OK) { + dragController_->UpdateDragInfo(windowId); + } + return res; } WMError WindowManagerService::Resize(uint32_t windowId, uint32_t width, uint32_t height)