Commit 7996d954 authored by Martin Flöser's avatar Martin Flöser

Provide the platform() -> AbstractBackend* in KWin::Application

Summary:
This is the first change in a refactoring series. The aim is to:
* rename AbstractBackend to Platform
* move backends/ to plugins/platforms/
* don't bind platforms to Wayland only
* provide a platform plugin for "normal" X11
* share more code between X11 and Wayland

This change moves the platform/backend from waylandServer to Application.
The init of the plugin happens directly in the Application from the
KPluginMetaData. There is no need to externally init it and set the
parent.

WaylandServer::backend() currently just delegates to
kwinApp()->platform(), the idea is to drop this method completely.

The test infrastructure is also adjusted to this change.

Test Plan: kwin_wayland still works, all tests pass

Reviewers: #plasma, sebas

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1331
parent 8d851a02
......@@ -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
......
......@@ -24,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../../workspace.h"
#include "../../xcbutils.h"
#include <KPluginMetaData>
#include <QAbstractEventDispatcher>
#include <QPluginLoader>
#include <QSocketNotifier>
......@@ -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()
......
......@@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "main.h"
#include <config-kwin.h>
// 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 <http://www.gnu.org/licenses/>.
#include <KConfigGroup>
#include <KCrash>
#include <KLocalizedString>
#include <KPluginMetaData>
#include <KSharedConfig>
// Qt
#include <qplatformdefs.h>
......@@ -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<AbstractBackend*>(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
......@@ -33,11 +33,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QAbstractNativeEventFilter>
#include <QProcessEnvironment>
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;
};
......
......@@ -693,26 +693,11 @@ int main(int argc, char * argv[])
}
server->init(parser.value(waylandSocketOption).toUtf8(), flags);
if (qobject_cast<KWin::AbstractBackend*>((*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);
}
......
......@@ -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();
}
}
......@@ -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<ShellClient*> m_clients;
QList<ShellClient*> m_internalClients;
QHash<KWayland::Server::ClientConnection*, quint16> m_clientIds;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment