2022-06-25 20:28:40 +02:00
|
|
|
#include "CHyprDropShadowDecoration.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../../Compositor.hpp"
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-11 15:18:04 +00:00
|
|
|
CHyprDropShadowDecoration::~CHyprDropShadowDecoration() {}
|
2022-06-25 20:28:40 +02:00
|
|
|
|
2023-11-11 14:37:17 +00:00
|
|
|
eDecorationType CHyprDropShadowDecoration::getDecorationType() {
|
|
|
|
|
return DECORATION_SHADOW;
|
|
|
|
|
}
|
2022-06-25 20:28:40 +02:00
|
|
|
|
2023-11-11 14:37:17 +00:00
|
|
|
SDecorationPositioningInfo CHyprDropShadowDecoration::getPositioningInfo() {
|
2023-11-11 15:18:04 +00:00
|
|
|
SDecorationPositioningInfo info;
|
|
|
|
|
info.policy = DECORATION_POSITION_ABSOLUTE;
|
|
|
|
|
info.desiredExtents = m_seExtents;
|
|
|
|
|
info.edges = DECORATION_EDGE_BOTTOM | DECORATION_EDGE_LEFT | DECORATION_EDGE_RIGHT | DECORATION_EDGE_TOP;
|
|
|
|
|
|
|
|
|
|
m_seReportedExtents = m_seExtents;
|
|
|
|
|
return info;
|
2022-06-25 20:28:40 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-11 14:37:17 +00:00
|
|
|
void CHyprDropShadowDecoration::onPositioningReply(const SDecorationPositioningReply& reply) {
|
|
|
|
|
updateWindow(m_pWindow);
|
2022-06-25 20:28:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CHyprDropShadowDecoration::damageEntire() {
|
2022-12-16 17:17:31 +00:00
|
|
|
static auto* const PSHADOWS = &g_pConfigManager->getConfigValuePtr("decoration:drop_shadow")->intValue;
|
2022-06-25 20:28:40 +02:00
|
|
|
|
|
|
|
|
if (*PSHADOWS != 1)
|
|
|
|
|
return; // disabled
|
|
|
|
|
|
2023-11-04 17:03:05 +00:00
|
|
|
CBox 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();
|
2022-06-27 14:07:33 +02:00
|
|
|
|
2023-11-11 14:37:17 +00:00
|
|
|
m_vLastWindowPos = pWindow->m_vRealPosition.vec() + WORKSPACEOFFSET;
|
|
|
|
|
m_vLastWindowSize = pWindow->m_vRealSize.vec();
|
2023-11-04 13:10:52 +00:00
|
|
|
|
2023-11-11 14:37:17 +00:00
|
|
|
m_bLastWindowBox = {m_vLastWindowPos.x, m_vLastWindowPos.y, m_vLastWindowSize.x, m_vLastWindowSize.y};
|
|
|
|
|
m_bLastWindowBoxWithDecos = g_pDecorationPositioner->getBoxWithIncludedDecos(pWindow);
|
2022-06-25 20:28:40 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-07 12:34:54 +01: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;
|
|
|
|
|
|
2023-08-12 21:37:55 +00:00
|
|
|
if (!m_pWindow->m_sSpecialRenderData.shadow)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-10-20 12:36:27 -07:00
|
|
|
if (m_pWindow->m_sAdditionalConfigData.forceNoShadow)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-12-16 17:17:31 +00:00
|
|
|
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
|
|
|
|
|
|
2023-11-04 13:10:52 +00:00
|
|
|
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
|
2023-11-11 14:37:17 +00:00
|
|
|
CBox fullBox = m_bLastWindowBoxWithDecos;
|
|
|
|
|
fullBox.translate(-pMonitor->vecPosition);
|
2023-11-04 17:03:05 +00:00
|
|
|
fullBox.x -= *PSHADOWSIZE;
|
|
|
|
|
fullBox.y -= *PSHADOWSIZE;
|
|
|
|
|
fullBox.w += 2 * *PSHADOWSIZE;
|
|
|
|
|
fullBox.h += 2 * *PSHADOWSIZE;
|
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
|
2023-11-04 17:03:05 +00:00
|
|
|
fullBox.scaleFromCenter(SHADOWSCALE).translate(*PSHADOWOFFSET);
|
2022-11-07 21:23:19 +00:00
|
|
|
|
2022-12-16 17:17:31 +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
|
|
|
|
2023-11-04 17:03:05 +00:00
|
|
|
fullBox.translate(offset);
|
2022-10-07 12:34:54 +01:00
|
|
|
|
2022-06-27 11:27:02 +02:00
|
|
|
if (fullBox.width < 1 || fullBox.height < 1)
|
2022-12-16 17:17:31 +00:00
|
|
|
return; // don't draw invisible shadows
|
2022-06-27 11:27:02 +02:00
|
|
|
|
2023-11-04 17:03:05 +00:00
|
|
|
g_pHyprOpenGL->scissor((CBox*)nullptr);
|
2022-08-05 19:23:53 +02:00
|
|
|
|
2023-11-04 13:10:52 +00:00
|
|
|
// we'll take the liberty of using this as it should not be used rn
|
2023-11-04 19:32:50 +00:00
|
|
|
CFramebuffer& alphaFB = g_pHyprOpenGL->m_RenderData.pCurrentMonData->mirrorFB;
|
|
|
|
|
CFramebuffer& alphaSwapFB = g_pHyprOpenGL->m_RenderData.pCurrentMonData->mirrorSwapFB;
|
|
|
|
|
auto* LASTFB = g_pHyprOpenGL->m_RenderData.currentFB;
|
2022-06-26 22:15:06 +02:00
|
|
|
|
2023-11-04 20:11:22 +00:00
|
|
|
fullBox.scale(pMonitor->scale).round();
|
|
|
|
|
|
2023-11-04 13:10:52 +00:00
|
|
|
if (*PSHADOWIGNOREWINDOW) {
|
2023-11-04 17:03:05 +00:00
|
|
|
CBox windowBox = m_bLastWindowBox;
|
2023-11-11 14:37:17 +00:00
|
|
|
CBox withDecos = m_bLastWindowBoxWithDecos;
|
|
|
|
|
|
|
|
|
|
// get window box
|
|
|
|
|
windowBox.translate(-pMonitor->vecPosition).scale(pMonitor->scale).round();
|
|
|
|
|
withDecos.translate(-pMonitor->vecPosition).scale(pMonitor->scale).round();
|
2023-11-04 17:03:05 +00:00
|
|
|
|
2023-11-11 14:37:17 +00:00
|
|
|
auto scaledDecoExtents = withDecos.extentsFrom(windowBox).round();
|
2022-06-29 11:13:30 +02:00
|
|
|
|
2023-11-11 14:37:17 +00:00
|
|
|
// add extents
|
|
|
|
|
windowBox.addExtents(scaledDecoExtents).round();
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2023-11-09 22:11:42 +00:00
|
|
|
if (windowBox.width < 1 || windowBox.height < 1)
|
2022-12-16 17:17:31 +00:00
|
|
|
return; // prevent assert failed
|
2022-08-19 14:52:18 +02:00
|
|
|
|
2023-11-04 13:10:52 +00:00
|
|
|
alphaFB.bind();
|
|
|
|
|
|
2023-11-09 22:11:42 +00:00
|
|
|
// build the matte
|
|
|
|
|
// 10-bit formats have dogshit alpha channels, so we have to use the matte to its fullest.
|
|
|
|
|
// first, clear with black (fully transparent)
|
|
|
|
|
g_pHyprOpenGL->clear(CColor(0, 0, 0, 1));
|
|
|
|
|
|
2023-11-11 00:52:40 +00:00
|
|
|
// render white shadow with the alpha of the shadow color (otherwise we clear with alpha later and shit it to 2 bit)
|
|
|
|
|
g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, CColor(1, 1, 1, m_pWindow->m_cRealShadowColor.col().a), a);
|
2023-11-09 22:11:42 +00:00
|
|
|
|
|
|
|
|
// render black window box ("clip")
|
|
|
|
|
g_pHyprOpenGL->renderRect(&windowBox, CColor(0, 0, 0, 1.0), ROUNDING * pMonitor->scale);
|
2022-06-26 22:15:06 +02:00
|
|
|
|
2023-11-04 19:32:50 +00:00
|
|
|
alphaSwapFB.bind();
|
|
|
|
|
|
2023-11-09 22:11:42 +00:00
|
|
|
// alpha swap just has the shadow color. It will be the "texture" to render.
|
2023-11-11 00:52:40 +00:00
|
|
|
g_pHyprOpenGL->clear(m_pWindow->m_cRealShadowColor.col().stripA());
|
2023-11-04 19:32:50 +00:00
|
|
|
|
2023-11-04 13:10:52 +00:00
|
|
|
LASTFB->bind();
|
2022-06-29 11:13:30 +02:00
|
|
|
|
2023-11-04 19:35:49 +00:00
|
|
|
CBox monbox = {0, 0, pMonitor->vecTransformedSize.x, pMonitor->vecTransformedSize.y};
|
|
|
|
|
g_pHyprOpenGL->setMonitorTransformEnabled(false);
|
2023-11-04 19:32:50 +00:00
|
|
|
g_pHyprOpenGL->renderTextureMatte(alphaSwapFB.m_cTex, &monbox, alphaFB);
|
2023-11-04 19:35:49 +00:00
|
|
|
g_pHyprOpenGL->setMonitorTransformEnabled(true);
|
2023-11-04 19:32:50 +00:00
|
|
|
} else {
|
|
|
|
|
g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, a);
|
|
|
|
|
}
|
2023-11-11 15:18:04 +00:00
|
|
|
|
|
|
|
|
if (m_seExtents != m_seReportedExtents)
|
|
|
|
|
g_pDecorationPositioner->repositionDeco(this);
|
2022-06-25 20:28:40 +02:00
|
|
|
}
|
2023-11-04 13:10:52 +00:00
|
|
|
|
|
|
|
|
eDecorationLayer CHyprDropShadowDecoration::getDecorationLayer() {
|
|
|
|
|
return DECORATION_LAYER_BOTTOM;
|
2023-11-11 15:18:04 +00:00
|
|
|
}
|