diff --git a/dashboard/qml/SettingsPage.qml b/dashboard/qml/SettingsPage.qml index 255f4e5c..2809f423 100644 --- a/dashboard/qml/SettingsPage.qml +++ b/dashboard/qml/SettingsPage.qml @@ -336,7 +336,7 @@ Kirigami.ScrollablePage { enabled: adb_custom.checked Controls.TextField { id: adb_location - placeholderText: settings.adb + placeholderText: settings.adb_location Layout.fillWidth: true } Controls.Button { @@ -345,6 +345,75 @@ Kirigami.ScrollablePage { } } + ListModel { + id: openvr_libs + + function init() { + openvr_libs.append({ + "name": i18n("Default"), + "value": "", + "is_custom": false + }); + + if (config.flatpak) { + openvr_libs.append({ + "name": i18n("xrizer"), + "value": "xrizer", + "is_custom": false + }); + openvr_libs.append({ + "name": i18n("Open Composite"), + "value": "OpenComposite", + "is_custom": false + }); + } + + openvr_libs.append({ + "name": i18nc("set a custom OpenVR compatibility library", "Custom"), + "is_custom": true + }); + + openvr_libs.append({ + "name": i18n("Disabled"), + "value": "-", + "is_custom": false + }); + } + } + + RowLayout { + Kirigami.FormData.label: i18n("OpenVR compatibility library:") + Layout.fillWidth: true + Controls.ComboBox { + id: openvr_combobox + Layout.columnSpan: 2 + textRole: "name" + model: openvr_libs + + function load() { + for(let i=0 ; i < openvr_libs.count; i++) { + if (openvr_libs.get(i).value == config.openvr) { + openvr_combobox.currentIndex = i; + return; + } + } + for(let i=0 ; i < openvr_libs.count; i++) { + if (openvr_libs.get(i).is_custom) { + openvr_text.text = config.openvr + openvr_combobox.currentIndex = i; + return; + } + } + } + } + Controls.TextField { + id: openvr_text + placeholderText: i18n("Library path, excluding bin/linux64/vrclient.so") + visible: !!openvr_combobox.model.get(openvr_combobox.currentIndex)?.is_custom + Layout.fillWidth: true + } + } + } Item { @@ -370,6 +439,7 @@ Kirigami.ScrollablePage { } Component.onCompleted: { + openvr_libs.init() config.load(WivrnServer); settings.load(); } @@ -378,6 +448,12 @@ Kirigami.ScrollablePage { config.bitrate = bitrate.value * 1000000; config.scale = manual_foveation.checked ? 1 - scale_slider.value / 100.0 : -1; config.manualEncoders = encoder_layout.currentIndex > 0; + let openvr = openvr_combobox.model.get(openvr_combobox.currentIndex) + if (openvr.is_custom) { + config.openvr = openvr_text.text; + } else { + config.openvr = openvr.value + } settings.adb_custom = adb_custom.checked; settings.adb_location = adb_location.text; Adb.setPath(adb_custom.checked ? adb_location.text : "adb"); @@ -400,6 +476,7 @@ Kirigami.ScrollablePage { // auto_encoders.checked = true; encoder_layout.currentIndex = 0; } + openvr_combobox.load() adb_custom.checked = settings.adb_custom; adb_location.text = settings.adb_location; diff --git a/dashboard/settings.cpp b/dashboard/settings.cpp index 066a160c..7dbecc50 100644 --- a/dashboard/settings.cpp +++ b/dashboard/settings.cpp @@ -19,6 +19,7 @@ #include "settings.h" #include "escape_string.h" +#include "utils/flatpak.h" #include "wivrn_server.h" #include #include @@ -211,6 +212,22 @@ void Settings::load(const wivrn_server * server) { set_application(""); } + + // OpenVR compat library + try + { + if (auto it = json_doc.find("openvr-compat-path"); it != json_doc.end()) + { + if (it->is_null()) + set_openvr("-"); + else + set_openvr(QString::fromStdString(*it)); + } + } + catch (...) + { + set_openvr(""); + } } void Settings::save(wivrn_server * server) @@ -281,6 +298,13 @@ void Settings::save(wivrn_server * server) if (application() != "") json_doc["application"] = unescape_string(application()); + if (openvr() == "-") + json_doc["openvr-compat-path"] = nullptr; + else if (openvr() == "") + json_doc.erase("openvr-compat-path"); + else + json_doc["openvr-compat-path"] = openvr().toStdString(); + server->setJsonConfiguration(QString::fromStdString(json_doc.dump(2))); } @@ -318,4 +342,9 @@ void Settings::set_encoder_preset(QJSValue preset) set_encoders(encoders); } +bool Settings::flatpak() const +{ + return wivrn::is_flatpak(); +} + #include "moc_settings.cpp" diff --git a/dashboard/settings.h b/dashboard/settings.h index bd53f3f3..11948896 100644 --- a/dashboard/settings.h +++ b/dashboard/settings.h @@ -123,6 +123,9 @@ class Settings : public QObject Q_PROPERTY(float scale READ scale WRITE set_scale NOTIFY scaleChanged) Q_PROPERTY(QString application READ application WRITE set_application NOTIFY applicationChanged) Q_PROPERTY(bool tcpOnly READ tcpOnly WRITE set_tcpOnly NOTIFY tcpOnlyChanged) + Q_PROPERTY(QString openvr READ openvr WRITE set_openvr NOTIFY openvrChanged) + + Q_PROPERTY(bool flatpak READ flatpak CONSTANT) SETTER_GETTER_NOTIFY(bool, manualEncoders) SETTER_GETTER_NOTIFY(std::vector, encoders) @@ -131,6 +134,7 @@ class Settings : public QObject SETTER_GETTER_NOTIFY(float, scale) SETTER_GETTER_NOTIFY(QString, application) SETTER_GETTER_NOTIFY(bool, tcpOnly) + SETTER_GETTER_NOTIFY(QString, openvr) public: Settings(QObject * parent = nullptr) : @@ -141,6 +145,8 @@ public: Q_INVOKABLE void restore_defaults(); Q_INVOKABLE void set_encoder_preset(QJSValue preset); + bool flatpak() const; + static std::optional encoder_id_from_string(std::string_view s); static std::optional codec_id_from_string(std::string_view s); static const std::string & encoder_from_id(std::optional id);