diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 23a10a26..888c159c 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -174,17 +174,15 @@ void IHyprLayout::onBeginDragWindow() { // get the grab corner if (m_vBeginDragXY.x < m_vBeginDragPositionXY.x + m_vBeginDragSizeXY.x / 2.0) { - // left if (m_vBeginDragXY.y < m_vBeginDragPositionXY.y + m_vBeginDragSizeXY.y / 2.0) - m_iGrabbedCorner = 0; + m_eGrabbedCorner = CORNER_TOPLEFT; else - m_iGrabbedCorner = 4; + m_eGrabbedCorner = CORNER_BOTTOMLEFT; } else { - // right if (m_vBeginDragXY.y < m_vBeginDragPositionXY.y + m_vBeginDragSizeXY.y / 2.0) - m_iGrabbedCorner = 1; + m_eGrabbedCorner = CORNER_TOPRIGHT; else - m_iGrabbedCorner = 3; + m_eGrabbedCorner = CORNER_BOTTOMRIGHT; } g_pInputManager->setCursorImageUntilUnset("grab"); @@ -258,21 +256,19 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { Vector2D newSize = m_vBeginDragSizeXY; Vector2D newPos = m_vBeginDragPositionXY; - if (m_iGrabbedCorner == 3) { - newSize = newSize + DELTA; - } else if (m_iGrabbedCorner == 0) { - newSize = newSize - DELTA; - newPos = newPos + DELTA; - } else if (m_iGrabbedCorner == 1) { - newSize = newSize + Vector2D(DELTA.x, -DELTA.y); - newPos = newPos + Vector2D(0, DELTA.y); - } else if (m_iGrabbedCorner == 4) { - newSize = newSize + Vector2D(-DELTA.x, DELTA.y); - newPos = newPos + Vector2D(DELTA.x, 0); + if (m_eGrabbedCorner == CORNER_BOTTOMRIGHT) { + newSize = (newSize + DELTA).clamp(Vector2D(20, 20), MAXSIZE); + } else if (m_eGrabbedCorner == CORNER_TOPLEFT) { + newSize = (newSize - DELTA).clamp(Vector2D(20, 20), MAXSIZE); + newPos = newPos - newSize + m_vBeginDragSizeXY; + } else if (m_eGrabbedCorner == CORNER_TOPRIGHT) { + newSize = (newSize + Vector2D(DELTA.x, -DELTA.y)).clamp(Vector2D(20, 20), MAXSIZE); + newPos = newPos + Vector2D(0, (m_vBeginDragSizeXY - newSize).y); + } else if (m_eGrabbedCorner == CORNER_BOTTOMLEFT) { + newSize = (newSize + Vector2D(-DELTA.x, DELTA.y)).clamp(Vector2D(20, 20), MAXSIZE); + newPos = newPos + Vector2D((m_vBeginDragSizeXY - newSize).x, 0); } - newSize = newSize.clamp(Vector2D(20, 20), MAXSIZE); - if (*PANIMATE) { DRAGGINGWINDOW->m_vRealSize = newSize; DRAGGINGWINDOW->m_vRealPosition = newPos; diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index 214a4927..3ee193a4 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -15,6 +15,14 @@ struct SLayoutMessageHeader { enum eFullscreenMode : uint8_t; +enum eRectCorner +{ + CORNER_TOPLEFT = 0, + CORNER_TOPRIGHT, + CORNER_BOTTOMRIGHT, + CORNER_BOTTOMLEFT +}; + interface IHyprLayout { public: virtual ~IHyprLayout() = 0; @@ -136,11 +144,11 @@ interface IHyprLayout { virtual void onWindowFocusChange(CWindow*); private: - Vector2D m_vBeginDragXY; - Vector2D m_vLastDragXY; - Vector2D m_vBeginDragPositionXY; - Vector2D m_vBeginDragSizeXY; - int m_iGrabbedCorner = 0; + Vector2D m_vBeginDragXY; + Vector2D m_vLastDragXY; + Vector2D m_vBeginDragPositionXY; + Vector2D m_vBeginDragSizeXY; + eRectCorner m_eGrabbedCorner = CORNER_TOPLEFT; - CWindow* m_pLastTiledWindow = nullptr; + CWindow* m_pLastTiledWindow = nullptr; };