2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-11-25 06:17:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-11-25 06:17:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-11-25 06:17:43 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/output.h"
|
|
|
|
#include "core/platform.h"
|
2016-11-25 06:17:43 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#include "keyboard_input.h"
|
|
|
|
#include "pointer_input.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/seat_interface.h"
|
|
|
|
#include "wayland/surface_interface.h"
|
2016-11-25 06:17:43 +00:00
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2016-11-25 06:17:43 +00:00
|
|
|
#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>
|
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
2022-05-16 20:13:39 +00:00
|
|
|
typedef std::function<QPointF(const QRectF &)> PointerFunc;
|
2016-11-25 06:17:43 +00:00
|
|
|
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();
|
2017-06-24 18:31:50 +00:00
|
|
|
void testCloseWindowWithLockedPointer();
|
2016-11-25 06:17:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void TestPointerConstraints::initTestCase()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<PointerFunc>();
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
2016-11-25 06:17:43 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
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();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2021-08-31 07:03:05 +00:00
|
|
|
QCOMPARE(outputs.count(), 2);
|
|
|
|
QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
|
2016-11-25 06:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->setActiveOutput(QPoint(640, 512));
|
2021-08-28 18:40:12 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(QPoint(640, 512));
|
2016-11-25 06:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::cleanup()
|
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::testConfinedPointer_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<PointerFunc>("positionFunction");
|
|
|
|
QTest::addColumn<int>("xOffset");
|
|
|
|
QTest::addColumn<int>("yOffset");
|
2022-05-16 20:13:39 +00:00
|
|
|
PointerFunc bottomLeft = [](const QRectF &rect) {
|
|
|
|
return rect.toRect().bottomLeft();
|
|
|
|
};
|
|
|
|
PointerFunc bottomRight = [](const QRectF &rect) {
|
|
|
|
return rect.toRect().bottomRight();
|
|
|
|
};
|
|
|
|
PointerFunc topRight = [](const QRectF &rect) {
|
|
|
|
return rect.toRect().topRight();
|
|
|
|
};
|
|
|
|
PointerFunc topLeft = [](const QRectF &rect) {
|
|
|
|
return rect.toRect().topLeft();
|
|
|
|
};
|
2016-11-25 06:17:43 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("XdgWmBase - bottomLeft") << bottomLeft << -1 << 1;
|
|
|
|
QTest::newRow("XdgWmBase - bottomRight") << bottomRight << 1 << 1;
|
|
|
|
QTest::newRow("XdgWmBase - topLeft") << topLeft << -1 << -1;
|
|
|
|
QTest::newRow("XdgWmBase - topRight") << 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
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
std::unique_ptr<Pointer> pointer(Test::waylandSeat()->createPointer());
|
|
|
|
std::unique_ptr<ConfinedPointer> confinedPointer(Test::waylandPointerConstraints()->confinePointer(surface.get(), pointer.get(), nullptr, PointerConstraints::LifeTime::OneShot));
|
|
|
|
QSignalSpy confinedSpy(confinedPointer.get(), &ConfinedPointer::confined);
|
|
|
|
QSignalSpy unconfinedSpy(confinedPointer.get(), &ConfinedPointer::unconfined);
|
2016-11-25 06:17:43 +00:00
|
|
|
|
|
|
|
// now map the window
|
2022-08-01 21:29:02 +00:00
|
|
|
auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 100), Qt::blue);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
if (window->pos() == QPoint(0, 0)) {
|
|
|
|
window->move(QPoint(1, 1));
|
2016-11-25 06:17:43 +00:00
|
|
|
}
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(!window->frameGeometry().contains(KWin::Cursors::self()->mouse()->pos()));
|
2016-11-25 06:17:43 +00:00
|
|
|
|
|
|
|
// now let's confine
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
2022-04-23 19:51:16 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(window->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);
|
2020-12-01 12:04:34 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(QPoint(512, 512));
|
2016-11-25 06:17:43 +00:00
|
|
|
QVERIFY(pointerPositionChangedSpy.isEmpty());
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), window->frameGeometry().center());
|
2016-11-25 06:17:43 +00:00
|
|
|
|
|
|
|
// TODO: test relative motion
|
|
|
|
QFETCH(PointerFunc, positionFunction);
|
2022-05-16 20:13:39 +00:00
|
|
|
const QPointF position = positionFunction(window->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");
|
2020-05-06 09:17:44 +00:00
|
|
|
group.writeEntry("CommandAllKey", QStringLiteral("Meta"));
|
2018-10-06 16:03:19 +00:00
|
|
|
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();
|
2020-05-06 09:17:44 +00:00
|
|
|
QCOMPARE(options->commandAllModifier(), Qt::MetaModifier);
|
2018-10-06 16:03:19 +00:00
|
|
|
QCOMPARE(options->commandAll1(), Options::MouseUnrestrictedMove);
|
|
|
|
QCOMPARE(options->commandAll2(), Options::MouseUnrestrictedMove);
|
|
|
|
QCOMPARE(options->commandAll3(), Options::MouseUnrestrictedMove);
|
|
|
|
|
|
|
|
quint32 timestamp = 1;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
|
|
|
|
Test::pointerButtonPressed(BTN_LEFT, timestamp++);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(!window->isInteractiveMove());
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::pointerButtonReleased(BTN_LEFT, timestamp++);
|
2018-10-07 19:02:09 +00:00
|
|
|
|
|
|
|
// set the opacity to 0.5
|
2022-04-23 19:51:16 +00:00
|
|
|
window->setOpacity(0.5);
|
|
|
|
QCOMPARE(window->opacity(), 0.5);
|
2018-10-07 19:02:09 +00:00
|
|
|
|
|
|
|
// pointer is confined so shortcut should not work
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::pointerAxisVertical(-5, timestamp++);
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(window->opacity(), 0.5);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::pointerAxisVertical(5, timestamp++);
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(window->opacity(), 0.5);
|
2018-10-07 19:02:09 +00:00
|
|
|
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(KEY_LEFTALT, timestamp++);
|
2018-10-06 16:03:19 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// deactivate the window, this should unconfine
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(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)
|
2022-08-01 21:29:02 +00:00
|
|
|
confinedPointer.reset(Test::waylandPointerConstraints()->confinePointer(surface.get(), pointer.get(), nullptr, PointerConstraints::LifeTime::Persistent));
|
|
|
|
QSignalSpy confinedSpy2(confinedPointer.get(), &ConfinedPointer::confined);
|
|
|
|
QSignalSpy unconfinedSpy2(confinedPointer.get(), &ConfinedPointer::unconfined);
|
2016-11-25 06:17:43 +00:00
|
|
|
|
2018-09-02 23:00:29 +00:00
|
|
|
// activate it again, this confines again
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(static_cast<Window *>(input()->pointer()->focus()));
|
2016-11-25 06:17:43 +00:00
|
|
|
QVERIFY(confinedSpy2.wait());
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), true);
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// deactivate the window one more time with the persistent life time constraint, this should unconfine
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(nullptr);
|
2018-06-18 18:14:04 +00:00
|
|
|
QVERIFY(unconfinedSpy2.wait());
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
|
|
|
// activate it again, this confines again
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(static_cast<Window *>(input()->pointer()->focus()));
|
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
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
|
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.get(), QSize(1280, 1024), Qt::blue);
|
2016-11-25 06:17:43 +00:00
|
|
|
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());
|
2021-09-03 17:54:03 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-11-25 06:17:43 +00:00
|
|
|
QVERIFY(unconfinedSpy2.wait());
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
|
|
|
// and set a full region again, that should confine
|
|
|
|
confinedPointer->setRegion(nullptr);
|
2021-09-03 17:54:03 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-11-25 06:17:43 +00:00
|
|
|
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.wait());
|
|
|
|
|
|
|
|
// should be unconfined
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
|
|
|
|
|
|
|
// confine again
|
2022-08-01 21:29:02 +00:00
|
|
|
confinedPointer.reset(Test::waylandPointerConstraints()->confinePointer(surface.get(), pointer.get(), nullptr, PointerConstraints::LifeTime::Persistent));
|
|
|
|
QSignalSpy confinedSpy3(confinedPointer.get(), &ConfinedPointer::confined);
|
2018-06-11 20:45:09 +00:00
|
|
|
QVERIFY(confinedSpy3.wait());
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), true);
|
|
|
|
|
2016-11-25 06:17:43 +00:00
|
|
|
// and now unmap
|
|
|
|
shellSurface.reset();
|
|
|
|
surface.reset();
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(Test::waitForWindowDestroyed(window));
|
2016-11-25 06:17:43 +00:00
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
std::unique_ptr<Pointer> pointer(Test::waylandSeat()->createPointer());
|
|
|
|
std::unique_ptr<LockedPointer> lockedPointer(Test::waylandPointerConstraints()->lockPointer(surface.get(), pointer.get(), nullptr, PointerConstraints::LifeTime::OneShot));
|
|
|
|
QSignalSpy lockedSpy(lockedPointer.get(), &LockedPointer::locked);
|
|
|
|
QSignalSpy unlockedSpy(lockedPointer.get(), &LockedPointer::unlocked);
|
2016-11-25 06:17:43 +00:00
|
|
|
|
|
|
|
// now map the window
|
2022-08-01 21:29:02 +00:00
|
|
|
auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 100), Qt::blue);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
QVERIFY(!window->frameGeometry().contains(KWin::Cursors::self()->mouse()->pos()));
|
2016-11-25 06:17:43 +00:00
|
|
|
|
|
|
|
// now let's lock
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
2022-04-23 19:51:16 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(window->frameGeometry().center());
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), window->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
|
2022-04-23 19:51:16 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(window->frameGeometry().center() + QPoint(1, 1));
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), window->frameGeometry().center());
|
2016-11-25 06:17:43 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// deactivate the window, this should unlock
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(nullptr);
|
2016-11-25 06:17:43 +00:00
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
|
|
|
QVERIFY(unlockedSpy.wait());
|
|
|
|
|
|
|
|
// moving cursor should be allowed again
|
2022-04-23 19:51:16 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(window->frameGeometry().center() + QPoint(1, 1));
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), window->frameGeometry().center() + QPoint(1, 1));
|
2018-06-11 20:45:09 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
lockedPointer.reset(Test::waylandPointerConstraints()->lockPointer(surface.get(), pointer.get(), nullptr, PointerConstraints::LifeTime::Persistent));
|
|
|
|
QSignalSpy lockedSpy2(lockedPointer.get(), &LockedPointer::locked);
|
2018-09-02 23:00:29 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// activate the window again, this should lock again
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(static_cast<Window *>(input()->pointer()->focus()));
|
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);
|
2022-04-23 19:51:16 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(window->frameGeometry().center());
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), window->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.wait());
|
|
|
|
|
|
|
|
// moving cursor should be allowed again
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
2022-04-23 19:51:16 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(window->frameGeometry().center());
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), window->frameGeometry().center());
|
2016-11-25 06:17:43 +00:00
|
|
|
}
|
|
|
|
|
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
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
std::unique_ptr<Pointer> pointer(Test::waylandSeat()->createPointer());
|
|
|
|
std::unique_ptr<LockedPointer> lockedPointer(Test::waylandPointerConstraints()->lockPointer(surface.get(), pointer.get(), nullptr, PointerConstraints::LifeTime::OneShot));
|
|
|
|
QSignalSpy lockedSpy(lockedPointer.get(), &LockedPointer::locked);
|
|
|
|
QSignalSpy unlockedSpy(lockedPointer.get(), &LockedPointer::unlocked);
|
2017-06-24 18:31:50 +00:00
|
|
|
|
|
|
|
// now map the window
|
2022-08-01 21:29:02 +00:00
|
|
|
auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 100), Qt::blue);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
QVERIFY(!window->frameGeometry().contains(KWin::Cursors::self()->mouse()->pos()));
|
2017-06-24 18:31:50 +00:00
|
|
|
|
|
|
|
// now let's lock
|
|
|
|
QCOMPARE(input()->pointer()->isConstrained(), false);
|
2022-04-23 19:51:16 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(window->frameGeometry().center());
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), window->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"
|