From 8f21ade0c707d3f3eb76eb57da7c694cb62d618c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 23 Nov 2018 19:56:35 -0800 Subject: [PATCH] make cmake -DDISABLE_QML=1 work again --- interface/src/Application.cpp | 145 +++++++++++++----- interface/src/Application_render.cpp | 2 + interface/src/ConnectionMonitor.cpp | 4 + interface/src/ui/ApplicationOverlay.cpp | 2 + interface/src/ui/OverlayConductor.cpp | 2 + interface/src/ui/OverlayConductor.h | 2 + interface/src/ui/overlays/Overlays.cpp | 4 + libraries/shared/src/DependencyManager.h | 30 ++-- libraries/ui/src/OffscreenUi.cpp | 4 +- libraries/ui/src/ui/Menu.cpp | 64 +++++--- .../ui/src/ui/TabletScriptingInterface.cpp | 2 + 11 files changed, 185 insertions(+), 76 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fb6e8ec566..21af28ffcb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -927,7 +927,9 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { #endif DependencyManager::set(); DependencyManager::set(); +#if !defined(DISABLE_QML) DependencyManager::set(); +#endif DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -1000,6 +1002,14 @@ const bool DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS = false; const QString DEFAULT_CURSOR_NAME = "DEFAULT"; const bool DEFAULT_MINI_TABLET_ENABLED = true; +QSharedPointer getOffscreenUI() { +#if !defined(DISABLE_QML) + return DependencyManager::get(); +#else + return nullptr; +#endif +} + Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runningMarkerExisted) : QApplication(argc, argv), _window(new MainWindow(desktop())), @@ -1604,7 +1614,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo auto userInputMapper = DependencyManager::get(); connect(userInputMapper.data(), &UserInputMapper::actionEvent, [this](int action, float state) { using namespace controller; - auto offscreenUi = DependencyManager::get(); auto tabletScriptingInterface = DependencyManager::get(); { auto actionEnum = static_cast(action); @@ -1743,7 +1752,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo return qApp->getMyAvatar()->getCharacterController()->onGround() ? 1 : 0; }); _applicationStateDevice->setInputVariant(STATE_NAV_FOCUSED, []() -> float { - return DependencyManager::get()->navigationFocused() ? 1 : 0; + auto offscreenUi = getOffscreenUI(); + return offscreenUi ? (offscreenUi->navigationFocused() ? 1 : 0) : 0; }); _applicationStateDevice->setInputVariant(STATE_PLATFORM_WINDOWS, []() -> float { #if defined(Q_OS_WIN) @@ -1809,9 +1819,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo // Now that we've loaded the menu and thus switched to the previous display plugin // we can unlock the desktop repositioning code, since all the positions will be // relative to the desktop size for this plugin - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); connect(offscreenUi.data(), &OffscreenUi::desktopReady, []() { - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); auto desktop = offscreenUi->getDesktop(); if (desktop) { desktop->setProperty("repositionLocked", false); @@ -2372,6 +2382,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo connect(&AndroidHelper::instance(), &AndroidHelper::enterForeground, this, &Application::enterForeground); AndroidHelper::instance().notifyLoadComplete(); #else +#if !defined(DISABLE_QML) // Do not show login dialog if requested not to on the command line const QString HIFI_NO_LOGIN_COMMAND_LINE_KEY = "--no-login-suggestion"; int index = arguments().indexOf(HIFI_NO_LOGIN_COMMAND_LINE_KEY); @@ -2396,6 +2407,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo checkLoginTimer->start(); } #endif +#endif } void Application::updateVerboseLogging() { @@ -2546,7 +2558,9 @@ void Application::onAboutToQuit() { DependencyManager::get()->startThread(); // Hide Running Scripts dialog so that it gets destroyed in an orderly manner; prevents warnings at shutdown. - DependencyManager::get()->hide("RunningScripts"); +#if !defined(DISABLE_QML) + getOffscreenUI()->hide("RunningScripts"); +#endif _aboutToQuit = true; @@ -2784,10 +2798,10 @@ void Application::initializeGL() { _glWidget->windowHandle()->setFormat(getDefaultOpenGLSurfaceFormat()); // When loading QtWebEngineWidgets, it creates a global share context on startup. - // We have to account for this possibility by checking here for an existing + // We have to account for this possibility by checking here for an existing // global share context auto globalShareContext = qt_gl_global_share_context(); - + #if !defined(DISABLE_QML) // Build a shared canvas / context for the Chromium processes if (!globalShareContext) { @@ -2974,7 +2988,9 @@ void Application::initializeRenderEngine() { } extern void setupPreferences(); +#if !defined(DISABLE_QML) static void addDisplayPluginToMenu(const DisplayPluginPointer& displayPlugin, int index, bool active = false); +#endif void Application::initializeUi() { AddressBarDialog::registerType(); @@ -3024,12 +3040,13 @@ void Application::initializeUi() { tabletScriptingInterface->getTablet(SYSTEM_TABLET); } - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); connect(offscreenUi.data(), &hifi::qml::OffscreenSurface::rootContextCreated, this, &Application::onDesktopRootContextCreated); connect(offscreenUi.data(), &hifi::qml::OffscreenSurface::rootItemCreated, this, &Application::onDesktopRootItemCreated); +#if !defined(DISABLE_QML) offscreenUi->setProxyWindow(_window->windowHandle()); // OffscreenUi is a subclass of OffscreenQmlSurface specifically designed to // support the window management and scripting proxies for VR use @@ -3039,9 +3056,13 @@ void Application::initializeUi() { // FIXME either expose so that dialogs can set this themselves or // do better detection in the offscreen UI of what has focus offscreenUi->setNavigationFocused(false); +#else + _window->setMenuBar(new Menu()); +#endif setupPreferences(); +#if !defined(DISABLE_QML) _glWidget->installEventFilter(offscreenUi.data()); offscreenUi->setMouseTranslator([=](const QPointF& pt) { QPointF result = pt; @@ -3054,6 +3075,7 @@ void Application::initializeUi() { return result.toPoint(); }); offscreenUi->resume(); +#endif connect(_window, &MainWindow::windowGeometryChanged, [this](const QRect& r){ resizeGL(); if (_touchscreenVirtualPadDevice) { @@ -3092,6 +3114,7 @@ void Application::initializeUi() { } }); +#if !defined(DISABLE_QML) // Pre-create a couple of Web3D overlays to speed up tablet UI auto offscreenSurfaceCache = DependencyManager::get(); offscreenSurfaceCache->setOnRootContextCreated([&](const QString& rootObject, QQmlContext* surfaceContext) { @@ -3105,9 +3128,11 @@ void Application::initializeUi() { offscreenSurfaceCache->reserve(TabletScriptingInterface::QML, 1); offscreenSurfaceCache->reserve(Web3DOverlay::QML, 2); +#endif flushMenuUpdates(); +#if !defined(DISABLE_QML) // Now that the menu is instantiated, ensure the display plugin menu is properly updated { auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins(); @@ -3126,6 +3151,7 @@ void Application::initializeUi() { auto parent = getPrimaryMenu()->getMenu(MenuOption::OutputMenu); parent->addSeparator(); } +#endif // The display plugins are created before the menu now, so we need to do this here to hide the menu bar // now that it exists @@ -3230,12 +3256,12 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) { void Application::onDesktopRootItemCreated(QQuickItem* rootItem) { Stats::show(); AnimStats::show(); - auto surfaceContext = DependencyManager::get()->getSurfaceContext(); + auto surfaceContext = getOffscreenUI()->getSurfaceContext(); surfaceContext->setContextProperty("Stats", Stats::getInstance()); surfaceContext->setContextProperty("AnimStats", AnimStats::getInstance()); #if !defined(Q_OS_ANDROID) - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); auto qml = PathUtils::qmlUrl("AvatarInputsBar.qml"); offscreenUi->show(qml, "AvatarInputsBar"); #endif @@ -3418,7 +3444,7 @@ void Application::setPreferredCursor(const QString& cursorName) { void Application::setSettingConstrainToolbarPosition(bool setting) { _constrainToolbarPosition.set(setting); - DependencyManager::get()->setConstrainToolbarToCenterX(setting); + getOffscreenUI()->setConstrainToolbarToCenterX(setting); } void Application::setMiniTabletEnabled(bool enabled) { @@ -3512,7 +3538,9 @@ void Application::resizeGL() { _myCamera.loadViewFrustum(_viewFrustum); } - DependencyManager::get()->resize(fromGlm(displayPlugin->getRecommendedUiSize())); +#if !defined(DISABLE_QML) + getOffscreenUI()->resize(fromGlm(displayPlugin->getRecommendedUiSize())); +#endif } void Application::handleSandboxStatus(QNetworkReply* reply) { @@ -3912,10 +3940,12 @@ bool Application::eventFilter(QObject* object, QEvent* event) { } if (event->type() == QEvent::ShortcutOverride) { - if (DependencyManager::get()->shouldSwallowShortcut(event)) { +#if !defined(DISABLE_QML) + if (getOffscreenUI()->shouldSwallowShortcut(event)) { event->accept(); return true; } +#endif // Filter out captured keys before they're used for shortcut actions. if (_controllerScriptingInterface->isKeyCaptured(static_cast(event))) { @@ -3998,7 +4028,7 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_X: if (isShifted && isMeta) { - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); offscreenUi->togglePinned(); //offscreenUi->getSurfaceContext()->engine()->clearComponentCache(); //OffscreenUi::information("Debugging", "Component cache cleared"); @@ -4014,7 +4044,7 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_B: if (isMeta) { - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); offscreenUi->load("Browser.qml"); } else if (isOption) { controller::InputRecorder* inputRecorder = controller::InputRecorder::getInstance(); @@ -4036,7 +4066,7 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_R: if (isMeta && !event->isAutoRepeat()) { DependencyManager::get()->reloadAllScripts(); - DependencyManager::get()->clearCache(); + getOffscreenUI()->clearCache(); } break; @@ -4233,9 +4263,13 @@ void Application::mouseMoveEvent(QMouseEvent* event) { return; // bail } - auto offscreenUi = DependencyManager::get(); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); auto eventPosition = compositor.getMouseEventPosition(event); - QPointF transformedPos = offscreenUi->mapToVirtualScreen(eventPosition); + QPointF transformedPos = offscreenUi ? offscreenUi->mapToVirtualScreen(eventPosition) : QPointF(); +#else + QPointF transformedPos; +#endif auto button = event->button(); auto buttons = event->buttons(); // Determine if the ReticleClick Action is 1 and if so, fake include the LeftMouseButton @@ -4273,7 +4307,8 @@ void Application::mousePressEvent(QMouseEvent* event) { // Inhibit the menu if the user is using alt-mouse dragging _altPressed = false; - auto offscreenUi = DependencyManager::get(); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); // If we get a mouse press event it means it wasn't consumed by the offscreen UI, // hence, we should defocus all of the offscreen UI windows, in order to allow // keyboard shortcuts not to be swallowed by them. In particular, WebEngineViews @@ -4282,6 +4317,9 @@ void Application::mousePressEvent(QMouseEvent* event) { auto eventPosition = getApplicationCompositor().getMouseEventPosition(event); QPointF transformedPos = offscreenUi->mapToVirtualScreen(eventPosition); +#else + QPointF transformedPos; +#endif QMouseEvent mappedEvent(event->type(), transformedPos, event->screenPos(), event->button(), @@ -4318,9 +4356,13 @@ void Application::mousePressEvent(QMouseEvent* event) { } void Application::mouseDoublePressEvent(QMouseEvent* event) { - auto offscreenUi = DependencyManager::get(); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); auto eventPosition = getApplicationCompositor().getMouseEventPosition(event); QPointF transformedPos = offscreenUi->mapToVirtualScreen(eventPosition); +#else + QPointF transformedPos; +#endif QMouseEvent mappedEvent(event->type(), transformedPos, event->screenPos(), event->button(), @@ -4341,9 +4383,13 @@ void Application::mouseDoublePressEvent(QMouseEvent* event) { void Application::mouseReleaseEvent(QMouseEvent* event) { - auto offscreenUi = DependencyManager::get(); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); auto eventPosition = getApplicationCompositor().getMouseEventPosition(event); QPointF transformedPos = offscreenUi->mapToVirtualScreen(eventPosition); +#else + QPointF transformedPos; +#endif QMouseEvent mappedEvent(event->type(), transformedPos, event->screenPos(), event->button(), @@ -4739,7 +4785,8 @@ void Application::idle() { // Update the deadlock watchdog updateHeartbeat(); - auto offscreenUi = DependencyManager::get(); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); // These tasks need to be done on our first idle, because we don't want the showing of // overlay subwindows to do a showDesktop() until after the first time through @@ -4748,6 +4795,7 @@ void Application::idle() { firstIdle = false; connect(offscreenUi.data(), &OffscreenUi::showDesktop, this, &Application::showDesktop); } +#endif #ifdef Q_OS_WIN // If tracing is enabled then monitor the CPU in a separate thread @@ -4764,6 +4812,7 @@ void Application::idle() { #endif auto displayPlugin = getActiveDisplayPlugin(); +#if !defined(DISABLE_QML) if (displayPlugin) { auto uiSize = displayPlugin->getRecommendedUiSize(); // Bit of a hack since there's no device pixel ratio change event I can find. @@ -4772,6 +4821,7 @@ void Application::idle() { offscreenUi->resize(fromGlm(uiSize)); } } +#endif if (displayPlugin) { PROFILE_COUNTER_IF_CHANGED(app, "present", float, displayPlugin->presentRate()); @@ -4806,6 +4856,7 @@ void Application::idle() { float secondsSinceLastUpdate = (float)_lastTimeUpdated.nsecsElapsed() / NSECS_PER_MSEC / MSECS_PER_SECOND; _lastTimeUpdated.start(); +#if !defined(DISABLE_QML) // If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus. if (offscreenUi && offscreenUi->getWindow()) { auto activeFocusItem = offscreenUi->getWindow()->activeFocusItem(); @@ -4817,9 +4868,11 @@ void Application::idle() { _keyboardDeviceHasFocus = true; } } +#endif checkChangeCursor(); +#if !defined(DISABLE_QML) auto stats = Stats::getInstance(); if (stats) { stats->updateStats(); @@ -4828,6 +4881,7 @@ void Application::idle() { if (animStats) { animStats->updateStats(); } +#endif // Normally we check PipelineWarnings, but since idle will often take more than 10ms we only show these idle timing // details if we're in ExtraDebugging mode. However, the ::update() and its subcomponents will show their timing @@ -5163,7 +5217,9 @@ QVector Application::pasteEntities(float x, float y, float z) { void Application::init() { // Make sure Login state is up to date +#if !defined(DISABLE_QML) DependencyManager::get()->toggleLoginDialog(); +#endif if (!DISABLE_DEFERRED) { DependencyManager::get()->init(); } @@ -6702,8 +6758,9 @@ void Application::nodeActivated(SharedNodePointer node) { if (node->getType() == NodeType::AssetServer) { // asset server just connected - check if we have the asset browser showing - auto offscreenUi = DependencyManager::get(); - auto assetDialog = offscreenUi->getRootItem()->findChild("AssetServer"); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); + auto assetDialog = offscreenUi ? offscreenUi->getRootItem()->findChild("AssetServer") : nullptr; if (assetDialog) { auto nodeList = DependencyManager::get(); @@ -6716,6 +6773,7 @@ void Application::nodeActivated(SharedNodePointer node) { assetDialog->setVisible(false); } } +#endif } // If we get a new EntityServer activated, reset lastQueried time @@ -6773,13 +6831,15 @@ void Application::nodeKilled(SharedNodePointer node) { } else if (node->getType() == NodeType::AssetServer) { // asset server going away - check if we have the asset browser showing - auto offscreenUi = DependencyManager::get(); - auto assetDialog = offscreenUi->getRootItem()->findChild("AssetServer"); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); + auto assetDialog = offscreenUi ? offscreenUi->getRootItem()->findChild("AssetServer") : nullptr; if (assetDialog) { // call reload on the shown asset browser dialog QMetaObject::invokeMethod(assetDialog, "clear"); } +#endif } } @@ -6886,8 +6946,10 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe qScriptRegisterMetaType(scriptEngine.data(), RayToOverlayIntersectionResultToScriptValue, RayToOverlayIntersectionResultFromScriptValue); - scriptEngine->registerGlobalObject("OffscreenFlags", DependencyManager::get()->getFlags()); +#if !defined(DISABLE_QML) + scriptEngine->registerGlobalObject("OffscreenFlags", getOffscreenUI()->getFlags()); scriptEngine->registerGlobalObject("Desktop", DependencyManager::get().data()); +#endif qScriptRegisterMetaType(scriptEngine.data(), wrapperToScriptValue, wrapperFromScriptValue); qScriptRegisterMetaType(scriptEngine.data(), @@ -6913,14 +6975,16 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe bool clientScript = scriptEngine->isClientScript(); scriptEngine->registerFunction("OverlayWindow", clientScript ? QmlWindowClass::constructor : QmlWindowClass::restricted_constructor); -#if !defined(Q_OS_ANDROID) +#if !defined(Q_OS_ANDROID) && !defined(DISABLE_QML) scriptEngine->registerFunction("OverlayWebWindow", clientScript ? QmlWebWindowClass::constructor : QmlWebWindowClass::restricted_constructor); #endif scriptEngine->registerFunction("QmlFragment", clientScript ? QmlFragmentClass::constructor : QmlFragmentClass::restricted_constructor); scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("DesktopPreviewProvider", DependencyManager::get().data()); +#if !defined(DISABLE_QML) scriptEngine->registerGlobalObject("Stats", Stats::getInstance()); +#endif scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Snapshot", DependencyManager::get().data()); scriptEngine->registerGlobalObject("AudioStats", DependencyManager::get()->getStats().data()); @@ -7116,7 +7180,7 @@ bool Application::askToSetAvatarUrl(const QString& url) { qCDebug(interfaceapp) << "Declined to agree to avatar license"; } - //auto offscreenUi = DependencyManager::get(); + //auto offscreenUi = getOffscreenUI(); }); } else { setAvatar(url, modelName); @@ -7314,7 +7378,9 @@ void Application::showDialog(const QUrl& widgetUrl, const QUrl& tabletUrl, const toggleTabletUI(true); } } else { - DependencyManager::get()->show(widgetUrl, name); +#if !defined(DISABLE_QML) + getOffscreenUI()->show(widgetUrl, name); +#endif } } @@ -7339,10 +7405,10 @@ void Application::showAssetServerWidget(QString filePath) { auto tablet = dynamic_cast(tabletScriptingInterface->getTablet(SYSTEM_TABLET)); auto hmd = DependencyManager::get(); if (tablet->getToolbarMode()) { - DependencyManager::get()->show(url, "AssetServer", startUpload); + getOffscreenUI()->show(url, "AssetServer", startUpload); } else { if (!hmd->getShouldShowTablet() && !isHMDMode()) { - DependencyManager::get()->show(url, "AssetServer", startUpload); + getOffscreenUI()->show(url, "AssetServer", startUpload); } else { static const QUrl url("hifi/dialogs/TabletAssetServer.qml"); if (!tablet->isPathLoaded(url)) { @@ -7697,7 +7763,7 @@ void Application::addAssetToWorldInfo(QString modelName, QString infoText) { if (!_addAssetToWorldErrorTimer.isActive()) { if (!_addAssetToWorldMessageBox) { - _addAssetToWorldMessageBox = DependencyManager::get()->createMessageBox(OffscreenUi::ICON_INFORMATION, + _addAssetToWorldMessageBox = getOffscreenUI()->createMessageBox(OffscreenUi::ICON_INFORMATION, "Downloading Model", "", QMessageBox::NoButton, QMessageBox::NoButton); connect(_addAssetToWorldMessageBox, SIGNAL(destroyed()), this, SLOT(onAssetToWorldMessageBoxClosed())); } @@ -7780,7 +7846,7 @@ void Application::addAssetToWorldError(QString modelName, QString errorText) { addAssetToWorldInfoClear(modelName); if (!_addAssetToWorldMessageBox) { - _addAssetToWorldMessageBox = DependencyManager::get()->createMessageBox(OffscreenUi::ICON_INFORMATION, + _addAssetToWorldMessageBox = getOffscreenUI()->createMessageBox(OffscreenUi::ICON_INFORMATION, "Downloading Model", "", QMessageBox::NoButton, QMessageBox::NoButton); connect(_addAssetToWorldMessageBox, SIGNAL(destroyed()), this, SLOT(onAssetToWorldMessageBoxClosed())); } @@ -8274,6 +8340,8 @@ DisplayPluginPointer Application::getActiveDisplayPlugin() const { return _displayPlugin; } + +#if !defined(DISABLE_QML) static const char* EXCLUSION_GROUP_KEY = "exclusionGroup"; static void addDisplayPluginToMenu(const DisplayPluginPointer& displayPlugin, int index, bool active) { @@ -8314,6 +8382,7 @@ static void addDisplayPluginToMenu(const DisplayPluginPointer& displayPlugin, in action->setProperty(EXCLUSION_GROUP_KEY, QVariant::fromValue(displayPluginGroup)); Q_ASSERT(menu->menuItemExists(MenuOption::OutputMenu, name)); } +#endif void Application::updateDisplayMode() { // Unsafe to call this method from anything but the main thread @@ -8358,8 +8427,8 @@ void Application::setDisplayPlugin(DisplayPluginPointer newDisplayPlugin) { // instead emit a signal that the display plugin is changing and let // the desktop lock itself. Reduces coupling between the UI and display // plugins - auto offscreenUi = DependencyManager::get(); - auto desktop = offscreenUi->getDesktop(); + auto offscreenUi = getOffscreenUI(); + auto desktop = offscreenUi ? offscreenUi->getDesktop() : nullptr; auto menu = Menu::getInstance(); // Make the switch atomic from the perspective of other threads @@ -8405,7 +8474,9 @@ void Application::setDisplayPlugin(DisplayPluginPointer newDisplayPlugin) { } } - offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize())); + if (offscreenUi) { + offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize())); + } getApplicationCompositor().setDisplayPlugin(newDisplayPlugin); _displayPlugin = newDisplayPlugin; connect(_displayPlugin.get(), &DisplayPlugin::presented, this, &Application::onPresent, Qt::DirectConnection); diff --git a/interface/src/Application_render.cpp b/interface/src/Application_render.cpp index a87caeb9a8..646cc53cc0 100644 --- a/interface/src/Application_render.cpp +++ b/interface/src/Application_render.cpp @@ -156,12 +156,14 @@ void Application::paintGL() { renderArgs._blitFramebuffer.reset(); renderArgs._context->enableStereo(false); +#if !defined(DISABLE_QML) { auto stats = Stats::getInstance(); if (stats) { stats->setRenderDetails(renderArgs._details); } } +#endif uint64_t lastPaintDuration = usecTimestampNow() - lastPaintBegin; _frameTimingsScriptingInterface.addValue(lastPaintDuration); diff --git a/interface/src/ConnectionMonitor.cpp b/interface/src/ConnectionMonitor.cpp index e86061b090..33d9fddc1b 100644 --- a/interface/src/ConnectionMonitor.cpp +++ b/interface/src/ConnectionMonitor.cpp @@ -48,7 +48,9 @@ void ConnectionMonitor::init() { emit setRedirectErrorState(REDIRECT_HIFI_ADDRESS, "", 5); } else { qDebug() << "ConnectionMonitor: Showing connection failure window"; +#if !defined(DISABLE_QML) DependencyManager::get()->setDomainConnectionFailureVisibility(true); +#endif } }); } @@ -59,8 +61,10 @@ void ConnectionMonitor::startTimer() { void ConnectionMonitor::stopTimer() { _timer.stop(); +#if !defined(DISABLE_QML) bool enableInterstitial = DependencyManager::get()->getDomainHandler().getInterstitialModeEnabled(); if (!enableInterstitial) { DependencyManager::get()->setDomainConnectionFailureVisibility(false); } +#endif } diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 2fb40c8c30..26781631db 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -83,7 +83,9 @@ void ApplicationOverlay::renderOverlay(RenderArgs* renderArgs) { // Now render the overlay components together into a single texture renderDomainConnectionStatusBorder(renderArgs); // renders the connected domain line renderOverlays(renderArgs); // renders Scripts Overlay and AudioScope +#if !defined(DISABLE_QML) renderQmlUi(renderArgs); // renders a unit quad with the QML UI texture, and the text overlays from scripts +#endif }); renderArgs->_batch = nullptr; // so future users of renderArgs don't try to use our batch diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index da4fdaba44..8edd8ee3a5 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -74,6 +74,7 @@ void OverlayConductor::centerUI() { } void OverlayConductor::update(float dt) { +#if !defined(DISABLE_QML) auto offscreenUi = DependencyManager::get(); if (!offscreenUi) { return; @@ -115,4 +116,5 @@ void OverlayConductor::update(float dt) { if (shouldRecenter && !_suppressedByHead) { centerUI(); } +#endif } diff --git a/interface/src/ui/OverlayConductor.h b/interface/src/ui/OverlayConductor.h index b47e23d28a..6c3732cf3c 100644 --- a/interface/src/ui/OverlayConductor.h +++ b/interface/src/ui/OverlayConductor.h @@ -25,8 +25,10 @@ private: bool headOutsideOverlay() const; bool updateAvatarIsAtRest(); +#if !defined(DISABLE_QML) bool _suppressedByHead { false }; bool _hmdMode { false }; +#endif // used by updateAvatarIsAtRest uint64_t _desiredAtRestTimer { 0 }; diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 22b123c85d..17b0895f47 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -232,11 +232,15 @@ OverlayID Overlays::addOverlay(const QString& type, const QVariant& properties) */ if (type == ImageOverlay::TYPE) { +#if !defined(DISABLE_QML) thisOverlay = Overlay::Pointer(new ImageOverlay(), [](Overlay* ptr) { ptr->deleteLater(); }); +#endif } else if (type == Image3DOverlay::TYPE || type == "billboard") { // "billboard" for backwards compatibility thisOverlay = Overlay::Pointer(new Image3DOverlay(), [](Overlay* ptr) { ptr->deleteLater(); }); } else if (type == TextOverlay::TYPE) { +#if !defined(DISABLE_QML) thisOverlay = Overlay::Pointer(new TextOverlay(), [](Overlay* ptr) { ptr->deleteLater(); }); +#endif } else if (type == Text3DOverlay::TYPE) { thisOverlay = Overlay::Pointer(new Text3DOverlay(), [](Overlay* ptr) { ptr->deleteLater(); }); } else if (type == Shape3DOverlay::TYPE) { diff --git a/libraries/shared/src/DependencyManager.h b/libraries/shared/src/DependencyManager.h index da877f7b3b..978732fd50 100644 --- a/libraries/shared/src/DependencyManager.h +++ b/libraries/shared/src/DependencyManager.h @@ -27,16 +27,16 @@ class Dependency { public: typedef std::function DeleterFunction; - + protected: virtual ~Dependency() {} virtual void customDeleter() { _customDeleter(this); } - + void setCustomDeleter(DeleterFunction customDeleter) { _customDeleter = customDeleter; } DeleterFunction _customDeleter = [](Dependency* pointer) { delete pointer; }; - + friend class DependencyManager; }; @@ -49,10 +49,10 @@ class DependencyManager { public: template static QSharedPointer get(); - + template static bool isSet(); - + template static QSharedPointer set(Args&&... args); @@ -61,10 +61,10 @@ public: template static void destroy(); - + template static void registerInheritance(); - + template static size_t typeHash() { #ifdef Q_OS_ANDROID @@ -79,9 +79,9 @@ private: template size_t getHashCode(); - + QSharedPointer& safeGet(size_t hashCode); - + QHash> _instanceHash; QHash _inheritanceHash; }; @@ -90,15 +90,17 @@ template QSharedPointer DependencyManager::get() { static size_t hashCode = manager().getHashCode(); static QWeakPointer instance; - + if (instance.isNull()) { instance = qSharedPointerCast(manager().safeGet(hashCode)); - + +#ifndef QT_NO_DEBUG if (instance.isNull()) { qWarning() << "DependencyManager::get(): No instance available for" << typeid(T).name(); } +#endif } - + return instance.toStrongRef(); } @@ -159,12 +161,12 @@ template size_t DependencyManager::getHashCode() { size_t hashCode = typeHash(); auto derivedHashCode = _inheritanceHash.find(hashCode); - + while (derivedHashCode != _inheritanceHash.end()) { hashCode = derivedHashCode.value(); derivedHashCode = _inheritanceHash.find(hashCode); } - + return hashCode; } diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index 0aad297587..a13bdf0657 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -616,7 +616,9 @@ bool OffscreenUi::navigationFocused() { } void OffscreenUi::setNavigationFocused(bool focused) { - offscreenFlags->setNavigationFocused(focused); + if (offscreenFlags) { + offscreenFlags->setNavigationFocused(focused); + } } // FIXME HACK.... diff --git a/libraries/ui/src/ui/Menu.cpp b/libraries/ui/src/ui/Menu.cpp index 848b2362ee..b3b76ab534 100644 --- a/libraries/ui/src/ui/Menu.cpp +++ b/libraries/ui/src/ui/Menu.cpp @@ -422,9 +422,11 @@ void Menu::removeMenu(const QString& menuName) { } else { QMenuBar::removeAction(action); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->removeAction(action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->removeAction(action); + }); + } } QMenuBar::repaint(); @@ -532,9 +534,11 @@ void Menu::setGroupingIsVisible(const QString& grouping, bool isVisible) { MenuWrapper::MenuWrapper(ui::Menu& rootMenu, QMenu* menu) : _rootMenu(rootMenu), _realMenu(menu) { auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->addMenu(menu); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->addMenu(menu); + }); + } _rootMenu._backMap[menu] = this; } @@ -553,50 +557,62 @@ void MenuWrapper::setEnabled(bool enabled) { QAction* MenuWrapper::addSeparator() { QAction* action = _realMenu->addSeparator(); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->addSeparator(_realMenu); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->addSeparator(_realMenu); + }); + } return action; } void MenuWrapper::addAction(QAction* action) { _realMenu->addAction(action); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->addAction(_realMenu, action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->addAction(_realMenu, action); + }); + } } QAction* MenuWrapper::addAction(const QString& menuName) { QAction* action = _realMenu->addAction(menuName); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->addAction(_realMenu, action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->addAction(_realMenu, action); + }); + } return action; } QAction* MenuWrapper::addAction(const QString& menuName, const QObject* receiver, const char* member, const QKeySequence& shortcut) { QAction* action = _realMenu->addAction(menuName, receiver, member, shortcut); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->addAction(_realMenu, action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->addAction(_realMenu, action); + }); + } return action; } void MenuWrapper::removeAction(QAction* action) { _realMenu->removeAction(action); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->removeAction(action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->removeAction(action); + }); + } } void MenuWrapper::insertAction(QAction* before, QAction* action) { _realMenu->insertAction(before, action); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->insertAction(before, action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->insertAction(before, action); + }); + } } diff --git a/libraries/ui/src/ui/TabletScriptingInterface.cpp b/libraries/ui/src/ui/TabletScriptingInterface.cpp index 8fc2d069ec..13b0498e76 100644 --- a/libraries/ui/src/ui/TabletScriptingInterface.cpp +++ b/libraries/ui/src/ui/TabletScriptingInterface.cpp @@ -366,6 +366,7 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { auto offscreenUi = DependencyManager::get(); if (toolbarMode) { +#if !defined(DISABLE_QML) // create new desktop window auto tabletRootWindow = new TabletRootWindow(); tabletRootWindow->initQml(QVariantMap()); @@ -379,6 +380,7 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { // forward qml surface events to interface js connect(tabletRootWindow, &QmlWindowClass::fromQml, this, &TabletProxy::fromQml); +#endif } else { if (_currentPathLoaded != TABLET_HOME_SOURCE_URL) { loadHomeScreen(true);