diff options
Diffstat (limited to 'src/config/ConfigManager.cpp')
-rw-r--r-- | src/config/ConfigManager.cpp | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 3f6d58ae..6b54e984 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -2,6 +2,8 @@ #include "../managers/KeybindManager.hpp" #include "../render/decorations/CHyprGroupBarDecoration.hpp" +#include "config/ConfigDataValues.hpp" +#include "helpers/VarList.hpp" #include <string.h> #include <string> @@ -76,6 +78,31 @@ static void configHandleGradientDestroy(void** data) { delete reinterpret_cast<CGradientValueData*>(*data); } +static Hyprlang::CParseResult configHandleGapSet(const char* VALUE, void** data) { + std::string V = VALUE; + + if (!*data) + *data = new CCssGapData(); + + const auto DATA = reinterpret_cast<CCssGapData*>(*data); + CVarList varlist(V); + Hyprlang::CParseResult result; + + try { + DATA->parseGapData(varlist); + } catch (...) { + std::string parseError = "Error parsing gaps " + V; + result.setError(parseError.c_str()); + } + + return result; +} + +static void configHandleGapDestroy(void** data) { + if (*data) + delete reinterpret_cast<CCssGapData*>(*data); +} + static Hyprlang::CParseResult handleRawExec(const char* c, const char* v) { const std::string VALUE = v; const std::string COMMAND = c; @@ -279,8 +306,8 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("general:border_size", {1L}); m_pConfig->addConfigValue("general:no_border_on_floating", {0L}); m_pConfig->addConfigValue("general:border_part_of_window", {1L}); - m_pConfig->addConfigValue("general:gaps_in", {5L}); - m_pConfig->addConfigValue("general:gaps_out", {20L}); + m_pConfig->addConfigValue("general:gaps_in", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "5"}); + m_pConfig->addConfigValue("general:gaps_out", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "20"}); m_pConfig->addConfigValue("general:gaps_workspaces", {0L}); m_pConfig->addConfigValue("general:cursor_inactive_timeout", {0L}); m_pConfig->addConfigValue("general:no_cursor_warps", {0L}); @@ -2116,12 +2143,22 @@ std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::strin auto assignRule = [&](std::string rule) -> std::optional<std::string> { size_t delim = std::string::npos; - if ((delim = rule.find("gapsin:")) != std::string::npos) - wsRule.gapsIn = std::stoi(rule.substr(delim + 7)); - else if ((delim = rule.find("gapsout:")) != std::string::npos) - wsRule.gapsOut = std::stoi(rule.substr(delim + 8)); - else if ((delim = rule.find("bordersize:")) != std::string::npos) - wsRule.borderSize = std::stoi(rule.substr(delim + 11)); + if ((delim = rule.find("gapsin:")) != std::string::npos) { + CVarList varlist = CVarList(rule.substr(delim + 7), 0, ' '); + wsRule.gapsIn = CCssGapData(); + try { + wsRule.gapsIn->parseGapData(varlist); + } catch (...) { return "Error parsing workspace rule gaps: {}", rule.substr(delim + 7); } + } else if ((delim = rule.find("gapsout:")) != std::string::npos) { + CVarList varlist = CVarList(rule.substr(delim + 8), 0, ' '); + wsRule.gapsOut = CCssGapData(); + try { + wsRule.gapsOut->parseGapData(varlist); + } catch (...) { return "Error parsing workspace rule gaps: {}", rule.substr(delim + 8); } + } else if ((delim = rule.find("bordersize:")) != std::string::npos) + try { + wsRule.borderSize = std::stoi(rule.substr(delim + 11)); + } catch (...) { return "Error parsing workspace rule bordersize: {}", rule.substr(delim + 11); } else if ((delim = rule.find("border:")) != std::string::npos) wsRule.border = configStringToInt(rule.substr(delim + 7)); else if ((delim = rule.find("shadow:")) != std::string::npos) @@ -2264,4 +2301,4 @@ std::optional<std::string> CConfigManager::handlePlugin(const std::string& comma m_vDeclaredPlugins.push_back(path); return {}; -}
\ No newline at end of file +} |