From 83b67b3c4c8f03068ae1904df02244c3c8a73e4f Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 27 Oct 2019 13:44:48 +1000 Subject: [PATCH] Frontend: Clear focus after loading/saving state --- dep/imgui/src/imgui_impl_sdl.cpp | 4 ++-- src/duckstation/sdl_interface.cpp | 13 ++++++++++++- src/duckstation/sdl_interface.h | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/dep/imgui/src/imgui_impl_sdl.cpp b/dep/imgui/src/imgui_impl_sdl.cpp index 52938fdb4..398b73f2f 100644 --- a/dep/imgui/src/imgui_impl_sdl.cpp +++ b/dep/imgui/src/imgui_impl_sdl.cpp @@ -180,8 +180,8 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event) { static constexpr unsigned int mapping[][2] = {{SDL_CONTROLLER_BUTTON_A, ImGuiNavInput_Activate}, {SDL_CONTROLLER_BUTTON_B, ImGuiNavInput_Cancel}, - {SDL_CONTROLLER_BUTTON_X, ImGuiNavInput_Input}, - {SDL_CONTROLLER_BUTTON_Y, ImGuiNavInput_Menu}, + {SDL_CONTROLLER_BUTTON_Y, ImGuiNavInput_Input}, + // {SDL_CONTROLLER_BUTTON_X, ImGuiNavInput_Menu}, {SDL_CONTROLLER_BUTTON_LEFTSHOULDER, ImGuiNavInput_FocusPrev}, {SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, ImGuiNavInput_FocusNext}, {SDL_CONTROLLER_BUTTON_DPAD_UP, ImGuiNavInput_DpadUp}, diff --git a/src/duckstation/sdl_interface.cpp b/src/duckstation/sdl_interface.cpp index b7a604508..da7010381 100644 --- a/src/duckstation/sdl_interface.cpp +++ b/src/duckstation/sdl_interface.cpp @@ -405,7 +405,7 @@ static void HandleSDLControllerAxisEventForController(const SDL_Event* ev, Digit { // Log_DevPrintf("axis %d %d", ev->caxis.axis, ev->caxis.value); - static constexpr int deadzone = 5000; + static constexpr int deadzone = 8192; const bool negative = (ev->caxis.value < 0); const bool active = (std::abs(ev->caxis.value) >= deadzone); @@ -583,6 +583,11 @@ void SDLInterface::HandleSDLKeyEvent(const SDL_Event* event) } } +void SDLInterface::ClearImGuiFocus() +{ + ImGui::SetWindowFocus(nullptr); +} + void SDLInterface::Render() { DrawImGui(); @@ -1091,6 +1096,8 @@ void SDLInterface::DoStartDisc() AddOSDMessage(SmallString::FromFormat("Starting disc from '%s'...", path)); if (!InitializeSystem(path, nullptr)) return; + + ClearImGuiFocus(); } void SDLInterface::DoStartBIOS() @@ -1100,6 +1107,8 @@ void SDLInterface::DoStartBIOS() AddOSDMessage("Starting BIOS..."); if (!InitializeSystem(nullptr, nullptr)) return; + + ClearImGuiFocus(); } void SDLInterface::DoLoadState(u32 index) @@ -1112,12 +1121,14 @@ void SDLInterface::DoLoadState(u32 index) m_last_internal_frame_number = m_system->GetInternalFrameNumber(); m_last_global_tick_counter = m_system->GetGlobalTickCounter(); m_fps_timer.Reset(); + ClearImGuiFocus(); } void SDLInterface::DoSaveState(u32 index) { Assert(m_system); SaveState(GetSaveStateFilename(index)); + ClearImGuiFocus(); } void SDLInterface::Run() diff --git a/src/duckstation/sdl_interface.h b/src/duckstation/sdl_interface.h index 453d819dd..f20738816 100644 --- a/src/duckstation/sdl_interface.h +++ b/src/duckstation/sdl_interface.h @@ -75,6 +75,8 @@ private: void HandleSDLEvent(const SDL_Event* event); void HandleSDLKeyEvent(const SDL_Event* event); + void ClearImGuiFocus(); + void Render(); void RenderDisplay(); void DrawMainMenuBar();