Support global defaults for input devices

This adds support for reading values from a "Libinput/Defaults" group in
the input config file. This allows specifying global defaults for
devices, that are preferred over the libinput defaults. Because of the
cascading mechanisms of KConfig, this then allows distributions and
hardware vendors to supply system-wide defaults for devices.
This commit is contained in:
Arjen Hiemstra 2021-12-15 16:49:28 +01:00
parent 0319a66ead
commit 352e92e32f
3 changed files with 64 additions and 22 deletions

View file

@ -614,6 +614,21 @@ void Connection::applyScreenToDevice(Device *device)
void Connection::applyDeviceConfig(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 // pass configuration to Device
device->setConfig(m_config->group("Libinput").group(QString::number(device->vendor())).group(QString::number(device->product())).group(device->name())); device->setConfig(m_config->group("Libinput").group(QString::number(device->vendor())).group(QString::number(device->product())).group(device->name()));
device->loadConfiguration(); device->loadConfiguration();

View file

@ -315,7 +315,7 @@ Device::Device(libinput_device *device, QObject *parent)
, m_scrollButton(libinput_device_config_scroll_get_button(m_device)) , m_scrollButton(libinput_device_config_scroll_get_button(m_device))
, m_defaultPointerAcceleration(libinput_device_config_accel_get_default_speed(m_device)) , m_defaultPointerAcceleration(libinput_device_config_accel_get_default_speed(m_device))
, m_pointerAcceleration(libinput_device_config_accel_get_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_supportedPointerAccelerationProfiles(libinput_device_config_accel_get_profiles(m_device))
, m_defaultPointerAccelerationProfile(libinput_device_config_accel_get_default_profile(m_device)) , m_defaultPointerAccelerationProfile(libinput_device_config_accel_get_default_profile(m_device))
, m_pointerAccelerationProfile(libinput_device_config_accel_get_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() void Device::loadConfiguration()
{ {
if (!m_config.isValid()) { if (!m_config.isValid() && !m_defaultConfig.isValid()) {
return; return;
} }

View file

@ -196,7 +196,7 @@ public:
return m_tapFingerCount; return m_tapFingerCount;
} }
bool tapToClickEnabledByDefault() const { bool tapToClickEnabledByDefault() const {
return m_tapToClickEnabledByDefault; return defaultValue("TapToClick", m_tapToClickEnabledByDefault);
} }
bool isTapToClick() const { bool isTapToClick() const {
return m_tapToClick; return m_tapToClick;
@ -206,14 +206,14 @@ public:
*/ */
void setTapToClick(bool set); void setTapToClick(bool set);
bool tapAndDragEnabledByDefault() const { bool tapAndDragEnabledByDefault() const {
return m_tapAndDragEnabledByDefault; return defaultValue("TapAndDrag", m_tapAndDragEnabledByDefault);
} }
bool isTapAndDrag() const { bool isTapAndDrag() const {
return m_tapAndDrag; return m_tapAndDrag;
} }
void setTapAndDrag(bool set); void setTapAndDrag(bool set);
bool tapDragLockEnabledByDefault() const { bool tapDragLockEnabledByDefault() const {
return m_tapDragLockEnabledByDefault; return defaultValue("TapDragLock", m_tapDragLockEnabledByDefault);
} }
bool isTapDragLock() const { bool isTapDragLock() const {
return m_tapDragLock; return m_tapDragLock;
@ -223,7 +223,7 @@ public:
return m_supportsDisableWhileTyping; return m_supportsDisableWhileTyping;
} }
bool disableWhileTypingEnabledByDefault() const { bool disableWhileTypingEnabledByDefault() const {
return m_disableWhileTypingEnabledByDefault; return defaultValue("DisableWhileTyping", m_disableWhileTypingEnabledByDefault);
} }
bool supportsPointerAcceleration() const { bool supportsPointerAcceleration() const {
return m_supportsPointerAcceleration; return m_supportsPointerAcceleration;
@ -256,34 +256,36 @@ public:
return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
} }
bool leftHandedEnabledByDefault() const { bool leftHandedEnabledByDefault() const {
return m_leftHandedEnabledByDefault; return defaultValue("LeftHanded", m_leftHandedEnabledByDefault);
} }
bool middleEmulationEnabledByDefault() const { bool middleEmulationEnabledByDefault() const {
return m_middleEmulationEnabledByDefault; return defaultValue("MiddleButtonEmulation", m_middleEmulationEnabledByDefault);
} }
bool naturalScrollEnabledByDefault() const { bool naturalScrollEnabledByDefault() const {
return m_naturalScrollEnabledByDefault; return defaultValue("NaturalScroll", m_naturalScrollEnabledByDefault);
} }
enum libinput_config_scroll_method defaultScrollMethod() const { enum libinput_config_scroll_method defaultScrollMethod() const {
return m_defaultScrollMethod; quint32 defaultScrollMethod = defaultValue("ScrollMethod", static_cast<quint32>(m_defaultScrollMethod));
return static_cast<libinput_config_scroll_method>(defaultScrollMethod);
} }
quint32 defaultScrollMethodToInt() const { quint32 defaultScrollMethodToInt() const {
return (quint32) m_defaultScrollMethod; return static_cast<quint32>(defaultScrollMethod());
} }
bool scrollTwoFingerEnabledByDefault() const { bool scrollTwoFingerEnabledByDefault() const {
return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_2FG; return defaultScrollMethod() == LIBINPUT_CONFIG_SCROLL_2FG;
} }
bool scrollEdgeEnabledByDefault() const { bool scrollEdgeEnabledByDefault() const {
return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_EDGE; return defaultScrollMethod() == LIBINPUT_CONFIG_SCROLL_EDGE;
} }
bool scrollOnButtonDownEnabledByDefault() const { bool scrollOnButtonDownEnabledByDefault() const {
return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; return defaultScrollMethod() == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
} }
bool supportsLmrTapButtonMap() const { bool supportsLmrTapButtonMap() const {
return m_tapFingerCount > 1; return m_tapFingerCount > 1;
} }
bool lmrTapButtonMapEnabledByDefault() const { bool lmrTapButtonMapEnabledByDefault() const {
return m_defaultTapButtonMap == LIBINPUT_CONFIG_TAP_MAP_LMR; quint32 lmrButtonMap = defaultValue("LmrTapButtonMap", static_cast<quint32>(m_defaultTapButtonMap));
return lmrButtonMap == LIBINPUT_CONFIG_TAP_MAP_LMR;
} }
void setLmrTapButtonMap(bool set); void setLmrTapButtonMap(bool set);
@ -330,7 +332,7 @@ public:
void setScrollButton(quint32 button); void setScrollButton(quint32 button);
qreal scrollFactorDefault() const { qreal scrollFactorDefault() const {
return 1.0; return defaultValue("ScrollFactor", 1.0);
} }
qreal scrollFactor() const { qreal scrollFactor() const {
return m_scrollFactor; return m_scrollFactor;
@ -352,6 +354,11 @@ public:
QMatrix4x4 defaultCalibrationMatrix() const QMatrix4x4 defaultCalibrationMatrix() const
{ {
auto list = defaultValue("CalibrationMatrix", QList<float>{});
if (list.size() == 16) {
return QMatrix4x4{list.toVector().constData()};
}
return m_defaultCalibrationMatrix; return m_defaultCalibrationMatrix;
} }
QMatrix4x4 calibrationMatrix() const QMatrix4x4 calibrationMatrix() const
@ -362,7 +369,8 @@ public:
Qt::ScreenOrientation defaultOrientation() const Qt::ScreenOrientation defaultOrientation() const
{ {
return Qt::PrimaryOrientation; quint32 orientation = defaultValue("Orientation", static_cast<quint32>(Qt::PrimaryOrientation));
return static_cast<Qt::ScreenOrientation>(orientation);
} }
Qt::ScreenOrientation orientation() const Qt::ScreenOrientation orientation() const
{ {
@ -419,13 +427,13 @@ public:
setPointerAccelerationProfile(true, (libinput_config_accel_profile) profile); setPointerAccelerationProfile(true, (libinput_config_accel_profile) profile);
} }
quint32 defaultPointerAccelerationProfileToInt() const { quint32 defaultPointerAccelerationProfileToInt() const {
return (quint32) m_defaultPointerAccelerationProfile; return defaultValue("PointerAccelerationProfile", static_cast<quint32>(m_defaultPointerAccelerationProfile));
} }
bool supportsClickMethodAreas() const { bool supportsClickMethodAreas() const {
return (m_supportedClickMethods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); return (m_supportedClickMethods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
} }
bool defaultClickMethodAreas() const { bool defaultClickMethodAreas() const {
return (m_defaultClickMethod == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); return (defaultClickMethod() == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
} }
bool isClickMethodAreas() const { bool isClickMethodAreas() const {
return (m_clickMethod == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); return (m_clickMethod == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
@ -434,7 +442,7 @@ public:
return (m_supportedClickMethods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); return (m_supportedClickMethods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
} }
bool defaultClickMethodClickfinger() const { bool defaultClickMethodClickfinger() const {
return (m_defaultClickMethod == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); return (defaultClickMethod() == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
} }
bool isClickMethodClickfinger() const { bool isClickMethodClickfinger() const {
return (m_clickMethod == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); return (m_clickMethod == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
@ -449,8 +457,11 @@ public:
void setClickMethodFromInt(quint32 method) { void setClickMethodFromInt(quint32 method) {
setClickMethod(true, (libinput_config_click_method) method); setClickMethod(true, (libinput_config_click_method) method);
} }
libinput_config_click_method defaultClickMethod() const {
return static_cast<libinput_config_click_method>(defaultClickMethodToInt());
}
quint32 defaultClickMethodToInt() const { quint32 defaultClickMethodToInt() const {
return (quint32) m_defaultClickMethod; return defaultValue("ClickMethod", static_cast<quint32>(m_defaultClickMethod));
} }
bool isEnabled() const override { bool isEnabled() const override {
@ -459,7 +470,7 @@ public:
void setEnabled(bool enabled) override; void setEnabled(bool enabled) override;
bool isEnabledByDefault() const { bool isEnabledByDefault() const {
return true; return defaultValue("Enabled", true);
} }
libinput_device *device() const { libinput_device *device() const {
@ -474,6 +485,10 @@ public:
m_config = config; m_config = config;
} }
void setDefaultConfig(const KConfigGroup &config) {
m_defaultConfig = config;
}
/** /**
* Used to deserialize monitor data from KConfig when initializing a device * Used to deserialize monitor data from KConfig when initializing a device
*/ */
@ -545,6 +560,17 @@ Q_SIGNALS:
private: private:
template <typename T> template <typename T>
void writeEntry(const ConfigKey &key, const T &value); void writeEntry(const ConfigKey &key, const T &value);
template <typename T>
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; libinput_device *m_device;
bool m_keyboard; bool m_keyboard;
bool m_alphaNumericKeyboard = false; bool m_alphaNumericKeyboard = false;
@ -604,6 +630,7 @@ private:
bool m_enabled; bool m_enabled;
KConfigGroup m_config; KConfigGroup m_config;
KConfigGroup m_defaultConfig;
bool m_loading = false; bool m_loading = false;
QPointer<AbstractOutput> m_output; QPointer<AbstractOutput> m_output;