Consider multi-monitor setups in QPlatformWindow::initialGeometry().

Task-number: QTBUG-34204

Change-Id: Id79efe33ece071ad94578b6ac0370b0f040d1c3c
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
This commit is contained in:
Friedemann Kleint 2013-10-30 14:03:19 +01:00 committed by The Qt Project
parent 195cd51f7d
commit a3d72efc65

View File

@ -487,6 +487,27 @@ bool QPlatformWindow::isAlertState() const
return false; return false;
} }
// Return the effective screen for the initial geometry of a window. In a
// multimonitor-setup, try to find the right screen by checking the transient
// parent or the mouse cursor for parentless windows (cf QTBUG-34204,
// QDialog::adjustPosition()).
static inline const QScreen *effectiveScreen(const QWindow *window)
{
if (!window)
return QGuiApplication::primaryScreen();
const QScreen *screen = window->screen();
if (!screen)
return QGuiApplication::primaryScreen();
const QList<QScreen *> siblings = screen->virtualSiblings();
if (siblings.size() > 1) {
const QPoint referencePoint = window->transientParent() ? window->transientParent()->geometry().center() : QCursor::pos();
foreach (const QScreen *sibling, siblings)
if (sibling->geometry().contains(referencePoint))
return sibling;
}
return screen;
}
/*! /*!
Helper function to get initial geometry on windowing systems which do not Helper function to get initial geometry on windowing systems which do not
do smart positioning and also do not provide a means of centering a do smart positioning and also do not provide a means of centering a
@ -511,8 +532,8 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w,
} }
if (w->isTopLevel() && qt_window_private(const_cast<QWindow*>(w))->positionAutomatic if (w->isTopLevel() && qt_window_private(const_cast<QWindow*>(w))->positionAutomatic
&& w->type() != Qt::Popup) { && w->type() != Qt::Popup) {
if (const QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(w)) { if (const QScreen *screen = effectiveScreen(w)) {
const QRect availableGeometry = platformScreen->availableGeometry(); const QRect availableGeometry = screen->availableGeometry();
// Center unless the geometry ( + unknown window frame) is too large for the screen). // Center unless the geometry ( + unknown window frame) is too large for the screen).
if (rect.height() < (availableGeometry.height() * 8) / 9 if (rect.height() < (availableGeometry.height() * 8) / 9
&& rect.width() < (availableGeometry.width() * 8) / 9) { && rect.width() < (availableGeometry.width() * 8) / 9) {