Commit 729601ba authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

Port pointer-constraints-v1 to the new design

parent 0265c55f
......@@ -17,7 +17,7 @@
// server
#include "../../src/server/display.h"
#include "../../src/server/compositor_interface.h"
#include "../../src/server/pointerconstraints_interface.h"
#include "../../src/server/pointerconstraints_v1_interface.h"
#include "../../src/server/seat_interface.h"
#include "../../src/server/surface_interface.h"
......@@ -25,8 +25,8 @@ using namespace KWayland::Client;
using namespace KWaylandServer;
Q_DECLARE_METATYPE(KWayland::Client::PointerConstraints::LifeTime)
Q_DECLARE_METATYPE(KWaylandServer::ConfinedPointerInterface::LifeTime)
Q_DECLARE_METATYPE(KWaylandServer::LockedPointerInterface::LifeTime)
Q_DECLARE_METATYPE(KWaylandServer::ConfinedPointerV1Interface::LifeTime)
Q_DECLARE_METATYPE(KWaylandServer::LockedPointerV1Interface::LifeTime)
class TestPointerConstraints : public QObject
{
......@@ -47,7 +47,7 @@ private:
Display *m_display = nullptr;
CompositorInterface *m_compositorInterface = nullptr;
SeatInterface *m_seatInterface = nullptr;
PointerConstraintsInterface *m_pointerConstraintsInterface = nullptr;
PointerConstraintsV1Interface *m_pointerConstraintsInterface = nullptr;
ConnectionThread *m_connection = nullptr;
QThread *m_thread = nullptr;
EventQueue *m_queue = nullptr;
......@@ -71,8 +71,7 @@ void TestPointerConstraints::init()
m_seatInterface->setHasPointer(true);
m_seatInterface->create();
m_compositorInterface = m_display->createCompositor(m_display);
m_pointerConstraintsInterface = m_display->createPointerConstraints(PointerConstraintsInterfaceVersion::UnstableV1, m_display);
m_pointerConstraintsInterface->create();
m_pointerConstraintsInterface = m_display->createPointerConstraintsV1(m_display);
// setup connection
m_connection = new KWayland::Client::ConnectionThread;
......@@ -153,12 +152,12 @@ void TestPointerConstraints::cleanup()
void TestPointerConstraints::testLockPointer_data()
{
QTest::addColumn<PointerConstraints::LifeTime>("clientLifeTime");
QTest::addColumn<LockedPointerInterface::LifeTime>("serverLifeTime");
QTest::addColumn<LockedPointerV1Interface::LifeTime>("serverLifeTime");
QTest::addColumn<bool>("hasConstraintAfterUnlock");
QTest::addColumn<int>("pointerChangedCount");
QTest::newRow("persistent") << PointerConstraints::LifeTime::Persistent << LockedPointerInterface::LifeTime::Persistent << true << 1;
QTest::newRow("oneshot") << PointerConstraints::LifeTime::OneShot << LockedPointerInterface::LifeTime::OneShot << false << 2;
QTest::newRow("persistent") << PointerConstraints::LifeTime::Persistent << LockedPointerV1Interface::LifeTime::Persistent << true << 1;
QTest::newRow("oneshot") << PointerConstraints::LifeTime::OneShot << LockedPointerV1Interface::LifeTime::OneShot << false << 2;
}
void TestPointerConstraints::testLockPointer()
......@@ -173,8 +172,8 @@ void TestPointerConstraints::testLockPointer()
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface*>();
QVERIFY(serverSurface);
QVERIFY(serverSurface->lockedPointer().isNull());
QVERIFY(serverSurface->confinedPointer().isNull());
QVERIFY(!serverSurface->lockedPointer());
QVERIFY(!serverSurface->confinedPointer());
// now create the locked pointer
QSignalSpy pointerConstraintsChangedSpy(serverSurface, &SurfaceInterface::pointerConstraintsChanged);
......@@ -190,20 +189,20 @@ void TestPointerConstraints::testLockPointer()
auto serverLockedPointer = serverSurface->lockedPointer();
QVERIFY(serverLockedPointer);
QVERIFY(serverSurface->confinedPointer().isNull());
QVERIFY(!serverSurface->confinedPointer());
QCOMPARE(serverLockedPointer->isLocked(), false);
QCOMPARE(serverLockedPointer->region(), QRegion());
QFETCH(LockedPointerInterface::LifeTime, serverLifeTime);
QFETCH(LockedPointerV1Interface::LifeTime, serverLifeTime);
QCOMPARE(serverLockedPointer->lifeTime(), serverLifeTime);
// setting to unlocked now should not trigger an unlocked spy
serverLockedPointer->setLocked(false);
QVERIFY(!unlockedSpy.wait(500));
// try setting a region
QSignalSpy destroyedSpy(serverLockedPointer.data(), &QObject::destroyed);
QSignalSpy destroyedSpy(serverLockedPointer, &QObject::destroyed);
QVERIFY(destroyedSpy.isValid());
QSignalSpy regionChangedSpy(serverLockedPointer.data(), &LockedPointerInterface::regionChanged);
QSignalSpy regionChangedSpy(serverLockedPointer, &LockedPointerV1Interface::regionChanged);
QVERIFY(regionChangedSpy.isValid());
lockedPointer->setRegion(m_compositor->createRegion(QRegion(0, 5, 10, 20), m_compositor));
// it's double buffered
......@@ -218,7 +217,7 @@ void TestPointerConstraints::testLockPointer()
QCOMPARE(serverLockedPointer->region(), QRegion());
// let's lock the surface
QSignalSpy lockedChangedSpy(serverLockedPointer.data(), &LockedPointerInterface::lockedChanged);
QSignalSpy lockedChangedSpy(serverLockedPointer, &LockedPointerV1Interface::lockedChanged);
QVERIFY(lockedChangedSpy.isValid());
m_seatInterface->setFocusedPointerSurface(serverSurface);
QSignalSpy pointerMotionSpy(m_pointer, &Pointer::motion);
......@@ -236,7 +235,7 @@ void TestPointerConstraints::testLockPointer()
QVERIFY(unlockedSpy.isEmpty());
const QPointF hint = QPointF(1.5, 0.5);
QSignalSpy hintChangedSpy(serverLockedPointer.data(), &LockedPointerInterface::cursorPositionHintChanged);
QSignalSpy hintChangedSpy(serverLockedPointer, &LockedPointerV1Interface::cursorPositionHintChanged);
lockedPointer->setCursorPositionHint(hint);
QCOMPARE(serverLockedPointer->cursorPositionHint(), QPointF(-1., -1.));
surface->commit(Surface::CommitFlag::None);
......@@ -248,7 +247,7 @@ void TestPointerConstraints::testLockPointer()
QCOMPARE(serverLockedPointer->isLocked(), false);
QCOMPARE(serverLockedPointer->cursorPositionHint(), QPointF(-1., -1.));
QCOMPARE(lockedChangedSpy.count(), 2);
QTEST(!serverSurface->lockedPointer().isNull(), "hasConstraintAfterUnlock");
QTEST(bool(serverSurface->lockedPointer()), "hasConstraintAfterUnlock");
QTEST(pointerConstraintsChangedSpy.count(), "pointerChangedCount");
QVERIFY(unlockedSpy.wait());
QCOMPARE(unlockedSpy.count(), 1);
......@@ -267,12 +266,12 @@ void TestPointerConstraints::testLockPointer()
void TestPointerConstraints::testConfinePointer_data()
{
QTest::addColumn<PointerConstraints::LifeTime>("clientLifeTime");
QTest::addColumn<ConfinedPointerInterface::LifeTime>("serverLifeTime");
QTest::addColumn<ConfinedPointerV1Interface::LifeTime>("serverLifeTime");
QTest::addColumn<bool>("hasConstraintAfterUnlock");
QTest::addColumn<int>("pointerChangedCount");
QTest::newRow("persistent") << PointerConstraints::LifeTime::Persistent << ConfinedPointerInterface::LifeTime::Persistent << true << 1;
QTest::newRow("oneshot") << PointerConstraints::LifeTime::OneShot << ConfinedPointerInterface::LifeTime::OneShot << false << 2;
QTest::newRow("persistent") << PointerConstraints::LifeTime::Persistent << ConfinedPointerV1Interface::LifeTime::Persistent << true << 1;
QTest::newRow("oneshot") << PointerConstraints::LifeTime::OneShot << ConfinedPointerV1Interface::LifeTime::OneShot << false << 2;
}
void TestPointerConstraints::testConfinePointer()
......@@ -287,8 +286,8 @@ void TestPointerConstraints::testConfinePointer()
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface*>();
QVERIFY(serverSurface);
QVERIFY(serverSurface->lockedPointer().isNull());
QVERIFY(serverSurface->confinedPointer().isNull());
QVERIFY(!serverSurface->lockedPointer());
QVERIFY(!serverSurface->confinedPointer());
// now create the confined pointer
QSignalSpy pointerConstraintsChangedSpy(serverSurface, &SurfaceInterface::pointerConstraintsChanged);
......@@ -304,20 +303,20 @@ void TestPointerConstraints::testConfinePointer()
auto serverConfinedPointer = serverSurface->confinedPointer();
QVERIFY(serverConfinedPointer);
QVERIFY(serverSurface->lockedPointer().isNull());
QVERIFY(!serverSurface->lockedPointer());
QCOMPARE(serverConfinedPointer->isConfined(), false);
QCOMPARE(serverConfinedPointer->region(), QRegion());
QFETCH(ConfinedPointerInterface::LifeTime, serverLifeTime);
QFETCH(ConfinedPointerV1Interface::LifeTime, serverLifeTime);
QCOMPARE(serverConfinedPointer->lifeTime(), serverLifeTime);
// setting to unconfined now should not trigger an unconfined spy
serverConfinedPointer->setConfined(false);
QVERIFY(!unconfinedSpy.wait(500));
// try setting a region
QSignalSpy destroyedSpy(serverConfinedPointer.data(), &QObject::destroyed);
QSignalSpy destroyedSpy(serverConfinedPointer, &QObject::destroyed);
QVERIFY(destroyedSpy.isValid());
QSignalSpy regionChangedSpy(serverConfinedPointer.data(), &ConfinedPointerInterface::regionChanged);
QSignalSpy regionChangedSpy(serverConfinedPointer, &ConfinedPointerV1Interface::regionChanged);
QVERIFY(regionChangedSpy.isValid());
confinedPointer->setRegion(m_compositor->createRegion(QRegion(0, 5, 10, 20), m_compositor));
// it's double buffered
......@@ -332,7 +331,7 @@ void TestPointerConstraints::testConfinePointer()
QCOMPARE(serverConfinedPointer->region(), QRegion());
// let's confine the surface
QSignalSpy confinedChangedSpy(serverConfinedPointer.data(), &ConfinedPointerInterface::confinedChanged);
QSignalSpy confinedChangedSpy(serverConfinedPointer, &ConfinedPointerV1Interface::confinedChanged);
QVERIFY(confinedChangedSpy.isValid());
m_seatInterface->setFocusedPointerSurface(serverSurface);
serverConfinedPointer->setConfined(true);
......@@ -346,7 +345,7 @@ void TestPointerConstraints::testConfinePointer()
serverConfinedPointer->setConfined(false);
QCOMPARE(serverConfinedPointer->isConfined(), false);
QCOMPARE(confinedChangedSpy.count(), 2);
QTEST(!serverSurface->confinedPointer().isNull(), "hasConstraintAfterUnlock");
QTEST(bool(serverSurface->confinedPointer()), "hasConstraintAfterUnlock");
QTEST(pointerConstraintsChangedSpy.count(), "pointerChangedCount");
QVERIFY(unconfinedSpy.wait());
QCOMPARE(unconfinedSpy.count(), 1);
......
......@@ -37,8 +37,7 @@ set(SERVER_LIB_SRCS
plasmavirtualdesktop_interface.cpp
plasmawindowmanagement_interface.cpp
pointer_interface.cpp
pointerconstraints_interface.cpp
pointerconstraints_interface_v1.cpp
pointerconstraints_v1_interface.cpp
pointergestures_v1_interface.cpp
primaryselectiondevice_v1_interface.cpp
primaryselectiondevicemanager_v1_interface.cpp
......@@ -175,7 +174,7 @@ ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
BASENAME pointer-gestures-unstable-v1
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${WaylandProtocols_DATADIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml
BASENAME pointer-constraints-unstable-v1
)
......@@ -409,7 +408,7 @@ set(SERVER_LIB_HEADERS
plasmavirtualdesktop_interface.h
plasmawindowmanagement_interface.h
pointer_interface.h
pointerconstraints_interface.h
pointerconstraints_v1_interface.h
pointergestures_v1_interface.h
primaryselectiondevicemanager_v1_interface.h
region_interface.h
......
......@@ -28,7 +28,7 @@
#include "plasmashell_interface.h"
#include "plasmavirtualdesktop_interface.h"
#include "plasmawindowmanagement_interface.h"
#include "pointerconstraints_interface_p.h"
#include "pointerconstraints_v1_interface_p.h"
#include "pointergestures_v1_interface.h"
#include "primaryselectiondevicemanager_v1_interface.h"
#include "relativepointer_v1_interface.h"
......@@ -380,14 +380,9 @@ PointerGesturesV1Interface *Display::createPointerGesturesV1(QObject *parent)
return p;
}
PointerConstraintsInterface *Display::createPointerConstraints(const PointerConstraintsInterfaceVersion &version, QObject *parent)
PointerConstraintsV1Interface *Display::createPointerConstraintsV1(QObject *parent)
{
PointerConstraintsInterface *p = nullptr;
switch (version) {
case PointerConstraintsInterfaceVersion::UnstableV1:
p = new PointerConstraintsUnstableV1Interface(this, parent);
break;
}
PointerConstraintsV1Interface *p = new PointerConstraintsV1Interface(this, parent);
connect(this, &Display::aboutToTerminate, p, [p] { delete p; });
return p;
}
......
......@@ -59,8 +59,7 @@ class TextInputManagerV3Interface;
class XdgShellInterface;
class RelativePointerManagerV1Interface;
class PointerGesturesV1Interface;
enum class PointerConstraintsInterfaceVersion;
class PointerConstraintsInterface;
class PointerConstraintsV1Interface;
class XdgForeignV2Interface;
class AppMenuManagerInterface;
class ServerSideDecorationPaletteManagerInterface;
......@@ -228,12 +227,12 @@ public:
PointerGesturesV1Interface *createPointerGesturesV1(QObject *parent = nullptr);
/**
* Creates the PointerConstraintsInterface in interface @p version
* Creates the PointerConstraintsV1Interface
*
* @returns The created manager object
* @since 5.29
**/
PointerConstraintsInterface *createPointerConstraints(const PointerConstraintsInterfaceVersion &version, QObject *parent = nullptr);
PointerConstraintsV1Interface *createPointerConstraintsV1(QObject *parent = nullptr);
/**
* Creates the XdgForeignV2Interface in interface @p version
......
......@@ -5,7 +5,7 @@
*/
#include "pointer_interface.h"
#include "pointer_interface_p.h"
#include "pointerconstraints_interface.h"
#include "pointerconstraints_v1_interface.h"
#include "pointergestures_v1_interface_p.h"
#include "resource_p.h"
#include "relativepointer_v1_interface_p.h"
......@@ -220,7 +220,7 @@ PointerInterface::PointerInterface(SeatInterface *parent, wl_resource *parentRes
return;
}
}
if (!d->focusedSurface->lockedPointer().isNull() && d->focusedSurface->lockedPointer()->isLocked()) {
if (d->focusedSurface->lockedPointer() && d->focusedSurface->lockedPointer()->isLocked()) {
return;
}
const QPointF pos = d->seat->focusedPointerSurfaceTransformation().map(d->seat->pointerPos());
......
/*
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "pointerconstraints_interface_p.h"
#include <functional>
namespace KWaylandServer
{
PointerConstraintsInterface::Private::Private(PointerConstraintsInterfaceVersion interfaceVersion, PointerConstraintsInterface *q, Display *d, const wl_interface *interface, quint32 version)
: Global::Private(d, interface, version)
, interfaceVersion(interfaceVersion)
, q(q)
{
}
PointerConstraintsInterface::PointerConstraintsInterface(Private *d, QObject *parent)
: Global(d, parent)
{
}
PointerConstraintsInterface::~PointerConstraintsInterface() = default;
PointerConstraintsInterfaceVersion PointerConstraintsInterface::interfaceVersion() const
{
Q_D();
return d->interfaceVersion;
}
PointerConstraintsInterface::Private *PointerConstraintsInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
}
LockedPointerInterface::Private::Private(PointerConstraintsInterfaceVersion interfaceVersion, LockedPointerInterface *q, Global *c, wl_resource *parentResource, const wl_interface *interface, const void *implementation)
: Resource::Private(q, c, parentResource, interface, implementation)
, interfaceVersion(interfaceVersion)
{
}
LockedPointerInterface::Private::~Private()
{
if (resource) {
wl_resource_destroy(resource);
resource = nullptr;
}
}
void LockedPointerInterface::Private::commit()
{
if (regionIsSet) {
region = pendingRegion;
pendingRegion = QRegion();
regionIsSet = false;
emit q_func()->regionChanged();
}
if (hintIsSet) {
hint = pendingHint;
hintIsSet = false;
emit q_func()->cursorPositionHintChanged();
}
}
LockedPointerInterface::LockedPointerInterface(Private *p, QObject *parent)
: Resource(p, parent)
{
connect(this, &LockedPointerInterface::unbound, this, [this]() { setLocked(false); });
}
LockedPointerInterface::~LockedPointerInterface() = default;
PointerConstraintsInterfaceVersion LockedPointerInterface::interfaceVersion() const
{
Q_D();
return d->interfaceVersion;
}
LockedPointerInterface::LifeTime LockedPointerInterface::lifeTime() const
{
Q_D();
return d->lifeTime;
}
QRegion LockedPointerInterface::region() const
{
Q_D();
return d->region;
}
QPointF LockedPointerInterface::cursorPositionHint() const
{
Q_D();
return d->hint;
}
bool LockedPointerInterface::isLocked() const
{
Q_D();
return d->locked;
}
void LockedPointerInterface::setLocked(bool locked)
{
Q_D();
if (locked == d->locked) {
return;
}
if (!locked) {
d->hint = QPointF(-1., -1.);
}
d->locked = locked;
d->updateLocked();
emit lockedChanged();
}
LockedPointerInterface::Private *LockedPointerInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
}
ConfinedPointerInterface::Private::Private(PointerConstraintsInterfaceVersion interfaceVersion, ConfinedPointerInterface *q, Global *c, wl_resource *parentResource, const wl_interface *interface, const void *implementation)
: Resource::Private(q, c, parentResource, interface, implementation)
, interfaceVersion(interfaceVersion)
{
}
ConfinedPointerInterface::Private::~Private()
{
if (resource) {
wl_resource_destroy(resource);
resource = nullptr;
}
}
void ConfinedPointerInterface::Private::commit()
{
if (!regionIsSet) {
return;
}
region = pendingRegion;
pendingRegion = QRegion();
regionIsSet = false;
emit q_func()->regionChanged();
}
ConfinedPointerInterface::ConfinedPointerInterface(Private *p, QObject *parent)
: Resource(p, parent)
{
connect(this, &ConfinedPointerInterface::unbound, this, [this]() { setConfined(false); });
}
ConfinedPointerInterface::~ConfinedPointerInterface() = default;
PointerConstraintsInterfaceVersion ConfinedPointerInterface::interfaceVersion() const
{
Q_D();
return d->interfaceVersion;
}
ConfinedPointerInterface::LifeTime ConfinedPointerInterface::lifeTime() const
{
Q_D();
return d->lifeTime;
}
QRegion ConfinedPointerInterface::region() const
{
Q_D();
return d->region;
}
bool ConfinedPointerInterface::isConfined() const
{
Q_D();
return d->confined;
}
void ConfinedPointerInterface::setConfined(bool confined)
{
Q_D();
if (confined == d->confined) {
return;
}
d->confined = confined;
d->updateConfined();
emit confinedChanged();
}
ConfinedPointerInterface::Private *ConfinedPointerInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
}
}
/*
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef KWAYLAND_SERVER_POINTERCONSTRAINTS_INTERFACE_P_H
#define KWAYLAND_SERVER_POINTERCONSTRAINTS_INTERFACE_P_H
#include "pointerconstraints_interface.h"
#include "global_p.h"
#include "resource_p.h"
#include <QRegion>
namespace KWaylandServer
{
class PointerConstraintsInterface::Private : public Global::Private
{
public:
PointerConstraintsInterfaceVersion interfaceVersion;
protected:
Private(PointerConstraintsInterfaceVersion interfaceVersion, PointerConstraintsInterface *q, Display *d, const wl_interface *interface, quint32 version);
PointerConstraintsInterface *q;
};
class PointerConstraintsUnstableV1Interface : public PointerConstraintsInterface
{
Q_OBJECT
public:
explicit PointerConstraintsUnstableV1Interface(Display *display, QObject *parent = nullptr);
virtual ~PointerConstraintsUnstableV1Interface();
private:
class Private;
};
class LockedPointerInterface::Private : public Resource::Private
{
public:
~Private();
virtual void updateLocked() = 0;
void commit();
PointerConstraintsInterfaceVersion interfaceVersion;
LifeTime lifeTime;
QRegion region;
bool locked = false;
QPointF hint = QPointF(-1., -1.);
protected:
Private(PointerConstraintsInterfaceVersion interfaceVersion, LockedPointerInterface *q, Global *c, wl_resource *parentResource, const wl_interface *interface, const void *implementation);
QRegion pendingRegion;
bool regionIsSet = false;
QPointF pendingHint;
bool hintIsSet = false;
private:
LockedPointerInterface *q_func() {
return reinterpret_cast<LockedPointerInterface *>(q);
}
};
class LockedPointerUnstableV1Interface : public LockedPointerInterface
{
Q_OBJECT
public:
explicit LockedPointerUnstableV1Interface(PointerConstraintsUnstableV1Interface *parent, wl_resource *parentResource);
virtual ~LockedPointerUnstableV1Interface();
private:
class Private;
Private *d_func() const;
friend class PointerConstraintsUnstableV1Interface;
};
class ConfinedPointerInterface::Private : public Resource::Private
{
public:
~Private();
virtual void updateConfined() = 0;
void commit();
PointerConstraintsInterfaceVersion interfaceVersion;
LifeTime lifeTime;
QRegion region;
bool confined = false;
protected:
Private(PointerConstraintsInterfaceVersion interfaceVersion, ConfinedPointerInterface *q, Global *c, wl_resource *parentResource, const wl_interface *interface, const void *implementation);
QRegion pendingRegion;
bool regionIsSet = false;
private:
ConfinedPointerInterface *q_func() {
return reinterpret_cast<ConfinedPointerInterface *>(q);
}
};
class ConfinedPointerUnstableV1Interface : public ConfinedPointerInterface
{
Q_OBJECT
public:
explicit ConfinedPointerUnstableV1Interface(PointerConstraintsUnstableV1Interface *parent, wl_resource *parentResource);
virtual ~ConfinedPointerUnstableV1Interface();
private:
class Private;
Private *d_func() const;
friend class PointerConstraintsUnstableV1Interface;
};
}
#endif
/*
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>