File indexing completed on 2024-04-21 04:56:50

0001 /**
0002  * SPDX-FileCopyrightText: 2018 Albert Vaca Cintora <albertvaka@gmail.com>
0003  * SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
0004  * SPDX-FileCopyrightText: 2014 Ahmed I. Khalil <ahmedibrahimkhali@gmail.com>
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007  */
0008 
0009 #include "mousepadplugin.h"
0010 #include <KLocalizedString>
0011 #include <KPluginFactory>
0012 #include <QGuiApplication>
0013 
0014 #if defined(Q_OS_WIN)
0015 #include "windowsremoteinput.h"
0016 #elif defined(Q_OS_MACOS)
0017 #include "macosremoteinput.h"
0018 #else
0019 #include "waylandremoteinput.h"
0020 #if WITH_X11
0021 #include "x11remoteinput.h"
0022 #endif
0023 #endif
0024 
0025 K_PLUGIN_CLASS_WITH_JSON(MousepadPlugin, "kdeconnect_mousepad.json")
0026 
0027 MousepadPlugin::MousepadPlugin(QObject *parent, const QVariantList &args)
0028     : KdeConnectPlugin(parent, args)
0029     , m_impl(nullptr)
0030 {
0031 #if defined(Q_OS_WIN)
0032     m_impl = new WindowsRemoteInput(this);
0033 #elif defined(Q_OS_MACOS)
0034     m_impl = new MacOSRemoteInput(this);
0035 #else
0036     if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
0037         m_impl = new WaylandRemoteInput(this);
0038     }
0039 #if WITH_X11
0040     if (QGuiApplication::platformName() == QLatin1String("xcb")) {
0041         m_impl = new X11RemoteInput(this);
0042     }
0043 #endif
0044 #endif
0045 
0046     if (!m_impl) {
0047         qDebug() << "KDE Connect was built without" << QGuiApplication::platformName() << "support";
0048     }
0049 }
0050 
0051 MousepadPlugin::~MousepadPlugin()
0052 {
0053     delete m_impl;
0054 }
0055 
0056 void MousepadPlugin::receivePacket(const NetworkPacket &np)
0057 {
0058     if (m_impl) {
0059         m_impl->handlePacket(np);
0060     }
0061 }
0062 
0063 void MousepadPlugin::connected()
0064 {
0065     NetworkPacket np(PACKET_TYPE_MOUSEPAD_KEYBOARDSTATE);
0066     if (m_impl) {
0067         np.set<bool>(QStringLiteral("state"), m_impl->hasKeyboardSupport());
0068     }
0069     sendPacket(np);
0070 }
0071 
0072 #include "moc_mousepadplugin.cpp"
0073 #include "mousepadplugin.moc"