From e7063e6cc6673857097b865ea386eca6bcd6668f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 6 Aug 2018 18:37:14 +0200 Subject: Add QPlatformScreen::windows() helper to return all windows on screen Change-Id: Ib55b37b64ed0890ca777dfea8c4d702e267c34bf Reviewed-by: Gatis Paeglis --- src/gui/kernel/qplatformscreen.cpp | 24 +++++++++++++++--------- src/gui/kernel/qplatformscreen.h | 2 ++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp index e22037c1e9..358ff16930 100644 --- a/src/gui/kernel/qplatformscreen.cpp +++ b/src/gui/kernel/qplatformscreen.cpp @@ -103,6 +103,20 @@ QWindow *QPlatformScreen::topLevelAt(const QPoint & pos) const return 0; } +/*! + Return all windows residing on this screen. +*/ +QWindowList QPlatformScreen::windows() const +{ + QWindowList windows; + for (QWindow *window : QGuiApplication::allWindows()) { + if (platformScreenForWindow(window) != this) + continue; + windows.append(window); + } + return windows; +} + /*! Find the sibling screen corresponding to \a globalPos. @@ -369,25 +383,17 @@ QPlatformCursor *QPlatformScreen::cursor() const */ void QPlatformScreen::resizeMaximizedWindows() { - QList windows = QGuiApplication::allWindows(); - // 'screen()' still has the old geometry info while 'this' has the new geometry info const QRect oldGeometry = screen()->geometry(); const QRect oldAvailableGeometry = screen()->availableGeometry(); const QRect newGeometry = deviceIndependentGeometry(); const QRect newAvailableGeometry = QHighDpi::fromNative(availableGeometry(), QHighDpiScaling::factor(this), newGeometry.topLeft()); - // make sure maximized and fullscreen windows are updated - for (int i = 0; i < windows.size(); ++i) { - QWindow *w = windows.at(i); - + for (QWindow *w : windows()) { // Skip non-platform windows, e.g., offscreen windows. if (!w->handle()) continue; - if (platformScreenForWindow(w) != this) - continue; - if (w->windowState() & Qt::WindowMaximized || w->geometry() == oldAvailableGeometry) w->setGeometry(newAvailableGeometry); else if (w->windowState() & Qt::WindowFullScreen || w->geometry() == oldGeometry) diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h index 97fe3fed03..e9d64c8a29 100644 --- a/src/gui/kernel/qplatformscreen.h +++ b/src/gui/kernel/qplatformscreen.h @@ -123,6 +123,8 @@ public: virtual void setOrientationUpdateMask(Qt::ScreenOrientations mask); virtual QWindow *topLevelAt(const QPoint &point) const; + QWindowList windows() const; + virtual QList virtualSiblings() const; const QPlatformScreen *screenForPosition(const QPoint &point) const; -- cgit v1.2.3