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>
This commit is contained in:
Yuhang Zhao 2022-03-07 10:26:16 +08:00
parent 824b0746c1
commit 04f31f7b42
3 changed files with 14 additions and 1 deletions

View File

@ -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<WId>(msg->hwnd));
const QWindow * const window = Utilities::findWindow(reinterpret_cast<WId>(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<QWindow *>(window), true);
Utilities::triggerFrameChange(reinterpret_cast<WId>(msg->hwnd));
} break;
default:
break;
}

View File

@ -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

View File

@ -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<HWND>(window()->winId()), SW_MINIMIZE);
#else
window()->showMinimized();