diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 5bc6d1b2e0..c809e772c4 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -183,6 +183,27 @@ QWindowList QGuiApplication::topLevelWindows() return QGuiApplicationPrivate::window_list; } +QWindow *QGuiApplication::topLevelAt(const QPoint &pos) +{ + QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); + + QList screens = pi->screens(); + QList::const_iterator screen = screens.constBegin(); + QList::const_iterator end = screens.constEnd(); + + // The first screen in a virtual environment should know about all top levels + if (pi->isVirtualDesktop()) + return (*screen)->topLevelAt(pos); + + while (screen != end) { + if ((*screen)->geometry().contains(pos)) + return (*screen)->topLevelAt(pos); + ++screen; + } + return 0; +} + + static void init_platform(const QString &name, const QString &platformPluginPath) { QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, platformPluginPath); diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index f12214dee1..4557b946a8 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -80,6 +80,7 @@ public: virtual ~QGuiApplication(); static QWindowList topLevelWindows(); + static QWindow *topLevelAt(const QPoint &pos); static QWindow *activeWindow(); diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index fef579b6b0..5efd087b09 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -58,21 +58,27 @@ QWindow::QWindow(QWindow *parent) { Q_D(QWindow); d->parentWindow = parent; + QGuiApplicationPrivate::window_list.prepend(this); } QWindow::~QWindow() { if (QGuiApplicationPrivate::active_window == this) QGuiApplicationPrivate::active_window = 0; + QGuiApplicationPrivate::window_list.removeAll(this); destroy(); } void QWindow::setVisible(bool visible) { Q_D(QWindow); - if (!d->platformWindow) { + + if (d->visible == visible) + return; + d->visible = visible; + + if (!d->platformWindow) create(); - } d->platformWindow->setVisible(visible); }