Files
JR Lanteigne 91f6e69ffb 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.
2026-07-08 19:10:50 +02:00

44 lines
1.2 KiB
C++

#include "wivrn_packets.h"
#include "wivrn_sockets.h"
#include <cstdint>
#include <map>
#include <vector>
#include <linux/uinput.h>
class wivrn_uinput
{
public:
// Devices are created lazily on first use, so only forwarded classes are exposed.
wivrn_uinput() = default;
void handle_input(wivrn::from_headset::hid::input &);
// The gamepad device is created on the first packet with gamepad inputs
void handle_gamepad(const wivrn::from_headset::inputs &);
// Remove the virtual gamepad, when the headset stops mirroring or the gamepad disconnects
void destroy_gamepad();
// Drains pending force-feedback requests from the virtual gamepad and returns the
// resulting haptics packets to forward to the headset, if any changed.
std::vector<wivrn::to_headset::haptics> read_rumble();
private:
void init_keyboard();
void init_mouse();
void init_gamepad();
void send_key(uint16_t key, bool down);
void send_button(uint16_t mouse_button, bool down);
void mouse_move_relative(int16_t x, int16_t y);
void mouse_scroll(int16_t vertical, int16_t horizontal);
static constexpr int ff_effects_max = 16;
wivrn::fd_base kbd_fd;
wivrn::fd_base mouse_fd;
wivrn::fd_base gamepad_fd;
std::map<int16_t, ff_effect> ff_effects;
};