From 94c1276a5ff347eb9ce3ae7778f1192db2790027 Mon Sep 17 00:00:00 2001 From: Thomas Ballinger Date: Sun, 7 Nov 2021 20:49:32 -0500 Subject: [PATCH] emscripten: Decrease vertical scroll speed by using deltaMode Reference issue #4623. --- src/video/emscripten/SDL_emscriptenevents.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 0c1b94c71..bae18d212 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -409,7 +409,22 @@ static EM_BOOL Emscripten_HandleWheel(int eventType, const EmscriptenWheelEvent *wheelEvent, void *userData) { SDL_WindowData *window_data = userData; - SDL_SendMouseWheel(window_data->window, 0, (float)wheelEvent->deltaX, (float)-wheelEvent->deltaY, SDL_MOUSEWHEEL_NORMAL); + + float deltaY = wheelEvent->deltaY; + + switch (wheelEvent->deltaMode) { + case DOM_DELTA_PIXEL: + deltaY /= 100; /* 100 pixels make up a step */ + break; + case DOM_DELTA_LINE: + deltaY /= 3; /* 3 lines make up a step */ + break; + case DOM_DELTA_PAGE: + deltaY *= 80; /* A page makes up 80 steps */ + break; + } + + SDL_SendMouseWheel(window_data->window, 0, (float)wheelEvent->deltaX, -deltaY, SDL_MOUSEWHEEL_NORMAL); return SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE; }