This commit is contained in:
Copilot 2026-03-10 22:52:54 +08:00 committed by GitHub
commit bff8f77e81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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