From 5f34d04596cd86044818c8fdeff561ed6ea80301 Mon Sep 17 00:00:00 2001 From: rampa3 <68955305+rampa3@users.noreply.github.com> Date: Tue, 6 Jun 2023 22:27:44 +0200 Subject: [PATCH 01/16] Added initial mouse look script Added initial WIP implementation of mouse look script. --- .../system/controllers/controllerScripts.js | 1 + scripts/system/controllers/mouseLook.js | 85 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 scripts/system/controllers/mouseLook.js diff --git a/scripts/system/controllers/controllerScripts.js b/scripts/system/controllers/controllerScripts.js index de185e3fe0a..088b0fae672 100644 --- a/scripts/system/controllers/controllerScripts.js +++ b/scripts/system/controllers/controllerScripts.js @@ -19,6 +19,7 @@ var CONTOLLER_SCRIPTS = [ "grab.js", "toggleAdvancedMovementForHandControllers.js", "handTouch.js", + "mouseLook.js", "controllerModules/nearParentGrabOverlay.js", "controllerModules/stylusInput.js", "controllerModules/equipEntity.js", diff --git a/scripts/system/controllers/mouseLook.js b/scripts/system/controllers/mouseLook.js new file mode 100644 index 00000000000..33901eb9e0a --- /dev/null +++ b/scripts/system/controllers/mouseLook.js @@ -0,0 +1,85 @@ +/* +mouseLook.js – mouse look switching script +by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) +*/ +(function() { // BEGIN LOCAL_SCOPE + + var oldMode; + + var mouseLookEnabled = false; + + mouseLookOn(); + + Controller.keyPressEvent.connect(function(event) { + if (event.text === 'm') { + if (mouseLookEnabled) { + if (!Camera.getCaptureMouse()){ + Window.displayAnnouncement("Mouse look: ON"); + mouseLookOn(); + } else { + Window.displayAnnouncement("Mouse look: TEMPORARILY OFF"); + mouseLookOff(); + } + } + } + if (event.text === 'M') { + if (!mouseLookEnabled){ + Window.displayAnnouncement("Mouse look: ENABLED") + mouseLookEnabled = true; + mouseLookOn(); + } else { + Window.displayAnnouncement("Mouse look: DISABLED") + mouseLookEnabled = false; + mouseLookOff(); + } + } + }); + + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + tablet.tabletShownChanged.connect(function () { + if (!tablet.toolbarMode) { + if (tablet.tabletShown) { + Window.displayAnnouncement("Tablet is up – mouse look temporarily off."); + mouseLookOff(); + + } else if (!tablet.tabletShown) { + Window.displayAnnouncement("Tablet hidden – mouse look on."); + mouseLookOn(); + } + } + }); + + MyAvatar.wentAway.connect(function () { + Window.displayAnnouncement("Away state ON – mouse look temporarily off.") + mouseLookOff() + }); + + MyAvatar.wentActive.connect(function () { + Window.displayAnnouncement("Away state OFF – mouse look on."); + mouseLookOn(); + }); + + function mouseLookOn() { + oldMode = Camera.mode; + Camera.mode = "first person"; + Camera.captureMouse = true; + } + + function mouseLookOff() { + Camera.captureMouse = false; + Camera.mode = oldMode; + } + + function onCameraModeUpdated(newMode) { + if (Camera.getCaptureMouse()){ + Camera.captureMouse = false; + } + } + + Camera.modeUpdated.connect(onCameraModeUpdated); + + Script.scriptEnding.connect(function() { + Camera.captureMouse = false; + }); + +}()); // END LOCAL_SCOPE \ No newline at end of file From 3daab28245ce0e3f76a62b528307881d1920baa2 Mon Sep 17 00:00:00 2001 From: rampa3 <68955305+rampa3@users.noreply.github.com> Date: Tue, 6 Jun 2023 22:49:04 +0200 Subject: [PATCH 02/16] Added before forgotten condition to check if mouse look is enabled by default before auto-starting it. --- scripts/system/controllers/mouseLook.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/system/controllers/mouseLook.js b/scripts/system/controllers/mouseLook.js index 33901eb9e0a..a8126a8e696 100644 --- a/scripts/system/controllers/mouseLook.js +++ b/scripts/system/controllers/mouseLook.js @@ -7,8 +7,10 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) var oldMode; var mouseLookEnabled = false; - - mouseLookOn(); + + if (mouseLookEnabled) { + mouseLookOn(); + } Controller.keyPressEvent.connect(function(event) { if (event.text === 'm') { From a824fe01e0ed7858a83f67394602434b8b956d1b Mon Sep 17 00:00:00 2001 From: rampa3 <68955305+rampa3@users.noreply.github.com> Date: Tue, 6 Jun 2023 23:58:13 +0200 Subject: [PATCH 03/16] Minor rewrite to make script clean up properly on exit, and added conditions to fix misbehavior in situation of going away with open tablet. --- scripts/system/controllers/mouseLook.js | 88 ++++++++++++++++++------- 1 file changed, 64 insertions(+), 24 deletions(-) diff --git a/scripts/system/controllers/mouseLook.js b/scripts/system/controllers/mouseLook.js index a8126a8e696..0e37144e125 100644 --- a/scripts/system/controllers/mouseLook.js +++ b/scripts/system/controllers/mouseLook.js @@ -6,13 +6,23 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) var oldMode; + var tabletUp; + + var away; + var mouseLookEnabled = false; + + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); if (mouseLookEnabled) { - mouseLookOn(); + if (!tablet.tabletShown){ + mouseLookOn(); + } } - Controller.keyPressEvent.connect(function(event) { + Controller.keyPressEvent.connect(onKeyPressEvent); + + function onKeyPressEvent(event) { if (event.text === 'm') { if (mouseLookEnabled) { if (!Camera.getCaptureMouse()){ @@ -35,31 +45,53 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) mouseLookOff(); } } - }); + } - var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); - tablet.tabletShownChanged.connect(function () { - if (!tablet.toolbarMode) { - if (tablet.tabletShown) { - Window.displayAnnouncement("Tablet is up – mouse look temporarily off."); - mouseLookOff(); - - } else if (!tablet.tabletShown) { - Window.displayAnnouncement("Tablet hidden – mouse look on."); - mouseLookOn(); + tablet.tabletShownChanged.connect(onTabletShownChanged); + + function onTabletShownChanged() { + if (mouseLookEnabled) { + if (!tablet.toolbarMode) { + if (tablet.tabletShown) { + tabletUp = true; + if (!away) { + Window.displayAnnouncement("Tablet is up – mouse look temporarily off."); + mouseLookOff(); + } + } else if (!tablet.tabletShown) { + tabletUp = false; + if (!away) { + Window.displayAnnouncement("Tablet hidden – mouse look on."); + mouseLookOn(); + } + } } } - }); + } - MyAvatar.wentAway.connect(function () { - Window.displayAnnouncement("Away state ON – mouse look temporarily off.") - mouseLookOff() - }); + MyAvatar.wentAway.connect(onWentAway); - MyAvatar.wentActive.connect(function () { - Window.displayAnnouncement("Away state OFF – mouse look on."); - mouseLookOn(); - }); + function onWentAway() { + if (mouseLookEnabled) { + away = true; + if (!tabletUp){ + Window.displayAnnouncement("Away state ON – mouse look temporarily off.") + mouseLookOff() + } + } + } + + MyAvatar.wentActive.connect(onWentActive); + + function onWentActive() { + if (mouseLookEnabled) { + away = false; + if (!tabletUp) { + Window.displayAnnouncement("Away state OFF – mouse look on."); + mouseLookOn(); + } + } + } function mouseLookOn() { oldMode = Camera.mode; @@ -80,8 +112,16 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) Camera.modeUpdated.connect(onCameraModeUpdated); - Script.scriptEnding.connect(function() { + Script.scriptEnding.connect(onScriptEnding); + + function onScriptEnding() { Camera.captureMouse = false; - }); + Controller.keyPressEvent.disconnect(onKeyPressEvent); + tablet.tabletShownChanged.disconnect(onTabletShownChanged); + MyAvatar.wentAway.disconnect(onWentAway); + MyAvatar.wentActive.disconnect(onWentActive); + Camera.modeUpdated.disconnect(onCameraModeUpdated); + Script.scriptEnding.disconnect(); + } }()); // END LOCAL_SCOPE \ No newline at end of file From 5d7c9c1cbbe2bb572b4ab8a28c995884a1cbbbe2 Mon Sep 17 00:00:00 2001 From: rampa3 <68955305+rampa3@users.noreply.github.com> Date: Wed, 7 Jun 2023 01:04:21 +0200 Subject: [PATCH 04/16] Added check for if user is in VR and made temporary mouse look disable persist over opening tablet. It will stay disabled until re-enabled manually, or will self reset after cycling away state or taking off VR headset. --- scripts/system/controllers/mouseLook.js | 138 ++++++++++++++++-------- 1 file changed, 92 insertions(+), 46 deletions(-) diff --git a/scripts/system/controllers/mouseLook.js b/scripts/system/controllers/mouseLook.js index 0e37144e125..c4790dd87c0 100644 --- a/scripts/system/controllers/mouseLook.js +++ b/scripts/system/controllers/mouseLook.js @@ -4,65 +4,87 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) */ (function() { // BEGIN LOCAL_SCOPE - var oldMode; - - var tabletUp; - var away; + var hmd; + var mouseLookEnabled = false; + var oldMode; + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + + var tabletUp; + + var tempOff = false; - if (mouseLookEnabled) { - if (!tablet.tabletShown){ - mouseLookOn(); + hmd = AvatarInputs.isHMD; + + if (!hmd){ + if (mouseLookEnabled) { + if (!tablet.tabletShown){ + Window.displayAnnouncement("Mouse look: ON"); + mouseLookOn(); + } else { + Window.displayAnnouncement("Tablet is up – mouse look temporarily off."); + } } } Controller.keyPressEvent.connect(onKeyPressEvent); function onKeyPressEvent(event) { - if (event.text === 'm') { - if (mouseLookEnabled) { - if (!Camera.getCaptureMouse()){ - Window.displayAnnouncement("Mouse look: ON"); + if (!hmd){ + if (event.text === 'm') { + if (mouseLookEnabled) { + if (!Camera.getCaptureMouse()){ + tempOff = false; + Window.displayAnnouncement("Mouse look: ON"); + mouseLookOn(); + } else { + tempOff = true; + Window.displayAnnouncement("Mouse look: TEMPORARILY OFF"); + mouseLookOff(); + } + } + } + if (event.text === 'M') { + if (!mouseLookEnabled){ + Window.displayAnnouncement("Mouse look: ENABLED") + mouseLookEnabled = true; mouseLookOn(); } else { - Window.displayAnnouncement("Mouse look: TEMPORARILY OFF"); + Window.displayAnnouncement("Mouse look: DISABLED") + mouseLookEnabled = false; + tempOff = false; mouseLookOff(); } } } - if (event.text === 'M') { - if (!mouseLookEnabled){ - Window.displayAnnouncement("Mouse look: ENABLED") - mouseLookEnabled = true; - mouseLookOn(); - } else { - Window.displayAnnouncement("Mouse look: DISABLED") - mouseLookEnabled = false; - mouseLookOff(); - } - } } tablet.tabletShownChanged.connect(onTabletShownChanged); function onTabletShownChanged() { - if (mouseLookEnabled) { - if (!tablet.toolbarMode) { - if (tablet.tabletShown) { - tabletUp = true; - if (!away) { - Window.displayAnnouncement("Tablet is up – mouse look temporarily off."); - mouseLookOff(); - } - } else if (!tablet.tabletShown) { - tabletUp = false; - if (!away) { - Window.displayAnnouncement("Tablet hidden – mouse look on."); - mouseLookOn(); + if (!hmd) { + if (mouseLookEnabled) { + if (!tablet.toolbarMode) { + if (tablet.tabletShown) { + tabletUp = true; + if (!tempOff) { + if (!away) { + Window.displayAnnouncement("Tablet is up – mouse look temporarily off."); + mouseLookOff(); + } + } + } else if (!tablet.tabletShown) { + tabletUp = false; + if (!tempOff) { + if (!away) { + Window.displayAnnouncement("Tablet hidden – mouse look on."); + mouseLookOn(); + } + } } } } @@ -72,11 +94,14 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) MyAvatar.wentAway.connect(onWentAway); function onWentAway() { - if (mouseLookEnabled) { - away = true; - if (!tabletUp){ - Window.displayAnnouncement("Away state ON – mouse look temporarily off.") - mouseLookOff() + if (!hmd) { + if (mouseLookEnabled) { + away = true; + if (!tabletUp){ + Window.displayAnnouncement("Away state ON – mouse look temporarily off.") + tempOff = false; + mouseLookOff() + } } } } @@ -84,11 +109,31 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) MyAvatar.wentActive.connect(onWentActive); function onWentActive() { + if (!hmd) { + if (mouseLookEnabled) { + away = false; + if (!tabletUp) { + Window.displayAnnouncement("Away state OFF – mouse look on."); + mouseLookOn(); + } + } + } + } + + AvatarInputs.isHMDChanged.connect(onIsHMDChanged); + + function onIsHMDChanged() { if (mouseLookEnabled) { - away = false; - if (!tabletUp) { - Window.displayAnnouncement("Away state OFF – mouse look on."); - mouseLookOn(); + if (AvatarInputs.isHMD) { + hmd = true; + mouseLookOff(); + } else { + hmd = false; + if (!tempOff) { + if (!tabletUp) { + mouseLookOn(); + } + } } } } @@ -120,8 +165,9 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) tablet.tabletShownChanged.disconnect(onTabletShownChanged); MyAvatar.wentAway.disconnect(onWentAway); MyAvatar.wentActive.disconnect(onWentActive); + AvatarInputs.isHMDChanged.disconnect(onIsHMDChanged); Camera.modeUpdated.disconnect(onCameraModeUpdated); - Script.scriptEnding.disconnect(); + Script.scriptEnding.disconnect(onScriptEnding); } }()); // END LOCAL_SCOPE \ No newline at end of file From e6f2ba65fd94545df6b18c821cb8558256fb47af Mon Sep 17 00:00:00 2001 From: rampa3 <68955305+rampa3@users.noreply.github.com> Date: Mon, 12 Jun 2023 21:18:36 +0200 Subject: [PATCH 05/16] Updated the script to enable usage of mouselook with other camera modes. --- scripts/system/controllers/mouseLook.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/scripts/system/controllers/mouseLook.js b/scripts/system/controllers/mouseLook.js index c4790dd87c0..49af1fb20ff 100644 --- a/scripts/system/controllers/mouseLook.js +++ b/scripts/system/controllers/mouseLook.js @@ -10,14 +10,12 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) var mouseLookEnabled = false; - var oldMode; - var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var tabletUp; var tempOff = false; - + hmd = AvatarInputs.isHMD; if (!hmd){ @@ -139,20 +137,11 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) } function mouseLookOn() { - oldMode = Camera.mode; - Camera.mode = "first person"; Camera.captureMouse = true; } function mouseLookOff() { Camera.captureMouse = false; - Camera.mode = oldMode; - } - - function onCameraModeUpdated(newMode) { - if (Camera.getCaptureMouse()){ - Camera.captureMouse = false; - } } Camera.modeUpdated.connect(onCameraModeUpdated); From 98282d1255de8ddd6cd79dd6b758c3e323e8a7c9 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Tue, 20 Jun 2023 21:18:33 +0200 Subject: [PATCH 06/16] Add mouse look preference setting --- .../qml/hifi/tablet/ControllerSettings.qml | 2 +- interface/src/ui/PreferencesDialog.cpp | 7 ++++ libraries/shared/src/shared/Camera.cpp | 7 ++++ libraries/shared/src/shared/Camera.h | 32 +++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/interface/resources/qml/hifi/tablet/ControllerSettings.qml b/interface/resources/qml/hifi/tablet/ControllerSettings.qml index 28fea649c0d..492ec265d46 100644 --- a/interface/resources/qml/hifi/tablet/ControllerSettings.qml +++ b/interface/resources/qml/hifi/tablet/ControllerSettings.qml @@ -335,7 +335,7 @@ Item { anchors.fill: stackView id: controllerPrefereneces objectName: "TabletControllerPreferences" - showCategories: ["VR Movement", "Game Controller", "Sixense Controllers", "Perception Neuron", "Leap Motion", "Open Sound Control (OSC)"] + showCategories: ["Desktop Movement", "VR Movement", "Game Controller", "Sixense Controllers", "Perception Neuron", "Leap Motion", "Open Sound Control (OSC)"] categoryProperties: { "VR Movement" : { "User real-world height (meters)" : { "anchors.right" : "undefined" }, diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index dcd9ccb4093..9340f593919 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -343,6 +343,13 @@ void setupPreferences() { preferences->addPreference(preference); } + static const QString DESKTOP_MOVEMENT{ "Desktop Movement" }; + { + auto getter = []()->bool { return qApp->getCamera().getMouseLook(); }; + auto setter = [](bool value) { qApp->getCamera().setMouseLook(value); }; + auto preference = new CheckPreference(DESKTOP_MOVEMENT, "Mouse look (toggle with M key)", getter, setter); + preferences->addPreference(preference); + } static const QString VR_MOVEMENT{ "VR Movement" }; { auto getter = [myAvatar]()->bool { return myAvatar->getAllowTeleporting(); }; diff --git a/libraries/shared/src/shared/Camera.cpp b/libraries/shared/src/shared/Camera.cpp index 55ee69d08aa..287db4e752c 100644 --- a/libraries/shared/src/shared/Camera.cpp +++ b/libraries/shared/src/shared/Camera.cpp @@ -189,6 +189,13 @@ QString Camera::getModeString() const { return modeToString(_mode); } +void Camera::setMouseLook(bool mouseLook) { Setting::Handle{"MouseLookAllowed", false }.set(mouseLook); + if (!mouseLook) { + setCaptureMouse(false); + } + emit mouseLookChanged(mouseLook); +} + void Camera::lookAt(const glm::vec3& lookAt) { glm::vec3 up = IDENTITY_UP; glm::mat4 lookAtMatrix = glm::lookAt(_position, lookAt, up); diff --git a/libraries/shared/src/shared/Camera.h b/libraries/shared/src/shared/Camera.h index 7247eb16a60..1c3de2b8e95 100644 --- a/libraries/shared/src/shared/Camera.h +++ b/libraries/shared/src/shared/Camera.h @@ -15,6 +15,7 @@ #include "../GLMHelpers.h" #include "../RegisteredMetaTypes.h" #include "../ViewFrustum.h" +#include "../SettingHandle.h" enum CameraMode { @@ -130,6 +131,23 @@ public slots: */ void setCaptureMouse(bool captureMouse) { _captureMouse = captureMouse; emit captureMouseChanged(captureMouse); } + /*@jsdoc + * Gets the current mouse look setting state. + * @function Camera.getMouseLook + * @returns {boolean} true if the mouse look setting is enabled (mouse look can be toggled with M key in this + * mode), false if the mouse look setting is disabled. + */ + bool getMouseLook() const { return Setting::Handle{"MouseLookAllowed", false }.get(); } + + /*@jsdoc + * Sets the mouse look setting state. When true, the mouse look setting is enabled (mouse look can be toggled + * with M key in this mode). When false, the mouse behaves normally. + * @function Camera.setMouseLook + * @param {boolean} mouseLook - true to enable mouse look setting, false to disable mouse look + * setting. + */ + void setMouseLook(bool mouseLook); + /*@jsdoc * Gets the current camera sensitivity. * @function Camera.getSensitivity @@ -229,6 +247,20 @@ public slots: */ void captureMouseChanged(bool newCaptureMouse); + /*@jsdoc + * Triggered when mouse look setting changes. + * @function Camera.mouseLookChanged + * @param {boolean} mouseLookChanged - The new mouse look state. + * @returns {Signal} + * @example Report mouse look state changes. + * function onMouseLookChanged(newMouseLook) { + * print("The mouse look has changed to " + newMouseLook); + * } + * + * Camera.mouseLookChanged.connect(onMouseLookChanged); + */ + void mouseLookChanged(bool newMouseLook); + private: void recompose(); void decompose(); From 042e7293b92cfa666765c756787e9aea163f2bac Mon Sep 17 00:00:00 2001 From: rampa3 <68955305+rampa3@users.noreply.github.com> Date: Wed, 21 Jun 2023 19:11:56 +0200 Subject: [PATCH 07/16] Updated mouse look script to get setting value for enable/disable and tydied up some text formatting in the status notifications. --- scripts/system/controllers/mouseLook.js | 33 +++++++++++-------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/scripts/system/controllers/mouseLook.js b/scripts/system/controllers/mouseLook.js index 49af1fb20ff..9f23a8a5b60 100644 --- a/scripts/system/controllers/mouseLook.js +++ b/scripts/system/controllers/mouseLook.js @@ -8,7 +8,7 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) var hmd; - var mouseLookEnabled = false; + var mouseLookEnabled = Camera.getMouseLook; var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); @@ -18,13 +18,19 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) hmd = AvatarInputs.isHMD; + Camera.mouseLookChanged.connect(onMouseLookChanged); + + function onMouseLookChanged(newMouseLook) { + mouseLookEnabled = newMouseLook; + } + if (!hmd){ if (mouseLookEnabled) { if (!tablet.tabletShown){ Window.displayAnnouncement("Mouse look: ON"); mouseLookOn(); } else { - Window.displayAnnouncement("Tablet is up – mouse look temporarily off."); + Window.displayAnnouncement("Tablet is up – mouse look temporarily OFF."); } } } @@ -41,23 +47,11 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) mouseLookOn(); } else { tempOff = true; - Window.displayAnnouncement("Mouse look: TEMPORARILY OFF"); + Window.displayAnnouncement("Mouse look: Temporarily OFF"); mouseLookOff(); } } } - if (event.text === 'M') { - if (!mouseLookEnabled){ - Window.displayAnnouncement("Mouse look: ENABLED") - mouseLookEnabled = true; - mouseLookOn(); - } else { - Window.displayAnnouncement("Mouse look: DISABLED") - mouseLookEnabled = false; - tempOff = false; - mouseLookOff(); - } - } } } @@ -71,7 +65,7 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) tabletUp = true; if (!tempOff) { if (!away) { - Window.displayAnnouncement("Tablet is up – mouse look temporarily off."); + Window.displayAnnouncement("Tablet is up – mouse look temporarily OFF."); mouseLookOff(); } } @@ -79,7 +73,7 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) tabletUp = false; if (!tempOff) { if (!away) { - Window.displayAnnouncement("Tablet hidden – mouse look on."); + Window.displayAnnouncement("Tablet hidden – mouse look ON."); mouseLookOn(); } } @@ -96,7 +90,7 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) if (mouseLookEnabled) { away = true; if (!tabletUp){ - Window.displayAnnouncement("Away state ON – mouse look temporarily off.") + Window.displayAnnouncement("Away state ON – mouse look temporarily OFF.") tempOff = false; mouseLookOff() } @@ -111,7 +105,7 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) if (mouseLookEnabled) { away = false; if (!tabletUp) { - Window.displayAnnouncement("Away state OFF – mouse look on."); + Window.displayAnnouncement("Away state OFF – mouse look ON."); mouseLookOn(); } } @@ -150,6 +144,7 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) function onScriptEnding() { Camera.captureMouse = false; + Camera.mouseLookChanged.disconnect(onMouseLookChanged); Controller.keyPressEvent.disconnect(onKeyPressEvent); tablet.tabletShownChanged.disconnect(onTabletShownChanged); MyAvatar.wentAway.disconnect(onWentAway); From 3fe3284258d7f337acf086ff073212fdaf983c58 Mon Sep 17 00:00:00 2001 From: rampa3 <68955305+rampa3@users.noreply.github.com> Date: Wed, 21 Jun 2023 23:41:34 +0200 Subject: [PATCH 08/16] Fixed missing brackets on setting getter. --- scripts/system/controllers/mouseLook.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/controllers/mouseLook.js b/scripts/system/controllers/mouseLook.js index 9f23a8a5b60..18113a8c87c 100644 --- a/scripts/system/controllers/mouseLook.js +++ b/scripts/system/controllers/mouseLook.js @@ -8,7 +8,7 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) var hmd; - var mouseLookEnabled = Camera.getMouseLook; + var mouseLookEnabled = Camera.getMouseLook(); var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); From 89f826fa5ca1d4167f2cc2c577dbdc65cb726332 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sun, 25 Jun 2023 12:12:51 +0200 Subject: [PATCH 09/16] Fix disabling mouse look when switching to VR mode --- scripts/system/controllers/mouseLook.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/scripts/system/controllers/mouseLook.js b/scripts/system/controllers/mouseLook.js index 18113a8c87c..ad5c1b6fb15 100644 --- a/scripts/system/controllers/mouseLook.js +++ b/scripts/system/controllers/mouseLook.js @@ -6,7 +6,7 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) var away; - var hmd; + var hmd = HMD.active; var mouseLookEnabled = Camera.getMouseLook(); @@ -16,8 +16,6 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) var tempOff = false; - hmd = AvatarInputs.isHMD; - Camera.mouseLookChanged.connect(onMouseLookChanged); function onMouseLookChanged(newMouseLook) { @@ -112,11 +110,11 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) } } - AvatarInputs.isHMDChanged.connect(onIsHMDChanged); + HMD.displayModeChanged.connect(onDisplayModeChanged); - function onIsHMDChanged() { + function onDisplayModeChanged() { if (mouseLookEnabled) { - if (AvatarInputs.isHMD) { + if (HMD.active) { hmd = true; mouseLookOff(); } else { @@ -149,7 +147,7 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) tablet.tabletShownChanged.disconnect(onTabletShownChanged); MyAvatar.wentAway.disconnect(onWentAway); MyAvatar.wentActive.disconnect(onWentActive); - AvatarInputs.isHMDChanged.disconnect(onIsHMDChanged); + HMD.displayModeChanged.disconnect(onDisplayModeChanged); Camera.modeUpdated.disconnect(onCameraModeUpdated); Script.scriptEnding.disconnect(onScriptEnding); } From 3d4a993476736fc308573e9aafd9a5bd3a5a1a96 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Thu, 24 Aug 2023 21:01:36 +0200 Subject: [PATCH 10/16] API changes for detecting active Window --- interface/src/Application.cpp | 16 ++++++++++++++++ .../src/scripting/DesktopScriptingInterface.h | 9 +++++++++ interface/src/ui/LoginDialog.cpp | 2 ++ 3 files changed, 27 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 10574f330d4..a4d9b15eff0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -868,6 +868,22 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, b DependencyManager::set(); #if !defined(DISABLE_QML) DependencyManager::set(); + { + auto window = DependencyManager::get()->getWindow(); + auto desktopScriptingInterface = DependencyManager::get(); + QObject::connect(window, &QQuickWindow::focusObjectChanged, [desktopScriptingInterface](QObject *object) { + if (object) { + if (object->objectName() == QString("desktop")) { + emit desktopScriptingInterface->uiFocusChanged(false); + return; + } + // Signal with empty object name happens in addition to regular named ones and is not necessary here + if (!object->objectName().isEmpty()) { + emit desktopScriptingInterface->uiFocusChanged(true); + } + } + }); + } #endif DependencyManager::set(); DependencyManager::set(); diff --git a/interface/src/scripting/DesktopScriptingInterface.h b/interface/src/scripting/DesktopScriptingInterface.h index 0f30b140fcc..db52906cfd7 100644 --- a/interface/src/scripting/DesktopScriptingInterface.h +++ b/interface/src/scripting/DesktopScriptingInterface.h @@ -104,6 +104,15 @@ class DesktopScriptingInterface : public QObject, public Dependency { int getWidth(); int getHeight(); +signals: + + /*@jsdoc + * Triggered when keyboard focus changes to another overlay UI window. + * @param {boolean} isActive - true if the keyboard focus is on overlay UI window, false if not. + * @function Desktop.uiFocusChanged + * @returns {Signal} + */ + void uiFocusChanged(bool isActive); private: static int flagAlwaysOnTop() { return AlwaysOnTop; } diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index 7dd5ac303d7..5dcbebab45f 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -33,6 +33,7 @@ #include "Application.h" #include "scripting/HMDScriptingInterface.h" #include "Constants.h" +#include "scripting/DesktopScriptingInterface.h" HIFI_QML_DEF(LoginDialog) @@ -67,6 +68,7 @@ void LoginDialog::showWithSelection() { auto hmd = DependencyManager::get(); if (!qApp->isHMDMode()) { + emit DependencyManager::get()->uiFocusChanged(true); if (qApp->getLoginDialogPoppedUp()) { LoginDialog::show(); return; From 025f530db623f62136e1d07abbcd9a04b62da4e8 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sun, 27 Aug 2023 22:06:03 +0200 Subject: [PATCH 11/16] Added an API function to check if an overlay has keyboard focus --- interface/src/scripting/DesktopScriptingInterface.cpp | 4 +++- interface/src/scripting/DesktopScriptingInterface.h | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/interface/src/scripting/DesktopScriptingInterface.cpp b/interface/src/scripting/DesktopScriptingInterface.cpp index ffa63ea670e..f7ac8f43c91 100644 --- a/interface/src/scripting/DesktopScriptingInterface.cpp +++ b/interface/src/scripting/DesktopScriptingInterface.cpp @@ -60,7 +60,9 @@ static const QVariantMap RELATIVE_POSITION_ANCHOR { }; DesktopScriptingInterface::DesktopScriptingInterface(QObject* parent, bool restricted) - : QObject(parent), _restricted(restricted) { } + : QObject(parent), _restricted(restricted) { + connect(this, &DesktopScriptingInterface::uiFocusChanged, [this] (bool isActive) { _isOverlayWindowFocused = isActive; }); +} int DesktopScriptingInterface::getWidth() { QSize size = qApp->getWindow()->windowHandle()->screen()->virtualSize(); diff --git a/interface/src/scripting/DesktopScriptingInterface.h b/interface/src/scripting/DesktopScriptingInterface.h index db52906cfd7..41a2c51ac99 100644 --- a/interface/src/scripting/DesktopScriptingInterface.h +++ b/interface/src/scripting/DesktopScriptingInterface.h @@ -104,6 +104,13 @@ class DesktopScriptingInterface : public QObject, public Dependency { int getWidth(); int getHeight(); + /*@jsdoc + * Checks whether the keyboard focus belongs to overlay UI window. + * @function Desktop.isOverlayWindowFocused + * @returns {boolean} true if the keyboard focus is on overlay UI window, false if not. + */ + Q_INVOKABLE bool isOverlayWindowFocused() { return _isOverlayWindowFocused; }; + signals: /*@jsdoc @@ -124,6 +131,7 @@ class DesktopScriptingInterface : public QObject, public Dependency { static QVariantMap getRelativePositionAnchor(); Q_INVOKABLE static QVariantMap getPresentationMode(); const bool _restricted; + std::atomic _isOverlayWindowFocused { false }; }; From 831ef9a3bb0156f4044914c7d34573a530ecb929 Mon Sep 17 00:00:00 2001 From: rampa3 <68955305+rampa3@users.noreply.github.com> Date: Mon, 28 Aug 2023 22:19:54 +0200 Subject: [PATCH 12/16] Updated mouse look script to use added API endpoints for preventing softlocks with overlays. (Needs testing.) --- scripts/system/controllers/mouseLook.js | 134 +++++++++++++++--------- 1 file changed, 84 insertions(+), 50 deletions(-) diff --git a/scripts/system/controllers/mouseLook.js b/scripts/system/controllers/mouseLook.js index ad5c1b6fb15..cefe6e0c043 100644 --- a/scripts/system/controllers/mouseLook.js +++ b/scripts/system/controllers/mouseLook.js @@ -13,6 +13,8 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var tabletUp; + + var keysOnOverlay = Desktop.isOverlayWindowFocused(); var tempOff = false; @@ -24,12 +26,14 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) if (!hmd){ if (mouseLookEnabled) { - if (!tablet.tabletShown){ - Window.displayAnnouncement("Mouse look: ON"); - mouseLookOn(); - } else { - Window.displayAnnouncement("Tablet is up – mouse look temporarily OFF."); - } + if (!keysOnOverlay) { + if (!tablet.tabletShown){ + Window.displayAnnouncement("Mouse look: ON"); + mouseLookOn(); + } else { + Window.displayAnnouncement("Tablet is up – mouse look temporarily OFF."); + } + } } } @@ -38,17 +42,19 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) function onKeyPressEvent(event) { if (!hmd){ if (event.text === 'm') { - if (mouseLookEnabled) { - if (!Camera.getCaptureMouse()){ - tempOff = false; - Window.displayAnnouncement("Mouse look: ON"); - mouseLookOn(); - } else { - tempOff = true; - Window.displayAnnouncement("Mouse look: Temporarily OFF"); - mouseLookOff(); - } - } + if (!keysOnOverlay) { + if (mouseLookEnabled) { + if (!Camera.getCaptureMouse()){ + tempOff = false; + Window.displayAnnouncement("Mouse look: ON"); + mouseLookOn(); + } else { + tempOff = true; + Window.displayAnnouncement("Mouse look: Temporarily OFF"); + mouseLookOff(); + } + } + } } } } @@ -59,23 +65,25 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) if (!hmd) { if (mouseLookEnabled) { if (!tablet.toolbarMode) { - if (tablet.tabletShown) { - tabletUp = true; - if (!tempOff) { - if (!away) { - Window.displayAnnouncement("Tablet is up – mouse look temporarily OFF."); - mouseLookOff(); - } - } - } else if (!tablet.tabletShown) { - tabletUp = false; - if (!tempOff) { - if (!away) { - Window.displayAnnouncement("Tablet hidden – mouse look ON."); - mouseLookOn(); - } - } - } + if (!keysOnOverlay) { + if (tablet.tabletShown) { + tabletUp = true; + if (!tempOff) { + if (!away) { + Window.displayAnnouncement("Tablet is up – mouse look temporarily OFF."); + mouseLookOff(); + } + } + } else if (!tablet.tabletShown) { + tabletUp = false; + if (!tempOff) { + if (!away && !keysOnOverlay) { + Window.displayAnnouncement("Tablet hidden – mouse look ON."); + mouseLookOn(); + } + } + } + } } } } @@ -87,11 +95,13 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) if (!hmd) { if (mouseLookEnabled) { away = true; - if (!tabletUp){ - Window.displayAnnouncement("Away state ON – mouse look temporarily OFF.") - tempOff = false; - mouseLookOff() - } + if (!keysOnOverlay) { + if (!tabletUp){ + Window.displayAnnouncement("Away state ON – mouse look temporarily OFF.") + tempOff = false; + mouseLookOff() + } + } } } } @@ -102,10 +112,12 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) if (!hmd) { if (mouseLookEnabled) { away = false; - if (!tabletUp) { - Window.displayAnnouncement("Away state OFF – mouse look ON."); - mouseLookOn(); - } + if (!keysOnOverlay) { + if (!tabletUp) { + Window.displayAnnouncement("Away state OFF – mouse look ON."); + mouseLookOn(); + } + } } } } @@ -120,9 +132,11 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) } else { hmd = false; if (!tempOff) { - if (!tabletUp) { - mouseLookOn(); - } + if (!keysOnOverlay) { + if (!tabletUp) { + mouseLookOn(); + } + } } } } @@ -135,8 +149,28 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) function mouseLookOff() { Camera.captureMouse = false; } - - Camera.modeUpdated.connect(onCameraModeUpdated); + + Desktop.uiFocusChanged.connect(onUiFocusChanged); + + function onUiFocusChanged(keyFocus) { + if (!hmd) { + if (keyFocus) { + keysOnOverlay = true; + if (Camera.captureMouse) { + Camera.captureMouse = false; + } + } else { + keysOnOverlay = false; + if (!tablet.tabletShown) { + if (!tempOff) { + if (!away) { + mouseLookOn(); + } + } + } + } + } + } Script.scriptEnding.connect(onScriptEnding); @@ -148,8 +182,8 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) MyAvatar.wentAway.disconnect(onWentAway); MyAvatar.wentActive.disconnect(onWentActive); HMD.displayModeChanged.disconnect(onDisplayModeChanged); - Camera.modeUpdated.disconnect(onCameraModeUpdated); + Desktop.uiFocusChanged.disconnect(onUiFocusChanged); Script.scriptEnding.disconnect(onScriptEnding); } -}()); // END LOCAL_SCOPE \ No newline at end of file +}()); // END LOCAL_SCOPE From 8ed70d5d8476adf1c784ed6d255b4f7734ae3644 Mon Sep 17 00:00:00 2001 From: rampa3 <68955305+rampa3@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:57:47 +0200 Subject: [PATCH 13/16] Added missing mouse look enabled check --- scripts/system/controllers/mouseLook.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts/system/controllers/mouseLook.js b/scripts/system/controllers/mouseLook.js index cefe6e0c043..6535a2e07e8 100644 --- a/scripts/system/controllers/mouseLook.js +++ b/scripts/system/controllers/mouseLook.js @@ -154,17 +154,19 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) function onUiFocusChanged(keyFocus) { if (!hmd) { - if (keyFocus) { - keysOnOverlay = true; - if (Camera.captureMouse) { - Camera.captureMouse = false; - } - } else { - keysOnOverlay = false; - if (!tablet.tabletShown) { - if (!tempOff) { - if (!away) { - mouseLookOn(); + if (mouseLookEnabled) { + if (keyFocus) { + keysOnOverlay = true; + if (Camera.captureMouse) { + mouseLookOff(); + } + } else { + keysOnOverlay = false; + if (!tablet.tabletShown) { + if (!tempOff) { + if (!away) { + mouseLookOn(); + } } } } From 51a26522b924b0ce5773fded69cc9a511edb5567 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Fri, 1 Sep 2023 20:52:07 +0200 Subject: [PATCH 14/16] Fixed reticle setting --- interface/src/Application.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a4d9b15eff0..35df55ddf23 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1505,7 +1505,6 @@ Application::Application( qCDebug(interfaceapp, "Initialized Display"); if (_displayPlugin && !_displayPlugin->isHmd()) { - _preferredCursor.set(Cursor::Manager::getIconName(Cursor::Icon::SYSTEM)); showCursor(Cursor::Manager::lookupIcon(_preferredCursor.get())); } // An audio device changed signal received before the display plugins are set up will cause a crash, From c49c947984ba05c2f50be1dc7f8427fd96a2d1aa Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Fri, 1 Sep 2023 23:43:22 +0200 Subject: [PATCH 15/16] Fixed llack of precision in mouse look mode --- interface/src/Application.cpp | 3 +++ .../src/input-plugins/KeyboardMouseDevice.cpp | 10 +++++++--- .../src/input-plugins/KeyboardMouseDevice.h | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 35df55ddf23..0ca518d44d6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -6326,6 +6326,9 @@ void Application::update(float deltaTime) { if (QCursor::pos() != point) { _mouseCaptureTarget = point; _ignoreMouseMove = true; + if (_captureMouse) { + _keyboardMouseDevice->updateMousePositionForCapture(QCursor::pos(), _mouseCaptureTarget); + } QCursor::setPos(point); } } diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp index 88994ddd926..b0bf8198fc1 100644 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp @@ -113,14 +113,18 @@ void KeyboardMouseDevice::eraseMouseClicked() { _inputDevice->_buttonPressedMap.erase(_inputDevice->makeInput(Qt::RightButton, true).getChannel()); } +void KeyboardMouseDevice::updateMousePositionForCapture(QPoint globalPos, QPointF captureTarget) { + if (!isNaN(captureTarget.x())) { + QPointF change = globalPos - captureTarget; + _accumulatedMove += QPoint(change.x(), change.y()); + } +} + void KeyboardMouseDevice::mouseMoveEvent(QMouseEvent* event, bool capture, QPointF captureTarget) { QPoint currentPos = event->pos(); if (!capture) { _accumulatedMove += currentPos - _lastCursor; - } else if (!isNaN(captureTarget.x())) { - QPointF change = event->globalPos() - captureTarget; - _accumulatedMove += QPoint(change.x(), change.y()); } // FIXME - this has the characteristic that it will show large jumps when you move the cursor diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h index 216194a7125..d33ced6a474 100644 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h @@ -93,6 +93,9 @@ class KeyboardMouseDevice : public InputPlugin { void wheelEvent(QWheelEvent* event); bool isWheelByTouchPad(QWheelEvent* event); + // This gets called from Application::update just before resetting cursor position when mouse capture is enabled + void updateMousePositionForCapture(QPoint globalPos, QPointF captureTarget); + static void enableTouch(bool enableTouch) { _enableTouch = enableTouch; } static const char* NAME; From f8aec053323479a53518d79e12cc43bf1d95c1dc Mon Sep 17 00:00:00 2001 From: rampa3 <68955305+rampa3@users.noreply.github.com> Date: Sun, 10 Sep 2023 11:43:07 +0200 Subject: [PATCH 16/16] Converted indentations from tabs to spaces --- scripts/system/controllers/mouseLook.js | 160 ++++++++++++------------ 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/scripts/system/controllers/mouseLook.js b/scripts/system/controllers/mouseLook.js index 6535a2e07e8..f62a802a709 100644 --- a/scripts/system/controllers/mouseLook.js +++ b/scripts/system/controllers/mouseLook.js @@ -4,28 +4,28 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) */ (function() { // BEGIN LOCAL_SCOPE - var away; + var away; - var hmd = HMD.active; + var hmd = HMD.active; - var mouseLookEnabled = Camera.getMouseLook(); + var mouseLookEnabled = Camera.getMouseLook(); - var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); - var tabletUp; + var tabletUp; var keysOnOverlay = Desktop.isOverlayWindowFocused(); - var tempOff = false; + var tempOff = false; - Camera.mouseLookChanged.connect(onMouseLookChanged); + Camera.mouseLookChanged.connect(onMouseLookChanged); - function onMouseLookChanged(newMouseLook) { - mouseLookEnabled = newMouseLook; - } + function onMouseLookChanged(newMouseLook) { + mouseLookEnabled = newMouseLook; + } - if (!hmd){ - if (mouseLookEnabled) { + if (!hmd){ + if (mouseLookEnabled) { if (!keysOnOverlay) { if (!tablet.tabletShown){ Window.displayAnnouncement("Mouse look: ON"); @@ -34,14 +34,14 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) Window.displayAnnouncement("Tablet is up – mouse look temporarily OFF."); } } - } - } + } + } - Controller.keyPressEvent.connect(onKeyPressEvent); + Controller.keyPressEvent.connect(onKeyPressEvent); - function onKeyPressEvent(event) { - if (!hmd){ - if (event.text === 'm') { + function onKeyPressEvent(event) { + if (!hmd){ + if (event.text === 'm') { if (!keysOnOverlay) { if (mouseLookEnabled) { if (!Camera.getCaptureMouse()){ @@ -55,16 +55,16 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) } } } - } - } - } + } + } + } - tablet.tabletShownChanged.connect(onTabletShownChanged); + tablet.tabletShownChanged.connect(onTabletShownChanged); - function onTabletShownChanged() { - if (!hmd) { - if (mouseLookEnabled) { - if (!tablet.toolbarMode) { + function onTabletShownChanged() { + if (!hmd) { + if (mouseLookEnabled) { + if (!tablet.toolbarMode) { if (!keysOnOverlay) { if (tablet.tabletShown) { tabletUp = true; @@ -84,17 +84,17 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) } } } - } - } - } - } + } + } + } + } - MyAvatar.wentAway.connect(onWentAway); + MyAvatar.wentAway.connect(onWentAway); - function onWentAway() { - if (!hmd) { - if (mouseLookEnabled) { - away = true; + function onWentAway() { + if (!hmd) { + if (mouseLookEnabled) { + away = true; if (!keysOnOverlay) { if (!tabletUp){ Window.displayAnnouncement("Away state ON – mouse look temporarily OFF.") @@ -102,53 +102,53 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) mouseLookOff() } } - } - } - } + } + } + } - MyAvatar.wentActive.connect(onWentActive); + MyAvatar.wentActive.connect(onWentActive); - function onWentActive() { - if (!hmd) { - if (mouseLookEnabled) { - away = false; + function onWentActive() { + if (!hmd) { + if (mouseLookEnabled) { + away = false; if (!keysOnOverlay) { if (!tabletUp) { Window.displayAnnouncement("Away state OFF – mouse look ON."); mouseLookOn(); } } - } - } - } - - HMD.displayModeChanged.connect(onDisplayModeChanged); - - function onDisplayModeChanged() { - if (mouseLookEnabled) { - if (HMD.active) { - hmd = true; - mouseLookOff(); - } else { - hmd = false; - if (!tempOff) { + } + } + } + + HMD.displayModeChanged.connect(onDisplayModeChanged); + + function onDisplayModeChanged() { + if (mouseLookEnabled) { + if (HMD.active) { + hmd = true; + mouseLookOff(); + } else { + hmd = false; + if (!tempOff) { if (!keysOnOverlay) { if (!tabletUp) { mouseLookOn(); } } - } - } - } - } - - function mouseLookOn() { - Camera.captureMouse = true; - } - - function mouseLookOff() { - Camera.captureMouse = false; - } + } + } + } + } + + function mouseLookOn() { + Camera.captureMouse = true; + } + + function mouseLookOff() { + Camera.captureMouse = false; + } Desktop.uiFocusChanged.connect(onUiFocusChanged); @@ -174,18 +174,18 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon) } } - Script.scriptEnding.connect(onScriptEnding); + Script.scriptEnding.connect(onScriptEnding); - function onScriptEnding() { - Camera.captureMouse = false; - Camera.mouseLookChanged.disconnect(onMouseLookChanged); - Controller.keyPressEvent.disconnect(onKeyPressEvent); - tablet.tabletShownChanged.disconnect(onTabletShownChanged); - MyAvatar.wentAway.disconnect(onWentAway); - MyAvatar.wentActive.disconnect(onWentActive); - HMD.displayModeChanged.disconnect(onDisplayModeChanged); + function onScriptEnding() { + Camera.captureMouse = false; + Camera.mouseLookChanged.disconnect(onMouseLookChanged); + Controller.keyPressEvent.disconnect(onKeyPressEvent); + tablet.tabletShownChanged.disconnect(onTabletShownChanged); + MyAvatar.wentAway.disconnect(onWentAway); + MyAvatar.wentActive.disconnect(onWentActive); + HMD.displayModeChanged.disconnect(onDisplayModeChanged); Desktop.uiFocusChanged.disconnect(onUiFocusChanged); - Script.scriptEnding.disconnect(onScriptEnding); - } + Script.scriptEnding.disconnect(onScriptEnding); + } }()); // END LOCAL_SCOPE