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()