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>
This commit is contained in:
Friedemann Kleint 2019-05-21 16:37:20 +02:00
parent eea6c920c9
commit 6fb2b4b271

View File

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