[libinput] Add support for tapToClick configuration
New property added to Device which allows reading and setting the tap to click configuration.
This commit is contained in:
parent
079095beea
commit
2f7298bed5
5 changed files with 82 additions and 2 deletions
|
@ -67,6 +67,8 @@ private Q_SLOTS:
|
|||
void testAlphaNumericKeyboard();
|
||||
void testEnabled_data();
|
||||
void testEnabled();
|
||||
void testTapToClick_data();
|
||||
void testTapToClick();
|
||||
};
|
||||
|
||||
void TestLibinputDevice::testStaticGetter()
|
||||
|
@ -606,5 +608,45 @@ void TestLibinputDevice::testEnabled()
|
|||
QCOMPARE(d.isEnabled(), expectedValue);
|
||||
}
|
||||
|
||||
void TestLibinputDevice::testTapToClick_data()
|
||||
{
|
||||
QTest::addColumn<int>("fingerCount");
|
||||
QTest::addColumn<bool>("initValue");
|
||||
QTest::addColumn<bool>("setValue");
|
||||
QTest::addColumn<bool>("setShouldFail");
|
||||
QTest::addColumn<bool>("expectedValue");
|
||||
|
||||
QTest::newRow("unsupported") << 0 << false << true << true << false;
|
||||
QTest::newRow("true -> false") << 1 << true << false << false << false;
|
||||
QTest::newRow("false -> true") << 2 << false << true << false << true;
|
||||
QTest::newRow("set fails") << 3 << true << false << true << true;
|
||||
QTest::newRow("true -> true") << 2 << true << true << false << true;
|
||||
QTest::newRow("false -> false") << 1 << false << false << false << false;
|
||||
}
|
||||
|
||||
void TestLibinputDevice::testTapToClick()
|
||||
{
|
||||
libinput_device device;
|
||||
QFETCH(int, fingerCount);
|
||||
QFETCH(bool, initValue);
|
||||
QFETCH(bool, setShouldFail);
|
||||
device.tapFingerCount = fingerCount;
|
||||
device.tapToClick = initValue;
|
||||
device.setTapToClickReturnValue = setShouldFail;
|
||||
|
||||
Device d(&device);
|
||||
QCOMPARE(d.tapFingerCount(), fingerCount);
|
||||
QCOMPARE(d.isTapToClick(), initValue);
|
||||
QCOMPARE(d.property("tapToClick").toBool(), initValue);
|
||||
|
||||
QSignalSpy tapToClickChangedSpy(&d, &Device::tapToClickChanged);
|
||||
QVERIFY(tapToClickChangedSpy.isValid());
|
||||
QFETCH(bool, setValue);
|
||||
d.setTapToClick(setValue);
|
||||
QFETCH(bool, expectedValue);
|
||||
QCOMPARE(d.isTapToClick(), expectedValue);
|
||||
QCOMPARE(tapToClickChangedSpy.isEmpty(), initValue == expectedValue);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestLibinputDevice)
|
||||
#include "device_test.moc"
|
||||
|
|
|
@ -78,8 +78,20 @@ int libinput_device_config_tap_get_finger_count(struct libinput_device *device)
|
|||
|
||||
enum libinput_config_tap_state libinput_device_config_tap_get_enabled(struct libinput_device *device)
|
||||
{
|
||||
Q_UNUSED(device)
|
||||
return LIBINPUT_CONFIG_TAP_DISABLED;
|
||||
if (device->tapToClick) {
|
||||
return LIBINPUT_CONFIG_TAP_ENABLED;
|
||||
} else {
|
||||
return LIBINPUT_CONFIG_TAP_DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
enum libinput_config_status libinput_device_config_tap_set_enabled(struct libinput_device *device, enum libinput_config_tap_state enable)
|
||||
{
|
||||
if (device->setTapToClickReturnValue == 0) {
|
||||
device->tapToClick = (enable == LIBINPUT_CONFIG_TAP_ENABLED);
|
||||
return LIBINPUT_CONFIG_STATUS_SUCCESS;
|
||||
}
|
||||
return LIBINPUT_CONFIG_STATUS_INVALID;
|
||||
}
|
||||
|
||||
enum libinput_config_tap_state libinput_device_config_tap_get_default_enabled(struct libinput_device *device)
|
||||
|
|
|
@ -41,6 +41,7 @@ struct libinput_device {
|
|||
QSizeF deviceSize;
|
||||
int deviceSizeReturnValue = 0;
|
||||
bool tapEnabledByDefault = false;
|
||||
bool tapToClick = false;
|
||||
bool supportsDisableWhileTyping = false;
|
||||
bool supportsPointerAcceleration = false;
|
||||
bool supportsLeftHanded = false;
|
||||
|
@ -55,6 +56,7 @@ struct libinput_device {
|
|||
QVector<quint32> keys;
|
||||
bool enabled = true;
|
||||
int setEnableModeReturnValue = 0;
|
||||
int setTapToClickReturnValue = 0;
|
||||
};
|
||||
|
||||
struct libinput_event {
|
||||
|
|
|
@ -90,6 +90,7 @@ Device::Device(libinput_device *device, QObject *parent)
|
|||
, m_vendor(libinput_device_get_id_vendor(m_device))
|
||||
, m_tapFingerCount(libinput_device_config_tap_get_finger_count(m_device))
|
||||
, m_tapEnabledByDefault(libinput_device_config_tap_get_default_enabled(m_device) == LIBINPUT_CONFIG_TAP_ENABLED)
|
||||
, m_tapToClick(libinput_device_config_tap_get_enabled(m_device))
|
||||
, m_supportsDisableWhileTyping(libinput_device_config_dwt_is_available(m_device))
|
||||
, m_supportsPointerAcceleration(libinput_device_config_accel_is_available(m_device))
|
||||
, m_supportsLeftHanded(libinput_device_config_left_handed_is_available(m_device))
|
||||
|
@ -186,5 +187,18 @@ void Device::setEnabled(bool enabled)
|
|||
}
|
||||
}
|
||||
|
||||
void Device::setTapToClick(bool set)
|
||||
{
|
||||
if (m_tapFingerCount == 0) {
|
||||
return;
|
||||
}
|
||||
if (libinput_device_config_tap_set_enabled(m_device, set ? LIBINPUT_CONFIG_TAP_ENABLED : LIBINPUT_CONFIG_TAP_DISABLED) == LIBINPUT_CONFIG_STATUS_SUCCESS) {
|
||||
if (m_tapToClick != set) {
|
||||
m_tapToClick = set;
|
||||
emit tapToClickChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ class Device : public QObject
|
|||
Q_PROPERTY(bool supportsDisableEventsOnExternalMouse READ supportsDisableEventsOnExternalMouse CONSTANT)
|
||||
Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged)
|
||||
Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged)
|
||||
Q_PROPERTY(bool tapToClick READ isTapToClick WRITE setTapToClick NOTIFY tapToClickChanged)
|
||||
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
|
||||
public:
|
||||
explicit Device(libinput_device *device, QObject *parent = nullptr);
|
||||
|
@ -111,6 +112,13 @@ public:
|
|||
bool tapEnabledByDefault() const {
|
||||
return m_tapEnabledByDefault;
|
||||
}
|
||||
bool isTapToClick() const {
|
||||
return m_tapToClick;
|
||||
}
|
||||
/**
|
||||
* Set the Device to tap to click if @p set is @c true.
|
||||
**/
|
||||
void setTapToClick(bool set);
|
||||
bool supportsDisableWhileTyping() const {
|
||||
return m_supportsDisableWhileTyping;
|
||||
}
|
||||
|
@ -171,6 +179,7 @@ Q_SIGNALS:
|
|||
void leftHandedChanged();
|
||||
void pointerAccelerationChanged();
|
||||
void enabledChanged();
|
||||
void tapToClickChanged();
|
||||
|
||||
private:
|
||||
libinput_device *m_device;
|
||||
|
@ -190,6 +199,7 @@ private:
|
|||
Qt::MouseButtons m_supportedButtons = Qt::NoButton;
|
||||
int m_tapFingerCount;
|
||||
bool m_tapEnabledByDefault;
|
||||
bool m_tapToClick;
|
||||
bool m_supportsDisableWhileTyping;
|
||||
bool m_supportsPointerAcceleration;
|
||||
bool m_supportsLeftHanded;
|
||||
|
|
Loading…
Reference in a new issue