From 04f31f7b42f7de920ba1cb60073bb5be811837d2 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Mon, 7 Mar 2022 10:26:16 +0800 Subject: [PATCH] Win32: update the internal margin when DPI changes Make the internal margin sync with the latest DPI. Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- framelesshelper_win32.cpp | 8 +++++++- framelesshelper_windows.h | 4 ++++ framelessquickhelper.cpp | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/framelesshelper_win32.cpp b/framelesshelper_win32.cpp index 483757a..48096cb 100644 --- a/framelesshelper_win32.cpp +++ b/framelesshelper_win32.cpp @@ -154,7 +154,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me // Anyway, we should skip it in this case. return false; } - const QWindow *window = Utilities::findWindow(reinterpret_cast(msg->hwnd)); + const QWindow * const window = Utilities::findWindow(reinterpret_cast(msg->hwnd)); if (!window || !window->property(Constants::kFramelessModeFlag).toBool()) { return false; } @@ -675,6 +675,12 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me windowPos->flags |= SWP_NOCOPYBITS; } break; #endif + case WM_DPICHANGED: { + // The DPI has changed, we need to update the internal window frame + // recorded in Windows QPA. + Utilities::updateQtFrameMargins(const_cast(window), true); + Utilities::triggerFrameChange(reinterpret_cast(msg->hwnd)); + } break; default: break; } diff --git a/framelesshelper_windows.h b/framelesshelper_windows.h index 6d53db4..a32e725 100644 --- a/framelesshelper_windows.h +++ b/framelesshelper_windows.h @@ -90,6 +90,10 @@ #define WM_DWMCOLORIZATIONCOLORCHANGED (0x0320) #endif +#ifndef WM_DPICHANGED +#define WM_DPICHANGED (0x02E0) +#endif + #ifndef SM_CXPADDEDBORDER #define SM_CXPADDEDBORDER (92) #endif diff --git a/framelessquickhelper.cpp b/framelessquickhelper.cpp index 59a4732..00d37f1 100644 --- a/framelessquickhelper.cpp +++ b/framelessquickhelper.cpp @@ -96,6 +96,9 @@ void FramelessQuickHelper::showMinimized() { #ifdef Q_OS_WINDOWS // Work-around a QtQuick bug: https://bugreports.qt.io/browse/QTBUG-69711 + // Don't use "SW_SHOWMINIMIZED" because it will activate the current + // window instead of the next window in the Z order, that's not the + // native behavior of Windows applications. ShowWindow(reinterpret_cast(window()->winId()), SW_MINIMIZE); #else window()->showMinimized();