|
|
|
@ -5,14 +5,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
constexpr auto s_leftHandedKey = "leftHanded";
|
|
|
|
|
|
|
|
constexpr auto s_naturalScrollKey = "naturalScroll";
|
|
|
|
|
|
|
|
constexpr auto s_pointerAccelerationKey = "pointerAcceleration";
|
|
|
|
|
|
|
|
constexpr auto s_accelerationProfileKey = "accelerationProfile";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Mouse::Mouse(QObject *parent)
|
|
|
|
Mouse::Mouse(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_backend(new KWinInputBackend(KWinInputBackend::DeviceType::Pointer, this))
|
|
|
|
, m_backend(new KWinInputBackend(KWinInputBackend::DeviceType::Pointer, this))
|
|
|
|
|
|
|
|
, m_settings(QSettings::UserScope, QStringLiteral("cutefishos"), QStringLiteral("mouse"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
new MouseAdaptor(this);
|
|
|
|
new MouseAdaptor(this);
|
|
|
|
QDBusConnection::sessionBus().registerObject(QStringLiteral("/Mouse"), this);
|
|
|
|
QDBusConnection::sessionBus().registerObject(QStringLiteral("/Mouse"), this);
|
|
|
|
|
|
|
|
|
|
|
|
connect(m_backend, &KWinInputBackend::devicesChanged, this, [this] {
|
|
|
|
connect(m_backend, &KWinInputBackend::devicesChanged, this, [this] {
|
|
|
|
|
|
|
|
restoreSettings();
|
|
|
|
emit availableChanged();
|
|
|
|
emit availableChanged();
|
|
|
|
emit leftHandedChanged();
|
|
|
|
emit leftHandedChanged();
|
|
|
|
emit accelerationChanged();
|
|
|
|
emit accelerationChanged();
|
|
|
|
@ -23,6 +33,26 @@ Mouse::Mouse(QObject *parent)
|
|
|
|
|
|
|
|
|
|
|
|
Mouse::~Mouse() = default;
|
|
|
|
Mouse::~Mouse() = default;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Mouse::restoreSettings()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!m_backend->available())
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto restoreBoolean = [this](const QString &property, const char *key) {
|
|
|
|
|
|
|
|
if (m_settings.contains(QLatin1String(key)))
|
|
|
|
|
|
|
|
m_backend->setBooleanProperty(property, m_settings.value(QLatin1String(key)).toBool());
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
restoreBoolean(QStringLiteral("leftHanded"), s_leftHandedKey);
|
|
|
|
|
|
|
|
restoreBoolean(QStringLiteral("naturalScroll"), s_naturalScrollKey);
|
|
|
|
|
|
|
|
restoreBoolean(QStringLiteral("pointerAccelerationProfileFlat"), s_accelerationProfileKey);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_settings.contains(QLatin1String(s_pointerAccelerationKey))) {
|
|
|
|
|
|
|
|
m_backend->setRealProperty(QStringLiteral("pointerAcceleration"),
|
|
|
|
|
|
|
|
m_settings.value(QLatin1String(s_pointerAccelerationKey)).toReal());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Mouse::available() const
|
|
|
|
bool Mouse::available() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return m_backend->available();
|
|
|
|
return m_backend->available();
|
|
|
|
@ -37,6 +67,8 @@ void Mouse::setLeftHanded(bool enabled)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (leftHanded() == enabled)
|
|
|
|
if (leftHanded() == enabled)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_settings.setValue(QLatin1String(s_leftHandedKey), enabled);
|
|
|
|
|
|
|
|
m_settings.sync();
|
|
|
|
m_backend->setBooleanProperty(QStringLiteral("leftHanded"), enabled);
|
|
|
|
m_backend->setBooleanProperty(QStringLiteral("leftHanded"), enabled);
|
|
|
|
emit leftHandedChanged();
|
|
|
|
emit leftHandedChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -50,6 +82,8 @@ void Mouse::setAcceleration(bool enabled)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (acceleration() == enabled)
|
|
|
|
if (acceleration() == enabled)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_settings.setValue(QLatin1String(s_accelerationProfileKey), enabled);
|
|
|
|
|
|
|
|
m_settings.sync();
|
|
|
|
m_backend->setBooleanProperty(QStringLiteral("pointerAccelerationProfileFlat"), enabled);
|
|
|
|
m_backend->setBooleanProperty(QStringLiteral("pointerAccelerationProfileFlat"), enabled);
|
|
|
|
m_backend->setBooleanProperty(QStringLiteral("pointerAccelerationProfileAdaptive"), !enabled);
|
|
|
|
m_backend->setBooleanProperty(QStringLiteral("pointerAccelerationProfileAdaptive"), !enabled);
|
|
|
|
emit accelerationChanged();
|
|
|
|
emit accelerationChanged();
|
|
|
|
@ -64,6 +98,8 @@ void Mouse::setNaturalScroll(bool enabled)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (naturalScroll() == enabled)
|
|
|
|
if (naturalScroll() == enabled)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_settings.setValue(QLatin1String(s_naturalScrollKey), enabled);
|
|
|
|
|
|
|
|
m_settings.sync();
|
|
|
|
m_backend->setBooleanProperty(QStringLiteral("naturalScroll"), enabled);
|
|
|
|
m_backend->setBooleanProperty(QStringLiteral("naturalScroll"), enabled);
|
|
|
|
emit naturalScrollChanged();
|
|
|
|
emit naturalScrollChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -78,6 +114,8 @@ void Mouse::setPointerAcceleration(qreal value)
|
|
|
|
value = qBound<qreal>(-1.0, value, 1.0);
|
|
|
|
value = qBound<qreal>(-1.0, value, 1.0);
|
|
|
|
if (qFuzzyCompare(1.0 + pointerAcceleration(), 1.0 + value))
|
|
|
|
if (qFuzzyCompare(1.0 + pointerAcceleration(), 1.0 + value))
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_settings.setValue(QLatin1String(s_pointerAccelerationKey), value);
|
|
|
|
|
|
|
|
m_settings.sync();
|
|
|
|
m_backend->setRealProperty(QStringLiteral("pointerAcceleration"), value);
|
|
|
|
m_backend->setRealProperty(QStringLiteral("pointerAcceleration"), value);
|
|
|
|
emit pointerAccelerationChanged();
|
|
|
|
emit pointerAccelerationChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|