From a05b619563b5e385c5f531d3c0d3e4e26f2c2ea7 Mon Sep 17 00:00:00 2001 From: Yero~ Date: Wed, 7 Jan 2026 11:20:26 +0530 Subject: [PATCH] Fix: Window positioning out of bounds on multi-monitors setup #13828 (#13903) --- flutter/lib/common.dart | 63 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 0804ebbf4..8de0f2b12 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1933,44 +1933,41 @@ Future _adjustRestoreMainWindowOffset( return null; } - double? frameLeft; - double? frameTop; - double? frameRight; - double? frameBottom; - 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); + final screens = await window_size.getScreenList(); + if (screens.isNotEmpty) { + final windowRect = Rect.fromLTWH(left, top, width, height); + bool isVisible = false; + for (final screen in screens) { + final intersection = windowRect.intersect(screen.visibleFrame); + if (intersection.width >= 10.0 && intersection.height >= 10.0) { + isVisible = true; + break; + } + } + if (!isVisible) { + return null; + } + return Offset(left, top); } } - if (frameLeft == null) { - frameLeft = 0.0; - frameTop = 0.0; - frameRight = ((isDesktop || isWebDesktop) - ? kDesktopMaxDisplaySize - : kMobileMaxDisplaySize) - .toDouble(); - frameBottom = ((isDesktop || isWebDesktop) - ? kDesktopMaxDisplaySize - : kMobileMaxDisplaySize) - .toDouble(); - } + + double frameLeft = 0.0; + double frameTop = 0.0; + double frameRight = ((isDesktop || isWebDesktop) + ? kDesktopMaxDisplaySize + : kMobileMaxDisplaySize) + .toDouble(); + double frameBottom = ((isDesktop || isWebDesktop) + ? kDesktopMaxDisplaySize + : kMobileMaxDisplaySize) + .toDouble(); + final minWidth = 10.0; - if ((left + minWidth) > frameRight! || - (top + minWidth) > frameBottom! || + if ((left + minWidth) > frameRight || + (top + minWidth) > frameBottom || (left + width - minWidth) < frameLeft || - top < frameTop!) { + top < frameTop) { return null; } else { return Offset(left, top);