From e8b99ae13a0525f9fbd6899fe39fe723879f86b9 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 11 Dec 2022 17:15:02 +0000 Subject: [PATCH] add override to opacity rules --- src/Compositor.cpp | 18 +++++------------- src/Window.cpp | 23 ++++++++++++++++------- src/Window.hpp | 2 ++ src/config/ConfigManager.hpp | 2 +- src/render/Renderer.cpp | 6 ------ 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index c0fec3ad..942da2ee 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1458,22 +1458,14 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) { // opacity - if (pWindow->m_bIsFullscreen) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); - - if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) - pWindow->m_fActiveInactiveAlpha = *PFULLSCREENALPHA; - else { - if (pWindow == m_pLastWindow) - pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alpha * *PACTIVEALPHA; - else - pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alphaInactive != -1 ? pWindow->m_sSpecialRenderData.alphaInactive * *PINACTIVEALPHA : *PINACTIVEALPHA; - } + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + if (pWindow->m_bIsFullscreen && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) { + pWindow->m_fActiveInactiveAlpha = *PFULLSCREENALPHA; } else { if (pWindow == m_pLastWindow) - pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alpha * *PACTIVEALPHA; + pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alphaOverride ? pWindow->m_sSpecialRenderData.alpha : pWindow->m_sSpecialRenderData.alpha * *PACTIVEALPHA; else - pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alphaInactive != -1 ? pWindow->m_sSpecialRenderData.alphaInactive * *PINACTIVEALPHA : *PINACTIVEALPHA; + pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alphaInactive != -1 ? (pWindow->m_sSpecialRenderData.alphaInactiveOverride ? pWindow->m_sSpecialRenderData.alphaInactive : pWindow->m_sSpecialRenderData.alphaInactive * *PINACTIVEALPHA) : *PINACTIVEALPHA; } // dim diff --git a/src/Window.cpp b/src/Window.cpp index 274c3d57..61711415 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -328,14 +328,23 @@ void CWindow::applyDynamicRule(const SWindowRule& r) { } } else if (r.szRule.find("opacity") == 0) { try { - std::string alphaPart = removeBeginEndSpacesTabs(r.szRule.substr(r.szRule.find_first_of(' ') + 1)); + CVarList vars(r.szRule, 0, ' '); - if (alphaPart.contains(' ')) { - // we have a space, 2 values - m_sSpecialRenderData.alpha = std::stof(alphaPart.substr(0, alphaPart.find_first_of(' '))); - m_sSpecialRenderData.alphaInactive = std::stof(alphaPart.substr(alphaPart.find_first_of(' ') + 1)); - } else { - m_sSpecialRenderData.alpha = std::stof(alphaPart); + for (size_t i = 1 /* first item is "opacity" */; i < vars.size(); ++i) { + if (i == 1) { + // first arg, alpha + m_sSpecialRenderData.alpha = std::stof(vars[i]); + } else { + if (vars[i] == "override") { + if (i == 2) { + m_sSpecialRenderData.alphaOverride = true; + } else { + m_sSpecialRenderData.alphaInactiveOverride = true; + } + } else { + m_sSpecialRenderData.alphaInactive = std::stof(vars[i]); + } + } } } catch(std::exception& e) { Debug::log(ERR, "Opacity rule \"%s\" failed with: %s", r.szRule.c_str(), e.what()); diff --git a/src/Window.hpp b/src/Window.hpp index a7c6657c..2d76d12d 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -16,7 +16,9 @@ enum eIdleInhibitMode { }; struct SWindowSpecialRenderData { + bool alphaOverride = false; float alpha = 1.f; + bool alphaInactiveOverride = false; float alphaInactive = -1.f; // -1 means unset int64_t activeBorderColor = -1; // -1 means unset diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 298745cc..432ea084 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -95,7 +95,7 @@ public: ~CVarList() = default; - int size() const { + size_t size() const { return m_vArgs.size(); } diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 8307108c..9c8354ec 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -255,12 +255,6 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* renderdata.fadeAlpha = 255.f; } - // apply window special data - if (pWindow->m_sSpecialRenderData.alphaInactive == -1) - renderdata.alpha *= pWindow->m_sSpecialRenderData.alpha; - else - renderdata.alpha *= pWindow == g_pCompositor->m_pLastWindow ? pWindow->m_sSpecialRenderData.alpha : pWindow->m_sSpecialRenderData.alphaInactive; - // apply opaque if (pWindow->m_sAdditionalConfigData.forceOpaque) renderdata.alpha = 1.f;