diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index ee7806a14..ff88c5647 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1408,8 +1408,24 @@ Future saveWindowPosition(WindowType type, {int? windowId}) async { sz.width, sz.height, position.dx, position.dy, isMaximized); debugPrint( "Saving frame: $windowId: ${pos.width}/${pos.height}, offset:${pos.offsetWidth}/${pos.offsetHeight}"); + await bind.setLocalFlutterConfig( k: kWindowPrefix + type.name, v: pos.toString()); + + if (type == WindowType.RemoteDesktop && windowId != null) { + await _saveSessionWindowPosition(windowId, pos); + } +} + +Future _saveSessionWindowPosition(int windowId, LastWindowPosition pos) async { + final remoteList = await DesktopMultiWindow.invokeMethod( + windowId, kWindowEventGetRemoteList, null); + if (remoteList != null) { + for (final peerId in remoteList.split(',')) { + bind.sessionSetFlutterConfigByPeerId( + id: peerId, k: kWindowPrefix, v: pos.toString()); + } + } } Future _adjustRestoreMainWindowSize(double? width, double? height) async { @@ -1499,7 +1515,7 @@ Future _adjustRestoreMainWindowOffset( /// Restore window position and size on start /// Note that windowId must be provided if it's subwindow -Future restoreWindowPosition(WindowType type, {int? windowId}) async { +Future restoreWindowPosition(WindowType type, {int? windowId, String? peerId}) async { if (bind .mainGetEnv(key: "DISABLE_RUSTDESK_RESTORE_WINDOW_POSITION") .isNotEmpty) { @@ -1508,8 +1524,16 @@ Future restoreWindowPosition(WindowType type, {int? windowId}) async { if (type != WindowType.Main && windowId == null) { debugPrint( "Error: windowId cannot be null when saving positions for sub window"); + return false; } - final pos = bind.getLocalFlutterConfig(k: kWindowPrefix + type.name); + + String? pos; + if (type == WindowType.RemoteDesktop && windowId != null && peerId != null) { + pos = await bind.sessionGetFlutterConfigByPeerId(id: peerId, k: kWindowPrefix); + } + pos ??= bind.getLocalFlutterConfig(k: kWindowPrefix + type.name); + + var lpos = LastWindowPosition.loadFromString(pos); if (lpos == null) { debugPrint("no window position saved, ignoring position restoration"); diff --git a/flutter/lib/consts.dart b/flutter/lib/consts.dart index e44da0854..f945a6292 100644 --- a/flutter/lib/consts.dart +++ b/flutter/lib/consts.dart @@ -36,6 +36,7 @@ const String kWindowEventNewRemoteDesktop = "new_remote_desktop"; const String kWindowEventNewFileTransfer = "new_file_transfer"; const String kWindowEventNewPortForward = "new_port_forward"; const String kWindowEventActiveSession = "active_session"; +const String kWindowEventGetRemoteList = "get_remote_list"; const String kOptionSeparateRemoteWindow = "enable-separate-remote-window"; diff --git a/flutter/lib/desktop/pages/remote_tab_page.dart b/flutter/lib/desktop/pages/remote_tab_page.dart index 296b7ec08..4ab731649 100644 --- a/flutter/lib/desktop/pages/remote_tab_page.dart +++ b/flutter/lib/desktop/pages/remote_tab_page.dart @@ -131,11 +131,22 @@ class _ConnectionTabPageState extends State { windowOnTop(windowId()); } return jumpOk; + } else if (call.method == kWindowEventGetRemoteList) { + return tabController.state.value.tabs + .map((e) => e.key) + .toList() + .join(','); } _update_remote_count(); }); Future.delayed(Duration.zero, () { - restoreWindowPosition(WindowType.RemoteDesktop, windowId: windowId()); + restoreWindowPosition( + WindowType.RemoteDesktop, + windowId: windowId(), + peerId: tabController.state.value.tabs.isEmpty + ? null + : tabController.state.value.tabs[0].key, + ); }); } diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 8fcbd4ad0..14db061bd 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -197,7 +197,7 @@ void runMultiWindow( switch (appType) { case kAppTypeDesktopRemote: await restoreWindowPosition(WindowType.RemoteDesktop, - windowId: kWindowId!); + windowId: kWindowId!, peerId: argument['id'] as String?); break; case kAppTypeDesktopFileTransfer: await restoreWindowPosition(WindowType.FileTransfer, diff --git a/flutter/lib/utils/multi_window_manager.dart b/flutter/lib/utils/multi_window_manager.dart index 8b18eb750..3fcb17c2b 100644 --- a/flutter/lib/utils/multi_window_manager.dart +++ b/flutter/lib/utils/multi_window_manager.dart @@ -70,7 +70,7 @@ class RustDeskMultiWindowManager { newSessionWindow() async { final windowController = await DesktopMultiWindow.createWindow(msg); windowController - ..setFrame(const Offset(0, 0) & const Size(1280, 720)) + ..setFrame(const Offset(0, 0) & Size(1280 + windowController.windowId * 20, 720 + windowController.windowId * 20)) ..center() ..setTitle(getWindowNameWithId( remoteId, diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 710a3f3db..5df00c344 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -205,6 +205,25 @@ pub fn session_set_flutter_config(session_id: SessionID, k: String, v: String) { } } +pub fn session_get_flutter_config_by_peer_id(id: String, k: String) -> Option { + if let Some((_, session)) = SESSIONS.read().unwrap().iter().find(|(_, s)| s.id == id) { + Some(session.get_flutter_config(k)) + } else { + None + } +} + +pub fn session_set_flutter_config_by_peer_id(id: String, k: String, v: String) { + if let Some((_, session)) = SESSIONS + .write() + .unwrap() + .iter_mut() + .find(|(_, s)| s.id == id) + { + session.save_flutter_config(k, v); + } +} + pub fn get_next_texture_key() -> SyncReturn { let k = TEXTURE_RENDER_KEY.fetch_add(1, Ordering::SeqCst) + 1; SyncReturn(k)