Fix: Window positioning out of bounds on multi-monitors setup #13828 (#13903)

This commit is contained in:
Yero~
2026-01-07 11:20:26 +05:30
committed by GitHub
parent 7f9506b476
commit a05b619563

View File

@@ -1933,44 +1933,41 @@ Future<Offset?> _adjustRestoreMainWindowOffset(
return null; return null;
} }
double? frameLeft;
double? frameTop;
double? frameRight;
double? frameBottom;
if (isDesktop || isWebDesktop) { if (isDesktop || isWebDesktop) {
for (final screen in await window_size.getScreenList()) { final screens = await window_size.getScreenList();
frameLeft = frameLeft == null if (screens.isNotEmpty) {
? screen.visibleFrame.left final windowRect = Rect.fromLTWH(left, top, width, height);
: min(screen.visibleFrame.left, frameLeft); bool isVisible = false;
frameTop = frameTop == null for (final screen in screens) {
? screen.visibleFrame.top final intersection = windowRect.intersect(screen.visibleFrame);
: min(screen.visibleFrame.top, frameTop); if (intersection.width >= 10.0 && intersection.height >= 10.0) {
frameRight = frameRight == null isVisible = true;
? screen.visibleFrame.right break;
: max(screen.visibleFrame.right, frameRight); }
frameBottom = frameBottom == null }
? screen.visibleFrame.bottom if (!isVisible) {
: max(screen.visibleFrame.bottom, frameBottom); return null;
}
return Offset(left, top);
} }
} }
if (frameLeft == null) {
frameLeft = 0.0; double frameLeft = 0.0;
frameTop = 0.0; double frameTop = 0.0;
frameRight = ((isDesktop || isWebDesktop) double frameRight = ((isDesktop || isWebDesktop)
? kDesktopMaxDisplaySize ? kDesktopMaxDisplaySize
: kMobileMaxDisplaySize) : kMobileMaxDisplaySize)
.toDouble(); .toDouble();
frameBottom = ((isDesktop || isWebDesktop) double frameBottom = ((isDesktop || isWebDesktop)
? kDesktopMaxDisplaySize ? kDesktopMaxDisplaySize
: kMobileMaxDisplaySize) : kMobileMaxDisplaySize)
.toDouble(); .toDouble();
}
final minWidth = 10.0; final minWidth = 10.0;
if ((left + minWidth) > frameRight! || if ((left + minWidth) > frameRight ||
(top + minWidth) > frameBottom! || (top + minWidth) > frameBottom ||
(left + width - minWidth) < frameLeft || (left + width - minWidth) < frameLeft ||
top < frameTop!) { top < frameTop) {
return null; return null;
} else { } else {
return Offset(left, top); return Offset(left, top);