diff --git a/abstract_backend.cpp b/abstract_backend.cpp
index 8f0172caac..59fa327b79 100644
--- a/abstract_backend.cpp
+++ b/abstract_backend.cpp
@@ -33,12 +33,10 @@ namespace KWin
AbstractBackend::AbstractBackend(QObject *parent)
: QObject(parent)
{
- WaylandServer::self()->installBackend(this);
}
AbstractBackend::~AbstractBackend()
{
- WaylandServer::self()->uninstallBackend(this);
}
QImage AbstractBackend::softwareCursor() const
diff --git a/autotests/wayland/kwin_wayland_test.cpp b/autotests/wayland/kwin_wayland_test.cpp
index 76b1b9a866..6cacc6a082 100644
--- a/autotests/wayland/kwin_wayland_test.cpp
+++ b/autotests/wayland/kwin_wayland_test.cpp
@@ -24,6 +24,8 @@ along with this program. If not, see .
#include "../../workspace.h"
#include "../../xcbutils.h"
+#include
+
#include
#include
#include
@@ -47,9 +49,8 @@ WaylandTestApplication::WaylandTestApplication(int &argc, char **argv)
setUseKActivities(false);
#endif
qputenv("KWIN_COMPOSE", QByteArrayLiteral("Q"));
- WaylandServer *server = WaylandServer::create(this);
- QPluginLoader loader(QStringLiteral(KWINBACKENDPATH));
- loader.instance()->setParent(server);
+ initPlatform(KPluginMetaData(QStringLiteral(KWINBACKENDPATH)));
+ WaylandServer::create(this);
}
WaylandTestApplication::~WaylandTestApplication()
diff --git a/main.cpp b/main.cpp
index 25f5fae984..5de2e78668 100644
--- a/main.cpp
+++ b/main.cpp
@@ -22,6 +22,7 @@ along with this program. If not, see .
#include "main.h"
#include
// kwin
+#include "abstract_backend.h"
#include "atoms.h"
#include "composite.h"
#include "cursor.h"
@@ -39,6 +40,7 @@ along with this program. If not, see .
#include
#include
#include
+#include
#include
// Qt
#include
@@ -528,5 +530,27 @@ QProcessEnvironment Application::processStartupEnvironment() const
return QProcessEnvironment::systemEnvironment();
}
+void Application::initPlatform(const KPluginMetaData &plugin)
+{
+ Q_ASSERT(!m_platform);
+ m_platform = qobject_cast(plugin.instantiate());
+ if (m_platform) {
+ m_platform->setParent(this);
+#if HAVE_INPUT
+ // check whether it needs libinput
+ const QJsonObject &metaData = plugin.rawData();
+ auto it = metaData.find(QStringLiteral("input"));
+ if (it != metaData.end()) {
+ if ((*it).isBool()) {
+ if (!(*it).toBool()) {
+ qCDebug(KWIN_CORE) << "Platform does not support input, enforcing libinput support";
+ setUseLibinput(true);
+ }
+ }
+ }
+#endif
+ }
+}
+
} // namespace
diff --git a/main.h b/main.h
index 1ea9c1c1d8..e7b928ac1e 100644
--- a/main.h
+++ b/main.h
@@ -33,11 +33,14 @@ along with this program. If not, see .
#include
#include
+class KPluginMetaData;
class QCommandLineParser;
namespace KWin
{
+class AbstractBackend;
+
class XcbEventFilter : public QAbstractNativeEventFilter
{
public:
@@ -161,6 +164,11 @@ public:
virtual QProcessEnvironment processStartupEnvironment() const;
+ void initPlatform(const KPluginMetaData &plugin);
+ AbstractBackend *platform() const {
+ return m_platform;
+ }
+
static void setupMalloc();
static void setupLocalizedString();
@@ -225,6 +233,7 @@ private:
#ifdef KWIN_BUILD_ACTIVITIES
bool m_useKActivities = true;
#endif
+ AbstractBackend *m_platform = nullptr;
static int crashes;
};
diff --git a/main_wayland.cpp b/main_wayland.cpp
index c9ee426150..73396df1f3 100644
--- a/main_wayland.cpp
+++ b/main_wayland.cpp
@@ -693,26 +693,11 @@ int main(int argc, char * argv[])
}
server->init(parser.value(waylandSocketOption).toUtf8(), flags);
- if (qobject_cast((*pluginIt).instantiate())) {
-#if HAVE_INPUT
- // check whether it needs libinput
- const QJsonObject &metaData = (*pluginIt).rawData();
- auto it = metaData.find(QStringLiteral("input"));
- if (it != metaData.end()) {
- if ((*it).isBool()) {
- if (!(*it).toBool()) {
- std::cerr << "Backend does not support input, enforcing libinput support" << std::endl;
- KWin::Application::setUseLibinput(true);
- }
- }
- }
-#endif
- }
- if (!server->backend()) {
+ a.initPlatform(*pluginIt);
+ if (!a.platform()) {
std::cerr << "FATAL ERROR: could not instantiate a backend" << std::endl;
return 1;
}
- server->backend()->setParent(server);
if (!deviceIdentifier.isEmpty()) {
server->backend()->setDeviceIdentifier(deviceIdentifier);
}
diff --git a/wayland_server.cpp b/wayland_server.cpp
index cb7a15c943..fbf54a9d09 100644
--- a/wayland_server.cpp
+++ b/wayland_server.cpp
@@ -238,7 +238,7 @@ void WaylandServer::init(const QByteArray &socketName, InitalizationFlags flags)
m_outputManagement = m_display->createOutputManagement(m_display);
connect(m_outputManagement, &OutputManagementInterface::configurationChangeRequested,
this, [this](KWayland::Server::OutputConfigurationInterface *config) {
- m_backend->configurationChangeRequested(config);
+ kwinApp()->platform()->configurationChangeRequested(config);
});
m_display->createSubCompositor(m_display)->create();
@@ -282,7 +282,7 @@ void WaylandServer::initWorkspace()
void WaylandServer::initOutputs()
{
- if (m_backend && m_backend->handlesOutputs()) {
+ if (kwinApp()->platform()->handlesOutputs()) {
return;
}
Screens *s = screens();
@@ -377,18 +377,6 @@ void WaylandServer::createInternalConnection()
m_internalConnection.client->initConnection();
}
-void WaylandServer::installBackend(AbstractBackend *backend)
-{
- Q_ASSERT(!m_backend);
- m_backend = backend;
-}
-
-void WaylandServer::uninstallBackend(AbstractBackend *backend)
-{
- Q_ASSERT(m_backend == backend);
- m_backend = nullptr;
-}
-
void WaylandServer::removeClient(ShellClient *c)
{
m_clients.removeAll(c);
@@ -525,4 +513,9 @@ bool WaylandServer::isScreenLocked() const
ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::AcquiringLock;
}
+AbstractBackend *WaylandServer::backend() const
+{
+ return kwinApp()->platform();
+}
+
}
diff --git a/wayland_server.h b/wayland_server.h
index 26b2eec2b6..531b72e821 100644
--- a/wayland_server.h
+++ b/wayland_server.h
@@ -106,11 +106,7 @@ public:
ShellClient *findClient(KWayland::Server::SurfaceInterface *surface) const;
ShellClient *findClient(QWindow *w) const;
- AbstractBackend *backend() const {
- return m_backend;
- }
- void installBackend(AbstractBackend *backend);
- void uninstallBackend(AbstractBackend *backend);
+ AbstractBackend *backend() const;
/**
* @returns file descriptor for Xwayland to connect to.
@@ -188,7 +184,6 @@ private:
KWayland::Client::ShmPool *shm = nullptr;
} m_internalConnection;
- AbstractBackend *m_backend = nullptr;
QList m_clients;
QList m_internalClients;
QHash m_clientIds;