From 3274e850bcd4dfe784628db207c5a3d9b222fce3 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Sun, 30 Nov 2025 21:44:49 -0500 Subject: [PATCH] cocoa: Add SDL_HINT_MAC_PRESS_AND_HOLD hint --- include/SDL3/SDL_hints.h | 15 +++++++++++++++ src/video/cocoa/SDL_cocoaevents.m | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index 972e0b7e782a1..ac4ab50139c10 100644 --- a/include/SDL3/SDL_hints.h +++ b/include/SDL3/SDL_hints.h @@ -2620,6 +2620,21 @@ extern "C" { */ #define SDL_HINT_MAC_SCROLL_MOMENTUM "SDL_MAC_SCROLL_MOMENTUM" +/** + * A variable controlling whether holding down a key will repeat the pressed key + * or open the accents menu on macOS. + * + * The variable can be set to the following values: + * + * - "0": Holding a key will open the accents menu for that key. + * - "1": Holding a key will repeat the pressed key. (default) + * + * This hint needs to be set before SDL_Init(). + * + * \since This hint is available since SDL 3.4.0. + */ +#define SDL_HINT_MAC_PRESS_AND_HOLD "SDL_MAC_PRESS_AND_HOLD" + /** * Request SDL_AppIterate() be called at a specific rate. * diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m index 64b2798c1eb4b..431d491d52393 100644 --- a/src/video/cocoa/SDL_cocoaevents.m +++ b/src/video/cocoa/SDL_cocoaevents.m @@ -105,10 +105,11 @@ - (void)sendEvent:(NSEvent *)theEvent + (void)registerUserDefaults { BOOL momentumScrollSupported = (BOOL)SDL_GetHintBoolean(SDL_HINT_MAC_SCROLL_MOMENTUM, false); + BOOL pressAndHoldEnabled = (BOOL)SDL_GetHintBoolean(SDL_HINT_MAC_PRESS_AND_HOLD, true); NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithBool:momentumScrollSupported], @"AppleMomentumScrollSupported", - [NSNumber numberWithBool:YES], @"ApplePressAndHoldEnabled", + [NSNumber numberWithBool:pressAndHoldEnabled], @"ApplePressAndHoldEnabled", [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];