diff --git a/autotests/libinput/device_test.cpp b/autotests/libinput/device_test.cpp index da0599c8e..3effab7b9 100644 --- a/autotests/libinput/device_test.cpp +++ b/autotests/libinput/device_test.cpp @@ -1,1768 +1,1690 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2016 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "mock_libinput.h" #include "../../libinput/device.h" #include #include #include #include using namespace KWin::LibInput; class TestLibinputDevice : public QObject { Q_OBJECT private Q_SLOTS: void testStaticGetter(); void testDeviceType_data(); void testDeviceType(); void testGestureSupport_data(); void testGestureSupport(); void testNames_data(); void testNames(); void testProduct(); void testVendor(); void testTapFingerCount(); void testSize_data(); void testSize(); void testLeftHandedEnabledByDefault_data(); void testLeftHandedEnabledByDefault(); void testTapEnabledByDefault_data(); void testTapEnabledByDefault(); void testMiddleEmulationEnabledByDefault_data(); void testMiddleEmulationEnabledByDefault(); void testNaturalScrollEnabledByDefault_data(); void testNaturalScrollEnabledByDefault(); void testScrollTwoFingerEnabledByDefault_data(); void testScrollTwoFingerEnabledByDefault(); void testScrollEdgeEnabledByDefault_data(); void testScrollEdgeEnabledByDefault(); void testScrollOnButtonDownEnabledByDefault_data(); void testScrollOnButtonDownEnabledByDefault(); void testSupportsDisableWhileTyping_data(); void testSupportsDisableWhileTyping(); void testSupportsPointerAcceleration_data(); void testSupportsPointerAcceleration(); void testSupportsLeftHanded_data(); void testSupportsLeftHanded(); void testSupportsCalibrationMatrix_data(); void testSupportsCalibrationMatrix(); void testSupportsDisableEvents_data(); void testSupportsDisableEvents(); void testSupportsDisableEventsOnExternalMouse_data(); void testSupportsDisableEventsOnExternalMouse(); void testSupportsMiddleEmulation_data(); void testSupportsMiddleEmulation(); void testSupportsNaturalScroll_data(); void testSupportsNaturalScroll(); void testSupportsScrollTwoFinger_data(); void testSupportsScrollTwoFinger(); void testSupportsScrollEdge_data(); void testSupportsScrollEdge(); void testSupportsScrollOnButtonDown_data(); void testSupportsScrollOnButtonDown(); void testDefaultScrollButton_data(); void testDefaultScrollButton(); void testPointerAcceleration_data(); void testPointerAcceleration(); void testLeftHanded_data(); void testLeftHanded(); void testSupportedButtons_data(); void testSupportedButtons(); void testAlphaNumericKeyboard_data(); void testAlphaNumericKeyboard(); void testEnabled_data(); void testEnabled(); void testTapToClick_data(); void testTapToClick(); void testTapAndDragEnabledByDefault_data(); void testTapAndDragEnabledByDefault(); void testTapAndDrag_data(); void testTapAndDrag(); void testTapDragLockEnabledByDefault_data(); void testTapDragLockEnabledByDefault(); void testTapDragLock_data(); void testTapDragLock(); void testMiddleEmulation_data(); void testMiddleEmulation(); void testNaturalScroll_data(); void testNaturalScroll(); void testScrollTwoFinger_data(); void testScrollTwoFinger(); void testScrollEdge_data(); void testScrollEdge(); void testScrollButtonDown_data(); void testScrollButtonDown(); void testScrollButton_data(); void testScrollButton(); void testLoadEnabled_data(); void testLoadEnabled(); void testLoadTapToClick_data(); void testLoadTapToClick(); void testLoadTapAndDrag_data(); void testLoadTapAndDrag(); void testLoadTapDragLock_data(); void testLoadTapDragLock(); void testLoadMiddleButtonEmulation_data(); void testLoadMiddleButtonEmulation(); void testLoadNaturalScroll_data(); void testLoadNaturalScroll(); - void testLoadScrollTwoFinger_data(); - void testLoadScrollTwoFinger(); - void testLoadScrollEdge_data(); - void testLoadScrollEdge(); - void testLoadScrollOnButton_data(); - void testLoadScrollOnButton(); + void testLoadScrollMethod_data(); + void testLoadScrollMethod(); void testLoadScrollButton_data(); void testLoadScrollButton(); void testLoadLeftHanded_data(); void testLoadLeftHanded(); }; void TestLibinputDevice::testStaticGetter() { // this test verifies that the static getter for Device works as expected QVERIFY(Device::devices().isEmpty()); // create some device libinput_device device1; libinput_device device2; // at the moment not yet known to Device QVERIFY(!Device::getDevice(&device1)); QVERIFY(!Device::getDevice(&device2)); QVERIFY(Device::devices().isEmpty()); // now create a Device for one Device *d1 = new Device(&device1); QCOMPARE(Device::devices().count(), 1); QCOMPARE(Device::devices().first(), d1); QCOMPARE(Device::getDevice(&device1), d1); QVERIFY(!Device::getDevice(&device2)); // and a second Device Device *d2 = new Device(&device2); QCOMPARE(Device::devices().count(), 2); QCOMPARE(Device::devices().first(), d1); QCOMPARE(Device::devices().last(), d2); QCOMPARE(Device::getDevice(&device1), d1); QCOMPARE(Device::getDevice(&device2), d2); // now delete d1 delete d1; QCOMPARE(Device::devices().count(), 1); QCOMPARE(Device::devices().first(), d2); QCOMPARE(Device::getDevice(&device2), d2); QVERIFY(!Device::getDevice(&device1)); // and delete d2 delete d2; QVERIFY(!Device::getDevice(&device1)); QVERIFY(!Device::getDevice(&device2)); QVERIFY(Device::devices().isEmpty()); } void TestLibinputDevice::testDeviceType_data() { QTest::addColumn("keyboard"); QTest::addColumn("pointer"); QTest::addColumn("touch"); QTest::addColumn("tabletTool"); QTest::newRow("keyboard") << true << false << false << false; QTest::newRow("pointer") << false << true << false << false; QTest::newRow("touch") << false << false << true << false; QTest::newRow("keyboard/pointer") << true << true << false << false; QTest::newRow("keyboard/touch") << true << false << true << false; QTest::newRow("pointer/touch") << false << true << true << false; QTest::newRow("keyboard/pointer/touch") << true << true << true << false; QTest::newRow("tabletTool") << false << false << false << true; } void TestLibinputDevice::testDeviceType() { // this test verifies that the device type is recognized correctly QFETCH(bool, keyboard); QFETCH(bool, pointer); QFETCH(bool, touch); QFETCH(bool, tabletTool); libinput_device device; device.keyboard = keyboard; device.pointer = pointer; device.touch = touch; device.tabletTool = tabletTool; Device d(&device); QCOMPARE(d.isKeyboard(), keyboard); QCOMPARE(d.property("keyboard").toBool(), keyboard); QCOMPARE(d.isPointer(), pointer); QCOMPARE(d.property("pointer").toBool(), pointer); QCOMPARE(d.isTouch(), touch); QCOMPARE(d.property("touch").toBool(), touch); QCOMPARE(d.isTabletPad(), false); QCOMPARE(d.property("tabletPad").toBool(), false); QCOMPARE(d.isTabletTool(), tabletTool); QCOMPARE(d.property("tabletTool").toBool(), tabletTool); QCOMPARE(d.device(), &device); } void TestLibinputDevice::testGestureSupport_data() { QTest::addColumn("supported"); QTest::newRow("supported") << true; QTest::newRow("not supported") << false; } void TestLibinputDevice::testGestureSupport() { // this test verifies whether the Device supports gestures QFETCH(bool, supported); libinput_device device; device.gestureSupported = supported; Device d(&device); QCOMPARE(d.supportsGesture(), supported); QCOMPARE(d.property("gestureSupport").toBool(), supported); } void TestLibinputDevice::testNames_data() { QTest::addColumn("name"); QTest::addColumn("sysName"); QTest::addColumn("outputName"); QTest::newRow("empty") << QByteArray() << QByteArrayLiteral("event1") << QByteArray(); QTest::newRow("set") << QByteArrayLiteral("awesome test device") << QByteArrayLiteral("event0") << QByteArrayLiteral("hdmi0"); } void TestLibinputDevice::testNames() { // this test verifies the various name properties of the Device QFETCH(QByteArray, name); QFETCH(QByteArray, sysName); QFETCH(QByteArray, outputName); libinput_device device; device.name = name; device.sysName = sysName; device.outputName = outputName; Device d(&device); QCOMPARE(d.name().toUtf8(), name); QCOMPARE(d.property("name").toString().toUtf8(), name); QCOMPARE(d.sysName().toUtf8(), sysName); QCOMPARE(d.property("sysName").toString().toUtf8(), sysName); QCOMPARE(d.outputName().toUtf8(), outputName); QCOMPARE(d.property("outputName").toString().toUtf8(), outputName); } void TestLibinputDevice::testProduct() { // this test verifies the product property libinput_device device; device.product = 100u; Device d(&device); QCOMPARE(d.product(), 100u); QCOMPARE(d.property("product").toUInt(), 100u); } void TestLibinputDevice::testVendor() { // this test verifies the vendor property libinput_device device; device.vendor = 200u; Device d(&device); QCOMPARE(d.vendor(), 200u); QCOMPARE(d.property("vendor").toUInt(), 200u); } void TestLibinputDevice::testTapFingerCount() { // this test verifies the tap finger count property libinput_device device; device.tapFingerCount = 3; Device d(&device); QCOMPARE(d.tapFingerCount(), 3); QCOMPARE(d.property("tapFingerCount").toInt(), 3); } void TestLibinputDevice::testSize_data() { QTest::addColumn("setSize"); QTest::addColumn("returnValue"); QTest::addColumn("expectedSize"); QTest::newRow("10/20") << QSizeF(10.5, 20.2) << 0 << QSizeF(10.5, 20.2); QTest::newRow("failure") << QSizeF(10, 20) << 1 << QSizeF(); } void TestLibinputDevice::testSize() { // this test verifies that getting the size works correctly including failures QFETCH(QSizeF, setSize); QFETCH(int, returnValue); libinput_device device; device.deviceSize = setSize; device.deviceSizeReturnValue = returnValue; Device d(&device); QTEST(d.size(), "expectedSize"); QTEST(d.property("size").toSizeF(), "expectedSize"); } void TestLibinputDevice::testLeftHandedEnabledByDefault_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testLeftHandedEnabledByDefault() { QFETCH(bool, enabled); libinput_device device; device.leftHandedEnabledByDefault = enabled; Device d(&device); QCOMPARE(d.leftHandedEnabledByDefault(), enabled); QCOMPARE(d.property("leftHandedEnabledByDefault").toBool(), enabled); } void TestLibinputDevice::testTapEnabledByDefault_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testTapEnabledByDefault() { QFETCH(bool, enabled); libinput_device device; device.tapEnabledByDefault = enabled; Device d(&device); QCOMPARE(d.tapToClickEnabledByDefault(), enabled); QCOMPARE(d.property("tapToClickEnabledByDefault").toBool(), enabled); } void TestLibinputDevice::testMiddleEmulationEnabledByDefault_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testMiddleEmulationEnabledByDefault() { QFETCH(bool, enabled); libinput_device device; device.middleEmulationEnabledByDefault = enabled; Device d(&device); QCOMPARE(d.middleEmulationEnabledByDefault(), enabled); QCOMPARE(d.property("middleEmulationEnabledByDefault").toBool(), enabled); } void TestLibinputDevice::testNaturalScrollEnabledByDefault_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testNaturalScrollEnabledByDefault() { QFETCH(bool, enabled); libinput_device device; device.naturalScrollEnabledByDefault = enabled; Device d(&device); QCOMPARE(d.naturalScrollEnabledByDefault(), enabled); QCOMPARE(d.property("naturalScrollEnabledByDefault").toBool(), enabled); } void TestLibinputDevice::testScrollTwoFingerEnabledByDefault_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testScrollTwoFingerEnabledByDefault() { QFETCH(bool, enabled); libinput_device device; device.defaultScrollMethod = enabled ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; Device d(&device); QCOMPARE(d.scrollTwoFingerEnabledByDefault(), enabled); QCOMPARE(d.property("scrollTwoFingerEnabledByDefault").toBool(), enabled); } void TestLibinputDevice::testScrollEdgeEnabledByDefault_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testScrollEdgeEnabledByDefault() { QFETCH(bool, enabled); libinput_device device; device.defaultScrollMethod = enabled ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; Device d(&device); QCOMPARE(d.scrollEdgeEnabledByDefault(), enabled); QCOMPARE(d.property("scrollEdgeEnabledByDefault").toBool(), enabled); } void TestLibinputDevice::testScrollOnButtonDownEnabledByDefault_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testScrollOnButtonDownEnabledByDefault() { QFETCH(bool, enabled); libinput_device device; device.defaultScrollMethod = enabled ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; Device d(&device); QCOMPARE(d.scrollOnButtonDownEnabledByDefault(), enabled); QCOMPARE(d.property("scrollOnButtonDownEnabledByDefault").toBool(), enabled); } void TestLibinputDevice::testDefaultScrollButton_data() { QTest::addColumn("button"); QTest::newRow("0") << 0u; QTest::newRow("BTN_LEFT") << quint32(BTN_LEFT); QTest::newRow("BTN_RIGHT") << quint32(BTN_RIGHT); QTest::newRow("BTN_MIDDLE") << quint32(BTN_MIDDLE); QTest::newRow("BTN_SIDE") << quint32(BTN_SIDE); QTest::newRow("BTN_EXTRA") << quint32(BTN_EXTRA); QTest::newRow("BTN_FORWARD") << quint32(BTN_FORWARD); QTest::newRow("BTN_BACK") << quint32(BTN_BACK); QTest::newRow("BTN_TASK") << quint32(BTN_TASK); } void TestLibinputDevice::testDefaultScrollButton() { libinput_device device; QFETCH(quint32, button); device.defaultScrollButton = button; Device d(&device); QCOMPARE(d.defaultScrollButton(), button); QCOMPARE(d.property("defaultScrollButton").value(), button); } void TestLibinputDevice::testSupportsDisableWhileTyping_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testSupportsDisableWhileTyping() { QFETCH(bool, enabled); libinput_device device; device.supportsDisableWhileTyping = enabled; Device d(&device); QCOMPARE(d.supportsDisableWhileTyping(), enabled); QCOMPARE(d.property("supportsDisableWhileTyping").toBool(), enabled); } void TestLibinputDevice::testSupportsPointerAcceleration_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testSupportsPointerAcceleration() { QFETCH(bool, enabled); libinput_device device; device.supportsPointerAcceleration = enabled; Device d(&device); QCOMPARE(d.supportsPointerAcceleration(), enabled); QCOMPARE(d.property("supportsPointerAcceleration").toBool(), enabled); } void TestLibinputDevice::testSupportsLeftHanded_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testSupportsLeftHanded() { QFETCH(bool, enabled); libinput_device device; device.supportsLeftHanded = enabled; Device d(&device); QCOMPARE(d.supportsLeftHanded(), enabled); QCOMPARE(d.property("supportsLeftHanded").toBool(), enabled); } void TestLibinputDevice::testSupportsCalibrationMatrix_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testSupportsCalibrationMatrix() { QFETCH(bool, enabled); libinput_device device; device.supportsCalibrationMatrix = enabled; Device d(&device); QCOMPARE(d.supportsCalibrationMatrix(), enabled); QCOMPARE(d.property("supportsCalibrationMatrix").toBool(), enabled); } void TestLibinputDevice::testSupportsDisableEvents_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testSupportsDisableEvents() { QFETCH(bool, enabled); libinput_device device; device.supportsDisableEvents = enabled; Device d(&device); QCOMPARE(d.supportsDisableEvents(), enabled); QCOMPARE(d.property("supportsDisableEvents").toBool(), enabled); } void TestLibinputDevice::testSupportsDisableEventsOnExternalMouse_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testSupportsDisableEventsOnExternalMouse() { QFETCH(bool, enabled); libinput_device device; device.supportsDisableEventsOnExternalMouse = enabled; Device d(&device); QCOMPARE(d.supportsDisableEventsOnExternalMouse(), enabled); QCOMPARE(d.property("supportsDisableEventsOnExternalMouse").toBool(), enabled); } void TestLibinputDevice::testSupportsMiddleEmulation_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testSupportsMiddleEmulation() { QFETCH(bool, enabled); libinput_device device; device.supportsMiddleEmulation = enabled; Device d(&device); QCOMPARE(d.supportsMiddleEmulation(), enabled); QCOMPARE(d.property("supportsMiddleEmulation").toBool(), enabled); } void TestLibinputDevice::testSupportsNaturalScroll_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testSupportsNaturalScroll() { QFETCH(bool, enabled); libinput_device device; device.supportsNaturalScroll = enabled; Device d(&device); QCOMPARE(d.supportsNaturalScroll(), enabled); QCOMPARE(d.property("supportsNaturalScroll").toBool(), enabled); } void TestLibinputDevice::testSupportsScrollTwoFinger_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testSupportsScrollTwoFinger() { QFETCH(bool, enabled); libinput_device device; device.supportedScrollMethods = enabled ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; Device d(&device); QCOMPARE(d.supportsScrollTwoFinger(), enabled); QCOMPARE(d.property("supportsScrollTwoFinger").toBool(), enabled); } void TestLibinputDevice::testSupportsScrollEdge_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testSupportsScrollEdge() { QFETCH(bool, enabled); libinput_device device; device.supportedScrollMethods = enabled ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; Device d(&device); QCOMPARE(d.supportsScrollEdge(), enabled); QCOMPARE(d.property("supportsScrollEdge").toBool(), enabled); } void TestLibinputDevice::testSupportsScrollOnButtonDown_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testSupportsScrollOnButtonDown() { QFETCH(bool, enabled); libinput_device device; device.supportedScrollMethods = enabled ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; Device d(&device); QCOMPARE(d.supportsScrollOnButtonDown(), enabled); QCOMPARE(d.property("supportsScrollOnButtonDown").toBool(), enabled); } void TestLibinputDevice::testPointerAcceleration_data() { QTest::addColumn("supported"); QTest::addColumn("setShouldFail"); QTest::addColumn("accel"); QTest::addColumn("setAccel"); QTest::addColumn("expectedAccel"); QTest::addColumn("expectedChanged"); QTest::newRow("-1 -> 2.0") << true << false << -1.0 << 2.0 << 1.0 << true; QTest::newRow("0 -> -1.0") << true << false << 0.0 << -1.0 << -1.0 << true; QTest::newRow("1 -> 1") << true << false << 1.0 << 1.0 << 1.0 << false; QTest::newRow("unsupported") << false << false << 0.0 << 1.0 << 0.0 << false; QTest::newRow("set fails") << true << true << -1.0 << 1.0 << -1.0 << false; } void TestLibinputDevice::testPointerAcceleration() { QFETCH(bool, supported); QFETCH(bool, setShouldFail); QFETCH(qreal, accel); libinput_device device; device.supportsPointerAcceleration = supported; device.pointerAcceleration = accel; device.setPointerAccelerationReturnValue = setShouldFail; Device d(&device); QCOMPARE(d.pointerAcceleration(), accel); QCOMPARE(d.property("pointerAcceleration").toReal(), accel); QSignalSpy pointerAccelChangedSpy(&d, &Device::pointerAccelerationChanged); QVERIFY(pointerAccelChangedSpy.isValid()); QFETCH(qreal, setAccel); d.setPointerAcceleration(setAccel); QTEST(d.pointerAcceleration(), "expectedAccel"); QTEST(!pointerAccelChangedSpy.isEmpty(), "expectedChanged"); } void TestLibinputDevice::testLeftHanded_data() { QTest::addColumn("supported"); QTest::addColumn("setShouldFail"); QTest::addColumn("initValue"); QTest::addColumn("setValue"); QTest::addColumn("expectedValue"); QTest::newRow("unsupported/true") << false << false << true << false << false; QTest::newRow("unsupported/false") << false << false << false << true << false; QTest::newRow("true -> false") << true << false << true << false << false; QTest::newRow("false -> true") << true << false << false << true << true; QTest::newRow("set fails") << true << true << true << false << true; QTest::newRow("true -> true") << true << false << true << true << true; QTest::newRow("false -> false") << true << false << false << false << false; } void TestLibinputDevice::testLeftHanded() { QFETCH(bool, supported); QFETCH(bool, setShouldFail); QFETCH(bool, initValue); libinput_device device; device.supportsLeftHanded = supported; device.leftHanded = initValue; device.setLeftHandedReturnValue = setShouldFail; Device d(&device); QCOMPARE(d.isLeftHanded(), supported && initValue); QCOMPARE(d.property("leftHanded").toBool(), supported && initValue); QSignalSpy leftHandedChangedSpy(&d, &Device::leftHandedChanged); QVERIFY(leftHandedChangedSpy.isValid()); QFETCH(bool, setValue); d.setLeftHanded(setValue); QFETCH(bool, expectedValue); QCOMPARE(d.isLeftHanded(), expectedValue); QCOMPARE(leftHandedChangedSpy.isEmpty(), (supported && initValue) == expectedValue); } void TestLibinputDevice::testSupportedButtons_data() { QTest::addColumn("isPointer"); QTest::addColumn("setButtons"); QTest::addColumn("expectedButtons"); QTest::newRow("left") << true << Qt::MouseButtons(Qt::LeftButton) << Qt::MouseButtons(Qt::LeftButton); QTest::newRow("right") << true << Qt::MouseButtons(Qt::RightButton) << Qt::MouseButtons(Qt::RightButton); QTest::newRow("middle") << true << Qt::MouseButtons(Qt::MiddleButton) << Qt::MouseButtons(Qt::MiddleButton); QTest::newRow("extra1") << true << Qt::MouseButtons(Qt::ExtraButton1) << Qt::MouseButtons(Qt::ExtraButton1); QTest::newRow("extra2") << true << Qt::MouseButtons(Qt::ExtraButton2) << Qt::MouseButtons(Qt::ExtraButton2); QTest::newRow("back") << true << Qt::MouseButtons(Qt::BackButton) << Qt::MouseButtons(Qt::BackButton); QTest::newRow("forward") << true << Qt::MouseButtons(Qt::ForwardButton) << Qt::MouseButtons(Qt::ForwardButton); QTest::newRow("task") << true << Qt::MouseButtons(Qt::TaskButton) << Qt::MouseButtons(Qt::TaskButton); QTest::newRow("no pointer/left") << false << Qt::MouseButtons(Qt::LeftButton) << Qt::MouseButtons(); QTest::newRow("no pointer/right") << false << Qt::MouseButtons(Qt::RightButton) << Qt::MouseButtons(); QTest::newRow("no pointer/middle") << false << Qt::MouseButtons(Qt::MiddleButton) << Qt::MouseButtons(); QTest::newRow("no pointer/extra1") << false << Qt::MouseButtons(Qt::ExtraButton1) << Qt::MouseButtons(); QTest::newRow("no pointer/extra2") << false << Qt::MouseButtons(Qt::ExtraButton2) << Qt::MouseButtons(); QTest::newRow("no pointer/back") << false << Qt::MouseButtons(Qt::BackButton) << Qt::MouseButtons(); QTest::newRow("no pointer/forward") << false << Qt::MouseButtons(Qt::ForwardButton) << Qt::MouseButtons(); QTest::newRow("no pointer/task") << false << Qt::MouseButtons(Qt::TaskButton) << Qt::MouseButtons(); QTest::newRow("all") << true << Qt::MouseButtons(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton | Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::BackButton | Qt::ForwardButton | Qt::TaskButton) << Qt::MouseButtons(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton | Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::BackButton | Qt::ForwardButton | Qt::TaskButton); } void TestLibinputDevice::testSupportedButtons() { libinput_device device; QFETCH(bool, isPointer); device.pointer = isPointer; QFETCH(Qt::MouseButtons, setButtons); device.supportedButtons = setButtons; Device d(&device); QCOMPARE(d.isPointer(), isPointer); QTEST(d.supportedButtons(), "expectedButtons"); } void TestLibinputDevice::testAlphaNumericKeyboard_data() { QTest::addColumn>("supportedKeys"); QTest::addColumn("isAlpha"); QVector keys; for (int i = KEY_1; i <= KEY_0; i++) { keys << i; QByteArray row = QByteArrayLiteral("number"); row.append(QByteArray::number(i)); QTest::newRow(row.constData()) << keys << false; } for (int i = KEY_Q; i <= KEY_P; i++) { keys << i; QByteArray row = QByteArrayLiteral("alpha"); row.append(QByteArray::number(i)); QTest::newRow(row.constData()) << keys << false; } for (int i = KEY_A; i <= KEY_L; i++) { keys << i; QByteArray row = QByteArrayLiteral("alpha"); row.append(QByteArray::number(i)); QTest::newRow(row.constData()) << keys << false; } for (int i = KEY_Z; i < KEY_M; i++) { keys << i; QByteArray row = QByteArrayLiteral("alpha"); row.append(QByteArray::number(i)); QTest::newRow(row.constData()) << keys << false; } // adding a different key should not result in it becoming alphanumeric keyboard keys << KEY_SEMICOLON; QTest::newRow("semicolon") << keys << false; // last but not least the M which should turn everything on keys << KEY_M; QTest::newRow("alphanumeric") << keys << true; } void TestLibinputDevice::testAlphaNumericKeyboard() { QFETCH(QVector, supportedKeys); libinput_device device; device.keyboard = true; device.keys = supportedKeys; Device d(&device); QCOMPARE(d.isKeyboard(), true); QTEST(d.isAlphaNumericKeyboard(), "isAlpha"); } void TestLibinputDevice::testEnabled_data() { QTest::addColumn("supported"); QTest::addColumn("setShouldFail"); QTest::addColumn("initValue"); QTest::addColumn("setValue"); QTest::addColumn("expectedValue"); QTest::newRow("unsupported/true") << false << false << true << false << true; QTest::newRow("unsupported/false") << false << false << false << true << true; QTest::newRow("true -> false") << true << false << true << false << false; QTest::newRow("false -> true") << true << false << false << true << true; QTest::newRow("set fails") << true << true << true << false << true; QTest::newRow("true -> true") << true << false << true << true << true; QTest::newRow("false -> false") << true << false << false << false << false; } void TestLibinputDevice::testEnabled() { libinput_device device; QFETCH(bool, supported); QFETCH(bool, setShouldFail); QFETCH(bool, initValue); device.supportsDisableEvents = supported; device.enabled = initValue; device.setEnableModeReturnValue = setShouldFail; Device d(&device); QCOMPARE(d.isEnabled(), !supported || initValue); QCOMPARE(d.property("enabled").toBool(), !supported || initValue); QSignalSpy enabledChangedSpy(&d, &Device::enabledChanged); QVERIFY(enabledChangedSpy.isValid()); QFETCH(bool, setValue); d.setEnabled(setValue); QFETCH(bool, expectedValue); QCOMPARE(d.isEnabled(), expectedValue); } void TestLibinputDevice::testTapToClick_data() { QTest::addColumn("fingerCount"); QTest::addColumn("initValue"); QTest::addColumn("setValue"); QTest::addColumn("setShouldFail"); QTest::addColumn("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); } void TestLibinputDevice::testTapAndDragEnabledByDefault_data() { QTest::addColumn("enabled"); QTest::newRow("enabled") << true; QTest::newRow("disabled") << false; } void TestLibinputDevice::testTapAndDragEnabledByDefault() { QFETCH(bool, enabled); libinput_device device; device.tapAndDragEnabledByDefault = enabled; Device d(&device); QCOMPARE(d.tapAndDragEnabledByDefault(), enabled); QCOMPARE(d.property("tapAndDragEnabledByDefault").toBool(), enabled); } void TestLibinputDevice::testTapAndDrag_data() { QTest::addColumn("initValue"); QTest::addColumn("setValue"); QTest::addColumn("setShouldFail"); QTest::addColumn("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::testTapAndDrag() { libinput_device device; QFETCH(bool, initValue); QFETCH(bool, setShouldFail); device.tapAndDrag = initValue; device.setTapAndDragReturnValue = setShouldFail; Device d(&device); QCOMPARE(d.isTapAndDrag(), initValue); QCOMPARE(d.property("tapAndDrag").toBool(), initValue); QSignalSpy tapAndDragChangedSpy(&d, &Device::tapAndDragChanged); QVERIFY(tapAndDragChangedSpy.isValid()); QFETCH(bool, setValue); d.setTapAndDrag(setValue); QFETCH(bool, expectedValue); QCOMPARE(d.isTapAndDrag(), expectedValue); QCOMPARE(tapAndDragChangedSpy.isEmpty(), initValue == expectedValue); } void TestLibinputDevice::testTapDragLockEnabledByDefault_data() { QTest::addColumn("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("initValue"); QTest::addColumn("setValue"); QTest::addColumn("setShouldFail"); QTest::addColumn("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); } void TestLibinputDevice::testMiddleEmulation_data() { QTest::addColumn("initValue"); QTest::addColumn("setValue"); QTest::addColumn("setShouldFail"); QTest::addColumn("expectedValue"); QTest::addColumn("supportsMiddleButton"); 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("false -> true, unsupported") << false << true << true << false << false; } void TestLibinputDevice::testMiddleEmulation() { libinput_device device; QFETCH(bool, initValue); QFETCH(bool, setShouldFail); QFETCH(bool, supportsMiddleButton); device.supportsMiddleEmulation = supportsMiddleButton; device.middleEmulation = initValue; device.setMiddleEmulationReturnValue = setShouldFail; Device d(&device); QCOMPARE(d.isMiddleEmulation(), initValue); QCOMPARE(d.property("middleEmulation").toBool(), initValue); QSignalSpy middleEmulationChangedSpy(&d, &Device::middleEmulationChanged); QVERIFY(middleEmulationChangedSpy.isValid()); QFETCH(bool, setValue); d.setMiddleEmulation(setValue); QFETCH(bool, expectedValue); QCOMPARE(d.isMiddleEmulation(), expectedValue); QCOMPARE(d.property("middleEmulation").toBool(), expectedValue); QCOMPARE(middleEmulationChangedSpy.isEmpty(), initValue == expectedValue); } void TestLibinputDevice::testNaturalScroll_data() { QTest::addColumn("initValue"); QTest::addColumn("setValue"); QTest::addColumn("setShouldFail"); QTest::addColumn("expectedValue"); QTest::addColumn("supportsNaturalScroll"); 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("false -> true, unsupported") << false << true << true << false << false; } void TestLibinputDevice::testNaturalScroll() { libinput_device device; QFETCH(bool, initValue); QFETCH(bool, setShouldFail); QFETCH(bool, supportsNaturalScroll); device.supportsNaturalScroll = supportsNaturalScroll; device.naturalScroll = initValue; device.setNaturalScrollReturnValue = setShouldFail; Device d(&device); QCOMPARE(d.isNaturalScroll(), initValue); QCOMPARE(d.property("naturalScroll").toBool(), initValue); QSignalSpy naturalScrollChangedSpy(&d, &Device::naturalScrollChanged); QVERIFY(naturalScrollChangedSpy.isValid()); QFETCH(bool, setValue); d.setNaturalScroll(setValue); QFETCH(bool, expectedValue); QCOMPARE(d.isNaturalScroll(), expectedValue); QCOMPARE(d.property("naturalScroll").toBool(), expectedValue); QCOMPARE(naturalScrollChangedSpy.isEmpty(), initValue == expectedValue); } void TestLibinputDevice::testScrollTwoFinger_data() { QTest::addColumn("initValue"); QTest::addColumn("setValue"); QTest::addColumn("setShouldFail"); QTest::addColumn("expectedValue"); QTest::addColumn("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("false -> true, unsupported") << false << true << true << false << false; } void TestLibinputDevice::testScrollTwoFinger() { libinput_device device; QFETCH(bool, initValue); 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.setScrollMethodReturnValue = setShouldFail; Device d(&device); QCOMPARE(d.isScrollTwoFinger(), initValue); QCOMPARE(d.property("scrollTwoFinger").toBool(), initValue); QSignalSpy scrollMethodChangedSpy(&d, &Device::scrollMethodChanged); QVERIFY(scrollMethodChangedSpy.isValid()); QFETCH(bool, setValue); d.setScrollTwoFinger(setValue); QFETCH(bool, expectedValue); QCOMPARE(d.isScrollTwoFinger(), expectedValue); QCOMPARE(d.property("scrollTwoFinger").toBool(), expectedValue); QCOMPARE(scrollMethodChangedSpy.isEmpty(), initValue == expectedValue); } void TestLibinputDevice::testScrollEdge_data() { QTest::addColumn("initValue"); QTest::addColumn("setValue"); QTest::addColumn("setShouldFail"); QTest::addColumn("expectedValue"); QTest::addColumn("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("false -> true, unsupported") << false << true << true << false << false; } void TestLibinputDevice::testScrollEdge() { libinput_device device; QFETCH(bool, initValue); 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.setScrollMethodReturnValue = setShouldFail; Device d(&device); QCOMPARE(d.isScrollEdge(), initValue); QCOMPARE(d.property("scrollEdge").toBool(), initValue); QSignalSpy scrollMethodChangedSpy(&d, &Device::scrollMethodChanged); QVERIFY(scrollMethodChangedSpy.isValid()); QFETCH(bool, setValue); d.setScrollEdge(setValue); QFETCH(bool, expectedValue); QCOMPARE(d.isScrollEdge(), expectedValue); QCOMPARE(d.property("scrollEdge").toBool(), expectedValue); QCOMPARE(scrollMethodChangedSpy.isEmpty(), initValue == expectedValue); } void TestLibinputDevice::testScrollButtonDown_data() { QTest::addColumn("initValue"); QTest::addColumn("setValue"); QTest::addColumn("setShouldFail"); QTest::addColumn("expectedValue"); QTest::addColumn("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("false -> true, unsupported") << false << true << true << false << false; } void TestLibinputDevice::testScrollButtonDown() { libinput_device device; QFETCH(bool, initValue); 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.setScrollMethodReturnValue = setShouldFail; Device d(&device); QCOMPARE(d.isScrollOnButtonDown(), initValue); QCOMPARE(d.property("scrollOnButtonDown").toBool(), initValue); QSignalSpy scrollMethodChangedSpy(&d, &Device::scrollMethodChanged); QVERIFY(scrollMethodChangedSpy.isValid()); QFETCH(bool, setValue); d.setScrollOnButtonDown(setValue); QFETCH(bool, expectedValue); QCOMPARE(d.isScrollOnButtonDown(), expectedValue); QCOMPARE(d.property("scrollOnButtonDown").toBool(), expectedValue); QCOMPARE(scrollMethodChangedSpy.isEmpty(), initValue == expectedValue); } void TestLibinputDevice::testScrollButton_data() { QTest::addColumn("initValue"); QTest::addColumn("setValue"); QTest::addColumn("expectedValue"); QTest::addColumn("setShouldFail"); QTest::addColumn("scrollOnButton"); QTest::newRow("BTN_LEFT -> BTN_RIGHT") << quint32(BTN_LEFT) << quint32(BTN_RIGHT) << quint32(BTN_RIGHT) << false << true; QTest::newRow("BTN_LEFT -> BTN_LEFT") << quint32(BTN_LEFT) << quint32(BTN_LEFT) << quint32(BTN_LEFT) << false << true; QTest::newRow("set should fail") << quint32(BTN_LEFT) << quint32(BTN_RIGHT) << quint32(BTN_LEFT) << true << true; QTest::newRow("not scroll on button") << quint32(BTN_LEFT) << quint32(BTN_RIGHT) << quint32(BTN_LEFT) << false << false; } void TestLibinputDevice::testScrollButton() { libinput_device device; QFETCH(quint32, initValue); QFETCH(bool, setShouldFail); QFETCH(bool, scrollOnButton); device.scrollButton = initValue; device.supportedScrollMethods = scrollOnButton ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; device.setScrollButtonReturnValue = setShouldFail; Device d(&device); QCOMPARE(d.scrollButton(), initValue); QCOMPARE(d.property("scrollButton").value(), initValue); QSignalSpy scrollButtonChangedSpy(&d, &Device::scrollButtonChanged); QVERIFY(scrollButtonChangedSpy.isValid()); QFETCH(quint32, setValue); d.setScrollButton(setValue); QFETCH(quint32, expectedValue); QCOMPARE(d.scrollButton(), expectedValue); QCOMPARE(d.property("scrollButton").value(), expectedValue); QCOMPARE(scrollButtonChangedSpy.isEmpty(), initValue == expectedValue); } void TestLibinputDevice::testLoadEnabled_data() { QTest::addColumn("initValue"); QTest::addColumn("configValue"); QTest::newRow("false -> true") << false << true; QTest::newRow("true -> false") << true << false; QTest::newRow("true -> true") << true << true; QTest::newRow("false -> false") << false << false; } void TestLibinputDevice::testLoadEnabled() { auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); KConfigGroup inputConfig(config, QStringLiteral("Test")); QFETCH(bool, configValue); QFETCH(bool, initValue); inputConfig.writeEntry("Enabled", configValue); libinput_device device; device.supportsDisableEvents = true; device.enabled = initValue; device.setEnableModeReturnValue = false; Device d(&device); QCOMPARE(d.isEnabled(), initValue); // no config group set, should not change d.loadConfiguration(); QCOMPARE(d.isEnabled(), initValue); // set the group d.setConfig(inputConfig); d.loadConfiguration(); QCOMPARE(d.isEnabled(), configValue); // and try to store if (configValue != initValue) { d.setEnabled(initValue); QCOMPARE(inputConfig.readEntry("Enabled", configValue), initValue); } } void TestLibinputDevice::testLoadTapToClick_data() { QTest::addColumn("initValue"); QTest::addColumn("configValue"); QTest::newRow("false -> true") << false << true; QTest::newRow("true -> false") << true << false; QTest::newRow("true -> true") << true << true; QTest::newRow("false -> false") << false << false; } void TestLibinputDevice::testLoadTapToClick() { auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); KConfigGroup inputConfig(config, QStringLiteral("Test")); QFETCH(bool, configValue); QFETCH(bool, initValue); inputConfig.writeEntry("TapToClick", configValue); libinput_device device; device.tapFingerCount = 2; device.tapToClick = initValue; device.setTapToClickReturnValue = false; Device d(&device); QCOMPARE(d.isTapToClick(), initValue); // no config group set, should not change d.loadConfiguration(); QCOMPARE(d.isTapToClick(), initValue); // set the group d.setConfig(inputConfig); d.loadConfiguration(); QCOMPARE(d.isTapToClick(), configValue); // and try to store if (configValue != initValue) { d.setTapToClick(initValue); QCOMPARE(inputConfig.readEntry("TapToClick", configValue), initValue); } } void TestLibinputDevice::testLoadTapAndDrag_data() { QTest::addColumn("initValue"); QTest::addColumn("configValue"); QTest::newRow("false -> true") << false << true; QTest::newRow("true -> false") << true << false; QTest::newRow("true -> true") << true << true; QTest::newRow("false -> false") << false << false; } void TestLibinputDevice::testLoadTapAndDrag() { auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); KConfigGroup inputConfig(config, QStringLiteral("Test")); QFETCH(bool, configValue); QFETCH(bool, initValue); inputConfig.writeEntry("TapAndDrag", configValue); libinput_device device; device.tapAndDrag = initValue; device.setTapAndDragReturnValue = false; Device d(&device); QCOMPARE(d.isTapAndDrag(), initValue); // no config group set, should not change d.loadConfiguration(); QCOMPARE(d.isTapAndDrag(), initValue); // set the group d.setConfig(inputConfig); d.loadConfiguration(); QCOMPARE(d.isTapAndDrag(), configValue); // and try to store if (configValue != initValue) { d.setTapAndDrag(initValue); QCOMPARE(inputConfig.readEntry("TapAndDrag", configValue), initValue); } } void TestLibinputDevice::testLoadTapDragLock_data() { QTest::addColumn("initValue"); QTest::addColumn("configValue"); QTest::newRow("false -> true") << false << true; QTest::newRow("true -> false") << true << false; QTest::newRow("true -> true") << true << true; QTest::newRow("false -> false") << false << false; } void TestLibinputDevice::testLoadTapDragLock() { auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); KConfigGroup inputConfig(config, QStringLiteral("Test")); QFETCH(bool, configValue); QFETCH(bool, initValue); inputConfig.writeEntry("TapDragLock", configValue); libinput_device device; device.tapDragLock = initValue; device.setTapDragLockReturnValue = false; Device d(&device); QCOMPARE(d.isTapDragLock(), initValue); // no config group set, should not change d.loadConfiguration(); QCOMPARE(d.isTapDragLock(), initValue); // set the group d.setConfig(inputConfig); d.loadConfiguration(); QCOMPARE(d.isTapDragLock(), configValue); // and try to store if (configValue != initValue) { d.setTapDragLock(initValue); QCOMPARE(inputConfig.readEntry("TapDragLock", configValue), initValue); } } void TestLibinputDevice::testLoadMiddleButtonEmulation_data() { QTest::addColumn("initValue"); QTest::addColumn("configValue"); QTest::newRow("false -> true") << false << true; QTest::newRow("true -> false") << true << false; QTest::newRow("true -> true") << true << true; QTest::newRow("false -> false") << false << false; } void TestLibinputDevice::testLoadMiddleButtonEmulation() { auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); KConfigGroup inputConfig(config, QStringLiteral("Test")); QFETCH(bool, configValue); QFETCH(bool, initValue); inputConfig.writeEntry("MiddleButtonEmulation", configValue); libinput_device device; device.supportsMiddleEmulation = true; device.middleEmulation = initValue; device.setMiddleEmulationReturnValue = false; Device d(&device); QCOMPARE(d.isMiddleEmulation(), initValue); // no config group set, should not change d.loadConfiguration(); QCOMPARE(d.isMiddleEmulation(), initValue); // set the group d.setConfig(inputConfig); d.loadConfiguration(); QCOMPARE(d.isMiddleEmulation(), configValue); // and try to store if (configValue != initValue) { d.setMiddleEmulation(initValue); QCOMPARE(inputConfig.readEntry("MiddleButtonEmulation", configValue), initValue); } } void TestLibinputDevice::testLoadNaturalScroll_data() { QTest::addColumn("initValue"); QTest::addColumn("configValue"); QTest::newRow("false -> true") << false << true; QTest::newRow("true -> false") << true << false; QTest::newRow("true -> true") << true << true; QTest::newRow("false -> false") << false << false; } void TestLibinputDevice::testLoadNaturalScroll() { auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); KConfigGroup inputConfig(config, QStringLiteral("Test")); QFETCH(bool, configValue); QFETCH(bool, initValue); inputConfig.writeEntry("NaturalScroll", configValue); libinput_device device; device.supportsNaturalScroll = true; device.naturalScroll = initValue; device.setNaturalScrollReturnValue = false; Device d(&device); QCOMPARE(d.isNaturalScroll(), initValue); // no config group set, should not change d.loadConfiguration(); QCOMPARE(d.isNaturalScroll(), initValue); // set the group d.setConfig(inputConfig); d.loadConfiguration(); QCOMPARE(d.isNaturalScroll(), configValue); // and try to store if (configValue != initValue) { d.setNaturalScroll(initValue); QCOMPARE(inputConfig.readEntry("NaturalScroll", configValue), initValue); } } -void TestLibinputDevice::testLoadScrollTwoFinger_data() +void TestLibinputDevice::testLoadScrollMethod_data() { - QTest::addColumn("initValue"); - QTest::addColumn("configValue"); - - QTest::newRow("false -> true") << false << true; - QTest::newRow("true -> false") << true << false; - QTest::newRow("true -> true") << true << true; - QTest::newRow("false -> false") << false << false; -} - -void TestLibinputDevice::testLoadScrollTwoFinger() -{ - auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); - KConfigGroup inputConfig(config, QStringLiteral("Test")); - QFETCH(bool, configValue); - QFETCH(bool, initValue); - inputConfig.writeEntry("ScrollTwoFinger", configValue); - - libinput_device device; - device.supportedScrollMethods = LIBINPUT_CONFIG_SCROLL_2FG; - device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; - device.setScrollMethodReturnValue = false; - - Device d(&device); - QCOMPARE(d.isScrollTwoFinger(), initValue); - // no config group set, should not change - d.loadConfiguration(); - QCOMPARE(d.isScrollTwoFinger(), initValue); - - // set the group - d.setConfig(inputConfig); - d.loadConfiguration(); - QCOMPARE(d.isScrollTwoFinger(), configValue); - - // and try to store - if (configValue != initValue) { - d.setScrollTwoFinger(initValue); - QCOMPARE(inputConfig.readEntry("ScrollTwoFinger", configValue), initValue); - } -} - -void TestLibinputDevice::testLoadScrollEdge_data() -{ - QTest::addColumn("initValue"); - QTest::addColumn("configValue"); + QTest::addColumn("initValue"); + QTest::addColumn("initValuePropNameString"); + QTest::addColumn("configValue"); + QTest::addColumn("configValuePropNameString"); - QTest::newRow("false -> true") << false << true; - QTest::newRow("true -> false") << true << false; - QTest::newRow("true -> true") << true << true; - QTest::newRow("false -> false") << false << false; + QTest::newRow("scrollTwoFinger -> scrollEdge") << (quint32) LIBINPUT_CONFIG_SCROLL_2FG << "scrollTwoFinger" << (quint32) LIBINPUT_CONFIG_SCROLL_EDGE << "scrollEdge"; + QTest::newRow("scrollOnButtonDown -> scrollTwoFinger") << (quint32) LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN << "scrollOnButtonDown" << (quint32) LIBINPUT_CONFIG_SCROLL_2FG << "scrollTwoFinger"; + QTest::newRow("scrollEdge -> scrollEdge") << (quint32) LIBINPUT_CONFIG_SCROLL_EDGE << "scrollEdge" << (quint32) LIBINPUT_CONFIG_SCROLL_EDGE << "scrollEdge"; } -void TestLibinputDevice::testLoadScrollEdge() +void TestLibinputDevice::testLoadScrollMethod() { auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); KConfigGroup inputConfig(config, QStringLiteral("Test")); - QFETCH(bool, configValue); - QFETCH(bool, initValue); - inputConfig.writeEntry("ScrollEdge", configValue); - - libinput_device device; - device.supportedScrollMethods = LIBINPUT_CONFIG_SCROLL_EDGE; - device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; - device.setScrollMethodReturnValue = false; - - Device d(&device); - QCOMPARE(d.isScrollEdge(), initValue); - // no config group set, should not change - d.loadConfiguration(); - QCOMPARE(d.isScrollEdge(), initValue); - - // set the group - d.setConfig(inputConfig); - d.loadConfiguration(); - QCOMPARE(d.isScrollEdge(), configValue); - - // and try to store - if (configValue != initValue) { - d.setScrollEdge(initValue); - QCOMPARE(inputConfig.readEntry("ScrollEdge", configValue), initValue); - } -} + QFETCH(quint32, initValue); + QFETCH(quint32, configValue); + QFETCH(QString, initValuePropNameString); + QFETCH(QString, configValuePropNameString); -void TestLibinputDevice::testLoadScrollOnButton_data() -{ - QTest::addColumn("initValue"); - QTest::addColumn("configValue"); + QByteArray initValuePropName = initValuePropNameString.toLatin1(); + QByteArray configValuePropName = configValuePropNameString.toLatin1(); - QTest::newRow("false -> true") << false << true; - QTest::newRow("true -> false") << true << false; - QTest::newRow("true -> true") << true << true; - QTest::newRow("false -> false") << false << false; -} - -void TestLibinputDevice::testLoadScrollOnButton() -{ - auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); - KConfigGroup inputConfig(config, QStringLiteral("Test")); - QFETCH(bool, configValue); - QFETCH(bool, initValue); - inputConfig.writeEntry("ScrollOnButton", configValue); + inputConfig.writeEntry("ScrollMethod", configValue); libinput_device device; - device.supportedScrollMethods = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; - device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; + device.supportedScrollMethods = LIBINPUT_CONFIG_SCROLL_2FG | LIBINPUT_CONFIG_SCROLL_EDGE | LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; + device.scrollMethod = (libinput_config_scroll_method) initValue; device.setScrollMethodReturnValue = false; Device d(&device); - QCOMPARE(d.isScrollOnButtonDown(), initValue); + QCOMPARE(d.property(initValuePropName).toBool(), true); + QCOMPARE(d.property(configValuePropName).toBool(), initValue == configValue); // no config group set, should not change d.loadConfiguration(); - QCOMPARE(d.isScrollOnButtonDown(), initValue); + QCOMPARE(d.property(initValuePropName).toBool(), true); + QCOMPARE(d.property(configValuePropName).toBool(), initValue == configValue); // set the group d.setConfig(inputConfig); d.loadConfiguration(); - QCOMPARE(d.isScrollOnButtonDown(), configValue); + QCOMPARE(d.property(initValuePropName).toBool(), initValue == configValue); + QCOMPARE(d.property(configValuePropName).toBool(), true); // and try to store if (configValue != initValue) { - d.setScrollOnButtonDown(initValue); - QCOMPARE(inputConfig.readEntry("ScrollOnButton", configValue), initValue); + d.setProperty(initValuePropName, true); + QCOMPARE(inputConfig.readEntry("ScrollMethod", configValue), initValue); } } void TestLibinputDevice::testLoadScrollButton_data() { QTest::addColumn("initValue"); QTest::addColumn("configValue"); QTest::newRow("BTN_LEFT -> BTN_RIGHT") << quint32(BTN_LEFT) << quint32(BTN_RIGHT); QTest::newRow("BTN_LEFT -> BTN_LEFT") << quint32(BTN_LEFT) << quint32(BTN_LEFT); } void TestLibinputDevice::testLoadScrollButton() { auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); KConfigGroup inputConfig(config, QStringLiteral("Test")); QFETCH(quint32, configValue); QFETCH(quint32, initValue); inputConfig.writeEntry("ScrollButton", configValue); libinput_device device; device.supportedScrollMethods = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; device.scrollMethod = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; device.scrollButton = initValue; device.setScrollButtonReturnValue = false; Device d(&device); QCOMPARE(d.isScrollOnButtonDown(), true); QCOMPARE(d.scrollButton(), initValue); // no config group set, should not change d.loadConfiguration(); QCOMPARE(d.isScrollOnButtonDown(), true); QCOMPARE(d.scrollButton(), initValue); // set the group d.setConfig(inputConfig); d.loadConfiguration(); QCOMPARE(d.isScrollOnButtonDown(), true); QCOMPARE(d.scrollButton(), configValue); // and try to store if (configValue != initValue) { d.setScrollButton(initValue); QCOMPARE(inputConfig.readEntry("ScrollButton", configValue), initValue); } } void TestLibinputDevice::testLoadLeftHanded_data() { QTest::addColumn("initValue"); QTest::addColumn("configValue"); QTest::newRow("false -> true") << false << true; QTest::newRow("true -> false") << true << false; QTest::newRow("true -> true") << true << true; QTest::newRow("false -> false") << false << false; } void TestLibinputDevice::testLoadLeftHanded() { auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); KConfigGroup inputConfig(config, QStringLiteral("Test")); QFETCH(bool, configValue); QFETCH(bool, initValue); inputConfig.writeEntry("LeftHanded", configValue); libinput_device device; device.supportsLeftHanded = true; device.leftHanded = initValue; device.setLeftHandedReturnValue = false; Device d(&device); QCOMPARE(d.isLeftHanded(), initValue); // no config group set, should not change d.loadConfiguration(); QCOMPARE(d.isLeftHanded(), initValue); // set the group d.setConfig(inputConfig); d.loadConfiguration(); QCOMPARE(d.isLeftHanded(), configValue); // and try to store if (configValue != initValue) { d.setLeftHanded(initValue); QCOMPARE(inputConfig.readEntry("LeftHanded", configValue), initValue); } } QTEST_GUILESS_MAIN(TestLibinputDevice) #include "device_test.moc" diff --git a/libinput/device.cpp b/libinput/device.cpp index c55da3b83..484be8226 100644 --- a/libinput/device.cpp +++ b/libinput/device.cpp @@ -1,378 +1,353 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2016 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "device.h" #include #include #include -#include - namespace KWin { namespace LibInput { static bool checkAlphaNumericKeyboard(libinput_device *device) { for (uint i = KEY_1; i <= KEY_0; i++) { if (libinput_device_keyboard_has_key(device, i) == 0) { return false; } } for (uint i = KEY_Q; i <= KEY_P; i++) { if (libinput_device_keyboard_has_key(device, i) == 0) { return false; } } for (uint i = KEY_A; i <= KEY_L; i++) { if (libinput_device_keyboard_has_key(device, i) == 0) { return false; } } for (uint i = KEY_Z; i <= KEY_M; i++) { if (libinput_device_keyboard_has_key(device, i) == 0) { return false; } } return true; } QVector Device::s_devices; Device *Device::getDevice(libinput_device *native) { auto it = std::find_if(s_devices.constBegin(), s_devices.constEnd(), [native] (const Device *d) { return d->device() == native; } ); if (it != s_devices.constEnd()) { return *it; } return nullptr; } enum class ConfigKey { Enabled, LeftHanded, TapToClick, TapAndDrag, TapDragLock, MiddleButtonEmulation, NaturalScroll, - ScrollTwoFinger, - ScrollEdge, - ScrollOnButton, + ScrollMethod, ScrollButton }; struct ConfigData { + explicit ConfigData(QByteArray _key, void (Device::*_setter)(bool), bool (Device::*_defaultValue)() const = nullptr) + : key(_key) + { booleanSetter.setter = _setter; booleanSetter.defaultValue = _defaultValue; } + + explicit ConfigData(QByteArray _key, void (Device::*_setter)(quint32), quint32 (Device::*_defaultValue)() const = nullptr) + : key(_key) + { quint32Setter.setter = _setter; quint32Setter.defaultValue = _defaultValue; } + QByteArray key; - struct BooleanSetter { - std::function setter; - std::function defaultValue; + + struct { + void (Device::*setter)(bool) = nullptr; + bool (Device::*defaultValue)() const; } booleanSetter; - struct UintSetter { - std::function setter; - std::function defaultValue; + + struct { + void (Device::*setter)(quint32) = nullptr; + quint32 (Device::*defaultValue)() const; } quint32Setter; }; static const QMap s_configData { - {ConfigKey::Enabled, {QByteArrayLiteral("Enabled"), {&Device::setEnabled, std::function()}, {}}}, - {ConfigKey::LeftHanded, {QByteArrayLiteral("LeftHanded"), {&Device::setLeftHanded, &Device::leftHandedEnabledByDefault}, {}}}, - {ConfigKey::TapToClick, {QByteArrayLiteral("TapToClick"), {&Device::setTapToClick, &Device::tapToClickEnabledByDefault}, {}}}, - {ConfigKey::TapAndDrag, {QByteArrayLiteral("TapAndDrag"), {&Device::setTapAndDrag, &Device::tapAndDragEnabledByDefault}, {}}}, - {ConfigKey::TapDragLock, {QByteArrayLiteral("TapDragLock"), {&Device::setTapDragLock, &Device::tapDragLockEnabledByDefault}, {}}}, - {ConfigKey::MiddleButtonEmulation, {QByteArrayLiteral("MiddleButtonEmulation"), {&Device::setMiddleEmulation, &Device::middleEmulationEnabledByDefault}, {}}}, - {ConfigKey::NaturalScroll, {QByteArrayLiteral("NaturalScroll"), {&Device::setNaturalScroll, &Device::naturalScrollEnabledByDefault}, {}}}, - {ConfigKey::ScrollTwoFinger, {QByteArrayLiteral("ScrollTwoFinger"), {&Device::setScrollTwoFinger, &Device::scrollTwoFingerEnabledByDefault}, {}}}, - {ConfigKey::ScrollEdge, {QByteArrayLiteral("ScrollEdge"), {&Device::setScrollEdge, &Device::scrollEdgeEnabledByDefault}, {}}}, - {ConfigKey::ScrollOnButton, {QByteArrayLiteral("ScrollOnButton"), {&Device::setScrollOnButtonDown, &Device::scrollOnButtonDownEnabledByDefault}, {}}}, - {ConfigKey::ScrollButton, {QByteArrayLiteral("ScrollButton"), {}, {&Device::setScrollButton, &Device::defaultScrollButton}}} + {ConfigKey::Enabled, ConfigData(QByteArrayLiteral("Enabled"), &Device::setEnabled)}, + {ConfigKey::LeftHanded, ConfigData(QByteArrayLiteral("LeftHanded"), &Device::setLeftHanded, &Device::leftHandedEnabledByDefault)}, + {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)}, + {ConfigKey::MiddleButtonEmulation, ConfigData(QByteArrayLiteral("MiddleButtonEmulation"), &Device::setMiddleEmulation, &Device::middleEmulationEnabledByDefault)}, + {ConfigKey::NaturalScroll, ConfigData(QByteArrayLiteral("NaturalScroll"), &Device::setNaturalScroll, &Device::naturalScrollEnabledByDefault)}, + {ConfigKey::ScrollMethod, ConfigData(QByteArrayLiteral("ScrollMethod"), &Device::activateScrollMethodFromInt, &Device::defaultScrollMethodToInt)}, + {ConfigKey::ScrollButton, ConfigData(QByteArrayLiteral("ScrollButton"), &Device::setScrollButton, &Device::defaultScrollButton)} }; Device::Device(libinput_device *device, QObject *parent) : QObject(parent) , m_device(device) , m_keyboard(libinput_device_has_capability(m_device, LIBINPUT_DEVICE_CAP_KEYBOARD)) , m_pointer(libinput_device_has_capability(m_device, LIBINPUT_DEVICE_CAP_POINTER)) , m_touch(libinput_device_has_capability(m_device, LIBINPUT_DEVICE_CAP_TOUCH)) , m_tabletTool(libinput_device_has_capability(m_device, LIBINPUT_DEVICE_CAP_TABLET_TOOL)) #if 0 // next libinput version , m_tabletPad(libinput_device_has_capability(m_device, LIBINPUT_DEVICE_CAP_TABLET_PAD)) #else , m_tabletPad(false) #endif , m_supportsGesture(libinput_device_has_capability(m_device, LIBINPUT_DEVICE_CAP_GESTURE)) , m_name(QString::fromLocal8Bit(libinput_device_get_name(m_device))) , m_sysName(QString::fromLocal8Bit(libinput_device_get_sysname(m_device))) , m_outputName(QString::fromLocal8Bit(libinput_device_get_output_name(m_device))) , m_product(libinput_device_get_id_product(m_device)) , m_vendor(libinput_device_get_id_vendor(m_device)) , m_tapFingerCount(libinput_device_config_tap_get_finger_count(m_device)) , m_tapToClickEnabledByDefault(libinput_device_config_tap_get_default_enabled(m_device) == LIBINPUT_CONFIG_TAP_ENABLED) , 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)) , m_supportsCalibrationMatrix(libinput_device_config_calibration_has_matrix(m_device)) , m_supportsDisableEvents(libinput_device_config_send_events_get_modes(m_device) & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED) , m_supportsDisableEventsOnExternalMouse(libinput_device_config_send_events_get_modes(m_device) & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE) , m_supportsMiddleEmulation(libinput_device_config_middle_emulation_is_available(m_device)) , m_supportsNaturalScroll(libinput_device_config_scroll_has_natural_scroll(m_device)) , m_supportedScrollMethods(libinput_device_config_scroll_get_methods(m_device)) , m_middleEmulationEnabledByDefault(libinput_device_config_middle_emulation_get_default_enabled(m_device) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED) , m_leftHandedEnabledByDefault(libinput_device_config_left_handed_get_default(m_device)) , m_naturalScrollEnabledByDefault(libinput_device_config_scroll_get_default_natural_scroll_enabled(m_device)) , m_defaultScrollMethod(libinput_device_config_scroll_get_default_method(m_device)) , m_defaultScrollButton(libinput_device_config_scroll_get_default_button(m_device)) , m_middleEmulation(libinput_device_config_middle_emulation_get_enabled(m_device) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED) , m_leftHanded(m_supportsLeftHanded ? libinput_device_config_left_handed_get(m_device) : false) , m_naturalScroll(m_supportsNaturalScroll ? libinput_device_config_scroll_get_natural_scroll_enabled(m_device) : false) , m_scrollMethod(libinput_device_config_scroll_get_method(m_device)) , m_scrollButton(libinput_device_config_scroll_get_button(m_device)) , m_pointerAcceleration(libinput_device_config_accel_get_speed(m_device)) , m_enabled(m_supportsDisableEvents ? libinput_device_config_send_events_get_mode(m_device) == LIBINPUT_CONFIG_SEND_EVENTS_ENABLED : true) , m_config() { libinput_device_ref(m_device); qreal width = 0; qreal height = 0; if (libinput_device_get_size(m_device, &width, &height) == 0) { m_size = QSizeF(width, height); } if (m_pointer) { if (libinput_device_pointer_has_button(m_device, BTN_LEFT) == 1) { m_supportedButtons |= Qt::LeftButton; } if (libinput_device_pointer_has_button(m_device, BTN_MIDDLE) == 1) { m_supportedButtons |= Qt::MiddleButton; } if (libinput_device_pointer_has_button(m_device, BTN_RIGHT) == 1) { m_supportedButtons |= Qt::RightButton; } if (libinput_device_pointer_has_button(m_device, BTN_SIDE) == 1) { m_supportedButtons |= Qt::ExtraButton1; } if (libinput_device_pointer_has_button(m_device, BTN_EXTRA) == 1) { m_supportedButtons |= Qt::ExtraButton2; } if (libinput_device_pointer_has_button(m_device, BTN_BACK) == 1) { m_supportedButtons |= Qt::BackButton; } if (libinput_device_pointer_has_button(m_device, BTN_FORWARD) == 1) { m_supportedButtons |= Qt::ForwardButton; } if (libinput_device_pointer_has_button(m_device, BTN_TASK) == 1) { m_supportedButtons |= Qt::TaskButton; } } if (m_keyboard) { m_alphaNumericKeyboard = checkAlphaNumericKeyboard(m_device); } s_devices << this; QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/kde/KWin/InputDevice/") + m_sysName, QStringLiteral("org.kde.KWin.InputDevice"), this, QDBusConnection::ExportAllProperties ); } Device::~Device() { s_devices.removeOne(this); QDBusConnection::sessionBus().unregisterObject(QStringLiteral("/org/kde/KWin/InputDevice/") + m_sysName); libinput_device_unref(m_device); } template void Device::writeEntry(const ConfigKey &key, const T &value) { if (!m_config.isValid()) { return; } if (m_loading) { return; } auto it = s_configData.find(key); Q_ASSERT(it != s_configData.end()); m_config.writeEntry(it.value().key.constData(), value); m_config.sync(); } template void Device::readEntry(const QByteArray &key, const Setter &s, const T &defaultValue) { if (!s.setter) { return; } - s.setter(this, m_config.readEntry(key.constData(), s.defaultValue ? s.defaultValue(this) : defaultValue)); + + (this->*(s.setter))(m_config.readEntry(key.constData(), s.defaultValue ? (this->*(s.defaultValue))() : defaultValue)); } void Device::loadConfiguration() { if (!m_config.isValid()) { return; } m_loading = true; for (auto it = s_configData.begin(), end = s_configData.end(); it != end; ++it) { const auto key = it.value().key; if (!m_config.hasKey(key.constData())) { continue; } readEntry(key, it.value().booleanSetter, true); readEntry(key, it.value().quint32Setter, 0); }; m_loading = false; } void Device::setPointerAcceleration(qreal acceleration) { if (!m_supportsPointerAcceleration) { return; } acceleration = qBound(-1.0, acceleration, 1.0); if (libinput_device_config_accel_set_speed(m_device, acceleration) == LIBINPUT_CONFIG_STATUS_SUCCESS) { if (m_pointerAcceleration != acceleration) { m_pointerAcceleration = acceleration; emit pointerAccelerationChanged(); } } } -bool Device::setScrollMethod(bool set, enum libinput_config_scroll_method method) +void Device::setScrollMethod(bool set, enum libinput_config_scroll_method method) { - if (!(m_supportedScrollMethods & method)) { - return false; + bool stays_the_same = (m_scrollMethod == method) == set; + if (!(m_supportedScrollMethods & method) || stays_the_same) { + return; } - if (set) { - if (m_scrollMethod == method) { - return false; - } - } else { - if (m_scrollMethod != method) { - return false; - } + + if (!set) { method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; } if (libinput_device_config_scroll_set_method(m_device, method) == LIBINPUT_CONFIG_STATUS_SUCCESS) { m_scrollMethod = method; emit scrollMethodChanged(); - return true; - } - return false; -} - -void Device::setScrollTwoFinger(bool set) { - if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_2FG)) { - writeEntry(ConfigKey::ScrollTwoFinger, set); - writeEntry(ConfigKey::ScrollEdge, !set); - writeEntry(ConfigKey::ScrollOnButton, !set); - } -} - -void Device::setScrollEdge(bool set) { - if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_EDGE)) { - writeEntry(ConfigKey::ScrollEdge, set); - writeEntry(ConfigKey::ScrollTwoFinger, !set); - writeEntry(ConfigKey::ScrollOnButton, !set); - } -} - -void Device::setScrollOnButtonDown(bool set) { - if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) { - writeEntry(ConfigKey::ScrollOnButton, set); - writeEntry(ConfigKey::ScrollTwoFinger, !set); - writeEntry(ConfigKey::ScrollEdge, !set); + writeEntry(ConfigKey::ScrollMethod, (quint32) method); } } void Device::setScrollButton(quint32 button) { if (!(m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) { return; } if (libinput_device_config_scroll_set_button(m_device, button) == LIBINPUT_CONFIG_STATUS_SUCCESS) { if (m_scrollButton != button) { m_scrollButton = button; writeEntry(ConfigKey::ScrollButton, m_scrollButton); emit scrollButtonChanged(); } } } #define CONFIG(method, condition, function, variable, key) \ void Device::method(bool set) \ { \ if (condition) { \ return; \ } \ if (libinput_device_config_##function(m_device, set) == LIBINPUT_CONFIG_STATUS_SUCCESS) { \ if (m_##variable != set) { \ m_##variable = set; \ writeEntry(ConfigKey::key, m_##variable); \ emit variable##Changed(); \ }\ } \ } CONFIG(setLeftHanded, !m_supportsLeftHanded, left_handed_set, leftHanded, LeftHanded) CONFIG(setNaturalScroll, !m_supportsNaturalScroll, scroll_set_natural_scroll_enabled, naturalScroll, NaturalScroll) #undef CONFIG #define CONFIG(method, condition, function, enum, variable, key) \ void Device::method(bool set) \ { \ if (condition) { \ return; \ } \ if (libinput_device_config_##function(m_device, set ? LIBINPUT_CONFIG_##enum##_ENABLED : LIBINPUT_CONFIG_##enum##_DISABLED) == LIBINPUT_CONFIG_STATUS_SUCCESS) { \ if (m_##variable != set) { \ m_##variable = set; \ writeEntry(ConfigKey::key, m_##variable); \ emit variable##Changed(); \ }\ } \ } CONFIG(setEnabled, !m_supportsDisableEvents, send_events_set_mode, SEND_EVENTS, enabled, Enabled) CONFIG(setTapToClick, m_tapFingerCount == 0, tap_set_enabled, TAP, tapToClick, TapToClick) CONFIG(setTapAndDrag, false, tap_set_drag_enabled, DRAG, tapAndDrag, TapAndDrag) CONFIG(setTapDragLock, false, tap_set_drag_lock_enabled, DRAG_LOCK, tapDragLock, TapDragLock) CONFIG(setMiddleEmulation, m_supportsMiddleEmulation == false, middle_emulation_set_enabled, MIDDLE_EMULATION, middleEmulation, MiddleButtonEmulation) #undef CONFIG } } diff --git a/libinput/device.h b/libinput/device.h index 03d5edd9f..c8a4b655e 100644 --- a/libinput/device.h +++ b/libinput/device.h @@ -1,368 +1,383 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2016 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #ifndef KWIN_LIBINPUT_DEVICE_H #define KWIN_LIBINPUT_DEVICE_H #include #include #include #include #include struct libinput_device; namespace KWin { namespace LibInput { enum class ConfigKey; class Device : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.KWin.InputDevice") Q_PROPERTY(bool keyboard READ isKeyboard CONSTANT) Q_PROPERTY(bool alphaNumericKeyboard READ isAlphaNumericKeyboard CONSTANT) Q_PROPERTY(bool pointer READ isPointer CONSTANT) Q_PROPERTY(bool touch READ isTouch CONSTANT) Q_PROPERTY(bool tabletTool READ isTabletTool CONSTANT) Q_PROPERTY(bool tabletPad READ isTabletPad CONSTANT) Q_PROPERTY(bool gestureSupport READ supportsGesture CONSTANT) Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString sysName READ sysName CONSTANT) Q_PROPERTY(QString outputName READ outputName CONSTANT) Q_PROPERTY(QSizeF size READ size CONSTANT) Q_PROPERTY(quint32 product READ product CONSTANT) Q_PROPERTY(quint32 vendor READ vendor CONSTANT) Q_PROPERTY(Qt::MouseButtons supportedButtons READ supportedButtons CONSTANT) Q_PROPERTY(int tapFingerCount READ tapFingerCount CONSTANT) Q_PROPERTY(bool tapToClickEnabledByDefault READ tapToClickEnabledByDefault CONSTANT) Q_PROPERTY(bool supportsDisableWhileTyping READ supportsDisableWhileTyping CONSTANT) Q_PROPERTY(bool supportsPointerAcceleration READ supportsPointerAcceleration CONSTANT) Q_PROPERTY(bool supportsLeftHanded READ supportsLeftHanded CONSTANT) Q_PROPERTY(bool supportsCalibrationMatrix READ supportsCalibrationMatrix CONSTANT) Q_PROPERTY(bool supportsDisableEvents READ supportsDisableEvents CONSTANT) Q_PROPERTY(bool supportsDisableEventsOnExternalMouse READ supportsDisableEventsOnExternalMouse CONSTANT) Q_PROPERTY(bool supportsMiddleEmulation READ supportsMiddleEmulation CONSTANT) Q_PROPERTY(bool supportsNaturalScroll READ supportsNaturalScroll CONSTANT) Q_PROPERTY(bool supportsScrollTwoFinger READ supportsScrollTwoFinger CONSTANT) Q_PROPERTY(bool supportsScrollEdge READ supportsScrollEdge CONSTANT) Q_PROPERTY(bool supportsScrollOnButtonDown READ supportsScrollOnButtonDown CONSTANT) Q_PROPERTY(bool middleEmulationEnabledByDefault READ middleEmulationEnabledByDefault CONSTANT) Q_PROPERTY(bool naturalScrollEnabledByDefault READ naturalScrollEnabledByDefault CONSTANT) Q_PROPERTY(bool scrollTwoFingerEnabledByDefault READ scrollTwoFingerEnabledByDefault CONSTANT) Q_PROPERTY(bool scrollEdgeEnabledByDefault READ scrollEdgeEnabledByDefault CONSTANT) Q_PROPERTY(bool scrollOnButtonDownEnabledByDefault READ scrollOnButtonDownEnabledByDefault CONSTANT) Q_PROPERTY(quint32 defaultScrollButton READ defaultScrollButton CONSTANT) Q_PROPERTY(bool middleEmulation READ isMiddleEmulation WRITE setMiddleEmulation NOTIFY middleEmulationChanged) Q_PROPERTY(bool leftHandedEnabledByDefault READ leftHandedEnabledByDefault CONSTANT) Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged) Q_PROPERTY(bool naturalScroll READ isNaturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged) Q_PROPERTY(bool scrollTwoFinger READ isScrollTwoFinger WRITE setScrollTwoFinger NOTIFY scrollMethodChanged) Q_PROPERTY(bool scrollEdge READ isScrollEdge WRITE setScrollEdge NOTIFY scrollMethodChanged) Q_PROPERTY(bool scrollOnButtonDown READ isScrollOnButtonDown WRITE setScrollOnButtonDown NOTIFY scrollMethodChanged) Q_PROPERTY(quint32 scrollButton READ scrollButton WRITE setScrollButton NOTIFY scrollButtonChanged) Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged) 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); virtual ~Device(); bool isKeyboard() const { return m_keyboard; } bool isAlphaNumericKeyboard() const { return m_alphaNumericKeyboard; } bool isPointer() const { return m_pointer; } bool isTouch() const { return m_touch; } bool isTabletTool() const { return m_tabletTool; } bool isTabletPad() const { return m_tabletPad; } bool supportsGesture() const { return m_supportsGesture; } QString name() const { return m_name; } QString sysName() const { return m_sysName; } QString outputName() const { return m_outputName; } QSizeF size() const { return m_size; } quint32 product() const { return m_product; } quint32 vendor() const { return m_vendor; } Qt::MouseButtons supportedButtons() const { return m_supportedButtons; } int tapFingerCount() const { return m_tapFingerCount; } bool tapToClickEnabledByDefault() const { return m_tapToClickEnabledByDefault; } bool isTapToClick() const { return m_tapToClick; } /** * Set the Device to tap to click if @p set is @c true. **/ void setTapToClick(bool set); bool tapAndDragEnabledByDefault() const { return m_tapAndDragEnabledByDefault; } bool isTapAndDrag() const { 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; } bool supportsPointerAcceleration() const { return m_supportsPointerAcceleration; } bool supportsLeftHanded() const { return m_supportsLeftHanded; } bool supportsCalibrationMatrix() const { return m_supportsCalibrationMatrix; } bool supportsDisableEvents() const { return m_supportsDisableEvents; } bool supportsDisableEventsOnExternalMouse() const { return m_supportsDisableEventsOnExternalMouse; } bool supportsMiddleEmulation() const { return m_supportsMiddleEmulation; } bool supportsNaturalScroll() const { return m_supportsNaturalScroll; } bool supportsScrollTwoFinger() const { return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_2FG); } bool supportsScrollEdge() const { return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_EDGE); } bool supportsScrollOnButtonDown() const { return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); } bool leftHandedEnabledByDefault() const { return m_leftHandedEnabledByDefault; } bool middleEmulationEnabledByDefault() const { return m_middleEmulationEnabledByDefault; } bool naturalScrollEnabledByDefault() const { return m_naturalScrollEnabledByDefault; } + enum libinput_config_scroll_method defaultScrollMethod() const { + return m_defaultScrollMethod; + } + quint32 defaultScrollMethodToInt() const { + return (quint32) m_defaultScrollMethod; + } bool scrollTwoFingerEnabledByDefault() const { return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_2FG; } bool scrollEdgeEnabledByDefault() const { return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_EDGE; } bool scrollOnButtonDownEnabledByDefault() const { return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; } quint32 defaultScrollButton() const { return m_defaultScrollButton; } bool isMiddleEmulation() const { return m_middleEmulation; } void setMiddleEmulation(bool set); bool isNaturalScroll() const { return m_naturalScroll; } void setNaturalScroll(bool set); - bool setScrollMethod(bool set, enum libinput_config_scroll_method method); + void setScrollMethod(bool set, enum libinput_config_scroll_method method); bool isScrollTwoFinger() const { return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_2FG; } - void setScrollTwoFinger(bool set); + void setScrollTwoFinger(bool set) { + setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_2FG); + } bool isScrollEdge() const { return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_EDGE; } - void setScrollEdge(bool set); + void setScrollEdge(bool set) { + setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_EDGE); + } bool isScrollOnButtonDown() const { return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; } - void setScrollOnButtonDown(bool set); + void setScrollOnButtonDown(bool set) { + setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); + } + void activateScrollMethodFromInt(quint32 method) { + setScrollMethod(true, (libinput_config_scroll_method) method); + } quint32 scrollButton() const { return m_scrollButton; } void setScrollButton(quint32 button); bool isLeftHanded() const { return m_leftHanded; } /** * Sets the Device to left handed mode if @p set is @c true. * If @p set is @c false the device is set to right handed mode **/ void setLeftHanded(bool set); qreal pointerAcceleration() const { return m_pointerAcceleration; } /** * @param acceleration mapped to range [-1,1] with -1 being the slowest, 1 being the fastest supported acceleration. **/ void setPointerAcceleration(qreal acceleration); bool isEnabled() const { return m_enabled; } void setEnabled(bool enabled); libinput_device *device() const { return m_device; } /** * Sets the @p config to load the Device configuration from and to store each * successful Device configuration. **/ void setConfig(const KConfigGroup &config) { m_config = config; } /** * Loads the configuration and applies it to the Device **/ void loadConfiguration(); /** * All created Devices **/ static QVector devices() { return s_devices; } /** * Gets the Device for @p native. @c null if there is no Device for @p native. **/ static Device *getDevice(libinput_device *native); Q_SIGNALS: void leftHandedChanged(); void pointerAccelerationChanged(); void enabledChanged(); void tapToClickChanged(); void tapAndDragChanged(); void tapDragLockChanged(); void middleEmulationChanged(); void naturalScrollChanged(); void scrollMethodChanged(); void scrollButtonChanged(); private: template void writeEntry(const ConfigKey &key, const T &value); template void readEntry(const QByteArray &key, const Setter &s, const T &defaultValue = T()); libinput_device *m_device; bool m_keyboard; bool m_alphaNumericKeyboard = false; bool m_pointer; bool m_touch; bool m_tabletTool; bool m_tabletPad; bool m_supportsGesture; QString m_name; QString m_sysName; QString m_outputName; QSizeF m_size; quint32 m_product; quint32 m_vendor; Qt::MouseButtons m_supportedButtons = Qt::NoButton; int m_tapFingerCount; bool m_tapToClickEnabledByDefault; bool m_tapToClick; bool m_tapAndDragEnabledByDefault; bool m_tapAndDrag; bool m_tapDragLockEnabledByDefault; bool m_tapDragLock; bool m_supportsDisableWhileTyping; bool m_supportsPointerAcceleration; bool m_supportsLeftHanded; bool m_supportsCalibrationMatrix; bool m_supportsDisableEvents; bool m_supportsDisableEventsOnExternalMouse; bool m_supportsMiddleEmulation; bool m_supportsNaturalScroll; quint32 m_supportedScrollMethods; bool m_supportsScrollEdge; bool m_supportsScrollOnButtonDown; bool m_leftHandedEnabledByDefault; bool m_middleEmulationEnabledByDefault; bool m_naturalScrollEnabledByDefault; enum libinput_config_scroll_method m_defaultScrollMethod; quint32 m_defaultScrollButton; bool m_middleEmulation; bool m_leftHanded; bool m_naturalScroll; enum libinput_config_scroll_method m_scrollMethod; quint32 m_scrollButton; qreal m_pointerAcceleration; bool m_enabled; KConfigGroup m_config; bool m_loading = false; static QVector s_devices; }; } } Q_DECLARE_METATYPE(KWin::LibInput::Device*) #endif