diff --git a/src/backends/drm/drm_backend.cpp b/src/backends/drm/drm_backend.cpp index 42078167aa..d8f8cc02e1 100644 --- a/src/backends/drm/drm_backend.cpp +++ b/src/backends/drm/drm_backend.cpp @@ -549,7 +549,7 @@ void DrmBackend::enableOutput(DrmAbstractOutput *output, bool enable) std::unique_ptr DrmBackend::createInputBackend() { - return std::make_unique(); + return std::make_unique(session()); } std::unique_ptr DrmBackend::createQPainterBackend() diff --git a/src/backends/libinput/connection.cpp b/src/backends/libinput/connection.cpp index ab1f40502b..8217996172 100644 --- a/src/backends/libinput/connection.cpp +++ b/src/backends/libinput/connection.cpp @@ -80,21 +80,20 @@ Q_SIGNALS: void deviceRemoved(QString sysName); }; -std::unique_ptr Connection::create() +std::unique_ptr Connection::create(Session *session) { std::unique_ptr udev = std::make_unique(); if (!udev->isValid()) { qCWarning(KWIN_LIBINPUT) << "Failed to initialize udev"; return nullptr; } - std::unique_ptr context = std::make_unique(std::move(udev)); + std::unique_ptr context = std::make_unique(session, std::move(udev)); if (!context->isValid()) { qCWarning(KWIN_LIBINPUT) << "Failed to create context from udev"; return nullptr; } - const QString seat = kwinApp()->platform()->session()->seat(); - if (!context->assignSeat(seat.toUtf8().constData())) { - qCWarning(KWIN_LIBINPUT) << "Failed to assign seat" << seat; + if (!context->initialize()) { + qCWarning(KWIN_LIBINPUT) << "Failed to initialize context"; return nullptr; } return std::unique_ptr(new Connection(std::move(context))); @@ -127,7 +126,7 @@ void Connection::doSetup() m_notifier = new QSocketNotifier(m_input->fileDescriptor(), QSocketNotifier::Read, this); connect(m_notifier, &QSocketNotifier::activated, this, &Connection::handleEvent); - connect(kwinApp()->platform()->session(), &Session::activeChanged, this, [this](bool active) { + connect(m_input->session(), &Session::activeChanged, this, [this](bool active) { if (active) { if (!m_input->isSuspended()) { return; diff --git a/src/backends/libinput/connection.h b/src/backends/libinput/connection.h index f50033b643..660e2d3ba3 100644 --- a/src/backends/libinput/connection.h +++ b/src/backends/libinput/connection.h @@ -27,6 +27,7 @@ class QThread; namespace KWin { +class Session; class Udev; namespace LibInput @@ -56,7 +57,7 @@ public: QStringList devicesSysNames() const; - static std::unique_ptr create(); + static std::unique_ptr create(Session *session); Q_SIGNALS: void deviceAdded(KWin::LibInput::Device *); diff --git a/src/backends/libinput/context.cpp b/src/backends/libinput/context.cpp index 4b6a20d03b..dd0659ba84 100644 --- a/src/backends/libinput/context.cpp +++ b/src/backends/libinput/context.cpp @@ -10,8 +10,6 @@ #include "events.h" #include "libinput_logging.h" -#include "main.h" -#include "platform.h" #include "session.h" #include "utils/udev.h" @@ -46,8 +44,9 @@ static void libinputLogHandler(libinput *libinput, libinput_log_priority priorit } } -Context::Context(std::unique_ptr &&udev) - : m_libinput(libinput_udev_create_context(&Context::s_interface, this, *udev.get())) +Context::Context(Session *session, std::unique_ptr &&udev) + : m_session(session) + , m_libinput(libinput_udev_create_context(&Context::s_interface, this, *udev.get())) , m_suspended(false) , m_udev(std::move(udev)) { @@ -62,12 +61,17 @@ Context::~Context() } } -bool Context::assignSeat(const char *seat) +bool Context::initialize() { if (!isValid()) { return false; } - return libinput_udev_assign_seat(m_libinput, seat) == 0; + return libinput_udev_assign_seat(m_libinput, m_session->seat().toUtf8().constData()) == 0; +} + +Session *Context::session() const +{ + return m_session; } int Context::fileDescriptor() @@ -100,7 +104,7 @@ void Context::closeRestrictedCallBack(int fd, void *user_data) int Context::openRestricted(const char *path, int flags) { - int fd = kwinApp()->platform()->session()->openRestricted(path); + int fd = m_session->openRestricted(path); if (fd < 0) { // failed return fd; @@ -144,7 +148,7 @@ int Context::openRestricted(const char *path, int flags) void Context::closeRestricted(int fd) { - kwinApp()->platform()->session()->closeRestricted(fd); + m_session->closeRestricted(fd); } std::unique_ptr Context::event() diff --git a/src/backends/libinput/context.h b/src/backends/libinput/context.h index 74da9eda9b..65080160c2 100644 --- a/src/backends/libinput/context.h +++ b/src/backends/libinput/context.h @@ -15,6 +15,7 @@ namespace KWin { +class Session; class Udev; namespace LibInput @@ -25,9 +26,9 @@ class Event; class Context { public: - Context(std::unique_ptr &&udev); + Context(Session *session, std::unique_ptr &&udev); ~Context(); - bool assignSeat(const char *seat); + bool initialize(); bool isValid() const { return m_libinput != nullptr; @@ -37,6 +38,7 @@ public: return m_suspended; } + Session *session() const; int fileDescriptor(); void dispatch(); void suspend(); @@ -63,6 +65,8 @@ public: private: int openRestricted(const char *path, int flags); void closeRestricted(int fd); + + Session *m_session; struct libinput *m_libinput; bool m_suspended; std::unique_ptr m_udev; diff --git a/src/backends/libinput/libinputbackend.cpp b/src/backends/libinput/libinputbackend.cpp index b7e6f37d5a..541b91b520 100644 --- a/src/backends/libinput/libinputbackend.cpp +++ b/src/backends/libinput/libinputbackend.cpp @@ -11,13 +11,13 @@ namespace KWin { -LibinputBackend::LibinputBackend(QObject *parent) +LibinputBackend::LibinputBackend(Session *session, QObject *parent) : InputBackend(parent) { m_thread.setObjectName(QStringLiteral("libinput-connection")); m_thread.start(); - m_connection = LibInput::Connection::create(); + m_connection = LibInput::Connection::create(session); m_connection->moveToThread(&m_thread); connect( diff --git a/src/backends/libinput/libinputbackend.h b/src/backends/libinput/libinputbackend.h index 628d048640..0d11041ecf 100644 --- a/src/backends/libinput/libinputbackend.h +++ b/src/backends/libinput/libinputbackend.h @@ -13,6 +13,8 @@ namespace KWin { +class Session; + namespace LibInput { class Connection; @@ -23,7 +25,7 @@ class KWIN_EXPORT LibinputBackend : public InputBackend Q_OBJECT public: - explicit LibinputBackend(QObject *parent = nullptr); + explicit LibinputBackend(Session *session, QObject *parent = nullptr); ~LibinputBackend() override; void initialize() override;