aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbbb651 <bar.ye651@gmail.com>2025-01-20 22:52:43 +0200
committerIvan Molodetskikh <yalterz@gmail.com>2025-01-23 12:07:32 +0300
commit128b01e04905d833214f52a3c6fab308bcc15ce0 (patch)
tree80a7877972b946f5dde1848691f8a34529d15ba7
parent788c9c6c545c016687b024d28f2806055ddb9fc8 (diff)
downloadniri-128b01e04905d833214f52a3c6fab308bcc15ce0.tar.gz
niri-128b01e04905d833214f52a3c6fab308bcc15ce0.tar.bz2
niri-128b01e04905d833214f52a3c6fab308bcc15ce0.zip
Add `scroll-factor` window rule
-rw-r--r--niri-config/src/lib.rs2
-rw-r--r--src/input/mod.rs15
-rw-r--r--src/window/mod.rs7
-rw-r--r--wiki/Configuration:-Window-Rules.md18
4 files changed, 38 insertions, 4 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs
index 2fd3d45c..11da976e 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<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)]
diff --git a/src/input/mod.rs b/src/input/mod.rs
index c9ab0b30..12746376 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -2086,6 +2086,8 @@ impl State {
}
fn on_pointer_axis<I: InputBackend>(&mut self, event: I::PointerAxisEvent) {
+ let pointer = &self.niri.seat.get_pointer().unwrap();
+
let source = event.source();
// We received an event for the regular pointer, so show it now. This is also needed for
@@ -2232,12 +2234,20 @@ impl State {
}
}
+ self.update_pointer_contents();
+
let scroll_factor = match source {
AxisSource::Wheel => self.niri.config.borrow().input.mouse.scroll_factor,
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 = pointer
+ .current_focus()
+ .map(|focused| self.niri.find_root_shell_surface(&focused))
+ .and_then(|root| self.niri.layout.find_window_and_output(&root).unzip().0)
+ .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.
@@ -2278,9 +2288,6 @@ impl State {
}
}
- self.update_pointer_contents();
-
- let pointer = &self.niri.seat.get_pointer().unwrap();
pointer.axis(self, frame);
pointer.frame(self);
}
diff --git a/src/window/mod.rs b/src/window/mod.rs
index 189049b3..84c33d5e 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<bool>,
+
+ /// Multiplier for all scroll events sent to this window.
+ pub scroll_factor: Option<f64>,
}
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());
diff --git a/wiki/Configuration:-Window-Rules.md b/wiki/Configuration:-Window-Rules.md
index cd0a65b2..5fa44021 100644
--- a/wiki/Configuration:-Window-Rules.md
+++ b/wiki/Configuration:-Window-Rules.md
@@ -53,6 +53,7 @@ window-rule {
// block-out-from "screen-capture"
variable-refresh-rate true
default-floating-position x=100 y=200 relative-to="bottom-left"
+ scroll-factor 0.75
focus-ring {
// off
@@ -557,6 +558,23 @@ window-rule {
}
```
+#### `scroll-factor`
+
+<sup>Since: next release</sup>
+
+Set a scroll factor for all scroll events sent to a window.
+
+This will be multiplied with the scroll factor set for your input device in the [input](/wiki/Configuration:-Input.md) section.
+
+```kdl
+// Make scrolling in Firefox a bit slower.
+window-rule {
+ match app-id="firefox$"
+
+ scroll-factor 0.75
+}
+```
+
#### `draw-border-with-background`
Override whether the border and the focus ring draw with a background.