diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-05-21 16:37:20 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-05-22 09:26:36 +0200 |
commit | 6fb2b4b271dba6f8b47bf66c50b30ce6df567178 (patch) | |
tree | 5cb0f75c55bbf29bc4f3f6df019e806e46f08dcf | |
parent | eea6c920c977bd6e506b9983feb5cad854c51695 (diff) |
QPA: Prevent QPlatformWindow::initialGeometry() from returning invalid geometries
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 <tmartsum@gmail.com>
-rw-r--r-- | src/gui/kernel/qplatformwindow.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
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<QWindow*>(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<QWindow*>(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 |