Commit 84b0c169 authored by David Edmundson's avatar David Edmundson
Browse files

Drop deprecated QtSurfaceExtensionInterface

Summary: This isn't used by kwin or Qt anymore

Differential Revision: https://phabricator.kde.org/D29338
parent 0498a06c
......@@ -20,24 +20,6 @@ target_link_libraries( testWaylandServerSeat Qt5::Test Qt5::Gui Plasma::KWayland
add_test(NAME kwayland-testWaylandServerSeat COMMAND testWaylandServerSeat)
ecm_mark_as_test(testWaylandServerSeat)
########################################################
# QtSurfaceExtenstion Helper
########################################################
add_executable(surfaceExtensionHelper surfaceextension_helper.cpp)
target_link_libraries( surfaceExtensionHelper Qt5::Gui)
ecm_mark_as_test(surfaceExtensionHelper)
########################################################
# Test QtSurfaceExtenstion
########################################################
set( testQtSurfaceExtension_SRCS
test_qt_surface_extension.cpp
)
add_executable(testQtSurfaceExtension ${testQtSurfaceExtension_SRCS})
target_link_libraries( testQtSurfaceExtension Qt5::Test Qt5::Gui Plasma::KWaylandServer)
add_test(NAME kwayland-testQtSurfaceExtension COMMAND testQtSurfaceExtension)
ecm_mark_as_test(testQtSurfaceExtension)
########################################################
# Test No XDG_RUNTIME_DIR
########################################################
......
/*
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 <QGuiApplication>
#include <QPainter>
#include <QRasterWindow>
class Window : public QRasterWindow
{
Q_OBJECT
public:
explicit Window();
virtual ~Window();
protected:
void paintEvent(QPaintEvent *event) override;
};
Window::Window()
: QRasterWindow()
{
setGeometry(QRect(0, 0, 200, 200));
}
Window::~Window() = default;
void Window::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QPainter p(this);
p.fillRect(QRect(QPoint(0, 0), size()), Qt::black);
}
int main(int argc, char **argv)
{
qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("wayland"));
QGuiApplication app(argc, argv);
QScopedPointer<Window> w(new Window);
w->show();
return app.exec();
}
#include "surfaceextension_helper.moc"
/*
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
*/
// Qt
#include <QtTest>
#include <QProcess>
// WaylandServer
#include "../../src/server/compositor_interface.h"
#include "../../src/server/display.h"
#include "../../src/server/output_interface.h"
#include "../../src/server/qtsurfaceextension_interface.h"
#include "../../src/server/seat_interface.h"
#include "../../src/server/shell_interface.h"
using namespace KWaylandServer;
class TestQtSurfaceExtension : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testCloseWindow();
};
static const QString s_socketName = QStringLiteral("kwin-wayland-server-qt-surface-extension-0");
void TestQtSurfaceExtension::testCloseWindow()
{
// this test verifies that we can close windows through the Qt surface extension interface
// for this we start a dummy server, launch a QtWayland powered application, wait for the
// window it opens, close it and verify that the process terminates
Display display;
display.setSocketName(s_socketName);
display.start();
display.createShm();
SeatInterface *seat = display.createSeat();
seat->setHasKeyboard(true);
seat->setHasPointer(true);
seat->setHasTouch(true);
seat->create();
CompositorInterface *compositor = display.createCompositor();
compositor->create();
ShellInterface *shell = display.createShell();
shell->create();
OutputInterface *output = display.createOutput();
output->setManufacturer(QStringLiteral("org.kde"));
output->setModel(QStringLiteral("QtSurfaceExtensionTestCase"));
output->addMode(QSize(1280, 1024), OutputInterface::ModeFlag::Preferred | OutputInterface::ModeFlag::Current);
output->setPhysicalSize(QSize(1280, 1024) / 3.8);
output->create();
// surface extension
QtSurfaceExtensionInterface *surfaceExtension = display.createQtSurfaceExtension();
surfaceExtension->create();
// create a signalspy for surfaceCreated
QSignalSpy surfaceExtensionSpy(surfaceExtension, &QtSurfaceExtensionInterface::surfaceCreated);
QVERIFY(surfaceExtensionSpy.isValid());
// now start our application
QString binary = QFINDTESTDATA("surfaceExtensionHelper");
QVERIFY(!binary.isEmpty());
QProcess process;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert(QStringLiteral("WAYLAND_DISPLAY"), s_socketName);
process.setProcessEnvironment(env);
process.start(binary, QStringList());
QVERIFY(surfaceExtensionSpy.wait());
QCOMPARE(surfaceExtensionSpy.count(), 1);
auto *extension = surfaceExtensionSpy.first().first().value<QtExtendedSurfaceInterface*>();
QVERIFY(extension);
QSignalSpy surfaceExtensionDestroyedSpy(extension, &QObject::destroyed);
QVERIFY(surfaceExtensionSpy.isValid());
qRegisterMetaType<QProcess::ProcessState>();
QSignalSpy processStateChangedSpy(&process, &QProcess::stateChanged);
QVERIFY(processStateChangedSpy.isValid());
extension->close();
extension->client()->flush();
QVERIFY(processStateChangedSpy.wait());
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
if (surfaceExtensionDestroyedSpy.count() == 0) {
QVERIFY(surfaceExtensionDestroyedSpy.wait());
}
QCOMPARE(surfaceExtensionSpy.count(), 1);
}
QTEST_GUILESS_MAIN(TestQtSurfaceExtension)
#include "test_qt_surface_extension.moc"
......@@ -35,7 +35,6 @@ set(SERVER_LIB_SRCS
pointerconstraints_interface_v1.cpp
pointergestures_interface.cpp
pointergestures_interface_v1.cpp
qtsurfaceextension_interface.cpp
region_interface.cpp
relativepointer_interface.cpp
relativepointer_interface_v1.cpp
......@@ -363,7 +362,6 @@ set(SERVER_LIB_HEADERS
pointer_interface.h
pointerconstraints_interface.h
pointergestures_interface.h
qtsurfaceextension_interface.h
region_interface.h
relativepointer_interface.h
remote_access_interface.h
......
......@@ -27,7 +27,6 @@
#include "plasmawindowmanagement_interface.h"
#include "pointerconstraints_interface_p.h"
#include "pointergestures_interface_p.h"
#include "qtsurfaceextension_interface.h"
#include "relativepointer_interface_p.h"
#include "remote_access_interface.h"
#include "seat_interface.h"
......@@ -306,13 +305,6 @@ PlasmaWindowManagementInterface *Display::createPlasmaWindowManagement(QObject *
return wm;
}
QtSurfaceExtensionInterface *Display::createQtSurfaceExtension(QObject *parent)
{
auto s = new QtSurfaceExtensionInterface(this, parent);
connect(this, &Display::aboutToTerminate, s, [s] { delete s; });
return s;
}
RemoteAccessManagerInterface *Display::createRemoteAccessManager(QObject *parent)
{
auto i = new RemoteAccessManagerInterface(this, parent);
......
/*
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "qtsurfaceextension_interface.h"
#include "global_p.h"
#include "resource_p.h"
#include "display.h"
#include "surface_interface.h"
#include <QTimer>
#include <QVariant>
#include <wayland-server.h>
#include <wayland-qt-surface-extension-server-protocol.h>
namespace KWaylandServer
{
class QtSurfaceExtensionInterface::Private : public Global::Private
{
public:
Private(QtSurfaceExtensionInterface *q, Display *d);
QList<QtExtendedSurfaceInterface*> surfaces;
private:
static void createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface);
void bind(wl_client *client, uint32_t version, uint32_t id) override;
void createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface, wl_resource *parentResource);
QtSurfaceExtensionInterface *q;
static const struct qt_surface_extension_interface s_interface;
static const quint32 s_version;
};
const quint32 QtSurfaceExtensionInterface::Private::s_version = 1;
QtSurfaceExtensionInterface::Private::Private(QtSurfaceExtensionInterface *q, Display *d)
: Global::Private(d, &qt_surface_extension_interface, s_version)
, q(q)
{
}
#ifndef K_DOXYGEN
const struct qt_surface_extension_interface QtSurfaceExtensionInterface::Private::s_interface = {
createSurfaceCallback
};
#endif
class QtExtendedSurfaceInterface::Private : public Resource::Private
{
public:
Private(QtExtendedSurfaceInterface *q, QtSurfaceExtensionInterface *shell, SurfaceInterface *surface, wl_resource *parentResource);
SurfaceInterface *surface;
private:
// interface callbacks
static void updateGenericPropertyCallback(wl_client *client, wl_resource *resource, const char *name, wl_array *value);
static void setContentOrientationMaskCallback(wl_client *client, wl_resource *resource, int32_t orientation);
static void setWindowFlagsCallback(wl_client *client, wl_resource *resource, int32_t flags);
static void raiseCallback(wl_client *client, wl_resource *resource);
static void lowerCallback(wl_client *client, wl_resource *resource);
QtExtendedSurfaceInterface *q_func() {
return reinterpret_cast<QtExtendedSurfaceInterface *>(q);
}
static const struct qt_extended_surface_interface s_interface;
};
QtSurfaceExtensionInterface::QtSurfaceExtensionInterface(Display *display, QObject *parent)
: Global(new Private(this, display), parent)
{
}
QtSurfaceExtensionInterface::~QtSurfaceExtensionInterface() = default;
void QtSurfaceExtensionInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
{
auto c = display->getConnection(client);
wl_resource *shell = c->createResource(&qt_surface_extension_interface, qMin(version, s_version), id);
if (!shell) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(shell, &s_interface, this, nullptr);
}
void QtSurfaceExtensionInterface::Private::createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface)
{
auto s = reinterpret_cast<QtSurfaceExtensionInterface::Private*>(wl_resource_get_user_data(resource));
s->createSurface(client, wl_resource_get_version(resource), id, SurfaceInterface::get(surface), resource);
}
void QtSurfaceExtensionInterface::Private::createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface, wl_resource *parentResource)
{
auto it = std::find_if(surfaces.constBegin(), surfaces.constEnd(),
[surface](QtExtendedSurfaceInterface *s) {
return surface == s->surface();
}
);
if (it != surfaces.constEnd()) {
wl_resource_post_error(surface->resource(), WL_DISPLAY_ERROR_INVALID_OBJECT, "Qt Surface Extension already created");
return;
}
QtExtendedSurfaceInterface *shellSurface = new QtExtendedSurfaceInterface(q, surface, parentResource);
surfaces << shellSurface;
QObject::connect(shellSurface, &QtExtendedSurfaceInterface::destroyed, q,
[this, shellSurface] {
surfaces.removeAll(shellSurface);
}
);
shellSurface->d->create(display->getConnection(client), version, id);
emit q->surfaceCreated(shellSurface);
}
/*********************************
* ShellSurfaceInterface
*********************************/
QtExtendedSurfaceInterface::Private::Private(QtExtendedSurfaceInterface *q, QtSurfaceExtensionInterface *shell, SurfaceInterface *surface, wl_resource *parentResource)
: Resource::Private(q, shell, parentResource, &qt_extended_surface_interface, &s_interface)
, surface(surface)
{
}
#ifndef K_DOXYGEN
const struct qt_extended_surface_interface QtExtendedSurfaceInterface::Private::s_interface = {
updateGenericPropertyCallback,
setContentOrientationMaskCallback,
setWindowFlagsCallback,
raiseCallback,
lowerCallback
};
#endif
void QtExtendedSurfaceInterface::Private::lowerCallback(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
emit cast<Private>(resource)->q_func()->lowerRequested();
}
void QtExtendedSurfaceInterface::Private::raiseCallback(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
emit cast<Private>(resource)->q_func()->raiseRequested();
}
void QtExtendedSurfaceInterface::Private::setContentOrientationMaskCallback(wl_client *client, wl_resource *resource, int32_t orientation)
{
Q_UNUSED(client)
Q_UNUSED(resource)
Q_UNUSED(orientation)
}
void QtExtendedSurfaceInterface::Private::setWindowFlagsCallback(wl_client *client, wl_resource *resource, int32_t flags)
{
Q_UNUSED(client)
Q_UNUSED(resource)
Q_UNUSED(flags)
}
void QtExtendedSurfaceInterface::Private::updateGenericPropertyCallback(wl_client *client, wl_resource *resource, const char *name, wl_array *value)
{
Q_UNUSED(client)
QByteArray data = QByteArray::fromRawData(static_cast<char *>(value->data), value->size);
QVariant variantValue;
QDataStream ds(data);
ds >> variantValue;
cast<Private>(resource)->q_func()->setProperty(name, variantValue);
}
QtExtendedSurfaceInterface::QtExtendedSurfaceInterface(QtSurfaceExtensionInterface *shell, SurfaceInterface *parent, wl_resource *parentResource)
: Resource(new Private(this, shell, parent, parentResource))
{
auto unsetSurface = [this] {
Q_D();
d->surface = nullptr;
};
connect(parent, &Resource::unbound, this, unsetSurface);
connect(parent, &QObject::destroyed, this, unsetSurface);
}
QtExtendedSurfaceInterface::~QtExtendedSurfaceInterface() = default;
SurfaceInterface *QtExtendedSurfaceInterface::surface() const
{
Q_D();
return d->surface;
}
QtSurfaceExtensionInterface *QtExtendedSurfaceInterface::shell() const
{
Q_D();
return reinterpret_cast<QtSurfaceExtensionInterface*>(d->global);
}
QtExtendedSurfaceInterface::Private *QtExtendedSurfaceInterface::d_func() const
{
return reinterpret_cast<QtExtendedSurfaceInterface::Private*>(d.data());
}
void QtExtendedSurfaceInterface::close()
{
Q_D();
if (!d->resource) {
return;
}
qt_extended_surface_send_close(d->resource);
d->client->flush();
}
}
/*
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef WAYLAND_SERVER_QTSURFACEEXTENSION_INTERFACE_H
#define WAYLAND_SERVER_QTSURFACEEXTENSION_INTERFACE_H
#include <QObject>
#include <KWaylandServer/kwaylandserver_export.h>
#include "global.h"
#include "resource.h"
class QSize;
struct wl_resource;
namespace KWaylandServer
{
class Display;
class SurfaceInterface;
class QtExtendedSurfaceInterface;
/**
* TODO
*/
class KWAYLANDSERVER_EXPORT QtSurfaceExtensionInterface : public Global
{
Q_OBJECT
public:
virtual ~QtSurfaceExtensionInterface();
Q_SIGNALS:
void surfaceCreated(KWaylandServer::QtExtendedSurfaceInterface*);
private:
friend class Display;
explicit QtSurfaceExtensionInterface(Display *display, QObject *parent);
class Private;
};
/**
* TODO
*/
class KWAYLANDSERVER_EXPORT QtExtendedSurfaceInterface : public Resource
{
Q_OBJECT
public:
virtual ~QtExtendedSurfaceInterface();
SurfaceInterface *surface() const;
QtSurfaceExtensionInterface *shell() const;
void close();
Q_SIGNALS:
/**
* Requests that the window be raised to appear above other windows.
* @since 5.5
**/
void raiseRequested();
/**
* Requests that the window be lowered to appear below other windows.
* @since 5.5
**/
void lowerRequested();
private:
friend class QtSurfaceExtensionInterface;
explicit QtExtendedSurfaceInterface(QtSurfaceExtensionInterface *shell, SurfaceInterface *parent, wl_resource *parentResource);
class Private;
Private *d_func() const;
};
}
#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