Skip to content

Commit

Permalink
cocoa: Don't round scroll deltas from trackpads
Browse files Browse the repository at this point in the history
Rounding the scroll deltas from trackpads causes jerky scrolling behavior
by artificially amplifying the effects of very small scroll movements.

We should only round events from devices with discrete scroll wheels,
because we know the smallest unit of movement there is a single tick.
  • Loading branch information
cgutman authored and slouken committed Dec 7, 2021
1 parent 8cee50e commit da0f76d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/video/cocoa/SDL_cocoamouse.m
Expand Up @@ -473,15 +473,19 @@ + (NSCursor *)invisibleCursor
}
}

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);
/* 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 respondsToSelector:@selector(hasPreciseScrollingDeltas)] || ![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);
}
}

SDL_SendMouseWheel(window, mouseID, x, y, direction);
Expand Down

0 comments on commit da0f76d

Please sign in to comment.