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. --- .../InputCommon/ControllerInterface/DInput/DInput.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInput.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInput.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInput.cpp index e65da0eb78..cb484cc6ca 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInput.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInput.cpp @@ -3,9 +3,11 @@ // Refer to the license.txt file included. #include "InputCommon/ControllerInterface/DInput/DInput.h" + +#include "Common/Logging/Log.h" #include "Common/StringUtil.h" -#include "InputCommon/ControllerInterface/ControllerInterface.h" +#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/DInput/DInputJoystick.h" #include "InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h" @@ -40,25 +42,32 @@ std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device) { result = StripSpaces(UTF16ToUTF8(str.wsz)); } + else + { + ERROR_LOG(PAD, "GetProperty(DIPROP_PRODUCTNAME) failed."); + } return result; } void PopulateDevices(HWND hwnd) { - g_controller_interface.RemoveDevice([](const auto* dev) { return dev->GetSource() == "DInput"; }); + // Remove unplugged devices. + g_controller_interface.RemoveDevice( + [](const auto* dev) { return dev->GetSource() == DINPUT_SOURCE_NAME && !dev->IsValid(); }); IDirectInput8* idi8; if (FAILED(DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&idi8, nullptr))) { + ERROR_LOG(PAD, "DirectInput8Create failed."); return; } - InitKeyboardMouse(idi8, hwnd); + InitKeyboardMouse(idi8); InitJoystick(idi8, hwnd); idi8->Release(); } -} -} +} // namespace DInput +} // namespace ciface -- cgit v1.2.3