From 731aa5e9f3faded01e4634a3a2eb02a9ff002792 Mon Sep 17 00:00:00 2001 From: dignow Date: Wed, 26 Jul 2023 21:29:35 +0800 Subject: [PATCH 1/5] support negative window position Signed-off-by: dignow --- flutter/lib/common.dart | 119 ++++++++++++++++++++++------------------ flutter/lib/consts.dart | 7 +-- 2 files changed, 69 insertions(+), 57 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 9f6fc4886..4a3813ba6 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1350,7 +1350,9 @@ class LastWindowPosition { return LastWindowPosition(m["width"], m["height"], m["offsetWidth"], m["offsetHeight"], m["isMaximized"]); } catch (e) { - debugPrintStack(label: 'Failed to load LastWindowPosition "$content" ${e.toString()}'); + debugPrintStack( + label: + 'Failed to load LastWindowPosition "$content" ${e.toString()}'); return null; } } @@ -1370,10 +1372,6 @@ Future saveWindowPosition(WindowType type, {int? windowId}) async { switch (type) { case WindowType.Main: position = await windowManager.getPosition(); - if (position.dx < 0 || position.dy < 0) { - debugPrint("Main window is hidden, ignoring position restoration"); - return; - } sz = await windowManager.getSize(); isMaximized = await windowManager.isMaximized(); break; @@ -1387,10 +1385,6 @@ Future saveWindowPosition(WindowType type, {int? windowId}) async { return; } position = frame.topLeft; - if (position.dx < 0 || position.dy < 0) { - debugPrint("Window $windowId is hidden, ignoring position restoration"); - return; - } sz = frame.size; isMaximized = await wc.isMaximized(); break; @@ -1408,12 +1402,12 @@ Future _adjustRestoreMainWindowSize(double? width, double? height) async { const double minWidth = 600; const double minHeight = 100; double maxWidth = (((isDesktop || isWebDesktop) - ? kDesktopMaxDisplayWidth - : kMobileMaxDisplayWidth)) + ? kDesktopMaxDisplaySize + : kMobileMaxDisplaySize)) .toDouble(); double maxHeight = ((isDesktop || isWebDesktop) - ? kDesktopMaxDisplayHeight - : kMobileMaxDisplayHeight) + ? kDesktopMaxDisplaySize + : kMobileMaxDisplaySize) .toDouble(); if (isDesktop || isWebDesktop) { @@ -1434,59 +1428,72 @@ Future _adjustRestoreMainWindowSize(double? width, double? height) async { double restoreHeight = height ?? defaultHeight; if (restoreWidth < minWidth) { - restoreWidth = minWidth; + restoreWidth = defaultWidth; } if (restoreHeight < minHeight) { - restoreHeight = minHeight; + restoreHeight = defaultHeight; } if (restoreWidth > maxWidth) { - restoreWidth = maxWidth; + restoreWidth = defaultWidth; } if (restoreHeight > maxHeight) { - restoreHeight = maxHeight; + restoreHeight = defaultHeight; } return Size(restoreWidth, restoreHeight); } /// return null means center Future _adjustRestoreMainWindowOffset( - double? left, double? top) async { - if (left == null || top == null) { - await windowManager.center(); - } else { - double windowLeft = max(0.0, left); - double windowTop = max(0.0, top); + double? left, + double? top, + double? width, + double? height, +) async { + if (left == null || top == null || width == null || height == null) { + return null; + } - double frameLeft = double.infinity; - double frameTop = double.infinity; - double frameRight = ((isDesktop || isWebDesktop) - ? kDesktopMaxDisplayWidth - : kMobileMaxDisplayWidth) - .toDouble(); - double frameBottom = ((isDesktop || isWebDesktop) - ? kDesktopMaxDisplayHeight - : kMobileMaxDisplayHeight) - .toDouble(); + double? frameLeft; + double? frameTop; + double? frameRight; + double? frameBottom; - if (isDesktop || isWebDesktop) { - for (final screen in await window_size.getScreenList()) { - frameLeft = min(screen.visibleFrame.left, frameLeft); - frameTop = min(screen.visibleFrame.top, frameTop); - frameRight = max(screen.visibleFrame.right, frameRight); - frameBottom = max(screen.visibleFrame.bottom, frameBottom); - } - } - - if (windowLeft < frameLeft || - windowLeft > frameRight || - windowTop < frameTop || - windowTop > frameBottom) { - return null; - } else { - return Offset(windowLeft, windowTop); + if (isDesktop || isWebDesktop) { + for (final screen in await window_size.getScreenList()) { + frameLeft = frameLeft == null + ? screen.visibleFrame.left + : min(screen.visibleFrame.left, frameLeft); + frameTop = frameTop == null + ? screen.visibleFrame.top + : min(screen.visibleFrame.top, frameTop); + frameRight = frameRight == null + ? screen.visibleFrame.right + : max(screen.visibleFrame.right, frameRight); + frameBottom = frameBottom == null + ? screen.visibleFrame.bottom + : max(screen.visibleFrame.bottom, frameBottom); } } - return null; + if (frameLeft == null) { + frameLeft = 0.0; + frameTop = 0.0; + frameRight = ((isDesktop || isWebDesktop) + ? kDesktopMaxDisplaySize + : kMobileMaxDisplaySize) + .toDouble(); + frameBottom = ((isDesktop || isWebDesktop) + ? kDesktopMaxDisplaySize + : kMobileMaxDisplaySize) + .toDouble(); + } + if (left > frameRight! || + top > frameBottom! || + (left + width) < frameLeft || + (top + height) < frameTop!) { + return null; + } else { + return Offset(left, top); + } } /// Restore window position and size on start @@ -1516,7 +1523,11 @@ Future restoreWindowPosition(WindowType type, {int? windowId}) async { final size = await _adjustRestoreMainWindowSize(lpos.width, lpos.height); final offset = await _adjustRestoreMainWindowOffset( - lpos.offsetWidth, lpos.offsetHeight); + lpos.offsetWidth, + lpos.offsetHeight, + size.width, + size.height, + ); await windowManager.setSize(size); if (offset == null) { await windowManager.center(); @@ -1533,7 +1544,11 @@ Future restoreWindowPosition(WindowType type, {int? windowId}) async { final size = await _adjustRestoreMainWindowSize(lpos.width, lpos.height); final offset = await _adjustRestoreMainWindowOffset( - lpos.offsetWidth, lpos.offsetHeight); + lpos.offsetWidth, + lpos.offsetHeight, + size.width, + size.height, + ); debugPrint( "restore lpos: ${size.width}/${size.height}, offset:${offset?.dx}/${offset?.dy}"); if (offset == null) { diff --git a/flutter/lib/consts.dart b/flutter/lib/consts.dart index 3e664c484..9dff28c22 100644 --- a/flutter/lib/consts.dart +++ b/flutter/lib/consts.dart @@ -50,11 +50,8 @@ const int kMobileDefaultDisplayHeight = 1280; const int kDesktopDefaultDisplayWidth = 1080; const int kDesktopDefaultDisplayHeight = 720; -const int kMobileMaxDisplayWidth = 720; -const int kMobileMaxDisplayHeight = 1280; - -const int kDesktopMaxDisplayWidth = 1920; -const int kDesktopMaxDisplayHeight = 1080; +const int kMobileMaxDisplaySize = 1280; +const int kDesktopMaxDisplaySize = 3840; const double kDesktopFileTransferNameColWidth = 200; const double kDesktopFileTransferModifiedColWidth = 120; From 5228b3490d0f14dca3d176ee005b75f538ea73d7 Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 27 Jul 2023 08:03:18 +0800 Subject: [PATCH 2/5] window, save and restore pos, maxmium Signed-off-by: dignow --- flutter/lib/desktop/widgets/tabbar_widget.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/flutter/lib/desktop/widgets/tabbar_widget.dart b/flutter/lib/desktop/widgets/tabbar_widget.dart index c3ef95c75..bc7864e45 100644 --- a/flutter/lib/desktop/widgets/tabbar_widget.dart +++ b/flutter/lib/desktop/widgets/tabbar_widget.dart @@ -516,6 +516,7 @@ class WindowActionPanelState extends State void _setMaximize(bool maximize) { stateGlobal.setMaximize(maximize); + _saveFrameDebounce.call(_saveFrame); setState(() {}); } From 343bcbb36363d393bd4a45e0de7d94af7ae96095 Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 27 Jul 2023 09:11:43 +0800 Subject: [PATCH 3/5] adjust window offset on start Signed-off-by: dignow --- flutter/lib/common.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 4a3813ba6..af1f200b2 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1486,10 +1486,11 @@ Future _adjustRestoreMainWindowOffset( : kMobileMaxDisplaySize) .toDouble(); } - if (left > frameRight! || - top > frameBottom! || - (left + width) < frameLeft || - (top + height) < frameTop!) { + final minWidth = 10.0; + if ((left - minWidth) > frameRight! || + (top - minWidth) > frameBottom! || + (left + width + minWidth) < frameLeft || + top < frameTop!) { return null; } else { return Offset(left, top); From 88ce98e71685c6dfa6e6479b80c6cdf457cef764 Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 27 Jul 2023 09:13:39 +0800 Subject: [PATCH 4/5] debug Signed-off-by: dignow --- flutter/lib/common.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index af1f200b2..4e5c21ced 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1487,9 +1487,9 @@ Future _adjustRestoreMainWindowOffset( .toDouble(); } final minWidth = 10.0; - if ((left - minWidth) > frameRight! || - (top - minWidth) > frameBottom! || - (left + width + minWidth) < frameLeft || + if ((left + minWidth) > frameRight! || + (top + minWidth) > frameBottom! || + (left + width - minWidth) < frameLeft || top < frameTop!) { return null; } else { From 6467b144862f2fe202a24c7a133c32609816a99a Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 27 Jul 2023 09:17:07 +0800 Subject: [PATCH 5/5] window, pos save and restore, add min window space to the top Signed-off-by: dignow --- flutter/lib/common.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 4e5c21ced..b069fcee1 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1490,7 +1490,7 @@ Future _adjustRestoreMainWindowOffset( if ((left + minWidth) > frameRight! || (top + minWidth) > frameBottom! || (left + width - minWidth) < frameLeft || - top < frameTop!) { + (top - minWidth) < frameTop!) { return null; } else { return Offset(left, top);