mode change hot zone

Signed-off-by: qianlf <qianliangfang@huawei.com>
Change-Id: Ia414d3f774d0b2d49e8735885dfe903ac863e1da
This commit is contained in:
qianlf
2022-04-22 17:05:43 +08:00
parent 029e315ed5
commit e421a44e4f
19 changed files with 221 additions and 23 deletions
+3 -1
View File
@@ -14,9 +14,11 @@
* limitations under the License.
-->
<Configs>
<!--decor enable is true means app main window show decoration-->
<!--decor enable is true means app main window show decoration-->
<decor enable="false"></decor>
<maxAppWindowNumber>100</maxAppWindowNumber>
<!--minimizeByOther enable is true means fullscreen window will be minmized by other fullscreen window-->
<minimizeByOther enable="true"></minimizeByOther>
<!--window mdoe change hot zones config, fullscreen primary secondary-->
<modeChangeHotZones>50 50 50</modeChangeHotZones>
</Configs>
+29 -1
View File
@@ -16,6 +16,7 @@
#ifndef OHOS_WM_INCLUDE_WM_HELPER_H
#define OHOS_WM_INCLUDE_WM_HELPER_H
#include <vector>
#include <wm_common.h>
#include <wm_common_inner.h>
@@ -200,10 +201,37 @@ public:
return AvoidPosType::AVOID_POS_UNKNOWN;
}
static inline bool IsNumber(std::string str)
{
for (int32_t i = 0; i < static_cast<int32_t>(str.size()); i++) {
if (str.at(i) < '0' || str.at(i) > '9') {
return false;
}
}
return true;
}
static std::vector<std::string> Split(std::string str, std::string pattern)
{
int32_t position;
std::vector<std::string> result;
str += pattern;
int32_t length = static_cast<int32_t>(str.size());
for (int32_t i = 0; i < length; i++) {
position = static_cast<int32_t>(str.find(pattern, i));
if (position < length) {
std::string tmp = str.substr(i, position - i);
result.push_back(tmp);
i = position + static_cast<int32_t>(pattern.size()) - 1;
}
}
return result;
}
private:
WindowHelper() = default;
~WindowHelper() = default;
};
} // namespace OHOS
} // namespace Rosen
#endif // OHOS_WM_INCLUDE_WM_HELPER_H
#endif // OHOS_WM_INCLUDE_WM_HELPER_H
+14
View File
@@ -17,6 +17,7 @@
#define OHOS_ROSEN_WM_COMMON_INNER_H
#include <cinttypes>
#include "wm_common.h"
namespace OHOS {
namespace Rosen {
@@ -75,6 +76,19 @@ enum class PropertyChangeAction : uint32_t {
ACTION_UPDATE_SET_BRIGHTNESS = 1 << 10,
};
struct ModeChangeHotZonesConfig {
bool isModeChangeHotZoneConfigured_;
uint32_t fullscreenRange_;
uint32_t primaryRange_;
uint32_t secondaryRange_;
};
struct ModeChangeHotZones {
Rect fullscreen_;
Rect primary_;
Rect secondary_;
};
namespace {
constexpr float DEFAULT_SPLIT_RATIO = 0.5;
constexpr uint32_t DIVIDER_WIDTH = 8;
+1
View File
@@ -52,6 +52,7 @@ public:
virtual WMError SetWindowLayoutMode(DisplayId displayId, WindowLayoutMode mode);
virtual WMError UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action);
virtual WMError GetSystemDecorEnable(bool& isSystemDecorEnable);
virtual WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones);
virtual void RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent);
+2 -1
View File
@@ -253,7 +253,7 @@ private:
void HandleDragEvent(int32_t posX, int32_t posY, int32_t pointId);
void HandleMoveEvent(int32_t posX, int32_t posY, int32_t pointId);
void ReadyToMoveOrDragWindow(int32_t globalX, int32_t globalY, int32_t pointId, const Rect& rect);
void EndMoveOrDragWindow(int32_t pointId);
void EndMoveOrDragWindow(int32_t posX, int32_t posY, int32_t pointId);
bool IsPointerEventConsumed();
void AdjustWindowAnimationFlag();
void MapFloatingWindowToAppIfNeeded();
@@ -262,6 +262,7 @@ private:
WMError SetBackgroundColor(uint32_t color);
uint32_t GetBackgroundColor() const;
Rect GetSystemAlarmWindowDefaultSize(Rect defaultRect);
void HandleModeChangeHotZones(int32_t posX, int32_t posY);
// colorspace, gamut
using ColorSpaceConvertMap = struct {
+7
View File
@@ -156,6 +156,13 @@ WMError WindowAdapter::GetSystemDecorEnable(bool& isSystemDecorEnable)
return windowManagerServiceProxy_->GetSystemDecorEnable(isSystemDecorEnable);
}
WMError WindowAdapter::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
{
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
return windowManagerServiceProxy_->GetModeChangeHotZones(displayId, hotZones);
}
bool WindowAdapter::InitWMSProxy()
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
+30 -2
View File
@@ -1447,7 +1447,34 @@ void WindowImpl::HandleDragEvent(int32_t posX, int32_t posY, int32_t pointId)
}
}
void WindowImpl::EndMoveOrDragWindow(int32_t pointId)
void WindowImpl::HandleModeChangeHotZones(int32_t posX, int32_t posY)
{
if (!WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) {
return;
}
ModeChangeHotZones hotZones;
auto res = SingletonContainer::Get<WindowAdapter>().GetModeChangeHotZones(property_->GetDisplayId(), hotZones);
WLOGFI("[HotZone] Window %{public}u, Pointer[%{public}d, %{public}d]", GetWindowId(), posX, posY);
if (res == WMError::WM_OK) {
WLOGFI("[HotZone] Fullscreen [%{public}d, %{public}d, %{public}u, %{public}u]", hotZones.fullscreen_.posX_,
hotZones.fullscreen_.posY_, hotZones.fullscreen_.width_, hotZones.fullscreen_.height_);
WLOGFI("[HotZone] Primary [%{public}d, %{public}d, %{public}u, %{public}u]", hotZones.primary_.posX_,
hotZones.primary_.posY_, hotZones.primary_.width_, hotZones.primary_.height_);
WLOGFI("[HotZone] Secondary [%{public}d, %{public}d, %{public}u, %{public}u]", hotZones.secondary_.posX_,
hotZones.secondary_.posY_, hotZones.secondary_.width_, hotZones.secondary_.height_);
if (WindowHelper::IsPointInTargetRect(posX, posY, hotZones.fullscreen_)) {
SetFullScreen(true);
} else if (WindowHelper::IsPointInTargetRect(posX, posY, hotZones.primary_)) {
SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
} else if (WindowHelper::IsPointInTargetRect(posX, posY, hotZones.secondary_)) {
SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
}
}
}
void WindowImpl::EndMoveOrDragWindow(int32_t posX, int32_t posY, int32_t pointId)
{
if (pointId != startPointerId_) {
return;
@@ -1463,6 +1490,7 @@ void WindowImpl::EndMoveOrDragWindow(int32_t pointId)
SingletonContainer::Get<WindowAdapter>().ProcessPointUp(GetWindowId());
}
startMoveFlag_ = false;
HandleModeChangeHotZones(posX, posY);
}
pointEventStarted_ = false;
}
@@ -1551,7 +1579,7 @@ void WindowImpl::ConsumeMoveOrDragEvent(std::shared_ptr<MMI::PointerEvent>& poin
case MMI::PointerEvent::POINTER_ACTION_UP:
case MMI::PointerEvent::POINTER_ACTION_BUTTON_UP:
case MMI::PointerEvent::POINTER_ACTION_CANCEL: {
EndMoveOrDragWindow(pointId);
EndMoveOrDragWindow(pointGlobalX, pointGlobalY, pointId);
WLOGFI("[Point Up/Cancel]: windowId: %{public}u, action: %{public}d, startMove: %{public}d, "
"startDrag: %{public}d", GetWindowId(), action, startMoveFlag_, startDragFlag_);
break;
+2
View File
@@ -55,6 +55,8 @@ public:
WMError UpdateProperty(sptr<WindowProperty>& property, PropertyChangeAction action);
void NotifySystemBarTints();
WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller);
WMError GetModeChangeHotZones(DisplayId displayId,
ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config);
private:
void CreateDesWindowNodeAndShow(sptr<WindowNode>& desNode, const WindowTransitionInfo& toInfo);
@@ -55,6 +55,7 @@ public:
TRANS_ID_ANIMATION_SET_CONTROLLER,
TRANS_ID_GET_SYSTEM_DECOR_ENABLE,
TRANS_ID_NOTIFY_WINDOW_TRANSITION,
TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE,
};
virtual WMError CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
const std::shared_ptr<RSSurfaceNode>& surfaceNode,
@@ -81,6 +82,7 @@ public:
virtual WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller) = 0;
virtual WMError GetSystemDecorEnable(bool& isSystemDecorEnable) = 0;
virtual void NotifyWindowTransition(WindowTransitionInfo from, WindowTransitionInfo to) = 0;
virtual WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones) = 0;
};
}
}
+1
View File
@@ -54,6 +54,7 @@ public:
WMError GetAccessibilityWindowInfo(sptr<AccessibilityWindowInfo>& windowInfo) override;
WMError GetSystemDecorEnable(bool& isSystemDecorEnable) override;
WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones) override;
private:
static inline BrokerDelegator<WindowManagerProxy> delegator_;
@@ -77,6 +77,7 @@ public:
WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller) override;
WMError GetSystemDecorEnable(bool& isSystemDecorEnable) override;
WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones) override;
protected:
WindowManagerService();
@@ -100,6 +101,7 @@ private:
sptr<DragController> dragController_;
sptr<FreezeController> freezeDisplayController_;
bool isSystemDecorEnable_ = true;
ModeChangeHotZonesConfig hotZonesConfig_ { false, 0, 0, 0 };
};
}
}
+2
View File
@@ -87,6 +87,8 @@ public:
void ProcessDisplayDestroy(DisplayId displayId, std::vector<uint32_t>& windowIds);
void ProcessDisplayChange(DisplayId displayId, const Rect& displayRect);
void SetMinimizedByOther(bool isMinimizedByOther);
void GetModeChangeHotZones(DisplayId displayId,
ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config);
private:
void TraverseWindowNode(sptr<WindowNode>& root, std::vector<sptr<WindowNode>>& windowNodes) const;
+2
View File
@@ -77,6 +77,8 @@ public:
WMError GetAccessibilityWindowInfo(sptr<AccessibilityWindowInfo>& windowInfo);
void SetMaxAppWindowNumber(int windowNum);
void SetMinimizedByOtherWindow(bool isMinimizedByOtherWindow);
WMError GetModeChangeHotZones(DisplayId displayId,
ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config);
private:
void OnRemoteDied(const sptr<IRemoteObject>& remoteObject);
+6
View File
@@ -626,5 +626,11 @@ WMError WindowController::UpdateProperty(sptr<WindowProperty>& property, Propert
}
return WMError::WM_OK;
}
WMError WindowController::GetModeChangeHotZones(DisplayId displayId,
ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config)
{
return windowRoot_->GetModeChangeHotZones(displayId, hotZones, config);
}
} // namespace OHOS
} // namespace Rosen
+39
View File
@@ -583,5 +583,44 @@ void WindowManagerProxy::NotifyWindowTransition(WindowTransitionInfo from, Windo
return;
}
}
WMError WindowManagerProxy::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint64(displayId)) {
WLOGFE("Write displayId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE),
data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
WMError ret = static_cast<WMError>(reply.ReadInt32());
if (ret == WMError::WM_OK) {
hotZones.fullscreen_.posX_ = reply.ReadInt32();
hotZones.fullscreen_.posY_ = reply.ReadInt32();
hotZones.fullscreen_.width_ = reply.ReadUint32();
hotZones.fullscreen_.height_ = reply.ReadUint32();
hotZones.primary_.posX_ = reply.ReadInt32();
hotZones.primary_.posY_ = reply.ReadInt32();
hotZones.primary_.width_ = reply.ReadUint32();
hotZones.primary_.height_ = reply.ReadUint32();
hotZones.secondary_.posX_ = reply.ReadInt32();
hotZones.secondary_.posY_ = reply.ReadInt32();
hotZones.secondary_.width_ = reply.ReadUint32();
hotZones.secondary_.height_ = reply.ReadUint32();
}
return ret;
}
} // namespace Rosen
} // namespace OHOS
+29 -18
View File
@@ -26,8 +26,9 @@
#include "display_manager_service_inner.h"
#include "drag_controller.h"
#include "singleton_container.h"
#include "window_manager_agent_controller.h"
#include "window_helper.h"
#include "window_inner_manager.h"
#include "window_manager_agent_controller.h"
#include "window_manager_hilog.h"
#include "wm_common.h"
#include "wm_trace.h"
@@ -162,26 +163,11 @@ bool WindowManagerService::ParseChildNode(xmlNode* child)
}
} else if (!xmlStrcmp(child->name, reinterpret_cast<const xmlChar*>("maxAppWindowNumber"))) {
const char* maxAppWindowNumberStr = reinterpret_cast<const char*>(xmlNodeGetContent(child));
if (!maxAppWindowNumberStr) {
return false;
}
int maxAppWindowNumber = 0;
const char* strEnd = maxAppWindowNumberStr + strlen(maxAppWindowNumberStr);
auto it = std::find_if(maxAppWindowNumberStr, strEnd, [&maxAppWindowNumber](char c) {
if (c < '0' || c > '9') {
return true;
} else {
maxAppWindowNumber *= 10;
maxAppWindowNumber += c - '0';
return false;
}
});
if (it != strEnd) {
if (!maxAppWindowNumberStr || !WindowHelper::IsNumber(maxAppWindowNumberStr)) {
WLOGFW("Invalid maxAppWindowNumber");
return false;
} else {
windowRoot_->SetMaxAppWindowNumber(maxAppWindowNumber);
}
windowRoot_->SetMaxAppWindowNumber(std::atoi(maxAppWindowNumberStr));
} else if (!xmlStrcmp(child->name, reinterpret_cast<const xmlChar*>("minimizeByOther"))) {
char* enable = reinterpret_cast<char*>(xmlGetProp(child, reinterpret_cast<const xmlChar*>("enable")));
if (!enable) {
@@ -194,6 +180,22 @@ bool WindowManagerService::ParseChildNode(xmlNode* child)
} else {
WLOGFW("Invalid resource prop");
}
} else if (!xmlStrcmp(child->name, reinterpret_cast<const xmlChar*>("modeChangeHotZones"))) {
const char* hotZones = reinterpret_cast<const char*>(xmlNodeGetContent(child));
if (!hotZones) {
WLOGFW("Invalid hotZones");
return false;
}
std::string hotZonesStr = hotZones;
auto result = WindowHelper::Split(hotZonesStr, " ");
if (result.size() != 3 || !WindowHelper::IsNumber(result[0]) || // 3 hot zones, 0 fullscreen
!WindowHelper::IsNumber(result[1]) || !WindowHelper::IsNumber(result[2])) { // 1 primary, 2 secondary
return false;
}
hotZonesConfig_.fullscreenRange_ = static_cast<uint32_t>(std::stoi(result[0])); // 0 fullscreen
hotZonesConfig_.primaryRange_ = static_cast<uint32_t>(std::stoi(result[1])); // 1 primary
hotZonesConfig_.secondaryRange_ = static_cast<uint32_t>(std::stoi(result[2])); // 2 secondary
hotZonesConfig_.isModeChangeHotZoneConfigured_ = true;
}
return true;
@@ -426,5 +428,14 @@ WMError WindowManagerService::GetSystemDecorEnable(bool& isSystemDecorEnable)
isSystemDecorEnable = isSystemDecorEnable_;
return WMError::WM_OK;
}
WMError WindowManagerService::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
{
if (!hotZonesConfig_.isModeChangeHotZoneConfigured_) {
return WMError::WM_DO_NOTHING;
}
return windowController_->GetModeChangeHotZones(displayId, hotZones, hotZonesConfig_);
}
} // namespace Rosen
} // namespace OHOS
+22
View File
@@ -188,6 +188,28 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M
NotifyWindowTransition(*from, *to);
break;
}
case WindowManagerMessage::TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE: {
DisplayId displayId = data.ReadUint64();
ModeChangeHotZones hotZones = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
WMError errCode = GetModeChangeHotZones(displayId, hotZones);
reply.WriteInt32(static_cast<int32_t>(errCode));
reply.WriteInt32(hotZones.fullscreen_.posX_);
reply.WriteInt32(hotZones.fullscreen_.posY_);
reply.WriteUint32(hotZones.fullscreen_.width_);
reply.WriteUint32(hotZones.fullscreen_.height_);
reply.WriteInt32(hotZones.primary_.posX_);
reply.WriteInt32(hotZones.primary_.posY_);
reply.WriteUint32(hotZones.primary_.width_);
reply.WriteUint32(hotZones.primary_.height_);
reply.WriteInt32(hotZones.secondary_.posX_);
reply.WriteInt32(hotZones.secondary_.posY_);
reply.WriteUint32(hotZones.secondary_.width_);
reply.WriteUint32(hotZones.secondary_.height_);
break;
}
default:
WLOGFW("unknown transaction code %{public}d", code);
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
+16
View File
@@ -1575,5 +1575,21 @@ void WindowNodeContainer::SetMinimizedByOther(bool isMinimizedByOther)
{
isMinimizedByOther_ = isMinimizedByOther;
}
void WindowNodeContainer::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones,
const ModeChangeHotZonesConfig& config)
{
auto displayRect = displayRectMap_[displayId];
hotZones.fullscreen_.width_ = displayRect.width_;
hotZones.fullscreen_.height_ = config.fullscreenRange_;
hotZones.primary_.width_ = config.primaryRange_;
hotZones.primary_.height_ = displayRect.height_;
hotZones.secondary_.posX_ = static_cast<int32_t>(displayRect.width_) - config.secondaryRange_;
hotZones.secondary_.width_ = config.secondaryRange_;
hotZones.secondary_.height_ = displayRect.height_;
}
} // namespace Rosen
} // namespace OHOS
+12
View File
@@ -908,5 +908,17 @@ void WindowRoot::SetMinimizedByOtherWindow(bool isMinimizedByOtherWindow)
WLOGFI("isMinimizedByOtherWindow:%{public}d", isMinimizedByOtherWindow);
isMinimizedByOtherWindow_ = isMinimizedByOtherWindow;
}
WMError WindowRoot::GetModeChangeHotZones(DisplayId displayId,
ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config)
{
auto container = GetWindowNodeContainer(displayId);
if (container == nullptr) {
WLOGFE("GetModeChangeHotZones failed, window container could not be found");
return WMError::WM_ERROR_NULLPTR;
}
container->GetModeChangeHotZones(displayId, hotZones, config);
return WMError::WM_OK;
}
} // namespace OHOS::Rosen
} // namespace OHOS