Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions WindowsEdgeLight/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +1155 to +1158
Copy link

Copilot AI Feb 12, 2026

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 screen parameter in a closure, which can become stale after monitor configuration changes. When monitors are hot-plugged or DPI settings change, the Screen objects from Screen.AllScreens can be outdated.

The main window's OnDpiChanged method (lines 585-619) handles this by calling UpdateCurrentMonitorIndex() to refresh the monitor list and get a fresh screen object before using screen.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.AllScreens within the DpiChanged handler. This ensures the WorkingArea values are current.

Copilot uses AI. Check for mistakes.

UpdateMonitorGeometry(ctx);
Comment on lines +1152 to +1160
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DpiChanged handler unconditionally updates window position and size without checking if the change is significant. This could potentially cause update loops or unnecessary geometry recalculations.

The main window's OnDpiChanged method (lines 609-616) includes a threshold check to only update if the difference is greater than 1 pixel, which helps avoid infinite update loops.

Consider adding a similar threshold check before updating the window properties and calling UpdateMonitorGeometry.

Suggested change
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);
}

Copilot uses AI. Check for mistakes.
};

return ctx;
}

Expand Down
Loading