From a1c84af6f57bc430c3f34bb79c035a27a9dd4348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 21 Nov 2016 12:51:02 +0100 Subject: [PATCH] Refactor QGuiApplication::topLevelWindows() Unifies the three conditions where we do not treat a window as a top level window. Uses QWindow::isTopLevel() instead of manually checking parent. Updated the comment about embedded windows, which applies to all embedded windows, not just QAxServers windows. Change-Id: I7f9dbdf50044bf375ca21818ac29fbd3fe502166 Reviewed-by: Simon Hausmann --- src/gui/kernel/qguiapplication.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 14f94951d0..ccb392f968 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -937,15 +937,25 @@ QWindowList QGuiApplication::topLevelWindows() { const QWindowList &list = QGuiApplicationPrivate::window_list; QWindowList topLevelWindows; - for (int i = 0; i < list.size(); i++) { - if (!list.at(i)->parent() && list.at(i)->type() != Qt::Desktop) { - // Top windows of embedded QAxServers do not have QWindow parents, - // but they are not true top level windows, so do not include them. - const bool embedded = list.at(i)->handle() && list.at(i)->handle()->isEmbedded(); - if (!embedded) - topLevelWindows.prepend(list.at(i)); - } + for (int i = 0; i < list.size(); ++i) { + QWindow *window = list.at(i); + if (!window->isTopLevel()) + continue; + + // Desktop windows are special, as each individual desktop window + // will report that it's a top level window, but we don't want to + // include them in the application wide list of top level windows. + if (window->type() == Qt::Desktop) + continue; + + // Windows embedded in native windows do not have QWindow parents, + // but they are not true top level windows, so do not include them. + if (window->handle() && window->handle()->isEmbedded()) + continue; + + topLevelWindows.prepend(window); } + return topLevelWindows; }