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.
This commit is contained in:
Vadim Zeitlin
2026-06-16 20:05:11 +02:00
parent 8386a98409
commit 75284bb8f0
+9
View File
@@ -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);