-
-
Notifications
You must be signed in to change notification settings - Fork 581
Fix Settings window off-screen after disconnecting high-DPI monitor #4342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+113
−68
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,4 +304,5 @@ Output-Performance.txt | |
|
|
||
| # vscode | ||
| .vscode | ||
| .history | ||
| .history | ||
| /.copilot | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -179,8 +179,8 @@ private void SetWindowPosition(double top, double left) | |||||||||||||||||||||||||||||||||||
| // 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,39 +191,35 @@ private void AdjustWindowPosition(ref double top, ref double left) | |||||||||||||||||||||||||||||||||||
| // 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; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+203
to
+206
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private double WindowLeft() | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| var screen = MonitorInfo.GetCursorDisplayMonitor(); | ||||||||||||||||||||||||||||||||||||
| var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); | ||||||||||||||||||||||||||||||||||||
| var dip2 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); | ||||||||||||||||||||||||||||||||||||
| var dip1 = screen.TransformPixelsToDIP(screen.WorkingArea.X, 0); | ||||||||||||||||||||||||||||||||||||
| var dip2 = screen.TransformPixelsToDIP(screen.WorkingArea.Width, 0); | ||||||||||||||||||||||||||||||||||||
| var left = (dip2.X - ActualWidth) / 2 + dip1.X; | ||||||||||||||||||||||||||||||||||||
| return left; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private double WindowTop() | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| var screen = MonitorInfo.GetCursorDisplayMonitor(); | ||||||||||||||||||||||||||||||||||||
| var dip1 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); | ||||||||||||||||||||||||||||||||||||
| var dip2 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); | ||||||||||||||||||||||||||||||||||||
| var dip1 = screen.TransformPixelsToDIP(0, screen.WorkingArea.Y); | ||||||||||||||||||||||||||||||||||||
| var dip2 = screen.TransformPixelsToDIP(0, screen.WorkingArea.Height); | ||||||||||||||||||||||||||||||||||||
| var top = (dip2.Y - ActualHeight) / 2 + dip1.Y - 20; | ||||||||||||||||||||||||||||||||||||
| return top; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: DPI scale uses integer division, truncating non-100%/200% scaling and producing incorrect DIP coordinates.
Prompt for AI agents