From f9380e15de1c57295e88757af16b5f74cdb1d46b Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 19 May 2026 15:41:04 -0700
Subject: [PATCH] visionOS: fixed mousewheel values
Here are the observed values using a Bluetooth mouse on visionOS 26.5
Slow scroll up:
Mouse scroll: 0,-0.017334
Mouse scroll: 0,0
Mouse scroll: 0,-0.017334
Mouse scroll: 0,0
Slow scroll down:
Mouse scroll: 0,0.017334
Mouse scroll: 0,0
Mouse scroll: 0,0.017334
Mouse scroll: 0,0
Fast scroll up:
Mouse scroll: 0,-0.017334
Mouse scroll: 0,-9.36021
Mouse scroll: 0,-100.08
Mouse scroll: 0,-75.2287
Mouse scroll: 0,-82.2284
Mouse scroll: 0,-92.0137
Mouse scroll: 0,-95.1917
Mouse scroll: 0,-101.846
Mouse scroll: 0,-203.266
Mouse scroll: 0,0
Fast scroll down:
Mouse scroll: 0,0.017334
Mouse scroll: 0,11.424
Mouse scroll: 0,59.3571
Mouse scroll: 0,68.7859
Mouse scroll: 0,267.834
Mouse scroll: 0,95.0823
Mouse scroll: 0,201.809
Mouse scroll: 0,0
---
src/video/uikit/SDL_uikitevents.m | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m
index a2722f0c01a55..3b94db3152a24 100644
--- a/src/video/uikit/SDL_uikitevents.m
+++ b/src/video/uikit/SDL_uikitevents.m
@@ -359,15 +359,18 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14
mouse.mouseInput.scroll.valueChangedHandler = ^(GCControllerDirectionPad *dpad, float xValue, float yValue) {
Uint64 timestamp = SDL_GetTicksNS();
+#ifdef SDL_PLATFORM_VISIONOS
+ /* Mouse scroll values on visionOS have swapped axes compared to other platforms.
+ * There is also an acceleration ramp applied, so clamp to a single tick per event.
+ */
+ float vertical = yValue < 0 ? -1 : yValue > 0 ? 1 : 0;
+ float horizontal = xValue < 0 ? -1 : xValue > 0 ? 1 : 0;
+#else
/* Raw scroll values come in here, vertical values in the first axis, horizontal values in the second axis.
* The vertical values are negative moving the mouse wheel up and positive moving it down.
* The horizontal values are negative moving the mouse wheel left and positive moving it right.
* The vertical values are inverted compared to SDL, and the horizontal values are as expected.
*/
-#ifdef SDL_PLATFORM_VISIONOS
- float vertical = -yValue;
- float horizontal = xValue;
-#else
float vertical = -xValue;
float horizontal = yValue;
#endif