diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 47f3b774b2..4be42256a5 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -962,6 +962,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) @@ -992,6 +993,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), @@ -3562,6 +3564,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 762ac9585a..226b18b202 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -236,6 +236,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; } @@ -357,6 +360,7 @@ signals: void loginDialogFocusDisabled(); void miniTabletEnabledChanged(bool enabled); + void awayStateWhenFocusLostInVRChanged(bool enabled); public slots: QVector pasteEntities(float x, float y, float z); @@ -660,6 +664,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 d41e8951a2..2233ab46c2 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(); static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine); @@ -411,6 +419,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 dbd24573ee..fe5849f375 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -89,6 +89,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 2af43b2055..2e4a5d507e 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; + } } } @@ -349,9 +353,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); @@ -359,6 +368,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);