Skip to content

Commit

Permalink
Add scroll-factor window rule
Browse files Browse the repository at this point in the history
Fixes YaLTeR#909.
  • Loading branch information
bbb651 committed Jan 20, 2025
1 parent bd559a2 commit 312246a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions niri-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,8 @@ pub struct WindowRule {
pub variable_refresh_rate: Option<bool>,
#[knuffel(child)]
pub default_floating_position: Option<FloatingPosition>,
#[knuffel(child, unwrap(argument))]
pub scroll_factor: Option<FloatOrInt<0, 100>>,
}

#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
Expand Down
8 changes: 7 additions & 1 deletion src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,

/// Multiplier for all scroll events sent to this window.
pub scroll_factor: Option<f64>,
}

impl<'a> WindowRef<'a> {
Expand Down Expand Up @@ -190,6 +193,7 @@ impl ResolvedWindowRules {
clip_to_geometry: None,
block_out_from: None,
variable_refresh_rate: None,
scroll_factor: None,
}
}

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 312246a

Please sign in to comment.