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()
|
||||
{
|
||||
return std::make_unique<LibinputBackend>();
|
||||
return std::make_unique<LibinputBackend>(session());
|
||||
}
|
||||
|
||||
std::unique_ptr<QPainterBackend> DrmBackend::createQPainterBackend()
|
||||
|
|
|
@ -80,21 +80,20 @@ Q_SIGNALS:
|
|||
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>();
|
||||
if (!udev->isValid()) {
|
||||
qCWarning(KWIN_LIBINPUT) << "Failed to initialize udev";
|
||||
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()) {
|
||||
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<Connection>(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;
|
||||
|
|
|
@ -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<Connection> create();
|
||||
static std::unique_ptr<Connection> create(Session *session);
|
||||
|
||||
Q_SIGNALS:
|
||||
void deviceAdded(KWin::LibInput::Device *);
|
||||
|
|
|
@ -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> &&udev)
|
||||
: m_libinput(libinput_udev_create_context(&Context::s_interface, this, *udev.get()))
|
||||
Context::Context(Session *session, std::unique_ptr<Udev> &&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<Event> Context::event()
|
||||
|
|
|
@ -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> &&udev);
|
||||
Context(Session *session, std::unique_ptr<Udev> &&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<Udev> m_udev;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue