mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 10:01:00 +01:00
fix(v2): ignore phantom/non-standard gamepads in nav polling
The v2 gamepad polling loop reads buttons and axes by hardcoded W3C standard-mapping indices, but only guarded against null pads. Firefox (and Zen) expose phantom or non-standard-mapping gamepads even with no real controller attached, whose analog controls drift across the press threshold. Index 4/5 (LB/RB) are bound to AppNav section cycling, so each oscillation re-fired cycleSection and looped the app through home/platforms/collections/search with no user input, making the UI unusable. Add an isUsablePad() guard requiring pad.connected and a "standard" mapping, applied in both the polling loop and detectPadPresence. Every button/axis read assumes the standard mapping, so a non-standard pad cannot be interpreted safely regardless. Fixes #3851 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -104,6 +104,16 @@ const BUTTON_MAP: Record<number, Binding | undefined> = {
|
||||
15: { key: "ArrowRight", code: "ArrowRight" },
|
||||
};
|
||||
|
||||
// Guards the polling loop against phantom / non-standard pads. All button
|
||||
// and axis reads use W3C standard-mapping indices, so a pad that is
|
||||
// disconnected or reports a non-standard mapping cannot be interpreted
|
||||
// safely. Firefox surfaces such devices and their analog drift would
|
||||
// otherwise trigger index-based actions (e.g. LB/RB section cycling) on
|
||||
// their own. See issue #3851.
|
||||
function isUsablePad(pad: Gamepad | null): pad is Gamepad {
|
||||
return pad !== null && pad.connected && pad.mapping === "standard";
|
||||
}
|
||||
|
||||
function dispatchKey(binding: Binding) {
|
||||
const target =
|
||||
(document.activeElement as HTMLElement | null) ?? document.body;
|
||||
@@ -229,7 +239,7 @@ export function useGamepad() {
|
||||
// or first button press takes over.
|
||||
function detectPadPresence() {
|
||||
const list = navigator.getGamepads?.() ?? [];
|
||||
const hasPad = Array.from(list).some((p) => p !== null);
|
||||
const hasPad = Array.from(list).some((p) => isUsablePad(p));
|
||||
if (hasPad && !everSawPad) {
|
||||
everSawPad = true;
|
||||
setModality("pad");
|
||||
@@ -257,7 +267,12 @@ export function useGamepad() {
|
||||
const actionsDisabled = ACTIONS_DISABLED_PATHS.has(route.path);
|
||||
|
||||
for (const pad of pads) {
|
||||
if (!pad) continue;
|
||||
// Only act on connected, standard-mapping pads: every button/axis
|
||||
// read below is by W3C standard index, so a phantom or non-standard
|
||||
// pad (Firefox keeps disconnected entries around and reports
|
||||
// uncalibrated analog controls) would map drifting values onto LB/RB
|
||||
// and cycle AppNav sections with no user input. See issue #3851.
|
||||
if (!isUsablePad(pad)) continue;
|
||||
const key = `${pad.index}:${pad.id}`;
|
||||
const st = (states[key] ||= {
|
||||
buttons: {},
|
||||
|
||||
Reference in New Issue
Block a user