From 4c4c9bb324b9e17bddb72c4614b451775521ee24 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 27 May 2025 01:15:11 +0800 Subject: dwindle: add better automatic window drag and drop direction detection (#9704) --- src/layout/IHyprLayout.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/layout/IHyprLayout.cpp') diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 8d32e44e..93b09c87 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -362,9 +362,33 @@ void IHyprLayout::onEndDragWindow() { } if (DRAGGINGWINDOW->m_draggingTiled) { + static auto PPRECISEMOUSE = CConfigValue("dwindle:precise_mouse_move"); DRAGGINGWINDOW->m_isFloating = false; g_pInputManager->refocus(); - changeWindowFloatingMode(DRAGGINGWINDOW); + + if (*PPRECISEMOUSE) { + eDirection direction = DIRECTION_DEFAULT; + + const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); + const PHLWINDOW pReferenceWindow = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING, DRAGGINGWINDOW); + + if (pReferenceWindow && pReferenceWindow != DRAGGINGWINDOW) { + const Vector2D draggedCenter = DRAGGINGWINDOW->m_realPosition->goal() + DRAGGINGWINDOW->m_realSize->goal() / 2.f; + const Vector2D referenceCenter = pReferenceWindow->m_realPosition->goal() + pReferenceWindow->m_realSize->goal() / 2.f; + const float xDiff = draggedCenter.x - referenceCenter.x; + const float yDiff = draggedCenter.y - referenceCenter.y; + + if (fabs(xDiff) > fabs(yDiff)) + direction = xDiff < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT; + else + direction = yDiff < 0 ? DIRECTION_UP : DIRECTION_DOWN; + } + + onWindowRemovedTiling(DRAGGINGWINDOW); + onWindowCreatedTiling(DRAGGINGWINDOW, direction); + } else + changeWindowFloatingMode(DRAGGINGWINDOW); + DRAGGINGWINDOW->m_lastFloatingSize = m_draggingWindowOriginalFloatSize; } -- cgit v1.2.3