diff --git a/src/util/imgui_manager.cpp b/src/util/imgui_manager.cpp index 626d0e123..f2dd32af0 100644 --- a/src/util/imgui_manager.cpp +++ b/src/util/imgui_manager.cpp @@ -208,9 +208,10 @@ struct ALIGN_TO_CACHE_LINE State { // Shared between both threads - // cached copies of WantCaptureKeyboard/Mouse, used to know when to dispatch events + // Cached ImGui input requests, used to know when to dispatch events. std::atomic_bool imgui_wants_keyboard{false}; std::atomic_bool imgui_wants_mouse{false}; + std::atomic_bool imgui_wants_text_input{false}; std::array software_cursors = {}; @@ -449,6 +450,10 @@ void ImGuiManager::Shutdown() ImGui::DestroyContext(s_state.imgui_context); s_state.imgui_context = nullptr; } + + s_state.imgui_wants_keyboard.store(false, std::memory_order_release); + s_state.imgui_wants_text_input.store(false, std::memory_order_release); + s_state.imgui_wants_mouse.store(false, std::memory_order_release); } bool ImGuiManager::CreateGPUResources(Error* error) @@ -564,7 +569,8 @@ void ImGuiManager::NewFrame(u64 current_time) // Disable nav input on the implicit (Debug##Default) window. Otherwise we end up requesting keyboard // focus when there's nothing there. We use GetCurrentWindowRead() because otherwise it'll make it visible. ImGui::GetCurrentWindowRead()->Flags |= ImGuiWindowFlags_NoNavInputs; - s_state.imgui_wants_keyboard.store(io.WantCaptureKeyboard, std::memory_order_relaxed); + s_state.imgui_wants_keyboard.store(io.WantCaptureKeyboard, std::memory_order_release); + s_state.imgui_wants_text_input.store(io.WantTextInput, std::memory_order_release); s_state.imgui_wants_mouse.store(io.WantCaptureMouse, std::memory_order_release); } @@ -1583,7 +1589,7 @@ void ImGuiManager::SetGamepadButtonType(InputManager::GamepadButtonType type) bool ImGuiManager::WantsTextInput() { - return s_state.imgui_wants_keyboard.load(std::memory_order_acquire); + return s_state.imgui_wants_text_input.load(std::memory_order_acquire); } bool ImGuiManager::WantsMouseInput() @@ -1593,7 +1599,7 @@ bool ImGuiManager::WantsMouseInput() void ImGuiManager::AddTextInput(std::string str) { - if (!s_state.imgui_context || !s_state.imgui_wants_keyboard.load(std::memory_order_acquire)) + if (!s_state.imgui_context || !s_state.imgui_wants_text_input.load(std::memory_order_acquire)) return; VideoThread::RunOnThread([str = std::move(str)]() { diff --git a/src/util/input_manager.h b/src/util/input_manager.h index ddae514dc..b78d67a15 100644 --- a/src/util/input_manager.h +++ b/src/util/input_manager.h @@ -297,15 +297,15 @@ void CloseSources(); void PollSources(); /// Returns true if any bindings exist for the specified key. -/// Can be safely called on another thread. +/// Must be called on the core thread. bool HasAnyBindingsForKey(InputBindingKey key); /// Returns true if any bindings exist for the specified source + index. -/// Can be safely called on another thread. +/// Must be called on the core thread. bool HasAnyBindingsForSource(InputBindingKey key); /// Returns true if any bindings exist for the specified subclass. -/// Can be safely called on another thread. +/// Must be called on the core thread. bool HasAnyBindingsForSubclass(InputBindingKey key); /// Parses a string binding into its components. Use with external AddBinding().