hyprland/workspaces: break up parseConfig
parent
e4353e548a
commit
9fe51af6b0
|
@ -145,7 +145,17 @@ class Workspaces : public AModule, public EventHandler {
|
||||||
Json::Value const& clientsData = Json::Value::nullRef);
|
Json::Value const& clientsData = Json::Value::nullRef);
|
||||||
void removeWorkspace(std::string const& name);
|
void removeWorkspace(std::string const& name);
|
||||||
void setUrgentWorkspace(std::string const& windowaddress);
|
void setUrgentWorkspace(std::string const& windowaddress);
|
||||||
|
|
||||||
|
// Config
|
||||||
void parseConfig(const Json::Value& config);
|
void parseConfig(const Json::Value& config);
|
||||||
|
auto populateIconsMap(const Json::Value& formatIcons) -> void;
|
||||||
|
auto populateBoolConfig(const Json::Value& config, const std::string& key, bool& member) -> void;
|
||||||
|
auto populateSortByConfig(const Json::Value& config) -> void;
|
||||||
|
auto populateIgnoreWorkspacesConfig(const Json::Value& config) -> void;
|
||||||
|
auto populatePersistentWorkspacesConfig(const Json::Value& config) -> void;
|
||||||
|
auto populateFormatWindowSeparatorConfig(const Json::Value& config) -> void;
|
||||||
|
auto populateWindowRewriteConfig(const Json::Value& config) -> void;
|
||||||
|
|
||||||
void registerIpc();
|
void registerIpc();
|
||||||
|
|
||||||
// workspace events
|
// workspace events
|
||||||
|
|
|
@ -55,54 +55,63 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Workspaces::parseConfig(const Json::Value &config) -> void {
|
auto Workspaces::parseConfig(const Json::Value &config) -> void {
|
||||||
const Json::Value &configFormat = config["format"];
|
const auto &configFormat = config["format"];
|
||||||
|
|
||||||
m_format = configFormat.isString() ? configFormat.asString() : "{name}";
|
m_format = configFormat.isString() ? configFormat.asString() : "{name}";
|
||||||
m_withIcon = m_format.find("{icon}") != std::string::npos;
|
m_withIcon = m_format.find("{icon}") != std::string::npos;
|
||||||
|
|
||||||
if (m_withIcon && m_iconsMap.empty()) {
|
if (m_withIcon && m_iconsMap.empty()) {
|
||||||
Json::Value formatIcons = config["format-icons"];
|
populateIconsMap(config["format-icons"]);
|
||||||
for (std::string &name : formatIcons.getMemberNames()) {
|
}
|
||||||
|
|
||||||
|
populateBoolConfig(config, "all-outputs", m_allOutputs);
|
||||||
|
populateBoolConfig(config, "show-special", m_showSpecial);
|
||||||
|
populateBoolConfig(config, "active-only", m_activeOnly);
|
||||||
|
populateBoolConfig(config, "move-to-monitor", m_moveToMonitor);
|
||||||
|
|
||||||
|
populateSortByConfig(config);
|
||||||
|
|
||||||
|
populateIgnoreWorkspacesConfig(config);
|
||||||
|
|
||||||
|
populatePersistentWorkspacesConfig(config);
|
||||||
|
|
||||||
|
populateFormatWindowSeparatorConfig(config);
|
||||||
|
|
||||||
|
populateWindowRewriteConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Workspaces::populateIconsMap(const Json::Value &formatIcons) -> void {
|
||||||
|
for (const auto &name : formatIcons.getMemberNames()) {
|
||||||
m_iconsMap.emplace(name, formatIcons[name].asString());
|
m_iconsMap.emplace(name, formatIcons[name].asString());
|
||||||
}
|
}
|
||||||
m_iconsMap.emplace("", "");
|
m_iconsMap.emplace("", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto configAllOutputs = config_["all-outputs"];
|
auto Workspaces::populateBoolConfig(const Json::Value &config, const std::string &key, bool &member)
|
||||||
if (configAllOutputs.isBool()) {
|
-> void {
|
||||||
m_allOutputs = configAllOutputs.asBool();
|
auto configValue = config[key];
|
||||||
|
if (configValue.isBool()) {
|
||||||
|
member = configValue.asBool();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto configShowSpecial = config_["show-special"];
|
auto Workspaces::populateSortByConfig(const Json::Value &config) -> void {
|
||||||
if (configShowSpecial.isBool()) {
|
auto configSortBy = config["sort-by"];
|
||||||
m_showSpecial = configShowSpecial.asBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto configActiveOnly = config_["active-only"];
|
|
||||||
if (configActiveOnly.isBool()) {
|
|
||||||
m_activeOnly = configActiveOnly.asBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto configMoveToMonitor = config_["move-to-monitor"];
|
|
||||||
if (configMoveToMonitor.isBool()) {
|
|
||||||
m_moveToMonitor = configMoveToMonitor.asBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto configSortBy = config_["sort-by"];
|
|
||||||
if (configSortBy.isString()) {
|
if (configSortBy.isString()) {
|
||||||
auto sortByStr = configSortBy.asString();
|
auto sortByStr = configSortBy.asString();
|
||||||
try {
|
try {
|
||||||
m_sortBy = m_enumParser.parseStringToEnum(sortByStr, m_sortMap);
|
m_sortBy = m_enumParser.parseStringToEnum(sortByStr, m_sortMap);
|
||||||
} catch (const std::invalid_argument &e) {
|
} catch (const std::invalid_argument &e) {
|
||||||
// Handle the case where the string is not a valid enum representation.
|
|
||||||
m_sortBy = SortMethod::DEFAULT;
|
m_sortBy = SortMethod::DEFAULT;
|
||||||
g_warning("Invalid string representation for sort-by. Falling back to default sort method.");
|
spdlog::warn(
|
||||||
|
"Invalid string representation for sort-by. Falling back to default sort method.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value ignoreWorkspaces = config["ignore-workspaces"];
|
auto Workspaces::populateIgnoreWorkspacesConfig(const Json::Value &config) -> void {
|
||||||
|
auto ignoreWorkspaces = config["ignore-workspaces"];
|
||||||
if (ignoreWorkspaces.isArray()) {
|
if (ignoreWorkspaces.isArray()) {
|
||||||
for (Json::Value &workspaceRegex : ignoreWorkspaces) {
|
for (const auto &workspaceRegex : ignoreWorkspaces) {
|
||||||
if (workspaceRegex.isString()) {
|
if (workspaceRegex.isString()) {
|
||||||
std::string ruleString = workspaceRegex.asString();
|
std::string ruleString = workspaceRegex.asString();
|
||||||
try {
|
try {
|
||||||
|
@ -116,29 +125,31 @@ auto Workspaces::parseConfig(const Json::Value &config) -> void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (config_["persistent_workspaces"].isObject()) {
|
auto Workspaces::populatePersistentWorkspacesConfig(const Json::Value &config) -> void {
|
||||||
|
if (config.isMember("persistent-workspaces") || config.isMember("persistent_workspaces")) {
|
||||||
spdlog::warn(
|
spdlog::warn(
|
||||||
"persistent_workspaces is deprecated. Please change config to use persistent-workspaces.");
|
"persistent_workspaces is deprecated. Please change config to use persistent-workspaces.");
|
||||||
|
m_persistentWorkspaceConfig =
|
||||||
|
config.get("persistent-workspaces", config.get("persistent_workspaces", Json::Value()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (config_["persistent-workspaces"].isObject() || config_["persistent_workspaces"].isObject()) {
|
auto Workspaces::populateFormatWindowSeparatorConfig(const Json::Value &config) -> void {
|
||||||
m_persistentWorkspaceConfig = config_["persistent-workspaces"].isObject()
|
auto formatWindowSeparator = config["format-window-separator"];
|
||||||
? config_["persistent-workspaces"]
|
|
||||||
: config_["persistent_workspaces"];
|
|
||||||
}
|
|
||||||
|
|
||||||
const Json::Value &formatWindowSeparator = config["format-window-separator"];
|
|
||||||
m_formatWindowSeparator =
|
m_formatWindowSeparator =
|
||||||
formatWindowSeparator.isString() ? formatWindowSeparator.asString() : " ";
|
formatWindowSeparator.isString() ? formatWindowSeparator.asString() : " ";
|
||||||
|
}
|
||||||
|
|
||||||
const Json::Value &windowRewrite = config["window-rewrite"];
|
auto Workspaces::populateWindowRewriteConfig(const Json::Value &config) -> void {
|
||||||
|
const auto &windowRewrite = config["window-rewrite"];
|
||||||
if (!windowRewrite.isObject()) {
|
if (!windowRewrite.isObject()) {
|
||||||
spdlog::debug("window-rewrite is not defined or is not an object, using default rules.");
|
spdlog::debug("window-rewrite is not defined or is not an object, using default rules.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Json::Value &windowRewriteDefaultConfig = config["window-rewrite-default"];
|
const auto &windowRewriteDefaultConfig = config["window-rewrite-default"];
|
||||||
std::string windowRewriteDefault =
|
std::string windowRewriteDefault =
|
||||||
windowRewriteDefaultConfig.isString() ? windowRewriteDefaultConfig.asString() : "?";
|
windowRewriteDefaultConfig.isString() ? windowRewriteDefaultConfig.asString() : "?";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue