decoration-positioner: improve extent handling

This commit is contained in:
Vaxry 2023-11-11 15:18:04 +00:00
parent c5d1faf72d
commit bea828ea45
6 changed files with 60 additions and 17 deletions

View file

@ -42,4 +42,8 @@ struct SWindowDecorationExtents {
SWindowDecorationExtents round() { SWindowDecorationExtents round() {
return {topLeft.round(), bottomRight.round()}; return {topLeft.round(), bottomRight.round()};
} }
bool operator==(const SWindowDecorationExtents& other) const {
return topLeft == other.topLeft && bottomRight == other.bottomRight;
}
}; };

View file

@ -668,6 +668,13 @@ void Events::listener_unmapWindow(void* owner, void* data) {
return; return;
} }
const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID);
if (PMONITOR) {
PWINDOW->m_vOriginalClosedPos = PWINDOW->m_vRealPosition.vec() - PMONITOR->vecPosition;
PWINDOW->m_vOriginalClosedSize = PWINDOW->m_vRealSize.vec();
PWINDOW->m_eOriginalClosedExtents = PWINDOW->getFullWindowExtents();
}
g_pEventManager->postEvent(SHyprIPCEvent{"closewindow", std::format("{:x}", PWINDOW)}); g_pEventManager->postEvent(SHyprIPCEvent{"closewindow", std::format("{:x}", PWINDOW)});
EMIT_HOOK_EVENT("closeWindow", PWINDOW); EMIT_HOOK_EVENT("closeWindow", PWINDOW);
@ -697,13 +704,6 @@ void Events::listener_unmapWindow(void* owner, void* data) {
if (PWINDOW->m_bIsFullscreen) if (PWINDOW->m_bIsFullscreen)
g_pCompositor->setWindowFullscreen(PWINDOW, false, FULLSCREEN_FULL); g_pCompositor->setWindowFullscreen(PWINDOW, false, FULLSCREEN_FULL);
const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID);
if (PMONITOR) {
PWINDOW->m_vOriginalClosedPos = PWINDOW->m_vRealPosition.vec() - PMONITOR->vecPosition;
PWINDOW->m_vOriginalClosedSize = PWINDOW->m_vRealSize.vec();
PWINDOW->m_eOriginalClosedExtents = PWINDOW->getFullWindowExtents();
}
// Allow the renderer to catch the last frame. // Allow the renderer to catch the last frame.
g_pHyprOpenGL->makeWindowSnapshot(PWINDOW); g_pHyprOpenGL->makeWindowSnapshot(PWINDOW);

View file

@ -6,16 +6,20 @@ CHyprDropShadowDecoration::CHyprDropShadowDecoration(CWindow* pWindow) : IHyprWi
m_pWindow = pWindow; m_pWindow = pWindow;
} }
CHyprDropShadowDecoration::~CHyprDropShadowDecoration() { CHyprDropShadowDecoration::~CHyprDropShadowDecoration() {}
updateWindow(m_pWindow);
}
eDecorationType CHyprDropShadowDecoration::getDecorationType() { eDecorationType CHyprDropShadowDecoration::getDecorationType() {
return DECORATION_SHADOW; return DECORATION_SHADOW;
} }
SDecorationPositioningInfo CHyprDropShadowDecoration::getPositioningInfo() { SDecorationPositioningInfo CHyprDropShadowDecoration::getPositioningInfo() {
return {DECORATION_POSITION_ABSOLUTE}; 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;
} }
void CHyprDropShadowDecoration::onPositioningReply(const SDecorationPositioningReply& reply) { void CHyprDropShadowDecoration::onPositioningReply(const SDecorationPositioningReply& reply) {
@ -148,8 +152,11 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D
} else { } else {
g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, a); g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, a);
} }
if (m_seExtents != m_seReportedExtents)
g_pDecorationPositioner->repositionDeco(this);
} }
eDecorationLayer CHyprDropShadowDecoration::getDecorationLayer() { eDecorationLayer CHyprDropShadowDecoration::getDecorationLayer() {
return DECORATION_LAYER_BOTTOM; return DECORATION_LAYER_BOTTOM;
} }

View file

@ -23,6 +23,7 @@ class CHyprDropShadowDecoration : public IHyprWindowDecoration {
private: private:
SWindowDecorationExtents m_seExtents; SWindowDecorationExtents m_seExtents;
SWindowDecorationExtents m_seReportedExtents;
CWindow* m_pWindow = nullptr; CWindow* m_pWindow = nullptr;

View file

@ -226,11 +226,41 @@ SWindowDecorationExtents CDecorationPositioner::getWindowDecorationReserved(CWin
} }
SWindowDecorationExtents CDecorationPositioner::getWindowDecorationExtents(CWindow* pWindow, bool inputOnly) { SWindowDecorationExtents CDecorationPositioner::getWindowDecorationExtents(CWindow* pWindow, bool inputOnly) {
if (!inputOnly) CBox accum = pWindow->getWindowMainSurfaceBox().expand(pWindow->getRealBorderSize());
return m_mWindowDatas[pWindow].extents;
// TODO: for (auto& data : m_vWindowPositioningDatas) {
return m_mWindowDatas[pWindow].extents; if (data->pWindow != pWindow)
continue;
if (!(data->pDecoration->getDecorationFlags() & DECORATION_ALLOWS_MOUSE_INPUT) && inputOnly)
continue;
CBox decoBox;
if (data->positioningInfo.policy == DECORATION_POSITION_ABSOLUTE) {
decoBox = data->pWindow->getWindowMainSurfaceBox();
decoBox.addExtents(data->positioningInfo.desiredExtents);
} else {
decoBox = data->lastReply.assignedGeometry;
const auto EDGEPOINT = getEdgeDefinedPoint(data->positioningInfo.edges, pWindow);
decoBox.translate(EDGEPOINT);
}
SWindowDecorationExtents extentsToAdd;
if (decoBox.x < accum.x)
extentsToAdd.topLeft.x = accum.x - decoBox.x;
if (decoBox.y < accum.y)
extentsToAdd.topLeft.y = accum.y - decoBox.y;
if (decoBox.x + decoBox.w > accum.x + accum.w)
extentsToAdd.bottomRight.x = (decoBox.x + decoBox.w) - (accum.x + accum.w);
if (decoBox.y + decoBox.h > accum.y + accum.h)
extentsToAdd.bottomRight.y = (decoBox.y + decoBox.h) - (accum.y + accum.h);
accum.addExtents(extentsToAdd);
}
return accum.extentsFrom(pWindow->getWindowMainSurfaceBox());
} }
CBox CDecorationPositioner::getBoxWithIncludedDecos(CWindow* pWindow) { CBox CDecorationPositioner::getBoxWithIncludedDecos(CWindow* pWindow) {

View file

@ -27,7 +27,8 @@ enum eDecorationEdges
Request the positioner to position a decoration Request the positioner to position a decoration
DECORATION_POSITION_ABSOLUTE: DECORATION_POSITION_ABSOLUTE:
- desiredExtents may contain the extents to be used when reserved is set. Edges has to have the edges used. - desiredExtents has to contain the extents. Edges has to have the edges used.
- reserved allowed
DECORATION_POSITION_STICKY: DECORATION_POSITION_STICKY:
- one edge allowed - one edge allowed
- priority allowed - priority allowed