From 0ce04fca498c76c01cc0e8855a454eab8a9daca6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 2 Jun 2026 03:30:45 +0200 Subject: [PATCH 1/2] Fix adjusting TLW size after DPI change in wxMSW We changed the size proposed by Windows by the double of the needed amount. Call wxRect::Inflate() with one half of the needed change. This may result in 1px being lost for odd sizes but this is probably not noticeable in practice. --- src/msw/nonownedwnd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/msw/nonownedwnd.cpp b/src/msw/nonownedwnd.cpp index 6e26bb28c2..0b4684ce32 100644 --- a/src/msw/nonownedwnd.cpp +++ b/src/msw/nonownedwnd.cpp @@ -318,7 +318,7 @@ bool wxNonOwnedWindow::HandleDPIChange(const wxSize& newDPI, const wxRect& newRe // one, to prevent moving the window back to the old display from // which it might have been just moved to this one, as doing this // would result in an infinite stream of WM_DPICHANGED messages. - actualNewRect.Inflate(diff); + actualNewRect.Inflate(diff / 2); } SetSize(actualNewRect); From 5aba16a7ceff07b3381510f8138b7aef8f06ee85 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 2 Jun 2026 03:34:42 +0200 Subject: [PATCH 2/2] Decrease the size of non-resizeable TLWs on DPI change We avoid decreasing the size of the TLW on DPI change to preserve the user-set size, but this logic doesn't apply to non-resizeable windows as the user couldn't have changed their size, so do shrink them. Closes #26485. --- src/msw/nonownedwnd.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/msw/nonownedwnd.cpp b/src/msw/nonownedwnd.cpp index 0b4684ce32..4897cb1c83 100644 --- a/src/msw/nonownedwnd.cpp +++ b/src/msw/nonownedwnd.cpp @@ -311,7 +311,17 @@ bool wxNonOwnedWindow::HandleDPIChange(const wxSize& newDPI, const wxRect& newRe { const wxSize minSize = ClientToWindowSize(sizer->GetMinSize()); wxSize diff = minSize - newRect.GetSize(); - diff.IncTo(wxSize(0, 0)); + + // We don't want to shrink the window as if the user had increased + // it beyond its minimum size, we should not make it smaller again + // just because the DPI has changed, but if the window is not + // resizeable, then we do want to make it exactly of its minimum + // size because the user couldn't resize it and making it bigger + // than needed would just show unnecessary extra empty space. + if ( HasFlag(wxRESIZE_BORDER) ) + { + diff.IncTo(wxSize(0, 0)); + } // Use wxRect::Inflate() to ensure that the center of the bigger // rectangle is at the same position as the center of the proposed