From d148d9515ba913a16a79c214b762b833e4c2f352 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 20 Feb 2026 17:44:34 +0000 Subject: [PATCH] Fix text input on SDL3 (#5574) --- src/platforms/rcore_desktop_sdl.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index ca49e6a8e..371d907f7 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -2016,6 +2016,22 @@ int InitPlatform(void) // Init window #if defined(USING_VERSION_SDL3) platform.window = SDL_CreateWindow(CORE.Window.title, CORE.Window.screen.width, CORE.Window.screen.height, flags); + + // NOTE: SDL3 no longer enables TextInput by default, so this is needed to preserve the behaviour and keep GetCharPressed working. + // This code is derived from SDL before the change was made: https://github.com/libsdl-org/SDL/commit/72fc6f86e5d605a3787222bc7dc18c5379047f4a. + const char *enableOSK = SDL_GetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD); + if (enableOSK == NULL) + { + SDL_SetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD, "0"); + } + if (!SDL_StartTextInput(platform.window)) + { + TRACELOG(LOG_WARNING, "SDL: Failed to start text input: %s", SDL_GetError()); + } + if (enableOSK == NULL) + { + SDL_SetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD, NULL); + } #else platform.window = SDL_CreateWindow(CORE.Window.title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, CORE.Window.screen.width, CORE.Window.screen.height, flags); #endif