From d48c11cc3f12dc12315008b5574be6455238db7b Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 28 Sep 2023 20:02:00 +0100 Subject: [PATCH] input: minor constraint fixes Better adjust to constraints that do not set a hint. Fixes #3436 --- src/helpers/WLClasses.hpp | 11 +++--- src/managers/input/InputManager.cpp | 56 ++++++++++++++--------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index d66ebdfd..d33af797 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -168,18 +168,19 @@ struct SConstraint { bool active = false; - bool hintSet = false; - Vector2D positionHint = {-1, -1}; // the position hint, but will be set to the current cursor pos if not set. + bool hintSet = false; + Vector2D positionHint = {-1, -1}; // the position hint, but will use cursorPosOnActivate if unset + Vector2D cursorPosOnActivate = {-1, -1}; DYNLISTENER(setConstraintRegion); DYNLISTENER(destroyConstraint); - CRegion getLogicCoordsRegion(); + CRegion getLogicCoordsRegion(); Vector2D getLogicConstraintPos(); Vector2D getLogicConstraintSize(); - bool operator==(const SConstraint& b) const { - return constraint == b.constraint; + bool operator==(const SConstraint& b) const { + return constraint == b.constraint; } }; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 02ccfd1b..beb55c5d 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1207,24 +1207,30 @@ void CInputManager::constrainMouse(SMouse* pMouse, wlr_pointer_constraint_v1* co return; const auto MOUSECOORDS = getMouseCoordsInternal(); + const auto PCONSTRAINT = constraintFromWlr(constraint); pMouse->hyprListener_commitConstraint.removeCallback(); - if (pMouse->currentConstraint) { - if (constraint) { - const auto PCONSTRAINT = constraintFromWlr(constraint); - if (constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) { - PCONSTRAINT->hintSet = true; - PCONSTRAINT->positionHint = {constraint->current.cursor_hint.x, constraint->current.cursor_hint.y}; - } - - if (constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT && constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED) - warpMouseToConstraintMiddle(PCONSTRAINT); - } - + if (pMouse->currentConstraint) wlr_pointer_constraint_v1_send_deactivated(pMouse->currentConstraint); + + if (const auto PWINDOW = g_pCompositor->getWindowFromSurface(constraint->surface); PWINDOW) { + const auto RELATIVETO = PWINDOW->m_bIsX11 ? + (PWINDOW->m_bIsMapped ? PWINDOW->m_vRealPosition.goalv() : + g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOW->m_uSurface.xwayland->x, PWINDOW->m_uSurface.xwayland->y})) : + PWINDOW->m_vRealPosition.goalv(); + + PCONSTRAINT->cursorPosOnActivate = MOUSECOORDS - RELATIVETO; } + if (constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) { + PCONSTRAINT->hintSet = true; + PCONSTRAINT->positionHint = {constraint->current.cursor_hint.x, constraint->current.cursor_hint.y}; + } + + if (constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT && constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED) + warpMouseToConstraintMiddle(PCONSTRAINT); + pMouse->currentConstraint = constraint; pMouse->constraintActive = true; @@ -1236,7 +1242,7 @@ void CInputManager::constrainMouse(SMouse* pMouse, wlr_pointer_constraint_v1* co // warp to the constraint recheckConstraint(pMouse); - constraintFromWlr(constraint)->active = true; + PCONSTRAINT->active = true; wlr_pointer_constraint_v1_send_activated(pMouse->currentConstraint); @@ -1253,23 +1259,17 @@ void CInputManager::warpMouseToConstraintMiddle(SConstraint* pConstraint) { const auto PWINDOW = g_pCompositor->getWindowFromSurface(pConstraint->constraint->surface); if (PWINDOW) { - const auto RELATIVETO = PWINDOW->m_bIsX11 ? - (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 RELATIVETO = pConstraint->getLogicConstraintPos(); const auto HINTSCALE = PWINDOW->m_fX11SurfaceScaledBy; - if (pConstraint->hintSet) { - 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); - } else { - const auto RELATIVESIZE = PWINDOW->m_bIsX11 ? - (PWINDOW->m_bIsMapped ? PWINDOW->m_vRealSize.goalv() : - g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOW->m_uSurface.xwayland->width, PWINDOW->m_uSurface.xwayland->height})) : - PWINDOW->m_vRealSize.goalv(); + auto HINT = pConstraint->hintSet ? pConstraint->positionHint : pConstraint->cursorPosOnActivate; - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, RELATIVETO.x + RELATIVESIZE.x / 2.f, RELATIVETO.y + RELATIVESIZE.y / 2.f); - wlr_seat_pointer_warp(pConstraint->constraint->seat, RELATIVESIZE.x / 2.f, RELATIVESIZE.y / 2.f); + if (HINT == Vector2D{-1, -1}) + HINT = pConstraint->getLogicConstraintSize() / 2.f; + + if (HINT != Vector2D{-1, -1}) { + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, RELATIVETO.x + HINT.x / HINTSCALE, RELATIVETO.y + HINT.y / HINTSCALE); + wlr_seat_pointer_warp(pConstraint->constraint->seat, pConstraint->constraint->current.cursor_hint.x, pConstraint->constraint->current.cursor_hint.y); } } } @@ -1597,7 +1597,7 @@ void CInputManager::setCursorIconOnBorder(CWindow* w) { wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; eBorderIconDirection direction = BORDERICON_NONE; wlr_box boxFullGrabInput = {box.x - *PEXTENDBORDERGRAB - BORDERSIZE, box.y - *PEXTENDBORDERGRAB - BORDERSIZE, box.width + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE), - box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)}; + box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)}; if (!wlr_box_contains_point(&boxFullGrabInput, mouseCoords.x, mouseCoords.y) || (!m_lCurrentlyHeldButtons.empty() && !currentlyDraggedWindow)) { direction = BORDERICON_NONE;