Commit 6cdb8101 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

Port pointer-gestures-v1 interface to the new design

parent c69afd76
......@@ -30,7 +30,7 @@
#include "../../src/server/display.h"
#include "../../src/server/keyboard_interface.h"
#include "../../src/server/pointer_interface.h"
#include "../../src/server/pointergestures_interface.h"
#include "../../src/server/pointergestures_v1_interface.h"
#include "../../src/server/relativepointer_v1_interface.h"
#include "../../src/server/seat_interface.h"
#include "../../src/server/subcompositor_interface.h"
......@@ -84,7 +84,7 @@ private:
KWaylandServer::SeatInterface *m_seatInterface;
KWaylandServer::SubCompositorInterface *m_subCompositorInterface;
KWaylandServer::RelativePointerManagerV1Interface *m_relativePointerManagerV1Interface;
KWaylandServer::PointerGesturesInterface *m_pointerGesturesInterface;
KWaylandServer::PointerGesturesV1Interface *m_pointerGesturesV1Interface;
KWayland::Client::ConnectionThread *m_connection;
KWayland::Client::Compositor *m_compositor;
KWayland::Client::Seat *m_seat;
......@@ -105,7 +105,7 @@ TestWaylandSeat::TestWaylandSeat(QObject *parent)
, m_seatInterface(nullptr)
, m_subCompositorInterface(nullptr)
, m_relativePointerManagerV1Interface(nullptr)
, m_pointerGesturesInterface(nullptr)
, m_pointerGesturesV1Interface(nullptr)
, m_connection(nullptr)
, m_compositor(nullptr)
, m_seat(nullptr)
......@@ -133,10 +133,7 @@ void TestWaylandSeat::init()
QVERIFY(m_subCompositorInterface);
m_relativePointerManagerV1Interface = m_display->createRelativePointerManagerV1(m_display);
m_pointerGesturesInterface = m_display->createPointerGestures(PointerGesturesInterfaceVersion::UnstableV1, m_display);
QVERIFY(m_pointerGesturesInterface);
m_pointerGesturesInterface->create();
QVERIFY(m_pointerGesturesInterface->isValid());
m_pointerGesturesV1Interface = m_display->createPointerGesturesV1(m_display);
// setup connection
m_connection = new KWayland::Client::ConnectionThread;
......@@ -251,8 +248,8 @@ void TestWaylandSeat::cleanup()
delete m_relativePointerManagerV1Interface;
m_relativePointerManagerV1Interface = nullptr;
delete m_pointerGesturesInterface;
m_pointerGesturesInterface = nullptr;
delete m_pointerGesturesV1Interface;
m_pointerGesturesV1Interface = nullptr;
delete m_display;
m_display = nullptr;
......@@ -1737,7 +1734,7 @@ void TestWaylandSeat::testDestroy()
m_seatInterface = nullptr;
m_subCompositorInterface = nullptr;
m_relativePointerManagerV1Interface = nullptr;
m_pointerGesturesInterface = nullptr;
m_pointerGesturesV1Interface = nullptr;
QVERIFY(connectionDiedSpy.wait());
// now the seat should be destroyed;
......
......@@ -39,8 +39,7 @@ set(SERVER_LIB_SRCS
pointer_interface.cpp
pointerconstraints_interface.cpp
pointerconstraints_interface_v1.cpp
pointergestures_interface.cpp
pointergestures_interface_v1.cpp
pointergestures_v1_interface.cpp
primaryselectiondevice_v1_interface.cpp
primaryselectiondevicemanager_v1_interface.cpp
primaryselectionoffer_v1_interface.cpp
......@@ -171,7 +170,7 @@ ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
BASENAME text-input-unstable-v3
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${WaylandProtocols_DATADIR}/unstable/pointer-gestures/pointer-gestures-unstable-v1.xml
BASENAME pointer-gestures-unstable-v1
)
......@@ -411,7 +410,7 @@ set(SERVER_LIB_HEADERS
plasmawindowmanagement_interface.h
pointer_interface.h
pointerconstraints_interface.h
pointergestures_interface.h
pointergestures_v1_interface.h
primaryselectiondevicemanager_v1_interface.h
region_interface.h
relativepointer_v1_interface.h
......
......@@ -29,7 +29,7 @@
#include "plasmavirtualdesktop_interface.h"
#include "plasmawindowmanagement_interface.h"
#include "pointerconstraints_interface_p.h"
#include "pointergestures_interface_p.h"
#include "pointergestures_v1_interface.h"
#include "primaryselectiondevicemanager_v1_interface.h"
#include "relativepointer_v1_interface.h"
#include "seat_interface.h"
......@@ -373,14 +373,9 @@ RelativePointerManagerV1Interface *Display::createRelativePointerManagerV1(QObje
return r;
}
PointerGesturesInterface *Display::createPointerGestures(const PointerGesturesInterfaceVersion &version, QObject *parent)
PointerGesturesV1Interface *Display::createPointerGesturesV1(QObject *parent)
{
PointerGesturesInterface *p = nullptr;
switch (version) {
case PointerGesturesInterfaceVersion::UnstableV1:
p = new PointerGesturesUnstableV1Interface(this, parent);
break;
}
PointerGesturesV1Interface *p = new PointerGesturesV1Interface(this, parent);
connect(this, &Display::aboutToTerminate, p, [p] { delete p; });
return p;
}
......
......@@ -58,8 +58,7 @@ class TextInputManagerV2Interface;
class TextInputManagerV3Interface;
class XdgShellInterface;
class RelativePointerManagerV1Interface;
enum class PointerGesturesInterfaceVersion;
class PointerGesturesInterface;
class PointerGesturesV1Interface;
enum class PointerConstraintsInterfaceVersion;
class PointerConstraintsInterface;
class XdgForeignV2Interface;
......@@ -221,12 +220,12 @@ public:
RelativePointerManagerV1Interface *createRelativePointerManagerV1(QObject *parent = nullptr);
/**
* Creates the PointerGesturesInterface in interface @p version
* Creates the PointerGesturesV1Interface
*
* @returns The created manager object
* @since 5.29
**/
PointerGesturesInterface *createPointerGestures(const PointerGesturesInterfaceVersion &version, QObject *parent = nullptr);
PointerGesturesV1Interface *createPointerGesturesV1(QObject *parent = nullptr);
/**
* Creates the PointerConstraintsInterface in interface @p version
......
......@@ -6,7 +6,7 @@
#include "pointer_interface.h"
#include "pointer_interface_p.h"
#include "pointerconstraints_interface.h"
#include "pointergestures_interface_p.h"
#include "pointergestures_v1_interface_p.h"
#include "resource_p.h"
#include "relativepointer_v1_interface_p.h"
#include "seat_interface.h"
......@@ -76,24 +76,28 @@ void PointerInterface::Private::unregisterRelativePointerV1(RelativePointerV1Int
relativePointersV1.removeOne(relativePointer);
}
void PointerInterface::Private::registerSwipeGesture(PointerSwipeGestureInterface *gesture)
void PointerInterface::Private::registerSwipeGestureV1(PointerSwipeGestureV1Interface *gesture)
{
swipeGestures << gesture;
QObject::connect(gesture, &QObject::destroyed, q,
[this, gesture] {
swipeGestures.removeOne(gesture);
}
);
Q_ASSERT(!swipeGesturesV1.contains(gesture));
swipeGesturesV1.append(gesture);
}
void PointerInterface::Private::registerPinchGesture(PointerPinchGestureInterface *gesture)
void PointerInterface::Private::unregisterSwipeGestureV1(PointerSwipeGestureV1Interface *gesture)
{
pinchGestures << gesture;
QObject::connect(gesture, &QObject::destroyed, q,
[this, gesture] {
pinchGestures.removeOne(gesture);
}
);
Q_ASSERT(swipeGesturesV1.contains(gesture));
swipeGesturesV1.removeOne(gesture);
}
void PointerInterface::Private::registerPinchGestureV1(PointerPinchGestureV1Interface *gesture)
{
Q_ASSERT(!pinchGesturesV1.contains(gesture));
pinchGesturesV1.append(gesture);
}
void PointerInterface::Private::unregisterPinchGestureV1(PointerPinchGestureV1Interface *gesture)
{
Q_ASSERT(pinchGesturesV1.contains(gesture));
pinchGesturesV1.removeOne(gesture);
}
namespace {
......@@ -118,81 +122,69 @@ void PointerInterface::Private::sendEnter(SurfaceInterface *surface, const QPoin
void PointerInterface::Private::startSwipeGesture(quint32 serial, quint32 fingerCount)
{
if (swipeGestures.isEmpty()) {
if (!focusedSurface) {
return;
}
for (auto it = swipeGestures.constBegin(), end = swipeGestures.constEnd(); it != end; it++) {
(*it)->start(serial, fingerCount);
for (PointerSwipeGestureV1Interface *gesture : qAsConst(swipeGesturesV1)) {
gesture->send_begin(serial, seat->timestamp(), focusedSurface->resource(), fingerCount);
}
}
void PointerInterface::Private::updateSwipeGesture(const QSizeF &delta)
{
if (swipeGestures.isEmpty()) {
return;
}
for (auto it = swipeGestures.constBegin(), end = swipeGestures.constEnd(); it != end; it++) {
(*it)->update(delta);
for (PointerSwipeGestureV1Interface *gesture : qAsConst(swipeGesturesV1)) {
gesture->send_update(seat->timestamp(),
wl_fixed_from_double(delta.width()),
wl_fixed_from_double(delta.height()));
}
}
void PointerInterface::Private::endSwipeGesture(quint32 serial)
{
if (swipeGestures.isEmpty()) {
return;
}
for (auto it = swipeGestures.constBegin(), end = swipeGestures.constEnd(); it != end; it++) {
(*it)->end(serial);
for (PointerSwipeGestureV1Interface *gesture : qAsConst(swipeGesturesV1)) {
gesture->send_end(serial, seat->timestamp(), false);
}
}
void PointerInterface::Private::cancelSwipeGesture(quint32 serial)
{
if (swipeGestures.isEmpty()) {
return;
}
for (auto it = swipeGestures.constBegin(), end = swipeGestures.constEnd(); it != end; it++) {
(*it)->cancel(serial);
for (PointerSwipeGestureV1Interface *gesture : qAsConst(swipeGesturesV1)) {
gesture->send_end(serial, seat->timestamp(), true);
}
}
void PointerInterface::Private::startPinchGesture(quint32 serial, quint32 fingerCount)
{
if (pinchGestures.isEmpty()) {
if (!focusedSurface) {
return;
}
for (auto it = pinchGestures.constBegin(), end = pinchGestures.constEnd(); it != end; it++) {
(*it)->start(serial, fingerCount);
for (PointerPinchGestureV1Interface *gesture : qAsConst(pinchGesturesV1)) {
gesture->send_begin(serial, seat->timestamp(), focusedSurface->resource(), fingerCount);
}
}
void PointerInterface::Private::updatePinchGesture(const QSizeF &delta, qreal scale, qreal rotation)
{
if (pinchGestures.isEmpty()) {
return;
}
for (auto it = pinchGestures.constBegin(), end = pinchGestures.constEnd(); it != end; it++) {
(*it)->update(delta, scale, rotation);
for (PointerPinchGestureV1Interface *gesture : qAsConst(pinchGesturesV1)) {
gesture->send_update(seat->timestamp(),
wl_fixed_from_double(delta.width()),
wl_fixed_from_double(delta.height()),
wl_fixed_from_double(scale),
wl_fixed_from_double(rotation));
}
}
void PointerInterface::Private::endPinchGesture(quint32 serial)
{
if (pinchGestures.isEmpty()) {
return;
}
for (auto it = pinchGestures.constBegin(), end = pinchGestures.constEnd(); it != end; it++) {
(*it)->end(serial);
for (PointerPinchGestureV1Interface *gesture : qAsConst(pinchGesturesV1)) {
gesture->send_end(serial, seat->timestamp(), false);
}
}
void PointerInterface::Private::cancelPinchGesture(quint32 serial)
{
if (pinchGestures.isEmpty()) {
return;
}
for (auto it = pinchGestures.constBegin(), end = pinchGestures.constEnd(); it != end; it++) {
(*it)->cancel(serial);
for (PointerPinchGestureV1Interface *gesture : qAsConst(pinchGesturesV1)) {
gesture->send_end(serial, seat->timestamp(), true);
}
}
......
......@@ -14,7 +14,6 @@ namespace KWaylandServer
{
class Cursor;
class PointerGesturesUnstableV1Interface;
class SeatInterface;
class SurfaceInterface;
......@@ -63,7 +62,8 @@ private:
void relativeMotion(const QSizeF &delta, const QSizeF &deltaNonAccelerated, quint64 microseconds);
friend class SeatInterface;
friend class RelativePointerV1Interface;
friend class PointerGesturesUnstableV1Interface;
friend class PointerPinchGestureV1Interface;
friend class PointerSwipeGestureV1Interface;
explicit PointerInterface(SeatInterface *parent, wl_resource *parentResource);
class Private;
Private *d_func() const;
......
......@@ -13,8 +13,8 @@
namespace KWaylandServer
{
class PointerPinchGestureInterface;
class PointerSwipeGestureInterface;
class PointerPinchGestureV1Interface;
class PointerSwipeGestureV1Interface;
class RelativePointerV1Interface;
class PointerInterface::Private : public Resource::Private
......@@ -28,18 +28,20 @@ public:
QMetaObject::Connection destroyConnection;
Cursor *cursor = nullptr;
QVector<RelativePointerV1Interface *> relativePointersV1;
QVector<PointerSwipeGestureInterface*> swipeGestures;
QVector<PointerPinchGestureInterface*> pinchGestures;
QVector<PointerSwipeGestureV1Interface *> swipeGesturesV1;
QVector<PointerPinchGestureV1Interface *> pinchGesturesV1;
void sendLeave(SurfaceInterface *surface, quint32 serial);
void sendEnter(SurfaceInterface *surface, const QPointF &parentSurfacePosition, quint32 serial);
void sendFrame();
void registerRelativePointerV1(RelativePointerV1Interface *relativePointer);
void registerSwipeGesture(PointerSwipeGestureInterface *gesture);
void registerPinchGesture(PointerPinchGestureInterface *gesture);
void registerSwipeGestureV1(PointerSwipeGestureV1Interface *gesture);
void registerPinchGestureV1(PointerPinchGestureV1Interface *gesture);
void unregisterRelativePointerV1(RelativePointerV1Interface *relativePointer);
void unregisterSwipeGestureV1(PointerSwipeGestureV1Interface *gesture);
void unregisterPinchGestureV1(PointerPinchGestureV1Interface *gesture);
void startSwipeGesture(quint32 serial, quint32 fingerCount);
void updateSwipeGesture(const QSizeF &delta);
......
/*
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 "pointergestures_interface_p.h"
namespace KWaylandServer
{
PointerGesturesInterface::Private::Private(PointerGesturesInterfaceVersion interfaceVersion, PointerGesturesInterface *q, Display *d, const wl_interface *interface, quint32 version)
: Global::Private(d, interface, version)
, interfaceVersion(interfaceVersion)
, q(q)
{
}
PointerGesturesInterface::PointerGesturesInterface(Private *d, QObject *parent)
: Global(d, parent)
{
}
PointerGesturesInterface::~PointerGesturesInterface() = default;
PointerGesturesInterfaceVersion PointerGesturesInterface::interfaceVersion() const
{
Q_D();
return d->interfaceVersion;
}
PointerGesturesInterface::Private *PointerGesturesInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
}
PointerSwipeGestureInterface::Private::Private(PointerSwipeGestureInterface *q, Global *c, wl_resource *parentResource, const wl_interface *interface, const void *implementation, PointerInterface *pointer)
: Resource::Private(q, c, parentResource, interface, implementation)
, pointer(pointer)
{
}
PointerSwipeGestureInterface::Private::~Private()
{
if (resource) {
wl_resource_destroy(resource);
resource = nullptr;
}
}
PointerSwipeGestureInterface::PointerSwipeGestureInterface(Private *p, QObject *parent)
: Resource(p, parent)
{
}
PointerSwipeGestureInterface::~PointerSwipeGestureInterface() = default;
PointerSwipeGestureInterface::Private *PointerSwipeGestureInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
}
PointerPinchGestureInterface::Private::Private(PointerPinchGestureInterface *q, Global *c, wl_resource *parentResource, const wl_interface *interface, const void *implementation, PointerInterface *pointer)
: Resource::Private(q, c, parentResource, interface, implementation)
, pointer(pointer)
{
}
PointerPinchGestureInterface::Private::~Private()
{
if (resource) {
wl_resource_destroy(resource);
resource = nullptr;
}
}
PointerPinchGestureInterface::PointerPinchGestureInterface(Private *p, QObject *parent)
: Resource(p, parent)
{
}
PointerPinchGestureInterface::~PointerPinchGestureInterface() = default;
PointerPinchGestureInterface::Private *PointerPinchGestureInterface::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_POINTERGESTURES_INTERFACE_P_H
#define KWAYLAND_SERVER_POINTERGESTURES_INTERFACE_P_H
#include "pointergestures_interface.h"
#include "resource_p.h"
#include "global_p.h"
namespace KWaylandServer
{
class PointerInterface;
class PointerGesturesInterface::Private : public Global::Private
{
public:
PointerGesturesInterfaceVersion interfaceVersion;
protected:
Private(PointerGesturesInterfaceVersion interfaceVersion, PointerGesturesInterface *q, Display *d, const wl_interface *interface, quint32 version);
PointerGesturesInterface *q;
};
class PointerGesturesUnstableV1Interface : public PointerGesturesInterface
{
Q_OBJECT
public:
explicit PointerGesturesUnstableV1Interface(Display *display, QObject *parent = nullptr);
virtual ~PointerGesturesUnstableV1Interface();
private:
class Private;
};
class PointerSwipeGestureInterface : public Resource
{
Q_OBJECT
public:
virtual ~PointerSwipeGestureInterface();
virtual void start(quint32 serial, quint32 fingerCount) = 0;
virtual void update(const QSizeF &delta) = 0;
virtual void end(quint32 serial) = 0;
virtual void cancel(quint32 serial) = 0;
protected:
class Private;
explicit PointerSwipeGestureInterface(Private *p, QObject *parent = nullptr);
private:
Private *d_func() const;
};
class PointerSwipeGestureInterface::Private : public Resource::Private
{
public:
~Private();
PointerInterface *pointer;
protected:
Private(PointerSwipeGestureInterface *q, Global *c, wl_resource *parentResource, const wl_interface *interface, const void *implementation, PointerInterface *pointer);
private:
PointerSwipeGestureInterface *q_func() {
return reinterpret_cast<PointerSwipeGestureInterface *>(q);
}
};
class PointerPinchGestureInterface : public Resource
{
Q_OBJECT
public:
virtual ~PointerPinchGestureInterface();
virtual void start(quint32 serial, quint32 fingerCount) = 0;
virtual void update(const QSizeF &delta, qreal scale, qreal rotation) = 0;
virtual void end(quint32 serial) = 0;
virtual void cancel(quint32 serial) = 0;
protected:
class Private;
explicit PointerPinchGestureInterface(Private *p, QObject *parent = nullptr);
private:
Private *d_func() const;
};
class PointerPinchGestureInterface::Private : public Resource::Private
{
public:
~Private();
PointerInterface *pointer;
protected:
Private(PointerPinchGestureInterface *q, Global *c, wl_resource *parentResource, const wl_interface *interface, const void *implementation, PointerInterface *pointer);
private:
PointerPinchGestureInterface *q_func() {
return reinterpret_cast<PointerPinchGestureInterface *>(q);
}
};
class PointerSwipeGestureUnstableV1Interface : public PointerSwipeGestureInterface
{
Q_OBJECT
public:
explicit PointerSwipeGestureUnstableV1Interface(PointerGesturesUnstableV1Interface *parent, wl_resource *parentResource, PointerInterface *pointer);
virtual ~PointerSwipeGestureUnstableV1Interface();
void start(quint32 serial, quint32 fingerCount) override;
void update(const QSizeF &delta) override;
void end(quint32 serial) override;
void cancel(quint32 serial) override;
private:
friend class PointerGesturesUnstableV1Interface;
class Private;
Private *d_func() const;
};
class PointerPinchGestureUnstableV1Interface : public PointerPinchGestureInterface
{
Q_OBJECT
public:
explicit PointerPinchGestureUnstableV1Interface(PointerGesturesUnstableV1Interface *parent, wl_resource *parentResource, PointerInterface *pointer);
virtual ~PointerPinchGestureUnstableV1Interface();
void start(quint32 serial, quint32 fingerCount) override;
void update(const QSizeF &delta, qreal scale, qreal rotation) override;
void end(quint32 serial) override;
void cancel(quint32 serial) override;
private:
friend class PointerGesturesUnstableV1Interface;
class Private;
Private *d_func() const;
};
}
#endif
/*
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 "pointergestures_interface_p.h"
#include "display.h"
#include "pointer_interface_p.h"
#include "resource_p.h"
#include "seat_interface.h"
#include "surface_interface.h"
#include <wayland-pointer-gestures-unstable-v1-server-protocol.h>
namespace KWaylandServer
{
class PointerGesturesUnstableV1Interface::Private : public PointerGesturesInterface::Private
{
public: