diff --git a/docs/configuration.md b/docs/configuration.md index fe7007c1..79f5ef14 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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 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. diff --git a/server/active_runtime.cpp b/server/active_runtime.cpp index 6c1725e0..84022a88 100644 --- a/server/active_runtime.cpp +++ b/server/active_runtime.cpp @@ -20,6 +20,7 @@ #include "active_runtime.h" #include "driver/configuration.h" #include "utils/flatpak.h" +#include "utils/overloaded.h" #include "utils/xdg_base_directory.h" #include "wivrn_config.h" #include @@ -49,20 +50,33 @@ std::filesystem::path active_runtime::manifest_path() std::filesystem::path active_runtime::openvr_compat_path() { - // config can override compat path (i.e. to debug changes to OpenComposite) - std::optional path_override = configuration::read_user_configuration().openvr_compat_path; - if (path_override.has_value()) - return std::filesystem::path(path_override.value()); + return std::visit( + utils::overloaded{ + [](std::monostate) { + // no user configuration: return default + std::optional 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 - if (auto path = flatpak_key(flatpak::section::instance, "app-path")) - return std::filesystem::path(*path) / "OpenComposite"; - for (auto path: std::ranges::split_view(std::string_view(OVR_COMPAT_SEARCH_PATH), std::string_view(":"))) - { - if (auto res = std::string_view(path); std::filesystem::exists(res)) - return res; - } - return {}; + for (auto path: std::ranges::split_view(std::string_view(OVR_COMPAT_SEARCH_PATH), std::string_view(":"))) + { + if (std::filesystem::path res = std::string_view(path); std::filesystem::exists(res)) + return res; + } + return std::filesystem::path(); + }, + [](const std::string & path) { + // exlicit value, use it + std::optional 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) diff --git a/server/driver/configuration.cpp b/server/driver/configuration.cpp index 5fe1287d..7839b28d 100644 --- a/server/driver/configuration.cpp +++ b/server/driver/configuration.cpp @@ -154,7 +154,10 @@ configuration configuration::read_user_configuration() 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) diff --git a/server/driver/configuration.h b/server/driver/configuration.h index 8da552ea..d3363b60 100644 --- a/server/driver/configuration.h +++ b/server/driver/configuration.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "wivrn_packets.h" @@ -60,7 +61,9 @@ struct configuration std::vector application; bool tcp_only = false; service_publication publication = service_publication::avahi; - std::optional openvr_compat_path; + + // monostate: default value, string: user defined, nullptr: disabled + std::variant openvr_compat_path; static void set_config_file(const std::filesystem::path &); static const std::filesystem::path & get_config_file();