summaryrefslogtreecommitdiff
path: root/src/managers/animation/DesktopAnimationManager.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2025-12-30 14:09:06 +0100
committerVaxry <vaxry@vaxry.net>2025-12-30 14:09:13 +0100
commit293d3e5de9fb18d54a5b0b7f9dbb4492207a25dd (patch)
tree82ae2dab404c3f3e788105bddb1475ffc1447402 /src/managers/animation/DesktopAnimationManager.cpp
parentf8464866ebacb8d17b37bab77c4ff9b1c1a34371 (diff)
desktopAnimationMgr: fix slide direction
ref https://github.com/hyprwm/Hyprland/discussions/12744
Diffstat (limited to 'src/managers/animation/DesktopAnimationManager.cpp')
-rw-r--r--src/managers/animation/DesktopAnimationManager.cpp48
1 files changed, 22 insertions, 26 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 <algorithm>
+
#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;
-
- // 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);
-
- 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 MONBOX = PMONITOR->logicalBox();
+
+ // find the closest edge to midpoint
+ // CSS style, top right bottom left
+ std::array<float, 4> distances = {
+ MIDPOINT.y - MONBOX.y, //
+ MONBOX.x + MONBOX.w - MIDPOINT.x, //
+ MONBOX.y + MONBOX.h - MIDPOINT.y, //
+ MIDPOINT.x - MONBOX.x, //
+ };
+
+ 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);