From 3434ef26f7b069b968999b3e5a35969e76872502 Mon Sep 17 00:00:00 2001
From: bbb651 <bar.ye651@gmail.com>
Date: Tue, 21 Jan 2025 14:06:53 +0200
Subject: [PATCH] Use pointer focus for `scroll-factor` window rule

Instead of window under pointer position, to properly
deal with pointer grabs.
---
 src/input/mod.rs | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/input/mod.rs b/src/input/mod.rs
index 8ddab8dd4..3fb6b1a77 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -2021,6 +2021,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
@@ -2167,14 +2169,16 @@ 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 window_scroll_factor = self
-            .niri
-            .window_under_cursor()
+        let window_scroll_factor = pointer
+            .current_focus()
+            .and_then(|focused| self.niri.layout.find_window_and_output(&focused).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.);
@@ -2218,9 +2222,6 @@ impl State {
             }
         }
 
-        self.update_pointer_contents();
-
-        let pointer = &self.niri.seat.get_pointer().unwrap();
         pointer.axis(self, frame);
         pointer.frame(self);
     }