diff --git a/src/input/controller.cpp b/src/input/controller.cpp index 8bc458be6..130b9d416 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -6,6 +6,7 @@ #include "common/logging/log.h" #include "core/libraries/kernel/time.h" #include "core/libraries/pad/pad.h" +#include "core/libraries/system/userservice.h" #include "input/controller.h" namespace Input { @@ -239,13 +240,24 @@ void GameController::SetTouchpadState(int touchIndex, bool touchDown, float x, f } void GameControllers::TryOpenSDLControllers(GameControllers& controllers) { + using namespace Libraries::UserService; int controller_count; SDL_JoystickID* joysticks = SDL_GetGamepads(&controller_count); for (int i = 0; i < 4; i++) { if (i < controller_count) { + SDL_Gamepad** temp = &(controllers[i]->m_sdl_gamepad); controllers[i]->m_sdl_gamepad = SDL_OpenGamepad(joysticks[i]); + if (*temp == 0) { + AddUserServiceEvent({OrbisUserServiceEventType::Login, + SDL_GetGamepadPlayerIndex(controllers[i]->m_sdl_gamepad) + 2}); + } } else { + SDL_Gamepad** temp = &(controllers[i]->m_sdl_gamepad); controllers[i]->m_sdl_gamepad = nullptr; + if (*temp != 0) { + AddUserServiceEvent( + {OrbisUserServiceEventType::Logout, SDL_GetGamepadPlayerIndex(*temp) + 2}); + } } } diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index cd576271b..546156963 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -270,6 +270,7 @@ void WindowSDL::OnKeyboardMouseInput(const SDL_Event* event) { // Handle window controls outside of the input maps if (event->type == SDL_EVENT_KEY_DOWN) { + using namespace Libraries::UserService; u32 input_id = input_event.input.sdl_id; // Reparse kbm inputs if (input_id == SDLK_F8) { @@ -295,6 +296,17 @@ void WindowSDL::OnKeyboardMouseInput(const SDL_Event* event) { VideoCore::TriggerCapture(); return; } + // test controller connect/disconnect + else if (input_id == SDLK_F4) { + int player_count = Config::GetNumberOfPlayers(); + AddUserServiceEvent({OrbisUserServiceEventType::Logout, player_count}); + Config::SetNumberOfPlayers(player_count - 1); + } + else if (input_id == SDLK_F5) { + int player_count = Config::GetNumberOfPlayers(); + AddUserServiceEvent({OrbisUserServiceEventType::Login, player_count + 1}); + Config::SetNumberOfPlayers(player_count + 1); + } } // if it's a wheel event, make a timer that turns it off after a set time