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 | pub disabled_on_external_mouse: bool, | 188 | pub disabled_on_external_mouse: bool, |
| 189 | #[knuffel(child)] | 189 | #[knuffel(child)] |
| 190 | pub middle_emulation: bool, | 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 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] | 195 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| @@ -208,6 +210,8 @@ pub struct Mouse { | |||
| 208 | pub left_handed: bool, | 210 | pub left_handed: bool, |
| 209 | #[knuffel(child)] | 211 | #[knuffel(child)] |
| 210 | pub middle_emulation: bool, | 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 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] | 217 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| @@ -2958,6 +2962,7 @@ mod tests { | |||
| 2958 | scroll-button 272 | 2962 | scroll-button 272 |
| 2959 | tap-button-map "left-middle-right" | 2963 | tap-button-map "left-middle-right" |
| 2960 | disabled-on-external-mouse | 2964 | disabled-on-external-mouse |
| 2965 | + scroll-factor 0.9 | ||
| 2961 | } | 2966 | } |
| 2962 | 2967 | ||
| 2963 | mouse { | 2968 | mouse { |
| @@ -2967,6 +2972,7 @@ mod tests { | |||
| 2967 | scroll-method "no-scroll" | 2972 | scroll-method "no-scroll" |
| 2968 | scroll-button 273 | 2973 | scroll-button 273 |
| 2969 | middle-emulation | 2974 | middle-emulation |
| 2975 | + scroll-factor 0.2 | ||
| 2970 | } | 2976 | } |
| 2971 | 2977 | ||
| 2972 | trackpoint { | 2978 | trackpoint { |
| @@ -3169,6 +3175,7 @@ mod tests { | |||
| 3169 | left_handed: false, | 3175 | left_handed: false, |
| 3170 | disabled_on_external_mouse: true, | 3176 | disabled_on_external_mouse: true, |
| 3171 | middle_emulation: false, | 3177 | middle_emulation: false, |
| 3178 | + scroll_factor: FloatOrInt(0.9), | ||
| 3172 | }, | 3179 | }, |
| 3173 | mouse: Mouse { | 3180 | mouse: Mouse { |
| 3174 | off: false, | 3181 | off: false, |
| @@ -3179,6 +3186,7 @@ mod tests { | |||
| 3179 | scroll_button: Some(273), | 3186 | scroll_button: Some(273), |
| 3180 | left_handed: false, | 3187 | left_handed: false, |
| 3181 | middle_emulation: true, | 3188 | middle_emulation: true, |
| 3189 | + scroll_factor: FloatOrInt(0.2), | ||
| 3182 | }, | 3190 | }, |
| 3183 | trackpoint: Trackpoint { | 3191 | trackpoint: Trackpoint { |
| 3184 | off: true, | 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 | let horizontal_amount = horizontal_amount.unwrap_or_else(|| { | 1890 | let horizontal_amount = horizontal_amount.unwrap_or_else(|| { |
| 1885 | // Winit backend, discrete scrolling. | 1891 | // Winit backend, discrete scrolling. |
| 1886 | horizontal_amount_v120.unwrap_or(0.0) / 120. * 15. | 1892 | horizontal_amount_v120.unwrap_or(0.0) / 120. * 15. |
| 1887 | - }); | 1893 | + }) * scroll_factor; |
| 1888 | let vertical_amount = vertical_amount.unwrap_or_else(|| { | 1894 | let vertical_amount = vertical_amount.unwrap_or_else(|| { |
| 1889 | // Winit backend, discrete scrolling. | 1895 | // Winit backend, discrete scrolling. |
| 1890 | vertical_amount_v120.unwrap_or(0.0) / 120. * 15. | 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 | let mut frame = AxisFrame::new(event.time_msec()).source(source); | 1902 | let mut frame = AxisFrame::new(event.time_msec()).source(source); |
| 1894 | if horizontal_amount != 0.0 { | 1903 | if horizontal_amount != 0.0 { |
wiki/Configuration:-Input.mdmodified+6 -0
| @@ -32,6 +32,7 @@ input { | |||
| 32 | natural-scroll | 32 | natural-scroll |
| 33 | // accel-speed 0.2 | 33 | // accel-speed 0.2 |
| 34 | // accel-profile "flat" | 34 | // accel-profile "flat" |
| 35 | + // scroll-factor 1.0 | ||
| 35 | // scroll-method "two-finger" | 36 | // scroll-method "two-finger" |
| 36 | // tap-button-map "left-middle-right" | 37 | // tap-button-map "left-middle-right" |
| 37 | // click-method "clickfinger" | 38 | // click-method "clickfinger" |
| @@ -45,6 +46,7 @@ input { | |||
| 45 | // natural-scroll | 46 | // natural-scroll |
| 46 | // accel-speed 0.2 | 47 | // accel-speed 0.2 |
| 47 | // accel-profile "flat" | 48 | // accel-profile "flat" |
| 49 | + // scroll-factor 1.0 | ||
| 48 | // scroll-method "no-scroll" | 50 | // scroll-method "no-scroll" |
| 49 | // left-handed | 51 | // left-handed |
| 50 | // middle-emulation | 52 | // middle-emulation |
| @@ -154,6 +156,10 @@ Settings specific to `touchpad`s: | |||
| 154 | - `click-method`: can be `button-areas` or `clickfinger`, changes the [click method](https://wayland.freedesktop.org/libinput/doc/latest/clickpad-softbuttons.html). | 156 | - `click-method`: can be `button-areas` or `clickfinger`, changes the [click method](https://wayland.freedesktop.org/libinput/doc/latest/clickpad-softbuttons.html). |
| 155 | - `disabled-on-external-mouse`: do not send events while external pointer device is plugged in. | 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 | Settings specific to `touchpad`, `mouse` and `tablet`: | 163 | Settings specific to `touchpad`, `mouse` and `tablet`: |
| 158 | 164 | ||
| 159 | - `left-handed`: if set, changes the device to left-handed mode. | 165 | - `left-handed`: if set, changes the device to left-handed mode. |