diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-07-23 14:01:38 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-09-05 15:21:39 +0200 |
commit | eac2876d55732696991c4629e6bd88e302a72f56 (patch) | |
tree | 320a3ef3adff529c51b46f15ef8d18c866dd0201 /src/plugins/platforms/windows/qwindowsscreen.cpp | |
parent | 070fcf9ce1ef3c2912bd15f1f39db9740cc754c6 (diff) |
Windows: Move dock windows automatically when screen is disconnected.
Windows does not automatically move WS_EX_TOOLWINDOW type windows.
Task-number: QTBUG-39320
Change-Id: If9804f32beb534a27ba649abf5eaceb686af8f50
Reviewed-by: Björn Breitmeyer <bjoern.breitmeyer@kdab.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsscreen.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsscreen.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 796975122e..f491b51aa8 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -429,6 +429,23 @@ static inline int indexOfMonitor(const QList<QWindowsScreenData> &screenData, return -1; } +// Move a window to a new virtual screen, accounting for varying sizes. +static void moveToVirtualScreen(QWindow *w, const QScreen *newScreen) +{ + QRect geometry = w->geometry(); + const QRect oldScreenGeometry = w->screen()->geometry(); + const QRect newScreenGeometry = newScreen->geometry(); + QPoint relativePosition = geometry.topLeft() - oldScreenGeometry.topLeft(); + if (oldScreenGeometry.size() != newScreenGeometry.size()) { + const qreal factor = + qreal(QPoint(newScreenGeometry.width(), newScreenGeometry.height()).manhattanLength()) / + qreal(QPoint(oldScreenGeometry.width(), oldScreenGeometry.height()).manhattanLength()); + relativePosition = (QPointF(relativePosition) * factor).toPoint(); + } + geometry.moveTopLeft(relativePosition); + w->setGeometry(geometry); +} + void QWindowsScreenManager::removeScreen(int index) { qCDebug(lcQpaWindows) << "Removing Monitor:" << m_screens.at(index)->data(); @@ -439,11 +456,18 @@ void QWindowsScreenManager::removeScreen(int index) // event, but unfortunately after the screen destruction signal. To prevent // QtGui from automatically hiding the QWindow, pretend all Windows move to // the primary screen first (which is likely the correct, final screen). + // QTBUG-39320: Windows does not automatically move WS_EX_TOOLWINDOW (dock) windows; + // move those manually. if (screen != primaryScreen) { unsigned movedWindowCount = 0; foreach (QWindow *w, QGuiApplication::topLevelWindows()) { if (w->screen() == screen && w->handle() && w->type() != Qt::Desktop) { - QWindowSystemInterface::handleWindowScreenChanged(w, primaryScreen); + if (w->isVisible() && w->windowState() != Qt::WindowMinimized + && (QWindowsWindow::baseWindowOf(w)->exStyle() & WS_EX_TOOLWINDOW)) { + moveToVirtualScreen(w, primaryScreen); + } else { + QWindowSystemInterface::handleWindowScreenChanged(w, primaryScreen); + } ++movedWindowCount; } } |