On Oculus Rift on/off, switch automatically to/from desktop mode
Showing the changes to interface/src/Application.cpp (1 of 8 files). Show all
Unified · Split
| @@ -247,6 +247,8 @@ static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStanda · 246 unmodified lines | ||
| 247 | 247 | Setting::Handle<int> maxOctreePacketsPerSecond("maxOctreePPS", DEFAULT_MAX_OCTREE_PPS); |
| 248 | 248 | |
| 249 | 249 | static const QString MARKETPLACE_CDN_HOSTNAME = "mpassets.highfidelity.com"; |
| 250 | +static const int INTERVAL_TO_CHECK_HMD_WORN_STATUS = 500; // milliseconds | |
| 251 | +static const QString DESKTOP_DISPLAY_PLUGIN_NAME = "Desktop"; | |
| 250 | 252 | |
| 251 | 253 | const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensions { |
| 252 | 254 | { SVO_EXTENSION, &Application::importSVOFromURL }, |
| @@ -1413,6 +1415,31 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 1160 unmodified lines | ||
| 1413 | 1415 | properties["active_display_plugin"] = getActiveDisplayPlugin()->getName(); |
| 1414 | 1416 | properties["using_hmd"] = isHMDMode(); |
| 1415 | 1417 | |
| 1418 | + _autoSwitchDisplayModeSupportedHMDPlugin = nullptr; | |
| 1419 | + foreach(DisplayPluginPointer displayPlugin, PluginManager::getInstance()->getDisplayPlugins()) { | |
| 1420 | + if (displayPlugin->isHmd() && | |
| 1421 | + displayPlugin->getSupportsAutoSwitch()) { | |
| 1422 | + _autoSwitchDisplayModeSupportedHMDPlugin = displayPlugin; | |
| 1423 | + _autoSwitchDisplayModeSupportedHMDPluginName = | |
| 1424 | + _autoSwitchDisplayModeSupportedHMDPlugin->getName(); | |
| 1425 | + _previousHMDWornStatus = | |
| 1426 | + _autoSwitchDisplayModeSupportedHMDPlugin->isDisplayVisible(); | |
| 1427 | + break; | |
| 1428 | + } | |
| 1429 | + } | |
| 1430 | + | |
| 1431 | + if (_autoSwitchDisplayModeSupportedHMDPlugin) { | |
| 1432 | + if (getActiveDisplayPlugin() != _autoSwitchDisplayModeSupportedHMDPlugin && | |
| 1433 | + !_autoSwitchDisplayModeSupportedHMDPlugin->isSessionActive()) { | |
| 1434 | + startHMDStandBySession(); | |
| 1435 | + } | |
| 1436 | + // Poll periodically to check whether the user has worn HMD or not. Switch Display mode accordingly. | |
| 1437 | + // If the user wears HMD then switch to VR mode. If the user removes HMD then switch to Desktop mode. | |
| 1438 | + QTimer* autoSwitchDisplayModeTimer = new QTimer(this); | |
| 1439 | + connect(autoSwitchDisplayModeTimer, SIGNAL(timeout()), this, SLOT(switchDisplayMode())); | |
| 1440 | + autoSwitchDisplayModeTimer->start(INTERVAL_TO_CHECK_HMD_WORN_STATUS); | |
| 1441 | + } | |
| 1442 | + | |
| 1416 | 1443 | auto glInfo = getGLContextData(); |
| 1417 | 1444 | properties["gl_info"] = glInfo; |
| 1418 | 1445 | properties["gpu_used_memory"] = (int)BYTES_TO_MB(gpu::Context::getUsedGPUMemSize()); |
| @@ -1646,7 +1673,10 @@ void Application::aboutToQuit() { · 227 unmodified lines | ||
| 1646 | 1673 | } |
| 1647 | 1674 | |
| 1648 | 1675 | getActiveDisplayPlugin()->deactivate(); |
| 1649 | − | |
| 1676 | + if (_autoSwitchDisplayModeSupportedHMDPlugin | |
| 1677 | + && _autoSwitchDisplayModeSupportedHMDPlugin->isSessionActive()) { | |
| 1678 | + _autoSwitchDisplayModeSupportedHMDPlugin->endSession(); | |
| 1679 | + } | |
| 1650 | 1680 | // use the CloseEventSender via a QThread to send an event that says the user asked for the app to close |
| 1651 | 1681 | auto closeEventSender = DependencyManager::get<CloseEventSender>(); |
| 1652 | 1682 | QThread* closureEventThread = new QThread(this); |
| @@ -6855,6 +6885,35 @@ void Application::updateDisplayMode() { · 5202 unmodified lines | ||
| 6855 | 6885 | Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); |
| 6856 | 6886 | } |
| 6857 | 6887 | |
| 6888 | +void Application::switchDisplayMode() { | |
| 6889 | + if (!_autoSwitchDisplayModeSupportedHMDPlugin) { | |
| 6890 | + return; | |
| 6891 | + } | |
| 6892 | + bool currentHMDWornStatus = _autoSwitchDisplayModeSupportedHMDPlugin->isDisplayVisible(); | |
| 6893 | + if (currentHMDWornStatus != _previousHMDWornStatus) { | |
| 6894 | + // Switch to respective mode as soon as currentHMDWornStatus changes | |
| 6895 | + if (currentHMDWornStatus) { | |
| 6896 | + qCDebug(interfaceapp) << "Switching from Desktop to HMD mode"; | |
| 6897 | + endHMDSession(); | |
| 6898 | + setActiveDisplayPlugin(_autoSwitchDisplayModeSupportedHMDPluginName); | |
| 6899 | + } else { | |
| 6900 | + qCDebug(interfaceapp) << "Switching from HMD to desktop mode"; | |
| 6901 | + setActiveDisplayPlugin(DESKTOP_DISPLAY_PLUGIN_NAME); | |
| 6902 | + startHMDStandBySession(); | |
| 6903 | + } | |
| 6904 | + emit activeDisplayPluginChanged(); | |
| 6905 | + } | |
| 6906 | + _previousHMDWornStatus = currentHMDWornStatus; | |
| 6907 | +} | |
| 6908 | + | |
| 6909 | +void Application::startHMDStandBySession() { | |
| 6910 | + _autoSwitchDisplayModeSupportedHMDPlugin->startStandBySession(); | |
| 6911 | +} | |
| 6912 | + | |
| 6913 | +void Application::endHMDSession() { | |
| 6914 | + _autoSwitchDisplayModeSupportedHMDPlugin->endSession(); | |
| 6915 | +} | |
| 6916 | + | |
| 6858 | 6917 | mat4 Application::getEyeProjection(int eye) const { |
| 6859 | 6918 | QMutexLocker viewLocker(&_viewMutex); |
| 6860 | 6919 | if (isHMDMode()) { |