Skip to content

Commit

Permalink
Better handling of Device Subtype
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Jun 15, 2024
1 parent 6776db1 commit c52b85e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
2 changes: 1 addition & 1 deletion BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 63
#define BUILD_NUMBER 64
8 changes: 5 additions & 3 deletions IDirectInputDeviceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ void m_IDirectInputDeviceX::InitializeEnumObjectData()
DIDEVICEINSTANCEW didi { sizeof(didi) };
if (SUCCEEDED(ProxyInterface->GetDeviceInfo(&didi)))
{
DevType7 = ConvertDevTypeTo7(GET_DIDEVICE_TYPE(didi.dwDevType), didi.wUsagePage, didi.wUsage, didi.dwDevType & DIDEVTYPE_HID);
BOOL IsGamepad = FALSE;
DevType7 = ConvertDevTypeTo7(GET_DIDEVICE_TYPE(didi.dwDevType), didi.wUsagePage, didi.wUsage, didi.dwDevType & DIDEVTYPE_HID, IsGamepad);

// We only need to do this trickery for game controllers - keyboard/mice should be sorted fine
// If this is ever proven to be false, just add code here for other DIDEVTYPE_*
Expand Down Expand Up @@ -652,8 +653,9 @@ HRESULT m_IDirectInputDeviceX::GetDeviceInfoX(V pdidi)
DWORD devType = GET_DIDEVICE_TYPE(pdidi->dwDevType);
DWORD devSubType = GET_DIDEVICE_SUBTYPE(pdidi->dwDevType);
DWORD hidDevice = pdidi->dwDevType & DIDEVTYPE_HID;
DWORD devType7 = ConvertDevTypeTo7(devType, pdidi->wUsagePage, pdidi->wUsage, hidDevice);
DWORD devSubType7 = ConvertDevSubTypeTo7(devType, devSubType);
BOOL IsGamepad = FALSE;
DWORD devType7 = ConvertDevTypeTo7(devType, pdidi->wUsagePage, pdidi->wUsage, hidDevice, IsGamepad);
DWORD devSubType7 = ConvertDevSubTypeTo7(devType, devType7, devSubType, IsGamepad);
pdidi->dwDevType = devType7 | (devSubType7 << 8) | hidDevice;
}

Expand Down
39 changes: 35 additions & 4 deletions IDirectInputTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#include "dinputto8.h"
#include <hidusage.h>

DWORD ConvertDevTypeTo7(DWORD dwDevType, WORD wUsagePage, WORD wUsage, BOOL isHID)
DWORD ConvertDevTypeTo7(DWORD dwDevType, WORD wUsagePage, WORD wUsage, BOOL isHID, BOOL& IsGamepad)
{
IsGamepad = FALSE;
switch (dwDevType)
{
case DIDEVTYPE_DEVICE:
Expand All @@ -31,10 +32,15 @@ DWORD ConvertDevTypeTo7(DWORD dwDevType, WORD wUsagePage, WORD wUsage, BOOL isHI
{
return DIDEVTYPE_MOUSE;
}
else if (wUsage == HID_USAGE_GENERIC_JOYSTICK || wUsage == HID_USAGE_GENERIC_GAMEPAD)
else if (wUsage == HID_USAGE_GENERIC_JOYSTICK)
{
return DIDEVTYPE_JOYSTICK;
}
else if (wUsage == HID_USAGE_GENERIC_GAMEPAD)
{
IsGamepad = TRUE;
return DIDEVTYPE_JOYSTICK;
}
else if (wUsage == HID_USAGE_GENERIC_KEYBOARD)
{
return DIDEVTYPE_KEYBOARD;
Expand All @@ -51,9 +57,11 @@ DWORD ConvertDevTypeTo7(DWORD dwDevType, WORD wUsagePage, WORD wUsage, BOOL isHI
case DIDEVTYPE_KEYBOARD:
case DI8DEVTYPE_KEYBOARD:
return DIDEVTYPE_KEYBOARD;
case DI8DEVTYPE_GAMEPAD:
IsGamepad = TRUE;
[[fallthrough]];
case DIDEVTYPE_JOYSTICK:
case DI8DEVTYPE_JOYSTICK:
case DI8DEVTYPE_GAMEPAD:
case DI8DEVTYPE_DRIVING:
case DI8DEVTYPE_FLIGHT:
case DI8DEVTYPE_SUPPLEMENTAL:
Expand All @@ -64,14 +72,37 @@ DWORD ConvertDevTypeTo7(DWORD dwDevType, WORD wUsagePage, WORD wUsage, BOOL isHI
}
}

DWORD ConvertDevSubTypeTo7(DWORD dwDevType, DWORD dwDevSubType)
DWORD ConvertDevSubTypeTo7(DWORD dwDevType, DWORD dwDevType7, DWORD dwDevSubType, BOOL IsGamepad)
{
switch (dwDevType)
{
case DIDEVTYPE_DEVICE:
case DI8DEVTYPE_DEVICE:
case DI8DEVTYPE_DEVICECTRL:
default:
switch (dwDevType7)
{
case DIDEVTYPE_MOUSE:
switch (dwDevSubType)
{
case DIDEVTYPEMOUSE_TRADITIONAL:
case DIDEVTYPEMOUSE_FINGERSTICK:
case DIDEVTYPEMOUSE_TOUCHPAD:
case DIDEVTYPEMOUSE_TRACKBALL:
return dwDevSubType;
case DI8DEVTYPEMOUSE_ABSOLUTE:
return DIDEVTYPEMOUSE_TOUCHPAD;
default:
return DIDEVTYPEMOUSE_UNKNOWN;
}
case DIDEVTYPE_KEYBOARD:
return DIDEVTYPEKEYBOARD_UNKNOWN;
case DIDEVTYPE_JOYSTICK:
if (IsGamepad)
return DIDEVTYPEJOYSTICK_GAMEPAD;
else
return DIDEVTYPEJOYSTICK_TRADITIONAL;
}
return 0;
case DIDEVTYPE_MOUSE:
case DI8DEVTYPE_MOUSE:
Expand Down
4 changes: 2 additions & 2 deletions IDirectInputTypes.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

DWORD ConvertDevTypeTo7(DWORD dwDevType, WORD wUsagePage, WORD wUsage, BOOL isHID);
DWORD ConvertDevSubTypeTo7(DWORD dwDevType, DWORD dwDevSubType);
DWORD ConvertDevTypeTo7(DWORD dwDevType, WORD wUsagePage, WORD wUsage, BOOL isHID, BOOL& IsGamepad);
DWORD ConvertDevSubTypeTo7(DWORD dwDevType, DWORD dwDevType7, DWORD dwDevSubType, BOOL IsGamepad);
5 changes: 3 additions & 2 deletions IDirectInputX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ HRESULT m_IDirectInputX::EnumDevicesX(DWORD dwDevType, V lpCallback, LPVOID pvRe
DWORD devType = GET_DIDEVICE_TYPE(lpddi->dwDevType);
DWORD devSubType = GET_DIDEVICE_SUBTYPE(lpddi->dwDevType);
DWORD hidDevice = lpddi->dwDevType & DIDEVTYPE_HID;
DWORD devType7 = ConvertDevTypeTo7(devType, lpddi->wUsagePage, lpddi->wUsage, hidDevice);
DWORD devSubType7 = ConvertDevSubTypeTo7(devType, devSubType);
BOOL IsGamepad = FALSE;
DWORD devType7 = ConvertDevTypeTo7(devType, lpddi->wUsagePage, lpddi->wUsage, hidDevice, IsGamepad);
DWORD devSubType7 = ConvertDevSubTypeTo7(devType, devType7, devSubType, IsGamepad);

// DirectInput 0x300 and earlier do not enumerate any game controllers
if (devType7 == DIDEVTYPE_JOYSTICK && self->diVersion <= 0x300)
Expand Down

0 comments on commit c52b85e

Please sign in to comment.