Commit a669b861 authored by Adrien Faveraux's avatar Adrien Faveraux Committed by Vlad Zahorodnii
Browse files

Migrate Migrate XdgForeign to new approach

parent 603dfbaf
......@@ -17,7 +17,7 @@
#include "../../src/server/display.h"
#include "../../src/server/compositor_interface.h"
#include "../../src/server/surface_interface.h"
#include "../../src/server/xdgforeign_interface.h"
#include "../../src/server/xdgforeign_v2_interface.h"
using namespace KWayland::Client;
......@@ -43,7 +43,7 @@ private:
KWaylandServer::Display *m_display;
QPointer<KWaylandServer::CompositorInterface> m_compositorInterface;
KWaylandServer::XdgForeignInterface *m_foreignInterface;
KWaylandServer::XdgForeignV2Interface *m_foreignInterface;
KWayland::Client::ConnectionThread *m_connection;
KWayland::Client::Compositor *m_compositor;
KWayland::Client::EventQueue *m_queue;
......@@ -86,8 +86,7 @@ void TestForeign::init()
m_display->start();
QVERIFY(m_display->isRunning());
qRegisterMetaType<KWaylandServer::SurfaceInterface*>("KWaylandServer::SurfaceInterface");
qRegisterMetaType<SurfaceInterface*>();
// setup connection
m_connection = new KWayland::Client::ConnectionThread;
QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected);
......@@ -127,9 +126,7 @@ void TestForeign::init()
QVERIFY(compositorSpy.wait());
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
m_foreignInterface = m_display->createXdgForeignInterface(m_display);
m_foreignInterface->create();
QVERIFY(m_foreignInterface->isValid());
m_foreignInterface = m_display->createXdgForeignV2Interface(m_display);
QVERIFY(exporterSpy.wait());
//Both importer and exporter should have been triggered by now
......@@ -163,17 +160,8 @@ void TestForeign::cleanup()
m_thread = nullptr;
}
CLEANUP(m_foreignInterface)
//internally there are some deleteLaters on exported interfaces
//we want them processed before we delete the connection
if (m_display) {
QSignalSpy destroyedSpy(m_display, &QObject::destroyed);
m_display->deleteLater();
m_display = nullptr;
destroyedSpy.wait();
}
QVERIFY(m_compositorInterface.isNull());
delete m_display;
m_display = nullptr;
#undef CLEANUP
}
......@@ -189,17 +177,17 @@ void TestForeign::doExport()
m_exportedSurfaceInterface = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface*>();
//Export a window
m_exported = m_exporter->exportTopLevel(m_exportedSurface, m_connection);
m_exported = m_exporter->exportTopLevel(m_exportedSurface);
QVERIFY(m_exported->handle().isEmpty());
QSignalSpy doneSpy(m_exported.data(), &XdgExported::done);
QVERIFY(doneSpy.wait());
QVERIFY(!m_exported->handle().isEmpty());
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignInterface::transientChanged);
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignV2Interface::transientChanged);
QVERIFY(transientSpy.isValid());
//Import the just exported window
m_imported = m_importer->importTopLevel(m_exported->handle(), m_connection);
m_imported = m_importer->importTopLevel(m_exported->handle());
QVERIFY(m_imported->isValid());
QSignalSpy childSurfaceInterfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWaylandServer::SurfaceInterface*)));
......@@ -228,7 +216,7 @@ void TestForeign::testDeleteImported()
{
doExport();
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignInterface::transientChanged);
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignV2Interface::transientChanged);
QVERIFY(transientSpy.isValid());
m_imported->deleteLater();
......@@ -245,7 +233,7 @@ void TestForeign::testDeleteChildSurface()
{
doExport();
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignInterface::transientChanged);
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignV2Interface::transientChanged);
QVERIFY(transientSpy.isValid());
m_childSurface->deleteLater();
......@@ -260,7 +248,7 @@ void TestForeign::testDeleteParentSurface()
{
doExport();
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignInterface::transientChanged);
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignV2Interface::transientChanged);
QVERIFY(transientSpy.isValid());
m_exportedSurface->deleteLater();
......@@ -280,7 +268,7 @@ void TestForeign::testDeleteExported()
{
doExport();
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignInterface::transientChanged);
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignV2Interface::transientChanged);
QSignalSpy destroyedSpy(m_imported.data(), &KWayland::Client::XdgImported::importedDestroyed);
QVERIFY(transientSpy.isValid());
......@@ -302,17 +290,17 @@ void TestForeign::testExportTwoTimes()
doExport();
//Export second window
KWayland::Client::XdgExported *exported2 = m_exporter->exportTopLevel(m_exportedSurface, m_connection);
KWayland::Client::XdgExported *exported2 = m_exporter->exportTopLevel(m_exportedSurface);
QVERIFY(exported2->handle().isEmpty());
QSignalSpy doneSpy(exported2, &XdgExported::done);
QVERIFY(doneSpy.wait());
QVERIFY(!exported2->handle().isEmpty());
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignInterface::transientChanged);
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignV2Interface::transientChanged);
QVERIFY(transientSpy.isValid());
//Import the just exported window
KWayland::Client::XdgImported *imported2 = m_importer->importTopLevel(exported2->handle(), m_connection);
KWayland::Client::XdgImported *imported2 = m_importer->importTopLevel(exported2->handle());
QVERIFY(imported2->isValid());
//create a second child surface
......@@ -341,11 +329,11 @@ void TestForeign::testImportTwoTimes()
{
doExport();
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignInterface::transientChanged);
QSignalSpy transientSpy(m_foreignInterface, &KWaylandServer::XdgForeignV2Interface::transientChanged);
QVERIFY(transientSpy.isValid());
//Import another time the exported window
KWayland::Client::XdgImported *imported2 = m_importer->importTopLevel(m_exported->handle(), m_connection);
KWayland::Client::XdgImported *imported2 = m_importer->importTopLevel(m_exported->handle());
QVERIFY(imported2->isValid());
//create a second child surface
......
......@@ -62,7 +62,6 @@ set(SERVER_LIB_SRCS
touch_interface.cpp
viewporter_interface.cpp
xdgdecoration_v1_interface.cpp
xdgforeign_interface.cpp
xdgforeign_v2_interface.cpp
xdgoutput_interface.cpp
xdgshell_interface.cpp
......@@ -177,7 +176,7 @@ ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
BASENAME pointer-constraints-unstable-v1
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${WaylandProtocols_DATADIR}/unstable/xdg-foreign/xdg-foreign-unstable-v2.xml
BASENAME xdg-foreign-unstable-v2
)
......@@ -410,7 +409,7 @@ set(SERVER_LIB_HEADERS
touch_interface.h
viewporter_interface.h
xdgdecoration_v1_interface.h
xdgforeign_interface.h
xdgforeign_v2_interface.h
xdgoutput_interface.h
xdgshell_interface.h
)
......
......@@ -42,7 +42,7 @@
#include "textinput_interface_p.h"
#include "viewporter_interface.h"
#include "xdgdecoration_v1_interface.h"
#include "xdgforeign_interface.h"
#include "xdgforeign_v2_interface.h"
#include "xdgoutput_interface.h"
#include "xdgshell_interface.h"
......@@ -401,9 +401,9 @@ PointerConstraintsInterface *Display::createPointerConstraints(const PointerCons
return p;
}
XdgForeignInterface *Display::createXdgForeignInterface(QObject *parent)
XdgForeignV2Interface *Display::createXdgForeignV2Interface(QObject *parent)
{
XdgForeignInterface *foreign = new XdgForeignInterface(this, parent);
XdgForeignV2Interface *foreign = new XdgForeignV2Interface(this, parent);
connect(this, &Display::aboutToTerminate, foreign, [foreign] { delete foreign; });
return foreign;
}
......
......@@ -65,7 +65,7 @@ enum class PointerGesturesInterfaceVersion;
class PointerGesturesInterface;
enum class PointerConstraintsInterfaceVersion;
class PointerConstraintsInterface;
class XdgForeignInterface;
class XdgForeignV2Interface;
class AppMenuManagerInterface;
class ServerSideDecorationPaletteManagerInterface;
class PlasmaVirtualDesktopManagementInterface;
......@@ -231,12 +231,12 @@ public:
PointerConstraintsInterface *createPointerConstraints(const PointerConstraintsInterfaceVersion &version, QObject *parent = nullptr);
/**
* Creates the XdgForeignInterface in interface @p version
* Creates the XdgForeignV2Interface in interface @p version
*
* @returns The created manager object
* @since 5.40
**/
XdgForeignInterface *createXdgForeignInterface(QObject *parent = nullptr);
XdgForeignV2Interface *createXdgForeignV2Interface(QObject *parent = nullptr);
/**
* Creates the IdleInhibitManagerInterface in interface @p version.
......
/*
SPDX-FileCopyrightText: 2017 Marco Martin <notmart@gmail.com>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "xdgforeign_interface.h"
#include "xdgforeign_v2_interface_p.h"
#include "display.h"
#include "global_p.h"
#include "resource_p.h"
#include "surface_interface_p.h"
#include "wayland-xdg-foreign-unstable-v2-server-protocol.h"
#include <QUuid>
#include <QDebug>
namespace KWaylandServer
{
XdgForeignInterface::Private::Private(Display *display, XdgForeignInterface *q)
: q(q)
{
exporter = new XdgExporterUnstableV2Interface(display, q);
importer = new XdgImporterUnstableV2Interface(display, q);
connect(importer, &XdgImporterUnstableV2Interface::transientChanged,
q, &XdgForeignInterface::transientChanged);
}
XdgForeignInterface::XdgForeignInterface(Display *display, QObject *parent)
: QObject(parent),
d(new Private(display, this))
{
}
XdgForeignInterface::~XdgForeignInterface()
{
delete d->exporter;
delete d->importer;
delete d;
}
void XdgForeignInterface::create()
{
d->exporter->create();
d->importer->create();
}
bool XdgForeignInterface::isValid()
{
return d->exporter->isValid() && d->importer->isValid();
}
SurfaceInterface *XdgForeignInterface::transientFor(SurfaceInterface *surface)
{
return d->importer->transientFor(surface);
}
}
This diff is collapsed.
......@@ -6,8 +6,7 @@
#ifndef KWAYLAND_SERVER_XDGFOREIGN_INTERFACE_H
#define KWAYLAND_SERVER_XDGFOREIGN_INTERFACE_H
#include "global.h"
#include "resource.h"
#include <QObject>
#include <KWaylandServer/kwaylandserver_export.h>
......@@ -16,8 +15,9 @@ namespace KWaylandServer
class Display;
class SurfaceInterface;
class XdgExporterUnstableV2Interface;
class XdgImporterUnstableV2Interface;
class XdgExporterV2Interface;
class XdgImporterV2Interface;
class XdgForeignV2InterfacePrivate;
/**
* This class encapsulates the server side logic of the XdgForeign protocol.
......@@ -29,23 +29,12 @@ class XdgImporterUnstableV2Interface;
*
* @since 5.40
*/
class KWAYLANDSERVER_EXPORT XdgForeignInterface : public QObject
class KWAYLANDSERVER_EXPORT XdgForeignV2Interface : public QObject
{
Q_OBJECT
public:
XdgForeignInterface(Display *display, QObject *parent = nullptr);
~XdgForeignInterface();
/**
* Creates the native zxdg_exporter_v2 and zxdg_importer_v2 interfaces
* and announces them to the client.
*/
void create();
/**
* @returns true if theimporter and exporter are valid and functional
*/
bool isValid();
XdgForeignV2Interface(Display *display, QObject *parent = nullptr);
~XdgForeignV2Interface() override;
/**
* If a client did import a surface and set one of its own as child of the
......@@ -69,10 +58,9 @@ Q_SIGNALS:
private:
friend class Display;
friend class XdgExporterUnstableV2Interface;
friend class XdgImporterUnstableV2Interface;
class Private;
Private *d;
friend class XdgExporterV2InterfacePrivate;
friend class XdgImporterV2InterfacePrivate;
QScopedPointer<XdgForeignV2InterfacePrivate> d;
};
}
......
......@@ -6,102 +6,110 @@
#ifndef KWAYLAND_SERVER_XDGFOREIGNV2_INTERFACE_P_H
#define KWAYLAND_SERVER_XDGFOREIGNV2_INTERFACE_P_H
#include "global.h"
#include "resource.h"
#include "xdgforeign_v2_interface.h"
#include "surface_interface_p.h"
#include <qwayland-server-xdg-foreign-unstable-v2.h>
namespace KWaylandServer
{
class Display;
class SurfaceInterface;
class XdgExportedUnstableV2Interface;
class XdgImportedUnstableV2Interface;
class Q_DECL_HIDDEN XdgForeignInterface::Private
class XdgExportedV2Interface;
class XdgImportedV2Interface;
class XdgExporterV2InterfacePrivate;
class XdgImporterV2InterfacePrivate;
class XdgExportedV2Interface;
class XdgImportedV2InterfacePrivate;
class XdgForeignV2InterfacePrivate : public QObject
{
Q_OBJECT
public:
Private(Display *display, XdgForeignInterface *q);
XdgForeignV2InterfacePrivate(Display *display, XdgForeignV2Interface *q);
XdgForeignInterface *q;
XdgExporterUnstableV2Interface *exporter;
XdgImporterUnstableV2Interface *importer;
XdgForeignV2Interface *q;
XdgExporterV2Interface *exporter;
XdgImporterV2Interface *importer;
};
class Q_DECL_HIDDEN XdgExporterUnstableV2Interface : public Global
class XdgExporterV2Interface : public QObject
{
Q_OBJECT
public:
virtual ~XdgExporterUnstableV2Interface();
explicit XdgExporterV2Interface(Display *display, XdgForeignV2Interface *parent = nullptr);
~XdgExporterV2Interface() override;
XdgExportedUnstableV2Interface *exportedSurface(const QString &handle);
XdgExportedV2Interface *exportedSurface(const QString &handle);
Q_SIGNALS:
void surfaceExported(const QString &handle, XdgExportedUnstableV2Interface *exported);
void surfaceExported(const QString &handle, XdgExportedV2Interface *exported);
void surfaceUnexported(const QString &handle);
private:
explicit XdgExporterUnstableV2Interface(Display *display, XdgForeignInterface *parent = nullptr);
friend class Display;
friend class XdgForeignInterface;
class Private;
Private *d_func() const;
QScopedPointer<XdgExporterV2InterfacePrivate> d;
};
class Q_DECL_HIDDEN XdgImporterUnstableV2Interface : public Global
class XdgImporterV2Interface : public QObject
{
Q_OBJECT
public:
virtual ~XdgImporterUnstableV2Interface();
explicit XdgImporterV2Interface(Display *display, XdgForeignV2Interface *parent = nullptr);
~XdgImporterV2Interface() override;
XdgImportedUnstableV2Interface *importedSurface(const QString &handle);
XdgImportedV2Interface *importedSurface(const QString &handle);
SurfaceInterface *transientFor(SurfaceInterface *surface);
Q_SIGNALS:
void surfaceImported(const QString &handle, XdgImportedUnstableV2Interface *imported);
void surfaceImported(const QString &handle, XdgImportedV2Interface *imported);
void surfaceUnimported(const QString &handle);
void transientChanged(KWaylandServer::SurfaceInterface *child, KWaylandServer::SurfaceInterface *parent);
private:
explicit XdgImporterUnstableV2Interface(Display *display, XdgForeignInterface *parent = nullptr);
friend class Display;
friend class XdgForeignInterface;
class Private;
Private *d_func() const;
QScopedPointer<XdgImporterV2InterfacePrivate> d;
};
class Q_DECL_HIDDEN XdgExportedUnstableV2Interface : public Resource
class XdgExportedV2Interface : public QObject, QtWaylandServer::zxdg_exported_v2
{
Q_OBJECT
public:
virtual ~XdgExportedUnstableV2Interface();
explicit XdgExportedV2Interface(SurfaceInterface *surface, wl_resource *resource );
~XdgExportedV2Interface() override;
SurfaceInterface *parentResource();
private:
explicit XdgExportedUnstableV2Interface(XdgExporterUnstableV2Interface *parent, wl_resource *parentResource);
friend class XdgExporterUnstableV2Interface;
SurfaceInterface *surface;
protected:
void zxdg_exported_v2_destroy(Resource *resource) override;
void zxdg_exported_v2_destroy_resource(Resource *resource) override;
class Private;
Private *d_func() const;
};
class Q_DECL_HIDDEN XdgImportedUnstableV2Interface : public Resource
class XdgImportedV2Interface : public QObject, QtWaylandServer::zxdg_imported_v2
{
Q_OBJECT
public:
virtual ~XdgImportedUnstableV2Interface();
explicit XdgImportedV2Interface(SurfaceInterface *surface, wl_resource *resource);
~XdgImportedV2Interface() override;
SurfaceInterface *child() const;
SurfaceInterface *parentResource();
Q_SIGNALS:
void childChanged(KWaylandServer::SurfaceInterface *child);
private:
explicit XdgImportedUnstableV2Interface(XdgImporterUnstableV2Interface *parent, wl_resource *parentResource);
friend class XdgImporterUnstableV2Interface;
SurfaceInterface *surface;
QPointer<SurfaceInterface> parentOf;
class Private;
Private *d_func() const;
};
protected:
void zxdg_imported_v2_set_parent_of(Resource *resource, wl_resource *surface) override;
void zxdg_imported_v2_destroy(Resource *resource) override;
void zxdg_imported_v2_destroy_resource(Resource *resource) override;
};
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment