From 10d311d9d244c3a6855dd654dcf9af4bbc7044b2 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 9 Nov 2015 15:13:55 +0100 Subject: [PATCH] Windows/Direct2D: Handle screen changes after window creation. Call QWindowSystemInterface::handleWindowScreenChanged() in QWindowsIntegration::createPlatformWindow() should the effective screen be different from the initial screen due to the geometry. In order to avoid code duplication in the Direct2D plugin, fold the helper method createWindowData() into QWindowsIntegration::createPlatformWindow() and introduce a new virtual helper to create the actual platform window for QWindowsDirect2DIntegration to hook in. Task-number: QTBUG-48379 Change-Id: I49c7a50a12245691414ab49bffe802239a87d2d6 Reviewed-by: J-P Nurmi Reviewed-by: Joerg Bornemann --- .../direct2d/qwindowsdirect2dintegration.cpp | 11 ++++--- .../direct2d/qwindowsdirect2dintegration.h | 4 ++- .../platforms/windows/qwindowsintegration.cpp | 30 ++++++++++++------- .../platforms/windows/qwindowsintegration.h | 4 ++- .../platforms/windows/qwindowswindow.h | 2 ++ 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp b/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp index 20dde476c1..b86dfa3546 100644 --- a/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp +++ b/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp @@ -219,12 +219,11 @@ QWindowsDirect2DIntegration::~QWindowsDirect2DIntegration() return static_cast(QWindowsIntegration::instance()); } - QPlatformWindow *QWindowsDirect2DIntegration::createPlatformWindow(QWindow *window) const - { - QWindowsWindowData data = createWindowData(window); - return data.hwnd ? new QWindowsDirect2DWindow(window, data) - : Q_NULLPTR; - } + +QWindowsWindow *QWindowsDirect2DIntegration::createPlatformWindowHelper(QWindow *window, const QWindowsWindowData &data) const +{ + return new QWindowsDirect2DWindow(window, data); +} QPlatformNativeInterface *QWindowsDirect2DIntegration::nativeInterface() const { diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.h b/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.h index 6b7b3fbea2..64042cab0a 100644 --- a/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.h +++ b/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.h @@ -52,7 +52,6 @@ public: static QWindowsDirect2DIntegration *instance(); - QPlatformWindow *createPlatformWindow(QWindow *window) const Q_DECL_OVERRIDE; QPlatformNativeInterface *nativeInterface() const Q_DECL_OVERRIDE; QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const Q_DECL_OVERRIDE; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const Q_DECL_OVERRIDE; @@ -60,6 +59,9 @@ public: QWindowsDirect2DContext *direct2DContext() const; +protected: + QWindowsWindow *createPlatformWindowHelper(QWindow *window, const QWindowsWindowData &) const Q_DECL_OVERRIDE; + private: explicit QWindowsDirect2DIntegration(const QStringList ¶mList); bool init(); diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index b67e0b859f..36ec9ebc92 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -288,7 +288,7 @@ bool QWindowsIntegration::hasCapability(QPlatformIntegration::Capability cap) co return false; } -QWindowsWindowData QWindowsIntegration::createWindowData(QWindow *window) const +QPlatformWindow *QWindowsIntegration::createPlatformWindow(QWindow *window) const { QWindowsWindowData requested; requested.flags = window->flags(); @@ -307,22 +307,30 @@ QWindowsWindowData QWindowsIntegration::createWindowData(QWindow *window) const << "\n Obtained : " << obtained.geometry << " margins=" << obtained.frame << " handle=" << obtained.hwnd << ' ' << obtained.flags << '\n'; - if (obtained.hwnd) { - if (requested.flags != obtained.flags) - window->setFlags(obtained.flags); - // Trigger geometry change signals of QWindow. - if ((obtained.flags & Qt::Desktop) != Qt::Desktop && requested.geometry != obtained.geometry) + if (Q_UNLIKELY(!obtained.hwnd)) + return Q_NULLPTR; + + QWindowsWindow *result = createPlatformWindowHelper(window, obtained); + Q_ASSERT(result); + + if (requested.flags != obtained.flags) + window->setFlags(obtained.flags); + // Trigger geometry/screen change signals of QWindow. + if ((obtained.flags & Qt::Desktop) != Qt::Desktop) { + if (requested.geometry != obtained.geometry) QWindowSystemInterface::handleGeometryChange(window, obtained.geometry); + QPlatformScreen *screen = result->screenForGeometry(obtained.geometry); + if (screen && result->screen() != screen) + QWindowSystemInterface::handleWindowScreenChanged(window, screen->screen()); } - return obtained; + return result; } -QPlatformWindow *QWindowsIntegration::createPlatformWindow(QWindow *window) const +// Overridden to return a QWindowsDirect2DWindow in Direct2D plugin. +QWindowsWindow *QWindowsIntegration::createPlatformWindowHelper(QWindow *window, const QWindowsWindowData &data) const { - QWindowsWindowData data = createWindowData(window); - return data.hwnd ? new QWindowsWindow(window, data) - : Q_NULLPTR; + return new QWindowsWindow(window, data); } #ifndef QT_NO_OPENGL diff --git a/src/plugins/platforms/windows/qwindowsintegration.h b/src/plugins/platforms/windows/qwindowsintegration.h index fa5192ba03..cb10bf08f5 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.h +++ b/src/plugins/platforms/windows/qwindowsintegration.h @@ -62,7 +62,6 @@ public: bool hasCapability(QPlatformIntegration::Capability cap) const; - QWindowsWindowData createWindowData(QWindow *window) const; QPlatformWindow *createPlatformWindow(QWindow *window) const; #ifndef QT_NO_OPENGL QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const Q_DECL_OVERRIDE; @@ -101,6 +100,9 @@ public: QPlatformSessionManager *createPlatformSessionManager(const QString &id, const QString &key) const Q_DECL_OVERRIDE; #endif +protected: + virtual QWindowsWindow *createPlatformWindowHelper(QWindow *window, const QWindowsWindowData &) const; + private: QScopedPointer d; diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 583d3a4267..40d7a3f076 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -143,6 +143,8 @@ public: QWindowsWindow(QWindow *window, const QWindowsWindowData &data); ~QWindowsWindow(); + using QPlatformWindow::screenForGeometry; + QSurfaceFormat format() const Q_DECL_OVERRIDE { return m_format; } void setGeometry(const QRect &rect) Q_DECL_OVERRIDE; QRect geometry() const Q_DECL_OVERRIDE { return m_data.geometry; }