2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-11-08 13:17:15 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
// Qt
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2016-11-08 13:17:15 +00:00
|
|
|
// client
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/compositor.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "KWayland/Client/connection_thread.h"
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/event_queue.h"
|
|
|
|
#include "KWayland/Client/pointer.h"
|
|
|
|
#include "KWayland/Client/pointerconstraints.h"
|
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/seat.h"
|
2023-05-11 20:22:02 +00:00
|
|
|
#include "KWayland/Client/shm_pool.h"
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/surface.h"
|
2016-11-08 13:17:15 +00:00
|
|
|
// server
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/compositor.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/display.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/pointerconstraints_v1.h"
|
|
|
|
#include "wayland/seat.h"
|
|
|
|
#include "wayland/surface.h"
|
2016-11-08 13:17:15 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(KWayland::Client::PointerConstraints::LifeTime)
|
2023-09-13 17:59:29 +00:00
|
|
|
Q_DECLARE_METATYPE(KWin::ConfinedPointerV1Interface::LifeTime)
|
|
|
|
Q_DECLARE_METATYPE(KWin::LockedPointerV1Interface::LifeTime)
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
class TestPointerConstraints : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testLockPointer_data();
|
|
|
|
void testLockPointer();
|
|
|
|
|
|
|
|
void testConfinePointer_data();
|
|
|
|
void testConfinePointer();
|
|
|
|
void testAlreadyConstrained_data();
|
|
|
|
void testAlreadyConstrained();
|
|
|
|
|
|
|
|
private:
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display *m_display = nullptr;
|
2016-11-08 13:17:15 +00:00
|
|
|
CompositorInterface *m_compositorInterface = nullptr;
|
|
|
|
SeatInterface *m_seatInterface = nullptr;
|
2020-11-03 18:44:32 +00:00
|
|
|
PointerConstraintsV1Interface *m_pointerConstraintsInterface = nullptr;
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection = nullptr;
|
2016-11-08 13:17:15 +00:00
|
|
|
QThread *m_thread = nullptr;
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::EventQueue *m_queue = nullptr;
|
|
|
|
KWayland::Client::Compositor *m_compositor = nullptr;
|
|
|
|
KWayland::Client::Seat *m_seat = nullptr;
|
2023-05-11 20:22:02 +00:00
|
|
|
KWayland::Client::ShmPool *m_shm = nullptr;
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Pointer *m_pointer = nullptr;
|
|
|
|
KWayland::Client::PointerConstraints *m_pointerConstraints = nullptr;
|
2016-11-08 13:17:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwayland-test-pointer_constraint-0");
|
|
|
|
|
|
|
|
void TestPointerConstraints::init()
|
|
|
|
{
|
|
|
|
delete m_display;
|
2023-09-13 17:59:29 +00:00
|
|
|
m_display = new KWin::Display(this);
|
2020-10-19 15:52:56 +00:00
|
|
|
m_display->addSocketName(s_socketName);
|
2016-11-08 13:17:15 +00:00
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
m_display->createShm();
|
2020-12-09 20:13:19 +00:00
|
|
|
m_seatInterface = new SeatInterface(m_display, m_display);
|
2016-11-08 13:17:15 +00:00
|
|
|
m_seatInterface->setHasPointer(true);
|
2020-12-09 20:13:19 +00:00
|
|
|
m_compositorInterface = new CompositorInterface(m_display, m_display);
|
|
|
|
m_pointerConstraintsInterface = new PointerConstraintsV1Interface(m_display, m_display);
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
// setup connection
|
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
|
2016-11-08 13:17:15 +00:00
|
|
|
m_connection->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_connection->moveToThread(m_thread);
|
|
|
|
m_thread->start();
|
|
|
|
|
|
|
|
m_connection->initConnection();
|
|
|
|
QVERIFY(connectedSpy.wait());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
m_queue = new KWayland::Client::EventQueue(this);
|
2016-11-08 13:17:15 +00:00
|
|
|
m_queue->setup(m_connection);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Registry registry;
|
|
|
|
QSignalSpy interfacesAnnouncedSpy(®istry, &KWayland::Client::Registry::interfacesAnnounced);
|
|
|
|
QSignalSpy interfaceAnnouncedSpy(®istry, &KWayland::Client::Registry::interfaceAnnounced);
|
2016-11-08 13:17:15 +00:00
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
registry.create(m_connection);
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(interfacesAnnouncedSpy.wait());
|
|
|
|
|
2023-05-11 20:22:02 +00:00
|
|
|
m_shm = new KWayland::Client::ShmPool(this);
|
|
|
|
m_shm->setup(registry.bindShm(registry.interface(KWayland::Client::Registry::Interface::Shm).name,
|
|
|
|
registry.interface(KWayland::Client::Registry::Interface::Shm).version));
|
|
|
|
QVERIFY(m_shm->isValid());
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
m_compositor =
|
2022-11-08 21:15:17 +00:00
|
|
|
registry.createCompositor(registry.interface(KWayland::Client::Registry::Interface::Compositor).name, registry.interface(KWayland::Client::Registry::Interface::Compositor).version, this);
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(m_compositor);
|
|
|
|
QVERIFY(m_compositor->isValid());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
m_pointerConstraints = registry.createPointerConstraints(registry.interface(KWayland::Client::Registry::Interface::PointerConstraintsUnstableV1).name,
|
|
|
|
registry.interface(KWayland::Client::Registry::Interface::PointerConstraintsUnstableV1).version,
|
2021-08-29 05:11:06 +00:00
|
|
|
this);
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(m_pointerConstraints);
|
|
|
|
QVERIFY(m_pointerConstraints->isValid());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
m_seat = registry.createSeat(registry.interface(KWayland::Client::Registry::Interface::Seat).name, registry.interface(KWayland::Client::Registry::Interface::Seat).version, this);
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(m_seat);
|
|
|
|
QVERIFY(m_seat->isValid());
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy pointerChangedSpy(m_seat, &KWayland::Client::Seat::hasPointerChanged);
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(pointerChangedSpy.wait());
|
|
|
|
m_pointer = m_seat->createPointer(this);
|
|
|
|
QVERIFY(m_pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::cleanup()
|
|
|
|
{
|
2022-04-19 10:14:26 +00:00
|
|
|
#define CLEANUP(variable) \
|
|
|
|
if (variable) { \
|
|
|
|
delete variable; \
|
|
|
|
variable = nullptr; \
|
2016-11-08 13:17:15 +00:00
|
|
|
}
|
|
|
|
CLEANUP(m_compositor)
|
|
|
|
CLEANUP(m_pointerConstraints)
|
|
|
|
CLEANUP(m_pointer)
|
2023-05-11 20:22:02 +00:00
|
|
|
CLEANUP(m_shm)
|
2016-11-08 13:17:15 +00:00
|
|
|
CLEANUP(m_seat)
|
|
|
|
CLEANUP(m_queue)
|
|
|
|
if (m_connection) {
|
|
|
|
m_connection->deleteLater();
|
|
|
|
m_connection = nullptr;
|
|
|
|
}
|
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CLEANUP(m_display)
|
|
|
|
#undef CLEANUP
|
2020-10-30 13:36:24 +00:00
|
|
|
|
|
|
|
// these are the children of the display
|
|
|
|
m_compositorInterface = nullptr;
|
|
|
|
m_seatInterface = nullptr;
|
|
|
|
m_pointerConstraintsInterface = nullptr;
|
2016-11-08 13:17:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::testLockPointer_data()
|
|
|
|
{
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::addColumn<KWayland::Client::PointerConstraints::LifeTime>("clientLifeTime");
|
2020-11-03 18:44:32 +00:00
|
|
|
QTest::addColumn<LockedPointerV1Interface::LifeTime>("serverLifeTime");
|
2016-11-08 13:17:15 +00:00
|
|
|
QTest::addColumn<bool>("hasConstraintAfterUnlock");
|
|
|
|
QTest::addColumn<int>("pointerChangedCount");
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("persistent") << KWayland::Client::PointerConstraints::LifeTime::Persistent << LockedPointerV1Interface::LifeTime::Persistent << true << 1;
|
|
|
|
QTest::newRow("oneshot") << KWayland::Client::PointerConstraints::LifeTime::OneShot << LockedPointerV1Interface::LifeTime::OneShot << false << 2;
|
2016-11-08 13:17:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::testLockPointer()
|
|
|
|
{
|
|
|
|
// this test verifies the basic interaction for lock pointer
|
|
|
|
// first create a surface
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(surface->isValid());
|
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
|
|
|
|
2023-05-11 20:22:02 +00:00
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::black);
|
|
|
|
surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
surface->damage(image.rect());
|
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(serverSurface);
|
2020-11-03 18:44:32 +00:00
|
|
|
QVERIFY(!serverSurface->lockedPointer());
|
|
|
|
QVERIFY(!serverSurface->confinedPointer());
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
// now create the locked pointer
|
|
|
|
QSignalSpy pointerConstraintsChangedSpy(serverSurface, &SurfaceInterface::pointerConstraintsChanged);
|
2022-11-08 21:15:17 +00:00
|
|
|
QFETCH(KWayland::Client::PointerConstraints::LifeTime, clientLifeTime);
|
|
|
|
std::unique_ptr<KWayland::Client::LockedPointer> lockedPointer(m_pointerConstraints->lockPointer(surface.get(), m_pointer, nullptr, clientLifeTime));
|
|
|
|
QSignalSpy lockedSpy(lockedPointer.get(), &KWayland::Client::LockedPointer::locked);
|
|
|
|
QSignalSpy unlockedSpy(lockedPointer.get(), &KWayland::Client::LockedPointer::unlocked);
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(lockedPointer->isValid());
|
|
|
|
QVERIFY(pointerConstraintsChangedSpy.wait());
|
|
|
|
|
|
|
|
auto serverLockedPointer = serverSurface->lockedPointer();
|
|
|
|
QVERIFY(serverLockedPointer);
|
2020-11-03 18:44:32 +00:00
|
|
|
QVERIFY(!serverSurface->confinedPointer());
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
QCOMPARE(serverLockedPointer->isLocked(), false);
|
2023-05-11 20:22:02 +00:00
|
|
|
QCOMPARE(serverLockedPointer->region(), QRegion(0, 0, 100, 100));
|
2020-11-03 18:44:32 +00:00
|
|
|
QFETCH(LockedPointerV1Interface::LifeTime, serverLifeTime);
|
2016-11-08 13:17:15 +00:00
|
|
|
QCOMPARE(serverLockedPointer->lifeTime(), serverLifeTime);
|
|
|
|
// setting to unlocked now should not trigger an unlocked spy
|
|
|
|
serverLockedPointer->setLocked(false);
|
2018-07-17 09:30:16 +00:00
|
|
|
QVERIFY(!unlockedSpy.wait(500));
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
// try setting a region
|
2020-11-03 18:44:32 +00:00
|
|
|
QSignalSpy destroyedSpy(serverLockedPointer, &QObject::destroyed);
|
|
|
|
QSignalSpy regionChangedSpy(serverLockedPointer, &LockedPointerV1Interface::regionChanged);
|
2016-11-08 13:17:15 +00:00
|
|
|
lockedPointer->setRegion(m_compositor->createRegion(QRegion(0, 5, 10, 20), m_compositor));
|
|
|
|
// it's double buffered
|
2018-07-17 09:30:16 +00:00
|
|
|
QVERIFY(!regionChangedSpy.wait(500));
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(regionChangedSpy.wait());
|
|
|
|
QCOMPARE(serverLockedPointer->region(), QRegion(0, 5, 10, 20));
|
2016-11-25 12:14:14 +00:00
|
|
|
// and unset region again
|
|
|
|
lockedPointer->setRegion(nullptr);
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-11-25 12:14:14 +00:00
|
|
|
QVERIFY(regionChangedSpy.wait());
|
2023-05-11 20:22:02 +00:00
|
|
|
QCOMPARE(serverLockedPointer->region(), QRegion(0, 0, 100, 100));
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
// let's lock the surface
|
2020-11-03 18:44:32 +00:00
|
|
|
QSignalSpy lockedChangedSpy(serverLockedPointer, &LockedPointerV1Interface::lockedChanged);
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(0, 0));
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy pointerMotionSpy(m_pointer, &KWayland::Client::Pointer::motion);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerMotion(QPoint(0, 1));
|
|
|
|
m_seatInterface->notifyPointerFrame();
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(pointerMotionSpy.wait());
|
|
|
|
|
|
|
|
serverLockedPointer->setLocked(true);
|
|
|
|
QCOMPARE(serverLockedPointer->isLocked(), true);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerMotion(QPoint(1, 1));
|
|
|
|
m_seatInterface->notifyPointerFrame();
|
2016-11-08 13:17:15 +00:00
|
|
|
QCOMPARE(lockedChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(pointerMotionSpy.count(), 1);
|
|
|
|
QVERIFY(lockedSpy.isEmpty());
|
|
|
|
QVERIFY(lockedSpy.wait());
|
|
|
|
QVERIFY(unlockedSpy.isEmpty());
|
|
|
|
|
2018-07-23 08:49:08 +00:00
|
|
|
const QPointF hint = QPointF(1.5, 0.5);
|
2020-11-03 18:44:32 +00:00
|
|
|
QSignalSpy hintChangedSpy(serverLockedPointer, &LockedPointerV1Interface::cursorPositionHintChanged);
|
2018-07-23 08:49:08 +00:00
|
|
|
lockedPointer->setCursorPositionHint(hint);
|
|
|
|
QCOMPARE(serverLockedPointer->cursorPositionHint(), QPointF(-1., -1.));
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2018-07-23 08:49:08 +00:00
|
|
|
QVERIFY(hintChangedSpy.wait());
|
|
|
|
QCOMPARE(serverLockedPointer->cursorPositionHint(), hint);
|
|
|
|
|
2016-11-08 13:17:15 +00:00
|
|
|
// and unlock again
|
|
|
|
serverLockedPointer->setLocked(false);
|
|
|
|
QCOMPARE(serverLockedPointer->isLocked(), false);
|
2018-07-23 08:49:08 +00:00
|
|
|
QCOMPARE(serverLockedPointer->cursorPositionHint(), QPointF(-1., -1.));
|
2016-11-08 13:17:15 +00:00
|
|
|
QCOMPARE(lockedChangedSpy.count(), 2);
|
2020-11-03 18:44:32 +00:00
|
|
|
QTEST(bool(serverSurface->lockedPointer()), "hasConstraintAfterUnlock");
|
2022-10-21 15:52:28 +00:00
|
|
|
QFETCH(int, pointerChangedCount);
|
|
|
|
QCOMPARE(pointerConstraintsChangedSpy.count(), pointerChangedCount);
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(unlockedSpy.wait());
|
|
|
|
QCOMPARE(unlockedSpy.count(), 1);
|
|
|
|
QCOMPARE(lockedSpy.count(), 1);
|
|
|
|
|
|
|
|
// now motion should work again
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerMotion(QPoint(0, 1));
|
|
|
|
m_seatInterface->notifyPointerFrame();
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(pointerMotionSpy.wait());
|
|
|
|
QCOMPARE(pointerMotionSpy.count(), 2);
|
|
|
|
|
|
|
|
lockedPointer.reset();
|
|
|
|
QVERIFY(destroyedSpy.wait());
|
|
|
|
QCOMPARE(pointerConstraintsChangedSpy.count(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::testConfinePointer_data()
|
|
|
|
{
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::addColumn<KWayland::Client::PointerConstraints::LifeTime>("clientLifeTime");
|
2020-11-03 18:44:32 +00:00
|
|
|
QTest::addColumn<ConfinedPointerV1Interface::LifeTime>("serverLifeTime");
|
2016-11-08 13:17:15 +00:00
|
|
|
QTest::addColumn<bool>("hasConstraintAfterUnlock");
|
|
|
|
QTest::addColumn<int>("pointerChangedCount");
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("persistent") << KWayland::Client::PointerConstraints::LifeTime::Persistent << ConfinedPointerV1Interface::LifeTime::Persistent << true << 1;
|
|
|
|
QTest::newRow("oneshot") << KWayland::Client::PointerConstraints::LifeTime::OneShot << ConfinedPointerV1Interface::LifeTime::OneShot << false << 2;
|
2016-11-08 13:17:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::testConfinePointer()
|
|
|
|
{
|
|
|
|
// this test verifies the basic interaction for confined pointer
|
|
|
|
// first create a surface
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(surface->isValid());
|
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
|
|
|
|
2023-05-11 20:22:02 +00:00
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::black);
|
|
|
|
surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
surface->damage(image.rect());
|
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(serverSurface);
|
2020-11-03 18:44:32 +00:00
|
|
|
QVERIFY(!serverSurface->lockedPointer());
|
|
|
|
QVERIFY(!serverSurface->confinedPointer());
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
// now create the confined pointer
|
|
|
|
QSignalSpy pointerConstraintsChangedSpy(serverSurface, &SurfaceInterface::pointerConstraintsChanged);
|
2022-11-08 21:15:17 +00:00
|
|
|
QFETCH(KWayland::Client::PointerConstraints::LifeTime, clientLifeTime);
|
|
|
|
std::unique_ptr<KWayland::Client::ConfinedPointer> confinedPointer(m_pointerConstraints->confinePointer(surface.get(), m_pointer, nullptr, clientLifeTime));
|
|
|
|
QSignalSpy confinedSpy(confinedPointer.get(), &KWayland::Client::ConfinedPointer::confined);
|
|
|
|
QSignalSpy unconfinedSpy(confinedPointer.get(), &KWayland::Client::ConfinedPointer::unconfined);
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(confinedPointer->isValid());
|
|
|
|
QVERIFY(pointerConstraintsChangedSpy.wait());
|
|
|
|
|
|
|
|
auto serverConfinedPointer = serverSurface->confinedPointer();
|
|
|
|
QVERIFY(serverConfinedPointer);
|
2020-11-03 18:44:32 +00:00
|
|
|
QVERIFY(!serverSurface->lockedPointer());
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
QCOMPARE(serverConfinedPointer->isConfined(), false);
|
2023-05-11 20:22:02 +00:00
|
|
|
QCOMPARE(serverConfinedPointer->region(), QRegion(0, 0, 100, 100));
|
2020-11-03 18:44:32 +00:00
|
|
|
QFETCH(ConfinedPointerV1Interface::LifeTime, serverLifeTime);
|
2016-11-08 13:17:15 +00:00
|
|
|
QCOMPARE(serverConfinedPointer->lifeTime(), serverLifeTime);
|
|
|
|
// setting to unconfined now should not trigger an unconfined spy
|
|
|
|
serverConfinedPointer->setConfined(false);
|
2018-07-17 09:30:16 +00:00
|
|
|
QVERIFY(!unconfinedSpy.wait(500));
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
// try setting a region
|
2020-11-03 18:44:32 +00:00
|
|
|
QSignalSpy destroyedSpy(serverConfinedPointer, &QObject::destroyed);
|
|
|
|
QSignalSpy regionChangedSpy(serverConfinedPointer, &ConfinedPointerV1Interface::regionChanged);
|
2016-11-08 13:17:15 +00:00
|
|
|
confinedPointer->setRegion(m_compositor->createRegion(QRegion(0, 5, 10, 20), m_compositor));
|
|
|
|
// it's double buffered
|
2018-07-17 09:30:16 +00:00
|
|
|
QVERIFY(!regionChangedSpy.wait(500));
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(regionChangedSpy.wait());
|
|
|
|
QCOMPARE(serverConfinedPointer->region(), QRegion(0, 5, 10, 20));
|
2016-11-25 12:14:14 +00:00
|
|
|
// and unset region again
|
|
|
|
confinedPointer->setRegion(nullptr);
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-11-25 12:14:14 +00:00
|
|
|
QVERIFY(regionChangedSpy.wait());
|
2023-05-11 20:22:02 +00:00
|
|
|
QCOMPARE(serverConfinedPointer->region(), QRegion(0, 0, 100, 100));
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
// let's confine the surface
|
2020-11-03 18:44:32 +00:00
|
|
|
QSignalSpy confinedChangedSpy(serverConfinedPointer, &ConfinedPointerV1Interface::confinedChanged);
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(0, 0));
|
2016-11-08 13:17:15 +00:00
|
|
|
serverConfinedPointer->setConfined(true);
|
|
|
|
QCOMPARE(serverConfinedPointer->isConfined(), true);
|
|
|
|
QCOMPARE(confinedChangedSpy.count(), 1);
|
|
|
|
QVERIFY(confinedSpy.isEmpty());
|
|
|
|
QVERIFY(confinedSpy.wait());
|
|
|
|
QVERIFY(unconfinedSpy.isEmpty());
|
|
|
|
|
|
|
|
// and unconfine again
|
|
|
|
serverConfinedPointer->setConfined(false);
|
|
|
|
QCOMPARE(serverConfinedPointer->isConfined(), false);
|
|
|
|
QCOMPARE(confinedChangedSpy.count(), 2);
|
2020-11-03 18:44:32 +00:00
|
|
|
QTEST(bool(serverSurface->confinedPointer()), "hasConstraintAfterUnlock");
|
2022-10-21 15:52:28 +00:00
|
|
|
QFETCH(int, pointerChangedCount);
|
|
|
|
QCOMPARE(pointerConstraintsChangedSpy.count(), pointerChangedCount);
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(unconfinedSpy.wait());
|
|
|
|
QCOMPARE(unconfinedSpy.count(), 1);
|
|
|
|
QCOMPARE(confinedSpy.count(), 1);
|
|
|
|
|
|
|
|
confinedPointer.reset();
|
|
|
|
QVERIFY(destroyedSpy.wait());
|
|
|
|
QCOMPARE(pointerConstraintsChangedSpy.count(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum class Constraint {
|
|
|
|
Lock,
|
2021-04-29 09:45:00 +00:00
|
|
|
Confine,
|
2016-11-08 13:17:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Constraint)
|
|
|
|
|
|
|
|
void TestPointerConstraints::testAlreadyConstrained_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Constraint>("firstConstraint");
|
|
|
|
QTest::addColumn<Constraint>("secondConstraint");
|
|
|
|
|
|
|
|
QTest::newRow("confine-confine") << Constraint::Confine << Constraint::Confine;
|
|
|
|
QTest::newRow("lock-confine") << Constraint::Lock << Constraint::Confine;
|
|
|
|
QTest::newRow("confine-lock") << Constraint::Confine << Constraint::Lock;
|
|
|
|
QTest::newRow("lock-lock") << Constraint::Lock << Constraint::Lock;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestPointerConstraints::testAlreadyConstrained()
|
|
|
|
{
|
|
|
|
// this test verifies that creating a pointer constraint for an already constrained surface triggers an error
|
|
|
|
// first create a surface
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-11-08 13:17:15 +00:00
|
|
|
QVERIFY(surface->isValid());
|
|
|
|
QFETCH(Constraint, firstConstraint);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::ConfinedPointer> confinedPointer;
|
|
|
|
std::unique_ptr<KWayland::Client::LockedPointer> lockedPointer;
|
2016-11-08 13:17:15 +00:00
|
|
|
switch (firstConstraint) {
|
|
|
|
case Constraint::Lock:
|
2022-11-08 21:15:17 +00:00
|
|
|
lockedPointer.reset(m_pointerConstraints->lockPointer(surface.get(), m_pointer, nullptr, KWayland::Client::PointerConstraints::LifeTime::OneShot));
|
2016-11-08 13:17:15 +00:00
|
|
|
break;
|
|
|
|
case Constraint::Confine:
|
2022-11-08 21:15:17 +00:00
|
|
|
confinedPointer.reset(m_pointerConstraints->confinePointer(surface.get(), m_pointer, nullptr, KWayland::Client::PointerConstraints::LifeTime::OneShot));
|
2016-11-08 13:17:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
QVERIFY(confinedPointer || lockedPointer);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy errorSpy(m_connection, &KWayland::Client::ConnectionThread::errorOccurred);
|
2016-11-08 13:17:15 +00:00
|
|
|
QFETCH(Constraint, secondConstraint);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::ConfinedPointer> confinedPointer2;
|
|
|
|
std::unique_ptr<KWayland::Client::LockedPointer> lockedPointer2;
|
2016-11-08 13:17:15 +00:00
|
|
|
switch (secondConstraint) {
|
|
|
|
case Constraint::Lock:
|
2022-11-08 21:15:17 +00:00
|
|
|
lockedPointer2.reset(m_pointerConstraints->lockPointer(surface.get(), m_pointer, nullptr, KWayland::Client::PointerConstraints::LifeTime::OneShot));
|
2016-11-08 13:17:15 +00:00
|
|
|
break;
|
|
|
|
case Constraint::Confine:
|
2022-11-08 21:15:17 +00:00
|
|
|
confinedPointer2.reset(m_pointerConstraints->confinePointer(surface.get(), m_pointer, nullptr, KWayland::Client::PointerConstraints::LifeTime::OneShot));
|
2016-11-08 13:17:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
QVERIFY(errorSpy.wait());
|
|
|
|
QVERIFY(m_connection->hasError());
|
|
|
|
if (confinedPointer2) {
|
|
|
|
confinedPointer2->destroy();
|
|
|
|
}
|
|
|
|
if (lockedPointer2) {
|
|
|
|
lockedPointer2->destroy();
|
|
|
|
}
|
|
|
|
if (confinedPointer) {
|
|
|
|
confinedPointer->destroy();
|
|
|
|
}
|
|
|
|
if (lockedPointer) {
|
|
|
|
lockedPointer->destroy();
|
|
|
|
}
|
|
|
|
surface->destroy();
|
|
|
|
m_compositor->destroy();
|
|
|
|
m_pointerConstraints->destroy();
|
|
|
|
m_pointer->destroy();
|
|
|
|
m_seat->destroy();
|
|
|
|
m_queue->destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(TestPointerConstraints)
|
|
|
|
#include "test_pointer_constraints.moc"
|