From 747ff3369d6377628e3e27e3b108c8d61cbc5733 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 25 Jun 2022 20:28:40 +0200 Subject: added drop shadows --- .../decorations/CHyprDropShadowDecoration.cpp | 66 ++++++++++++++++++++++ .../decorations/CHyprDropShadowDecoration.hpp | 27 +++++++++ src/render/decorations/IHyprWindowDecoration.hpp | 3 +- 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/render/decorations/CHyprDropShadowDecoration.cpp create mode 100644 src/render/decorations/CHyprDropShadowDecoration.hpp (limited to 'src/render/decorations') diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp new file mode 100644 index 00000000..528e00cf --- /dev/null +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -0,0 +1,66 @@ +#include "CHyprDropShadowDecoration.hpp" + +#include "../../Compositor.hpp" + +CHyprDropShadowDecoration::CHyprDropShadowDecoration(CWindow* pWindow) { + m_pWindow = pWindow; +} + +CHyprDropShadowDecoration::~CHyprDropShadowDecoration() { + updateWindow(m_pWindow); +} + +SWindowDecorationExtents CHyprDropShadowDecoration::getWindowDecorationExtents() { + static auto *const PSHADOWS = &g_pConfigManager->getConfigValuePtr("decoration:drop_shadow")->intValue; + + if (*PSHADOWS != 1) + return {{}, {}}; + + return m_seExtents; +} + +eDecorationType CHyprDropShadowDecoration::getDecorationType() { + return DECORATION_SHADOW; +} + +void CHyprDropShadowDecoration::damageEntire() { + static auto *const PSHADOWS = &g_pConfigManager->getConfigValuePtr("decoration:drop_shadow")->intValue; + + if (*PSHADOWS != 1) + return; // disabled + + wlr_box dm = {m_vLastWindowPos.x - m_seExtents.topLeft.x, m_vLastWindowPos.y - m_seExtents.topLeft.y, m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x, m_vLastWindowSize.y + m_seExtents.topLeft.y + m_seExtents.bottomRight.y}; + g_pHyprRenderer->damageBox(&dm); +} + +void CHyprDropShadowDecoration::updateWindow(CWindow* pWindow) { + damageEntire(); +} + +void CHyprDropShadowDecoration::draw(SMonitor* pMonitor) { + + if (!g_pCompositor->windowValidMapped(m_pWindow)) + return; + + 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; + + 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}}; + + 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}; + + fullBox.x -= pMonitor->vecPosition.x; + fullBox.y -= pMonitor->vecPosition.y; + + g_pHyprOpenGL->renderRoundedShadow(&fullBox, *PROUNDING, *PSHADOWSIZE); +} diff --git a/src/render/decorations/CHyprDropShadowDecoration.hpp b/src/render/decorations/CHyprDropShadowDecoration.hpp new file mode 100644 index 00000000..2a248a2f --- /dev/null +++ b/src/render/decorations/CHyprDropShadowDecoration.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "IHyprWindowDecoration.hpp" + +class CHyprDropShadowDecoration : public IHyprWindowDecoration { +public: + CHyprDropShadowDecoration(CWindow*); + virtual ~CHyprDropShadowDecoration(); + + virtual SWindowDecorationExtents getWindowDecorationExtents(); + + virtual void draw(SMonitor*); + + virtual eDecorationType getDecorationType(); + + virtual void updateWindow(CWindow*); + + virtual void damageEntire(); + +private: + SWindowDecorationExtents m_seExtents; + + CWindow* m_pWindow = nullptr; + + Vector2D m_vLastWindowPos; + Vector2D m_vLastWindowSize; +}; \ No newline at end of file diff --git a/src/render/decorations/IHyprWindowDecoration.hpp b/src/render/decorations/IHyprWindowDecoration.hpp index 0815273d..e9011a29 100644 --- a/src/render/decorations/IHyprWindowDecoration.hpp +++ b/src/render/decorations/IHyprWindowDecoration.hpp @@ -4,7 +4,8 @@ enum eDecorationType { DECORATION_NONE = -1, - DECORATION_GROUPBAR + DECORATION_GROUPBAR, + DECORATION_SHADOW }; struct SWindowDecorationExtents { -- cgit v1.2.3 From 2955698f2833920c2356429c4cf7771ebf7e2d56 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 25 Jun 2022 20:31:54 +0200 Subject: fix fade with deco --- src/render/decorations/CHyprDropShadowDecoration.cpp | 4 ++-- src/render/decorations/CHyprDropShadowDecoration.hpp | 2 +- src/render/decorations/CHyprGroupBarDecoration.cpp | 3 ++- src/render/decorations/CHyprGroupBarDecoration.hpp | 2 +- src/render/decorations/IHyprWindowDecoration.hpp | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/render/decorations') diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 528e00cf..6933e687 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -37,7 +37,7 @@ void CHyprDropShadowDecoration::updateWindow(CWindow* pWindow) { damageEntire(); } -void CHyprDropShadowDecoration::draw(SMonitor* pMonitor) { +void CHyprDropShadowDecoration::draw(SMonitor* pMonitor, float a) { if (!g_pCompositor->windowValidMapped(m_pWindow)) return; @@ -62,5 +62,5 @@ void CHyprDropShadowDecoration::draw(SMonitor* pMonitor) { fullBox.x -= pMonitor->vecPosition.x; fullBox.y -= pMonitor->vecPosition.y; - g_pHyprOpenGL->renderRoundedShadow(&fullBox, *PROUNDING, *PSHADOWSIZE); + g_pHyprOpenGL->renderRoundedShadow(&fullBox, *PROUNDING, *PSHADOWSIZE, a); } diff --git a/src/render/decorations/CHyprDropShadowDecoration.hpp b/src/render/decorations/CHyprDropShadowDecoration.hpp index 2a248a2f..f734c111 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.hpp +++ b/src/render/decorations/CHyprDropShadowDecoration.hpp @@ -9,7 +9,7 @@ public: virtual SWindowDecorationExtents getWindowDecorationExtents(); - virtual void draw(SMonitor*); + virtual void draw(SMonitor*, float a); virtual eDecorationType getDecorationType(); diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index 25d74065..2bb486ee 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -68,7 +68,7 @@ void CHyprGroupBarDecoration::damageEntire() { g_pHyprRenderer->damageBox(&dm); } -void CHyprGroupBarDecoration::draw(SMonitor* pMonitor) { +void CHyprGroupBarDecoration::draw(SMonitor* pMonitor, float a) { // get how many bars we will draw int barsToDraw = m_dwGroupMembers.size(); @@ -88,6 +88,7 @@ void CHyprGroupBarDecoration::draw(SMonitor* pMonitor) { break; CColor color = m_dwGroupMembers[i] == g_pCompositor->m_pLastWindow ? CColor(g_pConfigManager->getInt("dwindle:col.group_border_active")) : CColor(g_pConfigManager->getInt("dwindle:col.group_border")); + color.a *= a; g_pHyprOpenGL->renderRect(&rect, color); xoff += PAD + BARW; diff --git a/src/render/decorations/CHyprGroupBarDecoration.hpp b/src/render/decorations/CHyprGroupBarDecoration.hpp index 74a597a6..76baab65 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.hpp +++ b/src/render/decorations/CHyprGroupBarDecoration.hpp @@ -10,7 +10,7 @@ public: virtual SWindowDecorationExtents getWindowDecorationExtents(); - virtual void draw(SMonitor*); + virtual void draw(SMonitor*, float a); virtual eDecorationType getDecorationType(); diff --git a/src/render/decorations/IHyprWindowDecoration.hpp b/src/render/decorations/IHyprWindowDecoration.hpp index e9011a29..21219b36 100644 --- a/src/render/decorations/IHyprWindowDecoration.hpp +++ b/src/render/decorations/IHyprWindowDecoration.hpp @@ -22,7 +22,7 @@ public: virtual SWindowDecorationExtents getWindowDecorationExtents() = 0; - virtual void draw(SMonitor*) = 0; + virtual void draw(SMonitor*, float a) = 0; virtual eDecorationType getDecorationType() = 0; -- cgit v1.2.3