From 6fb2b4b271dba6f8b47bf66c50b30ce6df567178 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 21 May 2019 16:37:20 +0200 Subject: QPA: Prevent QPlatformWindow::initialGeometry() from returning invalid geometries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When trying to find the screen, the function would always try to determine the screen by checking parents, despite QWindowPrivate::positionAutomatic being false. Determine the screen from the initial geometry when QWindowPrivate::positionAutomatic is false. Bail out when positionAutomatic and resizeAutomatic are false. Fixes: QTBUG-75940 Change-Id: I3cd1b16feab16c89d29856cf3e1bccf2c89280c7 Reviewed-by: Thorbjørn Lund Martsum --- src/gui/kernel/qplatformwindow.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index 24cfd32ace..835c04a5df 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -705,14 +705,20 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w, w, defaultWidth, defaultHeight); return QRect(initialGeometry.topLeft(), QHighDpi::toNative(size, factor)); } - const QScreen *screen = effectiveScreen(w); + const auto *wp = qt_window_private(const_cast(w)); + const bool position = wp->positionAutomatic && w->type() != Qt::Popup; + if (!position && !wp->resizeAutomatic) + return initialGeometry; + const QScreen *screen = wp->positionAutomatic + ? effectiveScreen(w) + : QGuiApplication::screenAt(initialGeometry.center()); if (!screen) return initialGeometry; - const auto *wp = qt_window_private(const_cast(w)); + // initialGeometry refers to window's screen QRect rect(QHighDpi::fromNativePixels(initialGeometry, w)); if (wp->resizeAutomatic) rect.setSize(fixInitialSize(rect.size(), w, defaultWidth, defaultHeight)); - if (wp->positionAutomatic && w->type() != Qt::Popup) { + if (position) { const QRect availableGeometry = screen->availableGeometry(); // Center unless the geometry ( + unknown window frame) is too large for the screen). if (rect.height() < (availableGeometry.height() * 8) / 9 -- cgit v1.2.3