Files
lhns--steam-frame-nix/modules/vr-keyboard-touch.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

56 lines
2.3 KiB
Nix

# Touch typing on Steam's VR keyboard (steamFrame.keyboard.vr.touchTyping): a
# key is pressed when a controller's tip (where SteamVR's laser starts)
# passes through it. Independent of keyboard.vr.enable / extraKeys.
# - The tips relative to the keyboard come from the controller bridge
# (vr-keyboard-controllers.nix, turned on here).
# - vr-keyboard-touch/keyboard-patch.js (Steam UI, 8080; patch
# "vr-keyboard-touch"): tracker.js per hand (contact, hysteresis); presses
# the key with the keyboard's own touch handlers, like a laser press.
# Tests: vr-keyboard-touch/check.nix (built before the patch; also flake
# check `vr-keyboard-touch`).
{ config, pkgs, lib, ... }:
let
cfg = config.steamFrame.keyboard.vr.touchTyping;
uiLib = import ./steam-ui-patches/lib { inherit pkgs; };
checks = import ./vr-keyboard-touch/check.nix { inherit pkgs; };
ctl = config.steamFrame.keyboard.vr.controllers.files;
in {
imports = [ ./steam-ui-patches.nix ./vr-keyboard-controllers.nix ];
options.steamFrame.keyboard.vr.touchTyping = {
enable = lib.mkEnableOption ''
touch typing on Steam's VR keyboard: a key is pressed when a
controller's tip (where the laser starts) touches it, with both hands;
the lasers work as before'';
depth = lib.mkOption {
type = lib.types.numbers.between (-2) 5;
default = 0;
description = "How far behind the keyboard's surface a touch registers (cm; negative: in front).";
};
haptics = lib.mkOption {
type = lib.types.bool;
default = true;
description = "A haptic tick when a touch presses a key.";
};
};
config = lib.mkIf cfg.enable {
steamFrame.keyboard.vr.controllers.enable = true;
steamFrame.uiPatches.patches = [ {
name = "vr-keyboard-touch";
target.title = "SharedJSContext";
patch = pkgs.runCommand "vr-keyboard-touch.js" { nativeBuildInputs = [ pkgs.nodejs ]; } ''
: ${checks}
cp ${uiLib.mkPatch {
name = "vr-keyboard-touch";
src = ./vr-keyboard-touch/keyboard-patch.js;
opts = { inherit (cfg) haptics; depth = cfg.depth / 100.0; };
extraArgs = [ ./vr-keyboard-touch/tracker.js ctl.hub ];
}} $out
node --check $out
'';
unpatch = ./vr-keyboard-touch/keyboard-unpatch.js;
} ];
};
}