This commit is contained in:
kalaposfos13 2025-02-28 10:19:16 +01:00
parent c9ece44207
commit c05a5223ca
2 changed files with 24 additions and 0 deletions

View file

@ -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});
}
}
}

View file

@ -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