diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-07-05 20:12:56 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-07-05 20:53:11 +0400 |
| commit | 1da99f4003c100180b4821afc4e32e35c86dfdb4 (patch) | |
| tree | 70f465e9e585e5547f79ad6ac94a0828de588ad9 /niri-config/src | |
| parent | 120eaa6c56491e284a6a1a8bfb49ef477b8c0854 (diff) | |
| download | niri-1da99f4003c100180b4821afc4e32e35c86dfdb4.tar.gz niri-1da99f4003c100180b4821afc4e32e35c86dfdb4.tar.bz2 niri-1da99f4003c100180b4821afc4e32e35c86dfdb4.zip | |
Implement focus-follows-mouse max-scroll-amount
Diffstat (limited to 'niri-config/src')
| -rw-r--r-- | niri-config/src/lib.rs | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index aaf81bc0..2946b8c8 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -75,7 +75,7 @@ pub struct Input { #[knuffel(child)] pub warp_mouse_to_focus: bool, #[knuffel(child)] - pub focus_follows_mouse: bool, + pub focus_follows_mouse: Option<FocusFollowsMouse>, #[knuffel(child)] pub workspace_auto_back_and_forth: bool, } @@ -289,6 +289,15 @@ pub struct Touch { pub map_to_output: Option<String>, } +#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] +pub struct FocusFollowsMouse { + #[knuffel(property, str)] + pub max_scroll_amount: Option<Percent>, +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Percent(pub f64); + #[derive(Debug, Default, Clone, PartialEq)] pub struct Outputs(pub Vec<Output>); @@ -1794,6 +1803,16 @@ where } impl Animation { + pub fn new_off() -> Self { + Self { + off: true, + kind: AnimationKind::Easing(EasingParams { + duration_ms: 0, + curve: AnimationCurve::Linear, + }), + } + } + fn decode_node<S: knuffel::traits::ErrorSpan>( node: &knuffel::ast::SpannedNode<S>, ctx: &mut knuffel::decode::Context<S>, @@ -2418,6 +2437,23 @@ impl FromStr for TapButtonMap { } } +impl FromStr for Percent { + type Err = miette::Error; + + fn from_str(s: &str) -> Result<Self, Self::Err> { + let Some((value, empty)) = s.split_once('%') else { + return Err(miette!("value must end with '%'")); + }; + + if !empty.is_empty() { + return Err(miette!("trailing characters after '%' are not allowed")); + } + + let value: f64 = value.parse().map_err(|_| miette!("error parsing value"))?; + Ok(Percent(value / 100.)) + } +} + pub fn set_miette_hook() -> Result<(), miette::InstallError> { miette::set_hook(Box::new(|_| Box::new(NarratableReportHandler::new()))) } @@ -2664,7 +2700,9 @@ mod tests { }, disable_power_key_handling: true, warp_mouse_to_focus: true, - focus_follows_mouse: true, + focus_follows_mouse: Some(FocusFollowsMouse { + max_scroll_amount: None, + }), workspace_auto_back_and_forth: true, }, outputs: Outputs(vec