From 44aeb1fc909ec9cb3e6b82a5397e9eec8839192b Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 26 Jun 2022 22:15:06 +0200 Subject: added decoration:shadow_offset --- .../decorations/CHyprDropShadowDecoration.cpp | 45 ++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'src/render/decorations/CHyprDropShadowDecoration.cpp') diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 6933e687..f9c629bb 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -45,13 +45,29 @@ void CHyprDropShadowDecoration::draw(SMonitor* pMonitor, float a) { static auto *const PSHADOWS = &g_pConfigManager->getConfigValuePtr("decoration:drop_shadow")->intValue; static auto *const PSHADOWSIZE = &g_pConfigManager->getConfigValuePtr("decoration:shadow_range")->intValue; static auto *const PROUNDING = &g_pConfigManager->getConfigValuePtr("decoration:rounding")->intValue; + static auto *const PSHADOWIGNOREWINDOW = &g_pConfigManager->getConfigValuePtr("decoration:shadow_ignore_window")->intValue; + static auto *const PSHADOWOFFSET = &g_pConfigManager->getConfigValuePtr("decoration:shadow_offset")->strValue; if (*PSHADOWS != 1) return; // disabled - // update the extents if needed - if (*PSHADOWSIZE != m_seExtents.topLeft.x) - m_seExtents = {{*PSHADOWSIZE + 2, *PSHADOWSIZE + 2}, {*PSHADOWSIZE + 2, *PSHADOWSIZE + 2}}; + // get the real offset + Vector2D offset; + try { + if (const auto SPACEPOS = PSHADOWOFFSET->find(' '); SPACEPOS != std::string::npos) { + const auto X = PSHADOWOFFSET->substr(0, SPACEPOS); + const auto Y = PSHADOWOFFSET->substr(SPACEPOS + 1); + + if (isNumber(X, true) && isNumber(Y, true)) { + offset = Vector2D(std::stof(X), std::stof(Y)); + } + } + } catch (std::exception& e) { + return; // cannot parse + } + + // update the extents + m_seExtents = {{*PSHADOWSIZE + 2 - offset.x, *PSHADOWSIZE + 2 - offset.y}, {*PSHADOWSIZE + 2 + offset.x, *PSHADOWSIZE + 2 + offset.y}}; m_vLastWindowPos = m_pWindow->m_vRealPosition.vec(); m_vLastWindowSize = m_pWindow->m_vRealSize.vec(); @@ -61,6 +77,29 @@ void CHyprDropShadowDecoration::draw(SMonitor* pMonitor, float a) { fullBox.x -= pMonitor->vecPosition.x; fullBox.y -= pMonitor->vecPosition.y; + + if (*PSHADOWIGNOREWINDOW) { + glClearStencil(0); + glClear(GL_STENCIL_BUFFER_BIT); + + glEnable(GL_STENCIL_TEST); + + glStencilFunc(GL_ALWAYS, 1, -1); + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + + wlr_box windowBox = {m_vLastWindowPos.x, m_vLastWindowPos.y, m_vLastWindowSize.x, m_vLastWindowSize.y}; + g_pHyprOpenGL->renderRect(&windowBox, CColor(0,0,0,0), *PROUNDING); + + glStencilFunc(GL_NOTEQUAL, 1, -1); + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + } g_pHyprOpenGL->renderRoundedShadow(&fullBox, *PROUNDING, *PSHADOWSIZE, a); + + if (*PSHADOWIGNOREWINDOW) { + // cleanup + glClearStencil(0); + glClear(GL_STENCIL_BUFFER_BIT); + glDisable(GL_STENCIL_TEST); + } } -- cgit v1.2.3 From 0b1459ef04e99062e3f9f14e626d2ff24253f6da Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 26 Jun 2022 22:27:03 +0200 Subject: typo + fix shadow on multimon --- src/render/decorations/CHyprDropShadowDecoration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/render/decorations/CHyprDropShadowDecoration.cpp') diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index f9c629bb..01bc2170 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -87,7 +87,7 @@ void CHyprDropShadowDecoration::draw(SMonitor* pMonitor, float a) { glStencilFunc(GL_ALWAYS, 1, -1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); - wlr_box windowBox = {m_vLastWindowPos.x, m_vLastWindowPos.y, m_vLastWindowSize.x, m_vLastWindowSize.y}; + wlr_box windowBox = {m_vLastWindowPos.x - pMonitor->vecPosition.x, m_vLastWindowPos.y - pMonitor->vecPosition.y, m_vLastWindowSize.x, m_vLastWindowSize.y}; g_pHyprOpenGL->renderRect(&windowBox, CColor(0,0,0,0), *PROUNDING); glStencilFunc(GL_NOTEQUAL, 1, -1); -- cgit v1.2.3 From 3d48469cb43ac0609b112aea4e233276e04c4118 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 27 Jun 2022 00:25:37 +0200 Subject: fix decos with workspace offset --- src/render/decorations/CHyprDropShadowDecoration.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/render/decorations/CHyprDropShadowDecoration.cpp') diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 01bc2170..20dbbb30 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -35,6 +35,15 @@ void CHyprDropShadowDecoration::damageEntire() { void CHyprDropShadowDecoration::updateWindow(CWindow* pWindow) { damageEntire(); + + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + + if (pWindow->m_vRealPosition.vec() + PWORKSPACE->m_vRenderOffset.vec() != m_vLastWindowPos || pWindow->m_vRealSize.vec() != m_vLastWindowSize) { + m_vLastWindowPos = pWindow->m_vRealPosition.vec() + PWORKSPACE->m_vRenderOffset.vec(); + m_vLastWindowSize = pWindow->m_vRealSize.vec(); + + damageEntire(); + } } void CHyprDropShadowDecoration::draw(SMonitor* pMonitor, float a) { @@ -69,9 +78,6 @@ void CHyprDropShadowDecoration::draw(SMonitor* pMonitor, float a) { // update the extents m_seExtents = {{*PSHADOWSIZE + 2 - offset.x, *PSHADOWSIZE + 2 - offset.y}, {*PSHADOWSIZE + 2 + offset.x, *PSHADOWSIZE + 2 + offset.y}}; - m_vLastWindowPos = m_pWindow->m_vRealPosition.vec(); - m_vLastWindowSize = m_pWindow->m_vRealSize.vec(); - // draw the shadow wlr_box fullBox = {m_vLastWindowPos.x - m_seExtents.topLeft.x + 2, m_vLastWindowPos.y - m_seExtents.topLeft.y + 2, m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x - 4, m_vLastWindowSize.y + m_seExtents.topLeft.y + m_seExtents.bottomRight.y - 4}; -- cgit v1.2.3 From bc5fc7fad60bfd7db903b8606b8709abaf21cf1a Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 27 Jun 2022 11:27:02 +0200 Subject: guard shadow w/h --- src/render/decorations/CHyprDropShadowDecoration.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/render/decorations/CHyprDropShadowDecoration.cpp') diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 20dbbb30..7f472f5c 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -84,6 +84,9 @@ void CHyprDropShadowDecoration::draw(SMonitor* pMonitor, float a) { fullBox.x -= pMonitor->vecPosition.x; fullBox.y -= pMonitor->vecPosition.y; + if (fullBox.width < 1 || fullBox.height < 1) + return; // don't draw invisible shadows + if (*PSHADOWIGNOREWINDOW) { glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT); -- cgit v1.2.3 From 5ad8cead7cfc70cd7ca73cf60bb9703569f11927 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 27 Jun 2022 13:54:33 +0200 Subject: prevent failed assert --- src/render/decorations/CHyprDropShadowDecoration.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/render/decorations/CHyprDropShadowDecoration.cpp') diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 7f472f5c..1c11a1c9 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -97,6 +97,12 @@ void CHyprDropShadowDecoration::draw(SMonitor* pMonitor, float a) { glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); wlr_box windowBox = {m_vLastWindowPos.x - pMonitor->vecPosition.x, m_vLastWindowPos.y - pMonitor->vecPosition.y, m_vLastWindowSize.x, m_vLastWindowSize.y}; + + if (windowBox.width < 1 || windowBox.height < 1) { + glDisable(GL_STENCIL_TEST); + return; // prevent assert failed + } + g_pHyprOpenGL->renderRect(&windowBox, CColor(0,0,0,0), *PROUNDING); glStencilFunc(GL_NOTEQUAL, 1, -1); -- cgit v1.2.3 From dfe06cb060bcd71e74a47a9190de826d8ebf09be Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 27 Jun 2022 14:07:33 +0200 Subject: fix crash with decos with null workspaces --- src/render/decorations/CHyprDropShadowDecoration.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/render/decorations/CHyprDropShadowDecoration.cpp') diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 1c11a1c9..121bfa12 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -38,8 +38,10 @@ void CHyprDropShadowDecoration::updateWindow(CWindow* pWindow) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); - if (pWindow->m_vRealPosition.vec() + PWORKSPACE->m_vRenderOffset.vec() != m_vLastWindowPos || pWindow->m_vRealSize.vec() != m_vLastWindowSize) { - m_vLastWindowPos = pWindow->m_vRealPosition.vec() + PWORKSPACE->m_vRenderOffset.vec(); + const auto WORKSPACEOFFSET = PWORKSPACE ? PWORKSPACE->m_vRenderOffset.vec() : Vector2D(); + + if (pWindow->m_vRealPosition.vec() + WORKSPACEOFFSET != m_vLastWindowPos || pWindow->m_vRealSize.vec() != m_vLastWindowSize) { + m_vLastWindowPos = pWindow->m_vRealPosition.vec() + WORKSPACEOFFSET; m_vLastWindowSize = pWindow->m_vRealSize.vec(); damageEntire(); -- cgit v1.2.3 From 9388bb5d5551a2d8affa7e3adea305711029b5cd Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 29 Jun 2022 11:13:30 +0200 Subject: fix shadows on scaled --- src/render/decorations/CHyprDropShadowDecoration.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/render/decorations/CHyprDropShadowDecoration.cpp') diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 121bfa12..40051942 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -99,6 +99,8 @@ void CHyprDropShadowDecoration::draw(SMonitor* pMonitor, float a) { glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); wlr_box windowBox = {m_vLastWindowPos.x - pMonitor->vecPosition.x, m_vLastWindowPos.y - pMonitor->vecPosition.y, m_vLastWindowSize.x, m_vLastWindowSize.y}; + + scaleBox(&windowBox, pMonitor->scale); if (windowBox.width < 1 || windowBox.height < 1) { glDisable(GL_STENCIL_TEST); @@ -110,7 +112,8 @@ void CHyprDropShadowDecoration::draw(SMonitor* pMonitor, float a) { glStencilFunc(GL_NOTEQUAL, 1, -1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); } - + + scaleBox(&fullBox, pMonitor->scale); g_pHyprOpenGL->renderRoundedShadow(&fullBox, *PROUNDING, *PSHADOWSIZE, a); if (*PSHADOWIGNOREWINDOW) { -- cgit v1.2.3