From a2f00fb735d72ffad820fa1dc66647c534617580 Mon Sep 17 00:00:00 2001 From: Maximilian Seidler <78690852+PaideiaDilemma@users.noreply.github.com> Date: Wed, 1 Jan 2025 12:18:37 +0000 Subject: [PATCH] config: fix gradient rgb(a) parsing with spaces (for real this time) (#628) * config: fix gradient rgb(a) parsing with spaces (for real this time) * config: conditionally split gradient colors --- src/config/ConfigManager.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 5bf277f..afae96d 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -4,6 +4,7 @@ #include "../config/ConfigDataValues.hpp" #include #include +#include #include #include #include @@ -71,22 +72,33 @@ static void configHandleLayoutOptionDestroy(void** data) { } static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** data) { - std::string V = VALUE; + const std::string V = VALUE; if (!*data) *data = new CGradientValueData(); const auto DATA = reinterpret_cast(*data); - CVarList varlist(V, 0, ' '); DATA->m_vColors.clear(); DATA->m_bIsFallback = false; std::string parseError = ""; + std::string rolling = V; - for (auto const& var : varlist) { - if (var.find("deg") != std::string::npos) { - // last arg + while (!rolling.empty()) { + const auto SPACEPOS = rolling.find(' '); + const bool LAST = SPACEPOS == std::string::npos; + std::string var = rolling.substr(0, SPACEPOS); + if (var.find("rgb") != std::string::npos) { // rgb(a) + const auto CLOSEPARENPOS = rolling.find(')'); + if (CLOSEPARENPOS == std::string::npos || CLOSEPARENPOS + 1 >= rolling.length()) { + var = trim(rolling); + rolling.clear(); + } else { + var = rolling.substr(0, CLOSEPARENPOS + 1); + rolling = trim(rolling.substr(CLOSEPARENPOS + 2)); + } + } else if (var.find("deg") != std::string::npos) { // last arg try { DATA->m_fAngle = std::stoi(var.substr(0, var.find("deg"))) * (M_PI / 180.0); // radians } catch (...) { @@ -95,7 +107,8 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** } break; - } + } else // hex + rolling = trim(rolling.substr(LAST ? rolling.length() : SPACEPOS + 1)); if (DATA->m_vColors.size() >= 10) { Debug::log(WARN, "Error parsing gradient {}: max colors is 10.", V);