summaryrefslogtreecommitdiff
path: root/src/Window.cpp
diff options
context:
space:
mode:
authorIsaac Myhal <idmfoundinhim@gmail.com>2024-01-14 12:27:32 -0500
committerGitHub <noreply@github.com>2024-01-14 18:27:32 +0100
commitb6516bad0281efb55195e8db180aa2dcaf8b98e4 (patch)
treed51812e9eda1badd0782bc764afb9777da462537 /src/Window.cpp
parent13d9a637d61ffdd0cb23dda80f6a971f17e0f5b3 (diff)
config: Add border gradients to windowrulev2 (#4335)
* Add border gradients to windowrulev2 * windowrule border gradient: Use CVarList to parse * windowrule border gradient: No {} around short ifs
Diffstat (limited to 'src/Window.cpp')
-rw-r--r--src/Window.cpp48
1 files changed, 38 insertions, 10 deletions
diff --git a/src/Window.cpp b/src/Window.cpp
index 818b4089..5a50713b 100644
--- a/src/Window.cpp
+++ b/src/Window.cpp
@@ -614,14 +614,42 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
m_sAdditionalConfigData.animationStyle = STYLE;
} else if (r.szRule.starts_with("bordercolor")) {
try {
- std::string colorPart = removeBeginEndSpacesTabs(r.szRule.substr(r.szRule.find_first_of(' ') + 1));
-
- if (colorPart.contains(' ')) {
- // we have a space, 2 values
- m_sSpecialRenderData.activeBorderColor = configStringToInt(colorPart.substr(0, colorPart.find_first_of(' ')));
- m_sSpecialRenderData.inactiveBorderColor = configStringToInt(colorPart.substr(colorPart.find_first_of(' ') + 1));
- } else {
- m_sSpecialRenderData.activeBorderColor = configStringToInt(colorPart);
+ // Each vector will only get used if it has at least one color
+ CGradientValueData activeBorderGradient = {};
+ CGradientValueData inactiveBorderGradient = {};
+ bool active = true;
+ CVarList colorsAndAngles = CVarList(removeBeginEndSpacesTabs(r.szRule.substr(r.szRule.find_first_of(' ') + 1)), 0, 's', true);
+
+ // Basic form has only two colors, everything else can be parsed as a gradient
+ if (colorsAndAngles.size() == 2 && !colorsAndAngles[1].contains("deg")) {
+ m_sSpecialRenderData.activeBorderColor = CGradientValueData(CColor(configStringToInt(colorsAndAngles[0])));
+ m_sSpecialRenderData.inactiveBorderColor = CGradientValueData(CColor(configStringToInt(colorsAndAngles[1])));
+ return;
+ }
+
+ for (auto& token : colorsAndAngles) {
+ // The first angle, or an explicit "0deg", splits the two gradients
+ if (active && token.contains("deg")) {
+ activeBorderGradient.m_fAngle = std::stoi(token.substr(0, token.size() - 3)) * (PI / 180.0);
+ active = false;
+ } else if (token.contains("deg"))
+ inactiveBorderGradient.m_fAngle = std::stoi(token.substr(0, token.size() - 3)) * (PI / 180.0);
+ else if (active)
+ activeBorderGradient.m_vColors.push_back(configStringToInt(token));
+ else
+ inactiveBorderGradient.m_vColors.push_back(configStringToInt(token));
+ }
+
+ // Includes sanity checks for the number of colors in each gradient
+ if (activeBorderGradient.m_vColors.size() > 10 || inactiveBorderGradient.m_vColors.size() > 10)
+ Debug::log(WARN, "Bordercolor rule \"{}\" has more than 10 colors in one gradient, ignoring", r.szRule);
+ else if (activeBorderGradient.m_vColors.empty())
+ Debug::log(WARN, "Bordercolor rule \"{}\" has no colors, ignoring", r.szRule);
+ else if (inactiveBorderGradient.m_vColors.empty())
+ m_sSpecialRenderData.activeBorderColor = activeBorderGradient;
+ else {
+ m_sSpecialRenderData.activeBorderColor = activeBorderGradient;
+ m_sSpecialRenderData.inactiveBorderColor = inactiveBorderGradient;
}
} catch (std::exception& e) { Debug::log(ERR, "BorderColor rule \"{}\" failed with: {}", r.szRule, e.what()); }
} else if (r.szRule == "dimaround") {
@@ -651,8 +679,8 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
}
void CWindow::updateDynamicRules() {
- m_sSpecialRenderData.activeBorderColor = -1;
- m_sSpecialRenderData.inactiveBorderColor = -1;
+ m_sSpecialRenderData.activeBorderColor = CGradientValueData();
+ m_sSpecialRenderData.inactiveBorderColor = CGradientValueData();
m_sSpecialRenderData.alpha = 1.f;
m_sSpecialRenderData.alphaInactive = -1.f;
m_sAdditionalConfigData.forceNoBlur = false;