From a8e755e561d882527ca60efc860a1a6cdfcf8912 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 14:20:38 +0000 Subject: [PATCH] Fix Settings window going off-screen after disconnecting 4K monitor - Fix IsPositionValid to use SystemParameters.VirtualScreen* (DIP units) instead of MonitorInfo.WorkingArea (physical pixels) to avoid DPI coordinate mismatch on high-DPI and mixed-DPI multi-monitor setups. - Fix AdjustWindowPosition and SetWindowPosition to correctly calculate the max boundary as VirtualScreenTop + VirtualScreenHeight - ActualHeight (was VirtualScreenHeight - ActualHeight), which incorrectly allowed windows to extend beyond the bottom/right edge when VirtualScreenTop or VirtualScreenLeft were non-zero (e.g., monitors above/left of primary). Co-authored-by: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> --- Flow.Launcher/SettingWindow.xaml.cs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 054c60c8a..987c9cbf9 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -179,8 +179,8 @@ public partial class SettingWindow // Ensure window does not exceed screen boundaries top = Math.Max(top, SystemParameters.VirtualScreenTop); left = Math.Max(left, SystemParameters.VirtualScreenLeft); - top = Math.Min(top, SystemParameters.VirtualScreenHeight - ActualHeight); - left = Math.Min(left, SystemParameters.VirtualScreenWidth - ActualWidth); + top = Math.Min(top, SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight - ActualHeight); + left = Math.Min(left, SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth - ActualWidth); Top = top; Left = left; @@ -191,23 +191,19 @@ public partial class SettingWindow // Adjust window position if it exceeds screen boundaries top = Math.Max(top, SystemParameters.VirtualScreenTop); left = Math.Max(left, SystemParameters.VirtualScreenLeft); - top = Math.Min(top, SystemParameters.VirtualScreenHeight - ActualHeight); - left = Math.Min(left, SystemParameters.VirtualScreenWidth - ActualWidth); + top = Math.Min(top, SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight - ActualHeight); + left = Math.Min(left, SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth - ActualWidth); } private static bool IsPositionValid(double top, double left) { - foreach (var screen in MonitorInfo.GetDisplayMonitors()) - { - var workingArea = screen.WorkingArea; - - if (left >= workingArea.Left && left < workingArea.Right && - top >= workingArea.Top && top < workingArea.Bottom) - { - return true; - } - } - return false; + // Use SystemParameters (DIP units) to match the coordinate system of Window.Top/Left. + // MonitorInfo.WorkingArea uses physical pixels which can differ from DIP units when DPI + // scaling is active, leading to incorrect results on high-DPI or mixed-DPI setups. + return left >= SystemParameters.VirtualScreenLeft && + left < SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth && + top >= SystemParameters.VirtualScreenTop && + top < SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight; } private double WindowLeft()