Implement scroll_factor mouse and touchpad setting (#730)
Browse files at this commit3 changed files +25 -2
- niri-config/src/lib.rs +8 -0
- src/input/mod.rs +11 -2
- wiki/Configuration:-Input.md +6 -0
niri-config/src/lib.rsmodified+8 -0
| @@ -188,6 +188,8 @@ pub struct Touchpad { | ||
| 188 | 188 | pub disabled_on_external_mouse: bool, |
| 189 | 189 | #[knuffel(child)] |
| 190 | 190 | pub middle_emulation: bool, |
| 191 | + #[knuffel(child, unwrap(argument), default = FloatOrInt(1.0))] | |
| 192 | + pub scroll_factor: FloatOrInt<0, 100>, | |
| 191 | 193 | } |
| 192 | 194 | |
| 193 | 195 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| @@ -208,6 +210,8 @@ pub struct Mouse { | ||
| 208 | 210 | pub left_handed: bool, |
| 209 | 211 | #[knuffel(child)] |
| 210 | 212 | pub middle_emulation: bool, |
| 213 | + #[knuffel(child, unwrap(argument), default = FloatOrInt(1.0))] | |
| 214 | + pub scroll_factor: FloatOrInt<0, 100>, | |
| 211 | 215 | } |
| 212 | 216 | |
| 213 | 217 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| @@ -2958,6 +2962,7 @@ mod tests { | ||
| 2958 | 2962 | scroll-button 272 |
| 2959 | 2963 | tap-button-map "left-middle-right" |
| 2960 | 2964 | disabled-on-external-mouse |
| 2965 | + scroll-factor 0.9 | |
| 2961 | 2966 | } |
| 2962 | 2967 | |
| 2963 | 2968 | mouse { |
| @@ -2967,6 +2972,7 @@ mod tests { | ||
| 2967 | 2972 | scroll-method "no-scroll" |
| 2968 | 2973 | scroll-button 273 |
| 2969 | 2974 | middle-emulation |
| 2975 | + scroll-factor 0.2 | |
| 2970 | 2976 | } |
| 2971 | 2977 | |
| 2972 | 2978 | trackpoint { |
| @@ -3169,6 +3175,7 @@ mod tests { | ||
| 3169 | 3175 | left_handed: false, |
| 3170 | 3176 | disabled_on_external_mouse: true, |
| 3171 | 3177 | middle_emulation: false, |
| 3178 | + scroll_factor: FloatOrInt(0.9), | |
| 3172 | 3179 | }, |
| 3173 | 3180 | mouse: Mouse { |
| 3174 | 3181 | off: false, |
| @@ -3179,6 +3186,7 @@ mod tests { | ||
| 3179 | 3186 | scroll_button: Some(273), |
| 3180 | 3187 | left_handed: false, |
| 3181 | 3188 | middle_emulation: true, |
| 3189 | + scroll_factor: FloatOrInt(0.2), | |
| 3182 | 3190 | }, |
| 3183 | 3191 | trackpoint: Trackpoint { |
| 3184 | 3192 | off: true, |
src/input/mod.rsmodified+11 -2
| @@ -1881,14 +1881,23 @@ impl State { | ||
| 1881 | 1881 | } |
| 1882 | 1882 | } |
| 1883 | 1883 | |
| 1884 | + let scroll_factor = match source { | |
| 1885 | + AxisSource::Wheel => self.niri.config.borrow().input.mouse.scroll_factor.0, | |
| 1886 | + AxisSource::Finger => self.niri.config.borrow().input.touchpad.scroll_factor.0, | |
| 1887 | + _ => 1.0, | |
| 1888 | + }; | |
| 1889 | + | |
| 1884 | 1890 | let horizontal_amount = horizontal_amount.unwrap_or_else(|| { |
| 1885 | 1891 | // Winit backend, discrete scrolling. |
| 1886 | 1892 | horizontal_amount_v120.unwrap_or(0.0) / 120. * 15. |
| 1887 | - }); | |
| 1893 | + }) * scroll_factor; | |
| 1888 | 1894 | let vertical_amount = vertical_amount.unwrap_or_else(|| { |
| 1889 | 1895 | // Winit backend, discrete scrolling. |
| 1890 | 1896 | vertical_amount_v120.unwrap_or(0.0) / 120. * 15. |
| 1891 | - }); | |
| 1897 | + }) * scroll_factor; | |
| 1898 | + | |
| 1899 | + let horizontal_amount_v120 = horizontal_amount_v120.map(|x| x * scroll_factor); | |
| 1900 | + let vertical_amount_v120 = vertical_amount_v120.map(|x| x * scroll_factor); | |
| 1892 | 1901 | |
| 1893 | 1902 | let mut frame = AxisFrame::new(event.time_msec()).source(source); |
| 1894 | 1903 | if horizontal_amount != 0.0 { |
wiki/Configuration:-Input.mdmodified+6 -0
| @@ -32,6 +32,7 @@ input { | ||
| 32 | 32 | natural-scroll |
| 33 | 33 | // accel-speed 0.2 |
| 34 | 34 | // accel-profile "flat" |
| 35 | + // scroll-factor 1.0 | |
| 35 | 36 | // scroll-method "two-finger" |
| 36 | 37 | // tap-button-map "left-middle-right" |
| 37 | 38 | // click-method "clickfinger" |
| @@ -45,6 +46,7 @@ input { | ||
| 45 | 46 | // natural-scroll |
| 46 | 47 | // accel-speed 0.2 |
| 47 | 48 | // accel-profile "flat" |
| 49 | + // scroll-factor 1.0 | |
| 48 | 50 | // scroll-method "no-scroll" |
| 49 | 51 | // left-handed |
| 50 | 52 | // middle-emulation |
| @@ -154,6 +156,10 @@ Settings specific to `touchpad`s: | ||
| 154 | 156 | - `click-method`: can be `button-areas` or `clickfinger`, changes the [click method](https://wayland.freedesktop.org/libinput/doc/latest/clickpad-softbuttons.html). |
| 155 | 157 | - `disabled-on-external-mouse`: do not send events while external pointer device is plugged in. |
| 156 | 158 | |
| 159 | +Settings specific to `touchpad` and `mouse`: | |
| 160 | + | |
| 161 | +- `scroll-factor`: scales the scrolling by this value. | |
| 162 | + | |
| 157 | 163 | Settings specific to `touchpad`, `mouse` and `tablet`: |
| 158 | 164 | |
| 159 | 165 | - `left-handed`: if set, changes the device to left-handed mode. |