diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-03 02:03:14 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-03 02:03:44 +0300 |
| commit | b695d7cbc0d29540993642c23b3d5798cbf9f7dc (patch) | |
| tree | d7243c891dca6c8991583edd7666ec9fe8cc6f94 /src/pane/terminal.rs | |
| parent | daf636fef7fd68bcb1e30cfb155883c3b831513c (diff) | |
fix: forward any-motion pane mouse events
refs #419
Diffstat (limited to 'src/pane/terminal.rs')
| -rw-r--r-- | src/pane/terminal.rs | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/src/pane/terminal.rs b/src/pane/terminal.rs index be1200e6..0a67f11a 100644 --- a/src/pane/terminal.rs +++ b/src/pane/terminal.rs @@ -16,8 +16,8 @@ use crate::protocol::CellData; use super::{ input::{ ghostty_key_event_from_terminal_key, ghostty_mouse_encoder_for_terminal, - ghostty_mouse_event_from_button_kind, ghostty_mouse_event_from_wheel_kind, - ghostty_prefers_herdr_text_encoding, + ghostty_mouse_event_from_button_kind, ghostty_mouse_event_from_motion_kind, + ghostty_mouse_event_from_wheel_kind, ghostty_prefers_herdr_text_encoding, }, kitty_keyboard::KittyKeyboardTracker, osc::{ @@ -283,6 +283,17 @@ impl PaneTerminal { .encode_mouse_button(kind, column, row, modifiers) } + pub fn encode_mouse_motion( + &self, + kind: crossterm::event::MouseEventKind, + column: u16, + row: u16, + modifiers: crossterm::event::KeyModifiers, + ) -> Option<Vec<u8>> { + self.ghostty + .encode_mouse_motion(kind, column, row, modifiers) + } + pub fn encode_mouse_wheel( &self, kind: crossterm::event::MouseEventKind, @@ -887,6 +898,24 @@ impl GhosttyPaneTerminal { encoder.encode(&event).ok() } + pub fn encode_mouse_motion( + &self, + kind: crossterm::event::MouseEventKind, + column: u16, + row: u16, + modifiers: crossterm::event::KeyModifiers, + ) -> Option<Vec<u8>> { + let Ok(core) = self.core.lock() else { + return None; + }; + if !core.terminal.mode_get(MODE_MOUSE_ANY_MOTION).ok()? { + return None; + } + let mut encoder = ghostty_mouse_encoder_for_terminal(&core.terminal)?; + let event = ghostty_mouse_event_from_motion_kind(kind, column, row, modifiers)?; + encoder.encode(&event).ok() + } + pub fn encode_mouse_wheel( &self, kind: crossterm::event::MouseEventKind, @@ -2351,6 +2380,40 @@ mod tests { } #[test] + fn ghostty_mouse_moved_encoding_uses_any_motion_state() { + let (tx, _rx) = mpsc::channel(4); + let mut terminal = crate::ghostty::Terminal::new(80, 24, 0).unwrap(); + terminal.write(b"\x1b[?1003h\x1b[?1006h"); + let pane = GhosttyPaneTerminal::new(terminal, tx).unwrap(); + + let encoded = pane.encode_mouse_motion( + crossterm::event::MouseEventKind::Moved, + 4, + 6, + crossterm::event::KeyModifiers::empty(), + ); + + assert_eq!(encoded.as_deref(), Some(&b"\x1b[<35;5;7M"[..])); + } + + #[test] + fn ghostty_mouse_sgr_pixels_downgrades_to_cell_coordinates() { + let (tx, _rx) = mpsc::channel(4); + let mut terminal = crate::ghostty::Terminal::new(80, 24, 0).unwrap(); + terminal.write(b"\x1b[?1003h\x1b[?1006h\x1b[?1016h"); + let pane = GhosttyPaneTerminal::new(terminal, tx).unwrap(); + + let encoded = pane.encode_mouse_motion( + crossterm::event::MouseEventKind::Moved, + 4, + 6, + crossterm::event::KeyModifiers::empty(), + ); + + assert_eq!(encoded.as_deref(), Some(&b"\x1b[<35;5;7M"[..])); + } + + #[test] fn ghostty_normalize_buffer_symbol_prefers_grapheme_width_when_metadata_disagrees() { const WIDE_GRAPHEME: &str = "🙂"; const VS16_GRAPHEME: &str = "⚠️"; |
