diff options
author | Bernd Weimer <bernd.weimer@pelagicore.com> | 2018-03-29 10:47:48 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@pelagicore.com> | 2018-04-10 14:44:50 +0000 |
commit | a54db085ab1dca25d4afc40ea8dfe4ad7cf6993d (patch) | |
tree | a18491681de14a725461ae328c8af1d394844970 | |
parent | 1ef54ddaa182fc2d9e0592f7ab5c306004c0b2d3 (diff) | |
download | qtapplicationmanager-a54db085ab1dca25d4afc40ea8dfe4ad7cf6993d.tar.gz |
Relax requirement for System-UI root element
QtObjects will now be supported as System-UI root elements, as well.
Change-Id: I657de81d87a4d7f11e278d0d262e4f045d361900
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r-- | doc/systemui.qdoc | 12 | ||||
-rw-r--r-- | src/main-lib/main.cpp | 87 |
2 files changed, 70 insertions, 29 deletions
diff --git a/doc/systemui.qdoc b/doc/systemui.qdoc index 3751592f..5f4cfd85 100644 --- a/doc/systemui.qdoc +++ b/doc/systemui.qdoc @@ -25,6 +25,18 @@ ** ****************************************************************************/ +/* + We should mention some peculiarities, once this is documented: + + If the root element of the System-UI is an Item, the application-manager will create a + QQuickWindow for it and set the Item as its root Item. + + If the root element of the System-UI is a Window (or an Item, which will be wrapped in a + Window, see above), the window will be shown initially, regardless of its visible property. + Also, it will be registered as a compositor view. All other windows have to be registered + manually. +*/ + /*! \page howto-sysui.html diff --git a/src/main-lib/main.cpp b/src/main-lib/main.cpp index 442a1f5a..5780369c 100644 --- a/src/main-lib/main.cpp +++ b/src/main-lib/main.cpp @@ -659,47 +659,76 @@ void Main::showWindow(bool showFullscreen) QObject *rootObject = m_engine->rootObjects().constFirst(); if (!rootObject->isWindowType()) { - m_view = new QQuickView(m_engine, nullptr); - StartupTimer::instance()->checkpoint("after WindowManager/QuickView instantiation"); - m_view->setContent(m_mainQml, nullptr, rootObject); - window = m_view; + QQuickItem *contentItem = qobject_cast<QQuickItem *>(rootObject); + if (contentItem) { + m_view = new QQuickView(m_engine, nullptr); + m_view->setContent(m_mainQml, nullptr, rootObject); + m_view->setVisible(contentItem->isVisible()); + connect(contentItem, &QQuickItem::visibleChanged, this, [this, contentItem]() { + m_view->setVisible(contentItem->isVisible()); + }); + window = m_view; + } } else { window = qobject_cast<QQuickWindow *>(rootObject); if (!m_engine->incubationController()) m_engine->setIncubationController(window->incubationController()); } - Q_ASSERT(window); - - static QMetaObject::Connection conn = QObject::connect(window, &QQuickWindow::frameSwapped, this, []() { - // this is a queued signal, so there may be still one in the queue after calling disconnect() - if (conn) { -# if defined(Q_CC_MSVC) - qApp->disconnect(conn); // MSVC2013 cannot call static member functions without capturing this -# else - QObject::disconnect(conn); -# endif - StartupTimer::instance()->checkFirstFrame(); - StartupTimer::instance()->createReport(qSL("System-UI")); - } - }); - - m_windowManager->registerCompositorView(window); for (auto iface : qAsConst(m_startupPlugins)) iface->beforeWindowShow(window); - if (Q_LIKELY(showFullscreen)) - window->showFullScreen(); - else - window->show(); + if (!window) { + const QWindowList windowList = allWindows(); + for (QWindow *w : windowList) { + if (w->isVisible()) { + window = qobject_cast<QQuickWindow*>(w); + break; + } + } + } else { + m_windowManager->registerCompositorView(window); + } - // now check the surface format, in case we had requested a specific GL version/profile - checkOpenGLFormat("main window", window->format()); + if (window) { + StartupTimer::instance()->checkpoint("after Window instantiation/setup"); + + static QMetaObject::Connection conn = QObject::connect(window, &QQuickWindow::frameSwapped, this, []() { + // this is a queued signal, so there may be still one in the queue after calling disconnect() + if (conn) { + # if defined(Q_CC_MSVC) + qApp->disconnect(conn); // MSVC2013 cannot call static member functions without capturing this + # else + QObject::disconnect(conn); + # endif + StartupTimer::instance()->checkFirstFrame(); + StartupTimer::instance()->createReport(qSL("System-UI")); + } + }); - for (auto iface : qAsConst(m_startupPlugins)) - iface->afterWindowShow(window); + // Main window will always be shown, neglecting visible property for backwards compatibility + if (Q_LIKELY(showFullscreen)) + window->showFullScreen(); + else + window->show(); - StartupTimer::instance()->checkpoint("after window show"); + // now check the surface format, in case we had requested a specific GL version/profile + checkOpenGLFormat("main window", window->format()); + + for (auto iface : qAsConst(m_startupPlugins)) + iface->afterWindowShow(window); + + StartupTimer::instance()->checkpoint("after window show"); + } else { + static QMetaObject::Connection conn = + connect(this, &QGuiApplication::focusWindowChanged, this, [this] (QWindow *win) { + if (conn) { + QObject::disconnect(conn); + checkOpenGLFormat("first window", win->format()); + } + }); + StartupTimer::instance()->createReport(qSL("System-UI")); + } #endif } |