2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-02-10 18:54:46 +00:00
|
|
|
// Refer to the license.txt file included.
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "InputCommon/ControllerInterface/DInput/DInput.h"
|
2019-03-09 15:57:37 +00:00
|
|
|
|
|
|
|
#include "Common/Logging/Log.h"
|
2016-06-12 15:08:04 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2019-03-09 15:57:37 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "InputCommon/ControllerInterface/DInput/DInputJoystick.h"
|
|
|
|
#include "InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h"
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
#pragma comment(lib, "Dinput8.lib")
|
|
|
|
#pragma comment(lib, "dxguid.lib")
|
|
|
|
|
|
|
|
namespace ciface
|
|
|
|
{
|
2010-07-03 08:04:10 +00:00
|
|
|
namespace DInput
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
BOOL CALLBACK DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
((std::list<DIDEVICEOBJECTINSTANCE>*)pvRef)->push_back(*lpddoi);
|
|
|
|
return DIENUM_CONTINUE;
|
2010-06-21 03:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CALLBACK DIEnumDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
((std::list<DIDEVICEINSTANCE>*)pvRef)->push_back(*lpddi);
|
|
|
|
return DIENUM_CONTINUE;
|
2010-06-21 03:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
DIPROPSTRING str = {};
|
|
|
|
str.diph.dwSize = sizeof(str);
|
|
|
|
str.diph.dwHeaderSize = sizeof(str.diph);
|
|
|
|
str.diph.dwHow = DIPH_DEVICE;
|
|
|
|
|
|
|
|
std::string result;
|
|
|
|
if (SUCCEEDED(device->GetProperty(DIPROP_PRODUCTNAME, &str.diph)))
|
|
|
|
{
|
|
|
|
result = StripSpaces(UTF16ToUTF8(str.wsz));
|
|
|
|
}
|
2019-03-09 15:57:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ERROR_LOG(PAD, "GetProperty(DIPROP_PRODUCTNAME) failed.");
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
return result;
|
2010-06-21 03:12:16 +00:00
|
|
|
}
|
|
|
|
|
2016-10-16 20:39:05 +00:00
|
|
|
void PopulateDevices(HWND hwnd)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2019-03-09 15:57:37 +00:00
|
|
|
// Remove unplugged devices.
|
|
|
|
g_controller_interface.RemoveDevice(
|
|
|
|
[](const auto* dev) { return dev->GetSource() == DINPUT_SOURCE_NAME && !dev->IsValid(); });
|
2017-11-10 20:30:37 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
IDirectInput8* idi8;
|
|
|
|
if (FAILED(DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8,
|
|
|
|
(LPVOID*)&idi8, nullptr)))
|
|
|
|
{
|
2019-03-09 15:57:37 +00:00
|
|
|
ERROR_LOG(PAD, "DirectInput8Create failed.");
|
2016-06-24 08:43:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2019-04-20 14:25:11 +00:00
|
|
|
InitKeyboardMouse(idi8, hwnd);
|
2016-06-12 15:08:04 +00:00
|
|
|
InitJoystick(idi8, hwnd);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
idi8->Release();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
2019-03-09 15:57:37 +00:00
|
|
|
} // namespace DInput
|
|
|
|
} // namespace ciface
|