From 92ca6e124e82f63b61982a5ecfb26ca818f2fe47 Mon Sep 17 00:00:00 2001 From: Michael M Date: Fri, 10 Nov 2017 09:56:13 -0800 Subject: Add ControllerInterface::Win32 to wrap XInput and DInput --- .../ControllerInterface/ControllerInterface.cpp | 31 +++++++--------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 3da92e8b75..6eeb41e8b8 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(); #endif #ifdef CIFACE_USE_XLIB // nothing needed @@ -99,12 +93,8 @@ void ControllerInterface::RefreshDevices() m_is_populating_devices = true; -#ifdef CIFACE_USE_DINPUT - if (m_wsi.type == WindowSystemType::Windows) - ciface::DInput::PopulateDevices(reinterpret_cast(m_wsi.render_surface)); -#endif -#ifdef CIFACE_USE_XINPUT - ciface::XInput::PopulateDevices(); +#ifdef CIFACE_USE_WIN32 + ciface::Win32::PopulateDevices(m_wsi.render_surface); #endif #ifdef CIFACE_USE_XLIB if (m_wsi.type == WindowSystemType::X11) @@ -160,14 +150,11 @@ 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 + // nothing needed #endif #ifdef CIFACE_USE_OSX ciface::OSX::DeInit(); -- cgit v1.2.3 From d26c1ce24d9108114d7eab97cfc2ab4f3eea28ee Mon Sep 17 00:00:00 2001 From: Michael M Date: Fri, 10 Nov 2017 12:30:37 -0800 Subject: Add hotplug support to DInput and XInput controller backends --- Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 6eeb41e8b8..3a4f374c9d 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -46,7 +46,7 @@ void ControllerInterface::Initialize(const WindowSystemInfo& wsi) m_is_populating_devices = true; #ifdef CIFACE_USE_WIN32 - ciface::Win32::Init(); + ciface::Win32::Init(wsi.render_surface); #endif #ifdef CIFACE_USE_XLIB // nothing needed @@ -154,7 +154,7 @@ void ControllerInterface::Shutdown() ciface::Win32::DeInit(); #endif #ifdef CIFACE_USE_XLIB - // nothing needed +// nothing needed #endif #ifdef CIFACE_USE_OSX ciface::OSX::DeInit(); -- cgit v1.2.3 From eadbdd6bc389cd89c3e3e57a31dabaeadf161865 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sat, 9 Mar 2019 09:57:37 -0600 Subject: ControllerInterface/Win32: Prevent devcies from losing their "id" on a hotplug event. --- .../ControllerInterface/ControllerInterface.cpp | 37 ++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 3a4f374c9d..bb5ccb3f0e 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -93,6 +93,9 @@ void ControllerInterface::RefreshDevices() m_is_populating_devices = true; + // Make sure shared_ptr objects are released before repopulating. + InvokeDevicesChangedCallbacks(); + #ifdef CIFACE_USE_WIN32 ciface::Win32::PopulateDevices(m_wsi.render_surface); #endif @@ -179,21 +182,29 @@ void ControllerInterface::AddDevice(std::shared_ptr device { std::lock_guard 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)); -- cgit v1.2.3