Repository: wezterm/wezterm (language: rust)

Issue:
Scroll unfocused pane
### What Operating System(s) are you seeing this problem on?

macOS

### Which Wayland compositor or X11 Window manager(s) are you using?

_No response_

### WezTerm version

20220807-193129-ac3a9c00

### Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

### Describe the bug

Seemingly similar to https://github.com/wez/wezterm/issues/1437. Cannot scroll on a pane which is unfocused, it will instead scroll the currently active pane.

### To Reproduce

Create two panes, attempt to scroll on the inactive one.

### Configuration

no config

### Expected Behavior

(It should be possible to enable the behavior that) scrolling over the inactive pane should scroll the hovered pane, not the currently focused one.

### Logs

_No response_

### Anything else?

I could imagine this behavior not being desirable to people, given the lack of mention of it that i can find in config/issues, so perhaps a there ought to be a config option?


Discussion / hints:
I am seeing this as well on Ubuntu 22.04 with WezTerm 20220907-164742-2bbad26d and on macOS 12.6.1 with WezTerm 20220905-102802-7d4b8249.

If the inactive pane has mouse reporting on, I can scroll the hovered inactive pane as expected. However, if the inactive pane has mouse reporting disabled, I cannot scroll on it, for example to access the scrollback. Instead, the scroll input gets sent to the active pane.
oh, it's indeed the case..

`wezterm 20230419-102940-048e8dd1`

The pane under the cursor remains in the same position, and the active pane scrolls instead.
Dear @wez, can I provide some logs to nail the issue down? `debug_key_events` unfortunately doesn't show anything

#### Update
Interesting observation:

The inactive pane with opened vim receives the scroll event, scroll moves the cursor up and down. I guess, I'll rather record the screencast to demonstrate it


https://user-images.githubusercontent.com/3025537/233778842-f40ac0e6-1d13-450c-97fb-12aadc439831.mp4

It looks to me, that the terminal sends and processes different events to panes. See, inactive vim pane actually scrolls back and forth, instead of processing the actual scroll wheel.
What is odd to me is that if I have Pane A: Neovim, Pane B: shell and Pane C: shell, and have Pane C focused, i can't scroll pane B but I can scroll Pane A that has neovim in it.

Edit: 🤦i read the above comment more closely and it says the same thing as me.

Fix patch:
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 8106f4f5fcd..715f858debe 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -2360,22 +2360,18 @@ impl TermWindow {
         Ok(())
     }
 
-    fn scroll_by_current_event_wheel_delta(&mut self) -> anyhow::Result<()> {
+    fn scroll_by_current_event_wheel_delta(&mut self, pane: &Arc<dyn Pane>) -> anyhow::Result<()> {
         if let Some(event) = &self.current_mouse_event {
             let amount = match event.kind {
                 MouseEventKind::VertWheel(amount) => -amount,
                 _ => return Ok(()),
             };
-            self.scroll_by_line(amount.into())?;
+            self.scroll_by_line(amount.into(), pane)?;
         }
         Ok(())
     }
 
-    fn scroll_by_line(&mut self, amount: isize) -> anyhow::Result<()> {
-        let pane = match self.get_active_pane_or_overlay() {
-            Some(pane) => pane,
-            None => return Ok(()),
-        };
+    fn scroll_by_line(&mut self, amount: isize, pane: &Arc<dyn Pane>) -> anyhow::Result<()> {
         let dims = pane.get_dimensions();
         let position = self
             .get_viewport(pane.pane_id())
@@ -2583,8 +2579,8 @@ impl TermWindow {
             MoveTab(n) => self.move_tab(*n)?,
             MoveTabRelative(n) => self.move_tab_relative(*n)?,
             ScrollByPage(n) => self.scroll_by_page(**n)?,
-            ScrollByLine(n) => self.scroll_by_line(*n)?,
-            ScrollByCurrentEventWheelDelta => self.scroll_by_current_event_wheel_delta()?,
+            ScrollByLine(n) => self.scroll_by_line(*n, pane)?,
+            ScrollByCurrentEventWheelDelta => self.scroll_by_current_event_wheel_delta(pane)?,
             ScrollToPrompt(n) => self.scroll_to_prompt(*n)?,
             ScrollToTop => self.scroll_to_top(pane),
             ScrollToBottom => self.scroll_to_bottom(pane),


Test patch: