Hyprland/src/render/decorations/CHyprDropShadowDecoration.cpp

174 lines
7.2 KiB
C++
Raw Normal View History

2022-06-25 20:28:40 +02:00
#include "CHyprDropShadowDecoration.hpp"
#include "../../Compositor.hpp"
decos: groupbar mouse interaction (#3102) * allow groupbar clicking modified: src/Window.cpp modified: src/Window.hpp modified: src/managers/input/InputManager.cpp modified: src/render/decorations/CHyprGroupBarDecoration.cpp modified: src/render/decorations/CHyprGroupBarDecoration.hpp * remove setting pos inside insertWindowToGroup() modified: src/Window.cpp modified: src/layout/DwindleLayout.cpp modified: src/layout/MasterLayout.cpp modified: src/managers/KeybindManager.cpp * add group window by index and group size functions modified: src/Window.cpp modified: src/Window.hpp modified: src/managers/input/InputManager.cpp * allow dragging into groupbar modified: src/Window.cpp modified: src/layout/DwindleLayout.cpp modified: src/layout/MasterLayout.cpp * allow dragging from groupbar modified: src/managers/KeybindManager.cpp * try groupbar clicking before border resize modified: src/managers/input/InputManager.cpp * block grabbing groupbar on floating (crash) remove later when crashing is fixed modified: src/managers/KeybindManager.cpp * remove redundant { } modified: src/layout/DwindleLayout.cpp modified: src/layout/MasterLayout.cpp * implement getWindowDecorationBox() modified: src/Window.cpp modified: src/Window.hpp modified: src/layout/DwindleLayout.cpp modified: src/layout/MasterLayout.cpp modified: src/managers/KeybindManager.cpp modified: src/managers/input/InputManager.cpp modified: src/render/decorations/CHyprDropShadowDecoration.cpp modified: src/render/decorations/CHyprGroupBarDecoration.cpp modified: src/render/decorations/IHyprWindowDecoration.cpp modified: src/render/decorations/IHyprWindowDecoration.hpp * fix crash when moveoutofgroup in floating windows also removes dragging from floating windows limitation modified: src/layout/IHyprLayout.cpp modified: src/managers/KeybindManager.cpp * use CRegion in getWindowDecorationBox() modified: src/helpers/Region.cpp modified: src/helpers/Region.hpp modified: src/layout/DwindleLayout.cpp modified: src/layout/MasterLayout.cpp modified: src/managers/KeybindManager.cpp modified: src/managers/input/InputManager.cpp modified: src/render/decorations/IHyprWindowDecoration.cpp modified: src/render/decorations/IHyprWindowDecoration.hpp * add groupbar scrolling modified: src/config/ConfigManager.cpp modified: src/managers/input/InputManager.cpp * change name to getWindowDecorationRegion() modified: src/layout/DwindleLayout.cpp modified: src/layout/MasterLayout.cpp modified: src/managers/KeybindManager.cpp modified: src/managers/input/InputManager.cpp modified: src/render/decorations/IHyprWindowDecoration.cpp modified: src/render/decorations/IHyprWindowDecoration.hpp * make dragging from group less hacky for floating modified: src/managers/KeybindManager.cpp
2023-08-30 15:39:22 +00:00
CHyprDropShadowDecoration::CHyprDropShadowDecoration(CWindow* pWindow) : IHyprWindowDecoration(pWindow) {
2022-06-25 20:28:40 +02:00
m_pWindow = pWindow;
}
CHyprDropShadowDecoration::~CHyprDropShadowDecoration() {
updateWindow(m_pWindow);
}
SWindowDecorationExtents CHyprDropShadowDecoration::getWindowDecorationExtents() {
static auto* const PSHADOWS = &g_pConfigManager->getConfigValuePtr("decoration:drop_shadow")->intValue;
2022-06-25 20:28:40 +02:00
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;
2022-06-25 20:28:40 +02:00
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};
2022-06-25 20:28:40 +02:00
g_pHyprRenderer->damageBox(&dm);
}
void CHyprDropShadowDecoration::updateWindow(CWindow* pWindow) {
2022-06-27 00:25:37 +02:00
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID);
2022-09-11 20:27:59 +02:00
const auto WORKSPACEOFFSET = PWORKSPACE && !pWindow->m_bPinned ? 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;
2022-06-27 00:25:37 +02:00
m_vLastWindowSize = pWindow->m_vRealSize.vec();
damageEntire();
const auto BORDER = m_pWindow->getRealBorderSize();
// calculate extents of decos with the DECORATION_PART_OF_MAIN_WINDOW flag
SWindowDecorationExtents maxExtents;
for (auto& wd : m_pWindow->m_dWindowDecorations) {
// conveniently, this will also skip us.
if (!(wd->getDecorationFlags() & DECORATION_PART_OF_MAIN_WINDOW))
continue;
const auto EXTENTS = wd->getWindowDecorationExtents();
if (maxExtents.topLeft.x < EXTENTS.topLeft.x)
maxExtents.topLeft.x = EXTENTS.topLeft.x;
if (maxExtents.topLeft.y < EXTENTS.topLeft.y)
maxExtents.topLeft.y = EXTENTS.topLeft.y;
if (maxExtents.bottomRight.x < EXTENTS.bottomRight.x)
maxExtents.bottomRight.x = EXTENTS.bottomRight.x;
if (maxExtents.bottomRight.y < EXTENTS.bottomRight.y)
maxExtents.bottomRight.y = EXTENTS.bottomRight.y;
}
m_bLastWindowBox = {(int)(m_vLastWindowPos.x - maxExtents.topLeft.x - BORDER), (int)(m_vLastWindowPos.y - maxExtents.topLeft.y - BORDER),
(int)(m_vLastWindowSize.x + maxExtents.topLeft.x + maxExtents.bottomRight.x + 2 * BORDER),
(int)(m_vLastWindowSize.y + maxExtents.topLeft.y + maxExtents.bottomRight.y + 2 * BORDER)};
2022-06-27 00:25:37 +02:00
}
2022-06-25 20:28:40 +02:00
}
void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& offset) {
2022-06-25 20:28:40 +02:00
if (!g_pCompositor->windowValidMapped(m_pWindow))
return;
2022-07-18 12:39:57 +02:00
if (m_pWindow->m_cRealShadowColor.col() == CColor(0, 0, 0, 0))
return; // don't draw invisible shadows
2022-09-23 16:47:58 +01:00
if (!m_pWindow->m_sSpecialRenderData.decorate)
return;
if (!m_pWindow->m_sSpecialRenderData.shadow)
return;
if (m_pWindow->m_sAdditionalConfigData.forceNoShadow)
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 PSHADOWIGNOREWINDOW = &g_pConfigManager->getConfigValuePtr("decoration:shadow_ignore_window")->intValue;
static auto* const PSHADOWSCALE = &g_pConfigManager->getConfigValuePtr("decoration:shadow_scale")->floatValue;
static auto* const PSHADOWOFFSET = &g_pConfigManager->getConfigValuePtr("decoration:shadow_offset")->vecValue;
2022-06-25 20:28:40 +02:00
if (*PSHADOWS != 1)
return; // disabled
const auto ROUNDING = m_pWindow->rounding() + m_pWindow->getRealBorderSize();
2022-08-19 14:52:18 +02:00
2022-06-25 20:28:40 +02:00
// draw the shadow
wlr_box fullBox = {m_bLastWindowBox.x - *PSHADOWSIZE, m_bLastWindowBox.y - *PSHADOWSIZE, m_bLastWindowBox.width + 2.0 * *PSHADOWSIZE,
m_bLastWindowBox.height + 2.0 * *PSHADOWSIZE};
2022-09-25 20:07:48 +02:00
2022-06-25 20:28:40 +02:00
fullBox.x -= pMonitor->vecPosition.x;
fullBox.y -= pMonitor->vecPosition.y;
2022-06-26 22:15:06 +02:00
2022-11-07 22:51:26 +00:00
const float SHADOWSCALE = std::clamp(*PSHADOWSCALE, 0.f, 1.f);
2022-11-07 21:23:19 +00:00
// scale the box in relation to the center of the box
const Vector2D NEWSIZE = Vector2D{fullBox.width, fullBox.height} * SHADOWSCALE;
fullBox.width = NEWSIZE.x;
fullBox.height = NEWSIZE.y;
2022-11-07 21:23:19 +00:00
if (PSHADOWOFFSET->x < 0) {
fullBox.x += PSHADOWOFFSET->x;
} else if (PSHADOWOFFSET->x > 0) {
fullBox.x = m_bLastWindowBox.x + m_bLastWindowBox.width - fullBox.width + (SHADOWSCALE * *PSHADOWSIZE) + PSHADOWOFFSET->x - pMonitor->vecPosition.x;
2022-11-07 21:23:19 +00:00
} else {
fullBox.x += ((m_bLastWindowBox.width + 2.0 * *PSHADOWSIZE) - NEWSIZE.x) / 2.0;
2022-11-07 21:23:19 +00:00
}
if (PSHADOWOFFSET->y < 0) {
fullBox.y += PSHADOWOFFSET->y;
} else if (PSHADOWOFFSET->y > 0) {
fullBox.y = m_bLastWindowBox.y + m_bLastWindowBox.height - fullBox.height + (SHADOWSCALE * *PSHADOWSIZE) + PSHADOWOFFSET->y - pMonitor->vecPosition.y;
2022-11-07 21:23:19 +00:00
} else {
fullBox.y += ((m_bLastWindowBox.height + 2.0 * *PSHADOWSIZE) - NEWSIZE.y) / 2.0;
2022-11-07 21:23:19 +00:00
}
m_seExtents = {{m_vLastWindowPos.x - fullBox.x - pMonitor->vecPosition.x + 2, m_vLastWindowPos.y - fullBox.y - pMonitor->vecPosition.y + 2},
{fullBox.x + fullBox.width + pMonitor->vecPosition.x - m_vLastWindowPos.x - m_vLastWindowSize.x + 2,
fullBox.y + fullBox.height + pMonitor->vecPosition.y - m_vLastWindowPos.y - m_vLastWindowSize.y + 2}};
2022-11-16 15:34:46 +00:00
fullBox.x += offset.x;
fullBox.y += offset.y;
2022-06-27 11:27:02 +02:00
if (fullBox.width < 1 || fullBox.height < 1)
return; // don't draw invisible shadows
2022-06-27 11:27:02 +02:00
2022-11-07 21:23:19 +00:00
g_pHyprOpenGL->scissor((wlr_box*)nullptr);
2022-08-05 19:23:53 +02:00
// we'll take the liberty of using this as it should not be used rn
CFramebuffer& alphaFB = g_pHyprOpenGL->m_RenderData.pCurrentMonData->mirrorFB;
auto* LASTFB = g_pHyprOpenGL->m_RenderData.currentFB;
2022-06-26 22:15:06 +02:00
if (*PSHADOWIGNOREWINDOW) {
wlr_box windowBox = {m_bLastWindowBox.x - pMonitor->vecPosition.x, m_bLastWindowBox.y - pMonitor->vecPosition.y, m_bLastWindowBox.width, m_bLastWindowBox.height};
2022-06-29 11:13:30 +02:00
scaleBox(&windowBox, pMonitor->scale);
2022-09-25 20:07:48 +02:00
2022-06-27 13:54:33 +02:00
if (windowBox.width < 1 || windowBox.height < 1) {
return; // prevent assert failed
2022-06-27 13:54:33 +02:00
}
2022-08-19 14:52:18 +02:00
alphaFB.bind();
g_pHyprOpenGL->clear(CColor(0, 0, 0, 0));
g_pHyprOpenGL->renderRect(&windowBox, CColor(1.0, 1.0, 1.0, 1.0), ROUNDING * pMonitor->scale);
2022-06-26 22:15:06 +02:00
LASTFB->bind();
2022-06-26 22:15:06 +02:00
}
2022-06-29 11:13:30 +02:00
scaleBox(&fullBox, pMonitor->scale);
g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, a, &alphaFB);
2022-06-25 20:28:40 +02:00
}
eDecorationLayer CHyprDropShadowDecoration::getDecorationLayer() {
return DECORATION_LAYER_BOTTOM;
}