Skip to content

Commit

Permalink
[HID] Report passthrough as keyboard type and subtype device.
Browse files Browse the repository at this point in the history
- Added enums for: X_INPUT_DEVTYPE and X_INPUT_DEVSUBTYPE
- Fixed issue with xinput failure with keyboard flag received
  • Loading branch information
Gliniak committed Dec 23, 2024
1 parent 2e52138 commit a6e3d77
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/xenia/hid/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ enum X_INPUT_FLAG {
X_INPUT_FLAG_ANY_USER = 1 << 30
};

enum X_INPUT_DEVTYPE {
XINPUT_DEVTYPE_GAMEPAD = 0x00000001,
XINPUT_DEVTYPE_KEYBOARD = 0x00000002,
};

enum X_INPUT_DEVSUBTYPE {
XINPUT_DEVSUBTYPE_USB_KEYBOARD = 0x00000000,
XINPUT_DEVSUBTYPE_GAMEPAD = 0x00000001,
};

enum X_INPUT_GAMEPAD_BUTTON {
X_INPUT_GAMEPAD_DPAD_UP = 0x0001,
X_INPUT_GAMEPAD_DPAD_DOWN = 0x0002,
Expand Down
11 changes: 8 additions & 3 deletions src/xenia/hid/winkey/winkey_input_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@ X_RESULT WinKeyInputDriver::GetCapabilities(uint32_t user_index, uint32_t flags,
return X_ERROR_DEVICE_NOT_CONNECTED;
}

// TODO(benvanik): confirm with a real XInput controller.
out_caps->type = 0x01; // XINPUT_DEVTYPE_GAMEPAD
out_caps->sub_type = 0x01; // XINPUT_DEVSUBTYPE_GAMEPAD
if (IsPassthroughEnabled()) {
out_caps->type = X_INPUT_DEVTYPE::XINPUT_DEVTYPE_KEYBOARD;
out_caps->sub_type = X_INPUT_DEVSUBTYPE::XINPUT_DEVSUBTYPE_USB_KEYBOARD;
return X_ERROR_SUCCESS;
}

out_caps->type = X_INPUT_DEVTYPE::XINPUT_DEVTYPE_GAMEPAD;
out_caps->sub_type = X_INPUT_DEVSUBTYPE::XINPUT_DEVSUBTYPE_GAMEPAD;
out_caps->flags = 0;
out_caps->gamepad.buttons = 0xFFFF;
out_caps->gamepad.left_trigger = 0xFF;
Expand Down
4 changes: 3 additions & 1 deletion src/xenia/hid/xinput/xinput_input_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ X_RESULT XInputInputDriver::GetCapabilities(uint32_t user_index, uint32_t flags,
}
XINPUT_CAPABILITIES native_caps;
auto xigc = (decltype(&XInputGetCapabilities))XInputGetCapabilities_;
DWORD result = xigc(user_index, flags, &native_caps);
DWORD result =
xigc(user_index, flags & ~X_INPUT_DEVTYPE::XINPUT_DEVTYPE_KEYBOARD,
&native_caps);
if (result) {
if (result == ERROR_DEVICE_NOT_CONNECTED) {
set_skip(user_index);
Expand Down

0 comments on commit a6e3d77

Please sign in to comment.