From 80951a8e6ef9bdfbd8087486a11f0cc011f2d6ab Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 19 Oct 2023 07:50:59 +0800 Subject: [PATCH 1/3] open individual window, add offset Signed-off-by: dignow --- flutter/lib/common.dart | 26 +++++++++++++------ .../lib/desktop/pages/remote_tab_page.dart | 9 ++++--- flutter/lib/main.dart | 9 +++++-- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 545b8a238..9a22a8f89 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1673,8 +1673,10 @@ Future _adjustRestoreMainWindowOffset( /// Restore window position and size on start /// Note that windowId must be provided if it's subwindow +// +// display is used to set the offset of the window in individual display mode. Future restoreWindowPosition(WindowType type, - {int? windowId, String? peerId}) async { + {int? windowId, String? peerId, int? display}) async { if (bind .mainGetEnv(key: "DISABLE_RUSTDESK_RESTORE_WINDOW_POSITION") .isNotEmpty) { @@ -1710,14 +1712,22 @@ Future restoreWindowPosition(WindowType type, debugPrint("no window position saved, ignoring position restoration"); return false; } - if (type == WindowType.RemoteDesktop && - !isRemotePeerPos && - windowId != null) { - if (lpos.offsetWidth != null) { - lpos.offsetWidth = lpos.offsetWidth! + windowId * 20; + if (type == WindowType.RemoteDesktop) { + if (!isRemotePeerPos && windowId != null) { + if (lpos.offsetWidth != null) { + lpos.offsetWidth = lpos.offsetWidth! + windowId * 20; + } + if (lpos.offsetHeight != null) { + lpos.offsetHeight = lpos.offsetHeight! + windowId * 20; + } } - if (lpos.offsetHeight != null) { - lpos.offsetHeight = lpos.offsetHeight! + windowId * 20; + if (display != null) { + if (lpos.offsetWidth != null) { + lpos.offsetWidth = lpos.offsetWidth! + display * 30; + } + if (lpos.offsetHeight != null) { + lpos.offsetHeight = lpos.offsetHeight! + display * 30; + } } } diff --git a/flutter/lib/desktop/pages/remote_tab_page.dart b/flutter/lib/desktop/pages/remote_tab_page.dart index 6d28d967f..d785a9464 100644 --- a/flutter/lib/desktop/pages/remote_tab_page.dart +++ b/flutter/lib/desktop/pages/remote_tab_page.dart @@ -48,7 +48,8 @@ class _ConnectionTabPageState extends State { late ToolbarState _toolbarState; String? peerId; - bool isScreenRectSet = false; + bool _isScreenRectSet = false; + int? _display; var connectionMap = RxList.empty(growable: true); @@ -61,7 +62,8 @@ class _ConnectionTabPageState extends State { final display = params['display']; final displays = params['displays']; final screenRect = parseParamScreenRect(params); - isScreenRectSet = screenRect != null; + _isScreenRectSet = screenRect != null; + _display = display as int?; tryMoveToScreenAndSetFullscreen(screenRect); if (peerId != null) { ConnectionTypeState.init(peerId!); @@ -202,7 +204,7 @@ class _ConnectionTabPageState extends State { _update_remote_count(); return returnValue; }); - if (!isScreenRectSet) { + if (!_isScreenRectSet) { Future.delayed(Duration.zero, () { restoreWindowPosition( WindowType.RemoteDesktop, @@ -210,6 +212,7 @@ class _ConnectionTabPageState extends State { peerId: tabController.state.value.tabs.isEmpty ? null : tabController.state.value.tabs[0].key, + display: _display, ); }); } diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 59cf97345..83a633061 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -200,8 +200,13 @@ void runMultiWindow( case kAppTypeDesktopRemote: // If screen rect is set, the window will be moved to the target screen and then set fullscreen. if (argument['screen_rect'] == null) { - await restoreWindowPosition(WindowType.RemoteDesktop, - windowId: kWindowId!, peerId: argument['id'] as String?); + // int? display = argument['display'] as int?; + await restoreWindowPosition( + WindowType.RemoteDesktop, + windowId: kWindowId!, + peerId: argument['id'] as String?, + display: argument['display'] as int?, + ); } break; case kAppTypeDesktopFileTransfer: From 2e85d4b55afed3baff2948bb8914ca0c0004baef Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 19 Oct 2023 07:55:55 +0800 Subject: [PATCH 2/3] add comment Signed-off-by: dignow --- flutter/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 83a633061..d7dd5acee 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -200,7 +200,7 @@ void runMultiWindow( case kAppTypeDesktopRemote: // If screen rect is set, the window will be moved to the target screen and then set fullscreen. if (argument['screen_rect'] == null) { - // int? display = argument['display'] as int?; + // display can be used to control the offset of the window. await restoreWindowPosition( WindowType.RemoteDesktop, windowId: kWindowId!, From fb12ba8a2b85fb04d264d85043a4be021293fd9a Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 19 Oct 2023 12:21:35 +0800 Subject: [PATCH 3/3] Change the offset depending on the platform Signed-off-by: dignow --- flutter/lib/common.dart | 8 ++++---- flutter/lib/consts.dart | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 9a22a8f89..c6b613475 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1715,18 +1715,18 @@ Future restoreWindowPosition(WindowType type, if (type == WindowType.RemoteDesktop) { if (!isRemotePeerPos && windowId != null) { if (lpos.offsetWidth != null) { - lpos.offsetWidth = lpos.offsetWidth! + windowId * 20; + lpos.offsetWidth = lpos.offsetWidth! + windowId * kNewWindowOffset; } if (lpos.offsetHeight != null) { - lpos.offsetHeight = lpos.offsetHeight! + windowId * 20; + lpos.offsetHeight = lpos.offsetHeight! + windowId * kNewWindowOffset; } } if (display != null) { if (lpos.offsetWidth != null) { - lpos.offsetWidth = lpos.offsetWidth! + display * 30; + lpos.offsetWidth = lpos.offsetWidth! + display * kNewWindowOffset; } if (lpos.offsetHeight != null) { - lpos.offsetHeight = lpos.offsetHeight! + display * 30; + lpos.offsetHeight = lpos.offsetHeight! + display * kNewWindowOffset; } } } diff --git a/flutter/lib/consts.dart b/flutter/lib/consts.dart index e4d777ccb..e3339c1ec 100644 --- a/flutter/lib/consts.dart +++ b/flutter/lib/consts.dart @@ -66,8 +66,10 @@ const int kWindowMainId = 0; const String kPointerEventKindTouch = "touch"; const String kPointerEventKindMouse = "mouse"; -const String kKeyShowDisplaysAsIndividualWindows = 'displays_as_individual_windows'; -const String kKeyUseAllMyDisplaysForTheRemoteSession = 'use_all_my_displays_for_the_remote_session'; +const String kKeyShowDisplaysAsIndividualWindows = + 'displays_as_individual_windows'; +const String kKeyUseAllMyDisplaysForTheRemoteSession = + 'use_all_my_displays_for_the_remote_session'; const String kKeyShowMonitorsToolbar = 'show_monitors_toolbar'; // the executable name of the portable version @@ -87,6 +89,14 @@ const int kDesktopMaxDisplaySize = 3840; const double kDesktopFileTransferRowHeight = 30.0; const double kDesktopFileTransferHeaderHeight = 25.0; +double kNewWindowOffset = Platform.isWindows + ? 56.0 + : Platform.isLinux + ? 50.0 + : Platform.isMacOS + ? 30.0 + : 50.0; + EdgeInsets get kDragToResizeAreaPadding => !kUseCompatibleUiMode && Platform.isLinux ? stateGlobal.fullscreen.isTrue || stateGlobal.isMaximized.value