From 293d3e5de9fb18d54a5b0b7f9dbb4492207a25dd Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 30 Dec 2025 14:09:06 +0100 Subject: [PATCH] desktopAnimationMgr: fix slide direction ref https://github.com/hyprwm/Hyprland/discussions/12744 --- .../animation/DesktopAnimationManager.cpp | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/managers/animation/DesktopAnimationManager.cpp b/src/managers/animation/DesktopAnimationManager.cpp index 333df7e7..9470ec27 100644 --- a/src/managers/animation/DesktopAnimationManager.cpp +++ b/src/managers/animation/DesktopAnimationManager.cpp @@ -1,5 +1,7 @@ #include "DesktopAnimationManager.hpp" +#include + #include "../../desktop/view/LayerSurface.hpp" #include "../../desktop/view/Window.hpp" #include "../../desktop/Workspace.hpp" @@ -406,32 +408,26 @@ void CDesktopAnimationManager::animationSlide(PHLWINDOW pWindow, std::string for } const auto MIDPOINT = GOALPOS + GOALSIZE / 2.f; + const auto MONBOX = PMONITOR->logicalBox(); - // check sides it touches - const auto MONITOR_WORKAREA = PMONITOR->logicalBoxMinusReserved(); - const bool DISPLAYLEFT = STICKS(pWindow->m_position.x, MONITOR_WORKAREA.x); - const bool DISPLAYRIGHT = STICKS(pWindow->m_position.x + pWindow->m_size.x, MONITOR_WORKAREA.x + MONITOR_WORKAREA.w); - const bool DISPLAYTOP = STICKS(pWindow->m_position.y, MONITOR_WORKAREA.y); - const bool DISPLAYBOTTOM = STICKS(pWindow->m_position.y + pWindow->m_size.y, MONITOR_WORKAREA.y + MONITOR_WORKAREA.h); + // find the closest edge to midpoint + // CSS style, top right bottom left + std::array distances = { + MIDPOINT.y - MONBOX.y, // + MONBOX.x + MONBOX.w - MIDPOINT.x, // + MONBOX.y + MONBOX.h - MIDPOINT.y, // + MIDPOINT.x - MONBOX.x, // + }; - if (DISPLAYBOTTOM && DISPLAYTOP) { - if (DISPLAYLEFT && DISPLAYRIGHT) { - posOffset = GOALPOS + Vector2D(0.0, GOALSIZE.y); - } else if (DISPLAYLEFT) { - posOffset = GOALPOS - Vector2D(GOALSIZE.x, 0.0); - } else { - posOffset = GOALPOS + Vector2D(GOALSIZE.x, 0.0); - } - } else if (DISPLAYTOP) { - posOffset = GOALPOS - Vector2D(0.0, GOALSIZE.y); - } else if (DISPLAYBOTTOM) { - posOffset = GOALPOS + Vector2D(0.0, GOALSIZE.y); - } else { - if (MIDPOINT.y > PMONITOR->m_position.y + PMONITOR->m_size.y / 2.f) - posOffset = Vector2D(GOALPOS.x, PMONITOR->m_position.y + PMONITOR->m_size.y); - else - posOffset = Vector2D(GOALPOS.x, PMONITOR->m_position.y - GOALSIZE.y); - } + const auto MIN_DIST = std::min({distances[0], distances[1], distances[2], distances[3]}); + if (MIN_DIST == distances[2]) + posOffset = Vector2D(GOALPOS.x, PMONITOR->m_position.y + PMONITOR->m_size.y); + else if (MIN_DIST == distances[3]) + posOffset = GOALPOS - Vector2D(GOALSIZE.x, 0.0); + else if (MIN_DIST == distances[1]) + posOffset = GOALPOS + Vector2D(GOALSIZE.x, 0.0); + else + posOffset = Vector2D(GOALPOS.x, PMONITOR->m_position.y - GOALSIZE.y); if (!close) pWindow->m_realPosition->setValue(posOffset);