Files
lhns--steam-frame-nix/modules/vr-keyboard-extra-keys/allowlist.mjs
T
Pierre Kisters 514f073a6e VR keyboard extra keys: the helper holds only Ctrl/Alt, checked in allowlist.mjs
down:/up: were checked with MODKEY[arg], which inherited names like
constructor or toString pass (xdotool then got a junk key name). The check
is now allowedMod() in allowlist.mjs, covered by its test.
2026-10-01 04:09:13 +02:00

32 lines
1.6 KiB
JavaScript

// Allowlist of xdotool-helper.mjs: requests come from Steam's UI JS, so the
// helper must not be able to type ASCII text or press Enter on its behalf.
// Accepted:
// key:<combo> the extra keys (Esc, Del, Home, End, PgUp/PgDn, arrows,
// F1-F12 from keyboard.vr.functionKeys), optionally with
// modifiers; ctrl and/or alt (+ optional
// shift) with one key; or shift+Tab
// type:<char> one character Steam's key emulation can't produce: non-ASCII
// (äöü߀§°´…) or | @ { [ ] } \ ~ ^ `
// down:<mod> / up:<mod> hold/release ctrl or alt
const SPECIAL = new Set(['Escape', 'Delete', 'Home', 'End', 'Prior', 'Next', 'Left', 'Right', 'Up', 'Down',
...Array.from({ length: 12 }, (_, i) => `F${i + 1}`)]);
const KEY = /^([a-z0-9]|space|BackSpace|Tab|period|comma|minus|plus|numbersign|less|slash|ssharp|udiaeresis|odiaeresis|adiaeresis)$/;
export function allowedCombo(combo) {
const parts = combo.split('+');
const key = parts.pop();
const mods = new Set(parts);
if (parts.length !== mods.size || ![...mods].every((m) => ['ctrl', 'alt', 'shift'].includes(m))) return false;
if (SPECIAL.has(key)) return true;
if (key === 'Tab' && mods.size === 1 && mods.has('shift')) return true; // backwards focus
return KEY.test(key) && (mods.has('ctrl') || mods.has('alt'));
}
export function allowedChar(c) {
if ([...c].length !== 1) return false;
const cp = c.codePointAt(0);
return (cp > 0xa0 && !/\s|\p{C}/u.test(c)) || '|@{[]}\\~^`'.includes(c);
}
export const allowedMod = (m) => m === 'ctrl' || m === 'alt';