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>
This commit is contained in:
David Redondo 2024-03-07 15:18:40 +01:00
parent 4313de83d6
commit 24cd08a667
10 changed files with 128 additions and 92 deletions

View File

@ -42,6 +42,7 @@ qt_internal_add_module(WaylandClient
qwaylandinputmethodcontext.cpp qwaylandinputmethodcontext_p.h qwaylandinputmethodcontext.cpp qwaylandinputmethodcontext_p.h
qwaylandintegration.cpp qwaylandintegration_p.h qwaylandintegration.cpp qwaylandintegration_p.h
qwaylandnativeinterface.cpp qwaylandnativeinterface_p.h qwaylandnativeinterface.cpp qwaylandnativeinterface_p.h
qwaylandplatformservices.cpp qwaylandplatformservices_p.h
qwaylandpointergestures.cpp qwaylandpointergestures_p.h qwaylandpointergestures.cpp qwaylandpointergestures_p.h
qwaylandqtkey.cpp qwaylandqtkey_p.h qwaylandqtkey.cpp qwaylandqtkey_p.h
qwaylandscreen.cpp qwaylandscreen_p.h qwaylandscreen.cpp qwaylandscreen_p.h

View File

@ -312,7 +312,7 @@ QWaylandClientBufferIntegration * QWaylandDisplay::clientBufferIntegration() con
QWaylandWindowManagerIntegration *QWaylandDisplay::windowManagerIntegration() const QWaylandWindowManagerIntegration *QWaylandDisplay::windowManagerIntegration() const
{ {
return mWindowManagerIntegration.data(); return mGlobals.windowManagerIntegration.get();
} }
QWaylandDisplay::QWaylandDisplay(QWaylandIntegration *waylandIntegration) QWaylandDisplay::QWaylandDisplay(QWaylandIntegration *waylandIntegration)
@ -335,8 +335,6 @@ void QWaylandDisplay::setupConnection()
struct ::wl_registry *registry = wl_display_get_registry(mDisplay); struct ::wl_registry *registry = wl_display_get_registry(mDisplay);
init(registry); init(registry);
mWindowManagerIntegration.reset(new QWaylandWindowManagerIntegration(this));
#if QT_CONFIG(xkbcommon) #if QT_CONFIG(xkbcommon)
mXkbContext.reset(xkb_context_new(XKB_CONTEXT_NO_FLAGS)); mXkbContext.reset(xkb_context_new(XKB_CONTEXT_NO_FLAGS));
if (!mXkbContext) if (!mXkbContext)
@ -373,7 +371,6 @@ QWaylandDisplay::~QWaylandDisplay(void)
// Reset the globals manually since they need to be destroyed before the wl_display // Reset the globals manually since they need to be destroyed before the wl_display
mGlobals = {}; mGlobals = {};
mWindowManagerIntegration.reset();
if (object()) if (object())
wl_registry_destroy(object()); wl_registry_destroy(object());
@ -781,6 +778,9 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin
mGlobals.xdgToplevelDragManager.reset( mGlobals.xdgToplevelDragManager.reset(
new WithDestructor<QtWayland::xdg_toplevel_drag_manager_v1, new WithDestructor<QtWayland::xdg_toplevel_drag_manager_v1,
xdg_toplevel_drag_manager_v1_destroy>(registry, id, 1)); 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)); mRegistryGlobals.append(RegistryGlobal(id, interface, version, registry));

View File

@ -316,8 +316,6 @@ private:
QScopedPointer<QWaylandCursor> mCursor; QScopedPointer<QWaylandCursor> mCursor;
#endif #endif
QScopedPointer<QWaylandWindowManagerIntegration> mWindowManagerIntegration;
struct GlobalHolder struct GlobalHolder
{ {
std::unique_ptr<QtWayland::wl_compositor> compositor; 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_fractional_scale_manager_v1> fractionalScaleManager;
std::unique_ptr<QtWayland::wp_cursor_shape_manager_v1> cursorShapeManager; std::unique_ptr<QtWayland::wp_cursor_shape_manager_v1> cursorShapeManager;
std::unique_ptr<QtWayland::xdg_toplevel_drag_manager_v1> xdgToplevelDragManager; std::unique_ptr<QtWayland::xdg_toplevel_drag_manager_v1> xdgToplevelDragManager;
std::unique_ptr<QWaylandWindowManagerIntegration> windowManagerIntegration;
} mGlobals; } mGlobals;
int mFd = -1; int mFd = -1;
int mWritableNotificationFd = -1; int mWritableNotificationFd = -1;

View File

@ -15,6 +15,7 @@
#endif #endif
#include "qwaylanddnd_p.h" #include "qwaylanddnd_p.h"
#include "qwaylandwindowmanagerintegration_p.h" #include "qwaylandwindowmanagerintegration_p.h"
#include "qwaylandplatformservices_p.h"
#include "qwaylandscreen_p.h" #include "qwaylandscreen_p.h"
#include "qwaylandcursor_p.h" #include "qwaylandcursor_p.h"
@ -83,6 +84,7 @@ QWaylandIntegration::QWaylandIntegration()
#endif #endif
{ {
mDisplay.reset(new QWaylandDisplay(this)); mDisplay.reset(new QWaylandDisplay(this));
mPlatformServices.reset(new QWaylandPlatformServices(mDisplay.data()));
QWaylandWindow::fixedToplevelPositions = QWaylandWindow::fixedToplevelPositions =
!qEnvironmentVariableIsSet("QT_WAYLAND_DISABLE_FIXED_POSITIONS"); !qEnvironmentVariableIsSet("QT_WAYLAND_DISABLE_FIXED_POSITIONS");
@ -246,7 +248,7 @@ QPlatformAccessibility *QWaylandIntegration::accessibility() const
QPlatformServices *QWaylandIntegration::services() const QPlatformServices *QWaylandIntegration::services() const
{ {
return mDisplay->windowManagerIntegration(); return mPlatformServices.data();
} }
QWaylandDisplay *QWaylandIntegration::display() const QWaylandDisplay *QWaylandIntegration::display() const
@ -525,8 +527,7 @@ void QWaylandIntegration::reset()
void QWaylandIntegration::setApplicationBadge(qint64 number) void QWaylandIntegration::setApplicationBadge(qint64 number)
{ {
auto unixServices = mDisplay->windowManagerIntegration(); mPlatformServices->setApplicationBadge(number);
unixServices->setApplicationBadge(number);
} }
} }

View File

@ -34,6 +34,7 @@ class QWaylandInputDeviceIntegration;
class QWaylandInputDevice; class QWaylandInputDevice;
class QWaylandScreen; class QWaylandScreen;
class QWaylandCursor; class QWaylandCursor;
class QWaylandPlatformServices;
class Q_WAYLANDCLIENT_EXPORT QWaylandIntegration : public QPlatformIntegration class Q_WAYLANDCLIENT_EXPORT QWaylandIntegration : public QPlatformIntegration
{ {
@ -136,6 +137,7 @@ private:
#if QT_CONFIG(accessibility) #if QT_CONFIG(accessibility)
mutable QScopedPointer<QPlatformAccessibility> mAccessibility; mutable QScopedPointer<QPlatformAccessibility> mAccessibility;
#endif #endif
QScopedPointer<QWaylandPlatformServices> mPlatformServices;
QMutex mClientBufferInitLock; QMutex mClientBufferInitLock;
bool mClientBufferIntegrationInitialized = false; bool mClientBufferIntegrationInitialized = false;
bool mServerBufferIntegrationInitialized = false; bool mServerBufferIntegrationInitialized = false;

View File

@ -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"

View File

@ -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

View File

@ -12,7 +12,7 @@
#include "qwaylandshellsurface_p.h" #include "qwaylandshellsurface_p.h"
#include "qwaylandsubsurface_p.h" #include "qwaylandsubsurface_p.h"
#include "qwaylandabstractdecoration_p.h" #include "qwaylandabstractdecoration_p.h"
#include "qwaylandwindowmanagerintegration_p.h" #include "qwaylandplatformservices_p.h"
#include "qwaylandnativeinterface_p.h" #include "qwaylandnativeinterface_p.h"
#include "qwaylanddecorationfactory_p.h" #include "qwaylanddecorationfactory_p.h"
#include "qwaylandshmbackingstore_p.h" #include "qwaylandshmbackingstore_p.h"

View File

@ -22,49 +22,26 @@ QT_BEGIN_NAMESPACE
namespace QtWaylandClient { namespace QtWaylandClient {
class QWaylandWindowManagerIntegrationPrivate { QWaylandWindowManagerIntegration::QWaylandWindowManagerIntegration(QWaylandDisplay *waylandDisplay,
public: uint id, uint version)
QWaylandWindowManagerIntegrationPrivate(QWaylandDisplay *waylandDisplay); : QtWayland::qt_windowmanager(waylandDisplay->object(), id, version),
bool m_blockPropertyUpdates = false; m_waylandDisplay(waylandDisplay)
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))
{
waylandDisplay->addRegistryListener(&wlHandleListenerGlobal, this);
}
QWaylandWindowManagerIntegration::~QWaylandWindowManagerIntegration() QWaylandWindowManagerIntegration::~QWaylandWindowManagerIntegration()
{ {
if (object()) qt_windowmanager_destroy(object());
qt_windowmanager_destroy(object());
} }
bool QWaylandWindowManagerIntegration::showIsFullScreen() const bool QWaylandWindowManagerIntegration::showIsFullScreen() const
{ {
Q_D(const QWaylandWindowManagerIntegration); return m_showIsFullScreen;
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);
} }
void QWaylandWindowManagerIntegration::windowmanager_hints(int32_t showIsFullScreen) void QWaylandWindowManagerIntegration::windowmanager_hints(int32_t showIsFullScreen)
{ {
Q_D(QWaylandWindowManagerIntegration); m_showIsFullScreen = showIsFullScreen;
d->m_showIsFullScreen = showIsFullScreen;
} }
void QWaylandWindowManagerIntegration::windowmanager_quit() void QWaylandWindowManagerIntegration::windowmanager_quit()
@ -72,11 +49,9 @@ void QWaylandWindowManagerIntegration::windowmanager_quit()
QGuiApplication::quit(); QGuiApplication::quit();
} }
void QWaylandWindowManagerIntegration::openUrl_helper(const QUrl &url) void QWaylandWindowManagerIntegration::openUrl(const QUrl &url)
{ {
Q_ASSERT(isInitialized());
QString data = url.toString(); QString data = url.toString();
static const int chunkSize = 128; static const int chunkSize = 128;
while (!data.isEmpty()) { while (!data.isEmpty()) {
QString chunk = data.left(chunkSize); QString chunk = data.left(chunkSize);
@ -88,36 +63,6 @@ void QWaylandWindowManagerIntegration::openUrl_helper(const QUrl &url)
open_url(!data.isEmpty(), chunk); 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 QT_END_NAMESPACE

View File

@ -16,9 +16,6 @@
// //
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QScopedPointer>
#include <QtGui/private/qgenericunixservices_p.h>
#include <QtWaylandClient/private/qwayland-qt-windowmanager.h> #include <QtWaylandClient/private/qwayland-qt-windowmanager.h>
#include <QtWaylandClient/qtwaylandclientglobal.h> #include <QtWaylandClient/qtwaylandclientglobal.h>
@ -27,35 +24,28 @@ QT_BEGIN_NAMESPACE
namespace QtWaylandClient { namespace QtWaylandClient {
class QWaylandWindow;
class QWaylandDisplay; class QWaylandDisplay;
class QWaylandWindowManagerIntegrationPrivate; 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;
bool openUrl(const QUrl &url) override; public:
bool openDocument(const QUrl &url) override; explicit QWaylandWindowManagerIntegration(QWaylandDisplay *waylandDisplay, uint id,
QString portalWindowIdentifier(QWindow *window) override; uint version);
~QWaylandWindowManagerIntegration();
void openUrl(const QUrl &url);
bool showIsFullScreen() const; bool showIsFullScreen() const;
private: 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_hints(int32_t showIsFullScreen) override;
void windowmanager_quit() override; void windowmanager_quit() override;
void openUrl_helper(const QUrl &url); QWaylandDisplay *m_waylandDisplay = nullptr;
bool m_showIsFullScreen = false;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE