diff --git a/src/imgui/renderer/imgui_impl_sdl3.cpp b/src/imgui/renderer/imgui_impl_sdl3.cpp index 84b5dea91..634e720a4 100644 --- a/src/imgui/renderer/imgui_impl_sdl3.cpp +++ b/src/imgui/renderer/imgui_impl_sdl3.cpp @@ -9,6 +9,7 @@ #include "core/memory.h" #include "imgui_impl_sdl3.h" #include "input/controller.h" +#include "sdl_window.h" // SDL #include @@ -502,6 +503,9 @@ bool ProcessEvent(const SDL_Event* event) { bd->want_update_gamepads_list = true; return true; } + case SDL_EVENT_CHANGE_CONTROLLER: + bd->want_update_gamepads_list = true; + return false; } return false; } @@ -732,18 +736,15 @@ static void UpdateGamepads() { ImGuiIO& io = ImGui::GetIO(); SdlData* bd = GetBackendData(); - auto memory = Core::Memory::Instance(); auto controller = Common::Singleton::Instance(); auto engine = controller->GetEngine(); SDL_Gamepad* SDLGamepad = engine->m_gamepad; - - if (SDLGamepad) { - bd->gamepads.push_back(SDLGamepad); - bd->want_update_gamepads_list = false; - } else { - // Update list of gamepads to use - if (bd->want_update_gamepads_list && - bd->gamepad_mode != ImGui_ImplSDL3_GamepadMode_Manual) { + // Update list of gamepads to use + if (bd->want_update_gamepads_list && bd->gamepad_mode != ImGui_ImplSDL3_GamepadMode_Manual) { + if (SDLGamepad) { + bd->gamepads.push_back(SDLGamepad); + bd->want_update_gamepads_list = false; + } else { CloseGamepads(); int sdl_gamepads_count = 0; const SDL_JoystickID* sdl_gamepads = SDL_GetGamepads(&sdl_gamepads_count); diff --git a/src/qt_gui/control_settings.cpp b/src/qt_gui/control_settings.cpp index 6aa79ea1a..729dcfb61 100644 --- a/src/qt_gui/control_settings.cpp +++ b/src/qt_gui/control_settings.cpp @@ -685,7 +685,6 @@ void ControlSettings::CheckGamePad() { gamepad = nullptr; } - SDL_free(gamepads); gamepads = SDL_GetGamepads(&gamepad_count); if (!gamepads) { @@ -974,6 +973,11 @@ void ControlSettings::processSDLEvents(int Type, int Input, int Value) { } } } + + if (Type == SDL_EVENT_GAMEPAD_ADDED || SDL_EVENT_GAMEPAD_REMOVED) { + ui->ActiveGamepadBox->clear(); + CheckGamePad(); + } } void ControlSettings::pollSDLEvents() { @@ -988,11 +992,6 @@ void ControlSettings::pollSDLEvents() { return; } - if (event.type == SDL_EVENT_GAMEPAD_ADDED) { - ui->ActiveGamepadBox->clear(); - CheckGamePad(); - } - SdlEventWrapper::Wrapper::GetInstance()->Wrapper::ProcessEvent(&event); } } diff --git a/src/qt_gui/control_settings.ui b/src/qt_gui/control_settings.ui index efab94e2c..907946c4b 100644 --- a/src/qt_gui/control_settings.ui +++ b/src/qt_gui/control_settings.ui @@ -252,34 +252,6 @@ L1 and L2 - - - - L2 - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - unmapped - - - - - - @@ -314,6 +286,34 @@ + + + + L2 + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + unmapped + + + + + + @@ -1342,34 +1342,6 @@ R1 and R2 - - - - R2 - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - unmapped - - - - - - @@ -1404,6 +1376,34 @@ + + + + R2 + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + unmapped + + + + + + diff --git a/src/qt_gui/sdl_event_wrapper.cpp b/src/qt_gui/sdl_event_wrapper.cpp index 608acbbc5..052321233 100644 --- a/src/qt_gui/sdl_event_wrapper.cpp +++ b/src/qt_gui/sdl_event_wrapper.cpp @@ -24,8 +24,10 @@ bool Wrapper::ProcessEvent(SDL_Event* event) { case SDL_EVENT_WINDOW_EXPOSED: return false; case SDL_EVENT_GAMEPAD_ADDED: + emit SDLEvent(SDL_EVENT_GAMEPAD_ADDED, 0, 0); return false; case SDL_EVENT_GAMEPAD_REMOVED: + emit SDLEvent(SDL_EVENT_GAMEPAD_REMOVED, 0, 0); return false; case SDL_EVENT_QUIT: emit SDLEvent(SDL_EVENT_QUIT, 0, 0);