diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2013-10-30 14:03:19 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-30 14:50:02 +0100 |
commit | a3d72efc650db6b0663e11e3448b77ba93a0a925 (patch) | |
tree | 70d8ea3bfae1be0c81f688569e3513b630e98859 /src/gui/kernel/qplatformwindow.cpp | |
parent | 195cd51f7d1d853220c16d043f1dfabd852de98b (diff) |
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>
Diffstat (limited to 'src/gui/kernel/qplatformwindow.cpp')
-rw-r--r-- | src/gui/kernel/qplatformwindow.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
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<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 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 && 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) { |