diff --git a/src/backends/libinput/connection.cpp b/src/backends/libinput/connection.cpp index acdefb528d..2ecc100131 100644 --- a/src/backends/libinput/connection.cpp +++ b/src/backends/libinput/connection.cpp @@ -614,6 +614,21 @@ void Connection::applyScreenToDevice(Device *device) void Connection::applyDeviceConfig(Device *device) { + KConfigGroup defaults = m_config->group("Libinput").group("Defaults"); + if (defaults.isValid()) { + if (device->isAlphaNumericKeyboard() && defaults.hasGroup("Keyboard")) { + defaults = defaults.group("Keyboard"); + } + if (device->isPointer() && defaults.hasGroup("Pointer")) { + defaults = defaults.group("Pointer"); + } + if (device->isTouchpad() && defaults.hasGroup("Touchpad")) { + defaults = defaults.group("Touchpad"); + } + + device->setDefaultConfig(defaults); + } + // pass configuration to Device device->setConfig(m_config->group("Libinput").group(QString::number(device->vendor())).group(QString::number(device->product())).group(device->name())); device->loadConfiguration(); diff --git a/src/backends/libinput/device.cpp b/src/backends/libinput/device.cpp index 709e380676..f247b66d74 100644 --- a/src/backends/libinput/device.cpp +++ b/src/backends/libinput/device.cpp @@ -315,7 +315,7 @@ Device::Device(libinput_device *device, QObject *parent) , m_scrollButton(libinput_device_config_scroll_get_button(m_device)) , m_defaultPointerAcceleration(libinput_device_config_accel_get_default_speed(m_device)) , m_pointerAcceleration(libinput_device_config_accel_get_speed(m_device)) - , m_scrollFactor(scrollFactorDefault()) + , m_scrollFactor(1.0) , m_supportedPointerAccelerationProfiles(libinput_device_config_accel_get_profiles(m_device)) , m_defaultPointerAccelerationProfile(libinput_device_config_accel_get_default_profile(m_device)) , m_pointerAccelerationProfile(libinput_device_config_accel_get_profile(m_device)) @@ -409,7 +409,7 @@ void Device::writeEntry(const ConfigKey &key, const T &value) void Device::loadConfiguration() { - if (!m_config.isValid()) { + if (!m_config.isValid() && !m_defaultConfig.isValid()) { return; } diff --git a/src/backends/libinput/device.h b/src/backends/libinput/device.h index 751aef316a..152ea1e012 100644 --- a/src/backends/libinput/device.h +++ b/src/backends/libinput/device.h @@ -196,7 +196,7 @@ public: return m_tapFingerCount; } bool tapToClickEnabledByDefault() const { - return m_tapToClickEnabledByDefault; + return defaultValue("TapToClick", m_tapToClickEnabledByDefault); } bool isTapToClick() const { return m_tapToClick; @@ -206,14 +206,14 @@ public: */ void setTapToClick(bool set); bool tapAndDragEnabledByDefault() const { - return m_tapAndDragEnabledByDefault; + return defaultValue("TapAndDrag", m_tapAndDragEnabledByDefault); } bool isTapAndDrag() const { return m_tapAndDrag; } void setTapAndDrag(bool set); bool tapDragLockEnabledByDefault() const { - return m_tapDragLockEnabledByDefault; + return defaultValue("TapDragLock", m_tapDragLockEnabledByDefault); } bool isTapDragLock() const { return m_tapDragLock; @@ -223,7 +223,7 @@ public: return m_supportsDisableWhileTyping; } bool disableWhileTypingEnabledByDefault() const { - return m_disableWhileTypingEnabledByDefault; + return defaultValue("DisableWhileTyping", m_disableWhileTypingEnabledByDefault); } bool supportsPointerAcceleration() const { return m_supportsPointerAcceleration; @@ -256,34 +256,36 @@ public: return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); } bool leftHandedEnabledByDefault() const { - return m_leftHandedEnabledByDefault; + return defaultValue("LeftHanded", m_leftHandedEnabledByDefault); } bool middleEmulationEnabledByDefault() const { - return m_middleEmulationEnabledByDefault; + return defaultValue("MiddleButtonEmulation", m_middleEmulationEnabledByDefault); } bool naturalScrollEnabledByDefault() const { - return m_naturalScrollEnabledByDefault; + return defaultValue("NaturalScroll", m_naturalScrollEnabledByDefault); } enum libinput_config_scroll_method defaultScrollMethod() const { - return m_defaultScrollMethod; + quint32 defaultScrollMethod = defaultValue("ScrollMethod", static_cast(m_defaultScrollMethod)); + return static_cast(defaultScrollMethod); } quint32 defaultScrollMethodToInt() const { - return (quint32) m_defaultScrollMethod; + return static_cast(defaultScrollMethod()); } bool scrollTwoFingerEnabledByDefault() const { - return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_2FG; + return defaultScrollMethod() == LIBINPUT_CONFIG_SCROLL_2FG; } bool scrollEdgeEnabledByDefault() const { - return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_EDGE; + return defaultScrollMethod() == LIBINPUT_CONFIG_SCROLL_EDGE; } bool scrollOnButtonDownEnabledByDefault() const { - return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; + return defaultScrollMethod() == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; } bool supportsLmrTapButtonMap() const { return m_tapFingerCount > 1; } bool lmrTapButtonMapEnabledByDefault() const { - return m_defaultTapButtonMap == LIBINPUT_CONFIG_TAP_MAP_LMR; + quint32 lmrButtonMap = defaultValue("LmrTapButtonMap", static_cast(m_defaultTapButtonMap)); + return lmrButtonMap == LIBINPUT_CONFIG_TAP_MAP_LMR; } void setLmrTapButtonMap(bool set); @@ -330,7 +332,7 @@ public: void setScrollButton(quint32 button); qreal scrollFactorDefault() const { - return 1.0; + return defaultValue("ScrollFactor", 1.0); } qreal scrollFactor() const { return m_scrollFactor; @@ -352,6 +354,11 @@ public: QMatrix4x4 defaultCalibrationMatrix() const { + auto list = defaultValue("CalibrationMatrix", QList{}); + if (list.size() == 16) { + return QMatrix4x4{list.toVector().constData()}; + } + return m_defaultCalibrationMatrix; } QMatrix4x4 calibrationMatrix() const @@ -362,7 +369,8 @@ public: Qt::ScreenOrientation defaultOrientation() const { - return Qt::PrimaryOrientation; + quint32 orientation = defaultValue("Orientation", static_cast(Qt::PrimaryOrientation)); + return static_cast(orientation); } Qt::ScreenOrientation orientation() const { @@ -419,13 +427,13 @@ public: setPointerAccelerationProfile(true, (libinput_config_accel_profile) profile); } quint32 defaultPointerAccelerationProfileToInt() const { - return (quint32) m_defaultPointerAccelerationProfile; + return defaultValue("PointerAccelerationProfile", static_cast(m_defaultPointerAccelerationProfile)); } bool supportsClickMethodAreas() const { return (m_supportedClickMethods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); } bool defaultClickMethodAreas() const { - return (m_defaultClickMethod == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); + return (defaultClickMethod() == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); } bool isClickMethodAreas() const { return (m_clickMethod == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); @@ -434,7 +442,7 @@ public: return (m_supportedClickMethods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); } bool defaultClickMethodClickfinger() const { - return (m_defaultClickMethod == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); + return (defaultClickMethod() == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); } bool isClickMethodClickfinger() const { return (m_clickMethod == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); @@ -449,8 +457,11 @@ public: void setClickMethodFromInt(quint32 method) { setClickMethod(true, (libinput_config_click_method) method); } + libinput_config_click_method defaultClickMethod() const { + return static_cast(defaultClickMethodToInt()); + } quint32 defaultClickMethodToInt() const { - return (quint32) m_defaultClickMethod; + return defaultValue("ClickMethod", static_cast(m_defaultClickMethod)); } bool isEnabled() const override { @@ -459,7 +470,7 @@ public: void setEnabled(bool enabled) override; bool isEnabledByDefault() const { - return true; + return defaultValue("Enabled", true); } libinput_device *device() const { @@ -474,6 +485,10 @@ public: m_config = config; } + void setDefaultConfig(const KConfigGroup &config) { + m_defaultConfig = config; + } + /** * Used to deserialize monitor data from KConfig when initializing a device */ @@ -545,6 +560,17 @@ Q_SIGNALS: private: template void writeEntry(const ConfigKey &key, const T &value); + + template + T defaultValue(const char* key, const T &fallback) const + { + if (m_defaultConfig.isValid() && m_defaultConfig.hasKey(key)) { + return m_defaultConfig.readEntry(key, fallback); + } + + return fallback; + } + libinput_device *m_device; bool m_keyboard; bool m_alphaNumericKeyboard = false; @@ -604,6 +630,7 @@ private: bool m_enabled; KConfigGroup m_config; + KConfigGroup m_defaultConfig; bool m_loading = false; QPointer m_output;