From 9670fc3fdfc0de1f6465f085ccd0b0d99535d85f Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 6 Jan 2020 10:44:43 -0800 Subject: [PATCH] macos: fix minimum scroll wheel tick macos generates fractional distance values for the mouse wheel, with one tick starting at 0.1. We were truncating this to a 0 row move, which meant that you'd need to build up some acceleration to move the rows when all you really wanted was a single tick. This commit changes things so that we round up to at least 1.0 in this situation. --- window/src/os/macos/window.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 39e28c4b2..9d22c587f 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -36,6 +36,14 @@ pub fn use_ime(enable: bool) { USE_IME.store(enable, Ordering::Relaxed); } +fn round_away_from_zero(value: f64) -> i16 { + if value > 0. { + value.max(1.).round() as i16 + } else { + value.min(-1.).round() as i16 + } +} + #[repr(C)] struct NSRange(cocoa::foundation::NSRange); @@ -999,9 +1007,9 @@ impl WindowView { let vert_delta = unsafe { nsevent.scrollingDeltaY() }; let horz_delta = unsafe { nsevent.scrollingDeltaX() }; let kind = if vert_delta.abs() > horz_delta.abs() { - MouseEventKind::VertWheel(vert_delta as i16) + MouseEventKind::VertWheel(round_away_from_zero(vert_delta)) } else { - MouseEventKind::HorzWheel(horz_delta as i16) + MouseEventKind::HorzWheel(round_away_from_zero(horz_delta)) }; Self::mouse_common(this, nsevent, kind); }