From ea7569d7e0941d19f5f469a5fbb79bc0fa62b935 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 11 Dec 2023 22:58:40 +0000 Subject: [PATCH] config: improve layoutopt handling for workspacerules --- src/config/ConfigManager.cpp | 16 ++++++++++++++-- src/config/ConfigManager.hpp | 30 +++++++++++++++--------------- src/layout/MasterLayout.cpp | 13 ++++++------- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 5eb26efc..75def1dd 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1227,8 +1227,20 @@ void CConfigManager::handleWorkspaceRules(const std::string& command, const std: wsRule.isPersistent = configStringToInt(rule.substr(delim + 11)); else if ((delim = rule.find(ruleOnCreatedEmtpy)) != std::string::npos) wsRule.onCreatedEmptyRunCmd = cleanCmdForWorkspace(name, rule.substr(delim + ruleOnCreatedEmtpyLen)); - else if ((delim = rule.find("layoutopt:orientation:")) != std::string::npos) - wsRule.layoutopts["orientation"] = rule.substr(delim + 22); + else if ((delim = rule.find("layoutopt:")) != std::string::npos) { + std::string opt = rule.substr(delim + 10); + if (!opt.contains(":")) { + // invalid + Debug::log(ERR, "Invalid workspace rule found: {}", rule); + parseError = "Invalid workspace rule found: " + rule; + return; + } + + std::string val = opt.substr(opt.find(":") + 1); + opt = opt.substr(0, opt.find(":")); + + wsRule.layoutopts[opt] = val; + } }; size_t pos = 0; diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 8009100e..d5957cd5 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -37,21 +37,21 @@ struct SConfigValue { }; struct SWorkspaceRule { - std::string monitor = ""; - std::string workspaceString = ""; - std::string workspaceName = ""; - int workspaceId = -1; - bool isDefault = false; - bool isPersistent = false; - std::optional gapsIn; - std::optional gapsOut; - std::optional borderSize; - std::optional border; - std::optional rounding; - std::optional decorate; - std::optional shadow; - std::optional onCreatedEmptyRunCmd; - std::map layoutopts; + std::string monitor = ""; + std::string workspaceString = ""; + std::string workspaceName = ""; + int workspaceId = -1; + bool isDefault = false; + bool isPersistent = false; + std::optional gapsIn; + std::optional gapsOut; + std::optional borderSize; + std::optional border; + std::optional rounding; + std::optional decorate; + std::optional shadow; + std::optional onCreatedEmptyRunCmd; + std::map layoutopts; }; struct SMonitorAdditionalReservedArea { diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 8b12d669..ff7f9e2e 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -45,10 +45,8 @@ SMasterWorkspaceData* CHyprMasterLayout::getMasterWorkspaceData(const int& ws) { const auto layoutoptsForWs = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(ws)).layoutopts; auto orientationForWs = *orientation; - try { - if (layoutoptsForWs.contains("orientation")) - orientationForWs = std::any_cast(layoutoptsForWs.at("orientation")); - } catch (std::exception& e) { Debug::log(ERR, "Error from layoutopt rules: {}", e.what()); } + if (layoutoptsForWs.contains("orientation")) + orientationForWs = layoutoptsForWs.at("orientation"); if (orientationForWs == "top") { PWORKSPACEDATA->orientation = ORIENTATION_TOP; @@ -56,11 +54,12 @@ SMasterWorkspaceData* CHyprMasterLayout::getMasterWorkspaceData(const int& ws) { PWORKSPACEDATA->orientation = ORIENTATION_RIGHT; } else if (orientationForWs == "bottom") { PWORKSPACEDATA->orientation = ORIENTATION_BOTTOM; - } else if (orientationForWs == "left") { - PWORKSPACEDATA->orientation = ORIENTATION_LEFT; - } else { + } else if (orientationForWs == "center") { PWORKSPACEDATA->orientation = ORIENTATION_CENTER; + } else { + PWORKSPACEDATA->orientation = ORIENTATION_LEFT; } + return PWORKSPACEDATA; }