-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open source virtual keyboard support on Steam Deck.
GitOrigin-RevId: 1f31ec2249f8ba0bad5e25e2c6ab28e4ea1aeb98
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
}); | ||
} |