[libinput] Change unset of scroll method and acceleration profile

Go for a more intuitive unset behaviour of scroll method and acceleration
profile properties.

Summary:
Unsetting a scroll method should only work, if the scroll method is currently
active. For example when scroll-two-finger is active (i.e. scroll-edge,
scroll-on-button-down is not active):
* unsetting scroll-two-finger should deactivate it and activate no-scroll
* but unsetting for example scroll-edge should _not_ deactivate scroll-two-
  finger and _not_ activate no-scroll

Reworked setting scroll method auto test in order to test it.

Regarding acceleration profiles: Unsetting one, should always switch to the
other possible one as long as both are supported. In this case
LIBINPUT_CONFIG_ACCEL_PROFILE_NONE is not a valid option in contrast to the
definition of the scroll method enums.

Reviewers: #kwin

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D3590
This commit is contained in:
Roman Gilg 2016-12-06 13:45:54 +01:00
parent 82debf5548
commit fd07b1dc98
3 changed files with 50 additions and 31 deletions

View file

@ -1222,33 +1222,37 @@ void TestLibinputDevice::testNaturalScroll()
void TestLibinputDevice::testScrollTwoFinger_data()
{
QTest::addColumn<bool>("initValue");
QTest::addColumn<bool>("otherValue");
QTest::addColumn<bool>("setValue");
QTest::addColumn<bool>("setShouldFail");
QTest::addColumn<bool>("expectedValue");
QTest::addColumn<bool>("supportsScrollTwoFinger");
QTest::newRow("true -> false") << true << false << false << false << true;
QTest::newRow("false -> true") << false << true << false << true << true;
QTest::newRow("set fails") << true << false << true << true << true;
QTest::newRow("true -> true") << true << true << false << true << true;
QTest::newRow("false -> false") << false << false << false << false << true;
QTest::newRow("true -> false") << true << false << false << false << false << true;
QTest::newRow("other -> false") << false << true << false << false << false << true;
QTest::newRow("false -> true") << false << false << true << false << true << true;
QTest::newRow("set fails") << true << false << false << true << true << true;
QTest::newRow("true -> true") << true << false << true << false << true << true;
QTest::newRow("false -> false") << false << false << false << false << false << true;
QTest::newRow("false -> true, unsupported") << false << true << true << false << false;
QTest::newRow("false -> true, unsupported") << false << false << true << true << false << false;
}
void TestLibinputDevice::testScrollTwoFinger()
{
libinput_device device;
QFETCH(bool, initValue);
QFETCH(bool, otherValue);
QFETCH(bool, setShouldFail);
QFETCH(bool, supportsScrollTwoFinger);
device.supportedScrollMethods = supportsScrollTwoFinger ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
device.supportedScrollMethods = (supportsScrollTwoFinger ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL) | LIBINPUT_CONFIG_SCROLL_EDGE;
device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_2FG : otherValue ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
device.setScrollMethodReturnValue = setShouldFail;
Device d(&device);
QCOMPARE(d.isScrollTwoFinger(), initValue);
QCOMPARE(d.property("scrollTwoFinger").toBool(), initValue);
QCOMPARE(d.property("scrollEdge").toBool(), otherValue);
QSignalSpy scrollMethodChangedSpy(&d, &Device::scrollMethodChanged);
QVERIFY(scrollMethodChangedSpy.isValid());
@ -1263,33 +1267,37 @@ void TestLibinputDevice::testScrollTwoFinger()
void TestLibinputDevice::testScrollEdge_data()
{
QTest::addColumn<bool>("initValue");
QTest::addColumn<bool>("otherValue");
QTest::addColumn<bool>("setValue");
QTest::addColumn<bool>("setShouldFail");
QTest::addColumn<bool>("expectedValue");
QTest::addColumn<bool>("supportsScrollEdge");
QTest::newRow("true -> false") << true << false << false << false << true;
QTest::newRow("false -> true") << false << true << false << true << true;
QTest::newRow("set fails") << true << false << true << true << true;
QTest::newRow("true -> true") << true << true << false << true << true;
QTest::newRow("false -> false") << false << false << false << false << true;
QTest::newRow("true -> false") << true << false << false << false << false << true;
QTest::newRow("other -> false") << false << true << false << false << false << true;
QTest::newRow("false -> true") << false << false << true << false << true << true;
QTest::newRow("set fails") << true << false << false << true << true << true;
QTest::newRow("true -> true") << true << false << true << false << true << true;
QTest::newRow("false -> false") << false << false << false << false << false << true;
QTest::newRow("false -> true, unsupported") << false << true << true << false << false;
QTest::newRow("false -> true, unsupported") << false << false << true << true << false << false;
}
void TestLibinputDevice::testScrollEdge()
{
libinput_device device;
QFETCH(bool, initValue);
QFETCH(bool, otherValue);
QFETCH(bool, setShouldFail);
QFETCH(bool, supportsScrollEdge);
device.supportedScrollMethods = supportsScrollEdge ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
device.supportedScrollMethods = (supportsScrollEdge ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL) | LIBINPUT_CONFIG_SCROLL_2FG;
device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_EDGE : otherValue ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
device.setScrollMethodReturnValue = setShouldFail;
Device d(&device);
QCOMPARE(d.isScrollEdge(), initValue);
QCOMPARE(d.property("scrollEdge").toBool(), initValue);
QCOMPARE(d.property("scrollTwoFinger").toBool(), otherValue);
QSignalSpy scrollMethodChangedSpy(&d, &Device::scrollMethodChanged);
QVERIFY(scrollMethodChangedSpy.isValid());
@ -1304,33 +1312,37 @@ void TestLibinputDevice::testScrollEdge()
void TestLibinputDevice::testScrollButtonDown_data()
{
QTest::addColumn<bool>("initValue");
QTest::addColumn<bool>("otherValue");
QTest::addColumn<bool>("setValue");
QTest::addColumn<bool>("setShouldFail");
QTest::addColumn<bool>("expectedValue");
QTest::addColumn<bool>("supportsScrollButtonDown");
QTest::newRow("true -> false") << true << false << false << false << true;
QTest::newRow("false -> true") << false << true << false << true << true;
QTest::newRow("set fails") << true << false << true << true << true;
QTest::newRow("true -> true") << true << true << false << true << true;
QTest::newRow("false -> false") << false << false << false << false << true;
QTest::newRow("true -> false") << true << false << false << false << false << true;
QTest::newRow("other -> false") << false << true << false << false << false << true;
QTest::newRow("false -> true") << false << false << true << false << true << true;
QTest::newRow("set fails") << true << false << false << true << true << true;
QTest::newRow("true -> true") << true << false << true << false << true << true;
QTest::newRow("false -> false") << false << false << false << false << false << true;
QTest::newRow("false -> true, unsupported") << false << true << true << false << false;
QTest::newRow("false -> true, unsupported") << false << false << true << true << false << false;
}
void TestLibinputDevice::testScrollButtonDown()
{
libinput_device device;
QFETCH(bool, initValue);
QFETCH(bool, otherValue);
QFETCH(bool, setShouldFail);
QFETCH(bool, supportsScrollButtonDown);
device.supportedScrollMethods = supportsScrollButtonDown ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
device.supportedScrollMethods = (supportsScrollButtonDown ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : LIBINPUT_CONFIG_SCROLL_NO_SCROLL) | LIBINPUT_CONFIG_SCROLL_2FG;
device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : otherValue ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
device.setScrollMethodReturnValue = setShouldFail;
Device d(&device);
QCOMPARE(d.isScrollOnButtonDown(), initValue);
QCOMPARE(d.property("scrollOnButtonDown").toBool(), initValue);
QCOMPARE(d.property("scrollTwoFinger").toBool(), otherValue);
QSignalSpy scrollMethodChangedSpy(&d, &Device::scrollMethodChanged);
QVERIFY(scrollMethodChangedSpy.isValid());

View file

@ -121,7 +121,7 @@ static const QMap<ConfigKey, ConfigData> s_configData {
{ConfigKey::LeftHanded, ConfigData(QByteArrayLiteral("LeftHanded"), &Device::setLeftHanded, &Device::leftHandedEnabledByDefault)},
{ConfigKey::DisableWhileTyping, ConfigData(QByteArrayLiteral("DisableWhileTyping"), &Device::setDisableWhileTyping, &Device::disableWhileTypingEnabledByDefault)},
{ConfigKey::PointerAcceleration, ConfigData(QByteArrayLiteral("PointerAcceleration"), &Device::setPointerAccelerationFromString, &Device::defaultPointerAccelerationToString)},
{ConfigKey::PointerAccelerationProfile, ConfigData(QByteArrayLiteral("PointerAccelerationProfile"), &Device::activatePointerAccelerationProfileFromInt, &Device::defaultPointerAccelerationProfileToInt)},
{ConfigKey::PointerAccelerationProfile, ConfigData(QByteArrayLiteral("PointerAccelerationProfile"), &Device::setPointerAccelerationProfileFromInt, &Device::defaultPointerAccelerationProfileToInt)},
{ConfigKey::TapToClick, ConfigData(QByteArrayLiteral("TapToClick"), &Device::setTapToClick, &Device::tapToClickEnabledByDefault)},
{ConfigKey::TapAndDrag, ConfigData(QByteArrayLiteral("TapAndDrag"), &Device::setTapAndDrag, &Device::tapAndDragEnabledByDefault)},
{ConfigKey::TapDragLock, ConfigData(QByteArrayLiteral("TapDragLock"), &Device::setTapDragLock, &Device::tapDragLockEnabledByDefault)},
@ -315,13 +315,14 @@ void Device::setScrollButton(quint32 button)
}
void Device::setPointerAccelerationProfile(bool set, enum libinput_config_accel_profile profile) {
if (!(m_supportedPointerAccelerationProfiles & profile)) {
return;
}
if (!set) {
profile = LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
profile = (profile == LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT) ? LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE : LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
if (!(m_supportedPointerAccelerationProfiles & profile)) {
return;
}
}
if (libinput_device_config_accel_set_profile(m_device, profile) == LIBINPUT_CONFIG_STATUS_SUCCESS) {
@ -339,12 +340,18 @@ void Device::setScrollMethod(bool set, enum libinput_config_scroll_method method
return;
}
bool isCurrent = m_scrollMethod == method;
if (!set) {
method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
if (isCurrent) {
method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
isCurrent = false;
} else {
return;
}
}
if (libinput_device_config_scroll_set_method(m_device, method) == LIBINPUT_CONFIG_STATUS_SUCCESS) {
if (m_scrollMethod != method) {
if (!isCurrent) {
m_scrollMethod = method;
emit scrollMethodChanged();
writeEntry(ConfigKey::ScrollMethod, (quint32) method);

View file

@ -369,7 +369,7 @@ public:
void setPointerAccelerationProfileAdaptive(bool set) {
setPointerAccelerationProfile(set, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE);
}
void activatePointerAccelerationProfileFromInt(quint32 profile) {
void setPointerAccelerationProfileFromInt(quint32 profile) {
setPointerAccelerationProfile(true, (libinput_config_accel_profile) profile);
}
quint32 defaultPointerAccelerationProfileToInt() const {