diff --git a/autotests/integration/pointer_constraints_test.cpp b/autotests/integration/pointer_constraints_test.cpp --- a/autotests/integration/pointer_constraints_test.cpp +++ b/autotests/integration/pointer_constraints_test.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -246,6 +247,24 @@ QVERIFY(confinedSpy2.wait()); QCOMPARE(input()->pointer()->isConstrained(), true); + // delete pointer confine + confinedPointer.reset(nullptr); + Test::flushWaylandConnection(); + + QSignalSpy constraintsChangedSpy(input()->pointer()->window()->surface(), &KWayland::Server::SurfaceInterface::pointerConstraintsChanged); + QVERIFY(constraintsChangedSpy.isValid()); + QVERIFY(constraintsChangedSpy.wait()); + + // should be unconfined + QCOMPARE(input()->pointer()->isConstrained(), false); + + // confine again + confinedPointer.reset(Test::waylandPointerConstraints()->confinePointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::Persistent)); + QSignalSpy confinedSpy3(confinedPointer.data(), &ConfinedPointer::confined); + QVERIFY(confinedSpy3.isValid()); + QVERIFY(confinedSpy3.wait()); + QCOMPARE(input()->pointer()->isConstrained(), true); + // and now unmap shellSurface.reset(); surface.reset(); @@ -302,6 +321,29 @@ // moving cursor should be allowed again KWin::Cursor::setPos(c->geometry().center() + QPoint(1, 1)); QCOMPARE(KWin::Cursor::pos(), c->geometry().center() + QPoint(1, 1)); + + lockedPointer.reset(Test::waylandPointerConstraints()->lockPointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::Persistent)); + QSignalSpy lockedSpy2(lockedPointer.data(), &LockedPointer::locked); + QVERIFY(lockedSpy2.isValid()); + QVERIFY(lockedSpy2.wait()); + + // try to move the pointer + QCOMPARE(input()->pointer()->isConstrained(), true); + KWin::Cursor::setPos(c->geometry().center()); + QCOMPARE(KWin::Cursor::pos(), c->geometry().center() + QPoint(1, 1)); + + // delete pointer lock + lockedPointer.reset(nullptr); + Test::flushWaylandConnection(); + + QSignalSpy constraintsChangedSpy(input()->pointer()->window()->surface(), &KWayland::Server::SurfaceInterface::pointerConstraintsChanged); + QVERIFY(constraintsChangedSpy.isValid()); + QVERIFY(constraintsChangedSpy.wait()); + + // moving cursor should be allowed again + QCOMPARE(input()->pointer()->isConstrained(), false); + KWin::Cursor::setPos(c->geometry().center()); + QCOMPARE(KWin::Cursor::pos(), c->geometry().center()); } void TestPointerConstraints::testBreakConstrainedPointer_data() diff --git a/input.cpp b/input.cpp --- a/input.cpp +++ b/input.cpp @@ -1340,7 +1340,7 @@ if (event->buttons() == Qt::NoButton) { // update pointer window only if no button is pressed input()->pointer()->update(); - input()->pointer()->enablePointerConstraints(); + input()->pointer()->updatePointerConstraints(); } seat->setPointerPos(event->globalPos()); MouseEvent *e = static_cast(event); diff --git a/pointer_input.h b/pointer_input.h --- a/pointer_input.h +++ b/pointer_input.h @@ -84,8 +84,10 @@ void setWindowSelectionCursor(const QByteArray &shape); void removeWindowSelectionCursor(); - void enablePointerConstraints(); + void updatePointerConstraints(); void breakPointerConstraints(); + + /* This is only used for ESC pressing */ void blockPointerConstraints() { m_blockConstraint = true; } diff --git a/pointer_input.cpp b/pointer_input.cpp --- a/pointer_input.cpp +++ b/pointer_input.cpp @@ -542,10 +542,10 @@ } ); m_constraintsConnection = connect(m_window->surface(), &KWayland::Server::SurfaceInterface::pointerConstraintsChanged, - this, &PointerInputRedirection::enablePointerConstraints); + this, &PointerInputRedirection::updatePointerConstraints); // check whether a pointer confinement/lock fires m_blockConstraint = false; - enablePointerConstraints(); + updatePointerConstraints(); } else { m_window.clear(); warpXcbOnSurfaceLeft(nullptr); @@ -598,7 +598,7 @@ return intersected.translated(t->pos() + t->clientPos()); } -void PointerInputRedirection::enablePointerConstraints() +void PointerInputRedirection::updatePointerConstraints() { if (m_window.isNull()) { return; @@ -653,6 +653,7 @@ return; } } else { + m_confined = false; disconnectConfinedPointerRegionConnection(); } const auto lock = s->lockedPointer(); @@ -669,6 +670,8 @@ QStringLiteral("preferences-desktop-mouse"), 5000); // TODO: connect to region change - is it needed at all? If the pointer is locked it's always in the region } + } else { + m_locked = false; } }