2022-06-25 20:28:40 +02:00
|
|
|
#include "CHyprDropShadowDecoration.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../../Compositor.hpp"
|
2024-03-03 18:39:20 +00:00
|
|
|
#include "../../config/ConfigValue.hpp"
|
2024-12-22 17:12:09 +01:00
|
|
|
#include "../pass/ShadowPassElement.hpp"
|
2022-06-25 20:28:40 +02:00
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
CHyprDropShadowDecoration::CHyprDropShadowDecoration(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow), m_pWindow(pWindow) {
|
|
|
|
|
;
|
2022-06-25 20:28:40 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
CHyprDropShadowDecoration::~CHyprDropShadowDecoration() = default;
|
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) {
|
2024-04-27 12:43:12 +01:00
|
|
|
updateWindow(m_pWindow.lock());
|
2022-06-25 20:28:40 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-12 13:01:23 +00:00
|
|
|
uint64_t CHyprDropShadowDecoration::getDecorationFlags() {
|
|
|
|
|
return DECORATION_NON_SOLID;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 15:38:16 +00:00
|
|
|
std::string CHyprDropShadowDecoration::getDisplayName() {
|
|
|
|
|
return "Drop Shadow";
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-25 20:28:40 +02:00
|
|
|
void CHyprDropShadowDecoration::damageEntire() {
|
2024-11-05 15:44:40 +00:00
|
|
|
static auto PSHADOWS = CConfigValue<Hyprlang::INT>("decoration:shadow:enabled");
|
2022-06-25 20:28:40 +02:00
|
|
|
|
2024-03-03 18:39:20 +00:00
|
|
|
if (*PSHADOWS != 1)
|
2022-06-25 20:28:40 +02:00
|
|
|
return; // disabled
|
|
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
const auto PWINDOW = m_pWindow.lock();
|
2024-03-30 18:14:26 -07:00
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
CBox shadowBox = {PWINDOW->m_vRealPosition.value().x - m_seExtents.topLeft.x, PWINDOW->m_vRealPosition.value().y - m_seExtents.topLeft.y,
|
|
|
|
|
PWINDOW->m_vRealSize.value().x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x,
|
|
|
|
|
PWINDOW->m_vRealSize.value().y + m_seExtents.topLeft.y + m_seExtents.bottomRight.y};
|
|
|
|
|
|
|
|
|
|
const auto PWORKSPACE = PWINDOW->m_pWorkspace;
|
|
|
|
|
if (PWORKSPACE && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !PWINDOW->m_bPinned)
|
2024-03-30 18:14:26 -07:00
|
|
|
shadowBox.translate(PWORKSPACE->m_vRenderOffset.value());
|
2024-04-27 12:43:12 +01:00
|
|
|
shadowBox.translate(PWINDOW->m_vFloatingOffset);
|
2024-03-30 18:14:26 -07:00
|
|
|
|
2024-11-05 15:44:40 +00:00
|
|
|
static auto PSHADOWIGNOREWINDOW = CConfigValue<Hyprlang::INT>("decoration:shadow:ignore_window");
|
2024-04-27 12:43:12 +01:00
|
|
|
const auto ROUNDING = PWINDOW->rounding();
|
2025-01-05 12:38:49 -06:00
|
|
|
const auto ROUNDINGPOWER = PWINDOW->roundingPower();
|
2024-03-30 18:14:26 -07:00
|
|
|
const auto ROUNDINGSIZE = ROUNDING - M_SQRT1_2 * ROUNDING + 1;
|
|
|
|
|
|
|
|
|
|
CRegion shadowRegion(shadowBox);
|
|
|
|
|
if (*PSHADOWIGNOREWINDOW) {
|
2024-04-27 12:43:12 +01:00
|
|
|
CBox surfaceBox = PWINDOW->getWindowMainSurfaceBox();
|
|
|
|
|
if (PWORKSPACE && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !PWINDOW->m_bPinned)
|
2024-03-30 18:14:26 -07:00
|
|
|
surfaceBox.translate(PWORKSPACE->m_vRenderOffset.value());
|
2024-04-27 12:43:12 +01:00
|
|
|
surfaceBox.translate(PWINDOW->m_vFloatingOffset);
|
2024-03-30 18:14:26 -07:00
|
|
|
surfaceBox.expand(-ROUNDINGSIZE);
|
|
|
|
|
shadowRegion.subtract(CRegion(surfaceBox));
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& m : g_pCompositor->m_vMonitors) {
|
2024-10-19 23:03:29 +01:00
|
|
|
if (!g_pHyprRenderer->shouldRenderWindow(PWINDOW, m)) {
|
2024-03-30 18:14:26 -07:00
|
|
|
const CRegion monitorRegion({m->vecPosition, m->vecSize});
|
|
|
|
|
shadowRegion.subtract(monitorRegion);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_pHyprRenderer->damageRegion(shadowRegion);
|
2022-06-25 20:28:40 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
void CHyprDropShadowDecoration::updateWindow(PHLWINDOW pWindow) {
|
|
|
|
|
const auto PWINDOW = m_pWindow.lock();
|
|
|
|
|
|
|
|
|
|
m_vLastWindowPos = PWINDOW->m_vRealPosition.value();
|
|
|
|
|
m_vLastWindowSize = PWINDOW->m_vRealSize.value();
|
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
|
|
|
}
|
|
|
|
|
|
2024-10-31 00:20:32 +01:00
|
|
|
void CHyprDropShadowDecoration::draw(PHLMONITOR pMonitor, float const& a) {
|
2024-12-22 17:12:09 +01:00
|
|
|
CShadowPassElement::SShadowData data;
|
|
|
|
|
data.deco = this;
|
|
|
|
|
data.a = a;
|
|
|
|
|
g_pHyprRenderer->m_sRenderPass.add(makeShared<CShadowPassElement>(data));
|
|
|
|
|
}
|
2022-06-25 20:28:40 +02:00
|
|
|
|
2024-12-22 17:12:09 +01:00
|
|
|
void CHyprDropShadowDecoration::render(PHLMONITOR pMonitor, float const& a) {
|
2024-04-27 12:43:12 +01:00
|
|
|
const auto PWINDOW = m_pWindow.lock();
|
|
|
|
|
|
|
|
|
|
if (!validMapped(PWINDOW))
|
2022-06-25 20:28:40 +02:00
|
|
|
return;
|
|
|
|
|
|
2024-12-03 18:58:24 +00:00
|
|
|
if (PWINDOW->m_cRealShadowColor.value() == CHyprColor(0, 0, 0, 0))
|
2022-07-18 12:39:57 +02:00
|
|
|
return; // don't draw invisible shadows
|
|
|
|
|
|
2024-07-11 14:10:42 +00:00
|
|
|
if (!PWINDOW->m_sWindowData.decorate.valueOrDefault())
|
2022-09-23 16:47:58 +01:00
|
|
|
return;
|
|
|
|
|
|
2024-07-11 14:10:42 +00:00
|
|
|
if (PWINDOW->m_sWindowData.noShadow.valueOrDefault())
|
2022-10-20 12:36:27 -07:00
|
|
|
return;
|
|
|
|
|
|
2024-11-05 15:44:40 +00:00
|
|
|
static auto PSHADOWS = CConfigValue<Hyprlang::INT>("decoration:shadow:enabled");
|
|
|
|
|
static auto PSHADOWSIZE = CConfigValue<Hyprlang::INT>("decoration:shadow:range");
|
|
|
|
|
static auto PSHADOWIGNOREWINDOW = CConfigValue<Hyprlang::INT>("decoration:shadow:ignore_window");
|
|
|
|
|
static auto PSHADOWSCALE = CConfigValue<Hyprlang::FLOAT>("decoration:shadow:scale");
|
|
|
|
|
static auto PSHADOWOFFSET = CConfigValue<Hyprlang::VEC2>("decoration:shadow:offset");
|
2022-06-25 20:28:40 +02:00
|
|
|
|
2024-03-03 18:39:20 +00:00
|
|
|
if (*PSHADOWS != 1)
|
2022-06-25 20:28:40 +02:00
|
|
|
return; // disabled
|
|
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
const auto ROUNDINGBASE = PWINDOW->rounding();
|
2025-01-05 12:38:49 -06:00
|
|
|
const auto ROUNDINGPOWER = PWINDOW->roundingPower();
|
2024-04-27 12:43:12 +01:00
|
|
|
const auto ROUNDING = ROUNDINGBASE > 0 ? ROUNDINGBASE + PWINDOW->getRealBorderSize() : 0;
|
|
|
|
|
const auto PWORKSPACE = PWINDOW->m_pWorkspace;
|
|
|
|
|
const auto WORKSPACEOFFSET = PWORKSPACE && !PWINDOW->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D();
|
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;
|
2023-11-11 16:15:11 +00:00
|
|
|
fullBox.translate(-pMonitor->vecPosition + WORKSPACEOFFSET);
|
2024-03-03 18:39:20 +00:00
|
|
|
fullBox.x -= *PSHADOWSIZE;
|
|
|
|
|
fullBox.y -= *PSHADOWSIZE;
|
|
|
|
|
fullBox.w += 2 * *PSHADOWSIZE;
|
|
|
|
|
fullBox.h += 2 * *PSHADOWSIZE;
|
2022-06-26 22:15:06 +02:00
|
|
|
|
2024-03-03 18:39:20 +00:00
|
|
|
const float SHADOWSCALE = std::clamp(*PSHADOWSCALE, 0.f, 1.f);
|
2022-11-07 22:51:26 +00:00
|
|
|
|
2022-11-07 21:23:19 +00:00
|
|
|
// scale the box in relation to the center of the box
|
2024-06-19 16:20:06 +02:00
|
|
|
fullBox.scaleFromCenter(SHADOWSCALE).translate({(*PSHADOWOFFSET).x, (*PSHADOWOFFSET).y});
|
2022-11-07 21:23:19 +00:00
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
updateWindow(PWINDOW);
|
2023-11-20 14:34:28 -08:00
|
|
|
m_vLastWindowPos += WORKSPACEOFFSET;
|
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
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
fullBox.translate(PWINDOW->m_vFloatingOffset);
|
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);
|
2024-12-22 17:12:09 +01:00
|
|
|
g_pHyprOpenGL->m_RenderData.currentWindow = m_pWindow;
|
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();
|
|
|
|
|
|
2024-03-03 18:39:20 +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
|
2023-12-10 16:28:12 +00:00
|
|
|
windowBox.translate(-pMonitor->vecPosition + WORKSPACEOFFSET);
|
|
|
|
|
withDecos.translate(-pMonitor->vecPosition + WORKSPACEOFFSET);
|
2023-11-04 17:03:05 +00:00
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
windowBox.translate(PWINDOW->m_vFloatingOffset);
|
|
|
|
|
withDecos.translate(PWINDOW->m_vFloatingOffset);
|
2024-03-30 18:14:26 -07:00
|
|
|
|
2023-12-22 19:54:18 +01:00
|
|
|
auto scaledExtentss = withDecos.extentsFrom(windowBox);
|
|
|
|
|
scaledExtentss = scaledExtentss * pMonitor->scale;
|
|
|
|
|
scaledExtentss = scaledExtentss.round();
|
2022-06-29 11:13:30 +02:00
|
|
|
|
2023-11-11 14:37:17 +00:00
|
|
|
// add extents
|
2023-12-22 19:54:18 +01:00
|
|
|
windowBox.scale(pMonitor->scale).round().addExtents(scaledExtentss);
|
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-16 11:42:53 +00:00
|
|
|
CRegion saveDamage = g_pHyprOpenGL->m_RenderData.damage;
|
|
|
|
|
|
|
|
|
|
g_pHyprOpenGL->m_RenderData.damage = fullBox;
|
2023-11-16 17:31:52 +00:00
|
|
|
g_pHyprOpenGL->m_RenderData.damage.subtract(windowBox.copy().expand(-ROUNDING * pMonitor->scale)).intersect(saveDamage);
|
2024-04-03 14:09:58 +01:00
|
|
|
g_pHyprOpenGL->m_RenderData.renderModif.applyToRegion(g_pHyprOpenGL->m_RenderData.damage);
|
2023-11-16 11:42:53 +00: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.
|
2023-11-16 11:42:53 +00:00
|
|
|
// first, clear region of interest with black (fully transparent)
|
2024-12-03 18:58:24 +00:00
|
|
|
g_pHyprOpenGL->renderRect(&fullBox, CHyprColor(0, 0, 0, 1), 0);
|
2023-11-09 22:11:42 +00:00
|
|
|
|
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)
|
2025-01-05 12:38:49 -06:00
|
|
|
drawShadowInternal(&fullBox, ROUNDING * pMonitor->scale, ROUNDINGPOWER, *PSHADOWSIZE * pMonitor->scale, CHyprColor(1, 1, 1, PWINDOW->m_cRealShadowColor.value().a), a);
|
2023-11-09 22:11:42 +00:00
|
|
|
|
|
|
|
|
// render black window box ("clip")
|
2025-01-05 12:38:49 -06:00
|
|
|
g_pHyprOpenGL->renderRect(&windowBox, CHyprColor(0, 0, 0, 1.0), (ROUNDING + 1 /* This fixes small pixel gaps. */) * pMonitor->scale, ROUNDINGPOWER);
|
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.
|
2024-04-27 12:43:12 +01:00
|
|
|
g_pHyprOpenGL->renderRect(&fullBox, PWINDOW->m_cRealShadowColor.value().stripA(), 0);
|
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};
|
2024-12-22 17:12:09 +01:00
|
|
|
|
2023-11-04 19:35:49 +00:00
|
|
|
g_pHyprOpenGL->setMonitorTransformEnabled(true);
|
2024-04-03 14:09:58 +01:00
|
|
|
g_pHyprOpenGL->setRenderModifEnabled(false);
|
2024-11-02 15:26:25 +00:00
|
|
|
g_pHyprOpenGL->renderTextureMatte(alphaSwapFB.getTexture(), &monbox, alphaFB);
|
2024-04-03 14:09:58 +01:00
|
|
|
g_pHyprOpenGL->setRenderModifEnabled(true);
|
2024-03-03 02:18:00 +00:00
|
|
|
g_pHyprOpenGL->setMonitorTransformEnabled(false);
|
2023-11-16 11:42:53 +00:00
|
|
|
|
|
|
|
|
g_pHyprOpenGL->m_RenderData.damage = saveDamage;
|
2024-11-05 15:44:40 +00:00
|
|
|
} else
|
2025-01-05 12:38:49 -06:00
|
|
|
drawShadowInternal(&fullBox, ROUNDING * pMonitor->scale, ROUNDINGPOWER, *PSHADOWSIZE * pMonitor->scale, PWINDOW->m_cRealShadowColor.value(), a);
|
2023-11-11 15:18:04 +00:00
|
|
|
|
|
|
|
|
if (m_seExtents != m_seReportedExtents)
|
|
|
|
|
g_pDecorationPositioner->repositionDeco(this);
|
2024-12-22 17:12:09 +01:00
|
|
|
|
|
|
|
|
g_pHyprOpenGL->m_RenderData.currentWindow.reset();
|
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
|
|
|
}
|
2024-11-05 15:44:40 +00:00
|
|
|
|
2025-01-05 12:38:49 -06:00
|
|
|
void CHyprDropShadowDecoration::drawShadowInternal(CBox* box, int round, float roundingPower, int range, CHyprColor color, float a) {
|
2024-11-05 15:44:40 +00:00
|
|
|
static auto PSHADOWSHARP = CConfigValue<Hyprlang::INT>("decoration:shadow:sharp");
|
|
|
|
|
|
|
|
|
|
g_pHyprOpenGL->blend(true);
|
|
|
|
|
|
|
|
|
|
color.a *= a;
|
|
|
|
|
|
|
|
|
|
if (*PSHADOWSHARP)
|
2025-01-05 12:38:49 -06:00
|
|
|
g_pHyprOpenGL->renderRect(box, color, round, roundingPower);
|
2024-11-05 15:44:40 +00:00
|
|
|
else
|
2025-01-05 12:38:49 -06:00
|
|
|
g_pHyprOpenGL->renderRoundedShadow(box, round, roundingPower, range, color, 1.F);
|
2024-11-05 15:44:40 +00:00
|
|
|
}
|