backends/libinput: Destroy Connection in correct thread

This commit is contained in:
Vlad Zahorodnii 2024-06-03 18:15:34 +03:00
parent 7622921de6
commit eea79bddd8
4 changed files with 11 additions and 9 deletions

View file

@ -80,7 +80,7 @@ Q_SIGNALS:
void deviceRemoved(QString sysName);
};
std::unique_ptr<Connection> Connection::create(Session *session)
Connection *Connection::create(Session *session)
{
std::unique_ptr<Udev> udev = std::make_unique<Udev>();
if (!udev->isValid()) {
@ -96,7 +96,7 @@ std::unique_ptr<Connection> Connection::create(Session *session)
qCWarning(KWIN_LIBINPUT) << "Failed to initialize context";
return nullptr;
}
return std::unique_ptr<Connection>(new Connection(std::move(context)));
return new Connection(std::move(context));
}
Connection::Connection(std::unique_ptr<Context> &&input)

View file

@ -56,7 +56,7 @@ public:
QStringList devicesSysNames() const;
static std::unique_ptr<Connection> create(Session *session);
static Connection *create(Session *session);
Q_SIGNALS:
void deviceAdded(KWin::LibInput::Device *);

View file

@ -21,21 +21,23 @@ LibinputBackend::LibinputBackend(Session *session, QObject *parent)
m_connection->moveToThread(&m_thread);
connect(
m_connection.get(), &LibInput::Connection::eventsRead, this, [this]() {
m_connection->processEvents();
},
m_connection, &LibInput::Connection::eventsRead, this, [this]() {
m_connection->processEvents();
},
Qt::QueuedConnection);
// Direct connection because the deviceAdded() and the deviceRemoved() signals are emitted
// from the main thread.
connect(m_connection.get(), &LibInput::Connection::deviceAdded,
connect(m_connection, &LibInput::Connection::deviceAdded,
this, &InputBackend::deviceAdded, Qt::DirectConnection);
connect(m_connection.get(), &LibInput::Connection::deviceRemoved,
connect(m_connection, &LibInput::Connection::deviceRemoved,
this, &InputBackend::deviceRemoved, Qt::DirectConnection);
}
LibinputBackend::~LibinputBackend()
{
m_connection->deleteLater();
m_thread.quit();
m_thread.wait();
}

View file

@ -33,7 +33,7 @@ public:
private:
QThread m_thread;
std::unique_ptr<LibInput::Connection> m_connection;
LibInput::Connection *m_connection = nullptr;
};
} // namespace KWin