From 584924285940150d0d5e9e4c64c1ecfe269bdb56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20GINIER?= Date: Wed, 14 May 2025 03:31:51 +0200 Subject: [PATCH] MacOS: improve scroll smoothing Use scrollingDelta instead of delta, as recommended by the Apple documentation. It gives much smoother scrolling. --- src/video/cocoa/SDL_cocoamouse.m | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index 530ca0c874..50e463ae5e 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -538,27 +538,17 @@ void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event) SDL_MouseWheelDirection direction; CGFloat x, y; - x = -[event deltaX]; - y = [event deltaY]; + x = -[event scrollingDeltaX]; + y = [event scrollingDeltaY]; direction = SDL_MOUSEWHEEL_NORMAL; if ([event isDirectionInvertedFromDevice] == YES) { direction = SDL_MOUSEWHEEL_FLIPPED; } - /* For discrete scroll events from conventional mice, always send a full tick. - For continuous scroll events from trackpads, send fractional deltas for smoother scrolling. */ - if (![event hasPreciseScrollingDeltas]) { - if (x > 0) { - x = SDL_ceil(x); - } else if (x < 0) { - x = SDL_floor(x); - } - if (y > 0) { - y = SDL_ceil(y); - } else if (y < 0) { - y = SDL_floor(y); - } + if ([event hasPreciseScrollingDeltas]) { + x *= 0.1; + y *= 0.1; } SDL_SendMouseWheel(Cocoa_GetEventTimestamp([event timestamp]), window, mouseID, x, y, direction);