summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowscontext.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2019-05-15 07:11:41 +0200
committerLiang Qi <liang.qi@qt.io>2019-05-15 07:11:41 +0200
commitc0359bd3c3a098ace9d2fa7ee91c33b24a8d9477 (patch)
tree9bcae3bff2ccef2b020c7a9ef25b3643e9ae556f /src/plugins/platforms/windows/qwindowscontext.cpp
parent68eea0196ebf30617e7d837ac5f61aaeeb814692 (diff)
parent1e5deb06416b6efc33a2009d9678fd8f743c5ce7 (diff)
Merge remote-tracking branch 'origin/5.13' into dev
Conflicts: src/corelib/global/qfloat16.cpp src/corelib/global/qfloat16.h src/plugins/platforms/windows/qwindowswindow.cpp Change-Id: I0938aaa6a9771f55e48c95ed29f6f5291431b947
Diffstat (limited to 'src/plugins/platforms/windows/qwindowscontext.cpp')
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index 9ab9c2708b..320b5b1a41 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -210,6 +210,7 @@ void QWindowsUser32DLL::init()
if (QOperatingSystemVersion::current()
>= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 14393)) {
+ adjustWindowRectExForDpi = (AdjustWindowRectExForDpi)library.resolve("AdjustWindowRectExForDpi");
enableNonClientDpiScaling = (EnableNonClientDpiScaling)library.resolve("EnableNonClientDpiScaling");
getWindowDpiAwarenessContext = (GetWindowDpiAwarenessContext)library.resolve("GetWindowDpiAwarenessContext");
getAwarenessFromDpiAwarenessContext = (GetAwarenessFromDpiAwarenessContext)library.resolve("GetAwarenessFromDpiAwarenessContext");
@@ -977,7 +978,7 @@ static inline bool resizeOnDpiChanged(const QWindow *w)
return result;
}
-static bool shouldHaveNonClientDpiScaling(const QWindow *window)
+bool QWindowsContext::shouldHaveNonClientDpiScaling(const QWindow *window)
{
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10
&& window->isTopLevel()
@@ -1321,15 +1322,24 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
#endif
} break;
case QtWindows::DpiChangedEvent: {
- if (!resizeOnDpiChanged(platformWindow->window()))
- return false;
- platformWindow->setFlag(QWindowsWindow::WithinDpiChanged);
- const RECT *prcNewWindow = reinterpret_cast<RECT *>(lParam);
- SetWindowPos(hwnd, nullptr, prcNewWindow->left, prcNewWindow->top,
- prcNewWindow->right - prcNewWindow->left,
- prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE);
- platformWindow->clearFlag(QWindowsWindow::WithinDpiChanged);
- return true;
+ // Try to apply the suggested size first and then notify ScreenChanged
+ // so that the resize event sent from QGuiApplication incorporates it
+ // WM_DPICHANGED is sent with a size that avoids resize loops (by
+ // snapping back to the previous screen, see QTBUG-65580).
+ const bool doResize = resizeOnDpiChanged(platformWindow->window());
+ if (doResize) {
+ platformWindow->setFlag(QWindowsWindow::WithinDpiChanged);
+ platformWindow->updateFullFrameMargins();
+ const auto prcNewWindow = reinterpret_cast<RECT *>(lParam);
+ qCDebug(lcQpaWindows) << __FUNCTION__ << "WM_DPICHANGED"
+ << platformWindow->window() << *prcNewWindow;
+ SetWindowPos(hwnd, nullptr, prcNewWindow->left, prcNewWindow->top,
+ prcNewWindow->right - prcNewWindow->left,
+ prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE);
+ platformWindow->clearFlag(QWindowsWindow::WithinDpiChanged);
+ }
+ platformWindow->checkForScreenChanged(QWindowsWindow::FromDpiChange);
+ return doResize;
}
#if QT_CONFIG(sessionmanager)
case QtWindows::QueryEndSessionApplicationEvent: {
@@ -1587,6 +1597,7 @@ extern "C" LRESULT QT_WIN_CALLBACK qWindowsWndProc(HWND hwnd, UINT message, WPAR
marginsFromRects(ncCalcSizeFrame, rectFromNcCalcSize(message, wParam, lParam, 0));
if (margins.left() >= 0) {
if (platformWindow) {
+ qCDebug(lcQpaWindows) << __FUNCTION__ << "WM_NCCALCSIZE for" << hwnd << margins;
platformWindow->setFullFrameMargins(margins);
} else {
const QSharedPointer<QWindowCreationContext> ctx = QWindowsContext::instance()->windowCreationContext();