mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-01-15 03:15:13 +00:00
sdl: Respect text input main thread requirements. (#2138)
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
This commit is contained in:
parent
4f2f9494b0
commit
4719d32295
2
externals/sdl3
vendored
2
externals/sdl3
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 3a1d76d298db023f6cf37fb08ee766f20a4e12ab
|
||||
Subproject commit 22422f7748d5128135995ed34c8f8012861c7332
|
|
@ -11,7 +11,6 @@
|
|||
#include <SDL3/SDL.h>
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#include <dispatch/dispatch.h>
|
||||
#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<SDL_Window*>(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<SDL_Window*, SDL_Rect> 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<std::pair<SDL_Window*, SDL_Rect>*>(userdata);
|
||||
SDL_SetTextInputArea(params->first, ¶ms->second, 0);
|
||||
SDL_StartTextInput(params->first);
|
||||
},
|
||||
&usr_data, true);
|
||||
bd->ime_window = window;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<SDL_Window*>(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<SDL_Window*>(userdata)); }, window,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue