This commit is contained in:
Nelson Vicente Ordóñez Cabrera 2026-04-18 11:00:05 +08:00 committed by GitHub
commit 659b26a558
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -154,9 +154,29 @@ class _RemotePageState extends State<RemotePage> with WidgetsBindingObserver {
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
trySyncClipboard();
_restoreInputOnResume();
}
}
// Fix: restore keyboard/mouse input after returning from background on iPadOS.
// Bug: switching apps on iPadOS loses all input (keyboard, trackpad, touch).
// Root cause: iOS drops the focus node when app goes to background; nobody re-requests it.
// Fix: on resume, restart mouse listener and re-request physical focus with a small
// delay (same pattern already used in onSoftKeyboardChanged for iOS keyboard workaround).
void _restoreInputOnResume() {
if (!isIOS) return;
gFFI.inputModel.listenToMouse(true);
_iosKeyboardWorkaroundTimer?.cancel();
_iosKeyboardWorkaroundTimer = Timer(Duration(milliseconds: 100), () {
if (!mounted) return;
_physicalFocusNode.unfocus();
_iosKeyboardWorkaroundTimer = Timer(Duration(milliseconds: 50), () {
if (!mounted) return;
_physicalFocusNode.requestFocus();
});
});
}
// For client side
// When swithing from other app to this app, try to sync clipboard.
void trySyncClipboard() {