Files
lhns--steam-frame-nix/modules/vr-keyboard-controllers.nix
T
Pierre Kisters 224715d926 VR keyboard touch typing, on a controller bridge from the SteamVR dashboard
keyboard.vr.touchTyping (off by default): a key is pressed when a
controller's tip, where SteamVR's laser starts (/pose/tip: the device pose
times the render model's "tip" component), passes through it from the
front; released when pulled back 1 cm, re-armed 5 mm in front. Both hands,
also at once. Keys go through the keyboard's own HandleTouchStart /
HandleTouchEnd, like a laser press (Backspace repeats while held). Options
depth (cm) and haptics.

The geometry lives in a reusable controller bridge (vr-keyboard-controllers,
internal option): a systemui patch reads the keyboard's pose with SteamVR's
SGQueryService (an empty transform of ours in the keyboard's mount) and both
controllers' poses, and streams per hand the tip, the laser's hit on the
keyboard and the trigger (~90 Hz while relevant) through the
vr-keyboard-controllers-relay service to __sfuiControllers in Steam's
SharedJSContext. Tests: flake checks vr-keyboard-controllers and
vr-keyboard-touch.
2026-10-01 03:30:01 +02:00

67 lines
2.9 KiB
Nix

# The controller bridge for VR keyboard features (internal option
# steamFrame.keyboard.vr.controllers.enable, set by the features using it,
# e.g. keyboard.vr.touchTyping): both controllers relative to Steam's VR
# keyboard, from SteamVR's dashboard to Steam's UI.
# - vr-keyboard-controllers/bridge-patch.js (SteamVR systemui, 8087; patch
# "vr-keyboard-controllers"): the keyboard's pose, per hand the tip (where
# the laser starts), the laser's hit and the trigger (geometry.js), ~90 Hz
# while relevant; CDP binding __sfuiCtlOut.
# - vr-keyboard-controllers/relay.mjs (user service
# vr-keyboard-controllers-relay): to Steam's SharedJSContext.
# - vr-keyboard-controllers/hub.js: window.__sfuiControllers there (page px,
# subscribe); consumer patches take it as an extraArg.
# Tests: vr-keyboard-controllers/check.nix (flake check
# `vr-keyboard-controllers`).
{ config, pkgs, lib, ... }:
let
cfg = config.steamFrame.keyboard.vr.controllers;
uiLib = import ./steam-ui-patches/lib { inherit pkgs; };
checks = import ./vr-keyboard-controllers/check.nix { inherit pkgs; };
in {
imports = [ ./session.nix ./steam-ui-patches.nix ];
options.steamFrame.keyboard.vr.controllers = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
internal = true;
description = "The controller bridge (set by the VR keyboard features that use it).";
};
files = lib.mkOption {
type = lib.types.attrsOf lib.types.path;
readOnly = true;
internal = true;
default = { geometry = ./vr-keyboard-controllers/geometry.js; hub = ./vr-keyboard-controllers/hub.js; };
description = "geometry.js and hub.js, for consumer patches' extraArgs.";
};
};
config = lib.mkMerge [
{
steamFrame.uiPatches.patches = lib.optional cfg.enable {
name = "vr-keyboard-controllers";
endpoint = "http://127.0.0.1:8087";
target.title = "systemui";
patch = pkgs.runCommand "vr-keyboard-controllers.js" { nativeBuildInputs = [ pkgs.nodejs ]; } ''
: ${checks}
cp ${uiLib.mkPatch {
name = "vr-keyboard-controllers";
src = ./vr-keyboard-controllers/bridge-patch.js;
extraArgs = [ ./vr-keyboard-controllers/geometry.js ];
}} $out
node --check $out
'';
unpatch = ./vr-keyboard-controllers/unpatch.js;
};
steamFrame.session.services.${if cfg.enable then "restart" else "stop"} = [ "vr-keyboard-controllers-relay.service" ];
}
(lib.mkIf cfg.enable {
systemd.user.services.vr-keyboard-controllers-relay = {
Unit.Description = "Relay of the VR keyboard's controller frames (SteamVR dashboard -> Steam UI)";
Service = { ExecStart = "${pkgs.nodejs}/bin/node ${./vr-keyboard-controllers/relay.mjs}"; Restart = "always"; RestartSec = 5; };
Install.WantedBy = [ "default.target" ];
};
})
];
}