From e4bf7e0334f6a4e9c6f28fb3b71aa21111e3fe28 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 21 Jul 2021 09:18:07 +0300 Subject: [PATCH] Drop Global and Resource classes They're unused. --- src/wayland/CMakeLists.txt | 4 - .../datacontroldevicemanager_v1_interface.cpp | 1 - src/wayland/datadevicemanager_interface.cpp | 1 - src/wayland/server/global.cpp | 95 ---------------- src/wayland/server/global.h | 90 --------------- src/wayland/server/global_p.h | 46 -------- src/wayland/server/resource.cpp | 104 ------------------ src/wayland/server/resource.h | 82 -------------- src/wayland/server/resource_p.h | 78 ------------- 9 files changed, 501 deletions(-) delete mode 100644 src/wayland/server/global.cpp delete mode 100644 src/wayland/server/global.h delete mode 100644 src/wayland/server/global_p.h delete mode 100644 src/wayland/server/resource.cpp delete mode 100644 src/wayland/server/resource.h delete mode 100644 src/wayland/server/resource_p.h diff --git a/src/wayland/CMakeLists.txt b/src/wayland/CMakeLists.txt index 0aac977727..3267ad801a 100644 --- a/src/wayland/CMakeLists.txt +++ b/src/wayland/CMakeLists.txt @@ -21,7 +21,6 @@ set(SERVER_LIB_SRCS eglstream_controller_interface.cpp fakeinput_interface.cpp filtered_display.cpp - global.cpp idle_interface.cpp idleinhibit_v1_interface.cpp inputmethod_v1_interface.cpp @@ -47,7 +46,6 @@ set(SERVER_LIB_SRCS primaryselectionsource_v1_interface.cpp region_interface.cpp relativepointer_v1_interface.cpp - resource.cpp screencast_v1_interface.cpp seat_interface.cpp server_decoration_interface.cpp @@ -342,7 +340,6 @@ set(SERVER_LIB_HEADERS eglstream_controller_interface.h fakeinput_interface.h filtered_display.h - global.h idle_interface.h idleinhibit_v1_interface.h inputmethod_v1_interface.h @@ -364,7 +361,6 @@ set(SERVER_LIB_HEADERS pointergestures_v1_interface.h primaryselectiondevicemanager_v1_interface.h relativepointer_v1_interface.h - resource.h screencast_v1_interface.h seat_interface.h server_decoration_interface.h diff --git a/src/wayland/datacontroldevicemanager_v1_interface.cpp b/src/wayland/datacontroldevicemanager_v1_interface.cpp index 4cec0055fb..aa6bd00a93 100644 --- a/src/wayland/datacontroldevicemanager_v1_interface.cpp +++ b/src/wayland/datacontroldevicemanager_v1_interface.cpp @@ -7,7 +7,6 @@ #include "datacontroldevicemanager_v1_interface.h" #include "datacontroldevice_v1_interface.h" #include "datacontrolsource_v1_interface.h" -#include "global_p.h" #include "display.h" #include "seat_interface_p.h" // Wayland diff --git a/src/wayland/datadevicemanager_interface.cpp b/src/wayland/datadevicemanager_interface.cpp index 6223f97879..99c0ffa1c0 100644 --- a/src/wayland/datadevicemanager_interface.cpp +++ b/src/wayland/datadevicemanager_interface.cpp @@ -6,7 +6,6 @@ */ #include "datadevicemanager_interface.h" #include "datasource_interface.h" -#include "global_p.h" #include "display.h" #include "seat_interface_p.h" // Wayland diff --git a/src/wayland/server/global.cpp b/src/wayland/server/global.cpp deleted file mode 100644 index c9b1687e76..0000000000 --- a/src/wayland/server/global.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - SPDX-FileCopyrightText: 2014 Martin Gräßlin - - SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL -*/ -#include "global.h" -#include "global_p.h" -#include "display.h" -// wayland -#include - -namespace KWaylandServer -{ - -Global::Private::Private(Display *d, const wl_interface *interface, quint32 version) - : display(d) - , m_interface(interface) - , m_version(version) -{ -} - -Global::Private::~Private() = default; - -void Global::Private::bind(wl_client *client, void *data, uint32_t version, uint32_t id) -{ - auto d = reinterpret_cast(data); - d->bind(client, version, id); -} - -void Global::Private::create() -{ - Q_ASSERT(!global); - global = wl_global_create(*display, m_interface, m_version, this, bind); -} - -static void handleDisplayDestroyed(struct wl_listener *listener, void *data) -{ - Q_UNUSED(data) - Global *global = static_cast(listener)->global; - global->destroy(); -} - -Global::Global(Global::Private *d, QObject *parent) - : QObject(parent) - , d(d) -{ - d->displayDestroyListener.notify = handleDisplayDestroyed; - d->displayDestroyListener.global = this; - d->displayDestroyListener.link.next = nullptr; - d->displayDestroyListener.link.prev = nullptr; - wl_display_add_destroy_listener(*d->display, &d->displayDestroyListener); -} - -Global::~Global() -{ - destroy(); - wl_list_remove(&d->displayDestroyListener.link); -} - -void Global::create() -{ - d->create(); -} - -void Global::destroy() -{ - if (!d->global) { - return; - } - Q_EMIT aboutToDestroyGlobal(); - wl_global_destroy(d->global); - d->global = nullptr; -} - -bool Global::isValid() const -{ - return d->global != nullptr; -} - -Global::operator wl_global*() const -{ - return d->global; -} - -Global::operator wl_global*() -{ - return d->global; -} - -Display *Global::display() -{ - return d->display; -} - -} diff --git a/src/wayland/server/global.h b/src/wayland/server/global.h deleted file mode 100644 index 535e52ed33..0000000000 --- a/src/wayland/server/global.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - SPDX-FileCopyrightText: 2014 Martin Gräßlin - - SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL -*/ -#pragma once - -#include - -#include - -struct wl_global; - -namespace KWaylandServer -{ -class Display; - -/** - * @brief Base class for all Globals. - * - * Any class representing a Global should be derived from this base class. - * This class provides common functionality for all globals. A global is an - * object listed as an interface on the registry on client side. - * - * Normally a Global gets factored by the Display. For each Global-derived class there - * is a dedicated factory method. After creating an instance through the factory method - * it is not yet announced on the registry. One needs to call ::create on it. This allows - * to setup the Global before it gets announced, ensuring that the client's state is correct - * from the start. - * - * As an example shown for @link OutputInterface @endlink: - * @code - * Display *display; // The existing display - * auto o = display->createOutput(); - * o->setManufacturer(QStringLiteral("The KDE Community")); - * // setup further data on the OutputInterface - * o->create(); // announces OutputInterface - * @endcode - * - * @see Display - * - */ -class KWAYLANDSERVER_EXPORT Global : public QObject -{ - Q_OBJECT -public: - virtual ~Global(); - /** - * Creates the global by creating a native wl_global and by that announcing it - * to the clients. - */ - void create(); - /** - * Destroys the low level wl_global. Afterwards the Global is no longer shown to clients. - */ - void destroy(); - /** - * @returns whether the Global got created - */ - bool isValid() const; - - /** - * @returns the Display the Global got created on. - */ - Display *display(); - - /** - * Cast operator to the native wl_global this Global represents. - */ - operator wl_global*(); - /** - * Cast operator to the native wl_global this Global represents. - */ - operator wl_global*() const; - -Q_SIGNALS: - /** - * This signal is emitted when the client is in the process of removing the wl_global. - * At the time the signal is emitted the global is still valid and allows to perform - * cleanup tasks. - */ - void aboutToDestroyGlobal(); - -protected: - class Private; - explicit Global(Private *d, QObject *parent = nullptr); - QScopedPointer d; -}; - -} diff --git a/src/wayland/server/global_p.h b/src/wayland/server/global_p.h deleted file mode 100644 index 58bf1b77ec..0000000000 --- a/src/wayland/server/global_p.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - SPDX-FileCopyrightText: 2014 Martin Gräßlin - - SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL -*/ -#pragma once - -#include "global.h" - -#include - -#include - -namespace KWaylandServer -{ - -struct DisplayDestroyListener : public wl_listener -{ - Global *global = nullptr; -}; - -class Global::Private -{ -public: - static constexpr quint32 version = 0; - virtual ~Private(); - void create(); - - // We need to reset display from the destroy listener, but due to the private class - // being nested, this is not easy to do so. Either way, we are moving away from the - // old approach, so it's not worth wasting our time. - QPointer display; - wl_global *global = nullptr; - DisplayDestroyListener displayDestroyListener; - -protected: - Private(Display *d, const wl_interface *interface, quint32 version); - virtual void bind(wl_client *client, uint32_t version, uint32_t id) = 0; - - static void bind(wl_client *client, void *data, uint32_t version, uint32_t id); - - const wl_interface *const m_interface; - const quint32 m_version; -}; - -} diff --git a/src/wayland/server/resource.cpp b/src/wayland/server/resource.cpp deleted file mode 100644 index f64a097458..0000000000 --- a/src/wayland/server/resource.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - SPDX-FileCopyrightText: 2014 Martin Gräßlin - - SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL -*/ -#include "resource.h" -#include "resource_p.h" -#include "clientconnection.h" - -#include - -namespace KWaylandServer -{ - -QList Resource::Private::s_allResources; - -Resource::Private::Private(Resource *q, Global *g, wl_resource *parentResource, const wl_interface *interface, const void *implementation) - : parentResource(parentResource) - , global(g) - , q(q) - , m_interface(interface) - , m_interfaceImplementation(implementation) -{ - s_allResources << this; -} - -Resource::Private::~Private() -{ - s_allResources.removeAll(this); - if (resource) { - wl_resource_destroy(resource); - } -} - -void Resource::Private::create(ClientConnection *c, quint32 version, quint32 id) -{ - Q_ASSERT(!resource); - Q_ASSERT(!client); - client = c; - resource = client->createResource(m_interface, version, id); - if (!resource) { - return; - } - wl_resource_set_implementation(resource, m_interfaceImplementation, this, unbind); -} - -void Resource::Private::unbind(wl_resource *r) -{ - Private *p = cast(r); - Q_EMIT p->q->aboutToBeUnbound(); - p->resource = nullptr; - Q_EMIT p->q->unbound(); - p->q->deleteLater(); -} - - -void Resource::Private::resourceDestroyedCallback(wl_client *client, wl_resource *resource) -{ - Q_UNUSED(client) - wl_resource_destroy(resource); -} - -Resource::Resource(Resource::Private *d, QObject *parent) - : QObject(parent) - , d(d) -{ -} - -Resource::~Resource() = default; - -void Resource::create(ClientConnection *client, quint32 version, quint32 id) -{ - d->create(client, version, id); -} - -ClientConnection *Resource::client() -{ - return d->client; -} - -Global *Resource::global() -{ - return d->global; -} - -wl_resource *Resource::resource() -{ - return d->resource; -} - -wl_resource *Resource::parentResource() const -{ - return d->parentResource; -} - -quint32 Resource::id() const -{ - if (!d->resource) { - return 0; - } - return wl_resource_get_id(d->resource); -} - -} diff --git a/src/wayland/server/resource.h b/src/wayland/server/resource.h deleted file mode 100644 index c985ca5209..0000000000 --- a/src/wayland/server/resource.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - SPDX-FileCopyrightText: 2014 Martin Gräßlin - - SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL -*/ -#pragma once - -#include - -#include - -struct wl_client; -struct wl_resource; - -namespace KWaylandServer -{ - -class ClientConnection; -class Global; - -/** - * @brief Represents a bound Resource. - * - * A Resource normally gets created by a @link Global @endlink. - * - * The Resource is a base class for all specific resources and provides - * access to various common aspects. - */ -class KWAYLANDSERVER_EXPORT Resource : public QObject -{ - Q_OBJECT -public: - virtual ~Resource(); - void create(ClientConnection *client, quint32 version, quint32 id); - - /** - * @returns the native wl_resource this Resource was created for. - */ - wl_resource *resource(); - /** - * @returns The ClientConnection for which the Resource was created. - */ - ClientConnection *client(); - /** - * @returns The Global which created the Resource. - */ - Global *global(); - /** - * @returns the native parent wl_resource, e.g. the wl_resource bound on the Global - */ - wl_resource *parentResource() const; - /** - * @returns The id of this Resource if it is created, otherwise @c 0. - * - * This is a convenient wrapper for wl_resource_get_id. - */ - quint32 id() const; - -Q_SIGNALS: - /** - * This signal is emitted when the client unbound this Resource. - * The Resource will be deleted in the next event cycle after this event. - */ - void unbound(); - /** - * This signal is emitted when the client is in the process of unbinding the Resource. - * In opposite to @link{unbound} the @link{resource} is still valid and allows to perform - * cleanup tasks. Example: send a keyboard leave for the Surface which is in the process of - * getting destroyed. - * - * @see unbound - */ - void aboutToBeUnbound(); - -protected: - class Private; - explicit Resource(Private *d, QObject *parent = nullptr); - QScopedPointer d; - -}; - -} diff --git a/src/wayland/server/resource_p.h b/src/wayland/server/resource_p.h deleted file mode 100644 index 54628529dd..0000000000 --- a/src/wayland/server/resource_p.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - SPDX-FileCopyrightText: 2014 Martin Gräßlin - - SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL -*/ -#pragma once - -#include "resource.h" -#include -#include - -namespace KWaylandServer -{ - -class Resource::Private -{ -public: - virtual ~Private(); - void create(ClientConnection *client, quint32 version, quint32 id); - - wl_resource *parentResource = nullptr; - wl_resource *resource = nullptr; - ClientConnection *client = nullptr; - Global *global; - - template - static ResourceDerived *get(wl_resource *native) { - static_assert(std::is_base_of::value, - "ResourceDerived must be derived from Resource"); - if (!native) { - return nullptr; - } - auto it = std::find_if(s_allResources.constBegin(), s_allResources.constEnd(), - [native](Private *p) { - return p->resource == native; - } - ); - if (it == s_allResources.constEnd()) { - return nullptr; - } - return reinterpret_cast((*it)->q); - } - template - static ResourceDerived *get(quint32 id, const ClientConnection *c) { - static_assert(std::is_base_of::value, - "ResourceDerived must be derived from Resource"); - auto it = std::find_if(s_allResources.constBegin(), s_allResources.constEnd(), - [id, c](Private *p) { - return c == p->client && p->resource && wl_resource_get_id(p->resource) == id; - } - ); - if (it == s_allResources.constEnd()) { - return nullptr; - } - return reinterpret_cast((*it)->q); - } - -protected: - explicit Private(Resource *q, Global *g, wl_resource *parentResource, const wl_interface *interface, const void *implementation); - - template - static Derived *cast(wl_resource *r) { - static_assert(std::is_base_of::value, - "Derived must be derived from Resource::Private"); - return r ? reinterpret_cast(wl_resource_get_user_data(r)) : nullptr; - } - static void unbind(wl_resource *resource); - static void resourceDestroyedCallback(wl_client *client, wl_resource *resource); - - Resource *q; - static QList s_allResources; - -private: - const wl_interface *const m_interface; - const void *const m_interfaceImplementation; -}; - -}