forge
Explore
Log in

Don't you dare go Hollow

Add per-axis scroll speed config for input devices (#2109)

Browse files at this commit

5ea9092a4954f8c5cd795f0ebec910666b367d5fUnverifiedBernardo Kuri and Bernardo Kuri,
+2 others
  • Claude
  • Ivan Molodetskikh
Parent: 43a2648
* Add per-axis scroll speed config for input devices.

Accepts negative values to inverse scroll direction.

Properly complements/overrides global `scroll-direction` setting.

Includes docs and tests.

* Update per-axis scroll factor implementation after testing

- Refined configuration structure in niri-config
- Updated input handling to use per-axis scroll factors
- Added comprehensive test snapshots
- Updated documentation with per-axis examples

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Simplify per-axis scroll factor implementation per review feedback

- Make documentation concise and clear
- Remove unnecessary comments and test helper functions
- Use inline snapshots for tests
- Rename get_factors() to h_v_factors() for clarity
- Remove unnecessary .clone() calls (ScrollFactor is Copy)
- Reduce test count to essential cases only
- Fix comment about window factor override behavior

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Remove unnecessary ScrollFactor::new() helper function

The maintainer prefers minimal code, so removing this helper and
constructing ScrollFactor directly in tests.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix scroll factor behavior - all settings now multiply with window factor

Per maintainer feedback, both combined and per-axis scroll settings
should multiply with the window-specific scroll factor, not override it.
This ensures consistent behavior regardless of configuration method.

Also removed the now-unused has_per_axis_override() method.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Final cleanup: remove redundant comments and unused snapshot files

- Removed unused snapshot files (now using inline snapshots)
- Removed redundant inline comments in tests
- Simplified test descriptions to be more concise

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Convert scroll factor parsing tests to use assert_debug_snapshot

Updates parse_scroll_factor_combined, parse_scroll_factor_split, and
parse_scroll_factor_partial tests to use assert_debug_snapshot instead
of manual assert_eq comparisons, as requested in PR review.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Convert to inline snapshots as requested

- Convert all scroll factor parsing tests to use inline snapshots instead of external files
- Remove external snapshot files to keep test directory clean
- All tests still pass with inline snapshot assertions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix missed assert_eq in parse_scroll_factor_mixed test

Converts the remaining assert_eq calls to assert_debug_snapshot
with inline snapshots in the mixed syntax test function.
Also fixes raw string delimiters from ### to #.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Convert scroll_factor_h_v_factors test to use assert_debug_snapshot

Makes all scroll factor tests consistent by using snapshots instead
of assert_eq for better maintainability.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fixes

---------
docs/wiki/Configuration:-Input.mdmodified+4 -0
@@ -37,6 +37,7 @@ input {
37 // accel-speed 0.237 // accel-speed 0.2
38 // accel-profile "flat"38 // accel-profile "flat"
39 // scroll-factor 1.039 // scroll-factor 1.0
40+ // scroll-factor vertical=1.0 horizontal=-2.0
40 // scroll-method "two-finger"41 // scroll-method "two-finger"
41 // scroll-button 27342 // scroll-button 273
42 // scroll-button-lock43 // scroll-button-lock
@@ -53,6 +54,7 @@ input {
53 // accel-speed 0.254 // accel-speed 0.2
54 // accel-profile "flat"55 // accel-profile "flat"
55 // scroll-factor 1.056 // scroll-factor 1.0
57+ // scroll-factor vertical=1.0 horizontal=-2.0
56 // scroll-method "no-scroll"58 // scroll-method "no-scroll"
57 // scroll-button 27359 // scroll-button 273
58 // scroll-button-lock60 // scroll-button-lock
@@ -252,6 +254,8 @@ Settings specific to `touchpad` and `mouse`:
252 254
253 - `scroll-factor`: <sup>Since: 0.1.10</sup> scales the scrolling speed by this value.255 - `scroll-factor`: <sup>Since: 0.1.10</sup> scales the scrolling speed by this value.
254 256
257+ <sup>Since: next release</sup> You can also override horizontal and vertical scroll factor separately like so: `scroll-factor horizontal=2.0 vertical=-1.0`
258+
255 Settings specific to `tablet`s:259 Settings specific to `tablet`s:
256 260
257 - `calibration-matrix`: <sup>Since: 25.02</sup> set to six floating point numbers to change the calibration matrix. See the [`LIBINPUT_CALIBRATION_MATRIX` documentation](https://wayland.freedesktop.org/libinput/doc/latest/device-configuration-via-udev.html) for examples.261 - `calibration-matrix`: <sup>Since: 25.02</sup> set to six floating point numbers to change the calibration matrix. See the [`LIBINPUT_CALIBRATION_MATRIX` documentation](https://wayland.freedesktop.org/libinput/doc/latest/device-configuration-via-udev.html) for examples.
niri-config/src/lib.rsmodified+272 -10
@@ -191,6 +191,25 @@ pub enum TrackLayout {
191 Window,191 Window,
192 }192 }
193 193
194+#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq)]
195+pub struct ScrollFactor {
196+ #[knuffel(argument)]
197+ pub base: Option<FloatOrInt<0, 100>>,
198+ #[knuffel(property)]
199+ pub horizontal: Option<FloatOrInt<-100, 100>>,
200+ #[knuffel(property)]
201+ pub vertical: Option<FloatOrInt<-100, 100>>,
202+}
203+
204+impl ScrollFactor {
205+ pub fn h_v_factors(&self) -> (f64, f64) {
206+ let base_value = self.base.map(|f| f.0).unwrap_or(1.0);
207+ let h = self.horizontal.map(|f| f.0).unwrap_or(base_value);
208+ let v = self.vertical.map(|f| f.0).unwrap_or(base_value);
209+ (h, v)
210+ }
211+}
212+
194 #[derive(knuffel::Decode, Debug, Default, PartialEq)]213 #[derive(knuffel::Decode, Debug, Default, PartialEq)]
195 pub struct Touchpad {214 pub struct Touchpad {
196 #[knuffel(child)]215 #[knuffel(child)]
@@ -227,8 +246,8 @@ pub struct Touchpad {
227 pub disabled_on_external_mouse: bool,246 pub disabled_on_external_mouse: bool,
228 #[knuffel(child)]247 #[knuffel(child)]
229 pub middle_emulation: bool,248 pub middle_emulation: bool,
230- #[knuffel(child, unwrap(argument))]249+ #[knuffel(child)]
231- pub scroll_factor: Option<FloatOrInt<0, 100>>,250+ pub scroll_factor: Option<ScrollFactor>,
232 }251 }
233 252
234 #[derive(knuffel::Decode, Debug, Default, PartialEq)]253 #[derive(knuffel::Decode, Debug, Default, PartialEq)]
@@ -251,8 +270,8 @@ pub struct Mouse {
251 pub left_handed: bool,270 pub left_handed: bool,
252 #[knuffel(child)]271 #[knuffel(child)]
253 pub middle_emulation: bool,272 pub middle_emulation: bool,
254- #[knuffel(child, unwrap(argument))]273+ #[knuffel(child)]
255- pub scroll_factor: Option<FloatOrInt<0, 100>>,274+ pub scroll_factor: Option<ScrollFactor>,
256 }275 }
257 276
258 #[derive(knuffel::Decode, Debug, Default, PartialEq)]277 #[derive(knuffel::Decode, Debug, Default, PartialEq)]
@@ -4054,6 +4073,237 @@ mod tests {
4054 .unwrap()4073 .unwrap()
4055 }4074 }
4056 4075
4076+ #[test]
4077+ fn parse_scroll_factor_combined() {
4078+ // Test combined scroll-factor syntax
4079+ let parsed = do_parse(
4080+ r#"
4081+ input {
4082+ mouse {
4083+ scroll-factor 2.0
4084+ }
4085+ touchpad {
4086+ scroll-factor 1.5
4087+ }
4088+ }
4089+ "#,
4090+ );
4091+
4092+ assert_debug_snapshot!(parsed.input.mouse.scroll_factor, @r#"
4093+ Some(
4094+ ScrollFactor {
4095+ base: Some(
4096+ FloatOrInt(
4097+ 2.0,
4098+ ),
4099+ ),
4100+ horizontal: None,
4101+ vertical: None,
4102+ },
4103+ )
4104+ "#);
4105+ assert_debug_snapshot!(parsed.input.touchpad.scroll_factor, @r#"
4106+ Some(
4107+ ScrollFactor {
4108+ base: Some(
4109+ FloatOrInt(
4110+ 1.5,
4111+ ),
4112+ ),
4113+ horizontal: None,
4114+ vertical: None,
4115+ },
4116+ )
4117+ "#);
4118+ }
4119+
4120+ #[test]
4121+ fn parse_scroll_factor_split() {
4122+ // Test split horizontal/vertical syntax
4123+ let parsed = do_parse(
4124+ r#"
4125+ input {
4126+ mouse {
4127+ scroll-factor horizontal=2.0 vertical=-1.0
4128+ }
4129+ touchpad {
4130+ scroll-factor horizontal=-1.5 vertical=0.5
4131+ }
4132+ }
4133+ "#,
4134+ );
4135+
4136+ assert_debug_snapshot!(parsed.input.mouse.scroll_factor, @r#"
4137+ Some(
4138+ ScrollFactor {
4139+ base: None,
4140+ horizontal: Some(
4141+ FloatOrInt(
4142+ 2.0,
4143+ ),
4144+ ),
4145+ vertical: Some(
4146+ FloatOrInt(
4147+ -1.0,
4148+ ),
4149+ ),
4150+ },
4151+ )
4152+ "#);
4153+ assert_debug_snapshot!(parsed.input.touchpad.scroll_factor, @r#"
4154+ Some(
4155+ ScrollFactor {
4156+ base: None,
4157+ horizontal: Some(
4158+ FloatOrInt(
4159+ -1.5,
4160+ ),
4161+ ),
4162+ vertical: Some(
4163+ FloatOrInt(
4164+ 0.5,
4165+ ),
4166+ ),
4167+ },
4168+ )
4169+ "#);
4170+ }
4171+
4172+ #[test]
4173+ fn parse_scroll_factor_partial() {
4174+ // Test partial specification (only one axis)
4175+ let parsed = do_parse(
4176+ r#"
4177+ input {
4178+ mouse {
4179+ scroll-factor horizontal=2.0
4180+ }
4181+ touchpad {
4182+ scroll-factor vertical=-1.5
4183+ }
4184+ }
4185+ "#,
4186+ );
4187+
4188+ assert_debug_snapshot!(parsed.input.mouse.scroll_factor, @r#"
4189+ Some(
4190+ ScrollFactor {
4191+ base: None,
4192+ horizontal: Some(
4193+ FloatOrInt(
4194+ 2.0,
4195+ ),
4196+ ),
4197+ vertical: None,
4198+ },
4199+ )
4200+ "#);
4201+ assert_debug_snapshot!(parsed.input.touchpad.scroll_factor, @r#"
4202+ Some(
4203+ ScrollFactor {
4204+ base: None,
4205+ horizontal: None,
4206+ vertical: Some(
4207+ FloatOrInt(
4208+ -1.5,
4209+ ),
4210+ ),
4211+ },
4212+ )
4213+ "#);
4214+ }
4215+
4216+ #[test]
4217+ fn parse_scroll_factor_mixed() {
4218+ // Test mixed base + override syntax
4219+ let parsed = do_parse(
4220+ r#"
4221+ input {
4222+ mouse {
4223+ scroll-factor 2 vertical=-1
4224+ }
4225+ touchpad {
4226+ scroll-factor 1.5 horizontal=3
4227+ }
4228+ }
4229+ "#,
4230+ );
4231+
4232+ assert_debug_snapshot!(parsed.input.mouse.scroll_factor, @r#"
4233+ Some(
4234+ ScrollFactor {
4235+ base: Some(
4236+ FloatOrInt(
4237+ 2.0,
4238+ ),
4239+ ),
4240+ horizontal: None,
4241+ vertical: Some(
4242+ FloatOrInt(
4243+ -1.0,
4244+ ),
4245+ ),
4246+ },
4247+ )
4248+ "#);
4249+ assert_debug_snapshot!(parsed.input.touchpad.scroll_factor, @r#"
4250+ Some(
4251+ ScrollFactor {
4252+ base: Some(
4253+ FloatOrInt(
4254+ 1.5,
4255+ ),
4256+ ),
4257+ horizontal: Some(
4258+ FloatOrInt(
4259+ 3.0,
4260+ ),
4261+ ),
4262+ vertical: None,
4263+ },
4264+ )
4265+ "#);
4266+ }
4267+
4268+ #[test]
4269+ fn scroll_factor_h_v_factors() {
4270+ let sf = ScrollFactor {
4271+ base: Some(FloatOrInt(2.0)),
4272+ horizontal: None,
4273+ vertical: None,
4274+ };
4275+ assert_debug_snapshot!(sf.h_v_factors(), @r#"
4276+ (
4277+ 2.0,
4278+ 2.0,
4279+ )
4280+ "#);
4281+
4282+ let sf = ScrollFactor {
4283+ base: None,
4284+ horizontal: Some(FloatOrInt(3.0)),
4285+ vertical: Some(FloatOrInt(-1.0)),
4286+ };
4287+ assert_debug_snapshot!(sf.h_v_factors(), @r#"
4288+ (
4289+ 3.0,
4290+ -1.0,
4291+ )
4292+ "#);
4293+
4294+ let sf = ScrollFactor {
4295+ base: Some(FloatOrInt(2.0)),
4296+ horizontal: Some(FloatOrInt(1.0)),
4297+ vertical: None,
4298+ };
4299+ assert_debug_snapshot!(sf.h_v_factors(), @r"
4300+ (
4301+ 1.0,
4302+ 2.0,
4303+ )
4304+ ");
4305+ }
4306+
4057 #[test]4307 #[test]
4058 fn parse() {4308 fn parse() {
4059 let parsed = do_parse(4309 let parsed = do_parse(
@@ -4370,9 +4620,15 @@ mod tests {
4370 disabled_on_external_mouse: true,4620 disabled_on_external_mouse: true,
4371 middle_emulation: false,4621 middle_emulation: false,
4372 scroll_factor: Some(4622 scroll_factor: Some(
4373- FloatOrInt(4623+ ScrollFactor {
4374- 0.9,4624+ base: Some(
4375- ),4625+ FloatOrInt(
4626+ 0.9,
4627+ ),
4628+ ),
4629+ horizontal: None,
4630+ vertical: None,
4631+ },
4376 ),4632 ),
4377 },4633 },
4378 mouse: Mouse {4634 mouse: Mouse {
@@ -4394,9 +4650,15 @@ mod tests {
4394 left_handed: false,4650 left_handed: false,
4395 middle_emulation: true,4651 middle_emulation: true,
4396 scroll_factor: Some(4652 scroll_factor: Some(
4397- FloatOrInt(4653+ ScrollFactor {
4398- 0.2,4654+ base: Some(
4399- ),4655+ FloatOrInt(
4656+ 0.2,
4657+ ),
4658+ ),
4659+ horizontal: None,
4660+ vertical: None,
4661+ },
4400 ),4662 ),
4401 },4663 },
4402 trackpoint: Trackpoint {4664 trackpoint: Trackpoint {
src/input/mod.rsmodified+24 -11
@@ -3086,31 +3086,44 @@ impl State {
3086 3086
3087 self.update_pointer_contents();3087 self.update_pointer_contents();
3088 3088
3089- let scroll_factor = match source {3089+ let device_scroll_factor = {
3090- AxisSource::Wheel => self.niri.config.borrow().input.mouse.scroll_factor,3090+ let config = self.niri.config.borrow();
3091- AxisSource::Finger => self.niri.config.borrow().input.touchpad.scroll_factor,3091+ match source {
3092- _ => None,3092+ AxisSource::Wheel => config.input.mouse.scroll_factor,
3093+ AxisSource::Finger => config.input.touchpad.scroll_factor,
3094+ _ => None,
3095+ }
3093 };3096 };
3094- let scroll_factor = scroll_factor.map(|x| x.0).unwrap_or(1.);
3095 3097
3098+ // Get window-specific scroll factor
3096 let window_scroll_factor = pointer3099 let window_scroll_factor = pointer
3097 .current_focus()3100 .current_focus()
3098 .map(|focused| self.niri.find_root_shell_surface(&focused))3101 .map(|focused| self.niri.find_root_shell_surface(&focused))
3099 .and_then(|root| self.niri.layout.find_window_and_output(&root).unzip().0)3102 .and_then(|root| self.niri.layout.find_window_and_output(&root).unzip().0)
3100- .and_then(|window| window.rules().scroll_factor);3103+ .and_then(|window| window.rules().scroll_factor)
3101- let scroll_factor = scroll_factor * window_scroll_factor.unwrap_or(1.);3104+ .unwrap_or(1.);
3105+
3106+ // Determine final scroll factors based on configuration
3107+ let (horizontal_factor, vertical_factor) = device_scroll_factor
3108+ .map(|x| x.h_v_factors())
3109+ .unwrap_or((1.0, 1.0));
3110+ let (horizontal_factor, vertical_factor) = (
3111+ horizontal_factor * window_scroll_factor,
3112+ vertical_factor * window_scroll_factor,
3113+ );
3102 3114
3103 let horizontal_amount = horizontal_amount.unwrap_or_else(|| {3115 let horizontal_amount = horizontal_amount.unwrap_or_else(|| {
3104 // Winit backend, discrete scrolling.3116 // Winit backend, discrete scrolling.
3105 horizontal_amount_v120.unwrap_or(0.0) / 120. * 15.3117 horizontal_amount_v120.unwrap_or(0.0) / 120. * 15.
3106- }) * scroll_factor;3118+ }) * horizontal_factor;
3119+
3107 let vertical_amount = vertical_amount.unwrap_or_else(|| {3120 let vertical_amount = vertical_amount.unwrap_or_else(|| {
3108 // Winit backend, discrete scrolling.3121 // Winit backend, discrete scrolling.
3109 vertical_amount_v120.unwrap_or(0.0) / 120. * 15.3122 vertical_amount_v120.unwrap_or(0.0) / 120. * 15.
3110- }) * scroll_factor;3123+ }) * vertical_factor;
3111 3124
3112- let horizontal_amount_v120 = horizontal_amount_v120.map(|x| x * scroll_factor);3125+ let horizontal_amount_v120 = horizontal_amount_v120.map(|x| x * horizontal_factor);
3113- let vertical_amount_v120 = vertical_amount_v120.map(|x| x * scroll_factor);3126+ let vertical_amount_v120 = vertical_amount_v120.map(|x| x * vertical_factor);
3114 3127
3115 let mut frame = AxisFrame::new(event.time_msec()).source(source);3128 let mut frame = AxisFrame::new(event.time_msec()).source(source);
3116 if horizontal_amount != 0.0 {3129 if horizontal_amount != 0.0 {