MacOS: improve scroll smoothing

Use scrollingDelta instead of delta, as recommended by the Apple documentation.
It gives much smoother scrolling.
This commit is contained in:
Stéphane GINIER
2025-05-14 03:31:51 +02:00
committed by Sam Lantinga
parent 70eceec77b
commit 5dab2c73f0

View File

@@ -545,27 +545,17 @@ void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
SDL_MouseWheelDirection direction; SDL_MouseWheelDirection direction;
CGFloat x, y; CGFloat x, y;
x = -[event deltaX]; x = -[event scrollingDeltaX];
y = [event deltaY]; y = [event scrollingDeltaY];
direction = SDL_MOUSEWHEEL_NORMAL; direction = SDL_MOUSEWHEEL_NORMAL;
if ([event isDirectionInvertedFromDevice] == YES) { if ([event isDirectionInvertedFromDevice] == YES) {
direction = SDL_MOUSEWHEEL_FLIPPED; direction = SDL_MOUSEWHEEL_FLIPPED;
} }
/* For discrete scroll events from conventional mice, always send a full tick. if ([event hasPreciseScrollingDeltas]) {
For continuous scroll events from trackpads, send fractional deltas for smoother scrolling. */ x *= 0.1;
if (![event hasPreciseScrollingDeltas]) { y *= 0.1;
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);
}
} }
SDL_SendMouseWheel(Cocoa_GetEventTimestamp([event timestamp]), window, mouseID, x, y, direction); SDL_SendMouseWheel(Cocoa_GetEventTimestamp([event timestamp]), window, mouseID, x, y, direction);