cairoshell / ManagedShell

A library for creating Windows shell replacements using .NET.
https://www.nuget.org/packages/ManagedShell/
Apache License 2.0
295 stars 25 forks source link

Fix infinite loop in some mixed DPI setups #73

Closed dremin closed 1 year ago

dremin commented 1 year ago

When we move a window to a monitor that has a different DPI than the main display DPI ("system DPI"), Windows sends a WM_DPICHANGED message to the window telling it as such. However, when we move the window to that display, we have already given it the correct coordinates, so we do not need to handle the WM_DPICHANGED message.

Before, when we did handle WM_DPICHANGED in this scenario, we moved the window to the wrong place, which would send another WM_DPICHANGED message, causing it to move back to the correct place, and so on in an infinite loop until hitting the Windows message quota.

The fix for this is to suppress handling WM_DPICHANGED when the window is being positioned initially.

Also fixed another DPI-related issue when Application.Current.MainWindow was not on the primary display.