Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/openxr/editor/openxr_select_runtime.cpp
10278 views
1
/**************************************************************************/
2
/* openxr_select_runtime.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "openxr_select_runtime.h"
32
33
#include "core/io/dir_access.h"
34
#include "core/os/os.h"
35
#include "editor/settings/editor_settings.h"
36
37
void OpenXRSelectRuntime::_update_items() {
38
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
39
OS *os = OS::get_singleton();
40
Dictionary runtimes = EDITOR_GET("xr/openxr/runtime_paths");
41
42
int current_runtime = 0;
43
int index = 0;
44
String current_path = os->get_environment("XR_RUNTIME_JSON");
45
46
// Parse the user's home folder.
47
String home_folder = os->get_environment("HOME");
48
if (home_folder.is_empty()) {
49
home_folder = os->get_environment("HOMEDRIVE") + os->get_environment("HOMEPATH");
50
}
51
52
clear();
53
add_item("Default", -1);
54
set_item_metadata(index, "");
55
index++;
56
57
for (const KeyValue<Variant, Variant> &kv : runtimes) {
58
const String &key = kv.key;
59
const String &path = kv.value;
60
String adj_path = path.replace("~", home_folder);
61
62
if (da->file_exists(adj_path)) {
63
add_item(key, index);
64
set_item_metadata(index, adj_path);
65
66
if (current_path == adj_path) {
67
current_runtime = index;
68
}
69
index++;
70
}
71
}
72
73
select(current_runtime);
74
}
75
76
void OpenXRSelectRuntime::_on_item_selected(int p_which) {
77
OS *os = OS::get_singleton();
78
79
if (p_which == 0) {
80
// Return to default runtime
81
os->set_environment("XR_RUNTIME_JSON", "");
82
} else {
83
// Select the runtime we want
84
String runtime_path = get_item_metadata(p_which);
85
os->set_environment("XR_RUNTIME_JSON", runtime_path);
86
}
87
}
88
89
void OpenXRSelectRuntime::_notification(int p_notification) {
90
switch (p_notification) {
91
case NOTIFICATION_ENTER_TREE: {
92
// Update dropdown
93
_update_items();
94
95
// Connect signal
96
connect(SceneStringName(item_selected), callable_mp(this, &OpenXRSelectRuntime::_on_item_selected));
97
} break;
98
case NOTIFICATION_EXIT_TREE: {
99
// Disconnect signal
100
disconnect(SceneStringName(item_selected), callable_mp(this, &OpenXRSelectRuntime::_on_item_selected));
101
} break;
102
}
103
}
104
105
OpenXRSelectRuntime::OpenXRSelectRuntime() {
106
Dictionary default_runtimes;
107
108
// Add known common runtimes by default.
109
#ifdef WINDOWS_ENABLED
110
default_runtimes["Meta"] = "C:\\Program Files\\Oculus\\Support\\oculus-runtime\\oculus_openxr_64.json";
111
default_runtimes["SteamVR"] = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\SteamVR\\steamxr_win64.json";
112
default_runtimes["Varjo"] = "C:\\Program Files\\Varjo\\varjo-openxr\\VarjoOpenXR.json";
113
default_runtimes["WMR"] = "C:\\WINDOWS\\system32\\MixedRealityRuntime.json";
114
#endif
115
#ifdef LINUXBSD_ENABLED
116
default_runtimes["Monado"] = "/usr/share/openxr/1/openxr_monado.json";
117
default_runtimes["SteamVR"] = "~/.steam/steam/steamapps/common/SteamVR/steamxr_linux64.json";
118
#endif
119
120
// TODO: Move to editor_settings.cpp
121
EDITOR_DEF_RST("xr/openxr/runtime_paths", default_runtimes);
122
123
set_flat(true);
124
set_theme_type_variation("TopBarOptionButton");
125
set_fit_to_longest_item(false);
126
set_focus_mode(Control::FOCUS_NONE);
127
set_tooltip_text(TTR("Choose an XR runtime."));
128
}
129
130