mirror of
https://github.com/hyprwm/hyprlock.git
synced 2025-01-27 04:49:48 +01:00
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
This commit is contained in:
parent
836dbfbb13
commit
a2f00fb735
1 changed files with 19 additions and 6 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include "../config/ConfigDataValues.hpp"
|
#include "../config/ConfigDataValues.hpp"
|
||||||
#include <hyprlang.hpp>
|
#include <hyprlang.hpp>
|
||||||
#include <hyprutils/path/Path.hpp>
|
#include <hyprutils/path/Path.hpp>
|
||||||
|
#include <hyprutils/string/String.hpp>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <glob.h>
|
#include <glob.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -71,22 +72,33 @@ static void configHandleLayoutOptionDestroy(void** data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** data) {
|
static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** data) {
|
||||||
std::string V = VALUE;
|
const std::string V = VALUE;
|
||||||
|
|
||||||
if (!*data)
|
if (!*data)
|
||||||
*data = new CGradientValueData();
|
*data = new CGradientValueData();
|
||||||
|
|
||||||
const auto DATA = reinterpret_cast<CGradientValueData*>(*data);
|
const auto DATA = reinterpret_cast<CGradientValueData*>(*data);
|
||||||
|
|
||||||
CVarList varlist(V, 0, ' ');
|
|
||||||
DATA->m_vColors.clear();
|
DATA->m_vColors.clear();
|
||||||
DATA->m_bIsFallback = false;
|
DATA->m_bIsFallback = false;
|
||||||
|
|
||||||
std::string parseError = "";
|
std::string parseError = "";
|
||||||
|
std::string rolling = V;
|
||||||
|
|
||||||
for (auto const& var : varlist) {
|
while (!rolling.empty()) {
|
||||||
if (var.find("deg") != std::string::npos) {
|
const auto SPACEPOS = rolling.find(' ');
|
||||||
// last arg
|
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 {
|
try {
|
||||||
DATA->m_fAngle = std::stoi(var.substr(0, var.find("deg"))) * (M_PI / 180.0); // radians
|
DATA->m_fAngle = std::stoi(var.substr(0, var.find("deg"))) * (M_PI / 180.0); // radians
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
@ -95,7 +107,8 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void**
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
} else // hex
|
||||||
|
rolling = trim(rolling.substr(LAST ? rolling.length() : SPACEPOS + 1));
|
||||||
|
|
||||||
if (DATA->m_vColors.size() >= 10) {
|
if (DATA->m_vColors.size() >= 10) {
|
||||||
Debug::log(WARN, "Error parsing gradient {}: max colors is 10.", V);
|
Debug::log(WARN, "Error parsing gradient {}: max colors is 10.", V);
|
||||||
|
|
Loading…
Reference in a new issue