mirror of
https://github.com/hyprwm/Hyprland
synced 2025-01-03 19:09:49 +01:00
input: unify constraint hint logic
Unifies the constraint hint logic. Previously, ignoring the stupid conditions, unscaled hints were mistaken with scaled coordinates.
This commit is contained in:
parent
14f20a7372
commit
942ee943f5
3 changed files with 26 additions and 38 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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*);
|
||||
|
|
Loading…
Reference in a new issue