mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-12-22 16:02:19 +00:00
Initial Gamepad Hotplug Logic improvements
This changes the way how a Controller will be prioritized. By default: it'll always prioritize based on Player 1. It should play nicely with Steam Deck's internal inputs when Steam Input is active
This commit is contained in:
parent
a8cac8763d
commit
c9b3a5e03f
1 changed files with 98 additions and 72 deletions
|
|
@ -197,8 +197,13 @@ static void SetControllerTimeOfDayLED(Controller& controller, bool isNight)
|
|||
auto g = isNight ? 0 : 37;
|
||||
auto b = isNight ? 101 : 184;
|
||||
|
||||
controller.SetLED(r, g, b);
|
||||
// Ensure the lightbar is set correctly
|
||||
if (SDL_GameControllerHasLED(controller.controller))
|
||||
{
|
||||
SDL_GameControllerSetLED(controller.controller, r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int HID_OnSDLEvent(void*, SDL_Event* event)
|
||||
{
|
||||
|
|
@ -215,6 +220,12 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
|
|||
g_controllers[freeIndex] = controller;
|
||||
|
||||
SetControllerTimeOfDayLED(controller, App::s_isWerehog);
|
||||
|
||||
// Ensure Player 1's controller is always the active controller
|
||||
if (freeIndex == 0)
|
||||
{
|
||||
SetControllerInputDevice(&g_controllers[0]);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -227,6 +238,19 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
|
|||
if (controller)
|
||||
controller->Close();
|
||||
|
||||
// If Player 1's controller is removed, set the next available controller as active
|
||||
if (controller == &g_controllers[0])
|
||||
{
|
||||
for (auto& ctrl : g_controllers)
|
||||
{
|
||||
if (ctrl.CanPoll())
|
||||
{
|
||||
SetControllerInputDevice(&ctrl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -302,6 +326,8 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void hid::Init()
|
||||
{
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue