File indexing completed on 2024-04-21 16:11:00
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Bart Ribbers <bribbers@disroot.org> 0003 * SPDX-FileCopyrightText: 2022 Aleix Pol Gonzalez <aleixpol@kde.org> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include "kwinfakeinputsystem.h" 0009 #include "qwayland-fake-input.h" 0010 #include <QWaylandClientExtensionTemplate> 0011 #include <KLocalizedString> 0012 #include <QDebug> 0013 #include <QtGlobal> 0014 #include "plasmarc-debug.h" 0015 0016 class FakeInput : public QWaylandClientExtensionTemplate<FakeInput>, public QtWayland::org_kde_kwin_fake_input 0017 { 0018 public: 0019 FakeInput() 0020 : QWaylandClientExtensionTemplate<FakeInput>(ORG_KDE_KWIN_FAKE_INPUT_KEYBOARD_KEY_SINCE_VERSION) 0021 { 0022 #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) 0023 initialize(); 0024 #else 0025 // QWaylandClientExtensionTemplate invokes this with a QueuedConnection but we want it called immediately 0026 QMetaObject::invokeMethod(this, "addRegistryListener"); 0027 #endif 0028 } 0029 }; 0030 0031 bool KWinFakeInputSystem::init() 0032 { 0033 m_ext = new FakeInput; 0034 if (!m_ext->isInitialized()) { 0035 qCWarning(PLASMARC) << "Could not initialise the org_kde_kwin_fake_input implementation"; 0036 return false; 0037 } 0038 m_ext->setParent(this); 0039 if (!m_ext->isActive()) { 0040 return false; 0041 } 0042 m_ext->authenticate({}, {}); 0043 return true; 0044 } 0045 0046 void KWinFakeInputSystem::emitKey(int key, bool pressed) 0047 { 0048 m_ext->keyboard_key(key, pressed); 0049 }