backends/libinput: Take Session explicitly
The API will be more clear about what the libinput backend needs.
This commit is contained in:
parent
4f7b2054e1
commit
5e669aece9
7 changed files with 31 additions and 21 deletions
|
@ -549,7 +549,7 @@ void DrmBackend::enableOutput(DrmAbstractOutput *output, bool enable)
|
||||||
|
|
||||||
std::unique_ptr<InputBackend> DrmBackend::createInputBackend()
|
std::unique_ptr<InputBackend> DrmBackend::createInputBackend()
|
||||||
{
|
{
|
||||||
return std::make_unique<LibinputBackend>();
|
return std::make_unique<LibinputBackend>(session());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<QPainterBackend> DrmBackend::createQPainterBackend()
|
std::unique_ptr<QPainterBackend> DrmBackend::createQPainterBackend()
|
||||||
|
|
|
@ -80,21 +80,20 @@ Q_SIGNALS:
|
||||||
void deviceRemoved(QString sysName);
|
void deviceRemoved(QString sysName);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<Connection> Connection::create()
|
std::unique_ptr<Connection> Connection::create(Session *session)
|
||||||
{
|
{
|
||||||
std::unique_ptr<Udev> udev = std::make_unique<Udev>();
|
std::unique_ptr<Udev> udev = std::make_unique<Udev>();
|
||||||
if (!udev->isValid()) {
|
if (!udev->isValid()) {
|
||||||
qCWarning(KWIN_LIBINPUT) << "Failed to initialize udev";
|
qCWarning(KWIN_LIBINPUT) << "Failed to initialize udev";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
std::unique_ptr<Context> context = std::make_unique<Context>(std::move(udev));
|
std::unique_ptr<Context> context = std::make_unique<Context>(session, std::move(udev));
|
||||||
if (!context->isValid()) {
|
if (!context->isValid()) {
|
||||||
qCWarning(KWIN_LIBINPUT) << "Failed to create context from udev";
|
qCWarning(KWIN_LIBINPUT) << "Failed to create context from udev";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
const QString seat = kwinApp()->platform()->session()->seat();
|
if (!context->initialize()) {
|
||||||
if (!context->assignSeat(seat.toUtf8().constData())) {
|
qCWarning(KWIN_LIBINPUT) << "Failed to initialize context";
|
||||||
qCWarning(KWIN_LIBINPUT) << "Failed to assign seat" << seat;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return std::unique_ptr<Connection>(new Connection(std::move(context)));
|
return std::unique_ptr<Connection>(new Connection(std::move(context)));
|
||||||
|
@ -127,7 +126,7 @@ void Connection::doSetup()
|
||||||
m_notifier = new QSocketNotifier(m_input->fileDescriptor(), QSocketNotifier::Read, this);
|
m_notifier = new QSocketNotifier(m_input->fileDescriptor(), QSocketNotifier::Read, this);
|
||||||
connect(m_notifier, &QSocketNotifier::activated, this, &Connection::handleEvent);
|
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 (active) {
|
||||||
if (!m_input->isSuspended()) {
|
if (!m_input->isSuspended()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -27,6 +27,7 @@ class QThread;
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class Session;
|
||||||
class Udev;
|
class Udev;
|
||||||
|
|
||||||
namespace LibInput
|
namespace LibInput
|
||||||
|
@ -56,7 +57,7 @@ public:
|
||||||
|
|
||||||
QStringList devicesSysNames() const;
|
QStringList devicesSysNames() const;
|
||||||
|
|
||||||
static std::unique_ptr<Connection> create();
|
static std::unique_ptr<Connection> create(Session *session);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void deviceAdded(KWin::LibInput::Device *);
|
void deviceAdded(KWin::LibInput::Device *);
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "libinput_logging.h"
|
#include "libinput_logging.h"
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "platform.h"
|
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "utils/udev.h"
|
#include "utils/udev.h"
|
||||||
|
|
||||||
|
@ -46,8 +44,9 @@ static void libinputLogHandler(libinput *libinput, libinput_log_priority priorit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context::Context(std::unique_ptr<Udev> &&udev)
|
Context::Context(Session *session, std::unique_ptr<Udev> &&udev)
|
||||||
: m_libinput(libinput_udev_create_context(&Context::s_interface, this, *udev.get()))
|
: m_session(session)
|
||||||
|
, m_libinput(libinput_udev_create_context(&Context::s_interface, this, *udev.get()))
|
||||||
, m_suspended(false)
|
, m_suspended(false)
|
||||||
, m_udev(std::move(udev))
|
, m_udev(std::move(udev))
|
||||||
{
|
{
|
||||||
|
@ -62,12 +61,17 @@ Context::~Context()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Context::assignSeat(const char *seat)
|
bool Context::initialize()
|
||||||
{
|
{
|
||||||
if (!isValid()) {
|
if (!isValid()) {
|
||||||
return false;
|
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()
|
int Context::fileDescriptor()
|
||||||
|
@ -100,7 +104,7 @@ void Context::closeRestrictedCallBack(int fd, void *user_data)
|
||||||
|
|
||||||
int Context::openRestricted(const char *path, int flags)
|
int Context::openRestricted(const char *path, int flags)
|
||||||
{
|
{
|
||||||
int fd = kwinApp()->platform()->session()->openRestricted(path);
|
int fd = m_session->openRestricted(path);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
// failed
|
// failed
|
||||||
return fd;
|
return fd;
|
||||||
|
@ -144,7 +148,7 @@ int Context::openRestricted(const char *path, int flags)
|
||||||
|
|
||||||
void Context::closeRestricted(int fd)
|
void Context::closeRestricted(int fd)
|
||||||
{
|
{
|
||||||
kwinApp()->platform()->session()->closeRestricted(fd);
|
m_session->closeRestricted(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Event> Context::event()
|
std::unique_ptr<Event> Context::event()
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class Session;
|
||||||
class Udev;
|
class Udev;
|
||||||
|
|
||||||
namespace LibInput
|
namespace LibInput
|
||||||
|
@ -25,9 +26,9 @@ class Event;
|
||||||
class Context
|
class Context
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Context(std::unique_ptr<Udev> &&udev);
|
Context(Session *session, std::unique_ptr<Udev> &&udev);
|
||||||
~Context();
|
~Context();
|
||||||
bool assignSeat(const char *seat);
|
bool initialize();
|
||||||
bool isValid() const
|
bool isValid() const
|
||||||
{
|
{
|
||||||
return m_libinput != nullptr;
|
return m_libinput != nullptr;
|
||||||
|
@ -37,6 +38,7 @@ public:
|
||||||
return m_suspended;
|
return m_suspended;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Session *session() const;
|
||||||
int fileDescriptor();
|
int fileDescriptor();
|
||||||
void dispatch();
|
void dispatch();
|
||||||
void suspend();
|
void suspend();
|
||||||
|
@ -63,6 +65,8 @@ public:
|
||||||
private:
|
private:
|
||||||
int openRestricted(const char *path, int flags);
|
int openRestricted(const char *path, int flags);
|
||||||
void closeRestricted(int fd);
|
void closeRestricted(int fd);
|
||||||
|
|
||||||
|
Session *m_session;
|
||||||
struct libinput *m_libinput;
|
struct libinput *m_libinput;
|
||||||
bool m_suspended;
|
bool m_suspended;
|
||||||
std::unique_ptr<Udev> m_udev;
|
std::unique_ptr<Udev> m_udev;
|
||||||
|
|
|
@ -11,13 +11,13 @@
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
LibinputBackend::LibinputBackend(QObject *parent)
|
LibinputBackend::LibinputBackend(Session *session, QObject *parent)
|
||||||
: InputBackend(parent)
|
: InputBackend(parent)
|
||||||
{
|
{
|
||||||
m_thread.setObjectName(QStringLiteral("libinput-connection"));
|
m_thread.setObjectName(QStringLiteral("libinput-connection"));
|
||||||
m_thread.start();
|
m_thread.start();
|
||||||
|
|
||||||
m_connection = LibInput::Connection::create();
|
m_connection = LibInput::Connection::create(session);
|
||||||
m_connection->moveToThread(&m_thread);
|
m_connection->moveToThread(&m_thread);
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class Session;
|
||||||
|
|
||||||
namespace LibInput
|
namespace LibInput
|
||||||
{
|
{
|
||||||
class Connection;
|
class Connection;
|
||||||
|
@ -23,7 +25,7 @@ class KWIN_EXPORT LibinputBackend : public InputBackend
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LibinputBackend(QObject *parent = nullptr);
|
explicit LibinputBackend(Session *session, QObject *parent = nullptr);
|
||||||
~LibinputBackend() override;
|
~LibinputBackend() override;
|
||||||
|
|
||||||
void initialize() override;
|
void initialize() override;
|
||||||
|
|
Loading…
Reference in a new issue