diff --git a/kcms/touchpad/kcm/libinput/touchpad.qml b/kcms/touchpad/kcm/libinput/touchpad.qml --- a/kcms/touchpad/kcm/libinput/touchpad.qml +++ b/kcms/touchpad/kcm/libinput/touchpad.qml @@ -69,7 +69,8 @@ dwt.load() leftHanded.load() middleEmulation.load() - accelSpeed.load() + accelSpeedSpinbox.load() + accelSpeedSlider.load() accelProfile.load() tapToClick.load() tapAndDrag.load() @@ -237,31 +238,87 @@ } // Acceleration - Controls.Slider { - Kirigami.FormData.label: i18nd("kcm_touchpad", "Pointer speed:") - id: accelSpeed + Layouts.RowLayout { + Kirigami.FormData.label: i18nd("kcm_touchpad", "Pointer acceleration:") + id: accelSpeedRow - from: 1 - to: 11 - stepSize: 1 + Controls.Slider { + id: accelSpeedSlider - function load() { - enabled = touchpad.supportsPointerAcceleration - if (!enabled) { - value = 0.1 - return + from: 1 + to: 11 + stepSize: 1 + property bool updateAccelSpinbox: true // flag to avoid update loops + + function load() { + enabled = touchpad.supportsPointerAcceleration + if (!enabled) { + return + } + } + + onValueChanged: { + if (touchpad != undefined && enabled && !root.loading) { + // update the new value in accelSpeedSpinbox, if necessary + if (updateAccelSpinbox) { + accelSpeedSpinbox.value = (value-6) * 0.2 * 100 + } + updateAccelSpinbox = true; + } } - // transform libinput's pointer acceleration range [-1, 1] to slider range [1, 11] - value = 6 + touchpad.pointerAcceleration / 0.2 } - onValueChanged: { - if (touchpad != undefined && enabled && !root.loading) { - // transform slider range [1, 11] to libinput's pointer acceleration range [-1, 1] - // by *10 and /10, we ignore the floating points after 1 digit. This prevents from - // having a libinput value like 0.60000001 - touchpad.pointerAcceleration = Math.round(((value-6) * 0.2) * 10) / 10 - root.changeSignal() + Controls.SpinBox { + id: accelSpeedSpinbox + + from: -100 + to: 100 + stepSize: 1 + editable: true + property real accelSpeedValue: 0 + + validator: DoubleValidator { + bottom: accelSpeedSpinbox.from + top: accelSpeedSpinbox.to + } + + function updateAccelSlider(val) { + // convert libinput's pointer acceleration range [-1, 1] to slider range and update + accelSpeedSlider.updateAccelSpinbox = false + accelSpeedSlider.value = Math.round(6 + val / 0.2) + } + + function load() { + enabled = touchpad.supportsPointerAcceleration + if (!enabled) { + return + } + + // if existing configuration or another application set a value with more than 2 decimals + // we reduce the precision to 2 + accelSpeedValue = Math.round(touchpad.pointerAcceleration * 100) / 100 + value = accelSpeedValue * 100 + + // slider initialization + updateAccelSlider(accelSpeedValue) + } + + onValueChanged: { + if (touchpad != undefined && enabled && !root.loading) { + accelSpeedValue = value / 100 + updateAccelSlider(accelSpeedValue) + + touchpad.pointerAcceleration = accelSpeedValue + root.changeSignal() + } + } + + textFromValue: function(value, locale) { + return Number(value / 100).toLocaleString(locale, 'f', 2) + } + + valueFromText: function(text, locale) { + return Number.fromLocaleString(locale, text) * 100 } } } @@ -669,7 +726,7 @@ Kirigami.FormData.buddyFor: rightClickMethodAreas id: rightClickMethod enabled: touchpad.supportsClickMethodAreas && touchpad.supportsClickMethodClickfinger - + spacing: Kirigami.Units.smallSpacing function load() { @@ -736,7 +793,7 @@ Kirigami.FormData.label: i18nd("kcm_touchpad", "Middle-click: ") Kirigami.FormData.buddyFor: middleSoftwareEmulation id: middleClickMethod - + spacing: Kirigami.Units.smallSpacing function load() {