-
Notifications
You must be signed in to change notification settings - Fork 30
Fix secondary monitor windows not handling DPI changes #29
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1147,6 +1147,19 @@ private MonitorWindowContext CreateMonitorWindow(Screen screen) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.DpiChanged += (s, dpiArgs) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx.DpiScaleX = dpiArgs.NewDpi.DpiScaleX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx.DpiScaleY = dpiArgs.NewDpi.DpiScaleY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.Left = screen.WorkingArea.X / ctx.DpiScaleX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.Top = screen.WorkingArea.Y / ctx.DpiScaleY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.Width = screen.WorkingArea.Width / ctx.DpiScaleX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.Height = screen.WorkingArea.Height / ctx.DpiScaleY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| UpdateMonitorGeometry(ctx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1152
to
+1160
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx.DpiScaleX = dpiArgs.NewDpi.DpiScaleX; | |
| ctx.DpiScaleY = dpiArgs.NewDpi.DpiScaleY; | |
| window.Left = screen.WorkingArea.X / ctx.DpiScaleX; | |
| window.Top = screen.WorkingArea.Y / ctx.DpiScaleY; | |
| window.Width = screen.WorkingArea.Width / ctx.DpiScaleX; | |
| window.Height = screen.WorkingArea.Height / ctx.DpiScaleY; | |
| UpdateMonitorGeometry(ctx); | |
| double newDpiX = dpiArgs.NewDpi.DpiScaleX; | |
| double newDpiY = dpiArgs.NewDpi.DpiScaleY; | |
| double newLeft = screen.WorkingArea.X / newDpiX; | |
| double newTop = screen.WorkingArea.Y / newDpiY; | |
| double newWidth = screen.WorkingArea.Width / newDpiX; | |
| double newHeight = screen.WorkingArea.Height / newDpiY; | |
| // Only update if the resulting geometry change is significant (more than 1 pixel) | |
| if (Math.Abs(window.Left - newLeft) > 1.0 || | |
| Math.Abs(window.Top - newTop) > 1.0 || | |
| Math.Abs(window.Width - newWidth) > 1.0 || | |
| Math.Abs(window.Height - newHeight) > 1.0) | |
| { | |
| ctx.DpiScaleX = newDpiX; | |
| ctx.DpiScaleY = newDpiY; | |
| window.Left = newLeft; | |
| window.Top = newTop; | |
| window.Width = newWidth; | |
| window.Height = newHeight; | |
| UpdateMonitorGeometry(ctx); | |
| } |
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.
The DpiChanged handler captures the
screenparameter in a closure, which can become stale after monitor configuration changes. When monitors are hot-plugged or DPI settings change, the Screen objects fromScreen.AllScreenscan be outdated.The main window's
OnDpiChangedmethod (lines 585-619) handles this by callingUpdateCurrentMonitorIndex()to refresh the monitor list and get a fresh screen object before usingscreen.WorkingArea.Consider storing the screen's index or device name instead of the Screen object itself, then retrieve the current Screen from a refreshed
Screen.AllScreenswithin the DpiChanged handler. This ensures the WorkingArea values are current.