Skip to content

Commit

Permalink
renderer: Add dimaround layer rule
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOnlyMrCat committed Feb 8, 2024
1 parent a6ccd36 commit 5288808
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ bool windowRuleValid(const std::string& RULE) {
}

bool layerRuleValid(const std::string& RULE) {
return RULE == "noanim" || RULE == "blur" || RULE.starts_with("ignorealpha") || RULE.starts_with("ignorezero") || RULE.starts_with("xray");
return RULE == "noanim" || RULE == "blur" || RULE.starts_with("ignorealpha") || RULE.starts_with("ignorezero") || RULE == "dimaround" || RULE.starts_with("xray");
}

void CConfigManager::handleWindowRule(const std::string& command, const std::string& value) {
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/WLClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void SLayerSurface::applyRules() {
forceBlur = false;
ignoreAlpha = false;
ignoreAlphaValue = 0.f;
dimAround = false;
xray = -1;

for (auto& rule : g_pConfigManager->getMatchingRules(this)) {
Expand All @@ -39,6 +40,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 {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/WLClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct SLayerSurface {
int xray = -1;
bool ignoreAlpha = false;
float ignoreAlphaValue = 0.f;
bool dimAround = false;

// For the list lookup
bool operator==(const SLayerSurface& rhs) const {
Expand Down
11 changes: 9 additions & 2 deletions src/render/OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,9 +1772,11 @@ void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) {

void CHyprOpenGLImpl::renderSnapshot(SLayerSurface** pLayer) {
RASSERT(m_RenderData.pMonitor, "Tried to render snapshot rect without begin()!");
const auto PLAYER = *pLayer;
const auto PLAYER = *pLayer;

auto it = m_mLayerFramebuffers.begin();
static auto* const PDIMAROUND = &g_pConfigManager->getConfigValuePtr("decoration:dim_around")->floatValue;

auto it = m_mLayerFramebuffers.begin();
for (; it != m_mLayerFramebuffers.end(); it++) {
if (it->first == PLAYER) {
break;
Expand All @@ -1790,6 +1792,11 @@ void CHyprOpenGLImpl::renderSnapshot(SLayerSurface** pLayer) {

CRegion fakeDamage{0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y};

if (*PDIMAROUND && (*pLayer)->dimAround) {
g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * PLAYER->alpha.fl()));
g_pHyprRenderer->damageMonitor(PMONITOR);
}

m_bEndFrame = true;

renderTextureInternalWithDamage(it->second.m_cTex, &monbox, PLAYER->alpha.fl(), &fakeDamage, 0);
Expand Down
9 changes: 8 additions & 1 deletion src/render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,9 @@ void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, times

TRACY_GPU_ZONE("RenderLayer");

SRenderData renderdata = {pMonitor, time, pLayer->geometry.x, pLayer->geometry.y};
static auto* const PDIMAROUND = &g_pConfigManager->getConfigValuePtr("decoration:dim_around")->floatValue;

SRenderData renderdata = {pMonitor, time, pLayer->geometry.x, pLayer->geometry.y};
renderdata.fadeAlpha = pLayer->alpha.fl();
renderdata.blur = pLayer->forceBlur;
renderdata.surface = pLayer->layerSurface->surface;
Expand All @@ -617,6 +619,11 @@ void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, times

g_pHyprOpenGL->m_pCurrentLayer = pLayer;

if (*PDIMAROUND && pLayer->dimAround && !m_bRenderingSnapshot) {
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 * renderdata.alpha * renderdata.fadeAlpha));
}

if (pLayer->ignoreAlpha) {
g_pHyprOpenGL->m_RenderData.discardMode |= DISCARD_ALPHA;
g_pHyprOpenGL->m_RenderData.discardOpacity = pLayer->ignoreAlphaValue;
Expand Down

0 comments on commit 5288808

Please sign in to comment.