From 94811485c9e50eb310d8abf19ab60ea01fc3860d Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 22 Apr 2022 14:37:38 +0200 Subject: [PATCH] added opacity rule --- src/Window.hpp | 5 +++++ src/config/ConfigManager.cpp | 1 + src/events/Windows.cpp | 6 ++++++ src/render/Renderer.cpp | 5 ++++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Window.hpp b/src/Window.hpp index 216773fb..6969213a 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -4,6 +4,9 @@ #include "events/Events.hpp" #include "helpers/SubsurfaceTree.hpp" +struct SWindowSpecialRenderData { + float alpha = 1.f; +}; class CWindow { public: @@ -76,6 +79,8 @@ public: // For hidden windows and stuff bool m_bHidden = false; + // Special render data, rules, etc + SWindowSpecialRenderData m_sSpecialRenderData; // For the list lookup bool operator==(const CWindow& rhs) { diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 01e87138..f321651c 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -259,6 +259,7 @@ void CConfigManager::handleWindowRule(const std::string& command, const std::str // verify we support a rule if (RULE != "float" && RULE != "tile" + && RULE.find("opacity") != 0 && RULE.find("move") != 0 && RULE.find("size") != 0 && RULE.find("pseudo") != 0 diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 9851a76b..4887560c 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -86,6 +86,12 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->m_bIsFloating = false; } else if (r.szRule.find("pseudo") == 0) { PWINDOW->m_bIsPseudotiled = true; + } else if (r.szRule.find("opacity") == 0) { + try { + PWINDOW->m_sSpecialRenderData.alpha = std::stof(r.szRule.substr(r.szRule.find_first_of(' ') + 1)); + } catch(std::exception& e) { + Debug::log(ERR, "Opacity rule \"%s\" failed with: %s", r.szRule.c_str(), e.what()); + } } } diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 7b8a0e40..3315034f 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -92,11 +92,14 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, SMonitor* pMonitor, timespec* renderdata.fadeAlpha = pWindow->m_fAlpha; renderdata.alpha = pWindow == g_pCompositor->m_pLastWindow ? g_pConfigManager->getFloat("decoration:active_opacity") : g_pConfigManager->getFloat("decoration:inactive_opacity"); + // apply window special data + renderdata.alpha *= pWindow->m_sSpecialRenderData.alpha; + wlr_surface_for_each_surface(g_pXWaylandManager->getWindowSurface(pWindow), renderSurface, &renderdata); // border if (decorate && !pWindow->m_bX11DoesntWantBorders) - drawBorderForWindow(pWindow, pMonitor, pWindow->m_fAlpha); + drawBorderForWindow(pWindow, pMonitor, pWindow->m_fAlpha * renderdata.alpha); if (pWindow->m_bIsX11) { if (pWindow->m_uSurface.xwayland->surface) {