1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
#include "CHyprDropShadowDecoration.hpp"
#include "../../Compositor.hpp"
#include "../../config/ConfigValue.hpp"
#include "../pass/ShadowPassElement.hpp"
#include "../Renderer.hpp"
#include "../pass/RectPassElement.hpp"
#include "../pass/TextureMatteElement.hpp"
CHyprDropShadowDecoration::CHyprDropShadowDecoration(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow), m_window(pWindow) {
;
}
eDecorationType CHyprDropShadowDecoration::getDecorationType() {
return DECORATION_SHADOW;
}
SDecorationPositioningInfo CHyprDropShadowDecoration::getPositioningInfo() {
SDecorationPositioningInfo info;
info.policy = DECORATION_POSITION_ABSOLUTE;
info.desiredExtents = m_extents;
info.edges = DECORATION_EDGE_BOTTOM | DECORATION_EDGE_LEFT | DECORATION_EDGE_RIGHT | DECORATION_EDGE_TOP;
m_reportedExtents = m_extents;
return info;
}
void CHyprDropShadowDecoration::onPositioningReply(const SDecorationPositioningReply& reply) {
updateWindow(m_window.lock());
}
uint64_t CHyprDropShadowDecoration::getDecorationFlags() {
return DECORATION_NON_SOLID;
}
std::string CHyprDropShadowDecoration::getDisplayName() {
return "Drop Shadow";
}
void CHyprDropShadowDecoration::damageEntire() {
static auto PSHADOWS = CConfigValue<Config::INTEGER>("decoration:shadow:enabled");
if (*PSHADOWS != 1)
return; // disabled
const auto PWINDOW = m_window.lock();
const auto pos = PWINDOW->m_realPosition->value();
const auto size = PWINDOW->m_realSize->value();
CBox shadowBox = {pos.x - m_extents.topLeft.x, pos.y - m_extents.topLeft.y, pos.x + size.x + m_extents.bottomRight.x, pos.y + size.y + m_extents.bottomRight.y};
const auto PWORKSPACE = PWINDOW->m_workspace;
const auto applyOffset = [&](CBox& b) {
if (PWORKSPACE && PWORKSPACE->m_renderOffset->isBeingAnimated() && !PWINDOW->m_pinned)
b.translate(PWORKSPACE->m_renderOffset->value());
b.translate(PWINDOW->m_floatingOffset);
};
applyOffset(shadowBox);
CRegion shadowRegion(shadowBox);
for (auto const& m : g_pCompositor->m_monitors) {
if (!g_pHyprRenderer->shouldRenderWindow(PWINDOW, m)) {
const CRegion monitorRegion({m->m_position, m->m_size});
shadowRegion.subtract(monitorRegion);
}
}
g_pHyprRenderer->damageRegion(shadowRegion);
}
void CHyprDropShadowDecoration::updateWindow(PHLWINDOW pWindow) {
const auto PWINDOW = m_window.lock();
m_lastWindowPos = PWINDOW->m_realPosition->value();
m_lastWindowSize = PWINDOW->m_realSize->value();
m_lastWindowBox = {m_lastWindowPos.x, m_lastWindowPos.y, m_lastWindowSize.x, m_lastWindowSize.y};
m_lastWindowBoxWithDecos = g_pDecorationPositioner->getBoxWithIncludedDecos(pWindow);
}
void CHyprDropShadowDecoration::draw(PHLMONITOR pMonitor, float const& a) {
CShadowPassElement::SShadowData data;
data.deco = this;
data.a = a;
g_pHyprRenderer->m_renderPass.add(makeUnique<CShadowPassElement>(data));
}
bool CHyprDropShadowDecoration::canRender(PHLMONITOR pMonitor) {
static auto PSHADOWS = CConfigValue<Config::INTEGER>("decoration:shadow:enabled");
if (*PSHADOWS != 1)
return false; // disabled
const auto PWINDOW = m_window.lock();
if (!validMapped(PWINDOW))
return false;
if (PWINDOW->m_realShadowColor->value() == CHyprColor(0, 0, 0, 0))
return false; // don't draw invisible shadows
if (!PWINDOW->m_ruleApplicator->decorate().valueOrDefault())
return false;
if (PWINDOW->m_ruleApplicator->noShadow().valueOrDefault())
return false;
return true;
}
SShadowRenderData CHyprDropShadowDecoration::getRenderData(PHLMONITOR pMonitor, float const& a) {
if (!canRender(pMonitor))
return {};
const auto PWINDOW = m_window.lock();
static auto PSHADOWSIZE = CConfigValue<Config::INTEGER>("decoration:shadow:range");
static auto PSHADOWSCALE = CConfigValue<Config::FLOAT>("decoration:shadow:scale");
static auto PSHADOWOFFSET = CConfigValue<Config::VEC2>("decoration:shadow:offset");
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();
// draw the shadow
CBox fullBox = m_lastWindowBoxWithDecos;
fullBox.translate(-pMonitor->m_position + WORKSPACEOFFSET);
fullBox.x -= *PSHADOWSIZE;
fullBox.y -= *PSHADOWSIZE;
fullBox.w += 2 * *PSHADOWSIZE;
fullBox.h += 2 * *PSHADOWSIZE;
const float SHADOWSCALE = std::clamp(*PSHADOWSCALE, 0.f, 1.f);
// scale the box in relation to the center of the box
fullBox.scaleFromCenter(SHADOWSCALE).translate({(*PSHADOWOFFSET).x, (*PSHADOWOFFSET).y});
updateWindow(PWINDOW);
m_lastWindowPos += WORKSPACEOFFSET;
m_extents = {
.topLeft =
{
m_lastWindowPos.x - fullBox.x - pMonitor->m_position.x + 2,
m_lastWindowPos.y - fullBox.y - pMonitor->m_position.y + 2,
},
.bottomRight =
{
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,
},
};
fullBox.translate(PWINDOW->m_floatingOffset);
if (fullBox.width < 1 || fullBox.height < 1)
return {}; // don't draw invisible shadows
g_pHyprRenderer->m_renderData.currentWindow = m_window;
fullBox.scale(pMonitor->m_scale).round();
return {
.valid = true,
.fullBox = fullBox,
.rounding = ROUNDING,
.roundingPower = ROUNDINGPOWER,
.size = *PSHADOWSIZE,
};
}
void CHyprDropShadowDecoration::reposition() {
if (m_extents != m_reportedExtents)
g_pDecorationPositioner->repositionDeco(this);
g_pHyprRenderer->m_renderData.currentWindow.reset();
}
// TODO remove
void CHyprDropShadowDecoration::render(PHLMONITOR pMonitor, float const& a) {
auto data = getRenderData(pMonitor, a);
if (!data.valid)
return;
const auto PWINDOW = m_window.lock();
g_pHyprRenderer->disableScissor();
drawShadowInternal(data.fullBox, data.rounding * pMonitor->m_scale, data.roundingPower, data.size * pMonitor->m_scale, PWINDOW->m_realShadowColor->value(), a);
reposition();
}
eDecorationLayer CHyprDropShadowDecoration::getDecorationLayer() {
return DECORATION_LAYER_BOTTOM;
}
void CHyprDropShadowDecoration::drawShadowInternal(const CBox& box, int round, float roundingPower, int range, CHyprColor color, float a) {
static auto PSHADOWSHARP = CConfigValue<Config::INTEGER>("decoration:shadow:sharp");
if (box.w < 1 || box.h < 1)
return;
g_pHyprRenderer->blend(true);
color.a *= a;
if (*PSHADOWSHARP)
g_pHyprRenderer->draw(CRectPassElement::SRectData{
.box = box,
.color = color,
.round = round,
.roundingPower = roundingPower,
});
else
g_pHyprRenderer->drawShadow(box, round, roundingPower, range, color, 1.F);
}
|