From 4ad8798de428b44fe4c56e1ca111940068056c57 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 7 Dec 2015 12:44:09 +0100 Subject: QPlatformWindow::initialGeometry(): Pass screen when scaling. Otherwise, the window may up outside the display area when centering on a secondary screen and the primary screen has a different scale factor. Task-number: QTBUG-49803 Change-Id: I91ec7c5348722a90012f80a247e662e96bcbb391 Reviewed-by: Alessandro Portale --- src/gui/kernel/qplatformwindow.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/gui/kernel/qplatformwindow.cpp') diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index 8757715c0d..aea029b7f5 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -581,6 +581,9 @@ void QPlatformWindow::invalidateSurface() QRect QPlatformWindow::initialGeometry(const QWindow *w, const QRect &initialGeometry, int defaultWidth, int defaultHeight) { + const QScreen *screen = effectiveScreen(w); + if (!screen) + return initialGeometry; QRect rect(QHighDpi::fromNativePixels(initialGeometry, w)); if (rect.width() == 0) { const int minWidth = w->minimumWidth(); @@ -591,25 +594,23 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w, rect.setHeight(minHeight > 0 ? minHeight : defaultHeight); } if (w->isTopLevel() && qt_window_private(const_cast(w))->positionAutomatic - && w->type() != Qt::Popup) { - if (const QScreen *screen = effectiveScreen(w)) { - 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 + && w->type() != Qt::Popup) { + 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 && rect.width() < (availableGeometry.width() * 8) / 9) { - const QWindow *tp = w->transientParent(); - if (tp) { - // A transient window should be centered w.r.t. its transient parent. - rect.moveCenter(tp->geometry().center()); - } else { - // Center the window on the screen. (Only applicable on platforms - // which do not provide a better way.) - rect.moveCenter(availableGeometry.center()); - } + const QWindow *tp = w->transientParent(); + if (tp) { + // A transient window should be centered w.r.t. its transient parent. + rect.moveCenter(tp->geometry().center()); + } else { + // Center the window on the screen. (Only applicable on platforms + // which do not provide a better way.) + rect.moveCenter(availableGeometry.center()); } } } - return QHighDpi::toNativePixels(rect, w); + return QHighDpi::toNativePixels(rect, screen); } /*! -- cgit v1.2.3