Add gamepad forwarding through OpenXR

Forward a gamepad paired to the headset to the server. Useful when the controller is in range of the headset but not the server, such as a DualSense paired to a Quest over Bluetooth.

The headset reads the gamepad through the OpenXR microsoft/xbox_controller profile and forwards it on the existing input rails: gamepad device ids in the inputs packet, plus a gamepad entry in the interaction profile array that signals connection and disconnection from the tracking thread.

The server exposes a native OpenXR gamepad at /user/gamepad, connected while the headset reports a gamepad interaction profile. This needs no permission and is always available.

Rumble is sent back to the headset and applied through OpenXR haptics.
This commit is contained in:
JR Lanteigne
2026-07-08 19:10:50 +02:00
committed by xytovl
parent 9935203cfb
commit aeecc857de
14 changed files with 580 additions and 103 deletions
+11
View File
@@ -126,6 +126,11 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
static_roles.hand_tracking.unobstructed.right = static_xdevs[right_controller_index] = &right_controller;
static_xdevs[right_hand_interaction_index = static_xdev_count++] = &right_hand_interaction;
// Expose a gamepad forwarded from the headset as a native OpenXR device (/user/gamepad).
// Always present; inactive until the headset reports a connected gamepad.
roles.gamepad = static_xdev_count;
static_xdevs[static_xdev_count++] = &gamepad_device.emplace(*this);
#if WIVRN_FEATURE_STEAMVR_LIGHTHOUSE
auto use_steamvr_lh = configuration().use_steamvr_lh || std::getenv("WIVRN_USE_STEAMVR_LH");
xrt_system_devices * lhdevs = NULL;
@@ -543,6 +548,9 @@ static xrt_device_name get_name(interaction_profile profile)
void wivrn_session::operator()(const from_headset::tracking & tracking)
{
if (gamepad_device)
gamepad_device->set_connected(tracking.interaction_profiles[2] != interaction_profile::none);
auto left = (roles.left == -1 || roles.left == left_controller_index || roles.left == left_hand_interaction_index) ? get_name(tracking.interaction_profiles[0]) : XRT_DEVICE_INVALID;
auto right = (roles.right == -1 || roles.right == right_controller_index || roles.right == right_hand_interaction_index) ? get_name(tracking.interaction_profiles[1]) : XRT_DEVICE_INVALID;
if (left != roles.left_profile or right != roles.right_profile)
@@ -673,6 +681,9 @@ void wivrn_session::operator()(from_headset::inputs && inputs)
right_hand_interaction.set_inputs(inputs, offset);
else if (roles.right == right_controller_index)
right_controller.set_inputs(inputs, offset);
if (gamepad_device)
gamepad_device->set_inputs(inputs);
}
void wivrn_session::operator()(from_headset::hid::input && e)