diff options
author | David Redondo <qt@david-redondo.de> | 2024-03-07 15:18:40 +0100 |
---|---|---|
committer | David Redondo <qt@david-redondo.de> | 2024-05-10 08:57:33 +0200 |
commit | de2c3b3f85698d210ccfdb4b1e65e1c397a1cd3a (patch) | |
tree | 08b60b33367f0a4df03bc53e1ff9aab6d32c6a0c /src/client | |
parent | a5bea434aa9137f9b0ba6170fbb5a237e890b021 (diff) |
client: Disentangle platform services and windowmanagerintegration
The current state was a bit messy with the platform services being
the potentially no initialised qt window manager extension wayland
object.
Change-Id: Id1f911b75d34fcf70594ca7257b79bf431f0643f
Reviewed-by: David Edmundson <davidedmundson@kde.org>
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/client/qwaylanddisplay.cpp | 8 | ||||
-rw-r--r-- | src/client/qwaylanddisplay_p.h | 3 | ||||
-rw-r--r-- | src/client/qwaylandintegration.cpp | 7 | ||||
-rw-r--r-- | src/client/qwaylandintegration_p.h | 2 | ||||
-rw-r--r-- | src/client/qwaylandplatformservices.cpp | 50 | ||||
-rw-r--r-- | src/client/qwaylandplatformservices_p.h | 48 | ||||
-rw-r--r-- | src/client/qwaylandwindow.cpp | 2 | ||||
-rw-r--r-- | src/client/qwaylandwindowmanagerintegration.cpp | 71 | ||||
-rw-r--r-- | src/client/qwaylandwindowmanagerintegration_p.h | 26 |
10 files changed, 127 insertions, 91 deletions
diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 4916af81e..300fd4ffa 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -42,6 +42,7 @@ qt_internal_add_module(WaylandClient qwaylandinputmethodcontext.cpp qwaylandinputmethodcontext_p.h qwaylandintegration.cpp qwaylandintegration_p.h qwaylandnativeinterface.cpp qwaylandnativeinterface_p.h + qwaylandplatformservices.cpp qwaylandplatformservices_p.h qwaylandpointergestures.cpp qwaylandpointergestures_p.h qwaylandqtkey.cpp qwaylandqtkey_p.h qwaylandscreen.cpp qwaylandscreen_p.h diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp index 265f0bb3f..9bd60e741 100644 --- a/src/client/qwaylanddisplay.cpp +++ b/src/client/qwaylanddisplay.cpp @@ -312,7 +312,7 @@ QWaylandClientBufferIntegration * QWaylandDisplay::clientBufferIntegration() con QWaylandWindowManagerIntegration *QWaylandDisplay::windowManagerIntegration() const { - return mWindowManagerIntegration.data(); + return mGlobals.windowManagerIntegration.get(); } QWaylandDisplay::QWaylandDisplay(QWaylandIntegration *waylandIntegration) @@ -335,8 +335,6 @@ void QWaylandDisplay::setupConnection() struct ::wl_registry *registry = wl_display_get_registry(mDisplay); init(registry); - mWindowManagerIntegration.reset(new QWaylandWindowManagerIntegration(this)); - #if QT_CONFIG(xkbcommon) mXkbContext.reset(xkb_context_new(XKB_CONTEXT_NO_FLAGS)); if (!mXkbContext) @@ -373,7 +371,6 @@ QWaylandDisplay::~QWaylandDisplay(void) // Reset the globals manually since they need to be destroyed before the wl_display mGlobals = {}; - mWindowManagerIntegration.reset(); if (object()) wl_registry_destroy(object()); @@ -781,6 +778,9 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin mGlobals.xdgToplevelDragManager.reset( new WithDestructor<QtWayland::xdg_toplevel_drag_manager_v1, xdg_toplevel_drag_manager_v1_destroy>(registry, id, 1)); + } else if (interface == QLatin1String(QtWayland::qt_windowmanager::interface()->name)) { + mGlobals.windowManagerIntegration.reset( + new QWaylandWindowManagerIntegration(this, id, version)); } mRegistryGlobals.append(RegistryGlobal(id, interface, version, registry)); diff --git a/src/client/qwaylanddisplay_p.h b/src/client/qwaylanddisplay_p.h index 5b564c8d7..2fd176d84 100644 --- a/src/client/qwaylanddisplay_p.h +++ b/src/client/qwaylanddisplay_p.h @@ -316,8 +316,6 @@ private: QScopedPointer<QWaylandCursor> mCursor; #endif - QScopedPointer<QWaylandWindowManagerIntegration> mWindowManagerIntegration; - struct GlobalHolder { std::unique_ptr<QtWayland::wl_compositor> compositor; @@ -346,6 +344,7 @@ private: std::unique_ptr<QtWayland::wp_fractional_scale_manager_v1> fractionalScaleManager; std::unique_ptr<QtWayland::wp_cursor_shape_manager_v1> cursorShapeManager; std::unique_ptr<QtWayland::xdg_toplevel_drag_manager_v1> xdgToplevelDragManager; + std::unique_ptr<QWaylandWindowManagerIntegration> windowManagerIntegration; } mGlobals; int mFd = -1; int mWritableNotificationFd = -1; diff --git a/src/client/qwaylandintegration.cpp b/src/client/qwaylandintegration.cpp index eb19be45d..c5eb1e96a 100644 --- a/src/client/qwaylandintegration.cpp +++ b/src/client/qwaylandintegration.cpp @@ -15,6 +15,7 @@ #endif #include "qwaylanddnd_p.h" #include "qwaylandwindowmanagerintegration_p.h" +#include "qwaylandplatformservices_p.h" #include "qwaylandscreen_p.h" #include "qwaylandcursor_p.h" @@ -83,6 +84,7 @@ QWaylandIntegration::QWaylandIntegration() #endif { mDisplay.reset(new QWaylandDisplay(this)); + mPlatformServices.reset(new QWaylandPlatformServices(mDisplay.data())); QWaylandWindow::fixedToplevelPositions = !qEnvironmentVariableIsSet("QT_WAYLAND_DISABLE_FIXED_POSITIONS"); @@ -246,7 +248,7 @@ QPlatformAccessibility *QWaylandIntegration::accessibility() const QPlatformServices *QWaylandIntegration::services() const { - return mDisplay->windowManagerIntegration(); + return mPlatformServices.data(); } QWaylandDisplay *QWaylandIntegration::display() const @@ -525,8 +527,7 @@ void QWaylandIntegration::reset() void QWaylandIntegration::setApplicationBadge(qint64 number) { - auto unixServices = mDisplay->windowManagerIntegration(); - unixServices->setApplicationBadge(number); + mPlatformServices->setApplicationBadge(number); } } diff --git a/src/client/qwaylandintegration_p.h b/src/client/qwaylandintegration_p.h index 81d1ae6d2..f26cc3d29 100644 --- a/src/client/qwaylandintegration_p.h +++ b/src/client/qwaylandintegration_p.h @@ -34,6 +34,7 @@ class QWaylandInputDeviceIntegration; class QWaylandInputDevice; class QWaylandScreen; class QWaylandCursor; +class QWaylandPlatformServices; class Q_WAYLANDCLIENT_EXPORT QWaylandIntegration : public QPlatformIntegration { @@ -136,6 +137,7 @@ private: #if QT_CONFIG(accessibility) mutable QScopedPointer<QPlatformAccessibility> mAccessibility; #endif + QScopedPointer<QWaylandPlatformServices> mPlatformServices; QMutex mClientBufferInitLock; bool mClientBufferIntegrationInitialized = false; bool mServerBufferIntegrationInitialized = false; diff --git a/src/client/qwaylandplatformservices.cpp b/src/client/qwaylandplatformservices.cpp new file mode 100644 index 000000000..14556d282 --- /dev/null +++ b/src/client/qwaylandplatformservices.cpp @@ -0,0 +1,50 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "qwaylandplatformservices_p.h" +#include "qwaylandwindow_p.h" +#include "qwaylanddisplay_p.h" +#include "qwaylandshellsurface_p.h" +#include "qwaylandwindowmanagerintegration_p.h" + +QT_BEGIN_NAMESPACE + +namespace QtWaylandClient { + +QWaylandPlatformServices::QWaylandPlatformServices(QWaylandDisplay *display) + : m_display(display) { } + +bool QWaylandPlatformServices::openUrl(const QUrl &url) +{ + if (auto windowManagerIntegration = m_display->windowManagerIntegration()) { + windowManagerIntegration->openUrl(url); + return true; + } + return QGenericUnixServices::openUrl(url); +} + +bool QWaylandPlatformServices::openDocument(const QUrl &url) +{ + if (auto windowManagerIntegration = m_display->windowManagerIntegration()) { + windowManagerIntegration->openUrl(url); + return true; + } + return QGenericUnixServices::openDocument(url); +} + +QString QWaylandPlatformServices::portalWindowIdentifier(QWindow *window) +{ + if (window && window->handle()) { + auto shellSurface = static_cast<QWaylandWindow *>(window->handle())->shellSurface(); + if (shellSurface) { + const QString handle = shellSurface->externWindowHandle(); + return QLatin1String("wayland:") + handle; + } + } + return QString(); +} +} // namespace QtWaylandClient + +QT_END_NAMESPACE + +#include "moc_qwaylandplatformservices_p.cpp" diff --git a/src/client/qwaylandplatformservices_p.h b/src/client/qwaylandplatformservices_p.h new file mode 100644 index 000000000..6106a9018 --- /dev/null +++ b/src/client/qwaylandplatformservices_p.h @@ -0,0 +1,48 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef QWAYLANDPLATFORMSERVICES_H +#define QWAYLANDPLATFORMSERVICES_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/QObject> + +#include <QtGui/private/qgenericunixservices_p.h> + +#include <QtWaylandClient/private/qwayland-qt-windowmanager.h> +#include <QtWaylandClient/qtwaylandclientglobal.h> + +QT_BEGIN_NAMESPACE + +namespace QtWaylandClient { + +class QWaylandDisplay; + +class Q_WAYLANDCLIENT_EXPORT QWaylandPlatformServices : public QGenericUnixServices +{ +public: + explicit QWaylandPlatformServices(QWaylandDisplay *waylandDisplay); + + bool openUrl(const QUrl &url) override; + bool openDocument(const QUrl &url) override; + QString portalWindowIdentifier(QWindow *window) override; + +private: + QWaylandDisplay *m_display; +}; + +QT_END_NAMESPACE + +} // namespace QtWaylandClient + +#endif // QWAYLANDPLATFORMSERVICES_H diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp index 081110f83..73fb331eb 100644 --- a/src/client/qwaylandwindow.cpp +++ b/src/client/qwaylandwindow.cpp @@ -12,7 +12,7 @@ #include "qwaylandshellsurface_p.h" #include "qwaylandsubsurface_p.h" #include "qwaylandabstractdecoration_p.h" -#include "qwaylandwindowmanagerintegration_p.h" +#include "qwaylandplatformservices_p.h" #include "qwaylandnativeinterface_p.h" #include "qwaylanddecorationfactory_p.h" #include "qwaylandshmbackingstore_p.h" diff --git a/src/client/qwaylandwindowmanagerintegration.cpp b/src/client/qwaylandwindowmanagerintegration.cpp index 149190420..c7a5c0d14 100644 --- a/src/client/qwaylandwindowmanagerintegration.cpp +++ b/src/client/qwaylandwindowmanagerintegration.cpp @@ -22,49 +22,26 @@ QT_BEGIN_NAMESPACE namespace QtWaylandClient { -class QWaylandWindowManagerIntegrationPrivate { -public: - QWaylandWindowManagerIntegrationPrivate(QWaylandDisplay *waylandDisplay); - bool m_blockPropertyUpdates = false; - QWaylandDisplay *m_waylandDisplay = nullptr; - QHash<QWindow*, QVariantMap> m_queuedProperties; - bool m_showIsFullScreen = false; -}; - -QWaylandWindowManagerIntegrationPrivate::QWaylandWindowManagerIntegrationPrivate(QWaylandDisplay *waylandDisplay) - : m_waylandDisplay(waylandDisplay) -{ -} - -QWaylandWindowManagerIntegration::QWaylandWindowManagerIntegration(QWaylandDisplay *waylandDisplay) - : d_ptr(new QWaylandWindowManagerIntegrationPrivate(waylandDisplay)) +QWaylandWindowManagerIntegration::QWaylandWindowManagerIntegration(QWaylandDisplay *waylandDisplay, + uint id, uint version) + : QtWayland::qt_windowmanager(waylandDisplay->object(), id, version), + m_waylandDisplay(waylandDisplay) { - waylandDisplay->addRegistryListener(&wlHandleListenerGlobal, this); } QWaylandWindowManagerIntegration::~QWaylandWindowManagerIntegration() { - if (object()) - qt_windowmanager_destroy(object()); + qt_windowmanager_destroy(object()); } bool QWaylandWindowManagerIntegration::showIsFullScreen() const { - Q_D(const QWaylandWindowManagerIntegration); - return d->m_showIsFullScreen; -} - -void QWaylandWindowManagerIntegration::wlHandleListenerGlobal(void *data, wl_registry *registry, uint32_t id, const QString &interface, uint32_t version) -{ - Q_UNUSED(version); - if (interface == QStringLiteral("qt_windowmanager")) - static_cast<QWaylandWindowManagerIntegration *>(data)->init(registry, id, 1); + return m_showIsFullScreen; } void QWaylandWindowManagerIntegration::windowmanager_hints(int32_t showIsFullScreen) { - Q_D(QWaylandWindowManagerIntegration); - d->m_showIsFullScreen = showIsFullScreen; + m_showIsFullScreen = showIsFullScreen; } void QWaylandWindowManagerIntegration::windowmanager_quit() @@ -72,11 +49,9 @@ void QWaylandWindowManagerIntegration::windowmanager_quit() QGuiApplication::quit(); } -void QWaylandWindowManagerIntegration::openUrl_helper(const QUrl &url) +void QWaylandWindowManagerIntegration::openUrl(const QUrl &url) { - Q_ASSERT(isInitialized()); QString data = url.toString(); - static const int chunkSize = 128; while (!data.isEmpty()) { QString chunk = data.left(chunkSize); @@ -88,36 +63,6 @@ void QWaylandWindowManagerIntegration::openUrl_helper(const QUrl &url) open_url(!data.isEmpty(), chunk); } } - -bool QWaylandWindowManagerIntegration::openUrl(const QUrl &url) -{ - if (isInitialized()) { - openUrl_helper(url); - return true; - } - return QGenericUnixServices::openUrl(url); -} - -bool QWaylandWindowManagerIntegration::openDocument(const QUrl &url) -{ - if (isInitialized()) { - openUrl_helper(url); - return true; - } - return QGenericUnixServices::openDocument(url); -} - -QString QWaylandWindowManagerIntegration::portalWindowIdentifier(QWindow *window) -{ - if (window && window->handle()) { - auto shellSurface = static_cast<QWaylandWindow *>(window->handle())->shellSurface(); - if (shellSurface) { - const QString handle = shellSurface->externWindowHandle(); - return QLatin1String("wayland:") + handle; - } - } - return QString(); -} } QT_END_NAMESPACE diff --git a/src/client/qwaylandwindowmanagerintegration_p.h b/src/client/qwaylandwindowmanagerintegration_p.h index 18eb171b6..76d9b0da0 100644 --- a/src/client/qwaylandwindowmanagerintegration_p.h +++ b/src/client/qwaylandwindowmanagerintegration_p.h @@ -16,9 +16,6 @@ // #include <QtCore/QObject> -#include <QtCore/QScopedPointer> - -#include <QtGui/private/qgenericunixservices_p.h> #include <QtWaylandClient/private/qwayland-qt-windowmanager.h> #include <QtWaylandClient/qtwaylandclientglobal.h> @@ -27,35 +24,28 @@ QT_BEGIN_NAMESPACE namespace QtWaylandClient { -class QWaylandWindow; class QWaylandDisplay; class QWaylandWindowManagerIntegrationPrivate; -class Q_WAYLANDCLIENT_EXPORT QWaylandWindowManagerIntegration : public QObject, public QGenericUnixServices, public QtWayland::qt_windowmanager +class Q_WAYLANDCLIENT_EXPORT QWaylandWindowManagerIntegration : public QtWayland::qt_windowmanager { - Q_OBJECT - Q_DECLARE_PRIVATE(QWaylandWindowManagerIntegration) + public: - explicit QWaylandWindowManagerIntegration(QWaylandDisplay *waylandDisplay); - ~QWaylandWindowManagerIntegration() override; + explicit QWaylandWindowManagerIntegration(QWaylandDisplay *waylandDisplay, uint id, + uint version); + ~QWaylandWindowManagerIntegration(); - bool openUrl(const QUrl &url) override; - bool openDocument(const QUrl &url) override; - QString portalWindowIdentifier(QWindow *window) override; + void openUrl(const QUrl &url); bool showIsFullScreen() const; private: - static void wlHandleListenerGlobal(void *data, wl_registry *registry, uint32_t id, - const QString &interface, uint32_t version); - - QScopedPointer<QWaylandWindowManagerIntegrationPrivate> d_ptr; - void windowmanager_hints(int32_t showIsFullScreen) override; void windowmanager_quit() override; - void openUrl_helper(const QUrl &url); + QWaylandDisplay *m_waylandDisplay = nullptr; + bool m_showIsFullScreen = false; }; QT_END_NAMESPACE |