Skip to content

Commit 31c47e6

Browse files
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>
1 parent 4a847d4 commit 31c47e6

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ private void SetWindowPosition(double top, double left)
179179
// Ensure window does not exceed screen boundaries
180180
top = Math.Max(top, SystemParameters.VirtualScreenTop);
181181
left = Math.Max(left, SystemParameters.VirtualScreenLeft);
182-
top = Math.Min(top, SystemParameters.VirtualScreenHeight - ActualHeight);
183-
left = Math.Min(left, SystemParameters.VirtualScreenWidth - ActualWidth);
182+
top = Math.Min(top, SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight - ActualHeight);
183+
left = Math.Min(left, SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth - ActualWidth);
184184

185185
Top = top;
186186
Left = left;
@@ -191,23 +191,19 @@ private void AdjustWindowPosition(ref double top, ref double left)
191191
// Adjust window position if it exceeds screen boundaries
192192
top = Math.Max(top, SystemParameters.VirtualScreenTop);
193193
left = Math.Max(left, SystemParameters.VirtualScreenLeft);
194-
top = Math.Min(top, SystemParameters.VirtualScreenHeight - ActualHeight);
195-
left = Math.Min(left, SystemParameters.VirtualScreenWidth - ActualWidth);
194+
top = Math.Min(top, SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight - ActualHeight);
195+
left = Math.Min(left, SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth - ActualWidth);
196196
}
197197

198198
private static bool IsPositionValid(double top, double left)
199199
{
200-
foreach (var screen in MonitorInfo.GetDisplayMonitors())
201-
{
202-
var workingArea = screen.WorkingArea;
203-
204-
if (left >= workingArea.Left && left < workingArea.Right &&
205-
top >= workingArea.Top && top < workingArea.Bottom)
206-
{
207-
return true;
208-
}
209-
}
210-
return false;
200+
// Use SystemParameters (DIP units) to match the coordinate system of Window.Top/Left.
201+
// MonitorInfo.WorkingArea uses physical pixels which can differ from DIP units when DPI
202+
// scaling is active, leading to incorrect results on high-DPI or mixed-DPI setups.
203+
return left >= SystemParameters.VirtualScreenLeft &&
204+
left < SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth &&
205+
top >= SystemParameters.VirtualScreenTop &&
206+
top < SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight;
211207
}
212208

213209
private double WindowLeft()

0 commit comments

Comments
 (0)