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
+12
View File
@@ -180,6 +180,15 @@ configuration::configuration(xr::system & system, xr::session & session)
if (auto val = root["mic_unprocessed_audio"]; val.is_bool())
mic_unprocessed_audio = val.get_bool();
if (auto val = root["forward_keyboard"]; val.is_bool())
forward_keyboard = val.get_bool();
if (auto val = root["forward_mouse"]; val.is_bool())
forward_mouse = val.get_bool();
if (auto val = root["forward_gamepad"]; val.is_bool())
forward_gamepad = val.get_bool();
if (auto val = root["fb_lower_body"]; val.is_bool())
fb_lower_body = val.get_bool();
if (auto val = root["fb_hip"]; val.is_bool())
@@ -296,6 +305,9 @@ void configuration::save()
write_openxr_post_processing(json, openxr_post_processing);
json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled;
json << ",\"mic_unprocessed_audio\":" << std::boolalpha << mic_unprocessed_audio;
json << ",\"forward_keyboard\":" << std::boolalpha << forward_keyboard;
json << ",\"forward_mouse\":" << std::boolalpha << forward_mouse;
json << ",\"forward_gamepad\":" << std::boolalpha << forward_gamepad;
json << ",\"fb_lower_body\":" << std::boolalpha << fb_lower_body;
json << ",\"fb_hip\":" << std::boolalpha << fb_hip;
json << ",\"enable_stream_gui\":" << std::boolalpha << enable_stream_gui;
+5
View File
@@ -68,6 +68,11 @@ public:
bool passthrough_enabled = false;
bool mic_unprocessed_audio = false;
// Input forwarding, per device. Off by default; only effective if the server permits it.
bool forward_keyboard = false;
bool forward_mouse = false;
bool forward_gamepad = false;
bool fb_lower_body = false;
bool fb_hip = true;
+2
View File
@@ -867,6 +867,8 @@ void scenes::lobby::render(const XrFrameState & frame_state)
if (next_scene)
{
server_hid_forwarding = next_scene->hid_forwarding_enabled();
switch (next_scene->current_state())
{
case scenes::stream::state::streaming:
+4
View File
@@ -63,6 +63,10 @@ class lobby : public scene_impl<lobby>
std::string server_name;
bool autoconnect_enabled = true;
// Last known uinput forwarding state of the connected server, kept after disconnection so the
// settings can warn that forwarded keyboard and mouse will not reach the server.
std::optional<bool> server_hid_forwarding;
std::optional<input_profile> input;
entt::entity lobby_entity;
+26
View File
@@ -784,6 +784,32 @@ void scenes::lobby::gui_settings()
ImGui::Unindent();
ImGui::EndDisabled();
}
{
// Virtual devices: a keyboard, mouse or gamepad connected to the headset is
// replicated on the server through uinput. The gamepad is also exposed through
// OpenXR, whether or not it is mirrored to a virtual device.
ImGui::Text("%s", _S("Virtual devices"));
if (ImGui::IsItemHovered())
imgui_ctx->tooltip(_("Input devices connected to the headset are replicated as virtual devices on the PC.\nThe server must allow forwarded input devices; this is not available when the server runs as Flatpak.\nA gamepad is also usable without a virtual device by applications that read it through OpenXR."));
ImGui::Indent();
if (ImGui::Checkbox(_S("Keyboard"), &config.forward_keyboard))
config.save();
imgui_ctx->vibrate_on_hover();
if (ImGui::Checkbox(_S("Mouse"), &config.forward_mouse))
config.save();
imgui_ctx->vibrate_on_hover();
if (ImGui::Checkbox(_S("Gamepad"), &config.forward_gamepad))
config.save();
imgui_ctx->vibrate_on_hover();
ImGui::Unindent();
if (server_hid_forwarding == false and (config.forward_keyboard or config.forward_mouse or config.forward_gamepad))
{
ImGui::TextColored(constants::style::warn, ICON_FA_TRIANGLE_EXCLAMATION);
ImGui::SameLine();
ImGui::Text("%s", _S("The server does not allow forwarded input devices"));
}
}
if (system.hand_tracking_supported())
{
bool enabled = config.check_feature(feature::hand_tracking);
+10 -8
View File
@@ -265,6 +265,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
}
info.settings.bitrate_bps = config.bitrate_bps;
info.settings.mirror_gamepad = config.forward_gamepad;
info.hand_tracking = config.check_feature(feature::hand_tracking);
info.eye_gaze = config.check_feature(feature::eye_gaze);
@@ -1362,9 +1363,10 @@ void scenes::stream::on_xr_event(const xr::event & event)
}
}
bool scenes::stream::forward_hid_input(from_headset::hid::input_t packet)
bool scenes::stream::forward_hid_input(from_headset::hid::input_t packet, bool device_enabled)
{
if (not hid_forwarding)
// hid_forwarding is whether the server permits it; device_enabled is the headset toggle.
if (not hid_forwarding or not device_enabled)
return false;
network_session->send_control(from_headset::hid::input{packet});
return true;
@@ -1372,25 +1374,25 @@ bool scenes::stream::forward_hid_input(from_headset::hid::input_t packet)
bool scenes::stream::on_input_key_down(uint8_t key_code)
{
return forward_hid_input(from_headset::hid::key_down{key_code});
return forward_hid_input(from_headset::hid::key_down{key_code}, application::get_config().forward_keyboard);
}
bool scenes::stream::on_input_key_up(uint8_t key_code)
{
return forward_hid_input(from_headset::hid::key_up{key_code});
return forward_hid_input(from_headset::hid::key_up{key_code}, application::get_config().forward_keyboard);
}
bool scenes::stream::on_input_mouse_move(float x, float y)
{
return forward_hid_input(from_headset::hid::mouse_move{x, y});
return forward_hid_input(from_headset::hid::mouse_move{x, y}, application::get_config().forward_mouse);
}
bool scenes::stream::on_input_button_down(uint8_t button)
{
return forward_hid_input(from_headset::hid::button_down{button});
return forward_hid_input(from_headset::hid::button_down{button}, application::get_config().forward_mouse);
}
bool scenes::stream::on_input_button_up(uint8_t button)
{
return forward_hid_input(from_headset::hid::button_up{button});
return forward_hid_input(from_headset::hid::button_up{button}, application::get_config().forward_mouse);
}
bool scenes::stream::on_input_scroll(float h, float v)
{
return forward_hid_input(from_headset::hid::mouse_scroll{h, v});
return forward_hid_input(from_headset::hid::mouse_scroll{h, v}, application::get_config().forward_mouse);
}
+9 -1
View File
@@ -32,6 +32,7 @@
#include "wivrn_packets.h"
#include "xr/space.h"
#include <mutex>
#include <optional>
#include <queue>
#include <shared_mutex>
#include <thread>
@@ -188,7 +189,7 @@ private:
stream(std::string server_name, scene & parent_scene);
bool forward_hid_input(from_headset::hid::input_t);
bool forward_hid_input(from_headset::hid::input_t, bool device_enabled);
public:
~stream();
@@ -239,6 +240,13 @@ public:
return state_;
}
// Whether the server mirrors forwarded input devices to uinput. The gamepad is also exposed
// through OpenXR regardless, so this only affects forwarded keyboard and mouse.
bool hid_forwarding_enabled() const
{
return hid_forwarding;
}
void exit();
void start_application(std::string appid);
+1
View File
@@ -387,6 +387,7 @@ static void send_settings_changed_packet(xr::session & session, wivrn_session *
.minimum_refresh_rate = config.minimum_refresh_rate.value_or(0),
.fps_divider = config.fps_divider,
.bitrate_bps = config.bitrate_bps,
.mirror_gamepad = config.forward_gamepad,
});
}
+8 -3
View File
@@ -19,10 +19,8 @@
#include "stream.h"
#ifdef __ANDROID__
#include "application.h"
#endif
#include "utils/i18n.h"
#include "utils/named_thread.h"
#include <spdlog/spdlog.h>
@@ -87,6 +85,12 @@ void scenes::stream::operator()(to_headset::feature_control && control)
{
case wivrn::to_headset::feature_control::hid_input:
hid_forwarding = control.state;
if (not control.state and (application::get_config().forward_keyboard or application::get_config().forward_mouse or application::get_config().forward_gamepad))
{
auto toast = gui_toast.lock();
toast->emplace(_("The server does not allow forwarded input devices"), true);
gui_status_last_change = instance.now();
}
return;
case wivrn::to_headset::feature_control::microphone:
if (audio_handle)
@@ -94,6 +98,7 @@ void scenes::stream::operator()(to_headset::feature_control && control)
return;
}
}
void scenes::stream::operator()(to_headset::audio_stream_description && desc)
{
audio_handle.emplace(desc, *network_session, instance);