Mirror forwarded input devices to uinput

Mirror the gamepad forwarded from the headset to a uinput device with the standard Xbox layout, so applications that do not read it through OpenXR, such as SDL and Steam Input, pick it up. This extends the existing hid-forwarding uinput path, which already covered keyboard and mouse.

The headset chooses which devices to forward (keyboard, mouse, gamepad), off by default. The hid-forwarding server option gates the uinput mirror only; the OpenXR gamepad is always exposed. The mirror needs the uinput module and write access to /dev/uinput.

Gamepad rumble written to the uinput device is read back and forwarded to the headset as OpenXR haptics.
This commit is contained in:
JR Lanteigne
2026-07-08 19:10:50 +02:00
committed by xytovl
parent aeecc857de
commit 91f6e69ffb
18 changed files with 385 additions and 54 deletions
+27 -21
View File
@@ -20,6 +20,9 @@
#include "wivrn_packets.h"
#include <cstdint>
#include <linux/input-event-codes.h>
namespace wivrn
{
enum gp_input
@@ -58,6 +61,7 @@ struct gamepad_input
{
gp_input slot;
gp_value kind;
uint16_t ev_code; // BTN_* or ABS_*, unused for dpad
};
inline gamepad_input map_gamepad(device_id id)
@@ -65,47 +69,49 @@ inline gamepad_input map_gamepad(device_id id)
switch (id)
{
case device_id::GAMEPAD_MENU_CLICK:
return {gp_menu, gp_value::button};
return {gp_menu, gp_value::button, BTN_START};
case device_id::GAMEPAD_VIEW_CLICK:
return {gp_view, gp_value::button};
return {gp_view, gp_value::button, BTN_SELECT};
case device_id::GAMEPAD_A_CLICK:
return {gp_a, gp_value::button};
return {gp_a, gp_value::button, BTN_SOUTH};
case device_id::GAMEPAD_B_CLICK:
return {gp_b, gp_value::button};
return {gp_b, gp_value::button, BTN_EAST};
// BTN_X/BTN_Y aliases don't match compass positions (BTN_X == BTN_NORTH,
// BTN_Y == BTN_WEST); xpad and SDL expect the aliases, not the positions
case device_id::GAMEPAD_X_CLICK:
return {gp_x, gp_value::button};
return {gp_x, gp_value::button, BTN_X};
case device_id::GAMEPAD_Y_CLICK:
return {gp_y, gp_value::button};
return {gp_y, gp_value::button, BTN_Y};
case device_id::GAMEPAD_SHOULDER_LEFT_CLICK:
return {gp_shoulder_left, gp_value::button};
return {gp_shoulder_left, gp_value::button, BTN_TL};
case device_id::GAMEPAD_SHOULDER_RIGHT_CLICK:
return {gp_shoulder_right, gp_value::button};
return {gp_shoulder_right, gp_value::button, BTN_TR};
case device_id::GAMEPAD_THUMBSTICK_LEFT_CLICK:
return {gp_thumbstick_left_click, gp_value::button};
return {gp_thumbstick_left_click, gp_value::button, BTN_THUMBL};
case device_id::GAMEPAD_THUMBSTICK_RIGHT_CLICK:
return {gp_thumbstick_right_click, gp_value::button};
return {gp_thumbstick_right_click, gp_value::button, BTN_THUMBR};
case device_id::GAMEPAD_DPAD_DOWN_CLICK:
return {gp_dpad_down, gp_value::dpad};
return {gp_dpad_down, gp_value::dpad, 0};
case device_id::GAMEPAD_DPAD_RIGHT_CLICK:
return {gp_dpad_right, gp_value::dpad};
return {gp_dpad_right, gp_value::dpad, 0};
case device_id::GAMEPAD_DPAD_UP_CLICK:
return {gp_dpad_up, gp_value::dpad};
return {gp_dpad_up, gp_value::dpad, 0};
case device_id::GAMEPAD_DPAD_LEFT_CLICK:
return {gp_dpad_left, gp_value::dpad};
return {gp_dpad_left, gp_value::dpad, 0};
case device_id::GAMEPAD_TRIGGER_LEFT_VALUE:
return {gp_trigger_left, gp_value::trigger};
return {gp_trigger_left, gp_value::trigger, ABS_Z};
case device_id::GAMEPAD_TRIGGER_RIGHT_VALUE:
return {gp_trigger_right, gp_value::trigger};
return {gp_trigger_right, gp_value::trigger, ABS_RZ};
case device_id::GAMEPAD_THUMBSTICK_LEFT_X:
return {gp_thumbstick_left, gp_value::stick_x};
return {gp_thumbstick_left, gp_value::stick_x, ABS_X};
case device_id::GAMEPAD_THUMBSTICK_LEFT_Y:
return {gp_thumbstick_left, gp_value::stick_y};
return {gp_thumbstick_left, gp_value::stick_y, ABS_Y};
case device_id::GAMEPAD_THUMBSTICK_RIGHT_X:
return {gp_thumbstick_right, gp_value::stick_x};
return {gp_thumbstick_right, gp_value::stick_x, ABS_RX};
case device_id::GAMEPAD_THUMBSTICK_RIGHT_Y:
return {gp_thumbstick_right, gp_value::stick_y};
return {gp_thumbstick_right, gp_value::stick_y, ABS_RY};
default:
return {gp_count, gp_value::button};
return {gp_count, gp_value::button, 0};
}
}