[libinput] Query defaultLeftHanded, save leftHanded, fix ScrollMode config

Some small improvements / fixes to the libinput backend:
- Query libinput_device_config_left_handed_get_default
- Write leftHanded property to config file
- When saving the touchpad scroll mode, write false to all other ones.
  Otherwise it will always enable the last read entry after reboot.
- Use macro for setLeftHanded(bool) and setNaturalScroll(bool)

Reviewers: #kwin, graesslin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D3430
icc-effect-5.14.5
Roman Gilg 2016-11-22 14:49:01 +01:00
parent 0dc500fe94
commit ad0647688a
5 changed files with 105 additions and 27 deletions

View File

@ -45,6 +45,8 @@ private Q_SLOTS:
void testTapFingerCount();
void testSize_data();
void testSize();
void testLeftHandedEnabledByDefault_data();
void testLeftHandedEnabledByDefault();
void testTapEnabledByDefault_data();
void testTapEnabledByDefault();
void testMiddleEmulationEnabledByDefault_data();
@ -133,6 +135,8 @@ private Q_SLOTS:
void testLoadScrollOnButton();
void testLoadScrollButton_data();
void testLoadScrollButton();
void testLoadLeftHanded_data();
void testLoadLeftHanded();
};
void TestLibinputDevice::testStaticGetter()
@ -327,6 +331,25 @@ void TestLibinputDevice::testSize()
QTEST(d.property("size").toSizeF(), "expectedSize");
}
void TestLibinputDevice::testLeftHandedEnabledByDefault_data()
{
QTest::addColumn<bool>("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<bool>("enabled");
@ -1699,5 +1722,47 @@ void TestLibinputDevice::testLoadScrollButton()
}
}
void TestLibinputDevice::testLoadLeftHanded_data()
{
QTest::addColumn<bool>("initValue");
QTest::addColumn<bool>("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"

View File

@ -194,6 +194,11 @@ int libinput_device_config_left_handed_get(struct libinput_device *device)
return device->leftHanded;
}
int libinput_device_config_left_handed_get_default(struct libinput_device *device)
{
return device->leftHandedEnabledByDefault;
}
double libinput_device_config_accel_get_speed(struct libinput_device *device)
{
return device->pointerAcceleration;

View File

@ -59,6 +59,7 @@ struct libinput_device {
bool middleEmulation = false;
qreal pointerAcceleration = 0.0;
int setPointerAccelerationReturnValue = 0;
bool leftHandedEnabledByDefault = false;
bool leftHanded = false;
int setLeftHandedReturnValue = 0;
bool naturalScrollEnabledByDefault = false;

View File

@ -74,6 +74,7 @@ Device *Device::getDevice(libinput_device *native)
enum class ConfigKey {
Enabled,
LeftHanded,
TapToClick,
TapAndDrag,
TapDragLock,
@ -99,6 +100,7 @@ struct ConfigData {
static const QMap<ConfigKey, ConfigData> s_configData {
{ConfigKey::Enabled, {QByteArrayLiteral("Enabled"), {&Device::setEnabled, std::function<bool (Device*)>()}, {}}},
{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}, {}}},
@ -146,6 +148,7 @@ Device::Device(libinput_device *device, QObject *parent)
, 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))
@ -252,19 +255,6 @@ void Device::loadConfiguration()
m_loading = false;
}
void Device::setLeftHanded(bool set)
{
if (!m_supportsLeftHanded) {
return;
}
if (libinput_device_config_left_handed_set(m_device, set) == LIBINPUT_CONFIG_STATUS_SUCCESS) {
if (m_leftHanded != set) {
m_leftHanded = set;
emit leftHandedChanged();
}
}
}
void Device::setPointerAcceleration(qreal acceleration)
{
if (!m_supportsPointerAcceleration) {
@ -279,20 +269,6 @@ void Device::setPointerAcceleration(qreal acceleration)
}
}
void Device::setNaturalScroll(bool set)
{
if (!m_supportsNaturalScroll) {
return;
}
if (libinput_device_config_scroll_set_natural_scroll_enabled(m_device, set) == LIBINPUT_CONFIG_STATUS_SUCCESS) {
if (m_naturalScroll != set) {
m_naturalScroll = set;
writeEntry(ConfigKey::NaturalScroll, m_naturalScroll);
emit naturalScrollChanged();
}
}
}
bool Device::setScrollMethod(bool set, enum libinput_config_scroll_method method)
{
if (!(m_supportedScrollMethods & method)) {
@ -320,18 +296,24 @@ bool Device::setScrollMethod(bool set, enum libinput_config_scroll_method method
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);
}
}
@ -349,6 +331,26 @@ void Device::setScrollButton(quint32 button)
}
}
#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) \
{ \

View File

@ -74,6 +74,7 @@ class Device : public QObject
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)
@ -193,6 +194,9 @@ public:
bool supportsScrollOnButtonDown() const {
return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
}
bool leftHandedEnabledByDefault() const {
return m_leftHandedEnabledByDefault;
}
bool middleEmulationEnabledByDefault() const {
return m_middleEmulationEnabledByDefault;
}
@ -337,6 +341,7 @@ private:
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;