[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
This commit is contained in:
parent
0dc500fe94
commit
ad0647688a
5 changed files with 105 additions and 27 deletions
|
@ -45,6 +45,8 @@ private Q_SLOTS:
|
||||||
void testTapFingerCount();
|
void testTapFingerCount();
|
||||||
void testSize_data();
|
void testSize_data();
|
||||||
void testSize();
|
void testSize();
|
||||||
|
void testLeftHandedEnabledByDefault_data();
|
||||||
|
void testLeftHandedEnabledByDefault();
|
||||||
void testTapEnabledByDefault_data();
|
void testTapEnabledByDefault_data();
|
||||||
void testTapEnabledByDefault();
|
void testTapEnabledByDefault();
|
||||||
void testMiddleEmulationEnabledByDefault_data();
|
void testMiddleEmulationEnabledByDefault_data();
|
||||||
|
@ -133,6 +135,8 @@ private Q_SLOTS:
|
||||||
void testLoadScrollOnButton();
|
void testLoadScrollOnButton();
|
||||||
void testLoadScrollButton_data();
|
void testLoadScrollButton_data();
|
||||||
void testLoadScrollButton();
|
void testLoadScrollButton();
|
||||||
|
void testLoadLeftHanded_data();
|
||||||
|
void testLoadLeftHanded();
|
||||||
};
|
};
|
||||||
|
|
||||||
void TestLibinputDevice::testStaticGetter()
|
void TestLibinputDevice::testStaticGetter()
|
||||||
|
@ -327,6 +331,25 @@ void TestLibinputDevice::testSize()
|
||||||
QTEST(d.property("size").toSizeF(), "expectedSize");
|
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()
|
void TestLibinputDevice::testTapEnabledByDefault_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<bool>("enabled");
|
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)
|
QTEST_GUILESS_MAIN(TestLibinputDevice)
|
||||||
#include "device_test.moc"
|
#include "device_test.moc"
|
||||||
|
|
|
@ -194,6 +194,11 @@ int libinput_device_config_left_handed_get(struct libinput_device *device)
|
||||||
return device->leftHanded;
|
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)
|
double libinput_device_config_accel_get_speed(struct libinput_device *device)
|
||||||
{
|
{
|
||||||
return device->pointerAcceleration;
|
return device->pointerAcceleration;
|
||||||
|
|
|
@ -59,6 +59,7 @@ struct libinput_device {
|
||||||
bool middleEmulation = false;
|
bool middleEmulation = false;
|
||||||
qreal pointerAcceleration = 0.0;
|
qreal pointerAcceleration = 0.0;
|
||||||
int setPointerAccelerationReturnValue = 0;
|
int setPointerAccelerationReturnValue = 0;
|
||||||
|
bool leftHandedEnabledByDefault = false;
|
||||||
bool leftHanded = false;
|
bool leftHanded = false;
|
||||||
int setLeftHandedReturnValue = 0;
|
int setLeftHandedReturnValue = 0;
|
||||||
bool naturalScrollEnabledByDefault = false;
|
bool naturalScrollEnabledByDefault = false;
|
||||||
|
|
|
@ -74,6 +74,7 @@ Device *Device::getDevice(libinput_device *native)
|
||||||
|
|
||||||
enum class ConfigKey {
|
enum class ConfigKey {
|
||||||
Enabled,
|
Enabled,
|
||||||
|
LeftHanded,
|
||||||
TapToClick,
|
TapToClick,
|
||||||
TapAndDrag,
|
TapAndDrag,
|
||||||
TapDragLock,
|
TapDragLock,
|
||||||
|
@ -99,6 +100,7 @@ struct ConfigData {
|
||||||
|
|
||||||
static const QMap<ConfigKey, ConfigData> s_configData {
|
static const QMap<ConfigKey, ConfigData> s_configData {
|
||||||
{ConfigKey::Enabled, {QByteArrayLiteral("Enabled"), {&Device::setEnabled, std::function<bool (Device*)>()}, {}}},
|
{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::TapToClick, {QByteArrayLiteral("TapToClick"), {&Device::setTapToClick, &Device::tapToClickEnabledByDefault}, {}}},
|
||||||
{ConfigKey::TapAndDrag, {QByteArrayLiteral("TapAndDrag"), {&Device::setTapAndDrag, &Device::tapAndDragEnabledByDefault}, {}}},
|
{ConfigKey::TapAndDrag, {QByteArrayLiteral("TapAndDrag"), {&Device::setTapAndDrag, &Device::tapAndDragEnabledByDefault}, {}}},
|
||||||
{ConfigKey::TapDragLock, {QByteArrayLiteral("TapDragLock"), {&Device::setTapDragLock, &Device::tapDragLockEnabledByDefault}, {}}},
|
{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_supportsNaturalScroll(libinput_device_config_scroll_has_natural_scroll(m_device))
|
||||||
, m_supportedScrollMethods(libinput_device_config_scroll_get_methods(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_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_naturalScrollEnabledByDefault(libinput_device_config_scroll_get_default_natural_scroll_enabled(m_device))
|
||||||
, m_defaultScrollMethod(libinput_device_config_scroll_get_default_method(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_defaultScrollButton(libinput_device_config_scroll_get_default_button(m_device))
|
||||||
|
@ -252,19 +255,6 @@ void Device::loadConfiguration()
|
||||||
m_loading = false;
|
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)
|
void Device::setPointerAcceleration(qreal acceleration)
|
||||||
{
|
{
|
||||||
if (!m_supportsPointerAcceleration) {
|
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)
|
bool Device::setScrollMethod(bool set, enum libinput_config_scroll_method method)
|
||||||
{
|
{
|
||||||
if (!(m_supportedScrollMethods & 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) {
|
void Device::setScrollTwoFinger(bool set) {
|
||||||
if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_2FG)) {
|
if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_2FG)) {
|
||||||
writeEntry(ConfigKey::ScrollTwoFinger, set);
|
writeEntry(ConfigKey::ScrollTwoFinger, set);
|
||||||
|
writeEntry(ConfigKey::ScrollEdge, !set);
|
||||||
|
writeEntry(ConfigKey::ScrollOnButton, !set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::setScrollEdge(bool set) {
|
void Device::setScrollEdge(bool set) {
|
||||||
if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_EDGE)) {
|
if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_EDGE)) {
|
||||||
writeEntry(ConfigKey::ScrollEdge, set);
|
writeEntry(ConfigKey::ScrollEdge, set);
|
||||||
|
writeEntry(ConfigKey::ScrollTwoFinger, !set);
|
||||||
|
writeEntry(ConfigKey::ScrollOnButton, !set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::setScrollOnButtonDown(bool set) {
|
void Device::setScrollOnButtonDown(bool set) {
|
||||||
if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) {
|
if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) {
|
||||||
writeEntry(ConfigKey::ScrollOnButton, set);
|
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) \
|
#define CONFIG(method, condition, function, enum, variable, key) \
|
||||||
void Device::method(bool set) \
|
void Device::method(bool set) \
|
||||||
{ \
|
{ \
|
||||||
|
|
|
@ -74,6 +74,7 @@ class Device : public QObject
|
||||||
Q_PROPERTY(bool scrollOnButtonDownEnabledByDefault READ scrollOnButtonDownEnabledByDefault CONSTANT)
|
Q_PROPERTY(bool scrollOnButtonDownEnabledByDefault READ scrollOnButtonDownEnabledByDefault CONSTANT)
|
||||||
Q_PROPERTY(quint32 defaultScrollButton READ defaultScrollButton CONSTANT)
|
Q_PROPERTY(quint32 defaultScrollButton READ defaultScrollButton CONSTANT)
|
||||||
Q_PROPERTY(bool middleEmulation READ isMiddleEmulation WRITE setMiddleEmulation NOTIFY middleEmulationChanged)
|
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 leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged)
|
||||||
Q_PROPERTY(bool naturalScroll READ isNaturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged)
|
Q_PROPERTY(bool naturalScroll READ isNaturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged)
|
||||||
Q_PROPERTY(bool scrollTwoFinger READ isScrollTwoFinger WRITE setScrollTwoFinger NOTIFY scrollMethodChanged)
|
Q_PROPERTY(bool scrollTwoFinger READ isScrollTwoFinger WRITE setScrollTwoFinger NOTIFY scrollMethodChanged)
|
||||||
|
@ -193,6 +194,9 @@ public:
|
||||||
bool supportsScrollOnButtonDown() const {
|
bool supportsScrollOnButtonDown() const {
|
||||||
return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
|
return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
|
||||||
}
|
}
|
||||||
|
bool leftHandedEnabledByDefault() const {
|
||||||
|
return m_leftHandedEnabledByDefault;
|
||||||
|
}
|
||||||
bool middleEmulationEnabledByDefault() const {
|
bool middleEmulationEnabledByDefault() const {
|
||||||
return m_middleEmulationEnabledByDefault;
|
return m_middleEmulationEnabledByDefault;
|
||||||
}
|
}
|
||||||
|
@ -337,6 +341,7 @@ private:
|
||||||
quint32 m_supportedScrollMethods;
|
quint32 m_supportedScrollMethods;
|
||||||
bool m_supportsScrollEdge;
|
bool m_supportsScrollEdge;
|
||||||
bool m_supportsScrollOnButtonDown;
|
bool m_supportsScrollOnButtonDown;
|
||||||
|
bool m_leftHandedEnabledByDefault;
|
||||||
bool m_middleEmulationEnabledByDefault;
|
bool m_middleEmulationEnabledByDefault;
|
||||||
bool m_naturalScrollEnabledByDefault;
|
bool m_naturalScrollEnabledByDefault;
|
||||||
enum libinput_config_scroll_method m_defaultScrollMethod;
|
enum libinput_config_scroll_method m_defaultScrollMethod;
|
||||||
|
|
Loading…
Reference in a new issue