Add option to disable triggering an away state when interface

focus is lost.
This commit is contained in:
Saracen 2019-03-31 17:54:01 +01:00
parent 6ccf16dfe5
commit 90e979bda7
6 changed files with 53 additions and 2 deletions

View file

@ -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<OffscreenUi> 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);

View file

@ -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<EntityItemID> pasteEntities(float x, float y, float z);
@ -660,6 +664,7 @@ private:
Setting::Handle<bool> _preferStylusOverLaserSetting;
Setting::Handle<bool> _preferAvatarFingerOverStylusSetting;
Setting::Handle<bool> _constrainToolbarPosition;
Setting::Handle<bool> _awayStateWhenFocusLostInVREnabled;
Setting::Handle<QString> _preferredCursor;
Setting::Handle<bool> _miniTabletEnabledSetting;
Setting::Handle<bool> _keepLogWindowOnTop { "keepLogWindowOnTop", false };

View file

@ -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;

View file

@ -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 - <code>true</code> if the setting to go into an away state in VR when the interface focus is lost is enabled, otherwise <code>false</code>.
* @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<glm::vec3> getSensorPositions();

View file

@ -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(); };

View file

@ -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);