Skip to content

Commit

Permalink
Open source virtual keyboard support on Steam Deck.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 1f31ec2249f8ba0bad5e25e2c6ab28e4ea1aeb98
  • Loading branch information
cpojer committed Jun 16, 2024
1 parent d62b200 commit 27e5ab8
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions ui/controls/setupSteamDeck.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { App } from '../App.tsx';
import { FloatingGamepadTextInputMode } from './GamepadTextInput.tsx';

const inputTypes = new Set([
'text',
'password',
'search',
'email',
'number',
'tel',
'url',
]);
let currentElement: HTMLInputElement | null = null;
let setupHasRun = false;

export default function setupSteamDeck() {
if (setupHasRun || !App.isSteamDeck()) {
return;
}

setupHasRun = true;

document.addEventListener('focusin', (event) => {
const input = event.target as HTMLInputElement | null;
if (input?.tagName === 'INPUT' && input !== currentElement) {
if (!inputTypes.has(input.type)) {
return;
}

currentElement = input;
setTimeout(() => (currentElement = null), 1000);

const dimensions = input.getBoundingClientRect();
App.showFloatingGamepadTextInput(
FloatingGamepadTextInputMode.SingleLine,
Math.max(0, dimensions.x - window.scrollX || 0),
Math.max(0, dimensions.y - window.scrollY || 0),
dimensions.width || 200,
dimensions.height || 40,
);
}
});
}

0 comments on commit 27e5ab8

Please sign in to comment.