From a3d72efc650db6b0663e11e3448b77ba93a0a925 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 30 Oct 2013 14:03:19 +0100 Subject: Consider multi-monitor setups in QPlatformWindow::initialGeometry(). Task-number: QTBUG-34204 Change-Id: Id79efe33ece071ad94578b6ac0370b0f040d1c3c Reviewed-by: Andy Shaw Reviewed-by: Laszlo Agocs --- src/gui/kernel/qplatformwindow.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/gui/kernel/qplatformwindow.cpp') diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index 1f9183db44..954d47f18c 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -487,6 +487,27 @@ bool QPlatformWindow::isAlertState() const 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 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 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(w))->positionAutomatic && w->type() != Qt::Popup) { - if (const QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(w)) { - const QRect availableGeometry = platformScreen->availableGeometry(); + 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 && rect.width() < (availableGeometry.width() * 8) / 9) { -- cgit v1.2.3