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
+118 -92
View File
@@ -43,96 +43,122 @@ static constexpr int protocol_revision = 2;
enum class device_id : uint8_t
{
HEAD, // /user/head
LEFT_CONTROLLER_HAPTIC, // /user/hand/left/output/haptic
RIGHT_CONTROLLER_HAPTIC, // /user/hand/right/output/haptic
LEFT_TRIGGER_HAPTIC, // /user/hand/left/output/haptic_trigger
RIGHT_TRIGGER_HAPTIC, // /user/hand/right/output/haptic_trigger
LEFT_THUMB_HAPTIC, // /user/hand/left/output/haptic_thumb
RIGHT_THUMB_HAPTIC, // /user/hand/right/output/haptic_thumb
LEFT_GRIP, // /user/hand/left/input/grip/pose
LEFT_AIM, // /user/hand/left/input/aim/pose
LEFT_PALM, // /user/hand/left/palm_ext/pose
RIGHT_GRIP, // /user/hand/right/input/grip/pose
RIGHT_AIM, // /user/hand/right/input/aim/pose
RIGHT_PALM, // /user/hand/right/palm_ext/pose
X_CLICK, // /user/hand/left/input/x/click
X_TOUCH, // /user/hand/left/input/x/touch
Y_CLICK, // /user/hand/left/input/y/click
Y_TOUCH, // /user/hand/left/input/y/touch
MENU_CLICK, // /user/hand/left/input/menu/click
LEFT_SQUEEZE_CLICK, // /user/hand/left/input/squeeze/click
LEFT_SQUEEZE_FORCE, // /user/hand/left/input/squeeze/force
LEFT_SQUEEZE_VALUE, // /user/hand/left/input/squeeze/value
LEFT_TRIGGER_CLICK, // /user/hand/left/input/trigger/click
LEFT_TRIGGER_VALUE, // /user/hand/left/input/trigger/value
LEFT_TRIGGER_TOUCH, // /user/hand/left/input/trigger/touch
LEFT_TRIGGER_PROXIMITY, // /user/hand/left/input/trigger/proximity
LEFT_TRIGGER_CURL, // /user/hand/left/input/trigger/curl_fb
LEFT_TRIGGER_SLIDE, // /user/hand/left/input/trigger/slide_fb
LEFT_TRIGGER_FORCE, // /user/hand/left/input/trigger/force
LEFT_THUMBSTICK_X, // /user/hand/left/input/thumbstick/x
LEFT_THUMBSTICK_Y, // /user/hand/left/input/thumbstick/y
LEFT_THUMBSTICK_CLICK, // /user/hand/left/input/thumbstick/click
LEFT_THUMBSTICK_TOUCH, // /user/hand/left/input/thumbstick/touch
LEFT_THUMBREST_TOUCH, // /user/hand/left/input/thumbrest/touch
LEFT_THUMBREST_FORCE, // /user/hand/left/input/thumbrest/force
LEFT_THUMB_PROXIMITY, // /user/hand/left/input/thumb_resting_surfaces/proximity
LEFT_TRACKPAD_X, // /user/hand/left/input/trackpad/x
LEFT_TRACKPAD_Y, // /user/hand/left/input/trackpad/y
LEFT_TRACKPAD_CLICK, // /user/hand/left/input/trackpad/click
LEFT_TRACKPAD_TOUCH, // /user/hand/left/input/trackpad/touch
LEFT_TRACKPAD_FORCE, // /user/hand/left/input/trackpad/force
LEFT_STYLUS_FORCE, // /user/hand/left/input/stylus_fb/force
LEFT_PINCH_POSE, // /user/hand/left/input/pinch_ext/pose
LEFT_PINCH_VALUE, // /user/hand/left/input/pinch_ext/value
LEFT_PINCH_READY, // /user/hand/left/input/pinch_ext/ready_ext
LEFT_POKE, // /user/hand/left/input/poke_ext/pose
LEFT_AIM_ACTIVATE_VALUE, // /user/hand/left/input/aim_activate_ext/value
LEFT_AIM_ACTIVATE_READY, // /user/hand/left/input/aim_activate_ext/ready_ext
LEFT_GRASP_VALUE, // /user/hand/left/input/grasp_ext/value
LEFT_GRASP_READY, // /user/hand/left/input/grasp_ext/ready_ext
A_CLICK, // /user/hand/right/input/a/click
A_TOUCH, // /user/hand/right/input/a/touch
B_CLICK, // /user/hand/right/input/b/click
B_TOUCH, // /user/hand/right/input/b/touch
SYSTEM_CLICK, // /user/hand/right/input/system/click
RIGHT_SQUEEZE_CLICK, // /user/hand/right/input/squeeze/click
RIGHT_SQUEEZE_FORCE, // /user/hand/right/input/squeeze/force
RIGHT_SQUEEZE_VALUE, // /user/hand/right/input/squeeze/value
RIGHT_TRIGGER_CLICK, // /user/hand/right/input/trigger/click
RIGHT_TRIGGER_VALUE, // /user/hand/right/input/trigger/value
RIGHT_TRIGGER_TOUCH, // /user/hand/right/input/trigger/touch
RIGHT_TRIGGER_PROXIMITY, // /user/hand/right/input/trigger/proximity
RIGHT_TRIGGER_CURL, // /user/hand/right/input/trigger/curl_fb
RIGHT_TRIGGER_SLIDE, // /user/hand/right/input/trigger/slide_fb
RIGHT_TRIGGER_FORCE, // /user/hand/right/input/trigger/force
RIGHT_THUMBSTICK_X, // /user/hand/right/input/thumbstick/x
RIGHT_THUMBSTICK_Y, // /user/hand/right/input/thumbstick/y
RIGHT_THUMBSTICK_CLICK, // /user/hand/right/input/thumbstick/click
RIGHT_THUMBSTICK_TOUCH, // /user/hand/right/input/thumbstick/touch
RIGHT_THUMBREST_TOUCH, // /user/hand/right/input/thumbrest/touch
RIGHT_THUMBREST_FORCE, // /user/hand/right/input/thumbrest/force
RIGHT_THUMB_PROXIMITY, // /user/hand/right/input/thumb_resting_surfaces/proximity
RIGHT_TRACKPAD_X, // /user/hand/right/input/trackpad/x
RIGHT_TRACKPAD_Y, // /user/hand/right/input/trackpad/y
RIGHT_TRACKPAD_CLICK, // /user/hand/right/input/trackpad/click
RIGHT_TRACKPAD_TOUCH, // /user/hand/right/input/trackpad/touch
RIGHT_TRACKPAD_FORCE, // /user/hand/right/input/trackpad/force
RIGHT_STYLUS_FORCE, // /user/hand/right/input/stylus_fb/force
RIGHT_PINCH_POSE, // /user/hand/right/input/pinch_ext/pose
RIGHT_PINCH_VALUE, // /user/hand/right/input/pinch_ext/value
RIGHT_PINCH_READY, // /user/hand/right/input/pinch_ext/ready_ext
RIGHT_POKE, // /user/hand/right/input/poke_ext/pose
RIGHT_AIM_ACTIVATE_VALUE, // /user/hand/right/input/aim_activate_ext/value
RIGHT_AIM_ACTIVATE_READY, // /user/hand/right/input/aim_activate_ext/ready_ext
RIGHT_GRASP_VALUE, // /user/hand/right/input/grasp_ext/value
RIGHT_GRASP_READY, // /user/hand/right/input/grasp_ext/ready_ext
EYE_GAZE, // /user/eyes_ext/input/gaze_ext/pose
LEFT_HAND, // identify hand tracking
RIGHT_HAND, // identify hand tracking
BODY, // identify body tracking
FACE, // identify face tracking
HEAD, // /user/head
LEFT_CONTROLLER_HAPTIC, // /user/hand/left/output/haptic
RIGHT_CONTROLLER_HAPTIC, // /user/hand/right/output/haptic
LEFT_TRIGGER_HAPTIC, // /user/hand/left/output/haptic_trigger
RIGHT_TRIGGER_HAPTIC, // /user/hand/right/output/haptic_trigger
LEFT_THUMB_HAPTIC, // /user/hand/left/output/haptic_thumb
RIGHT_THUMB_HAPTIC, // /user/hand/right/output/haptic_thumb
GAMEPAD_HAPTIC_LEFT, // /user/gamepad/output/haptic_left
GAMEPAD_HAPTIC_RIGHT, // /user/gamepad/output/haptic_right
GAMEPAD_HAPTIC_LEFT_TRIGGER, // /user/gamepad/output/haptic_left_trigger
GAMEPAD_HAPTIC_RIGHT_TRIGGER, // /user/gamepad/output/haptic_right_trigger
LEFT_GRIP, // /user/hand/left/input/grip/pose
LEFT_AIM, // /user/hand/left/input/aim/pose
LEFT_PALM, // /user/hand/left/palm_ext/pose
RIGHT_GRIP, // /user/hand/right/input/grip/pose
RIGHT_AIM, // /user/hand/right/input/aim/pose
RIGHT_PALM, // /user/hand/right/palm_ext/pose
X_CLICK, // /user/hand/left/input/x/click
X_TOUCH, // /user/hand/left/input/x/touch
Y_CLICK, // /user/hand/left/input/y/click
Y_TOUCH, // /user/hand/left/input/y/touch
MENU_CLICK, // /user/hand/left/input/menu/click
LEFT_SQUEEZE_CLICK, // /user/hand/left/input/squeeze/click
LEFT_SQUEEZE_FORCE, // /user/hand/left/input/squeeze/force
LEFT_SQUEEZE_VALUE, // /user/hand/left/input/squeeze/value
LEFT_TRIGGER_CLICK, // /user/hand/left/input/trigger/click
LEFT_TRIGGER_VALUE, // /user/hand/left/input/trigger/value
LEFT_TRIGGER_TOUCH, // /user/hand/left/input/trigger/touch
LEFT_TRIGGER_PROXIMITY, // /user/hand/left/input/trigger/proximity
LEFT_TRIGGER_CURL, // /user/hand/left/input/trigger/curl_fb
LEFT_TRIGGER_SLIDE, // /user/hand/left/input/trigger/slide_fb
LEFT_TRIGGER_FORCE, // /user/hand/left/input/trigger/force
LEFT_THUMBSTICK_X, // /user/hand/left/input/thumbstick/x
LEFT_THUMBSTICK_Y, // /user/hand/left/input/thumbstick/y
LEFT_THUMBSTICK_CLICK, // /user/hand/left/input/thumbstick/click
LEFT_THUMBSTICK_TOUCH, // /user/hand/left/input/thumbstick/touch
LEFT_THUMBREST_TOUCH, // /user/hand/left/input/thumbrest/touch
LEFT_THUMBREST_FORCE, // /user/hand/left/input/thumbrest/force
LEFT_THUMB_PROXIMITY, // /user/hand/left/input/thumb_resting_surfaces/proximity
LEFT_TRACKPAD_X, // /user/hand/left/input/trackpad/x
LEFT_TRACKPAD_Y, // /user/hand/left/input/trackpad/y
LEFT_TRACKPAD_CLICK, // /user/hand/left/input/trackpad/click
LEFT_TRACKPAD_TOUCH, // /user/hand/left/input/trackpad/touch
LEFT_TRACKPAD_FORCE, // /user/hand/left/input/trackpad/force
LEFT_STYLUS_FORCE, // /user/hand/left/input/stylus_fb/force
LEFT_PINCH_POSE, // /user/hand/left/input/pinch_ext/pose
LEFT_PINCH_VALUE, // /user/hand/left/input/pinch_ext/value
LEFT_PINCH_READY, // /user/hand/left/input/pinch_ext/ready_ext
LEFT_POKE, // /user/hand/left/input/poke_ext/pose
LEFT_AIM_ACTIVATE_VALUE, // /user/hand/left/input/aim_activate_ext/value
LEFT_AIM_ACTIVATE_READY, // /user/hand/left/input/aim_activate_ext/ready_ext
LEFT_GRASP_VALUE, // /user/hand/left/input/grasp_ext/value
LEFT_GRASP_READY, // /user/hand/left/input/grasp_ext/ready_ext
A_CLICK, // /user/hand/right/input/a/click
A_TOUCH, // /user/hand/right/input/a/touch
B_CLICK, // /user/hand/right/input/b/click
B_TOUCH, // /user/hand/right/input/b/touch
SYSTEM_CLICK, // /user/hand/right/input/system/click
RIGHT_SQUEEZE_CLICK, // /user/hand/right/input/squeeze/click
RIGHT_SQUEEZE_FORCE, // /user/hand/right/input/squeeze/force
RIGHT_SQUEEZE_VALUE, // /user/hand/right/input/squeeze/value
RIGHT_TRIGGER_CLICK, // /user/hand/right/input/trigger/click
RIGHT_TRIGGER_VALUE, // /user/hand/right/input/trigger/value
RIGHT_TRIGGER_TOUCH, // /user/hand/right/input/trigger/touch
RIGHT_TRIGGER_PROXIMITY, // /user/hand/right/input/trigger/proximity
RIGHT_TRIGGER_CURL, // /user/hand/right/input/trigger/curl_fb
RIGHT_TRIGGER_SLIDE, // /user/hand/right/input/trigger/slide_fb
RIGHT_TRIGGER_FORCE, // /user/hand/right/input/trigger/force
RIGHT_THUMBSTICK_X, // /user/hand/right/input/thumbstick/x
RIGHT_THUMBSTICK_Y, // /user/hand/right/input/thumbstick/y
RIGHT_THUMBSTICK_CLICK, // /user/hand/right/input/thumbstick/click
RIGHT_THUMBSTICK_TOUCH, // /user/hand/right/input/thumbstick/touch
RIGHT_THUMBREST_TOUCH, // /user/hand/right/input/thumbrest/touch
RIGHT_THUMBREST_FORCE, // /user/hand/right/input/thumbrest/force
RIGHT_THUMB_PROXIMITY, // /user/hand/right/input/thumb_resting_surfaces/proximity
RIGHT_TRACKPAD_X, // /user/hand/right/input/trackpad/x
RIGHT_TRACKPAD_Y, // /user/hand/right/input/trackpad/y
RIGHT_TRACKPAD_CLICK, // /user/hand/right/input/trackpad/click
RIGHT_TRACKPAD_TOUCH, // /user/hand/right/input/trackpad/touch
RIGHT_TRACKPAD_FORCE, // /user/hand/right/input/trackpad/force
RIGHT_STYLUS_FORCE, // /user/hand/right/input/stylus_fb/force
RIGHT_PINCH_POSE, // /user/hand/right/input/pinch_ext/pose
RIGHT_PINCH_VALUE, // /user/hand/right/input/pinch_ext/value
RIGHT_PINCH_READY, // /user/hand/right/input/pinch_ext/ready_ext
RIGHT_POKE, // /user/hand/right/input/poke_ext/pose
RIGHT_AIM_ACTIVATE_VALUE, // /user/hand/right/input/aim_activate_ext/value
RIGHT_AIM_ACTIVATE_READY, // /user/hand/right/input/aim_activate_ext/ready_ext
RIGHT_GRASP_VALUE, // /user/hand/right/input/grasp_ext/value
RIGHT_GRASP_READY, // /user/hand/right/input/grasp_ext/ready_ext
EYE_GAZE, // /user/eyes_ext/input/gaze_ext/pose
LEFT_HAND, // identify hand tracking
RIGHT_HAND, // identify hand tracking
BODY, // identify body tracking
FACE, // identify face tracking
// Gamepad, microsoft/xbox_controller profile (/user/gamepad)
GAMEPAD_MENU_CLICK, // /user/gamepad/input/menu/click
GAMEPAD_VIEW_CLICK, // /user/gamepad/input/view/click
GAMEPAD_A_CLICK, // /user/gamepad/input/a/click
GAMEPAD_B_CLICK, // /user/gamepad/input/b/click
GAMEPAD_X_CLICK, // /user/gamepad/input/x/click
GAMEPAD_Y_CLICK, // /user/gamepad/input/y/click
GAMEPAD_DPAD_DOWN_CLICK, // /user/gamepad/input/dpad_down/click
GAMEPAD_DPAD_RIGHT_CLICK, // /user/gamepad/input/dpad_right/click
GAMEPAD_DPAD_UP_CLICK, // /user/gamepad/input/dpad_up/click
GAMEPAD_DPAD_LEFT_CLICK, // /user/gamepad/input/dpad_left/click
GAMEPAD_SHOULDER_LEFT_CLICK, // /user/gamepad/input/shoulder_left/click
GAMEPAD_SHOULDER_RIGHT_CLICK, // /user/gamepad/input/shoulder_right/click
GAMEPAD_THUMBSTICK_LEFT_CLICK, // /user/gamepad/input/thumbstick_left/click
GAMEPAD_THUMBSTICK_RIGHT_CLICK, // /user/gamepad/input/thumbstick_right/click
GAMEPAD_TRIGGER_LEFT_VALUE, // /user/gamepad/input/trigger_left/value
GAMEPAD_TRIGGER_RIGHT_VALUE, // /user/gamepad/input/trigger_right/value
GAMEPAD_THUMBSTICK_LEFT_X, // /user/gamepad/input/thumbstick_left/x
GAMEPAD_THUMBSTICK_LEFT_Y, // /user/gamepad/input/thumbstick_left/y
GAMEPAD_THUMBSTICK_RIGHT_X, // /user/gamepad/input/thumbstick_right/x
GAMEPAD_THUMBSTICK_RIGHT_Y, // /user/gamepad/input/thumbstick_right/y
};
enum class interaction_profile : uint8_t
@@ -319,8 +345,8 @@ struct tracking
XrFovf fov;
};
// /user/hand/left and /user/hand/right
std::array<interaction_profile, 2> interaction_profiles;
// /user/hand/left, /user/hand/right and /user/gamepad
std::array<interaction_profile, 3> interaction_profiles;
XrTime production_timestamp;
XrTime timestamp;