From f69d88c57f98472c483a7dcedcfd5afb0dbd3930 Mon Sep 17 00:00:00 2001 From: Nikita Gubarkov Date: Wed, 5 Apr 2023 13:41:51 +0000 Subject: [PATCH] 8301616: Drag & maximize to another monitor places window incorrectly (Windows) Reviewed-by: avu, aivanov, serb --- .../windows/native/libawt/windows/awt_Window.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp b/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp index 8208a57aa43..084556a4ec1 100644 --- a/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp +++ b/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp @@ -371,6 +371,20 @@ void AwtWindow::RepositionSecurityWarning(JNIEnv *env) MsgRouting AwtWindow::WmWindowPosChanged(LPARAM windowPos) { WINDOWPOS * wp = (WINDOWPOS *)windowPos; + // There's no good way to detect partial maximization (e.g. Aero Snap), + // but by inspecting SWP_* flags we can guess it and reset + // prevScaleRec to neutralize the CheckWindowDPIChange logic. + // Here are the flags, observed on Windows 11 for reference: + // Restore/maximize: SWP_NOZORDER | SWP_DRAWFRAME + // Partial Aero Snap: SWP_NOZORDER | SWP_NOREPOSITION + // DPI change (new screen): SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS + if (!(wp->flags & (SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE)) && + prevScaleRec.screen != -1 && prevScaleRec.screen != m_screenNum) { + prevScaleRec.screen = -1; + prevScaleRec.scaleX = -1.0f; + prevScaleRec.scaleY = -1.0f; + } + // Reposition the warning window if (IsUntrusted() && warningWindow != NULL) { if (wp->flags & SWP_HIDEWINDOW) {