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"
|
2025-01-17 15:21:35 +00:00
|
|
|
#include "../Renderer.hpp"
|
2022-06-25 20:28:40 +02:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
CHyprDropShadowDecoration::CHyprDropShadowDecoration(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow), m_window(pWindow) {
|
2024-12-07 18:51:18 +01:00
|
|
|
;
|
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;
|
2025-05-05 23:44:49 +02:00
|
|
|
info.desiredExtents = m_extents;
|
2023-11-11 15:18:04 +00:00
|
|
|
info.edges = DECORATION_EDGE_BOTTOM | DECORATION_EDGE_LEFT | DECORATION_EDGE_RIGHT | DECORATION_EDGE_TOP;
|
|
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
m_reportedExtents = m_extents;
|
2023-11-11 15:18:04 +00:00
|
|
|
return info;
|
2022-06-25 20:28:40 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-11 14:37:17 +00:00
|
|
|
void CHyprDropShadowDecoration::onPositioningReply(const SDecorationPositioningReply& reply) {
|
2025-05-05 23:44:49 +02:00
|
|
|
updateWindow(m_window.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
|
|
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
const auto PWINDOW = m_window.lock();
|
2024-03-30 18:14:26 -07:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
CBox shadowBox = {PWINDOW->m_realPosition->value().x - m_extents.topLeft.x, PWINDOW->m_realPosition->value().y - m_extents.topLeft.y,
|
|
|
|
|
PWINDOW->m_realSize->value().x + m_extents.topLeft.x + m_extents.bottomRight.x,
|
|
|
|
|
PWINDOW->m_realSize->value().y + m_extents.topLeft.y + m_extents.bottomRight.y};
|
2024-04-27 12:43:12 +01:00
|
|
|
|
2025-04-28 22:25:22 +02:00
|
|
|
const auto PWORKSPACE = PWINDOW->m_workspace;
|
|
|
|
|
if (PWORKSPACE && PWORKSPACE->m_renderOffset->isBeingAnimated() && !PWINDOW->m_pinned)
|
2025-04-25 02:37:12 +02:00
|
|
|
shadowBox.translate(PWORKSPACE->m_renderOffset->value());
|
2025-04-28 22:25:22 +02:00
|
|
|
shadowBox.translate(PWINDOW->m_floatingOffset);
|
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();
|
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();
|
2025-04-28 22:25:22 +02:00
|
|
|
if (PWORKSPACE && PWORKSPACE->m_renderOffset->isBeingAnimated() && !PWINDOW->m_pinned)
|
2025-04-25 02:37:12 +02:00
|
|
|
surfaceBox.translate(PWORKSPACE->m_renderOffset->value());
|
2025-04-28 22:25:22 +02:00
|
|
|
surfaceBox.translate(PWINDOW->m_floatingOffset);
|
2024-03-30 18:14:26 -07:00
|
|
|
surfaceBox.expand(-ROUNDINGSIZE);
|
|
|
|
|
shadowRegion.subtract(CRegion(surfaceBox));
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 15:23:29 +02:00
|
|
|
for (auto const& m : g_pCompositor->m_monitors) {
|
2024-10-19 23:03:29 +01:00
|
|
|
if (!g_pHyprRenderer->shouldRenderWindow(PWINDOW, m)) {
|
2025-04-30 23:45:20 +02:00
|
|
|
const CRegion monitorRegion({m->m_position, m->m_size});
|
2024-03-30 18:14:26 -07:00
|
|
|
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) {
|
2025-05-05 23:44:49 +02:00
|
|
|
const auto PWINDOW = m_window.lock();
|
2024-04-27 12:43:12 +01:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
m_lastWindowPos = PWINDOW->m_realPosition->value();
|
|
|
|
|
m_lastWindowSize = PWINDOW->m_realSize->value();
|
2023-11-04 13:10:52 +00:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
m_lastWindowBox = {m_lastWindowPos.x, m_lastWindowPos.y, m_lastWindowSize.x, m_lastWindowSize.y};
|
|
|
|
|
m_lastWindowBoxWithDecos = 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;
|
2025-07-10 10:44:59 +02:00
|
|
|
g_pHyprRenderer->m_renderPass.add(makeUnique<CShadowPassElement>(data));
|
2024-12-22 17:12:09 +01:00
|
|
|
}
|
2022-06-25 20:28:40 +02:00
|
|
|
|
2024-12-22 17:12:09 +01:00
|
|
|
void CHyprDropShadowDecoration::render(PHLMONITOR pMonitor, float const& a) {
|
2025-05-05 23:44:49 +02:00
|
|
|
const auto PWINDOW = m_window.lock();
|
2024-04-27 12:43:12 +01:00
|
|
|
|
|
|
|
|
if (!validMapped(PWINDOW))
|
2022-06-25 20:28:40 +02:00
|
|
|
return;
|
|
|
|
|
|
2025-04-28 22:25:22 +02:00
|
|
|
if (PWINDOW->m_realShadowColor->value() == CHyprColor(0, 0, 0, 0))
|
2022-07-18 12:39:57 +02:00
|
|
|
return; // don't draw invisible shadows
|
|
|
|
|
|
2025-04-28 22:25:22 +02:00
|
|
|
if (!PWINDOW->m_windowData.decorate.valueOrDefault())
|
2022-09-23 16:47:58 +01:00
|
|
|
return;
|
|
|
|
|
|
2025-04-28 22:25:22 +02:00
|
|
|
if (PWINDOW->m_windowData.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
|
|
|
|
|
|
2025-09-19 00:34:54 +02:00
|
|
|
const auto BORDERSIZE = PWINDOW->getRealBorderSize();
|
|
|
|
|
const auto ROUNDINGBASE = PWINDOW->rounding();
|
|
|
|
|
const auto ROUNDINGPOWER = PWINDOW->roundingPower();
|
|
|
|
|
const auto CORRECTIONOFFSET = (BORDERSIZE * (M_SQRT2 - 1) * std::max(2.0 - ROUNDINGPOWER, 0.0));
|
|
|
|
|
const auto ROUNDING = ROUNDINGBASE > 0 ? (ROUNDINGBASE + BORDERSIZE) - CORRECTIONOFFSET : 0;
|
|
|
|
|
const auto PWORKSPACE = PWINDOW->m_workspace;
|
|
|
|
|
const auto WORKSPACEOFFSET = PWORKSPACE && !PWINDOW->m_pinned ? PWORKSPACE->m_renderOffset->value() : Vector2D();
|
2022-08-19 14:52:18 +02:00
|
|
|
|
2022-06-25 20:28:40 +02:00
|
|
|
// draw the shadow
|
2025-05-05 23:44:49 +02:00
|
|
|
CBox fullBox = m_lastWindowBoxWithDecos;
|
2025-04-30 23:45:20 +02:00
|
|
|
fullBox.translate(-pMonitor->m_position + 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);
|
2025-05-05 23:44:49 +02:00
|
|
|
m_lastWindowPos += WORKSPACEOFFSET;
|
|
|
|
|
m_extents = {{m_lastWindowPos.x - fullBox.x - pMonitor->m_position.x + 2, m_lastWindowPos.y - fullBox.y - pMonitor->m_position.y + 2},
|
|
|
|
|
{fullBox.x + fullBox.width + pMonitor->m_position.x - m_lastWindowPos.x - m_lastWindowSize.x + 2,
|
|
|
|
|
fullBox.y + fullBox.height + pMonitor->m_position.y - m_lastWindowPos.y - m_lastWindowSize.y + 2}};
|
2022-11-16 15:34:46 +00:00
|
|
|
|
2025-04-28 22:25:22 +02:00
|
|
|
fullBox.translate(PWINDOW->m_floatingOffset);
|
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
|
|
|
|
2025-01-26 15:05:34 +00:00
|
|
|
g_pHyprOpenGL->scissor(nullptr);
|
2025-05-05 23:44:49 +02:00
|
|
|
g_pHyprOpenGL->m_renderData.currentWindow = m_window;
|
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
|
2025-05-05 23:44:49 +02: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
|
|
|
|
2025-04-30 23:45:20 +02:00
|
|
|
fullBox.scale(pMonitor->m_scale).round();
|
2023-11-04 20:11:22 +00:00
|
|
|
|
2024-03-03 18:39:20 +00:00
|
|
|
if (*PSHADOWIGNOREWINDOW) {
|
2025-05-05 23:44:49 +02:00
|
|
|
CBox windowBox = m_lastWindowBox;
|
|
|
|
|
CBox withDecos = m_lastWindowBoxWithDecos;
|
2023-11-11 14:37:17 +00:00
|
|
|
|
|
|
|
|
// get window box
|
2025-04-30 23:45:20 +02:00
|
|
|
windowBox.translate(-pMonitor->m_position + WORKSPACEOFFSET);
|
|
|
|
|
withDecos.translate(-pMonitor->m_position + WORKSPACEOFFSET);
|
2023-11-04 17:03:05 +00:00
|
|
|
|
2025-04-28 22:25:22 +02:00
|
|
|
windowBox.translate(PWINDOW->m_floatingOffset);
|
|
|
|
|
withDecos.translate(PWINDOW->m_floatingOffset);
|
2024-03-30 18:14:26 -07:00
|
|
|
|
2023-12-22 19:54:18 +01:00
|
|
|
auto scaledExtentss = withDecos.extentsFrom(windowBox);
|
2025-04-30 23:45:20 +02:00
|
|
|
scaledExtentss = scaledExtentss * pMonitor->m_scale;
|
2023-12-22 19:54:18 +01:00
|
|
|
scaledExtentss = scaledExtentss.round();
|
2022-06-29 11:13:30 +02:00
|
|
|
|
2023-11-11 14:37:17 +00:00
|
|
|
// add extents
|
2025-04-30 23:45:20 +02:00
|
|
|
windowBox.scale(pMonitor->m_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
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
CRegion saveDamage = g_pHyprOpenGL->m_renderData.damage;
|
2023-11-16 11:42:53 +00:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
g_pHyprOpenGL->m_renderData.damage = fullBox;
|
|
|
|
|
g_pHyprOpenGL->m_renderData.damage.subtract(windowBox.copy().expand(-ROUNDING * pMonitor->m_scale)).intersect(saveDamage);
|
|
|
|
|
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)
|
2025-07-31 16:23:09 +02:00
|
|
|
g_pHyprOpenGL->renderRect(fullBox, CHyprColor(0, 0, 0, 1), {.round = 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-04-30 23:45:20 +02:00
|
|
|
drawShadowInternal(fullBox, ROUNDING * pMonitor->m_scale, ROUNDINGPOWER, *PSHADOWSIZE * pMonitor->m_scale, CHyprColor(1, 1, 1, PWINDOW->m_realShadowColor->value().a), a);
|
2023-11-09 22:11:42 +00:00
|
|
|
|
|
|
|
|
// render black window box ("clip")
|
2025-07-31 16:23:09 +02:00
|
|
|
g_pHyprOpenGL->renderRect(windowBox, CHyprColor(0, 0, 0, 1.0),
|
|
|
|
|
{.round = (ROUNDING + 1 /* This fixes small pixel gaps. */) * pMonitor->m_scale, .roundingPower = 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.
|
2025-07-31 16:23:09 +02:00
|
|
|
g_pHyprOpenGL->renderRect(fullBox, PWINDOW->m_realShadowColor->value().stripA(), {.round = 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
|
|
|
|
2025-04-30 23:45:20 +02:00
|
|
|
CBox monbox = {0, 0, pMonitor->m_transformedSize.x, pMonitor->m_transformedSize.y};
|
2024-12-22 17:12:09 +01:00
|
|
|
|
2025-06-15 12:11:28 +02:00
|
|
|
g_pHyprOpenGL->pushMonitorTransformEnabled(true);
|
2024-04-03 14:09:58 +01:00
|
|
|
g_pHyprOpenGL->setRenderModifEnabled(false);
|
2025-01-26 15:05:34 +00:00
|
|
|
g_pHyprOpenGL->renderTextureMatte(alphaSwapFB.getTexture(), monbox, alphaFB);
|
2024-04-03 14:09:58 +01:00
|
|
|
g_pHyprOpenGL->setRenderModifEnabled(true);
|
2025-06-15 12:11:28 +02:00
|
|
|
g_pHyprOpenGL->popMonitorTransformEnabled();
|
2023-11-16 11:42:53 +00:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
g_pHyprOpenGL->m_renderData.damage = saveDamage;
|
2024-11-05 15:44:40 +00:00
|
|
|
} else
|
2025-04-30 23:45:20 +02:00
|
|
|
drawShadowInternal(fullBox, ROUNDING * pMonitor->m_scale, ROUNDINGPOWER, *PSHADOWSIZE * pMonitor->m_scale, PWINDOW->m_realShadowColor->value(), a);
|
2023-11-11 15:18:04 +00:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
if (m_extents != m_reportedExtents)
|
2023-11-11 15:18:04 +00:00
|
|
|
g_pDecorationPositioner->repositionDeco(this);
|
2024-12-22 17:12:09 +01:00
|
|
|
|
2025-05-05 23:44:49 +02: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-26 15:05:34 +00:00
|
|
|
void CHyprDropShadowDecoration::drawShadowInternal(const 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");
|
|
|
|
|
|
2025-01-26 15:15:54 +00:00
|
|
|
if (box.w < 1 || box.h < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-11-05 15:44:40 +00:00
|
|
|
g_pHyprOpenGL->blend(true);
|
|
|
|
|
|
|
|
|
|
color.a *= a;
|
|
|
|
|
|
|
|
|
|
if (*PSHADOWSHARP)
|
2025-07-31 16:23:09 +02:00
|
|
|
g_pHyprOpenGL->renderRect(box, color, {.round = round, .roundingPower = 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
|
|
|
}
|