From 8b39f986d9a2c99e87a9afc2e9d448a2c5280189 Mon Sep 17 00:00:00 2001 From: elipp <1861512+elipp@users.noreply.github.com> Date: Sun, 3 Nov 2024 20:43:03 +0200 Subject: Implement scroll_factor mouse and touchpad setting (#730) * Implement scroll_factor mouse and touchpad setting * Change to FloatOrInt, add docs * Also change v120 values --------- Co-authored-by: Ivan Molodetskikh --- niri-config/src/lib.rs | 8 ++++++++ src/input/mod.rs | 13 +++++++++++-- wiki/Configuration:-Input.md | 6 ++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 042cf6ba..86e6510c 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -188,6 +188,8 @@ pub struct Touchpad { pub disabled_on_external_mouse: bool, #[knuffel(child)] pub middle_emulation: bool, + #[knuffel(child, unwrap(argument), default = FloatOrInt(1.0))] + pub scroll_factor: FloatOrInt<0, 100>, } #[derive(knuffel::Decode, Debug, Default, PartialEq)] @@ -208,6 +210,8 @@ pub struct Mouse { pub left_handed: bool, #[knuffel(child)] pub middle_emulation: bool, + #[knuffel(child, unwrap(argument), default = FloatOrInt(1.0))] + pub scroll_factor: FloatOrInt<0, 100>, } #[derive(knuffel::Decode, Debug, Default, PartialEq)] @@ -2958,6 +2962,7 @@ mod tests { scroll-button 272 tap-button-map "left-middle-right" disabled-on-external-mouse + scroll-factor 0.9 } mouse { @@ -2967,6 +2972,7 @@ mod tests { scroll-method "no-scroll" scroll-button 273 middle-emulation + scroll-factor 0.2 } trackpoint { @@ -3169,6 +3175,7 @@ mod tests { left_handed: false, disabled_on_external_mouse: true, middle_emulation: false, + scroll_factor: FloatOrInt(0.9), }, mouse: Mouse { off: false, @@ -3179,6 +3186,7 @@ mod tests { scroll_button: Some(273), left_handed: false, middle_emulation: true, + scroll_factor: FloatOrInt(0.2), }, trackpoint: Trackpoint { off: true, diff --git a/src/input/mod.rs b/src/input/mod.rs index 5800b8a4..9936102e 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1881,14 +1881,23 @@ impl State { } } + let scroll_factor = match source { + AxisSource::Wheel => self.niri.config.borrow().input.mouse.scroll_factor.0, + AxisSource::Finger => self.niri.config.borrow().input.touchpad.scroll_factor.0, + _ => 1.0, + }; + let horizontal_amount = horizontal_amount.unwrap_or_else(|| { // Winit backend, discrete scrolling. horizontal_amount_v120.unwrap_or(0.0) / 120. * 15. - }); + }) * scroll_factor; let vertical_amount = vertical_amount.unwrap_or_else(|| { // Winit backend, discrete scrolling. vertical_amount_v120.unwrap_or(0.0) / 120. * 15. - }); + }) * scroll_factor; + + let horizontal_amount_v120 = horizontal_amount_v120.map(|x| x * scroll_factor); + let vertical_amount_v120 = vertical_amount_v120.map(|x| x * scroll_factor); let mut frame = AxisFrame::new(event.time_msec()).source(source); if horizontal_amount != 0.0 { diff --git a/wiki/Configuration:-Input.md b/wiki/Configuration:-Input.md index 05636fa5..b47fa19a 100644 --- a/wiki/Configuration:-Input.md +++ b/wiki/Configuration:-Input.md @@ -32,6 +32,7 @@ input { natural-scroll // accel-speed 0.2 // accel-profile "flat" + // scroll-factor 1.0 // scroll-method "two-finger" // tap-button-map "left-middle-right" // click-method "clickfinger" @@ -45,6 +46,7 @@ input { // natural-scroll // accel-speed 0.2 // accel-profile "flat" + // scroll-factor 1.0 // scroll-method "no-scroll" // left-handed // middle-emulation @@ -154,6 +156,10 @@ Settings specific to `touchpad`s: - `click-method`: can be `button-areas` or `clickfinger`, changes the [click method](https://wayland.freedesktop.org/libinput/doc/latest/clickpad-softbuttons.html). - `disabled-on-external-mouse`: do not send events while external pointer device is plugged in. +Settings specific to `touchpad` and `mouse`: + +- `scroll-factor`: scales the scrolling by this value. + Settings specific to `touchpad`, `mouse` and `tablet`: - `left-handed`: if set, changes the device to left-handed mode. -- cgit