XInputSource: Set initial state on connection

Instead of after polling.
This commit is contained in:
Stenzek
2025-08-13 15:09:12 +10:00
parent c0c022591c
commit 327e9b5ce0
2 changed files with 7 additions and 7 deletions

View File

@@ -165,7 +165,7 @@ bool XInputSource::ReloadDevices()
if (m_controllers[i].connected)
continue;
HandleControllerConnection(i);
HandleControllerConnection(i, new_state);
changed = true;
}
else if (result == ERROR_DEVICE_NOT_CONNECTED)
@@ -214,9 +214,9 @@ void XInputSource::PollEvents()
if (result == ERROR_SUCCESS)
{
if (!was_connected)
HandleControllerConnection(i);
CheckForStateChanges(i, new_state);
HandleControllerConnection(i, new_state);
else
CheckForStateChanges(i, new_state);
}
else
{
@@ -434,7 +434,7 @@ bool XInputSource::GetGenericBindingMapping(std::string_view device, GenericInpu
return true;
}
void XInputSource::HandleControllerConnection(u32 index)
void XInputSource::HandleControllerConnection(u32 index, const XINPUT_STATE& state)
{
INFO_LOG("XInput controller {} connected.", index);
@@ -446,7 +446,7 @@ void XInputSource::HandleControllerConnection(u32 index)
cd.connected = true;
cd.has_large_motor = caps.Vibration.wLeftMotorSpeed != 0;
cd.has_small_motor = caps.Vibration.wRightMotorSpeed != 0;
cd.last_state = {};
cd.last_state = state;
InputManager::OnInputDeviceConnected(MakeGenericControllerDeviceKey(InputSourceType::XInput, index),
fmt::format("XInput-{}", index), fmt::format("XInput Controller {}", index));

View File

@@ -69,7 +69,7 @@ private:
using ControllerDataArray = std::array<ControllerData, NUM_CONTROLLERS>;
void CheckForStateChanges(u32 index, const XINPUT_STATE& new_state);
void HandleControllerConnection(u32 index);
void HandleControllerConnection(u32 index, const XINPUT_STATE& state);
void HandleControllerDisconnection(u32 index);
ControllerDataArray m_controllers;