2023-12-10 16:28:12 +00:00
|
|
|
#include "CHyprBorderDecoration.hpp"
|
|
|
|
|
#include "../../Compositor.hpp"
|
2024-03-03 18:39:20 +00:00
|
|
|
#include "../../config/ConfigValue.hpp"
|
2023-12-10 16:28:12 +00:00
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
CHyprBorderDecoration::CHyprBorderDecoration(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) {
|
2023-12-10 16:28:12 +00:00
|
|
|
m_pWindow = pWindow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CHyprBorderDecoration::~CHyprBorderDecoration() {
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SDecorationPositioningInfo CHyprBorderDecoration::getPositioningInfo() {
|
2024-04-27 12:43:12 +01:00
|
|
|
const auto BORDERSIZE = m_pWindow.lock()->getRealBorderSize();
|
2023-12-10 16:28:12 +00:00
|
|
|
m_seExtents = {{BORDERSIZE, BORDERSIZE}, {BORDERSIZE, BORDERSIZE}};
|
|
|
|
|
|
|
|
|
|
if (doesntWantBorders())
|
|
|
|
|
m_seExtents = {{}, {}};
|
|
|
|
|
|
|
|
|
|
SDecorationPositioningInfo info;
|
|
|
|
|
info.priority = 10000;
|
|
|
|
|
info.policy = DECORATION_POSITION_STICKY;
|
|
|
|
|
info.desiredExtents = m_seExtents;
|
|
|
|
|
info.reserved = true;
|
|
|
|
|
info.edges = DECORATION_EDGE_BOTTOM | DECORATION_EDGE_LEFT | DECORATION_EDGE_RIGHT | DECORATION_EDGE_TOP;
|
|
|
|
|
|
|
|
|
|
m_seReportedExtents = m_seExtents;
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CHyprBorderDecoration::onPositioningReply(const SDecorationPositioningReply& reply) {
|
|
|
|
|
m_bAssignedGeometry = reply.assignedGeometry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBox CHyprBorderDecoration::assignedBoxGlobal() {
|
|
|
|
|
CBox box = m_bAssignedGeometry;
|
2024-04-27 12:43:12 +01:00
|
|
|
box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_BOTTOM | DECORATION_EDGE_LEFT | DECORATION_EDGE_RIGHT | DECORATION_EDGE_TOP, m_pWindow.lock()));
|
2023-12-10 16:28:12 +00:00
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
const auto PWORKSPACE = m_pWindow.lock()->m_pWorkspace;
|
2023-12-10 16:28:12 +00:00
|
|
|
|
|
|
|
|
if (!PWORKSPACE)
|
|
|
|
|
return box;
|
|
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow.lock()->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D();
|
2023-12-10 16:28:12 +00:00
|
|
|
return box.translate(WORKSPACEOFFSET);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-30 18:14:26 -07:00
|
|
|
void CHyprBorderDecoration::draw(CMonitor* pMonitor, float a) {
|
2023-12-10 16:28:12 +00:00
|
|
|
if (doesntWantBorders())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_bAssignedGeometry.width < m_seExtents.topLeft.x + 1 || m_bAssignedGeometry.height < m_seExtents.topLeft.y + 1)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
CBox windowBox =
|
|
|
|
|
assignedBoxGlobal().translate(-pMonitor->vecPosition + m_pWindow.lock()->m_vFloatingOffset).expand(-m_pWindow.lock()->getRealBorderSize()).scale(pMonitor->scale).round();
|
2023-12-10 19:32:03 +00:00
|
|
|
|
|
|
|
|
if (windowBox.width < 1 || windowBox.height < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
auto grad = m_pWindow.lock()->m_cRealBorderColor;
|
|
|
|
|
const bool ANIMATED = m_pWindow.lock()->m_fBorderFadeAnimationProgress.isBeingAnimated();
|
|
|
|
|
float a1 = a * (ANIMATED ? m_pWindow.lock()->m_fBorderFadeAnimationProgress.value() : 1.f);
|
2023-12-10 16:28:12 +00:00
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
if (m_pWindow.lock()->m_fBorderAngleAnimationProgress.getConfig()->pValues->internalEnabled) {
|
|
|
|
|
grad.m_fAngle += m_pWindow.lock()->m_fBorderAngleAnimationProgress.value() * M_PI * 2;
|
2023-12-10 16:28:12 +00:00
|
|
|
grad.m_fAngle = normalizeAngleRad(grad.m_fAngle);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
int borderSize = m_pWindow.lock()->getRealBorderSize();
|
|
|
|
|
const auto ROUNDING = m_pWindow.lock()->rounding() * pMonitor->scale;
|
2023-12-10 16:28:12 +00:00
|
|
|
|
|
|
|
|
g_pHyprOpenGL->renderBorder(&windowBox, grad, ROUNDING, borderSize, a1);
|
|
|
|
|
|
|
|
|
|
if (ANIMATED) {
|
2024-04-27 12:43:12 +01:00
|
|
|
float a2 = a * (1.f - m_pWindow.lock()->m_fBorderFadeAnimationProgress.value());
|
|
|
|
|
g_pHyprOpenGL->renderBorder(&windowBox, m_pWindow.lock()->m_cRealBorderColorPrevious, ROUNDING, borderSize, a2);
|
2023-12-10 16:28:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eDecorationType CHyprBorderDecoration::getDecorationType() {
|
|
|
|
|
return DECORATION_BORDER;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
void CHyprBorderDecoration::updateWindow(PHLWINDOW) {
|
|
|
|
|
if (m_pWindow.lock()->getRealBorderSize() != m_seExtents.topLeft.x)
|
2023-12-10 16:28:12 +00:00
|
|
|
g_pDecorationPositioner->repositionDeco(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CHyprBorderDecoration::damageEntire() {
|
2024-04-27 12:43:12 +01:00
|
|
|
if (!validMapped(m_pWindow))
|
2024-03-30 18:14:26 -07:00
|
|
|
return;
|
|
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
auto surfaceBox = m_pWindow.lock()->getWindowMainSurfaceBox();
|
|
|
|
|
const auto ROUNDING = m_pWindow.lock()->rounding();
|
2024-03-31 06:59:22 -07:00
|
|
|
const auto ROUNDINGSIZE = ROUNDING - M_SQRT1_2 * ROUNDING + 2;
|
2024-04-27 12:43:12 +01:00
|
|
|
const auto BORDERSIZE = m_pWindow.lock()->getRealBorderSize() + 1;
|
2024-03-30 18:14:26 -07:00
|
|
|
|
2024-04-27 12:43:12 +01:00
|
|
|
const auto PWINDOWWORKSPACE = m_pWindow.lock()->m_pWorkspace;
|
|
|
|
|
if (PWINDOWWORKSPACE && PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow.lock()->m_bPinned)
|
2024-03-30 18:14:26 -07:00
|
|
|
surfaceBox.translate(PWINDOWWORKSPACE->m_vRenderOffset.value());
|
2024-04-27 12:43:12 +01:00
|
|
|
surfaceBox.translate(m_pWindow.lock()->m_vFloatingOffset);
|
2024-03-30 18:14:26 -07:00
|
|
|
|
|
|
|
|
CBox surfaceBoxExpandedBorder = surfaceBox;
|
|
|
|
|
surfaceBoxExpandedBorder.expand(BORDERSIZE);
|
|
|
|
|
CBox surfaceBoxShrunkRounding = surfaceBox;
|
|
|
|
|
surfaceBoxShrunkRounding.expand(-ROUNDINGSIZE);
|
|
|
|
|
|
|
|
|
|
CRegion borderRegion(surfaceBoxExpandedBorder);
|
|
|
|
|
borderRegion.subtract(surfaceBoxShrunkRounding);
|
|
|
|
|
|
|
|
|
|
for (auto& m : g_pCompositor->m_vMonitors) {
|
2024-04-27 12:43:12 +01:00
|
|
|
if (!g_pHyprRenderer->shouldRenderWindow(m_pWindow.lock(), m.get())) {
|
2024-03-30 18:14:26 -07:00
|
|
|
const CRegion monitorRegion({m->vecPosition, m->vecSize});
|
|
|
|
|
borderRegion.subtract(monitorRegion);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_pHyprRenderer->damageRegion(borderRegion);
|
2023-12-10 16:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eDecorationLayer CHyprBorderDecoration::getDecorationLayer() {
|
|
|
|
|
return DECORATION_LAYER_OVER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t CHyprBorderDecoration::getDecorationFlags() {
|
2024-03-03 18:39:20 +00:00
|
|
|
static auto PPARTOFWINDOW = CConfigValue<Hyprlang::INT>("general:border_part_of_window");
|
2023-12-10 16:28:12 +00:00
|
|
|
|
2024-03-03 18:39:20 +00:00
|
|
|
return *PPARTOFWINDOW && !doesntWantBorders() ? DECORATION_PART_OF_MAIN_WINDOW : 0;
|
2023-12-10 16:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-28 15:38:16 +00:00
|
|
|
std::string CHyprBorderDecoration::getDisplayName() {
|
|
|
|
|
return "Border";
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-10 16:28:12 +00:00
|
|
|
bool CHyprBorderDecoration::doesntWantBorders() {
|
2024-04-27 12:43:12 +01:00
|
|
|
return !m_pWindow.lock()->m_sSpecialRenderData.border || m_pWindow.lock()->m_bX11DoesntWantBorders || m_pWindow.lock()->getRealBorderSize() == 0;
|
2023-12-28 15:38:16 +00:00
|
|
|
}
|