Add null to disable OpenVR configuration

This commit is contained in:
Patrick Nicolas
2025-04-29 19:40:35 +02:00
parent 81f2617d84
commit acd35e3ebd
4 changed files with 36 additions and 16 deletions
+1 -1
View File
@@ -189,4 +189,4 @@ Provides the path to the directory of an OpenVR compatibility tool (such as Open
If unset, WiVRn will autodetect the path of such a tool as usual (see [the SteamVR guide](./steamvr.md)). If unset, WiVRn will autodetect the path of such a tool as usual (see [the SteamVR guide](./steamvr.md)).
If set to an empty string, it is assumed detection failed ; the OpenVR configuration will not be modified and the pressure-vessel configuration won't be adjusted. If set to an null, WiVRn will not manage the OpenVR configuration.
+27 -13
View File
@@ -20,6 +20,7 @@
#include "active_runtime.h" #include "active_runtime.h"
#include "driver/configuration.h" #include "driver/configuration.h"
#include "utils/flatpak.h" #include "utils/flatpak.h"
#include "utils/overloaded.h"
#include "utils/xdg_base_directory.h" #include "utils/xdg_base_directory.h"
#include "wivrn_config.h" #include "wivrn_config.h"
#include <filesystem> #include <filesystem>
@@ -49,20 +50,33 @@ std::filesystem::path active_runtime::manifest_path()
std::filesystem::path active_runtime::openvr_compat_path() std::filesystem::path active_runtime::openvr_compat_path()
{ {
// config can override compat path (i.e. to debug changes to OpenComposite) return std::visit(
std::optional<std::string> path_override = configuration::read_user_configuration().openvr_compat_path; utils::overloaded{
if (path_override.has_value()) [](std::monostate) {
return std::filesystem::path(path_override.value()); // no user configuration: return default
std::optional<std::filesystem::path> flatpak_root = flatpak_key(flatpak::section::instance, "app-path");
// flatpak default
if (flatpak_root)
return *flatpak_root / "OpenComposite";
// otherwise, prefer flatpak copy if present or otherwise try to find it on the system for (auto path: std::ranges::split_view(std::string_view(OVR_COMPAT_SEARCH_PATH), std::string_view(":")))
if (auto path = flatpak_key(flatpak::section::instance, "app-path")) {
return std::filesystem::path(*path) / "OpenComposite"; if (std::filesystem::path res = std::string_view(path); std::filesystem::exists(res))
for (auto path: std::ranges::split_view(std::string_view(OVR_COMPAT_SEARCH_PATH), std::string_view(":"))) return res;
{ }
if (auto res = std::string_view(path); std::filesystem::exists(res)) return std::filesystem::path();
return res; },
} [](const std::string & path) {
return {}; // exlicit value, use it
std::optional<std::filesystem::path> flatpak_root = flatpak_key(flatpak::section::instance, "app-path");
return flatpak_root.value_or("") / path;
},
[](std::nullptr_t) {
// explicit null, don't set any compat path
return std::filesystem::path();
},
},
configuration::read_user_configuration().openvr_compat_path);
} }
static std::filesystem::path backup_name(std::filesystem::path file) static std::filesystem::path backup_name(std::filesystem::path file)
+4 -1
View File
@@ -154,7 +154,10 @@ configuration configuration::read_user_configuration()
if (auto it = json.find("openvr-compat-path"); it != json.end()) if (auto it = json.find("openvr-compat-path"); it != json.end())
{ {
result.openvr_compat_path = *it; if (it->is_null())
result.openvr_compat_path = nullptr;
else
result.openvr_compat_path = *it;
} }
} }
catch (const std::exception & e) catch (const std::exception & e)
+4 -1
View File
@@ -25,6 +25,7 @@
#include <map> #include <map>
#include <optional> #include <optional>
#include <string> #include <string>
#include <variant>
#include "wivrn_packets.h" #include "wivrn_packets.h"
@@ -60,7 +61,9 @@ struct configuration
std::vector<std::string> application; std::vector<std::string> application;
bool tcp_only = false; bool tcp_only = false;
service_publication publication = service_publication::avahi; service_publication publication = service_publication::avahi;
std::optional<std::string> openvr_compat_path;
// monostate: default value, string: user defined, nullptr: disabled
std::variant<std::monostate, std::string, std::nullptr_t> openvr_compat_path;
static void set_config_file(const std::filesystem::path &); static void set_config_file(const std::filesystem::path &);
static const std::filesystem::path & get_config_file(); static const std::filesystem::path & get_config_file();