diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp index 4b8eeea85..7a836edd1 100644 --- a/src/events/Devices.cpp +++ b/src/events/Devices.cpp @@ -122,19 +122,8 @@ 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->m_bIsX11) { - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, PCONSTRAINT->positionHint.x + PWINDOW->m_uSurface.xwayland->x, - PWINDOW->m_uSurface.xwayland->y + PCONSTRAINT->positionHint.y); - - wlr_seat_pointer_warp(PCONSTRAINT->constraint->seat, PCONSTRAINT->positionHint.x, PCONSTRAINT->positionHint.y); - } else { - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, PCONSTRAINT->positionHint.x + PWINDOW->m_vRealPosition.vec().x, - PCONSTRAINT->positionHint.y + PWINDOW->m_vRealPosition.vec().y); - - wlr_seat_pointer_warp(PCONSTRAINT->constraint->seat, PCONSTRAINT->positionHint.x, PCONSTRAINT->positionHint.y); - } - } + if (PWINDOW && PCONSTRAINT->positionHint != Vector2D{-1, -1}) + g_pInputManager->warpMouseToConstraintMiddle(PCONSTRAINT); PCONSTRAINT->pMouse->currentConstraint = nullptr; } diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index c4490f3cb..bda2e5ee3 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1177,31 +1177,8 @@ void CInputManager::constrainMouse(SMouse* pMouse, wlr_pointer_constraint_v1* co pMouse->hyprListener_commitConstraint.removeCallback(); if (pMouse->currentConstraint) { - if (!constraint) { - // warpe to hint - - if (constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) { - if (PWINDOW) { - if (PWINDOW->m_bIsX11) { - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, constraint->current.cursor_hint.x + PWINDOW->m_uSurface.xwayland->x, - constraint->current.cursor_hint.y + PWINDOW->m_uSurface.xwayland->y); - - wlr_seat_pointer_warp(constraint->seat, constraint->current.cursor_hint.x, constraint->current.cursor_hint.y); - } else { - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, constraint->current.cursor_hint.x + PWINDOW->m_vRealPosition.vec().x, - constraint->current.cursor_hint.y + PWINDOW->m_vRealPosition.vec().y); - - wlr_seat_pointer_warp(constraint->seat, constraint->current.cursor_hint.x, constraint->current.cursor_hint.y); - } - } - - const auto PCONSTRAINT = constraintFromWlr(constraint); - if (PCONSTRAINT) { // should never be null but who knows - PCONSTRAINT->positionHint = Vector2D(constraint->current.cursor_hint.x, constraint->current.cursor_hint.y); - PCONSTRAINT->hintSet = true; - } - } - } + if (constraint && constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) + warpMouseToConstraintMiddle(constraintFromWlr(constraint)); wlr_pointer_constraint_v1_send_deactivated(pMouse->currentConstraint); } @@ -1224,6 +1201,27 @@ void CInputManager::constrainMouse(SMouse* pMouse, wlr_pointer_constraint_v1* co Debug::log(LOG, "Constrained mouse to %lx", pMouse->currentConstraint); } +void CInputManager::warpMouseToConstraintMiddle(SConstraint* pConstraint) { + + if (!pConstraint) + return; + + pConstraint->positionHint = Vector2D(pConstraint->constraint->current.cursor_hint.x, pConstraint->constraint->current.cursor_hint.y); + pConstraint->hintSet = true; + + const auto PWINDOW = g_pCompositor->getWindowFromSurface(pConstraint->constraint->surface); + + 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_vRealPosition.goalv(); + const auto HINTSCALE = PWINDOW->m_fX11SurfaceScaledBy; + + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, RELATIVETO.x + pConstraint->positionHint.x / HINTSCALE, RELATIVETO.y + pConstraint->positionHint.y / HINTSCALE); + wlr_seat_pointer_warp(pConstraint->constraint->seat, pConstraint->constraint->current.cursor_hint.x, pConstraint->constraint->current.cursor_hint.y); + } +} + void CInputManager::unconstrainMouse() { if (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint) return; diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index 1a3eac0c1..a5f38947e 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -79,6 +79,7 @@ class CInputManager { void destroySwitch(SSwitchDevice*); void constrainMouse(SMouse*, wlr_pointer_constraint_v1*); + void warpMouseToConstraintMiddle(SConstraint*); void recheckConstraint(SMouse*); void unconstrainMouse(); SConstraint* constraintFromWlr(wlr_pointer_constraint_v1*);