diff --git a/flutter/lib/desktop/pages/remote_page.dart b/flutter/lib/desktop/pages/remote_page.dart index e66d84a35..4061fb74d 100644 --- a/flutter/lib/desktop/pages/remote_page.dart +++ b/flutter/lib/desktop/pages/remote_page.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:io'; import 'dart:ui' as ui; +import 'package:desktop_multi_window/desktop_multi_window.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -48,7 +49,7 @@ class RemotePage extends StatefulWidget { } class _RemotePageState extends State - with AutomaticKeepAliveClientMixin { + with AutomaticKeepAliveClientMixin, MultiWindowListener { Timer? _timer; String keyboardMode = "legacy"; final _cursorOverImage = false.obs; @@ -57,7 +58,7 @@ class _RemotePageState extends State late RxBool _remoteCursorMoved; late RxBool _keyboardEnabled; - final FocusNode _rawKeyFocusNode = FocusNode(); + final FocusNode _rawKeyFocusNode = FocusNode(debugLabel: "rawkeyFocusNode"); var _imageFocused = false; Function(bool)? _onEnterOrLeaveImage4Menubar; @@ -111,6 +112,7 @@ class _RemotePageState extends State id: widget.id, arg: 'show-remote-cursor'); _zoomCursor.value = bind.sessionGetToggleOptionSync(id: widget.id, arg: 'zoom-cursor'); + DesktopMultiWindow.addListener(this); // if (!_isCustomCursorInited) { // customCursorController.registerNeedUpdateCursorCallback( // (String? lastKey, String? currentKey) async { @@ -124,9 +126,18 @@ class _RemotePageState extends State // } } + @override + void onWindowBlur() { + super.onWindowBlur(); + // unfocus the key focus when the whole window is lost focus, + // and let OS to handle events instead. + _rawKeyFocusNode.unfocus(); + } + @override void dispose() { debugPrint("REMOTE PAGE dispose ${widget.id}"); + DesktopMultiWindow.removeListener(this); _ffi.dialogManager.hideMobileActionsOverlay(); _ffi.recordingModel.onClose(); _rawKeyFocusNode.dispose(); diff --git a/flutter/lib/desktop/pages/remote_tab_page.dart b/flutter/lib/desktop/pages/remote_tab_page.dart index f7237af96..10c2d4487 100644 --- a/flutter/lib/desktop/pages/remote_tab_page.dart +++ b/flutter/lib/desktop/pages/remote_tab_page.dart @@ -116,16 +116,6 @@ class _ConnectionTabPageState extends State _menubarState.save(); } - @override - void onWindowBlur() { - super.onWindowBlur(); - final state = tabController.state.value; - if (state.tabs.isNotEmpty) { - final sessionId = state.tabs[state.selected].key; - bind.sessionEnterOrLeave(id: sessionId, enter: false); - } - } - @override Widget build(BuildContext context) { final tabWidget = Obx(