Skip to content

Commit d79b7bf

Browse files
committed
fix: improve DPI handling for popup window on mixed-DPI setups
1 parent 92e8848 commit d79b7bf

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/platform/win32/PopupWindow.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#endif
4141

4242
#include <dwmapi.h>
43+
#include <shellscalingapi.h>
4344
#include <unknwn.h>
4445
#include <windows.ui.xaml.hosting.desktopwindowxamlsource.h>
4546
#include <winrt/Windows.Foundation.h>
@@ -3240,7 +3241,18 @@ class PopupWindow {
32403241
if (!GetMonitorInfoW(monitor, &info)) {
32413242
return;
32423243
}
3243-
const UINT dpi = GetDpiForWindow(hwnd_);
3244+
// Size for the monitor the popup is GOING to, not the one the hidden
3245+
// window happens to be parked on (GetDpiForWindow): when the two
3246+
// disagree — mixed-DPI setups, or a DPI topology change (RDP
3247+
// reconnect, resolution flip) since the window was placed — the old
3248+
// code sized at the stale scale and left WM_DPICHANGED's mid-
3249+
// SetWindowPos suggested-rect rescue racing the explicit size
3250+
// (observed in the wild: a quarter-size popup at 200%).
3251+
UINT dpi = 0;
3252+
UINT dpiYIgnored = 0;
3253+
if (FAILED(GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpi, &dpiYIgnored)) || dpi == 0) {
3254+
dpi = GetDpiForWindow(hwnd_);
3255+
}
32443256
const int width = DipsToPixels(CurrentWidthDips(), dpi);
32453257
const int height = DipsToPixels(kPopupHeightDips, dpi);
32463258
const RECT& work = info.rcWork;

0 commit comments

Comments
 (0)