properly clamp size in dragging floating corners

This commit is contained in:
vaxerski 2023-02-12 22:24:47 +00:00
parent 79ad93d536
commit 6b7e409f05
2 changed files with 29 additions and 25 deletions

View file

@ -174,17 +174,15 @@ void IHyprLayout::onBeginDragWindow() {
// get the grab corner // get the grab corner
if (m_vBeginDragXY.x < m_vBeginDragPositionXY.x + m_vBeginDragSizeXY.x / 2.0) { 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) if (m_vBeginDragXY.y < m_vBeginDragPositionXY.y + m_vBeginDragSizeXY.y / 2.0)
m_iGrabbedCorner = 0; m_eGrabbedCorner = CORNER_TOPLEFT;
else else
m_iGrabbedCorner = 4; m_eGrabbedCorner = CORNER_BOTTOMLEFT;
} else { } else {
// right
if (m_vBeginDragXY.y < m_vBeginDragPositionXY.y + m_vBeginDragSizeXY.y / 2.0) if (m_vBeginDragXY.y < m_vBeginDragPositionXY.y + m_vBeginDragSizeXY.y / 2.0)
m_iGrabbedCorner = 1; m_eGrabbedCorner = CORNER_TOPRIGHT;
else else
m_iGrabbedCorner = 3; m_eGrabbedCorner = CORNER_BOTTOMRIGHT;
} }
g_pInputManager->setCursorImageUntilUnset("grab"); g_pInputManager->setCursorImageUntilUnset("grab");
@ -258,21 +256,19 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) {
Vector2D newSize = m_vBeginDragSizeXY; Vector2D newSize = m_vBeginDragSizeXY;
Vector2D newPos = m_vBeginDragPositionXY; Vector2D newPos = m_vBeginDragPositionXY;
if (m_iGrabbedCorner == 3) { if (m_eGrabbedCorner == CORNER_BOTTOMRIGHT) {
newSize = newSize + DELTA; newSize = (newSize + DELTA).clamp(Vector2D(20, 20), MAXSIZE);
} else if (m_iGrabbedCorner == 0) { } else if (m_eGrabbedCorner == CORNER_TOPLEFT) {
newSize = newSize - DELTA; newSize = (newSize - DELTA).clamp(Vector2D(20, 20), MAXSIZE);
newPos = newPos + DELTA; newPos = newPos - newSize + m_vBeginDragSizeXY;
} else if (m_iGrabbedCorner == 1) { } else if (m_eGrabbedCorner == CORNER_TOPRIGHT) {
newSize = newSize + Vector2D(DELTA.x, -DELTA.y); newSize = (newSize + Vector2D(DELTA.x, -DELTA.y)).clamp(Vector2D(20, 20), MAXSIZE);
newPos = newPos + Vector2D(0, DELTA.y); newPos = newPos + Vector2D(0, (m_vBeginDragSizeXY - newSize).y);
} else if (m_iGrabbedCorner == 4) { } else if (m_eGrabbedCorner == CORNER_BOTTOMLEFT) {
newSize = newSize + Vector2D(-DELTA.x, DELTA.y); newSize = (newSize + Vector2D(-DELTA.x, DELTA.y)).clamp(Vector2D(20, 20), MAXSIZE);
newPos = newPos + Vector2D(DELTA.x, 0); newPos = newPos + Vector2D((m_vBeginDragSizeXY - newSize).x, 0);
} }
newSize = newSize.clamp(Vector2D(20, 20), MAXSIZE);
if (*PANIMATE) { if (*PANIMATE) {
DRAGGINGWINDOW->m_vRealSize = newSize; DRAGGINGWINDOW->m_vRealSize = newSize;
DRAGGINGWINDOW->m_vRealPosition = newPos; DRAGGINGWINDOW->m_vRealPosition = newPos;

View file

@ -15,6 +15,14 @@ struct SLayoutMessageHeader {
enum eFullscreenMode : uint8_t; enum eFullscreenMode : uint8_t;
enum eRectCorner
{
CORNER_TOPLEFT = 0,
CORNER_TOPRIGHT,
CORNER_BOTTOMRIGHT,
CORNER_BOTTOMLEFT
};
interface IHyprLayout { interface IHyprLayout {
public: public:
virtual ~IHyprLayout() = 0; virtual ~IHyprLayout() = 0;
@ -140,7 +148,7 @@ interface IHyprLayout {
Vector2D m_vLastDragXY; Vector2D m_vLastDragXY;
Vector2D m_vBeginDragPositionXY; Vector2D m_vBeginDragPositionXY;
Vector2D m_vBeginDragSizeXY; Vector2D m_vBeginDragSizeXY;
int m_iGrabbedCorner = 0; eRectCorner m_eGrabbedCorner = CORNER_TOPLEFT;
CWindow* m_pLastTiledWindow = nullptr; CWindow* m_pLastTiledWindow = nullptr;
}; };