diff --git a/externals/sdl3 b/externals/sdl3 index 3a1d76d2..22422f77 160000 --- a/externals/sdl3 +++ b/externals/sdl3 @@ -1 +1 @@ -Subproject commit 3a1d76d298db023f6cf37fb08ee766f20a4e12ab +Subproject commit 22422f7748d5128135995ed34c8f8012861c7332 diff --git a/src/imgui/renderer/imgui_impl_sdl3.cpp b/src/imgui/renderer/imgui_impl_sdl3.cpp index 60b440c2..e67bdc77 100644 --- a/src/imgui/renderer/imgui_impl_sdl3.cpp +++ b/src/imgui/renderer/imgui_impl_sdl3.cpp @@ -11,7 +11,6 @@ #include #if defined(__APPLE__) #include -#include #endif #ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN @@ -72,33 +71,25 @@ static void PlatformSetImeData(ImGuiContext*, ImGuiViewport* viewport, ImGuiPlat auto window_id = (SDL_WindowID)(intptr_t)viewport->PlatformHandle; SDL_Window* window = SDL_GetWindowFromID(window_id); if ((!data->WantVisible || bd->ime_window != window) && bd->ime_window != nullptr) { - auto stop_input = [&bd] { SDL_StopTextInput(bd->ime_window); }; -#ifdef __APPLE__ - dispatch_sync(dispatch_get_main_queue(), ^{ - stop_input(); - }); -#else - stop_input(); -#endif + SDL_RunOnMainThread( + [](void* userdata) { SDL_StopTextInput(static_cast(userdata)); }, + bd->ime_window, true); bd->ime_window = nullptr; } if (data->WantVisible) { - SDL_Rect r; - r.x = (int)data->InputPos.x; - r.y = (int)data->InputPos.y; - r.w = 1; - r.h = (int)data->InputLineHeight; - const auto start_input = [&window, &r] { - SDL_SetTextInputArea(window, &r, 0); - SDL_StartTextInput(window); - }; -#ifdef __APPLE__ - dispatch_sync(dispatch_get_main_queue(), ^{ - start_input(); - }); -#else - start_input(); -#endif + std::pair usr_data; + usr_data.first = window; + usr_data.second.x = (int)data->InputPos.x; + usr_data.second.y = (int)data->InputPos.y; + usr_data.second.w = 1; + usr_data.second.h = (int)data->InputLineHeight; + SDL_RunOnMainThread( + [](void* userdata) { + auto* params = static_cast*>(userdata); + SDL_SetTextInputArea(params->first, ¶ms->second, 0); + SDL_StartTextInput(params->first); + }, + &usr_data, true); bd->ime_window = window; } } diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index 318b3349..b0126def 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -205,7 +205,9 @@ void WindowSDL::InitTimers() { void WindowSDL::RequestKeyboard() { if (keyboard_grab == 0) { - SDL_StartTextInput(window); + SDL_RunOnMainThread( + [](void* userdata) { SDL_StartTextInput(static_cast(userdata)); }, window, + true); } keyboard_grab++; } @@ -214,7 +216,9 @@ void WindowSDL::ReleaseKeyboard() { ASSERT(keyboard_grab > 0); keyboard_grab--; if (keyboard_grab == 0) { - SDL_StopTextInput(window); + SDL_RunOnMainThread( + [](void* userdata) { SDL_StopTextInput(static_cast(userdata)); }, window, + true); } }