From e1edfde539557d175f8c48d94996469426da7c47 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Mon, 12 Jun 2023 00:30:31 +0700 Subject: Allow setting alpha value for ignorezero layer rule (#2477) * rename ignorezero to ignorealpha * allow setting ignorealpha value This commit allows setting a float value (0-1) for the ignorealpha layer rule. Does not yet have error handling; invalid ignorealpha layer rule will crash Hyprland. * add brackets i forgot to add * prevent crash with invalid ignorealpha value prevents hyprland from immediately crashing with invalid ignorealpha layer rule does not log * don't try to set ignoreAlphaValue if alpha value not specified * add catch to try, reintroduce ignorezero - added catch after try cuz i was an idiot - re-add ignorezero as an alternative to ignorealpha to not introduce a breaking change * add logging for failed ignorealpha layer rule * fix get ignorealpha's get VALUE * check npos and use empty() * rename VALUE cuz no longer const * format Shader.hpp --- src/helpers/WLClasses.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/helpers/WLClasses.cpp') diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 29e10a54..3a03afcd 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -8,16 +8,27 @@ SLayerSurface::SLayerSurface() { } void SLayerSurface::applyRules() { - noAnimations = false; - forceBlur = false; - ignoreZero = false; + noAnimations = false; + forceBlur = false; + ignoreAlpha = false; + ignoreAlphaValue = 0.f; for (auto& rule : g_pConfigManager->getMatchingRules(this)) { if (rule.rule == "noanim") noAnimations = true; else if (rule.rule == "blur") forceBlur = true; - else if (rule.rule == "ignorezero") - ignoreZero = true; + else if (rule.rule.find("ignorealpha") == 0 || rule.rule.find("ignorezero") == 0) { + const auto FIRST_SPACE_POS = rule.rule.find_first_of(' '); + std::string alphaValue = ""; + if (FIRST_SPACE_POS != std::string::npos) + alphaValue = rule.rule.substr(FIRST_SPACE_POS + 1); + + try { + ignoreAlpha = true; + if (!alphaValue.empty()) + ignoreAlphaValue = std::stof(alphaValue); + } catch (...) { Debug::log(ERR, "Invalid value passed to ignoreAlpha"); } + } } } \ No newline at end of file -- cgit v1.2.3