File indexing completed on 2024-11-10 04:56:32

0001 /*
0002     SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "libinputbackend.h"
0008 #include "connection.h"
0009 #include "device.h"
0010 
0011 namespace KWin
0012 {
0013 
0014 LibinputBackend::LibinputBackend(Session *session, QObject *parent)
0015     : InputBackend(parent)
0016 {
0017     m_thread.setObjectName(QStringLiteral("libinput-connection"));
0018     m_thread.start();
0019 
0020     m_connection = LibInput::Connection::create(session);
0021     m_connection->moveToThread(&m_thread);
0022 
0023     connect(
0024         m_connection.get(), &LibInput::Connection::eventsRead, this, [this]() {
0025             m_connection->processEvents();
0026         },
0027         Qt::QueuedConnection);
0028 
0029     // Direct connection because the deviceAdded() and the deviceRemoved() signals are emitted
0030     // from the main thread.
0031     connect(m_connection.get(), &LibInput::Connection::deviceAdded,
0032             this, &InputBackend::deviceAdded, Qt::DirectConnection);
0033     connect(m_connection.get(), &LibInput::Connection::deviceRemoved,
0034             this, &InputBackend::deviceRemoved, Qt::DirectConnection);
0035 }
0036 
0037 LibinputBackend::~LibinputBackend()
0038 {
0039     m_thread.quit();
0040     m_thread.wait();
0041 }
0042 
0043 void LibinputBackend::initialize()
0044 {
0045     m_connection->setInputConfig(config());
0046     m_connection->setup();
0047 }
0048 
0049 void LibinputBackend::updateScreens()
0050 {
0051     m_connection->updateScreens();
0052 }
0053 
0054 } // namespace KWin
0055 
0056 #include "moc_libinputbackend.cpp"