From d3df2920d0d1064c54923e6367bf30b7638eaf95 Mon Sep 17 00:00:00 2001 From: Autumn Lamonte <4357501+klamonte@users.noreply.github.com> Date: Sun, 16 Jan 2022 20:31:56 -0600 Subject: [PATCH] Filter out per-pixel mouse movement when not in SGR-Pixels mode (#1549) * #1457 Initial commit compiles but doesn't yet work * #1457 Fix cell offsets * #1457 refactor, ClickPosition * fix nits * #1457 filter per-pixel motion when not in SGR-Pixels mode * Much cleaner match condition for filtering mouse events based on encoding protocol --- term/src/terminalstate/mouse.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/term/src/terminalstate/mouse.rs b/term/src/terminalstate/mouse.rs index 089552fb4..fc82f8887 100644 --- a/term/src/terminalstate/mouse.rs +++ b/term/src/terminalstate/mouse.rs @@ -186,7 +186,18 @@ impl TerminalState { } fn mouse_move(&mut self, event: MouseEvent) -> anyhow::Result<()> { - let reportable = self.any_event_mouse || !self.current_mouse_buttons.is_empty(); + let moved = match (&self.last_mouse_move, self.mouse_encoding) { + (None, _) => true, + (Some(last), MouseEncoding::SgrPixels) => { + last.x != event.x + || last.y != event.y + || last.x_pixel_offset != event.x_pixel_offset + || last.y_pixel_offset != event.y_pixel_offset + } + (Some(last), _) => last.x != event.x || last.y != event.y, + }; + + let reportable = (self.any_event_mouse || !self.current_mouse_buttons.is_empty()) && moved; // Note: self.mouse_tracking on its own is for clicks, not drags! if reportable && (self.button_event_mouse || self.any_event_mouse) { match self.last_mouse_move.as_ref() {