Handle screen changes for non-top-level windows

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 <lars.knoll@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2018-07-31 17:32:25 +02:00
parent 9f2a671560
commit a882ffc603
3 changed files with 6 additions and 6 deletions

View File

@ -2338,11 +2338,11 @@ void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterf
if (QWindow *window = wse->window.data()) { if (QWindow *window = wse->window.data()) {
if (window->screen() == wse->screen.data()) if (window->screen() == wse->screen.data())
return; return;
if (window->isTopLevel()) { if (QWindow *topLevelWindow = window->d_func()->topLevelWindow(QWindow::ExcludeTransients)) {
if (QScreen *screen = wse->screen.data()) 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 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 // we may have changed scaling, so trigger resize event if needed
if (window->handle()) { if (window->handle()) {

View File

@ -2605,14 +2605,14 @@ void QWindowPrivate::maybeQuitOnLastWindowClosed()
} }
} }
QWindow *QWindowPrivate::topLevelWindow() const QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode) const
{ {
Q_Q(const QWindow); Q_Q(const QWindow);
QWindow *window = const_cast<QWindow *>(q); QWindow *window = const_cast<QWindow *>(q);
while (window) { while (window) {
QWindow *parent = window->parent(QWindow::IncludeTransients); QWindow *parent = window->parent(mode);
if (!parent) if (!parent)
break; break;

View File

@ -125,7 +125,7 @@ public:
QPoint globalPosition() const; QPoint globalPosition() const;
QWindow *topLevelWindow() const; QWindow *topLevelWindow(QWindow::AncestorMode mode = QWindow::IncludeTransients) const;
#if QT_CONFIG(opengl) #if QT_CONFIG(opengl)
virtual QOpenGLContext *shareContext() const; virtual QOpenGLContext *shareContext() const;