SDL: Added support for raw mousewheel events

From 8201b6dc4d5126a7e5767d7f310e63b983024d55 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 30 Mar 2024 07:38:38 -0700
Subject: [PATCH] Added support for raw mousewheel events

---
 src/video/windows/SDL_windowsevents.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index fb66bf94d4b57..e456c2efa7e1c 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -624,6 +624,16 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_VideoData *data, HANDL
                 SDL_SendMouseButton(timestamp, window, mouseID, state, button);
             }
         }
+
+        if (rawmouse->usButtonFlags & RI_MOUSE_WHEEL) {
+            short amount = (short)rawmouse->usButtonData;
+            float fAmount = (float)amount / WHEEL_DELTA;
+            SDL_SendMouseWheel(WIN_GetEventTimestamp(), window, mouseID, 0.0f, fAmount, SDL_MOUSEWHEEL_NORMAL);
+        } else if (rawmouse->usButtonFlags & RI_MOUSE_HWHEEL) {
+            short amount = (short)rawmouse->usButtonData;
+            float fAmount = (float)amount / WHEEL_DELTA;
+            SDL_SendMouseWheel(WIN_GetEventTimestamp(), window, mouseID, fAmount, 0.0f, SDL_MOUSEWHEEL_NORMAL);
+        }
     }
 }
 
@@ -1084,12 +1094,14 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
     case WM_MOUSEWHEEL:
     case WM_MOUSEHWHEEL:
     {
-        short amount = GET_WHEEL_DELTA_WPARAM(wParam);
-        float fAmount = (float)amount / WHEEL_DELTA;
-        if (msg == WM_MOUSEWHEEL) {
-            SDL_SendMouseWheel(WIN_GetEventTimestamp(), data->window, SDL_GLOBAL_MOUSE_ID, 0.0f, fAmount, SDL_MOUSEWHEEL_NORMAL);
-        } else {
-            SDL_SendMouseWheel(WIN_GetEventTimestamp(), data->window, SDL_GLOBAL_MOUSE_ID, fAmount, 0.0f, SDL_MOUSEWHEEL_NORMAL);
+        if (!data->videodata->raw_mouse_enabled) {
+            short amount = GET_WHEEL_DELTA_WPARAM(wParam);
+            float fAmount = (float)amount / WHEEL_DELTA;
+            if (msg == WM_MOUSEWHEEL) {
+                SDL_SendMouseWheel(WIN_GetEventTimestamp(), data->window, SDL_GLOBAL_MOUSE_ID, 0.0f, fAmount, SDL_MOUSEWHEEL_NORMAL);
+            } else {
+                SDL_SendMouseWheel(WIN_GetEventTimestamp(), data->window, SDL_GLOBAL_MOUSE_ID, fAmount, 0.0f, SDL_MOUSEWHEEL_NORMAL);
+            }
         }
     } break;