From 75284bb8f05ab3fe8a87ea560788af4a31ec2068 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 16 Jun 2026 20:05:11 +0200 Subject: [PATCH] Ensure the window origin is visible after DPI change Keep the window origin on its display to avoid moving it out of visible area, which is unexpected and inconvenient. --- src/msw/nonownedwnd.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/msw/nonownedwnd.cpp b/src/msw/nonownedwnd.cpp index 19b489394e..c08e6f8358 100644 --- a/src/msw/nonownedwnd.cpp +++ b/src/msw/nonownedwnd.cpp @@ -34,6 +34,7 @@ #include "wx/graphics.h" #endif // wxUSE_GRAPHICS_CONTEXT +#include "wx/display.h" #include "wx/dynlib.h" #include "wx/msw/missing.h" #include "wx/msw/private/darkmode.h" @@ -338,6 +339,14 @@ bool wxNonOwnedWindow::HandleDPIChange(const wxSize& newDPI, const wxRect& newRe // 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 / 2); + + // However still ensure that the window origin is visible on its + // display, we don't move to move it out of visible space. + const wxRect screenRect = wxDisplay(this).GetClientArea(); + if ( actualNewRect.x < screenRect.x ) + actualNewRect.x = screenRect.x; + if ( actualNewRect.y < screenRect.y ) + actualNewRect.y = screenRect.y; } SetSize(actualNewRect);