Add setting to force virtual window in VR.

This commit is contained in:
armored-dragon 2024-12-31 16:22:55 -06:00
parent 71c85d3889
commit 624ceefc24
No known key found for this signature in database
GPG key ID: C7207ACC3382AD8B
2 changed files with 51 additions and 8 deletions

View file

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

View file

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