Consolidate the platform plugins

Instead of having multiple platform plugins, have one that switches
behavior depending on the requested platform. From the outside there
is no behavior difference. Requesting wayland-egl or wayland-brcm
fails if the feature was not enabled and initializes the client
integration early.

Task-number: QTBUG-133223
Change-Id: I6fbaec7309b78cfcc470ad18dd6b63008119760e
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
David Redondo 2025-02-28 11:50:23 +01:00
parent 5e9c9eba0f
commit ab73b6c286
7 changed files with 91 additions and 5 deletions

View File

@ -10,6 +10,7 @@
QT_BEGIN_NAMESPACE
using RegistryGlobal = QtWaylandClient::QWaylandDisplay::RegistryGlobal;
using namespace Qt::StringLiterals;
QWaylandClientExtensionPrivate::QWaylandClientExtensionPrivate()
{
@ -17,7 +18,7 @@ QWaylandClientExtensionPrivate::QWaylandClientExtensionPrivate()
// but also add the possibility to run it as a QML component.
waylandIntegration = QtWaylandClient::QWaylandIntegration::instance();
if (!waylandIntegration)
waylandIntegration = new QtWaylandClient::QWaylandIntegration();
waylandIntegration = new QtWaylandClient::QWaylandIntegration("wayland"_L1);
}
void QWaylandClientExtensionPrivate::globalAdded(const RegistryGlobal &global)

View File

@ -5,7 +5,7 @@
add_subdirectory(hardwareintegration)
if(TARGET Qt::WaylandClient)
add_subdirectory(platforms)
add_subdirectory(platform)
add_subdirectory(decorations)
add_subdirectory(shellintegration)
endif()

View File

@ -0,0 +1,24 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
# Generated from qwayland-generic.pro.
#####################################################################
## QWaylandIntegrationPlugin Plugin:
#####################################################################
qt_internal_add_plugin(QWaylandIntegrationPlugin
OUTPUT_NAME qwayland
PLUGIN_TYPE platforms
DEFAULT_IF "wayland" IN_LIST QT_QPA_PLATFORMS
SOURCES
main.cpp
LIBRARIES
Qt::Core
Qt::Gui
Qt::WaylandClientPrivate
QT_LICENSE_ID QT_COMMERCIAL_OR_LGPL3
)
#### Keys ignored in scope 1:.:.:qwayland-generic.pro:<TRUE>:
# OTHER_FILES = "qwayland-generic.json"

View File

@ -0,0 +1,45 @@
// 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 <qpa/qplatformintegrationplugin.h>
#include <QtWaylandClient/private/qwaylandintegration_p.h>
#include <QtWaylandClient/private/qtwaylandclientglobal_p.h>
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
class QWaylandIntegrationPlugin : public QPlatformIntegrationPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QPlatformIntegrationFactoryInterface_iid FILE "qwayland-generic.json")
public:
QPlatformIntegration *create(const QString&, const QStringList&) override;
};
QPlatformIntegration *QWaylandIntegrationPlugin::create(const QString& system, const QStringList& paramList)
{
Q_UNUSED(paramList)
#if !QT_CONFIG(wayland_egl)
if (system == "wayland-egl")
return nullptr;
#endif
#if !QT_CONFIG(wayland_brcm)
if (system == "wayland-brcm")
return nullptr;
#endif
auto *integration = new QWaylandIntegration(system);
if (!integration->init()) {
delete integration;
integration = nullptr;
}
return integration;
}
} // namespace QtWaylandClient
QT_END_NAMESPACE
#include "main.moc"

View File

@ -0,0 +1,7 @@
{
"Keys": [
"wayland",
"wayland-egl",
"wayland-brcm"
]
}

View File

@ -74,15 +74,17 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
namespace QtWaylandClient {
QWaylandIntegration *QWaylandIntegration::sInstance = nullptr;
QWaylandIntegration::QWaylandIntegration()
QWaylandIntegration::QWaylandIntegration(const QString &platformName)
#if defined(Q_OS_MACOS)
: mFontDb(new QCoreTextFontDatabaseEngineFactory<QCoreTextFontEngine>)
#else
: mFontDb(new QGenericUnixFontDatabase())
: mPlatformName(platformName), mFontDb(new QGenericUnixFontDatabase())
#endif
{
mDisplay.reset(new QWaylandDisplay(this));
@ -92,6 +94,8 @@ QWaylandIntegration::QWaylandIntegration()
!qEnvironmentVariableIsSet("QT_WAYLAND_DISABLE_FIXED_POSITIONS");
sInstance = this;
if (platformName != "wayland"_L1)
initializeClientBufferIntegration();
}
QWaylandIntegration::~QWaylandIntegration()
@ -335,6 +339,10 @@ void QWaylandIntegration::initializeClientBufferIntegration()
return;
QString targetKey = QString::fromLocal8Bit(qgetenv("QT_WAYLAND_CLIENT_BUFFER_INTEGRATION"));
if (mPlatformName == "wayland-egl"_L1)
targetKey = "wayland-egl"_L1;
else if (mPlatformName == "wayland-brcm"_L1)
targetKey = "brcm"_L1;
if (targetKey.isEmpty()) {
if (mDisplay->hardwareIntegration()

View File

@ -39,7 +39,7 @@ class QWaylandPlatformServices;
class Q_WAYLANDCLIENT_EXPORT QWaylandIntegration : public QPlatformIntegration
{
public:
QWaylandIntegration();
QWaylandIntegration(const QString &platformName);
~QWaylandIntegration() override;
static QWaylandIntegration *instance() { return sInstance; }
@ -127,6 +127,7 @@ private:
void initializeInputDeviceIntegration();
QWaylandShellIntegration *createShellIntegration(const QString& interfaceName);
const QString mPlatformName;
QScopedPointer<QPlatformFontDatabase> mFontDb;
#if QT_CONFIG(clipboard)
QScopedPointer<QPlatformClipboard> mClipboard;