From 1f8bf8eaf1ba1902cb38fc016f0012b8b6d9ab85 Mon Sep 17 00:00:00 2001 From: barkure <43804451+barkure@users.noreply.github.com> Date: Tue, 7 Apr 2026 12:59:09 +0800 Subject: [PATCH 1/2] input: fix vertical scroll jitter on macOS touchpads --- crates/edit/src/input.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/edit/src/input.rs b/crates/edit/src/input.rs index bff72fc9b8a..ac79f453e18 100644 --- a/crates/edit/src/input.rs +++ b/crates/edit/src/input.rs @@ -444,7 +444,12 @@ impl<'input> Iterator for Stream<'_, '_, 'input> { mouse.state = InputMouseState::None; if (btn & 0x40) != 0 { mouse.state = InputMouseState::Scroll; - mouse.scroll.y += if (btn & 0x01) != 0 { 3 } else { -3 }; + match btn & 0x03 { + 0 => mouse.scroll.y -= 3, + 1 => mouse.scroll.y += 3, + 2 | 3 => {} + _ => unreachable!(), + } } else if csi.final_byte == 'M' { const STATES: [InputMouseState; 4] = [ InputMouseState::Left, From 19427b5547954faa77a7b4738ed4be859254bd51 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Tue, 7 Apr 2026 17:58:26 +0200 Subject: [PATCH 2/2] Ignore unrelated mouse keys --- crates/edit/src/helpers.rs | 7 +++++++ crates/edit/src/input.rs | 29 ++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/crates/edit/src/helpers.rs b/crates/edit/src/helpers.rs index f8539f8155f..7ab235fe843 100644 --- a/crates/edit/src/helpers.rs +++ b/crates/edit/src/helpers.rs @@ -48,6 +48,7 @@ pub const COORD_TYPE_SAFE_MAX: CoordType = (1 << (CoordType::BITS / 2 - 1)) - 1; /// A 2D point. Uses [`CoordType`]. #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] +#[repr(C)] pub struct Point { pub x: CoordType, pub y: CoordType, @@ -56,6 +57,10 @@ pub struct Point { impl Point { pub const MIN: Self = Self { x: CoordType::MIN, y: CoordType::MIN }; pub const MAX: Self = Self { x: CoordType::MAX, y: CoordType::MAX }; + + pub fn as_array(&mut self) -> &mut [CoordType; 2] { + unsafe { &mut *(self as *mut Self as *mut [CoordType; 2]) } + } } impl PartialOrd for Point { @@ -72,6 +77,7 @@ impl Ord for Point { /// A 2D size. Uses [`CoordType`]. #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] +#[repr(C)] pub struct Size { pub width: CoordType, pub height: CoordType, @@ -85,6 +91,7 @@ impl Size { /// A 2D rectangle. Uses [`CoordType`]. #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] +#[repr(C)] pub struct Rect { pub left: CoordType, pub top: CoordType, diff --git a/crates/edit/src/input.rs b/crates/edit/src/input.rs index ac79f453e18..fcd68644ce9 100644 --- a/crates/edit/src/input.rs +++ b/crates/edit/src/input.rs @@ -442,22 +442,21 @@ impl<'input> Iterator for Stream<'_, '_, 'input> { }; mouse.state = InputMouseState::None; - if (btn & 0x40) != 0 { - mouse.state = InputMouseState::Scroll; - match btn & 0x03 { - 0 => mouse.scroll.y -= 3, - 1 => mouse.scroll.y += 3, - 2 | 3 => {} - _ => unreachable!(), + + match csi.params[0] { + btn @ 0..3 if csi.final_byte == 'M' => match btn { + 0 => mouse.state = InputMouseState::Left, + 1 => mouse.state = InputMouseState::Middle, + 2 => mouse.state = InputMouseState::Right, + _ => {} + }, + btn @ 64..68 => { + let delta = if (btn & 1) != 0 { 3 } else { -3 }; + let idx = if (btn & 2) != 0 { 0 } else { 1 }; + mouse.scroll.as_array()[idx] += delta; + mouse.state = InputMouseState::Scroll; } - } else if csi.final_byte == 'M' { - const STATES: [InputMouseState; 4] = [ - InputMouseState::Left, - InputMouseState::Middle, - InputMouseState::Right, - InputMouseState::None, - ]; - mouse.state = STATES[(btn as usize) & 0x03]; + _ => {} } mouse.modifiers = kbmod::NONE;