From ef2674bab8a3b38984578473c1a80589ebcbb333 Mon Sep 17 00:00:00 2001 From: JJ Liebig Date: Mon, 31 Aug 2026 21:22:56 +0200 Subject: fix(windows): enable mouse reporting over openssh (#3461) refs #2810 --- src/terminal_modes.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/terminal_modes.rs') diff --git a/src/terminal_modes.rs b/src/terminal_modes.rs index 5b6a5d3b..c9f08ceb 100644 --- a/src/terminal_modes.rs +++ b/src/terminal_modes.rs @@ -6,6 +6,13 @@ use crossterm::event::{PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags const DISABLE_HOST_MOUSE_REPORTING_SEQUENCE: &[u8] = b"\x1b[?1006l\x1b[?1016l\x1b[?1015l\x1b[?1005l\x1b[?1003l\x1b[?1002l\x1b[?1000l"; +#[cfg(any(windows, test))] +const WINDOWS_SSH_MOUSE_REPORTING_ENABLE_SEQUENCE: &[u8] = + b"\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h"; +#[cfg(any(windows, test))] +const WINDOWS_SSH_MOUSE_REPORTING_DISABLE_SEQUENCE: &[u8] = + b"\x1b[?1016l\x1b[?1006l\x1b[?1003l\x1b[?1002l\x1b[?1000l"; + #[cfg(not(windows))] pub(crate) fn clear_host_mouse_reporting(writer: &mut W) -> io::Result<()> { writer.write_all(DISABLE_HOST_MOUSE_REPORTING_SEQUENCE)?; @@ -17,6 +24,27 @@ pub(crate) fn clear_host_mouse_reporting(_writer: &mut W) -> io::Resul Ok(()) } +#[cfg(any(windows, test))] +pub(crate) fn set_windows_ssh_mouse_reporting( + writer: &mut W, + enabled: bool, + sgr_pixels: bool, +) -> io::Result<()> { + writer.write_all(if enabled { + WINDOWS_SSH_MOUSE_REPORTING_ENABLE_SEQUENCE + } else { + WINDOWS_SSH_MOUSE_REPORTING_DISABLE_SEQUENCE + })?; + if enabled { + writer.write_all(if sgr_pixels { + b"\x1b[?1016h" + } else { + b"\x1b[?1016l" + })?; + } + writer.flush() +} + #[cfg(not(windows))] pub(crate) fn set_host_kitty_keyboard_report_all( writer: &mut W, @@ -73,4 +101,18 @@ mod tests { ); } } + + #[test] + fn windows_ssh_mouse_reporting_setup_and_teardown_request_required_modes() { + let mut output = Vec::new(); + + set_windows_ssh_mouse_reporting(&mut output, true, true).unwrap(); + set_windows_ssh_mouse_reporting(&mut output, true, false).unwrap(); + set_windows_ssh_mouse_reporting(&mut output, false, false).unwrap(); + + assert_eq!( + output, + b"\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h\x1b[?1016h\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h\x1b[?1016l\x1b[?1016l\x1b[?1006l\x1b[?1003l\x1b[?1002l\x1b[?1000l" + ); + } } -- cgit v1.2.3