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 <jpnurmi@theqtcompany.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-11-09 15:13:55 +01:00
parent 26e66694fa
commit 10d311d9d2
5 changed files with 32 additions and 19 deletions

View File

@ -219,11 +219,10 @@ QWindowsDirect2DIntegration::~QWindowsDirect2DIntegration()
return static_cast<QWindowsDirect2DIntegration *>(QWindowsIntegration::instance());
}
QPlatformWindow *QWindowsDirect2DIntegration::createPlatformWindow(QWindow *window) const
QWindowsWindow *QWindowsDirect2DIntegration::createPlatformWindowHelper(QWindow *window, const QWindowsWindowData &data) const
{
QWindowsWindowData data = createWindowData(window);
return data.hwnd ? new QWindowsDirect2DWindow(window, data)
: Q_NULLPTR;
return new QWindowsDirect2DWindow(window, data);
}
QPlatformNativeInterface *QWindowsDirect2DIntegration::nativeInterface() const

View File

@ -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 &paramList);
bool init();

View File

@ -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 (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 change signals of QWindow.
if ((obtained.flags & Qt::Desktop) != Qt::Desktop && requested.geometry != obtained.geometry)
// 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

View File

@ -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<QWindowsIntegrationPrivate> d;

View File

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