mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-21 04:25:28 -04:00
window manager config rewrite
Signed-off-by: qianlf <qianliangfang@huawei.com> Change-Id: Iae11fdb843fdea6553874dde9de03a3f99f7de84
This commit is contained in:
@@ -71,6 +71,7 @@ ohos_shared_library("libwms") {
|
||||
"src/window_layout_policy_cascade.cpp",
|
||||
"src/window_layout_policy_tile.cpp",
|
||||
"src/window_manager_agent_controller.cpp",
|
||||
"src/window_manager_config.cpp",
|
||||
"src/window_manager_service.cpp",
|
||||
"src/window_manager_stub.cpp",
|
||||
"src/window_node.cpp",
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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_WINDOW_MANAGER_CONFIG_H
|
||||
#define OHOS_ROSEN_WINDOW_MANAGER_CONFIG_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <refbase.h>
|
||||
#include "libxml/parser.h"
|
||||
#include "libxml/tree.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class WindowManagerConfig : public RefBase {
|
||||
public:
|
||||
WindowManagerConfig() = delete;
|
||||
~WindowManagerConfig() = default;
|
||||
|
||||
static bool LoadConfigXml(const std::string& configFilePath);
|
||||
static const std::map<std::string, bool>& GetEnableConfig();
|
||||
static const std::map<std::string, std::vector<int>>& GetNumbersConfig();
|
||||
static void DumpConfig();
|
||||
|
||||
private:
|
||||
static std::map<std::string, bool> enableConfig_;
|
||||
static std::map<std::string, std::vector<int>> numbersConfig_;
|
||||
|
||||
static bool IsValidNode(const xmlNode& currNode);
|
||||
static void ReadEnableConfigInfo(const xmlNodePtr& currNode);
|
||||
static void ReadNumbersConfigInfo(const xmlNodePtr& currNode);
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ROSEN_WINDOW_MANAGER_CONFIG_H
|
||||
@@ -32,9 +32,6 @@
|
||||
#include "window_root.h"
|
||||
#include "snapshot_controller.h"
|
||||
|
||||
#include "libxml/parser.h"
|
||||
#include "libxml/tree.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class DisplayChangeListener : public IDisplayChangeListener {
|
||||
@@ -89,8 +86,7 @@ private:
|
||||
void RegisterWindowManagerServiceHandler();
|
||||
void OnWindowEvent(Event event, uint32_t windowId);
|
||||
void NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type);
|
||||
bool LoadConfigXmlFile(std::string configFile);
|
||||
bool ParseChildNode(xmlNode* child);
|
||||
void ConfigureWindowManagerService();
|
||||
|
||||
static inline SingletonDelegator<WindowManagerService> delegator;
|
||||
std::recursive_mutex mutex_;
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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 "window_manager_config.h"
|
||||
#include "window_helper.h"
|
||||
#include "window_manager_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManagerConfig"};
|
||||
}
|
||||
|
||||
std::map<std::string, bool> WindowManagerConfig::enableConfig_;
|
||||
std::map<std::string, std::vector<int>> WindowManagerConfig::numbersConfig_;
|
||||
|
||||
bool WindowManagerConfig::LoadConfigXml(const std::string& configFilePath)
|
||||
{
|
||||
xmlDocPtr docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS);
|
||||
WLOGFI("[WmConfig] filePath: %{public}s", configFilePath.c_str());
|
||||
if (docPtr == nullptr) {
|
||||
WLOGFE("[WmConfig] load xml error!");
|
||||
return false;
|
||||
}
|
||||
|
||||
xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
|
||||
if (rootPtr == nullptr || rootPtr->name == nullptr ||
|
||||
xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
|
||||
WLOGFE("[WmConfig] get root element failed!");
|
||||
xmlFreeDoc(docPtr);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (xmlNodePtr curNodePtr = rootPtr->xmlChildrenNode; curNodePtr != nullptr; curNodePtr = curNodePtr->next) {
|
||||
if (!IsValidNode(*curNodePtr)) {
|
||||
WLOGFE("[WmConfig]: invalid node!");
|
||||
continue;
|
||||
}
|
||||
|
||||
auto nodeName = curNodePtr->name;
|
||||
if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("decor")) ||
|
||||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("minimizeByOther"))) {
|
||||
ReadEnableConfigInfo(curNodePtr);
|
||||
continue;
|
||||
}
|
||||
if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("maxAppWindowNumber")) ||
|
||||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("modeChangeHotZones"))) {
|
||||
ReadNumbersConfigInfo(curNodePtr);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
xmlFreeDoc(docPtr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WindowManagerConfig::IsValidNode(const xmlNode& currNode)
|
||||
{
|
||||
if (currNode.name == nullptr || currNode.type == XML_COMMENT_NODE) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WindowManagerConfig::ReadEnableConfigInfo(const xmlNodePtr& currNode)
|
||||
{
|
||||
xmlChar* enable = xmlGetProp(currNode, reinterpret_cast<const xmlChar*>("enable"));
|
||||
if (enable == nullptr) {
|
||||
WLOGFE("[WmConfig] read xml node error: nodeName:(%{public}s)", currNode->name);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string nodeName = reinterpret_cast<const char *>(currNode->name);
|
||||
enableConfig_[nodeName] = xmlStrcmp(enable, reinterpret_cast<const xmlChar*>("true")) ? false : true;
|
||||
xmlFree(enable);
|
||||
}
|
||||
|
||||
void WindowManagerConfig::ReadNumbersConfigInfo(const xmlNodePtr& currNode)
|
||||
{
|
||||
xmlChar* context = xmlNodeGetContent(currNode);
|
||||
if (context == nullptr) {
|
||||
WLOGFE("[WmConfig] read xml node error: nodeName:(%{public}s)", currNode->name);
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<int> numbersVec;
|
||||
std::string numbersStr = reinterpret_cast<const char*>(context);
|
||||
auto numbers = WindowHelper::Split(numbersStr, " ");
|
||||
for (auto& num : numbers) {
|
||||
if (!WindowHelper::IsNumber(num)) {
|
||||
WLOGFE("[WmConfig] read number error: nodeName:(%{public}s)", currNode->name);
|
||||
xmlFree(context);
|
||||
return;
|
||||
}
|
||||
numbersVec.emplace_back(std::stoi(num));
|
||||
}
|
||||
|
||||
std::string nodeName = reinterpret_cast<const char *>(currNode->name);
|
||||
numbersConfig_[nodeName] = numbersVec;
|
||||
xmlFree(context);
|
||||
}
|
||||
|
||||
const std::map<std::string, bool>& WindowManagerConfig::GetEnableConfig()
|
||||
{
|
||||
return enableConfig_;
|
||||
}
|
||||
|
||||
const std::map<std::string, std::vector<int>>& WindowManagerConfig::GetNumbersConfig()
|
||||
{
|
||||
return numbersConfig_;
|
||||
}
|
||||
|
||||
void WindowManagerConfig::DumpConfig()
|
||||
{
|
||||
for (auto& enable : enableConfig_) {
|
||||
WLOGFI("[WmConfig] Enable: %{public}s %{public}u", enable.first.c_str(), enable.second);
|
||||
}
|
||||
|
||||
for (auto& numbers : numbersConfig_) {
|
||||
WLOGFI("[WmConfig] Numbers: %{public}s %{public}zu", numbers.first.c_str(), numbers.second.size());
|
||||
for (auto& num : numbers.second) {
|
||||
WLOGFI("[WmConfig] Num: %{public}d", num);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "window_helper.h"
|
||||
#include "window_inner_manager.h"
|
||||
#include "window_manager_agent_controller.h"
|
||||
#include "window_manager_config.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "wm_common.h"
|
||||
#include "wm_trace.h"
|
||||
@@ -106,99 +107,43 @@ bool WindowManagerService::Init()
|
||||
WLOGFW("WindowManagerService::Init failed");
|
||||
return false;
|
||||
}
|
||||
if (!LoadConfigXmlFile(WINDOW_MANAGER_CONFIG_XML)) {
|
||||
WLOGFW("Failed to load %{public}s", WINDOW_MANAGER_CONFIG_XML.c_str());
|
||||
return false;
|
||||
if (WindowManagerConfig::LoadConfigXml(WINDOW_MANAGER_CONFIG_XML)) {
|
||||
WindowManagerConfig::DumpConfig();
|
||||
ConfigureWindowManagerService();
|
||||
}
|
||||
WLOGFI("WindowManagerService::Init success");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WindowManagerService::LoadConfigXmlFile(std::string configFile)
|
||||
void WindowManagerService::ConfigureWindowManagerService()
|
||||
{
|
||||
xmlKeepBlanksDefault(0);
|
||||
xmlDoc* file = xmlReadFile(configFile.c_str(), nullptr, 0);
|
||||
if (!file) {
|
||||
WLOGFE("Failed to open xml file");
|
||||
return false;
|
||||
}
|
||||
xmlNode* rootNode = xmlDocGetRootElement(file);
|
||||
if (!rootNode) {
|
||||
WLOGFE("Failed to get xml file's RootNode");
|
||||
xmlFreeDoc(file);
|
||||
return false;
|
||||
}
|
||||
if (!xmlStrcmp(rootNode->name, reinterpret_cast<const xmlChar*>("Configs"))) {
|
||||
xmlNode* child = rootNode->children;
|
||||
for (; child; child = child->next) {
|
||||
if (!ParseChildNode(child)) {
|
||||
WLOGFE("Invalid resource name for %{public}s", configFile.c_str());
|
||||
xmlFreeDoc(file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WLOGFE("Wrong format for xml file");
|
||||
xmlFreeDoc(file);
|
||||
return false;
|
||||
}
|
||||
xmlFreeDoc(file);
|
||||
WLOGFI("Success to Load %{public}s", configFile.c_str());
|
||||
return true;
|
||||
}
|
||||
auto enableConfig = WindowManagerConfig::GetEnableConfig();
|
||||
auto numbersConfig = WindowManagerConfig::GetNumbersConfig();
|
||||
|
||||
bool WindowManagerService::ParseChildNode(xmlNode* child)
|
||||
{
|
||||
if (!xmlStrcmp(child->name, reinterpret_cast<const xmlChar*>("decor"))) {
|
||||
char* enable = reinterpret_cast<char*>(xmlGetProp(child, reinterpret_cast<const xmlChar*>("enable")));
|
||||
if (!enable) {
|
||||
return false;
|
||||
}
|
||||
if (!strcmp(enable, "false")) {
|
||||
isSystemDecorEnable_ = false;
|
||||
} else if (!strcmp(enable, "true")) {
|
||||
isSystemDecorEnable_ = true;
|
||||
} else {
|
||||
WLOGFW("Invalid resource prop");
|
||||
}
|
||||
} else if (!xmlStrcmp(child->name, reinterpret_cast<const xmlChar*>("maxAppWindowNumber"))) {
|
||||
const char* maxAppWindowNumberStr = reinterpret_cast<const char*>(xmlNodeGetContent(child));
|
||||
if (!maxAppWindowNumberStr || !WindowHelper::IsNumber(maxAppWindowNumberStr)) {
|
||||
WLOGFW("Invalid maxAppWindowNumber");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
if (!strcmp(enable, "false")) {
|
||||
windowRoot_->SetMinimizedByOtherWindow(false);
|
||||
} else if (!strcmp(enable, "true")) {
|
||||
windowRoot_->SetMinimizedByOtherWindow(true);
|
||||
} 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;
|
||||
if (enableConfig.count("decor") != 0) {
|
||||
isSystemDecorEnable_ = enableConfig["decor"];
|
||||
}
|
||||
|
||||
return true;
|
||||
if (enableConfig.count("minimizeByOther") != 0) {
|
||||
windowRoot_->SetMinimizedByOtherWindow(enableConfig["minimizeByOther"]);
|
||||
}
|
||||
|
||||
if (numbersConfig.count("maxAppWindowNumber") != 0) {
|
||||
auto numbers = numbersConfig["maxAppWindowNumber"];
|
||||
if (numbers.size() == 1) {
|
||||
windowRoot_->SetMaxAppWindowNumber(numbers[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (numbersConfig.count("modeChangeHotZones") != 0) {
|
||||
auto numbers = numbersConfig["modeChangeHotZones"];
|
||||
if (numbers.size() == 3) { // 3 hot zones
|
||||
hotZonesConfig_.fullscreenRange_ = static_cast<uint32_t>(numbers[0]); // 0 fullscreen
|
||||
hotZonesConfig_.primaryRange_ = static_cast<uint32_t>(numbers[1]); // 1 primary
|
||||
hotZonesConfig_.secondaryRange_ = static_cast<uint32_t>(numbers[2]); // 2 secondary
|
||||
hotZonesConfig_.isModeChangeHotZoneConfigured_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManagerService::OnStop()
|
||||
|
||||
Reference in New Issue
Block a user