Merge pull request #5151 from dignow/fix/window_save_restore_position
Fix/window save restore position
This commit is contained in:
commit
8f851bc781
@ -1350,7 +1350,9 @@ class LastWindowPosition {
|
|||||||
return LastWindowPosition(m["width"], m["height"], m["offsetWidth"],
|
return LastWindowPosition(m["width"], m["height"], m["offsetWidth"],
|
||||||
m["offsetHeight"], m["isMaximized"]);
|
m["offsetHeight"], m["isMaximized"]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrintStack(label: 'Failed to load LastWindowPosition "$content" ${e.toString()}');
|
debugPrintStack(
|
||||||
|
label:
|
||||||
|
'Failed to load LastWindowPosition "$content" ${e.toString()}');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1370,10 +1372,6 @@ Future<void> saveWindowPosition(WindowType type, {int? windowId}) async {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case WindowType.Main:
|
case WindowType.Main:
|
||||||
position = await windowManager.getPosition();
|
position = await windowManager.getPosition();
|
||||||
if (position.dx < 0 || position.dy < 0) {
|
|
||||||
debugPrint("Main window is hidden, ignoring position restoration");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sz = await windowManager.getSize();
|
sz = await windowManager.getSize();
|
||||||
isMaximized = await windowManager.isMaximized();
|
isMaximized = await windowManager.isMaximized();
|
||||||
break;
|
break;
|
||||||
@ -1387,10 +1385,6 @@ Future<void> saveWindowPosition(WindowType type, {int? windowId}) async {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
position = frame.topLeft;
|
position = frame.topLeft;
|
||||||
if (position.dx < 0 || position.dy < 0) {
|
|
||||||
debugPrint("Window $windowId is hidden, ignoring position restoration");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sz = frame.size;
|
sz = frame.size;
|
||||||
isMaximized = await wc.isMaximized();
|
isMaximized = await wc.isMaximized();
|
||||||
break;
|
break;
|
||||||
@ -1408,12 +1402,12 @@ Future<Size> _adjustRestoreMainWindowSize(double? width, double? height) async {
|
|||||||
const double minWidth = 600;
|
const double minWidth = 600;
|
||||||
const double minHeight = 100;
|
const double minHeight = 100;
|
||||||
double maxWidth = (((isDesktop || isWebDesktop)
|
double maxWidth = (((isDesktop || isWebDesktop)
|
||||||
? kDesktopMaxDisplayWidth
|
? kDesktopMaxDisplaySize
|
||||||
: kMobileMaxDisplayWidth))
|
: kMobileMaxDisplaySize))
|
||||||
.toDouble();
|
.toDouble();
|
||||||
double maxHeight = ((isDesktop || isWebDesktop)
|
double maxHeight = ((isDesktop || isWebDesktop)
|
||||||
? kDesktopMaxDisplayHeight
|
? kDesktopMaxDisplaySize
|
||||||
: kMobileMaxDisplayHeight)
|
: kMobileMaxDisplaySize)
|
||||||
.toDouble();
|
.toDouble();
|
||||||
|
|
||||||
if (isDesktop || isWebDesktop) {
|
if (isDesktop || isWebDesktop) {
|
||||||
@ -1434,59 +1428,73 @@ Future<Size> _adjustRestoreMainWindowSize(double? width, double? height) async {
|
|||||||
double restoreHeight = height ?? defaultHeight;
|
double restoreHeight = height ?? defaultHeight;
|
||||||
|
|
||||||
if (restoreWidth < minWidth) {
|
if (restoreWidth < minWidth) {
|
||||||
restoreWidth = minWidth;
|
restoreWidth = defaultWidth;
|
||||||
}
|
}
|
||||||
if (restoreHeight < minHeight) {
|
if (restoreHeight < minHeight) {
|
||||||
restoreHeight = minHeight;
|
restoreHeight = defaultHeight;
|
||||||
}
|
}
|
||||||
if (restoreWidth > maxWidth) {
|
if (restoreWidth > maxWidth) {
|
||||||
restoreWidth = maxWidth;
|
restoreWidth = defaultWidth;
|
||||||
}
|
}
|
||||||
if (restoreHeight > maxHeight) {
|
if (restoreHeight > maxHeight) {
|
||||||
restoreHeight = maxHeight;
|
restoreHeight = defaultHeight;
|
||||||
}
|
}
|
||||||
return Size(restoreWidth, restoreHeight);
|
return Size(restoreWidth, restoreHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return null means center
|
/// return null means center
|
||||||
Future<Offset?> _adjustRestoreMainWindowOffset(
|
Future<Offset?> _adjustRestoreMainWindowOffset(
|
||||||
double? left, double? top) async {
|
double? left,
|
||||||
if (left == null || top == null) {
|
double? top,
|
||||||
await windowManager.center();
|
double? width,
|
||||||
} else {
|
double? height,
|
||||||
double windowLeft = max(0.0, left);
|
) async {
|
||||||
double windowTop = max(0.0, top);
|
if (left == null || top == null || width == null || height == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
double frameLeft = double.infinity;
|
double? frameLeft;
|
||||||
double frameTop = double.infinity;
|
double? frameTop;
|
||||||
double frameRight = ((isDesktop || isWebDesktop)
|
double? frameRight;
|
||||||
? kDesktopMaxDisplayWidth
|
double? frameBottom;
|
||||||
: kMobileMaxDisplayWidth)
|
|
||||||
.toDouble();
|
|
||||||
double frameBottom = ((isDesktop || isWebDesktop)
|
|
||||||
? kDesktopMaxDisplayHeight
|
|
||||||
: kMobileMaxDisplayHeight)
|
|
||||||
.toDouble();
|
|
||||||
|
|
||||||
if (isDesktop || isWebDesktop) {
|
if (isDesktop || isWebDesktop) {
|
||||||
for (final screen in await window_size.getScreenList()) {
|
for (final screen in await window_size.getScreenList()) {
|
||||||
frameLeft = min(screen.visibleFrame.left, frameLeft);
|
frameLeft = frameLeft == null
|
||||||
frameTop = min(screen.visibleFrame.top, frameTop);
|
? screen.visibleFrame.left
|
||||||
frameRight = max(screen.visibleFrame.right, frameRight);
|
: min(screen.visibleFrame.left, frameLeft);
|
||||||
frameBottom = max(screen.visibleFrame.bottom, frameBottom);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (frameLeft == null) {
|
||||||
if (windowLeft < frameLeft ||
|
frameLeft = 0.0;
|
||||||
windowLeft > frameRight ||
|
frameTop = 0.0;
|
||||||
windowTop < frameTop ||
|
frameRight = ((isDesktop || isWebDesktop)
|
||||||
windowTop > frameBottom) {
|
? kDesktopMaxDisplaySize
|
||||||
|
: kMobileMaxDisplaySize)
|
||||||
|
.toDouble();
|
||||||
|
frameBottom = ((isDesktop || isWebDesktop)
|
||||||
|
? kDesktopMaxDisplaySize
|
||||||
|
: kMobileMaxDisplaySize)
|
||||||
|
.toDouble();
|
||||||
|
}
|
||||||
|
final minWidth = 10.0;
|
||||||
|
if ((left + minWidth) > frameRight! ||
|
||||||
|
(top + minWidth) > frameBottom! ||
|
||||||
|
(left + width - minWidth) < frameLeft ||
|
||||||
|
(top - minWidth) < frameTop!) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return Offset(windowLeft, windowTop);
|
return Offset(left, top);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restore window position and size on start
|
/// Restore window position and size on start
|
||||||
@ -1516,7 +1524,11 @@ Future<bool> restoreWindowPosition(WindowType type, {int? windowId}) async {
|
|||||||
final size =
|
final size =
|
||||||
await _adjustRestoreMainWindowSize(lpos.width, lpos.height);
|
await _adjustRestoreMainWindowSize(lpos.width, lpos.height);
|
||||||
final offset = await _adjustRestoreMainWindowOffset(
|
final offset = await _adjustRestoreMainWindowOffset(
|
||||||
lpos.offsetWidth, lpos.offsetHeight);
|
lpos.offsetWidth,
|
||||||
|
lpos.offsetHeight,
|
||||||
|
size.width,
|
||||||
|
size.height,
|
||||||
|
);
|
||||||
await windowManager.setSize(size);
|
await windowManager.setSize(size);
|
||||||
if (offset == null) {
|
if (offset == null) {
|
||||||
await windowManager.center();
|
await windowManager.center();
|
||||||
@ -1533,7 +1545,11 @@ Future<bool> restoreWindowPosition(WindowType type, {int? windowId}) async {
|
|||||||
final size =
|
final size =
|
||||||
await _adjustRestoreMainWindowSize(lpos.width, lpos.height);
|
await _adjustRestoreMainWindowSize(lpos.width, lpos.height);
|
||||||
final offset = await _adjustRestoreMainWindowOffset(
|
final offset = await _adjustRestoreMainWindowOffset(
|
||||||
lpos.offsetWidth, lpos.offsetHeight);
|
lpos.offsetWidth,
|
||||||
|
lpos.offsetHeight,
|
||||||
|
size.width,
|
||||||
|
size.height,
|
||||||
|
);
|
||||||
debugPrint(
|
debugPrint(
|
||||||
"restore lpos: ${size.width}/${size.height}, offset:${offset?.dx}/${offset?.dy}");
|
"restore lpos: ${size.width}/${size.height}, offset:${offset?.dx}/${offset?.dy}");
|
||||||
if (offset == null) {
|
if (offset == null) {
|
||||||
|
@ -50,11 +50,8 @@ const int kMobileDefaultDisplayHeight = 1280;
|
|||||||
const int kDesktopDefaultDisplayWidth = 1080;
|
const int kDesktopDefaultDisplayWidth = 1080;
|
||||||
const int kDesktopDefaultDisplayHeight = 720;
|
const int kDesktopDefaultDisplayHeight = 720;
|
||||||
|
|
||||||
const int kMobileMaxDisplayWidth = 720;
|
const int kMobileMaxDisplaySize = 1280;
|
||||||
const int kMobileMaxDisplayHeight = 1280;
|
const int kDesktopMaxDisplaySize = 3840;
|
||||||
|
|
||||||
const int kDesktopMaxDisplayWidth = 1920;
|
|
||||||
const int kDesktopMaxDisplayHeight = 1080;
|
|
||||||
|
|
||||||
const double kDesktopFileTransferNameColWidth = 200;
|
const double kDesktopFileTransferNameColWidth = 200;
|
||||||
const double kDesktopFileTransferModifiedColWidth = 120;
|
const double kDesktopFileTransferModifiedColWidth = 120;
|
||||||
|
@ -516,6 +516,7 @@ class WindowActionPanelState extends State<WindowActionPanel>
|
|||||||
|
|
||||||
void _setMaximize(bool maximize) {
|
void _setMaximize(bool maximize) {
|
||||||
stateGlobal.setMaximize(maximize);
|
stateGlobal.setMaximize(maximize);
|
||||||
|
_saveFrameDebounce.call(_saveFrame);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user