2016-11-25 06:17:43 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "kwin_wayland_test.h"
|
2020-03-04 07:55:26 +00:00
|
|
|
#include "abstract_client.h"
|
2016-11-25 06:17:43 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#include "keyboard_input.h"
|
|
|
|
#include "platform.h"
|
|
|
|
#include "pointer_input.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KWayland/Client/compositor.h>
|
|
|
|
#include <KWayland/Client/keyboard.h>
|
|
|
|
#include <KWayland/Client/pointer.h>
|
|
|
|
#include <KWayland/Client/pointerconstraints.h>
|
|
|
|
#include <KWayland/Client/region.h>
|
|
|
|
#include <KWayland/Client/seat.h>
|
|
|
|
#include <KWayland/Client/shm_pool.h>
|
|
|
|
#include <KWayland/Client/surface.h>
|
2020-04-29 15:18:41 +00:00
|
|
|
#include <KWaylandServer/seat_interface.h>
|
|
|
|
#include <KWaylandServer/surface_interface.h>
|
2016-11-25 06:17:43 +00:00
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
|
|
|
typedef std::function<QPoint(const QRect&)> PointerFunc;
|
|
|
|
Q_DECLARE_METATYPE(PointerFunc)
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_pointer_constraints-0");
|
|
|
|
|
|
|
|
class TestPointerConstraints : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testConfinedPointer_data();
|
|
|
|
void testConfinedPointer();
|
|
|
|
void testLockedPointer_data();
|
|
|
|
void testLockedPointer();
|
2017-06-24 18:31:50 +00:00
|
|
|
void testCloseWindowWithLockedPointer_data();
|
|
|
|
void testCloseWindowWithLockedPointer();
|
2016-11-25 06:17:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void TestPointerConstraints::initTestCase()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<PointerFunc>();
|
|
|
|
qRegisterMetaType<KWin::AbstractClient*>();
|
|
|
|
QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated);
|
|
|
|
QVERIFY(workspaceCreatedSpy.isValid());
|
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
|
|
|
QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit()));
|
2019-08-26 21:16:53 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
2016-11-25 06:17:43 +00:00
|
|
|
|
2016-12-22 18:05:47 +00:00
|
|
|
// set custom config which disables the OnScreenNotification
|
|
|
|
KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
|
|
|
KConfigGroup group = config->group("OnScreenNotification");
|
|
|
|
group.writeEntry(QStringLiteral("QmlPath"), QString("/does/not/exist.qml"));
|
|
|
|
group.sync();
|
|
|
|
|
|
|
|
kwinApp()->setConfig(config);
|
|
|
|
|
|
|
|
|
2016-11-25 06:17:43 +00:00
|
|
|
kwinApp()->start();
|
|
|
|
QVERIFY(workspaceCreatedSpy.wait());
|
|
|
|
QCOMPARE(screens()->count(), 2);
|
|
|
|
QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024));
|
|
|
|
waylandServer()->initWorkspace();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::init()
|
|
|
|
{
|
2016-12-03 13:31:14 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat | Test::AdditionalWaylandInterface::PointerConstraints));
|
2016-11-25 06:17:43 +00:00
|
|
|
QVERIFY(Test::waitForWaylandPointer());
|
|
|
|
|
|
|
|
screens()->setCurrent(0);
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(QPoint(1280, 512));
|
2016-11-25 06:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::cleanup()
|
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::testConfinedPointer_data()
|
|
|
|
{
|
2019-08-27 15:01:14 +00:00
|
|
|
QTest::addColumn<Test::XdgShellSurfaceType>("type");
|
2016-11-25 06:17:43 +00:00
|
|
|
QTest::addColumn<PointerFunc>("positionFunction");
|
|
|
|
QTest::addColumn<int>("xOffset");
|
|
|
|
QTest::addColumn<int>("yOffset");
|
|
|
|
PointerFunc bottomLeft = &QRect::bottomLeft;
|
|
|
|
PointerFunc bottomRight = &QRect::bottomRight;
|
|
|
|
PointerFunc topRight = &QRect::topRight;
|
|
|
|
PointerFunc topLeft = &QRect::topLeft;
|
|
|
|
|
2019-08-27 15:01:14 +00:00
|
|
|
QTest::newRow("XdgWmBase - bottomLeft") << Test::XdgShellSurfaceType::XdgShellStable << bottomLeft << -1 << 1;
|
|
|
|
QTest::newRow("XdgWmBase - bottomRight") << Test::XdgShellSurfaceType::XdgShellStable << bottomRight << 1 << 1;
|
|
|
|
QTest::newRow("XdgWmBase - topLeft") << Test::XdgShellSurfaceType::XdgShellStable << topLeft << -1 << -1;
|
|
|
|
QTest::newRow("XdgWmBase - topRight") << Test::XdgShellSurfaceType::XdgShellStable << topRight << 1 << -1;
|
2016-11-25 06:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::testConfinedPointer()
|
|
|
|
{
|
|
|
|
// this test sets up a Surface with a confined pointer
|
|
|
|
// simple interaction test to verify that the pointer gets confined
|
|
|
|
QScopedPointer<Surface> surface(Test::createSurface());
|
2019-08-27 15:01:14 +00:00
|
|
|
QFETCH(Test::XdgShellSurfaceType, type);
|
|
|
|
QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellSurface(type, surface.data()));
|
2016-11-25 06:17:43 +00:00
|
|
|
QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer());
|
|
|
|
QScopedPointer<ConfinedPointer> confinedPointer(Test::waylandPointerConstraints()->confinePointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::OneShot));
|
|
|
|
QSignalSpy confinedSpy(confinedPointer.data(), &ConfinedPointer::confined);
|
|
|
|
QVERIFY(confinedSpy.isValid());
|
|
|
|
QSignalSpy unconfinedSpy(confinedPointer.data(), &ConfinedPointer::unconfined);
|
|
|
|
QVERIFY(unconfinedSpy.isValid());
|
|
|
|
|
|
|
|
// now map the window
|
|
|
|
auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 100), Qt::blue);
|
|
|
|
QVERIFY(c);
|
2019-09-27 10:01:10 +00:00
|
|
|
if (c->pos() == QPoint(0, 0)) {
|
2016-11-25 06:17:43 +00:00
|
|
|
c->move(QPoint(1, 1));
|
|
|
|
}
|
2020-04-02 16:18:01 +00:00
|
|
|
QVERIFY(!c->frameGeometry().contains(KWin::Cursors::self()->mouse()->pos()));
|
2016-11-25 06:17:43 +00:00
|
|
|
|
|
|
|
// now let's confine
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(c->frameGeometry().center());
|
2016-11-25 06:17:43 +00:00
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), true);
|
|
|
|
QVERIFY(confinedSpy.wait());
|
|
|
|
|
|
|
|
// picking a position outside the window geometry should not move pointer
|
|
|
|
QSignalSpy pointerPositionChangedSpy(input(), &InputRedirection::globalPointerChanged);
|
|
|
|
QVERIFY(pointerPositionChangedSpy.isValid());
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(QPoint(1280, 512));
|
2016-11-25 06:17:43 +00:00
|
|
|
QVERIFY(pointerPositionChangedSpy.isEmpty());
|
2020-04-02 16:18:01 +00:00
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), c->frameGeometry().center());
|
2016-11-25 06:17:43 +00:00
|
|
|
|
|
|
|
// TODO: test relative motion
|
|
|
|
QFETCH(PointerFunc, positionFunction);
|
2019-09-27 10:01:10 +00:00
|
|
|
const QPoint position = positionFunction(c->frameGeometry());
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(position);
|
2016-11-25 06:17:43 +00:00
|
|
|
QCOMPARE(pointerPositionChangedSpy.count(), 1);
|
2020-04-02 16:18:01 +00:00
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), position);
|
2016-11-25 06:17:43 +00:00
|
|
|
// moving one to right should not be possible
|
|
|
|
QFETCH(int, xOffset);
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(position + QPoint(xOffset, 0));
|
2016-11-25 06:17:43 +00:00
|
|
|
QCOMPARE(pointerPositionChangedSpy.count(), 1);
|
2020-04-02 16:18:01 +00:00
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), position);
|
2016-11-25 06:17:43 +00:00
|
|
|
// moving one to bottom should not be possible
|
|
|
|
QFETCH(int, yOffset);
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(position + QPoint(0, yOffset));
|
2016-11-25 06:17:43 +00:00
|
|
|
QCOMPARE(pointerPositionChangedSpy.count(), 1);
|
2020-04-02 16:18:01 +00:00
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), position);
|
2016-11-25 06:17:43 +00:00
|
|
|
|
2018-10-06 16:03:19 +00:00
|
|
|
// modifier + click should be ignored
|
|
|
|
// first ensure the settings are ok
|
|
|
|
KConfigGroup group = kwinApp()->config()->group("MouseBindings");
|
|
|
|
group.writeEntry("CommandAllKey", QStringLiteral("Alt"));
|
|
|
|
group.writeEntry("CommandAll1", "Move");
|
|
|
|
group.writeEntry("CommandAll2", "Move");
|
|
|
|
group.writeEntry("CommandAll3", "Move");
|
2018-10-07 19:02:09 +00:00
|
|
|
group.writeEntry("CommandAllWheel", "change opacity");
|
2018-10-06 16:03:19 +00:00
|
|
|
group.sync();
|
|
|
|
workspace()->slotReconfigure();
|
|
|
|
QCOMPARE(options->commandAllModifier(), Qt::AltModifier);
|
|
|
|
QCOMPARE(options->commandAll1(), Options::MouseUnrestrictedMove);
|
|
|
|
QCOMPARE(options->commandAll2(), Options::MouseUnrestrictedMove);
|
|
|
|
QCOMPARE(options->commandAll3(), Options::MouseUnrestrictedMove);
|
|
|
|
|
|
|
|
quint32 timestamp = 1;
|
|
|
|
kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTALT, timestamp++);
|
|
|
|
kwinApp()->platform()->pointerButtonPressed(BTN_LEFT, timestamp++);
|
|
|
|
QVERIFY(!c->isMove());
|
|
|
|
kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++);
|
2018-10-07 19:02:09 +00:00
|
|
|
|
|
|
|
// set the opacity to 0.5
|
|
|
|
c->setOpacity(0.5);
|
|
|
|
QCOMPARE(c->opacity(), 0.5);
|
|
|
|
|
|
|
|
// pointer is confined so shortcut should not work
|
|
|
|
kwinApp()->platform()->pointerAxisVertical(-5, timestamp++);
|
|
|
|
QCOMPARE(c->opacity(), 0.5);
|
|
|
|
kwinApp()->platform()->pointerAxisVertical(5, timestamp++);
|
|
|
|
QCOMPARE(c->opacity(), 0.5);
|
|
|
|
|
2018-10-06 16:03:19 +00:00
|
|
|
kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTALT, timestamp++);
|
|
|
|
|
2018-09-02 23:00:29 +00:00
|
|
|
// deactivate the client, this should unconfine
|
|
|
|
workspace()->activateClient(nullptr);
|
2016-11-25 06:17:43 +00:00
|
|
|
QVERIFY(unconfinedSpy.wait());
|
2018-09-02 23:00:29 +00:00
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
|
|
|
|
|
|
|
// reconfine pointer (this time with persistent life time)
|
2016-11-25 06:17:43 +00:00
|
|
|
confinedPointer.reset(Test::waylandPointerConstraints()->confinePointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::Persistent));
|
|
|
|
QSignalSpy confinedSpy2(confinedPointer.data(), &ConfinedPointer::confined);
|
|
|
|
QVERIFY(confinedSpy2.isValid());
|
|
|
|
QSignalSpy unconfinedSpy2(confinedPointer.data(), &ConfinedPointer::unconfined);
|
|
|
|
QVERIFY(unconfinedSpy2.isValid());
|
|
|
|
|
2018-09-02 23:00:29 +00:00
|
|
|
// activate it again, this confines again
|
2018-09-15 00:00:24 +00:00
|
|
|
workspace()->activateClient(static_cast<AbstractClient*>(input()->pointer()->focus().data()));
|
2016-11-25 06:17:43 +00:00
|
|
|
QVERIFY(confinedSpy2.wait());
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), true);
|
|
|
|
|
2018-09-02 23:00:29 +00:00
|
|
|
// deactivate the client one more time with the persistent life time constraint, this should unconfine
|
2018-06-18 18:14:04 +00:00
|
|
|
workspace()->activateClient(nullptr);
|
|
|
|
QVERIFY(unconfinedSpy2.wait());
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
|
|
|
// activate it again, this confines again
|
2018-09-15 00:00:24 +00:00
|
|
|
workspace()->activateClient(static_cast<AbstractClient*>(input()->pointer()->focus().data()));
|
2018-06-18 18:14:04 +00:00
|
|
|
QVERIFY(confinedSpy2.wait());
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), true);
|
|
|
|
|
2016-11-25 06:17:43 +00:00
|
|
|
// create a second window and move it above our constrained window
|
|
|
|
QScopedPointer<Surface> surface2(Test::createSurface());
|
2019-08-27 15:01:14 +00:00
|
|
|
QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellSurface(type, surface2.data()));
|
2016-11-25 06:17:43 +00:00
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(1280, 1024), Qt::blue);
|
|
|
|
QVERIFY(c2);
|
|
|
|
QVERIFY(unconfinedSpy2.wait());
|
|
|
|
// and unmapping the second window should confine again
|
|
|
|
shellSurface2.reset();
|
|
|
|
surface2.reset();
|
|
|
|
QVERIFY(confinedSpy2.wait());
|
|
|
|
|
|
|
|
// let's set a region which results in unconfined
|
2018-09-02 23:00:29 +00:00
|
|
|
auto r = Test::waylandCompositor()->createRegion(QRegion(2, 2, 3, 3));
|
2016-11-25 06:17:43 +00:00
|
|
|
confinedPointer->setRegion(r.get());
|
|
|
|
surface->commit(Surface::CommitFlag::None);
|
|
|
|
QVERIFY(unconfinedSpy2.wait());
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
|
|
|
// and set a full region again, that should confine
|
|
|
|
confinedPointer->setRegion(nullptr);
|
|
|
|
surface->commit(Surface::CommitFlag::None);
|
|
|
|
QVERIFY(confinedSpy2.wait());
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), true);
|
|
|
|
|
2018-06-11 20:45:09 +00:00
|
|
|
// delete pointer confine
|
|
|
|
confinedPointer.reset(nullptr);
|
|
|
|
Test::flushWaylandConnection();
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
QSignalSpy constraintsChangedSpy(input()->pointer()->focus()->surface(), &KWaylandServer::SurfaceInterface::pointerConstraintsChanged);
|
2018-06-11 20:45:09 +00:00
|
|
|
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);
|
|
|
|
|
2016-11-25 06:17:43 +00:00
|
|
|
// and now unmap
|
|
|
|
shellSurface.reset();
|
|
|
|
surface.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(c));
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::testLockedPointer_data()
|
|
|
|
{
|
2019-08-27 15:01:14 +00:00
|
|
|
QTest::addColumn<Test::XdgShellSurfaceType>("type");
|
2016-11-25 06:17:43 +00:00
|
|
|
|
2019-08-27 15:01:14 +00:00
|
|
|
QTest::newRow("xdgWmBase") << Test::XdgShellSurfaceType::XdgShellStable;
|
2016-11-25 06:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::testLockedPointer()
|
|
|
|
{
|
|
|
|
// this test sets up a Surface with a locked pointer
|
|
|
|
// simple interaction test to verify that the pointer gets locked
|
|
|
|
// the various ways to unlock are not tested as that's already verified by testConfinedPointer
|
|
|
|
QScopedPointer<Surface> surface(Test::createSurface());
|
2019-08-27 15:01:14 +00:00
|
|
|
QFETCH(Test::XdgShellSurfaceType, type);
|
|
|
|
QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellSurface(type, surface.data()));
|
2016-11-25 06:17:43 +00:00
|
|
|
QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer());
|
|
|
|
QScopedPointer<LockedPointer> lockedPointer(Test::waylandPointerConstraints()->lockPointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::OneShot));
|
|
|
|
QSignalSpy lockedSpy(lockedPointer.data(), &LockedPointer::locked);
|
|
|
|
QVERIFY(lockedSpy.isValid());
|
|
|
|
QSignalSpy unlockedSpy(lockedPointer.data(), &LockedPointer::unlocked);
|
|
|
|
QVERIFY(unlockedSpy.isValid());
|
|
|
|
|
|
|
|
// now map the window
|
|
|
|
auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 100), Qt::blue);
|
|
|
|
QVERIFY(c);
|
2020-04-02 16:18:01 +00:00
|
|
|
QVERIFY(!c->frameGeometry().contains(KWin::Cursors::self()->mouse()->pos()));
|
2016-11-25 06:17:43 +00:00
|
|
|
|
|
|
|
// now let's lock
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(c->frameGeometry().center());
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), c->frameGeometry().center());
|
2016-11-25 06:17:43 +00:00
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), true);
|
|
|
|
QVERIFY(lockedSpy.wait());
|
|
|
|
|
|
|
|
// try to move the pointer
|
|
|
|
// TODO: add relative pointer
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(c->frameGeometry().center() + QPoint(1, 1));
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), c->frameGeometry().center());
|
2016-11-25 06:17:43 +00:00
|
|
|
|
2018-09-02 23:00:29 +00:00
|
|
|
// deactivate the client, this should unlock
|
|
|
|
workspace()->activateClient(nullptr);
|
2016-11-25 06:17:43 +00:00
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
|
|
|
QVERIFY(unlockedSpy.wait());
|
|
|
|
|
|
|
|
// moving cursor should be allowed again
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(c->frameGeometry().center() + QPoint(1, 1));
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), c->frameGeometry().center() + QPoint(1, 1));
|
2018-06-11 20:45:09 +00:00
|
|
|
|
|
|
|
lockedPointer.reset(Test::waylandPointerConstraints()->lockPointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::Persistent));
|
|
|
|
QSignalSpy lockedSpy2(lockedPointer.data(), &LockedPointer::locked);
|
|
|
|
QVERIFY(lockedSpy2.isValid());
|
2018-09-02 23:00:29 +00:00
|
|
|
|
|
|
|
// activate the client again, this should lock again
|
2018-09-15 00:00:24 +00:00
|
|
|
workspace()->activateClient(static_cast<AbstractClient*>(input()->pointer()->focus().data()));
|
2018-06-11 20:45:09 +00:00
|
|
|
QVERIFY(lockedSpy2.wait());
|
2018-09-02 23:00:29 +00:00
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), true);
|
2018-06-11 20:45:09 +00:00
|
|
|
|
|
|
|
// try to move the pointer
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), true);
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(c->frameGeometry().center());
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), c->frameGeometry().center() + QPoint(1, 1));
|
2018-06-11 20:45:09 +00:00
|
|
|
|
|
|
|
// delete pointer lock
|
|
|
|
lockedPointer.reset(nullptr);
|
|
|
|
Test::flushWaylandConnection();
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
QSignalSpy constraintsChangedSpy(input()->pointer()->focus()->surface(), &KWaylandServer::SurfaceInterface::pointerConstraintsChanged);
|
2018-06-11 20:45:09 +00:00
|
|
|
QVERIFY(constraintsChangedSpy.isValid());
|
|
|
|
QVERIFY(constraintsChangedSpy.wait());
|
|
|
|
|
|
|
|
// moving cursor should be allowed again
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(c->frameGeometry().center());
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), c->frameGeometry().center());
|
2016-11-25 06:17:43 +00:00
|
|
|
}
|
|
|
|
|
2017-06-24 18:31:50 +00:00
|
|
|
void TestPointerConstraints::testCloseWindowWithLockedPointer_data()
|
|
|
|
{
|
2019-08-27 15:01:14 +00:00
|
|
|
QTest::addColumn<Test::XdgShellSurfaceType>("type");
|
2017-06-24 18:31:50 +00:00
|
|
|
|
2019-08-27 15:01:14 +00:00
|
|
|
QTest::newRow("XdgWmBase") << Test::XdgShellSurfaceType::XdgShellStable;
|
2017-06-24 18:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::testCloseWindowWithLockedPointer()
|
|
|
|
{
|
|
|
|
// test case which verifies that the pointer gets unlocked when the window for it gets closed
|
|
|
|
QScopedPointer<Surface> surface(Test::createSurface());
|
2019-08-27 15:01:14 +00:00
|
|
|
QFETCH(Test::XdgShellSurfaceType, type);
|
|
|
|
QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellSurface(type, surface.data()));
|
2017-06-24 18:31:50 +00:00
|
|
|
QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer());
|
|
|
|
QScopedPointer<LockedPointer> lockedPointer(Test::waylandPointerConstraints()->lockPointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::OneShot));
|
|
|
|
QSignalSpy lockedSpy(lockedPointer.data(), &LockedPointer::locked);
|
|
|
|
QVERIFY(lockedSpy.isValid());
|
|
|
|
QSignalSpy unlockedSpy(lockedPointer.data(), &LockedPointer::unlocked);
|
|
|
|
QVERIFY(unlockedSpy.isValid());
|
|
|
|
|
|
|
|
// now map the window
|
|
|
|
auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 100), Qt::blue);
|
|
|
|
QVERIFY(c);
|
2020-04-02 16:18:01 +00:00
|
|
|
QVERIFY(!c->frameGeometry().contains(KWin::Cursors::self()->mouse()->pos()));
|
2017-06-24 18:31:50 +00:00
|
|
|
|
|
|
|
// now let's lock
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(c->frameGeometry().center());
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), c->frameGeometry().center());
|
2017-06-24 18:31:50 +00:00
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), true);
|
|
|
|
QVERIFY(lockedSpy.wait());
|
|
|
|
|
|
|
|
// close the window
|
|
|
|
shellSurface.reset();
|
|
|
|
surface.reset();
|
|
|
|
// this should result in unlocked
|
|
|
|
QVERIFY(unlockedSpy.wait());
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
|
|
|
}
|
|
|
|
|
2016-11-25 06:17:43 +00:00
|
|
|
WAYLANDTEST_MAIN(TestPointerConstraints)
|
|
|
|
#include "pointer_constraints_test.moc"
|