Skip to content

Commit fd99b1d

Browse files
slipherillwieckz
authored andcommitted
sdl3: disable the "accent menu" on macOS
For some reason SDL3 made a change to enable a system menu offering to input a letter with diacritics, which appears whenever you press and hold a key (for example while running). After SDL does this, call the same Objective C facility to undo the configuration change that SDL did.
1 parent b3bbc32 commit fd99b1d

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ set(CLIENTLIST
356356
${RENDERERLIST}
357357
)
358358

359+
if (APPLE)
360+
set(CLIENTLIST ${CLIENTLIST} ${ENGINE_DIR}/sys/DisableAccentMenu.m)
361+
endif()
362+
359363
set(CLIENTTESTLIST ${ENGINETESTLIST}
360364
${ENGINE_DIR}/renderer/gl_shader_test.cpp
361365
)

src/engine/sys/DisableAccentMenu.m

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
===========================================================================
3+
Daemon BSD Source Code
4+
Copyright (c) 2025, Daemon Developers
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the Daemon developers nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
===========================================================================
29+
*/
30+
31+
#import <Foundation/Foundation.h>
32+
33+
void DisableAccentMenu() {
34+
// Don't do this: https://forums.factorio.com/download/file.php?id=46540
35+
NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
36+
[NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled", nil];
37+
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
38+
}

src/engine/sys/sdl_input.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,9 @@ void IN_FrameEnd()
12981298
IN_Init
12991299
===============
13001300
*/
1301+
#ifdef __APPLE__
1302+
extern "C" void DisableAccentMenu();
1303+
#endif
13011304
void IN_Init( void *windowData )
13021305
{
13031306
int appState;
@@ -1328,6 +1331,13 @@ void IN_Init( void *windowData )
13281331
Cvar_SetValue( "com_unfocused", !( appState & SDL_WINDOW_INPUT_FOCUS ) );
13291332
Cvar_SetValue( "com_minimized", ( appState & SDL_WINDOW_MINIMIZED ) );
13301333
IN_InitJoystick();
1334+
1335+
#ifdef __APPLE__
1336+
// We have to act after SDL does. Whoever has the last word wins!
1337+
// https://github.com/libsdl-org/SDL/commit/caf0348b26d02bc22ba9a0a908c83c43f8e4e6ad
1338+
DisableAccentMenu();
1339+
#endif
1340+
13311341
Log::Debug( "------------------------------------" );
13321342
}
13331343

0 commit comments

Comments
 (0)