From 0bd5eff8623dceb6e2dee445edcc244ccb620660 Mon Sep 17 00:00:00 2001 From: Roman Gilg Date: Mon, 18 Jun 2018 20:14:04 +0200 Subject: [PATCH] Make keyboard focus a pointer constraints necessity Summary: This patch changes KWin's pointer constraining behavior by only allowing constraints if the surface has keyboard focus. In case the client activation state changes, it rechecks it. Test Plan: Manually with the pointer constraints test application and opening the launcher by pressing meta. Also amended autotest. Reviewers: #kwin, graesslin Reviewed By: #kwin, graesslin Subscribers: graesslin, davidedmundson, kwin Tags: #kwin Maniphest Tasks: T8923 Differential Revision: https://phabricator.kde.org/D13492 --- .../integration/pointer_constraints_test.cpp | 10 ++++++++++ pointer_input.cpp | 19 +++++++++++++++++-- pointer_input.h | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/autotests/integration/pointer_constraints_test.cpp b/autotests/integration/pointer_constraints_test.cpp index 2f6ca820d8..37a0416b62 100644 --- a/autotests/integration/pointer_constraints_test.cpp +++ b/autotests/integration/pointer_constraints_test.cpp @@ -224,6 +224,16 @@ void TestPointerConstraints::testConfinedPointer() QCOMPARE(input()->pointer()->isConstrained(), true); QVERIFY(confinedSpy2.wait()); + // deactivate the client, this should unconfine + workspace()->activateClient(nullptr); + QVERIFY(unconfinedSpy2.wait()); + QCOMPARE(input()->pointer()->isConstrained(), false); + + // activate it again, this confines again + workspace()->activateClient(static_cast(input()->pointer()->window().data())); + QVERIFY(confinedSpy2.wait()); + QCOMPARE(input()->pointer()->isConstrained(), true); + // create a second window and move it above our constrained window QScopedPointer surface2(Test::createSurface()); QScopedPointer shellSurface2(Test::createShellSurface(type, surface2.data())); diff --git a/pointer_input.cpp b/pointer_input.cpp index 46b84b788d..9f436f3723 100644 --- a/pointer_input.cpp +++ b/pointer_input.cpp @@ -544,6 +544,8 @@ void PointerInputRedirection::update() ); m_constraintsConnection = connect(m_window->surface(), &KWayland::Server::SurfaceInterface::pointerConstraintsChanged, this, &PointerInputRedirection::updatePointerConstraints); + m_constraintsActivatedConnection = connect(workspace(), &Workspace::clientActivated, + this, &PointerInputRedirection::updatePointerConstraints); // check whether a pointer confinement/lock fires m_blockConstraint = false; updatePointerConstraints(); @@ -588,6 +590,9 @@ void PointerInputRedirection::disconnectPointerConstraintsConnection() { disconnect(m_constraintsConnection); m_constraintsConnection = QMetaObject::Connection(); + + disconnect(m_constraintsActivatedConnection); + m_constraintsActivatedConnection = QMetaObject::Connection(); } template @@ -617,13 +622,19 @@ void PointerInputRedirection::updatePointerConstraints() if (m_blockConstraint) { return; } + const bool windowIsActive = m_window == workspace()->activeClient(); const auto cf = s->confinedPointer(); if (cf) { if (cf->isConfined()) { + if (!windowIsActive) { + cf->setConfined(false); + m_confined = false; + disconnectConfinedPointerRegionConnection(); + } return; } const QRegion r = getConstraintRegion(m_window.data(), cf.data()); - if (r.contains(m_pos.toPoint())) { + if (windowIsActive && r.contains(m_pos.toPoint())) { cf->setConfined(true); m_confined = true; m_confinedPointerRegionConnection = connect(cf.data(), &KWayland::Server::ConfinedPointerInterface::regionChanged, this, @@ -660,10 +671,14 @@ void PointerInputRedirection::updatePointerConstraints() const auto lock = s->lockedPointer(); if (lock) { if (lock->isLocked()) { + if (!windowIsActive) { + lock->setLocked(false); + m_locked = false; + } return; } const QRegion r = getConstraintRegion(m_window.data(), lock.data()); - if (r.contains(m_pos.toPoint())) { + if (windowIsActive && r.contains(m_pos.toPoint())) { lock->setLocked(true); m_locked = true; OSD::show(i18nc("notification about mouse pointer locked", diff --git a/pointer_input.h b/pointer_input.h index 1ea4032dcc..8226e2982d 100644 --- a/pointer_input.h +++ b/pointer_input.h @@ -165,6 +165,7 @@ private: QMetaObject::Connection m_windowGeometryConnection; QMetaObject::Connection m_internalWindowConnection; QMetaObject::Connection m_constraintsConnection; + QMetaObject::Connection m_constraintsActivatedConnection; QMetaObject::Connection m_confinedPointerRegionConnection; QMetaObject::Connection m_decorationGeometryConnection; bool m_confined = false;