From 624ceefc244c62b70f1400a146512bc138ee150e Mon Sep 17 00:00:00 2001 From: armored-dragon Date: Tue, 31 Dec 2024 16:22:55 -0600 Subject: [PATCH] Add setting to force virtual window in VR. --- scripts/system/domainChat/domainChat.js | 34 ++++++++++++++++++------ scripts/system/domainChat/domainChat.qml | 25 +++++++++++++++++ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/scripts/system/domainChat/domainChat.js b/scripts/system/domainChat/domainChat.js index 30b6081083..f6d8a10b3f 100644 --- a/scripts/system/domainChat/domainChat.js +++ b/scripts/system/domainChat/domainChat.js @@ -7,8 +7,6 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// TODO: Message trimming - (() => { ("use strict"); @@ -20,8 +18,10 @@ var settings = { external_window: false, maximum_messages: 200, - join_notification: true + join_notification: true, + switchToInternalOnHeadsetUsed: true }; + let temporaryChangeModeToVirtual = false; // Global vars var tablet; @@ -38,6 +38,7 @@ Messages.messageReceived.connect(receivedMessage); AvatarManager.avatarAddedEvent.connect((sessionId) => { _avatarAction("connected", sessionId); }); AvatarManager.avatarRemovedEvent.connect((sessionId) => { _avatarAction("left", sessionId); }); + HMD.displayModeChanged.connect(_onHMDDisplayModeChanged); startup(); @@ -135,15 +136,16 @@ break; case "setting_change": // Set the setting value, and save the config - settings[event.setting] = event.value; // Update local settings - _saveSettings(); // Save local settings + settings[event.setting] = event.value; // Update local settings + _saveSettings(); // Save local settings // Extra actions to preform. switch (event.setting) { case "external_window": - chatOverlayWindow.presentationMode = event.value - ? Desktop.PresentationMode.NATIVE - : Desktop.PresentationMode.VIRTUAL; + _changePresentationMode(event.value); + break; + case "switchToInternalOnHeadsetUsed": + _onHMDDisplayModeChanged(HMD.active); break; } @@ -177,6 +179,22 @@ }); } } + function _onHMDDisplayModeChanged(isHMDActive){ + // If the user enabled automatic switching to internal when they put on a headset... + if (!settings.switchToInternalOnHeadsetUsed) return; + + if (isHMDActive) temporaryChangeModeToVirtual = true; + else temporaryChangeModeToVirtual = false; + + _changePresentationMode(settings.external_window); + } + function _changePresentationMode(changeToExternal){ + if (temporaryChangeModeToVirtual) changeToExternal = false; + + chatOverlayWindow.presentationMode = changeToExternal + ? Desktop.PresentationMode.NATIVE + : Desktop.PresentationMode.VIRTUAL; + } function _sendMessage(message, channel) { if (message.length == 0) return; diff --git a/scripts/system/domainChat/domainChat.qml b/scripts/system/domainChat/domainChat.qml index 6a79cb7e2e..287bb1a825 100644 --- a/scripts/system/domainChat/domainChat.qml +++ b/scripts/system/domainChat/domainChat.qml @@ -369,6 +369,29 @@ Rectangle { } } } + // Switch to internal on VR Mode + Rectangle { + width: parent.width + height: 40 + color: "transparent" + + Text { + text: "Force Virtual window in VR" + color: "white" + font.pointSize: 12 + anchors.verticalCenter: parent.verticalCenter + } + + CheckBox { + id: s_force_vw_in_vr + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + + onCheckedChanged: { + toScript({type: 'setting_change', setting: 'switchToInternalOnHeadsetUsed', value: checked}) + } + } + } } } @@ -433,9 +456,11 @@ Rectangle { domain.clear(); break; case "initial_settings": + print(JSON.stringify(message.settings)); if (message.settings.external_window) s_external_window.checked = true; if (message.settings.maximum_messages) s_maximum_messages.value = message.settings.maximum_messages; if (message.settings.join_notification) s_join_notification.checked = true; + if (message.settings.switchToInternalOnHeadsetUsed) s_force_vw_in_vr.checked = true; break; } }