Browse Source

macOS: Add hint for smooth SDL_EVENT_MOUSE_WHEEL values

Jan Sedivy 7 months ago
parent
commit
c2b98e21ba
2 changed files with 18 additions and 1 deletions
  1. 15 0
      include/SDL3/SDL_hints.h
  2. 3 1
      src/video/cocoa/SDL_cocoaevents.m

+ 15 - 0
include/SDL3/SDL_hints.h

@@ -2288,6 +2288,21 @@ extern "C" {
  */
 #define SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH "SDL_MAC_OPENGL_ASYNC_DISPATCH"
 
+/**
+ * A variable controlling whether SDL_EVENT_MOUSE_WHEEL event values will have
+ * momentum on macOS.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": The mouse wheel events will have no momentum. (default)
+ * - "1": The mouse wheel events will have momentum.
+ *
+ * This hint should be set before applicationDidFinishLaunching() is called.
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_MAC_SCROLL_MOMENTUM "SDL_HINT_MAC_SCROLL_MOMENTUM"
+
 /**
  * Request SDL_AppIterate() be called at a specific rate.
  *

+ 3 - 1
src/video/cocoa/SDL_cocoaevents.m

@@ -106,8 +106,10 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
 
 + (void)registerUserDefaults
 {
+    BOOL momentumScrollSupported = (BOOL)SDL_GetHintBoolean(SDL_HINT_MAC_SCROLL_MOMENTUM, false);
+
     NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
-                                                          [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
+                                                          [NSNumber numberWithBool:momentumScrollSupported], @"AppleMomentumScrollSupported",
                                                           [NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
                                                           [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
                                                           nil];