diff options
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 3da92e8b75..bb5ccb3f0e 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -8,11 +8,8 @@ #include "Common/Logging/Log.h" -#ifdef CIFACE_USE_XINPUT -#include "InputCommon/ControllerInterface/XInput/XInput.h" -#endif -#ifdef CIFACE_USE_DINPUT -#include "InputCommon/ControllerInterface/DInput/DInput.h" +#ifdef CIFACE_USE_WIN32 +#include "InputCommon/ControllerInterface/Win32/Win32.h" #endif #ifdef CIFACE_USE_XLIB #include "InputCommon/ControllerInterface/Xlib/XInput2.h" @@ -48,11 +45,8 @@ void ControllerInterface::Initialize(const WindowSystemInfo& wsi) m_is_populating_devices = true; -#ifdef CIFACE_USE_DINPUT -// nothing needed -#endif -#ifdef CIFACE_USE_XINPUT - ciface::XInput::Init(); +#ifdef CIFACE_USE_WIN32 + ciface::Win32::Init(wsi.render_surface); #endif #ifdef CIFACE_USE_XLIB // nothing needed @@ -99,12 +93,11 @@ void ControllerInterface::RefreshDevices() m_is_populating_devices = true; -#ifdef CIFACE_USE_DINPUT - if (m_wsi.type == WindowSystemType::Windows) - ciface::DInput::PopulateDevices(reinterpret_cast<HWND>(m_wsi.render_surface)); -#endif -#ifdef CIFACE_USE_XINPUT - ciface::XInput::PopulateDevices(); + // Make sure shared_ptr<Device> objects are released before repopulating. + InvokeDevicesChangedCallbacks(); + +#ifdef CIFACE_USE_WIN32 + ciface::Win32::PopulateDevices(m_wsi.render_surface); #endif #ifdef CIFACE_USE_XLIB if (m_wsi.type == WindowSystemType::X11) @@ -160,11 +153,8 @@ void ControllerInterface::Shutdown() // BEFORE we shutdown the backends. InvokeDevicesChangedCallbacks(); -#ifdef CIFACE_USE_XINPUT - ciface::XInput::DeInit(); -#endif -#ifdef CIFACE_USE_DINPUT -// nothing needed +#ifdef CIFACE_USE_WIN32 + ciface::Win32::DeInit(); #endif #ifdef CIFACE_USE_XLIB // nothing needed @@ -192,21 +182,29 @@ void ControllerInterface::AddDevice(std::shared_ptr<ciface::Core::Device> device { std::lock_guard<std::mutex> lk(m_devices_mutex); - // Try to find an ID for this device - int id = 0; - while (true) + + const auto is_id_in_use = [&device, this](int id) { + return std::any_of(m_devices.begin(), m_devices.end(), [&device, &id](const auto& d) { + return d->GetSource() == device->GetSource() && d->GetName() == device->GetName() && + d->GetId() == id; + }); + }; + + const auto preferred_id = device->GetPreferredId(); + if (preferred_id.has_value() && !is_id_in_use(*preferred_id)) { - const auto it = - std::find_if(m_devices.begin(), m_devices.end(), [&device, &id](const auto& d) { - return d->GetSource() == device->GetSource() && d->GetName() == device->GetName() && - d->GetId() == id; - }); - if (it == m_devices.end()) // no device with the same name with this ID, so we can use it - break; - else - id++; + // Use the device's preferred ID if available. + device->SetId(*preferred_id); + } + else + { + // Find the first available ID to use. + int id = 0; + while (is_id_in_use(id)) + ++id; + + device->SetId(id); } - device->SetId(id); NOTICE_LOG(SERIALINTERFACE, "Added device: %s", device->GetQualifiedName().c_str()); m_devices.emplace_back(std::move(device)); |
