mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-04 05:04:33 +00:00
InputSource: Remove before calling OnInputDeviceDisconnected()
Fixes background polling interval not decreasing after last device disconnects.
This commit is contained in:
@@ -168,9 +168,9 @@ void DInputSource::Shutdown()
|
||||
while (!m_controllers.empty())
|
||||
{
|
||||
const u32 index = static_cast<u32>(m_controllers.size() - 1);
|
||||
InputManager::OnInputDeviceDisconnected(MakeGenericControllerDeviceKey(InputSourceType::DInput, index),
|
||||
GetDeviceIdentifier(static_cast<u32>(m_controllers.size() - 1)));
|
||||
m_controllers.pop_back();
|
||||
InputManager::OnInputDeviceDisconnected(MakeGenericControllerDeviceKey(InputSourceType::DInput, index),
|
||||
GetDeviceIdentifier(index));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,14 +272,10 @@ void DInputSource::PollEvents()
|
||||
|
||||
if (hr != DI_OK)
|
||||
{
|
||||
InputManager::OnInputDeviceDisconnected(InputBindingKey{{.source_type = InputSourceType::DInput,
|
||||
.source_index = static_cast<u32>(i),
|
||||
.source_subtype = InputSubclass::None,
|
||||
.modifier = InputModifier::None,
|
||||
.invert = 0,
|
||||
.data = 0}},
|
||||
GetDeviceIdentifier(static_cast<u32>(i)));
|
||||
m_controllers.erase(m_controllers.begin() + i);
|
||||
InputManager::OnInputDeviceDisconnected(
|
||||
MakeGenericControllerDeviceKey(InputSourceType::DInput, static_cast<u32>(i)),
|
||||
GetDeviceIdentifier(static_cast<u32>(i)));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,11 +291,12 @@ bool Win32RawInputSource::ReloadDevices()
|
||||
{
|
||||
DEV_LOG("Detected raw input device {} removal", i);
|
||||
|
||||
ms = {};
|
||||
|
||||
InputManager::OnInputDeviceDisconnected(
|
||||
MakeGenericControllerDeviceKey(InputSourceType::Pointer, static_cast<u32>(i)),
|
||||
InputManager::GetPointerDeviceName(static_cast<u32>(i)));
|
||||
|
||||
ms = {};
|
||||
any_changed = true;
|
||||
}
|
||||
}
|
||||
@@ -343,12 +344,14 @@ void Win32RawInputSource::CloseDevices()
|
||||
if (m_mice.empty())
|
||||
return;
|
||||
|
||||
for (u32 i = 0; i < static_cast<u32>(m_mice.size()); i++)
|
||||
m_mice.clear();
|
||||
|
||||
const u32 num_mice = static_cast<u32>(m_mice.size());
|
||||
for (u32 i = 0; i < num_mice; i++)
|
||||
{
|
||||
InputManager::OnInputDeviceDisconnected(MakeGenericControllerDeviceKey(InputSourceType::Pointer, i),
|
||||
InputManager::GetPointerDeviceName(i));
|
||||
}
|
||||
m_mice.clear();
|
||||
}
|
||||
|
||||
void Win32RawInputSource::EnsureRawInputRegistered()
|
||||
|
||||
@@ -238,13 +238,23 @@ InputManager::DeviceList XInputSource::EnumerateDevices()
|
||||
if (!m_controllers[i].connected)
|
||||
continue;
|
||||
|
||||
ret.emplace_back(MakeGenericControllerDeviceKey(InputSourceType::XInput, i), fmt::format("XInput-{}", i),
|
||||
fmt::format("XInput Controller {}", i));
|
||||
ret.emplace_back(MakeGenericControllerDeviceKey(InputSourceType::XInput, i), GetDeviceIdentifier(i),
|
||||
GetDeviceName(i));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string XInputSource::GetDeviceIdentifier(u32 index)
|
||||
{
|
||||
return fmt::format("XInput-{}", index);
|
||||
}
|
||||
|
||||
std::string XInputSource::GetDeviceName(u32 index)
|
||||
{
|
||||
return fmt::format("XInput Controller {}", index);
|
||||
}
|
||||
|
||||
bool XInputSource::ContainsDevice(std::string_view device) const
|
||||
{
|
||||
return device.starts_with("XInput-");
|
||||
@@ -458,16 +468,17 @@ void XInputSource::HandleControllerConnection(u32 index, const XINPUT_STATE& sta
|
||||
cd.last_state = state;
|
||||
|
||||
InputManager::OnInputDeviceConnected(MakeGenericControllerDeviceKey(InputSourceType::XInput, index),
|
||||
fmt::format("XInput-{}", index), fmt::format("XInput Controller {}", index));
|
||||
GetDeviceIdentifier(index), GetDeviceName(index));
|
||||
}
|
||||
|
||||
void XInputSource::HandleControllerDisconnection(u32 index)
|
||||
{
|
||||
INFO_LOG("XInput controller {} disconnected.", index);
|
||||
|
||||
InputManager::OnInputDeviceDisconnected(MakeGenericControllerDeviceKey(InputSourceType::XInput, index),
|
||||
fmt::format("XInput-{}", index));
|
||||
m_controllers[index] = {};
|
||||
|
||||
InputManager::OnInputDeviceDisconnected(MakeGenericControllerDeviceKey(InputSourceType::XInput, index),
|
||||
GetDeviceIdentifier(index));
|
||||
}
|
||||
|
||||
void XInputSource::CheckForStateChanges(u32 index, const XINPUT_STATE& new_state)
|
||||
|
||||
@@ -75,6 +75,9 @@ private:
|
||||
void HandleControllerConnection(u32 index, const XINPUT_STATE& state);
|
||||
void HandleControllerDisconnection(u32 index);
|
||||
|
||||
static std::string GetDeviceIdentifier(u32 index);
|
||||
static std::string GetDeviceName(u32 index);
|
||||
|
||||
ControllerDataArray m_controllers;
|
||||
|
||||
HMODULE m_xinput_module{};
|
||||
|
||||
Reference in New Issue
Block a user