Skip to content

fix: stop reading the gamepad while the window is not focused - #1

Open
cybx wants to merge 1 commit into
mainfrom
fix/gamepad-polling-when-window-unfocused
Open

cybx wants to merge 1 commit into
mainfrom
fix/gamepad-polling-when-window-unfocused

Conversation

@cybx

@cybx cybx commented Aug 8, 2026

Copy link
Copy Markdown
Owner

PR interno no fork, aberto só para o CI gerar o AppImage e permitir teste no Steam Deck antes de propor ao upstream.

Sintoma

Com o Hydra aberto no Gaming Mode, apertar o botão que abre o menu lateral da Steam faz o controle comandar os dois ao mesmo tempo: a seleção anda no menu da Steam e dentro do Hydra, atrás.

Causa

O requestAnimationFrame normalmente pausa quando a janela fica oculta, então o polling pararia sozinho. Isso não acontece aqui porque o overlay da Steam desenha por cima da janela sem ocultá-la — os frames continuam chegando e o app segue consumindo input que já não deveria receber.

Correção

Condiciona o polling ao foco da janela. O loop continua sendo agendado, então o input volta sozinho ao recuperar o foco.

Detalhes de implementação:

  • A flag é separada do inputEnabled, que pertence ao navigation-input.provider. Reutilizá-lo deixaria um evento de focus religar input que o provider tinha desligado de propósito.
  • No blur, limpa timers e entradas aceitas — a mesma limpeza que setInputEnabled(false) já fazia. Sem isso, um botão segurado no momento em que a janela perde o foco manteria o timer de repetição vivo em segundo plano.
  • O estado inicial vem de document.hasFocus(), porque a janela pode nascer em segundo plano.

Como testar

  1. Instalar no Steam Deck e adicionar o Hydra como atalho não-Steam
  2. Abrir pelo Gaming Mode
  3. Apertar o botão do menu lateral da Steam e navegar
  4. A seleção dentro do Hydra deve ficar parada

Verificações

  • tsc --noEmit -p tsconfig.web.json — sem erros
  • prettier --check — ok
  • eslint — sem avisos

On the Steam Deck, opening the Steam menu over Hydra made the controller
drive both at once: the selection moved in the Steam menu and in Hydra
underneath.

requestAnimationFrame throttles when a window is hidden, so polling would
normally pause on its own. That does not happen here because the Steam
overlay draws on top of the window without hiding it, so frames keep being
delivered and the app keeps consuming input it can no longer act on.

Gate the polling on window focus instead. The frame loop keeps being
scheduled so input resumes by itself, and losing focus clears pending timers
and accepted inputs the same way setInputEnabled(false) already does --
otherwise a button held at that moment would keep its repeat timer alive in
the background.

The flag is separate from inputEnabled on purpose: that one is owned by
navigation-input.provider, and reusing it would let a focus event re-enable
input the provider had deliberately turned off.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant