[libinput] Add device configuration for tap-drag-lock

From libinput documentation:
Also optional is a feature called "drag lock". With drag lock disabled,
lifting the finger will stop any drag process. When enabled, libinput
will ignore a finger up event during a drag process, provided the finger
is set down again within a implementation-specific timeout.
icc-effect-5.14.5
Martin Gräßlin 2016-08-11 16:32:00 +02:00
parent 02cf9e8a64
commit cd6d82fcbc
5 changed files with 103 additions and 0 deletions

View File

@ -73,6 +73,10 @@ private Q_SLOTS:
void testTapAndDragEnabledByDefault();
void testTapAndDrag_data();
void testTapAndDrag();
void testTapDragLockEnabledByDefault_data();
void testTapDragLockEnabledByDefault();
void testTapDragLock_data();
void testTapDragLock();
};
void TestLibinputDevice::testStaticGetter()
@ -706,5 +710,59 @@ void TestLibinputDevice::testTapAndDrag()
QCOMPARE(tapAndDragChangedSpy.isEmpty(), initValue == expectedValue);
}
void TestLibinputDevice::testTapDragLockEnabledByDefault_data()
{
QTest::addColumn<bool>("enabled");
QTest::newRow("enabled") << true;
QTest::newRow("disabled") << false;
}
void TestLibinputDevice::testTapDragLockEnabledByDefault()
{
QFETCH(bool, enabled);
libinput_device device;
device.tapDragLockEnabledByDefault = enabled;
Device d(&device);
QCOMPARE(d.tapDragLockEnabledByDefault(), enabled);
QCOMPARE(d.property("tapDragLockEnabledByDefault").toBool(), enabled);
}
void TestLibinputDevice::testTapDragLock_data()
{
QTest::addColumn<bool>("initValue");
QTest::addColumn<bool>("setValue");
QTest::addColumn<bool>("setShouldFail");
QTest::addColumn<bool>("expectedValue");
QTest::newRow("true -> false") << true << false << false << false;
QTest::newRow("false -> true") << false << true << false << true;
QTest::newRow("set fails") << true << false << true << true;
QTest::newRow("true -> true") << true << true << false << true;
QTest::newRow("false -> false") << false << false << false << false;
}
void TestLibinputDevice::testTapDragLock()
{
libinput_device device;
QFETCH(bool, initValue);
QFETCH(bool, setShouldFail);
device.tapDragLock = initValue;
device.setTapDragLockReturnValue = setShouldFail;
Device d(&device);
QCOMPARE(d.isTapDragLock(), initValue);
QCOMPARE(d.property("tapDragLock").toBool(), initValue);
QSignalSpy tapDragLockChangedSpy(&d, &Device::tapDragLockChanged);
QVERIFY(tapDragLockChangedSpy.isValid());
QFETCH(bool, setValue);
d.setTapDragLock(setValue);
QFETCH(bool, expectedValue);
QCOMPARE(d.isTapDragLock(), expectedValue);
QCOMPARE(tapDragLockChangedSpy.isEmpty(), initValue == expectedValue);
}
QTEST_GUILESS_MAIN(TestLibinputDevice)
#include "device_test.moc"

View File

@ -130,6 +130,33 @@ enum libinput_config_status libinput_device_config_tap_set_drag_enabled(struct l
return LIBINPUT_CONFIG_STATUS_INVALID;
}
enum libinput_config_drag_lock_state libinput_device_config_tap_get_default_drag_lock_enabled(struct libinput_device *device)
{
if (device->tapDragLockEnabledByDefault) {
return LIBINPUT_CONFIG_DRAG_LOCK_ENABLED;
} else {
return LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
}
}
enum libinput_config_drag_lock_state libinput_device_config_tap_get_drag_lock_enabled(struct libinput_device *device)
{
if (device->tapDragLock) {
return LIBINPUT_CONFIG_DRAG_LOCK_ENABLED;
} else {
return LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
}
}
enum libinput_config_status libinput_device_config_tap_set_drag_lock_enabled(struct libinput_device *device, enum libinput_config_drag_lock_state enable)
{
if (device->setTapDragLockReturnValue == 0) {
device->tapDragLock = (enable == LIBINPUT_CONFIG_DRAG_LOCK_ENABLED);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
return LIBINPUT_CONFIG_STATUS_INVALID;
}
int libinput_device_config_dwt_is_available(struct libinput_device *device)
{
return device->supportsDisableWhileTyping;

View File

@ -44,6 +44,8 @@ struct libinput_device {
bool tapToClick = false;
bool tapAndDragEnabledByDefault = false;
bool tapAndDrag = false;
bool tapDragLockEnabledByDefault = false;
bool tapDragLock = false;
bool supportsDisableWhileTyping = false;
bool supportsPointerAcceleration = false;
bool supportsLeftHanded = false;
@ -60,6 +62,7 @@ struct libinput_device {
int setEnableModeReturnValue = 0;
int setTapToClickReturnValue = 0;
int setTapAndDragReturnValue = 0;
int setTapDragLockReturnValue = 0;
};
struct libinput_event {

View File

@ -93,6 +93,8 @@ Device::Device(libinput_device *device, QObject *parent)
, m_tapToClick(libinput_device_config_tap_get_enabled(m_device))
, m_tapAndDragEnabledByDefault(libinput_device_config_tap_get_default_drag_enabled(m_device))
, m_tapAndDrag(libinput_device_config_tap_get_drag_enabled(m_device))
, m_tapDragLockEnabledByDefault(libinput_device_config_tap_get_default_drag_lock_enabled(m_device))
, m_tapDragLock(libinput_device_config_tap_get_drag_lock_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))
@ -193,6 +195,7 @@ void Device::method(bool set) \
CONFIG(setEnabled, !m_supportsDisableEvents, send_events_set_mode, SEND_EVENTS, enabled)
CONFIG(setTapToClick, m_tapFingerCount == 0, tap_set_enabled, TAP, tapToClick)
CONFIG(setTapAndDrag, false, tap_set_drag_enabled, DRAG, tapAndDrag)
CONFIG(setTapDragLock, false, tap_set_drag_lock_enabled, DRAG_LOCK, tapDragLock)
#undef CONFIG

View File

@ -61,6 +61,8 @@ class Device : public QObject
Q_PROPERTY(bool tapToClick READ isTapToClick WRITE setTapToClick NOTIFY tapToClickChanged)
Q_PROPERTY(bool tapAndDragEnabledByDefault READ tapAndDragEnabledByDefault CONSTANT)
Q_PROPERTY(bool tapAndDrag READ isTapAndDrag WRITE setTapAndDrag NOTIFY tapAndDragChanged)
Q_PROPERTY(bool tapDragLockEnabledByDefault READ tapDragLockEnabledByDefault CONSTANT)
Q_PROPERTY(bool tapDragLock READ isTapDragLock WRITE setTapDragLock NOTIFY tapDragLockChanged)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
public:
explicit Device(libinput_device *device, QObject *parent = nullptr);
@ -128,6 +130,13 @@ public:
return m_tapAndDrag;
}
void setTapAndDrag(bool set);
bool tapDragLockEnabledByDefault() const {
return m_tapDragLockEnabledByDefault;
}
bool isTapDragLock() const {
return m_tapDragLock;
}
void setTapDragLock(bool set);
bool supportsDisableWhileTyping() const {
return m_supportsDisableWhileTyping;
}
@ -190,6 +199,7 @@ Q_SIGNALS:
void enabledChanged();
void tapToClickChanged();
void tapAndDragChanged();
void tapDragLockChanged();
private:
libinput_device *m_device;
@ -212,6 +222,8 @@ private:
bool m_tapToClick;
bool m_tapAndDragEnabledByDefault;
bool m_tapAndDrag;
bool m_tapDragLockEnabledByDefault;
bool m_tapDragLock;
bool m_supportsDisableWhileTyping;
bool m_supportsPointerAcceleration;
bool m_supportsLeftHanded;