diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp index 7a836edd1..c80337f83 100644 --- a/src/events/Devices.cpp +++ b/src/events/Devices.cpp @@ -122,7 +122,7 @@ void Events::listener_destroyConstraint(void* owner, void* data) { const auto PWINDOW = g_pCompositor->getConstraintWindow(g_pCompositor->m_sSeat.mouse); - if (PWINDOW && PCONSTRAINT->positionHint != Vector2D{-1, -1}) + if (PWINDOW && PCONSTRAINT->active) g_pInputManager->warpMouseToConstraintMiddle(PCONSTRAINT); PCONSTRAINT->pMouse->currentConstraint = nullptr; diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 7b7eecbdd..dca7f1e08 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -166,6 +166,8 @@ struct SConstraint { SMouse* pMouse = nullptr; wlr_pointer_constraint_v1* constraint = nullptr; + bool active = false; + bool hintSet = false; Vector2D positionHint; // the position hint, but will be set to the current cursor pos if not set. @@ -310,8 +312,8 @@ struct SSwipeGesture { double delta = 0; int initialDirection = 0; - float avgSpeed = 0; - int speedPoints = 0; + float avgSpeed = 0; + int speedPoints = 0; CMonitor* pMonitor = nullptr; }; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 679c1bca0..bdb5c5274 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1193,6 +1193,8 @@ void CInputManager::constrainMouse(SMouse* pMouse, wlr_pointer_constraint_v1* co // warp to the constraint recheckConstraint(pMouse); + constraintFromWlr(constraint)->active = true; + wlr_pointer_constraint_v1_send_activated(pMouse->currentConstraint); pMouse->hyprListener_commitConstraint.initCallback(&pMouse->currentConstraint->surface->events.commit, &Events::listener_commitConstraint, pMouse, "Mouse constraint commit"); @@ -1212,7 +1214,8 @@ void CInputManager::warpMouseToConstraintMiddle(SConstraint* pConstraint) { if (PWINDOW) { const auto RELATIVETO = PWINDOW->m_bIsX11 ? - g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOW->m_uSurface.xwayland->x, PWINDOW->m_uSurface.xwayland->y}) / PWINDOW->m_fX11SurfaceScaledBy : + (PWINDOW->m_bIsMapped ? PWINDOW->m_vRealPosition.goalv() : + g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOW->m_uSurface.xwayland->x, PWINDOW->m_uSurface.xwayland->y})) : PWINDOW->m_vRealPosition.goalv(); const auto HINTSCALE = PWINDOW->m_fX11SurfaceScaledBy; @@ -1234,8 +1237,7 @@ void CInputManager::unconstrainMouse() { const auto PCONSTRAINT = constraintFromWlr(g_pCompositor->m_sSeat.mouse->currentConstraint); warpMouseToConstraintMiddle(PCONSTRAINT); - PCONSTRAINT->hintSet = false; - PCONSTRAINT->positionHint = {-1, -1}; + PCONSTRAINT->active = false; g_pCompositor->m_sSeat.mouse->constraintActive = false;