Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lxqt-config-input: add a knob to enable/disable a mouse/touchpad device #621

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lxqt-config-input/touchpadconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ TouchpadConfig::TouchpadConfig(LXQt::Settings* _settings, QWidget* parent):

connect(ui.devicesComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, [this] (int/* index*/) { initControls(); }); // update GUI on device change
connect(ui.deviceEnabledCheckBox, &QAbstractButton::clicked, this, &TouchpadConfig::settingsChanged);
connect(ui.tappingEnabledCheckBox, &QAbstractButton::clicked, this, &TouchpadConfig::settingsChanged);
connect(ui.naturalScrollingEnabledCheckBox, &QAbstractButton::clicked, this, &TouchpadConfig::settingsChanged);
connect(ui.tapToDragEnabledCheckBox, &QAbstractButton::clicked, this, &TouchpadConfig::settingsChanged);
Expand Down Expand Up @@ -75,6 +76,7 @@ void TouchpadConfig::initControls()
}

const TouchpadDevice& device = devices[curDevice];
initFeatureControl(ui.deviceEnabledCheckBox, device.deviceEnabled());
initFeatureControl(ui.tappingEnabledCheckBox, device.tappingEnabled());
initFeatureControl(ui.naturalScrollingEnabledCheckBox, device.naturalScrollingEnabled());
initFeatureControl(ui.tapToDragEnabledCheckBox, device.tapToDragEnabled());
Expand Down Expand Up @@ -133,6 +135,7 @@ void TouchpadConfig::reset()
{
for (const TouchpadDevice& device : qAsConst(devices))
{
device.setDeviceEnabled(device.oldDeviceEnabled());
device.setTappingEnabled(device.oldTappingEnabled());
device.setNaturalScrollingEnabled(device.oldNaturalScrollingEnabled());
device.setTapToDragEnabled(device.oldTapToDragEnabled());
Expand All @@ -153,7 +156,14 @@ void TouchpadConfig::applyConfig()
bool acceptSetting = false;
TouchpadDevice& device = devices[curDevice];

bool enable = ui.tappingEnabledCheckBox->checkState() == Qt::Checked;
bool enable = ui.deviceEnabledCheckBox->checkState() == Qt::Checked;
if (enable != (device.deviceEnabled() > 0))
{
device.setDeviceEnabled(enable);
acceptSetting = true;
}

enable = ui.tappingEnabledCheckBox->checkState() == Qt::Checked;
if (enable != (device.tappingEnabled() > 0))
{
device.setTappingEnabled(enable);
Expand Down
9 changes: 8 additions & 1 deletion lxqt-config-input/touchpadconfig.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>450</width>
<width>534</width>
<height>300</height>
</rect>
</property>
Expand Down Expand Up @@ -139,6 +139,13 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="deviceEnabledCheckBox">
<property name="text">
<string>Enable this device</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down
18 changes: 18 additions & 0 deletions lxqt-config-input/touchpaddevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include <X11/extensions/XInput2.h>
#include <libinput-properties.h>

// somehow libinput does not define this property
#define PROP_DEVICE_ENABLED "Device Enabled"

static QList<QVariant> xi2_get_device_property(int deviceid, const char* prop)
{
QList<QVariant> ret;
Expand Down Expand Up @@ -201,6 +204,7 @@ QList<TouchpadDevice> TouchpadDevice::enumerate_from_udev()
if(dev.find_xi2_device())
{
qDebug() << "Detected" << dev.m_name << "on" << dev.devnode;
dev.m_oldDeviceEnabled = dev.deviceEnabled();
dev.m_oldTappingEnabled = dev.tappingEnabled();
dev.m_oldNaturalScrollingEnabled = dev.naturalScrollingEnabled();
dev.m_oldTapToDragEnabled = dev.tapToDragEnabled();
Expand Down Expand Up @@ -259,6 +263,9 @@ void TouchpadDevice::loadSettings(LXQt::Settings* settings)
qDebug() << "Load settings for" << device.name();

settings->beginGroup(device.escapedName());
if (settings->contains(QLatin1String(DEVICE_ENABLED))) {
device.setDeviceEnabled(settings->value(QLatin1String(DEVICE_ENABLED)).toBool());
}
if (settings->contains(QLatin1String(TAPPING_ENABLED))) {
device.setTappingEnabled(settings->value(QLatin1String(TAPPING_ENABLED)).toBool());
}
Expand All @@ -285,6 +292,7 @@ void TouchpadDevice::saveSettings(LXQt::Settings* settings) const
settings->beginGroup(QStringLiteral("Touchpad"));

settings->beginGroup(escapedName());
settings->setValue(QLatin1String(DEVICE_ENABLED), deviceEnabled());
settings->setValue(QLatin1String(TAPPING_ENABLED), tappingEnabled());
settings->setValue(QLatin1String(NATURAL_SCROLLING_ENABLED), naturalScrollingEnabled());
settings->setValue(QLatin1String(TAP_TO_DRAG_ENABLED), tapToDragEnabled());
Expand All @@ -308,6 +316,11 @@ int TouchpadDevice::featureEnabled(const char* prop) const
}
}

int TouchpadDevice::deviceEnabled() const
{
return featureEnabled(PROP_DEVICE_ENABLED);
}

int TouchpadDevice::tappingEnabled() const
{
return featureEnabled(LIBINPUT_PROP_TAP);
Expand Down Expand Up @@ -336,6 +349,11 @@ float TouchpadDevice::accelSpeed() const
}
}

bool TouchpadDevice::setDeviceEnabled(bool enabled) const
{
return set_xi2_property(PROP_DEVICE_ENABLED, QList<QVariant>({enabled ? 1 : 0}));
}

bool TouchpadDevice::setTappingEnabled(bool enabled) const
{
return set_xi2_property(LIBINPUT_PROP_TAP, QList<QVariant>({enabled ? 1 : 0}));
Expand Down
5 changes: 5 additions & 0 deletions lxqt-config-input/touchpaddevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum ScrollingMethod
BUTTON = 4
};

const char DEVICE_ENABLED[] = "deviceEnabled";
const char TAPPING_ENABLED[] = "tappingEnabled";
const char NATURAL_SCROLLING_ENABLED[] = "naturalScrollingEnabled";
const char TAP_TO_DRAG_ENABLED[] = "tapToDragEnabled";
Expand All @@ -50,14 +51,17 @@ class TouchpadDevice
const QString& name() const { return m_name; }
QString escapedName() const;

int deviceEnabled() const;
int tappingEnabled() const;
int naturalScrollingEnabled() const;
int tapToDragEnabled() const;
float accelSpeed() const;
bool setDeviceEnabled(bool enabled) const;
bool setTappingEnabled(bool enabled) const;
bool setNaturalScrollingEnabled(bool enabled) const;
bool setTapToDragEnabled(bool enabled) const;
bool setAccelSpeed(float speed) const;
bool oldDeviceEnabled() const { return m_oldDeviceEnabled; }
bool oldTappingEnabled() const { return m_oldTappingEnabled; }
bool oldNaturalScrollingEnabled() const { return m_oldNaturalScrollingEnabled; }
bool oldTapToDragEnabled() const { return m_oldTapToDragEnabled; }
Expand All @@ -75,6 +79,7 @@ class TouchpadDevice
QString devnode;
int deviceid;

bool m_oldDeviceEnabled;
bool m_oldTappingEnabled;
bool m_oldNaturalScrollingEnabled;
bool m_oldTapToDragEnabled;
Expand Down