From 312246ad786f417c74cbf990f021dd2cb991c5aa Mon Sep 17 00:00:00 2001 From: bbb651 Date: Mon, 20 Jan 2025 22:52:43 +0200 Subject: [PATCH] Add `scroll-factor` window rule Fixes #909. --- niri-config/src/lib.rs | 2 ++ src/input/mod.rs | 8 +++++++- src/window/mod.rs | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 167ef6ac3..7f2ea598b 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -1079,6 +1079,8 @@ pub struct WindowRule { pub variable_refresh_rate: Option, #[knuffel(child)] pub default_floating_position: Option, + #[knuffel(child, unwrap(argument))] + pub scroll_factor: Option>, } #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] diff --git a/src/input/mod.rs b/src/input/mod.rs index b08fe3808..8ddab8dd4 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -37,6 +37,7 @@ use self::move_grab::MoveGrab; use self::resize_grab::ResizeGrab; use self::spatial_movement_grab::SpatialMovementGrab; use crate::layout::scrolling::ScrollDirection; +use crate::layout::LayoutElement; use crate::niri::State; use crate::ui::screenshot_ui::ScreenshotUi; use crate::utils::spawning::spawn; @@ -2171,7 +2172,12 @@ impl State { AxisSource::Finger => self.niri.config.borrow().input.touchpad.scroll_factor, _ => None, }; - let scroll_factor = scroll_factor.map(|x| x.0).unwrap_or(1.); + let window_scroll_factor = self + .niri + .window_under_cursor() + .and_then(|window| window.rules().scroll_factor); + let scroll_factor = + scroll_factor.map(|x| x.0).unwrap_or(1.) * window_scroll_factor.unwrap_or(1.); let horizontal_amount = horizontal_amount.unwrap_or_else(|| { // Winit backend, discrete scrolling. diff --git a/src/window/mod.rs b/src/window/mod.rs index 189049b34..84c33d5ea 100644 --- a/src/window/mod.rs +++ b/src/window/mod.rs @@ -100,6 +100,9 @@ pub struct ResolvedWindowRules { /// Whether to enable VRR on this window's primary output if it is on-demand. pub variable_refresh_rate: Option, + + /// Multiplier for all scroll events sent to this window. + pub scroll_factor: Option, } impl<'a> WindowRef<'a> { @@ -190,6 +193,7 @@ impl ResolvedWindowRules { clip_to_geometry: None, block_out_from: None, variable_refresh_rate: None, + scroll_factor: None, } } @@ -301,6 +305,9 @@ impl ResolvedWindowRules { if let Some(x) = rule.variable_refresh_rate { resolved.variable_refresh_rate = Some(x); } + if let Some(x) = rule.scroll_factor { + resolved.scroll_factor = Some(x.0); + } } resolved.open_on_output = open_on_output.map(|x| x.to_owned());