qt: do not assume that the interface window is in the primary monitor with csd on Windows
-
GetSystemMetrics()
function already scales most of the metrics for the primary monitor [1], evidently because Qt makes the application DPI aware. - Currently by multiplying the
GetSystemMetrics()
result withwindowDpi / screenDpi
, we apply the window's DPI which is what is wanted here. - If the window is in the primary monitor, there is no problem. If there are multiple monitors but they share the same DPI, there should also be no problem. But if there are multiple monitors that have different DPIs, in that case dragging would be problematic.
- The solution that Windows recommends [2] is using
GetSystemMetricsForDpi
andGetDpiForWindow
. Unfortunately these are only available on Windows 10, so I dynamically load the necessary library and resolve the symbols. - Handling
WM_DPICHANGED
and callingSetWindowPos()
should not be necessary, because Qt already calls it to resize the window according to the new dpi.
[1] https://learn.microsoft.com/en-us/windows/win32/gdi/multiple-monitor-system-metrics
All assumptions here are theoretical, as I have no means checking how is the behavior currently when the window is moved to a different screen with different DPI. I have checked if this would cause regressions (Windows 11, 10, 7) for single monitor case, and I could not find.
Request review @chub.