From 47e5b41fead236026ff7630689e677e854531c41 Mon Sep 17 00:00:00 2001 From: TheOnlyMrCat Date: Thu, 11 Apr 2024 21:41:18 +1000 Subject: [PATCH] renderer: Add dimaround layer rule (#4643) --- src/config/ConfigManager.cpp | 4 ++-- src/helpers/WLClasses.cpp | 8 ++++++++ src/helpers/WLClasses.hpp | 1 + src/render/Renderer.cpp | 7 +++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 606d667b..30cbb770 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1949,8 +1949,8 @@ bool windowRuleValid(const std::string& RULE) { } bool layerRuleValid(const std::string& RULE) { - return RULE == "noanim" || RULE == "blur" || RULE == "blurpopups" || RULE.starts_with("ignorealpha") || RULE.starts_with("ignorezero") || RULE.starts_with("xray") || - RULE.starts_with("animation"); + return RULE == "noanim" || RULE == "blur" || RULE == "blurpopups" || RULE.starts_with("ignorealpha") || RULE.starts_with("ignorezero") || RULE == "dimaround" || + RULE.starts_with("xray") || RULE.starts_with("animation"); } std::optional CConfigManager::handleWindowRule(const std::string& command, const std::string& value) { diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 6135098a..2e669e4f 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -10,6 +10,11 @@ SLayerSurface::SLayerSurface() { realPosition.registerVar(); realSize.registerVar(); + alpha.setUpdateCallback([this](void*) { + if (dimAround) + g_pHyprRenderer->damageMonitor(g_pCompositor->getMonitorFromID(monitorID)); + }); + alpha.setValueAndWarp(0.f); } @@ -26,6 +31,7 @@ void SLayerSurface::applyRules() { forceBlur = false; ignoreAlpha = false; ignoreAlphaValue = 0.f; + dimAround = false; xray = -1; animationStyle.reset(); @@ -47,6 +53,8 @@ void SLayerSurface::applyRules() { if (!alphaValue.empty()) ignoreAlphaValue = std::stof(alphaValue); } catch (...) { Debug::log(ERR, "Invalid value passed to ignoreAlpha"); } + } else if (rule.rule == "dimaround") { + dimAround = true; } else if (rule.rule.starts_with("xray")) { CVarList vars{rule.rule, 0, ' '}; try { diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index bad290e6..4d47ea25 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -63,6 +63,7 @@ struct SLayerSurface { int xray = -1; bool ignoreAlpha = false; float ignoreAlphaValue = 0.f; + bool dimAround = false; std::optional animationStyle; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 3c107e01..3bcb99bb 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -660,6 +660,13 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* } void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, timespec* time, bool popups) { + static auto PDIMAROUND = CConfigValue("decoration:dim_around"); + + if (*PDIMAROUND && pLayer->dimAround && !m_bRenderingSnapshot && !popups) { + CBox monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.y}; + g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * pLayer->alpha.value())); + } + if (pLayer->fadingOut) { if (!popups) g_pHyprOpenGL->renderSnapshot(&pLayer);