diff options
| author | xDarksome <dev@darkso.me> | 2022-06-26 19:20:20 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-26 19:20:20 +0300 |
| commit | 504f76112aec3625f2d67f9289a48a01bc90cb50 (patch) | |
| tree | f3a4c5176a2d8f1954a7632b542f829e994c8529 /src/render/decorations/CHyprDropShadowDecoration.cpp | |
| parent | be460ea9547691eb136bf8b600b67b778af47e3f (diff) | |
| parent | f1a5cb4979f312f56967888c2b1b6d2aa535bb9e (diff) | |
Merge branch 'hyprwm:main' into main
Diffstat (limited to 'src/render/decorations/CHyprDropShadowDecoration.cpp')
| -rw-r--r-- | src/render/decorations/CHyprDropShadowDecoration.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp new file mode 100644 index 00000000..6933e687 --- /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, float a) { + + 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, a); +} |
