diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 678f737f25..0e8c03e032 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -985,6 +985,7 @@ const bool DEFAULT_PREFER_STYLUS_OVER_LASER = false; const bool DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS = false; const QString DEFAULT_CURSOR_NAME = "DEFAULT"; const bool DEFAULT_MINI_TABLET_ENABLED = true; +const bool DEFAULT_AWAY_STATE_WHEN_FOCUS_LOST_IN_VR_ENABLED = true; QSharedPointer getOffscreenUI() { #if !defined(DISABLE_QML) @@ -1015,6 +1016,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _preferStylusOverLaserSetting("preferStylusOverLaser", DEFAULT_PREFER_STYLUS_OVER_LASER), _preferAvatarFingerOverStylusSetting("preferAvatarFingerOverStylus", DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS), _constrainToolbarPosition("toolbar/constrainToolbarToCenterX", true), + _awayStateWhenFocusLostInVREnabled("awayStateWhenFocusLostInVREnabled", DEFAULT_AWAY_STATE_WHEN_FOCUS_LOST_IN_VR_ENABLED), _preferredCursor("preferredCursor", DEFAULT_CURSOR_NAME), _miniTabletEnabledSetting("miniTabletEnabled", DEFAULT_MINI_TABLET_ENABLED), _scaleMirror(1.0f), @@ -3642,6 +3644,11 @@ void Application::setSettingConstrainToolbarPosition(bool setting) { getOffscreenUI()->setConstrainToolbarToCenterX(setting); } +void Application::setAwayStateWhenFocusLostInVREnabled(bool enabled) { + _awayStateWhenFocusLostInVREnabled.set(enabled); + emit awayStateWhenFocusLostInVRChanged(enabled); +} + void Application::setMiniTabletEnabled(bool enabled) { _miniTabletEnabledSetting.set(enabled); emit miniTabletEnabledChanged(enabled); diff --git a/interface/src/Application.h b/interface/src/Application.h index 373e2c16a2..e64101d2fd 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -241,6 +241,9 @@ public: float getSettingConstrainToolbarPosition() { return _constrainToolbarPosition.get(); } void setSettingConstrainToolbarPosition(bool setting); + float getAwayStateWhenFocusLostInVREnabled() { return _awayStateWhenFocusLostInVREnabled.get(); } + void setAwayStateWhenFocusLostInVREnabled(bool setting); + Q_INVOKABLE void setMinimumGPUTextureMemStabilityCount(int stabilityCount) { _minimumGPUTextureMemSizeStabilityCount = stabilityCount; } NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; } @@ -371,6 +374,7 @@ signals: void loginDialogFocusDisabled(); void miniTabletEnabledChanged(bool enabled); + void awayStateWhenFocusLostInVRChanged(bool enabled); public slots: QVector pasteEntities(float x, float y, float z); @@ -673,6 +677,7 @@ private: Setting::Handle _preferStylusOverLaserSetting; Setting::Handle _preferAvatarFingerOverStylusSetting; Setting::Handle _constrainToolbarPosition; + Setting::Handle _awayStateWhenFocusLostInVREnabled; Setting::Handle _preferredCursor; Setting::Handle _miniTabletEnabledSetting; Setting::Handle _keepLogWindowOnTop { "keepLogWindowOnTop", false }; diff --git a/interface/src/scripting/HMDScriptingInterface.cpp b/interface/src/scripting/HMDScriptingInterface.cpp index a365b84a15..baca6250d2 100644 --- a/interface/src/scripting/HMDScriptingInterface.cpp +++ b/interface/src/scripting/HMDScriptingInterface.cpp @@ -30,6 +30,9 @@ HMDScriptingInterface::HMDScriptingInterface() { connect(qApp, &Application::miniTabletEnabledChanged, [this](bool enabled) { emit miniTabletEnabledChanged(enabled); }); + connect(qApp, &Application::awayStateWhenFocusLostInVRChanged, [this](bool enabled) { + emit awayStateWhenFocusLostInVRChanged(enabled); + }); } glm::vec3 HMDScriptingInterface::calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction) const { @@ -137,6 +140,14 @@ bool HMDScriptingInterface::getMiniTabletEnabled() { return qApp->getMiniTabletEnabled(); } +void HMDScriptingInterface::setAwayStateWhenFocusLostInVREnabled(bool enabled) { + qApp->setAwayStateWhenFocusLostInVREnabled(enabled); +} + +bool HMDScriptingInterface::getAwayStateWhenFocusLostInVREnabled() { + return qApp->getAwayStateWhenFocusLostInVREnabled(); +} + QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine) { glm::vec3 hudIntersection; diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h index c6202d4105..335816bf7c 100644 --- a/interface/src/scripting/HMDScriptingInterface.h +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -375,6 +375,14 @@ signals: */ bool miniTabletEnabledChanged(bool enabled); + /**jsdoc + * Triggered when the altering the mode for going into an away state when the interface focus is lost in VR. + * @function HMD.awayStateWhenFocusLostInVRChanged + * @param {boolean} enabled - true if the setting to go into an away state in VR when the interface focus is lost is enabled, otherwise false. + * @returns {Signal} + */ + bool awayStateWhenFocusLostInVRChanged(bool enabled); + public: HMDScriptingInterface(); @@ -423,6 +431,9 @@ public: void setMiniTabletEnabled(bool enabled); bool getMiniTabletEnabled(); + void setAwayStateWhenFocusLostInVREnabled(bool enabled); + bool getAwayStateWhenFocusLostInVREnabled(); + QVariant getPlayAreaRect(); QVector getSensorPositions(); diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 6a2516115d..fb7b0ef993 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -111,6 +111,12 @@ void setupPreferences() { auto setter = [](bool value) { qApp->setSettingConstrainToolbarPosition(value); }; preferences->addPreference(new CheckPreference(UI_CATEGORY, "Constrain Toolbar Position to Horizontal Center", getter, setter)); } + + { + auto getter = []()->bool { return qApp->getAwayStateWhenFocusLostInVREnabled(); }; + auto setter = [](bool value) { qApp->setAwayStateWhenFocusLostInVREnabled(value); }; + preferences->addPreference(new CheckPreference(UI_CATEGORY, "Go into away state when interface window loses focus in VR", getter, setter)); + } { auto getter = []()->float { return qApp->getDesktopTabletScale(); }; diff --git a/scripts/system/away.js b/scripts/system/away.js index 5180588e9d..6293c0c452 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -67,6 +67,8 @@ var avatarPosition = MyAvatar.position; var wasHmdMounted = HMD.mounted; var previousBubbleState = Users.getIgnoreRadiusEnabled(); +var enterAwayStateWhenFocusLostInVR = HMD.enterAwayStateWhenFocusLostInVR; + // some intervals we may create/delete var avatarMovedInterval; @@ -283,8 +285,10 @@ function maybeGoAway() { if (Reticle.mouseCaptured !== wasMouseCaptured) { wasMouseCaptured = !wasMouseCaptured; if (!wasMouseCaptured) { - goAway(); - return; + if (enterAwayStateWhenFocusLostInVR) { + goAway(); + return; + } } } @@ -357,9 +361,14 @@ eventMapping.from(Controller.Standard.Back).peek().to(goActive); eventMapping.from(Controller.Standard.Start).peek().to(goActive); Controller.enableMapping(eventMappingName); +function awayStateWhenFocusLostInVRChanged(enabled) { + enterAwayStateWhenFocusLostInVR = enabled; +} + Script.scriptEnding.connect(function () { Script.clearInterval(maybeIntervalTimer); goActive(); + HMD.awayStateWhenFocusLostInVRChanged.disconnect(awayStateWhenFocusLostInVRChanged); Controller.disableMapping(eventMappingName); Controller.mousePressEvent.disconnect(goActive); Controller.keyPressEvent.disconnect(maybeGoActive); @@ -367,6 +376,8 @@ Script.scriptEnding.connect(function () { Messages.unsubscribe(CHANNEL_AWAY_ENABLE); }); +HMD.awayStateWhenFocusLostInVRChanged.connect(awayStateWhenFocusLostInVRChanged); + if (HMD.active && !HMD.mounted) { print("Starting script, while HMD is active and not mounted..."); goAway(true);