rawinput: add basic support for xinput (#617)

## Link to GitHub Issue or related Pull Request, if one exists
#616 

## Description of change
Adds preliminary support for XInput controllers. Enough to manually bind
buttons and map analogs.
This commit is contained in:
bicarus
2026-04-09 02:49:20 -07:00
committed by GitHub
parent f89efa2558
commit 7b4227d2a9
13 changed files with 511 additions and 6 deletions
+31
View File
@@ -70,6 +70,8 @@ void rawinput::set_midi_algorithm(rawinput::MidiNoteAlgorithm new_algo) {
rawinput::RawInputManager::RawInputManager() {
XINPUT_MGR = std::make_unique<xinput::XInputManager>();
// create input window and load in devices
this->input_hwnd_create();
this->devices_reload();
@@ -106,6 +108,8 @@ void rawinput::RawInputManager::stop() {
// destruct all devices and input window
this->devices_destruct();
this->input_hwnd_destroy();
XINPUT_MGR.reset();
}
void rawinput::RawInputManager::input_hwnd_create() {
@@ -191,6 +195,8 @@ void rawinput::RawInputManager::devices_reload() {
this->devices_scan_smxdedicab();
}
this->devices_scan_xinput();
// check for LIT Board
sextet_register("COM54", "LIT Board", false);
@@ -1009,6 +1015,27 @@ void rawinput::RawInputManager::devices_scan_smxdedicab() {
}
}
void rawinput::RawInputManager::devices_scan_xinput() {
log_misc("rawinput", "scan XInput devices...");
const auto players = XINPUT_MGR->get_available_players();
for (const auto player : players) {
auto *new_xinput_device = new Device();
new_xinput_device->type = XINPUT_GAMEPAD;
new_xinput_device->name = fmt::format(";XINPUT;{}", player);
new_xinput_device->desc = fmt::format("XInput Gamepad P{}", player + 1);
new_xinput_device->handle = reinterpret_cast<HANDLE>(player);
new_xinput_device->mutex = new std::mutex();
new_xinput_device->mutex_out = new std::mutex();
auto &device = this->devices.emplace_back(*new_xinput_device);
// notify add
for (auto &cb : this->callback_add) {
cb.f(cb.data, &device);
}
}
}
void rawinput::RawInputManager::flush_start() {
// start flush thread
@@ -2734,6 +2761,10 @@ void rawinput::RawInputManager::devices_print() {
log_misc("rawinput", "device type: SMX_DEDICAB");
break;
}
case XINPUT_GAMEPAD: {
log_misc("rawinput", "device type: XINPUT");
break;
}
case UNKNOWN:
default:
log_warning("rawinput", "device type: UNKNOWN");