File indexing completed on 2026-09-06 12:36:39

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 "fakeinputbackend.h"
0008 #include "fakeinputdevice.h"
0009 #include "wayland/fakeinput_interface.h"
0010 #include "wayland_server.h"
0011 
0012 namespace KWin
0013 {
0014 
0015 FakeInputBackend::FakeInputBackend() = default;
0016 FakeInputBackend::~FakeInputBackend() = default;
0017 
0018 void FakeInputBackend::initialize()
0019 {
0020     m_interface = std::make_unique<KWaylandServer::FakeInputInterface>(waylandServer()->display());
0021     connect(m_interface.get(), &KWaylandServer::FakeInputInterface::deviceCreated, this, [this](KWaylandServer::FakeInputDevice *fakeDevice) {
0022         m_devices[fakeDevice] = std::make_unique<FakeInputDevice>(fakeDevice);
0023         Q_EMIT deviceAdded(m_devices[fakeDevice].get());
0024     });
0025     connect(m_interface.get(), &KWaylandServer::FakeInputInterface::deviceDestroyed, this, [this](KWaylandServer::FakeInputDevice *fakeDevice) {
0026         auto it = m_devices.find(fakeDevice);
0027         if (it != m_devices.end()) {
0028             const std::unique_ptr<FakeInputDevice> device = std::move(it->second);
0029             m_devices.erase(it);
0030             Q_EMIT deviceRemoved(device.get());
0031         }
0032     });
0033 }
0034 
0035 } // namespace KWin