summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2017-02-13 08:48:25 +0100
committerOlivier Goffart (Woboq GmbH) <ogoffart@woboq.com>2017-02-16 15:31:38 +0000
commitcd2b5f1ada07fc7a5ec31e3b48a7fdf76bf62020 (patch)
tree882e22fc30624de0f5f4883d658ebad7bc170c9f /src/plugins
parent2b34aefcf02f09253473b096eb4faffd3e62b5f4 (diff)
Resize the window when the screen's dpi changes
That's what the MSDN documentation say one should do in the handler for WM_DPICHANGED [ChangeLog][QtGui][Windows] Windows are now automatically resized when they are moved on a screen to adapt to the new pixel ratio. Task-number: QTBUG-55510 Task-number: QTBUG-48242 Change-Id: I7688f12165f76585d75686e2e94b0fc562627be2 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/windows/qtwindowsglobal.h7
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp9
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.cpp8
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.h3
4 files changed, 24 insertions, 3 deletions
diff --git a/src/plugins/platforms/windows/qtwindowsglobal.h b/src/plugins/platforms/windows/qtwindowsglobal.h
index 27632de688..a5c05bf1a3 100644
--- a/src/plugins/platforms/windows/qtwindowsglobal.h
+++ b/src/plugins/platforms/windows/qtwindowsglobal.h
@@ -56,6 +56,10 @@
# define WM_GESTURE 0x0119
#endif
+#ifndef WM_DPICHANGED
+# define WM_DPICHANGED 0x02E0
+#endif
+
QT_BEGIN_NAMESPACE
namespace QtWindows
@@ -96,6 +100,7 @@ enum WindowsEventType // Simplify event types
FocusInEvent = WindowEventFlag + 17,
FocusOutEvent = WindowEventFlag + 18,
WhatsThisEvent = WindowEventFlag + 19,
+ DpiChangedEvent = WindowEventFlag + 21,
MouseEvent = MouseEventFlag + 1,
MouseWheelEvent = MouseEventFlag + 2,
CursorEvent = MouseEventFlag + 3,
@@ -266,6 +271,8 @@ inline QtWindows::WindowsEventType windowsEventType(UINT message, WPARAM wParamI
#endif
case WM_GESTURE:
return QtWindows::GestureEvent;
+ case WM_DPICHANGED:
+ return QtWindows::DpiChangedEvent;
default:
break;
}
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index fefc848d01..5745fc6d19 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -1088,6 +1088,15 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
return true;
#endif
} break;
+ case QtWindows::DpiChangedEvent: {
+ platformWindow->setFlag(QWindowsWindow::WithinDpiChanged);
+ const RECT *prcNewWindow = reinterpret_cast<RECT *>(lParam);
+ SetWindowPos(hwnd, NULL, prcNewWindow->left, prcNewWindow->top,
+ prcNewWindow->right - prcNewWindow->left,
+ prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE);
+ platformWindow->clearFlag(QWindowsWindow::WithinDpiChanged);
+ return true;
+ }
#if !defined(QT_NO_SESSIONMANAGER)
case QtWindows::QueryEndSessionApplicationEvent: {
QWindowsSessionManager *sessionManager = platformSessionManager();
diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
index 42eb6d4ca7..40229d00af 100644
--- a/src/plugins/platforms/windows/qwindowswindow.cpp
+++ b/src/plugins/platforms/windows/qwindowswindow.cpp
@@ -2114,8 +2114,12 @@ void QWindowsWindow::setFrameStrutEventsEnabled(bool enabled)
void QWindowsWindow::getSizeHints(MINMAXINFO *mmi) const
{
- const QWindowsGeometryHint hint(window(), m_data.customMargins);
- hint.applyToMinMaxInfo(m_data.hwnd, mmi);
+ // We don't apply the min/max size hint as we change the dpi, because we did not adjust the
+ // QScreen of the window yet so we don't have the min/max with the right ratio
+ if (!testFlag(QWindowsWindow::WithinDpiChanged)) {
+ const QWindowsGeometryHint hint(window(), m_data.customMargins);
+ hint.applyToMinMaxInfo(m_data.hwnd, mmi);
+ }
if ((testFlag(WithinMaximize) || (window()->windowState() == Qt::WindowMinimized))
&& (m_data.flags & Qt::FramelessWindowHint)) {
diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h
index 8179280bb3..10cfc18dff 100644
--- a/src/plugins/platforms/windows/qwindowswindow.h
+++ b/src/plugins/platforms/windows/qwindowswindow.h
@@ -205,7 +205,8 @@ public:
MaximizeToFullScreen = 0x80000,
InputMethodDisabled = 0x100000,
Compositing = 0x200000,
- HasBorderInFullScreen = 0x400000
+ HasBorderInFullScreen = 0x400000,
+ WithinDpiChanged = 0x800000,
};
QWindowsWindow(QWindow *window, const QWindowsWindowData &data);