Skip to content

Commit

Permalink
config: fix gradient rgb(a) parsing with spaces (for real this time) (#…
Browse files Browse the repository at this point in the history
…628)

* config: fix gradient rgb(a) parsing with spaces (for real this time)

* config: conditionally split gradient colors
  • Loading branch information
PaideiaDilemma authored Jan 1, 2025
1 parent 836dbfb commit a2f00fb
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../config/ConfigDataValues.hpp"
#include <hyprlang.hpp>
#include <hyprutils/path/Path.hpp>
#include <hyprutils/string/String.hpp>
#include <filesystem>
#include <glob.h>
#include <cstring>
Expand Down Expand Up @@ -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<CGradientValueData*>(*data);

CVarList varlist(V, 0, ' ');
DATA->m_vColors.clear();
DATA->m_bIsFallback = false;

std::string parseError = "";

for (auto const& var : varlist) {
if (var.find("deg") != std::string::npos) {
// last arg
std::string rolling = V;

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 (...) {
Expand All @@ -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);
Expand Down

0 comments on commit a2f00fb

Please sign in to comment.