mirror of
https://invent.kde.org/plasma/plasma-desktop.git
synced 2026-11-03 22:59:45 -09:00
kcms/touchpad: Fold TouchpadBackend into KWinWaylandBackend
This commit is contained in:
parent
44dfb7cffd
commit
2721020359
10 changed files with 64 additions and 175 deletions
|
|
@ -3,9 +3,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kcm_touchpad\")
|
|||
|
||||
add_subdirectory(icon)
|
||||
|
||||
add_library(touchpad_common STATIC
|
||||
touchpadbackend.cpp
|
||||
)
|
||||
add_library(touchpad_common STATIC)
|
||||
set_property(TARGET touchpad_common PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
ecm_qt_declare_logging_category(touchpad_common
|
||||
|
|
|
|||
|
|
@ -14,16 +14,17 @@
|
|||
#include <QDBusMessage>
|
||||
#include <QDBusReply>
|
||||
#include <QStringList>
|
||||
#include <QThreadStorage>
|
||||
|
||||
#include <KWindowSystem>
|
||||
|
||||
#include "devicesmodel.h"
|
||||
#include "logging.h"
|
||||
|
||||
KWinWaylandBackend::KWinWaylandBackend(QObject *parent)
|
||||
: TouchpadBackend(parent)
|
||||
: QObject(parent)
|
||||
, m_devicesModel(new KWinDevices::DevicesModel(KWinDevices::DevicesModel::Kind::Pointers, {{QStringLiteral("touchpad"), true}}, this))
|
||||
{
|
||||
setMode(TouchpadInputBackendMode::WaylandLibinput);
|
||||
|
||||
connect(m_devicesModel, &QAbstractItemModel::rowsInserted, this, &KWinWaylandBackend::onDeviceRowsInserted);
|
||||
connect(m_devicesModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &KWinWaylandBackend::onDeviceRowsAboutToBeRemoved);
|
||||
|
||||
|
|
@ -121,4 +122,20 @@ void KWinWaylandBackend::onDeviceRowsAboutToBeRemoved(const QModelIndex &parent,
|
|||
}
|
||||
}
|
||||
|
||||
KWinWaylandBackend *KWinWaylandBackend::implementation()
|
||||
{
|
||||
// TODO: test on kwin_wayland specifically? What about possibly other compositors under Wayland?
|
||||
if (KWindowSystem::isPlatformWayland()) {
|
||||
static QThreadStorage<std::shared_ptr<KWinWaylandBackend>> backend;
|
||||
if (!backend.hasLocalData()) {
|
||||
qCDebug(KCM_TOUCHPAD) << "Using KWin+Wayland backend";
|
||||
backend.setLocalData(std::shared_ptr<KWinWaylandBackend>(new KWinWaylandBackend()));
|
||||
}
|
||||
return backend.localData().get();
|
||||
}
|
||||
|
||||
qCCritical(KCM_TOUCHPAD) << "Not able to select appropriate backend.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#include "moc_kwinwaylandbackend.cpp"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "kwinwaylandtouchpad.h"
|
||||
#include "touchpadbackend.h"
|
||||
|
||||
#include <QList>
|
||||
|
||||
|
|
@ -16,33 +15,49 @@ namespace KWinDevices
|
|||
class DevicesModel;
|
||||
}
|
||||
|
||||
class KWinWaylandBackend : public TouchpadBackend
|
||||
class KWinWaylandBackend : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QList<KWinWaylandTouchpad *> inputDevices READ inputDevices NOTIFY inputDevicesChanged FINAL)
|
||||
|
||||
public:
|
||||
explicit KWinWaylandBackend(QObject *parent = nullptr);
|
||||
~KWinWaylandBackend();
|
||||
|
||||
bool save() override;
|
||||
bool load() override;
|
||||
bool defaults() override;
|
||||
bool isSaveNeeded() const override;
|
||||
static KWinWaylandBackend *implementation();
|
||||
|
||||
QString errorString() const override
|
||||
bool save();
|
||||
bool load();
|
||||
bool defaults();
|
||||
bool isSaveNeeded() const;
|
||||
|
||||
QString errorString() const
|
||||
{
|
||||
return m_errorString;
|
||||
}
|
||||
|
||||
int deviceCount() const override
|
||||
int deviceCount() const
|
||||
{
|
||||
return m_devices.count();
|
||||
}
|
||||
QList<KWinWaylandTouchpad *> inputDevices() const override
|
||||
QList<KWinWaylandTouchpad *> inputDevices() const
|
||||
{
|
||||
return m_devices;
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void needsSaveChanged();
|
||||
|
||||
void touchpadStateChanged();
|
||||
void touchpadReset();
|
||||
void keyboardActivityStarted();
|
||||
void keyboardActivityFinished();
|
||||
|
||||
void inputDevicesChanged();
|
||||
void deviceAdded(bool success);
|
||||
void deviceRemoved(int index);
|
||||
|
||||
private:
|
||||
void findTouchpads();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
#include <QDBusMessage>
|
||||
#include <QDBusReply>
|
||||
#include <QList>
|
||||
#include <QThreadStorage>
|
||||
|
||||
#include <KWindowSystem>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
#include "kcm.h"
|
||||
|
||||
#include "backends/kwin_wayland/kwinwaylandbackend.h"
|
||||
#include "backends/kwin_wayland/kwinwaylandtouchpad.h"
|
||||
#include "logging.h"
|
||||
#include "touchpadbackend.h"
|
||||
#include "touchpadmoduledata.h"
|
||||
|
||||
#include <KLocalizedContext>
|
||||
|
|
@ -50,9 +50,9 @@ KCMTouchpad::KCMTouchpad(QObject *parent, const KPluginMetaData &data)
|
|||
qmlRegisterUncreatableType<Message>(uri, 1, 0, "message", QString());
|
||||
qmlRegisterUncreatableMetaObject(MessageType::staticMetaObject, uri, 1, 0, "MessageType", QString());
|
||||
qmlRegisterUncreatableType<KCMTouchpad>(uri, 1, 0, "KCMTouchpad", QString());
|
||||
qmlRegisterUncreatableType<TouchpadBackend>(uri, 1, 0, "TouchpadBackend", QString());
|
||||
qmlRegisterUncreatableType<KWinWaylandBackend>(uri, 1, 0, "TouchpadBackend", QString());
|
||||
|
||||
m_backend = TouchpadBackend::implementation();
|
||||
m_backend = KWinWaylandBackend::implementation();
|
||||
if (!m_backend) {
|
||||
m_initError = true;
|
||||
setSaveLoadMessage(Message::error(i18n("Not able to select appropriate backend")));
|
||||
|
|
@ -65,14 +65,14 @@ KCMTouchpad::KCMTouchpad(QObject *parent, const KPluginMetaData &data)
|
|||
if (m_initError) {
|
||||
setSaveLoadMessage(Message::error(m_backend->errorString()));
|
||||
} else {
|
||||
connect(m_backend, &TouchpadBackend::needsSaveChanged, this, &KCMTouchpad::updateKcmNeedsSave);
|
||||
connect(m_backend, &TouchpadBackend::deviceAdded, this, &KCMTouchpad::onDeviceAdded);
|
||||
connect(m_backend, &TouchpadBackend::deviceRemoved, this, &KCMTouchpad::onDeviceRemoved);
|
||||
connect(m_backend, &KWinWaylandBackend::needsSaveChanged, this, &KCMTouchpad::updateKcmNeedsSave);
|
||||
connect(m_backend, &KWinWaylandBackend::deviceAdded, this, &KCMTouchpad::onDeviceAdded);
|
||||
connect(m_backend, &KWinWaylandBackend::deviceRemoved, this, &KCMTouchpad::onDeviceRemoved);
|
||||
}
|
||||
setCurrentDeviceIndex(0);
|
||||
}
|
||||
|
||||
TouchpadBackend *KCMTouchpad::backend() const
|
||||
KWinWaylandBackend *KCMTouchpad::backend() const
|
||||
{
|
||||
return m_backend;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include <KPluginMetaData>
|
||||
#include <KQuickConfigModule>
|
||||
|
||||
class TouchpadBackend;
|
||||
class KWinWaylandBackend;
|
||||
class TouchpadConfigPlugin;
|
||||
|
||||
namespace MessageType
|
||||
|
|
@ -48,13 +48,13 @@ class KCMTouchpad : public KQuickConfigModule
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(Message saveLoadMessage MEMBER m_saveLoadMessage NOTIFY saveLoadMessageChanged FINAL)
|
||||
Q_PROPERTY(Message hotplugMessage MEMBER m_hotplugMessage NOTIFY hotplugMessageChanged FINAL)
|
||||
Q_PROPERTY(TouchpadBackend *backend READ backend CONSTANT FINAL)
|
||||
Q_PROPERTY(KWinWaylandBackend *backend READ backend CONSTANT FINAL)
|
||||
Q_PROPERTY(int currentDeviceIndex READ currentDeviceIndex WRITE setCurrentDeviceIndex NOTIFY currentDeviceIndexChanged FINAL)
|
||||
|
||||
public:
|
||||
explicit KCMTouchpad(QObject *parent, const KPluginMetaData &data);
|
||||
|
||||
TouchpadBackend *backend() const;
|
||||
KWinWaylandBackend *backend() const;
|
||||
|
||||
int currentDeviceIndex() const;
|
||||
void setCurrentDeviceIndex(int index);
|
||||
|
|
@ -80,7 +80,7 @@ private:
|
|||
|
||||
Message m_saveLoadMessage;
|
||||
Message m_hotplugMessage;
|
||||
TouchpadBackend *m_backend;
|
||||
KWinWaylandBackend *m_backend;
|
||||
bool m_initError = false;
|
||||
int m_currentDeviceIndex = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2017 Roman Gilg <subdiff@gmail.com>
|
||||
SPDX-FileCopyrightText: 2013 Alexander Mezin <mezin.alexander@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "touchpadbackend.h"
|
||||
|
||||
#include "backends/kwin_wayland/kwinwaylandbackend.h"
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
#include <QThreadStorage>
|
||||
|
||||
#include <KWindowSystem>
|
||||
|
||||
void TouchpadBackend::setMode(TouchpadInputBackendMode mode)
|
||||
{
|
||||
m_mode = mode;
|
||||
}
|
||||
|
||||
TouchpadBackend *TouchpadBackend::implementation()
|
||||
{
|
||||
// TODO: test on kwin_wayland specifically? What about possibly other compositors under Wayland?
|
||||
if (KWindowSystem::isPlatformWayland()) {
|
||||
static QThreadStorage<std::shared_ptr<KWinWaylandBackend>> backend;
|
||||
if (!backend.hasLocalData()) {
|
||||
qCDebug(KCM_TOUCHPAD) << "Using KWin+Wayland backend";
|
||||
backend.setLocalData(std::shared_ptr<KWinWaylandBackend>(new KWinWaylandBackend()));
|
||||
}
|
||||
return backend.localData().get();
|
||||
}
|
||||
|
||||
qCCritical(KCM_TOUCHPAD) << "Not able to select appropriate backend.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#include "moc_touchpadbackend.cpp"
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2017 Roman Gilg <subdiff@gmail.com>
|
||||
SPDX-FileCopyrightText: 2013 Alexander Mezin <mezin.alexander@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "backends/kwin_wayland/kwinwaylandtouchpad.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QVariantHash>
|
||||
|
||||
enum class TouchpadInputBackendMode {
|
||||
Unset = 0,
|
||||
WaylandLibinput = 1,
|
||||
};
|
||||
|
||||
class Q_DECL_EXPORT TouchpadBackend : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QList<KWinWaylandTouchpad *> inputDevices READ inputDevices NOTIFY inputDevicesChanged FINAL)
|
||||
|
||||
protected:
|
||||
explicit TouchpadBackend(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_mode(TouchpadInputBackendMode::Unset)
|
||||
{
|
||||
}
|
||||
void setMode(TouchpadInputBackendMode mode);
|
||||
|
||||
public:
|
||||
static TouchpadBackend *implementation();
|
||||
|
||||
TouchpadInputBackendMode getMode() const
|
||||
{
|
||||
return m_mode;
|
||||
}
|
||||
|
||||
virtual bool save()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool load()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool defaults()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool isSaveNeeded() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual QString errorString() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
virtual QList<KWinWaylandTouchpad *> inputDevices() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
virtual int deviceCount() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual bool isTouchpadAvailable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool isTouchpadSuspended() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual void setTouchpadSuspended(bool)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void watchForEvents()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
TouchpadInputBackendMode m_mode;
|
||||
|
||||
Q_SIGNALS:
|
||||
void needsSaveChanged();
|
||||
|
||||
void touchpadStateChanged();
|
||||
void touchpadReset();
|
||||
void keyboardActivityStarted();
|
||||
void keyboardActivityFinished();
|
||||
|
||||
void inputDevicesChanged();
|
||||
void deviceAdded(bool success);
|
||||
void deviceRemoved(int index);
|
||||
};
|
||||
|
|
@ -5,14 +5,13 @@
|
|||
*/
|
||||
|
||||
#include "touchpadmoduledata.h"
|
||||
|
||||
#include "touchpadbackend.h"
|
||||
#include "backends/kwin_wayland/kwinwaylandbackend.h"
|
||||
|
||||
TouchpadModuleData::TouchpadModuleData(QObject *parent)
|
||||
: KCModuleData(parent)
|
||||
{
|
||||
m_backend = TouchpadBackend::implementation();
|
||||
connect(m_backend, &TouchpadBackend::inputDevicesChanged, this, &TouchpadModuleData::updateRelevance);
|
||||
m_backend = KWinWaylandBackend::implementation();
|
||||
connect(m_backend, &KWinWaylandBackend::inputDevicesChanged, this, &TouchpadModuleData::updateRelevance);
|
||||
updateRelevance();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include <KCModuleData>
|
||||
|
||||
class TouchpadBackend;
|
||||
class KWinWaylandBackend;
|
||||
|
||||
class TouchpadModuleData : public KCModuleData
|
||||
{
|
||||
|
|
@ -20,5 +20,5 @@ public:
|
|||
private:
|
||||
void updateRelevance();
|
||||
|
||||
TouchpadBackend *m_backend = nullptr;
|
||||
KWinWaylandBackend *m_backend = nullptr;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue