mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-19 17:08:11 -04:00
@@ -51,6 +51,11 @@ public:
|
||||
virtual void OnAvoidAreaChanged(std::vector<Rect> 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<Window> Create(const std::string& windowName,
|
||||
@@ -99,6 +104,8 @@ public:
|
||||
virtual void RegisterWindowChangeListener(sptr<IWindowChangeListener>& listener) = 0;
|
||||
virtual void RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) = 0;
|
||||
virtual void UnregisterAvoidAreaChangeListener() = 0;
|
||||
virtual void RegisterDragListener(sptr<IWindowDragListener>& listener) = 0;
|
||||
virtual void UnregisterDragListener(sptr<IWindowDragListener>& listener) = 0;
|
||||
virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine,
|
||||
NativeValue* storage, bool isdistributed = false) = 0;
|
||||
virtual std::string GetContentInfo() = 0;
|
||||
|
||||
@@ -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<WindowType, SystemBarProperty>& 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<WindowType, SystemBarProperty> sysBarPropMap_ {
|
||||
{ WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() },
|
||||
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
|
||||
bool GetDecorEnable() const;
|
||||
const PointInfo& GetHitOffset() const;
|
||||
|
||||
virtual bool Marshalling(Parcel& parcel) const override;
|
||||
static sptr<WindowProperty> 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<WindowType, SystemBarProperty> sysBarPropMap_ {
|
||||
{ WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() },
|
||||
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
|
||||
|
||||
@@ -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> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Rect>& avoidAreas) override;
|
||||
void UpdateWindowState(WindowState state) override;
|
||||
|
||||
void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) override;
|
||||
private:
|
||||
sptr<WindowImpl> window_;
|
||||
};
|
||||
|
||||
@@ -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<IWindowChangeListener>& listener) override;
|
||||
virtual void RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) override;
|
||||
virtual void UnregisterAvoidAreaChangeListener() override;
|
||||
virtual void RegisterDragListener(sptr<IWindowDragListener>& listener) override;
|
||||
virtual void UnregisterDragListener(sptr<IWindowDragListener>& listener) override;
|
||||
|
||||
void UpdateRect(const struct Rect& rect);
|
||||
void UpdateMode(WindowMode mode);
|
||||
@@ -105,6 +108,7 @@ public:
|
||||
virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
|
||||
void UpdateAvoidArea(const std::vector<Rect>& 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<IWindowLifeCycle> lifecycleListener_;
|
||||
sptr<IWindowChangeListener> windowChangeListener_;
|
||||
sptr<IAvoidAreaChangedListener> avoidAreaChangeListener_;
|
||||
std::vector<sptr<IWindowDragListener>> windowDragListeners_;
|
||||
std::shared_ptr<RSSurfaceNode> surfaceNode_;
|
||||
std::string name_;
|
||||
std::unique_ptr<Ace::UIContent> uiContent_;
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_; // give up when context offer getToken
|
||||
std::shared_ptr<AbilityRuntime::Context> 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;
|
||||
|
||||
@@ -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<Rect>& avoidAreas) = 0;
|
||||
virtual void UpdateWindowState(WindowState state) = 0;
|
||||
virtual void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) = 0;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -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<Rect>& avoidAreas) override;
|
||||
void UpdateWindowState(WindowState state) override;
|
||||
|
||||
void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) override;
|
||||
private:
|
||||
static inline BrokerDelegator<WindowProxy> delegator_;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "window_agent.h"
|
||||
#include "window_helper.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "wm_common.h"
|
||||
|
||||
#include <ability_manager_client.h>
|
||||
|
||||
@@ -48,6 +49,7 @@ WindowImpl::WindowImpl(const sptr<WindowOption>& 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<IWindowDragListener>& listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
windowDragListeners_.emplace_back(listener);
|
||||
}
|
||||
|
||||
void WindowImpl::UnregisterDragListener(sptr<IWindowDragListener>& listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> 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<std::recursive_mutex> lock(mutex_);
|
||||
for (auto& iter : windowDragListeners_) {
|
||||
iter->OnDrag(point.x, point.y, event);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowImpl::SetDefaultOption()
|
||||
{
|
||||
auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId());
|
||||
|
||||
@@ -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<WindowType, SystemBarProperty>& WindowOption::GetSystemBarProperty() const
|
||||
{
|
||||
return sysBarPropMap_;
|
||||
|
||||
+25
-1
@@ -15,7 +15,9 @@
|
||||
|
||||
#include "window_proxy.h"
|
||||
#include <ipc_types.h>
|
||||
#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<uint32_t>(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
|
||||
|
||||
@@ -64,6 +64,14 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce
|
||||
UpdateWindowState(static_cast<WindowState>(data.ReadUint32()));
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_UPDATE_DRAG_EVENT: {
|
||||
PointInfo point;
|
||||
point.x = data.ReadInt32();
|
||||
point.y = data.ReadInt32();
|
||||
DragEvent event = static_cast<DragEvent> (data.ReadUint32());
|
||||
UpdateWindowDragInfo(point, event);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 <refbase.h>
|
||||
|
||||
#include "window_root.h"
|
||||
#include "wm_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class DragController : public RefBase {
|
||||
public:
|
||||
DragController(sptr<WindowRoot>& root) : windowRoot_(root) {}
|
||||
~DragController() = default;
|
||||
void StartDrag(uint32_t windowId);
|
||||
void UpdateDragInfo(uint32_t windowId);
|
||||
void FinishDrag(uint32_t windowId);
|
||||
private:
|
||||
sptr<WindowNode> GetHitWindow(PointInfo point);
|
||||
bool GetHitPoint(uint32_t windowId, PointInfo& point);
|
||||
sptr<WindowRoot> windowRoot_;
|
||||
uint64_t hitWindowId_ = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // OHOS_ROSEN_DRAG_CONTROLLER_H
|
||||
|
||||
@@ -36,7 +36,8 @@ private:
|
||||
sptr<WindowRoot> windowRoot_;
|
||||
std::vector<MMI::PhysicalDisplayInfo> physicalDisplays_;
|
||||
std::vector<MMI::LogicalDisplayInfo> logicalDisplays_;
|
||||
std::unordered_set<WindowType> windowTypeSkipped_ { WindowType::WINDOW_TYPE_POINTER };
|
||||
std::unordered_set<WindowType> windowTypeSkipped_ { WindowType::WINDOW_TYPE_POINTER,
|
||||
WindowType::WINDOW_TYPE_DRAGGING_EFFECT };
|
||||
const int INVALID_WINDOW_ID = -1;
|
||||
void TraverseWindowNodes(const std::vector<sptr<WindowNode>>& windowNodes,
|
||||
std::vector<MMI::LogicalDisplayInfo>::iterator& iter);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <parameters.h>
|
||||
#include <system_ability.h>
|
||||
#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> windowController_;
|
||||
sptr<InputWindowMonitor> inputWindowMonitor_;
|
||||
sptr<SnapshotController> snapshotController_;
|
||||
sptr<DragController> dragController_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<WindowNode> 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<WindowNode> 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<WindowNode> 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<WindowNode> node = windowRoot_->GetWindowNode(windowId);
|
||||
if (node == nullptr) {
|
||||
WLOGFE("get node failed");
|
||||
return;
|
||||
}
|
||||
if (node->GetWindowType() != WindowType::WINDOW_TYPE_DRAGGING_EFFECT) {
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<WindowNode> 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<WindowNode> 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<WindowNodeContainer> container = windowRoot_->GetOrCreateWindowNodeContainer(id);
|
||||
if (container == nullptr) {
|
||||
WLOGFE("get container failed %{public}" PRIu64"", id);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<sptr<WindowNode>> 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> windowNode = windowRoot_->GetWindowNode(windowId);
|
||||
if (windowNode == nullptr || windowNode->GetWindowType() != WindowType::WINDOW_TYPE_DRAGGING_EFFECT) {
|
||||
WLOGFE("Get hit point failed");
|
||||
return false;
|
||||
}
|
||||
sptr<WindowProperty> property = windowNode->GetWindowProperty();
|
||||
point.x = property->GetWindowRect().posX_ + property->GetHitOffset().x;
|
||||
point.y = property->GetWindowRect().posY_ + property->GetHitOffset().y;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<IWindow>& window, sptr<WindowPro
|
||||
WMError WindowManagerService::AddWindow(sptr<WindowProperty>& 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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)
|
||||
|
||||
Reference in New Issue
Block a user