From a882ffc603bdc663e3d32905a1817a45167b84b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 31 Jul 2018 17:32:25 +0200 Subject: [PATCH] Handle screen changes for non-top-level windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The platform may emit screen changes for child windows before top-level windows, so we need to update the top level screen as soon as possible. Change-Id: I090c620725c9c3171f5b038708d78ddfeec8512d Reviewed-by: Lars Knoll Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qguiapplication.cpp | 6 +++--- src/gui/kernel/qwindow.cpp | 4 ++-- src/gui/kernel/qwindow_p.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 91348265cd..712699ddc9 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2338,11 +2338,11 @@ void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterf if (QWindow *window = wse->window.data()) { if (window->screen() == wse->screen.data()) return; - if (window->isTopLevel()) { + if (QWindow *topLevelWindow = window->d_func()->topLevelWindow(QWindow::ExcludeTransients)) { if (QScreen *screen = wse->screen.data()) - window->d_func()->setTopLevelScreen(screen, false /* recreate */); + topLevelWindow->d_func()->setTopLevelScreen(screen, false /* recreate */); else // Fall back to default behavior, and try to find some appropriate screen - window->setScreen(0); + topLevelWindow->setScreen(0); } // we may have changed scaling, so trigger resize event if needed if (window->handle()) { diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 75f63c046f..3d7d22959d 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -2605,14 +2605,14 @@ void QWindowPrivate::maybeQuitOnLastWindowClosed() } } -QWindow *QWindowPrivate::topLevelWindow() const +QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode) const { Q_Q(const QWindow); QWindow *window = const_cast(q); while (window) { - QWindow *parent = window->parent(QWindow::IncludeTransients); + QWindow *parent = window->parent(mode); if (!parent) break; diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index 745ff2e46f..bf5e645114 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -125,7 +125,7 @@ public: QPoint globalPosition() const; - QWindow *topLevelWindow() const; + QWindow *topLevelWindow(QWindow::AncestorMode mode = QWindow::IncludeTransients) const; #if QT_CONFIG(opengl) virtual QOpenGLContext *shareContext() const;