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
+43 -7
View File
@@ -39,6 +39,7 @@
#include <boost/locale.hpp>
#include <boost/url/parse.hpp>
#include <chrono>
#include <cstring>
#include <ctype.h>
#include <exception>
#include <magic_enum.hpp>
@@ -602,6 +603,35 @@ static std::vector<interaction_profile> interaction_profiles{
"/user/eyes_ext/input/gaze_ext/pose",
},
},
interaction_profile{
.profile_name = "/interaction_profiles/microsoft/xbox_controller",
.input_sources = {
"/user/gamepad/input/menu/click",
"/user/gamepad/input/view/click",
"/user/gamepad/input/a/click",
"/user/gamepad/input/b/click",
"/user/gamepad/input/x/click",
"/user/gamepad/input/y/click",
"/user/gamepad/input/dpad_up/click",
"/user/gamepad/input/dpad_down/click",
"/user/gamepad/input/dpad_left/click",
"/user/gamepad/input/dpad_right/click",
"/user/gamepad/input/shoulder_left/click",
"/user/gamepad/input/shoulder_right/click",
"/user/gamepad/input/thumbstick_left/click",
"/user/gamepad/input/thumbstick_right/click",
"/user/gamepad/input/trigger_left/value",
"/user/gamepad/input/trigger_right/value",
"/user/gamepad/input/thumbstick_left/x",
"/user/gamepad/input/thumbstick_left/y",
"/user/gamepad/input/thumbstick_right/x",
"/user/gamepad/input/thumbstick_right/y",
"/user/gamepad/output/haptic_left",
"/user/gamepad/output/haptic_right",
"/user/gamepad/output/haptic_left_trigger",
"/user/gamepad/output/haptic_right_trigger",
},
},
};
static const std::pair<std::string_view, XrActionType> action_suffixes[] =
@@ -634,11 +664,15 @@ static const std::pair<std::string_view, XrActionType> action_suffixes[] =
{"/ready_ext", XR_ACTION_TYPE_BOOLEAN_INPUT},
// Output paths
{"/haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_trigger", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_trigger_fb",XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_thumb", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_thumb_fb", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_trigger", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_trigger_fb", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_thumb", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_thumb_fb", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_left", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_right", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_left_trigger", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_right_trigger",XR_ACTION_TYPE_VIBRATION_OUTPUT},
// clang-format on
};
@@ -1717,8 +1751,10 @@ void application::run()
while (ALooper_pollOnce(100, nullptr, &events, (void **)&source) >= 0)
{
// Process this event.
if (source != nullptr)
source->process(app_info.native_app, source);
if (source == nullptr)
continue;
source->process(app_info.native_app, source);
}
if (app_info.native_app->destroyRequested)