diff --git a/flatpak/io.github.wivrn.wivrn.yml.in b/flatpak/io.github.wivrn.wivrn.yml.in index 694f61a4..d7984521 100644 --- a/flatpak/io.github.wivrn.wivrn.yml.in +++ b/flatpak/io.github.wivrn.wivrn.yml.in @@ -3,7 +3,7 @@ id: io.github.wivrn.wivrn runtime: org.kde.Platform runtime-version: '6.7' sdk: org.kde.Sdk -command: launch-wivrn-dashboard +command: wivrn-dashboard finish-args: # X11 + XShm access @@ -179,9 +179,6 @@ modules: - type: shell commands: - cd deps/monado-src && ../../patches/apply.sh ../../patches/monado - - type: shell - commands: - - sed -i "s,Exec=.*$,Exec=${FLATPAK_DEST}/bin/launch-wivrn-dashboard," dashboard/io.github.wivrn.wivrn.desktop.in - name: opencomposite buildsystem: cmake-ninja @@ -192,32 +189,3 @@ modules: - type: git url: https://gitlab.com/znixian/OpenOVR.git tag: 402aff64a7f60dc142fd50d0da6ae5214cdfdc49 - - - name: launcher - buildsystem: simple - build-commands: - - install -Dm755 launch-wivrn-dashboard.sh ${FLATPAK_DEST}/bin/launch-wivrn-dashboard - sources: - - type: script - dest-filename: launch-wivrn-dashboard.sh - commands: - - if [ -f $XDG_CONFIG_HOME/openvr/openvrpaths.vrpath ] - - then - - mv $XDG_CONFIG_HOME/openvr/openvrpaths.vrpath $XDG_CONFIG_HOME/openvrpaths.vrpath-backup - - else - - rm -f $XDG_CONFIG_HOME/openvrpaths.vrpath-backup - - fi - - - - cleanup() { - - rm -f $XDG_CONFIG_HOME/openvr/openvrpaths.vrpath - - if [ -f $XDG_CONFIG_HOME/openvrpaths.vrpath-backup ] - - then - - mv $XDG_CONFIG_HOME/openvrpaths.vrpath-backup $XDG_CONFIG_HOME/openvr/openvrpaths.vrpath - - fi - - trap - EXIT - - '}' - - - - sed -ne 's#app-path=\(.*\)#{"runtime":["\1/OpenComposite"],"version":1}#p' /.flatpak-info > $XDG_CONFIG_HOME/openvr/openvrpaths.vrpath && trap cleanup EXIT INT TERM HUP - - chmod -w $XDG_CONFIG_HOME/openvr/openvrpaths.vrpath - - - - wivrn-dashboard "$@" diff --git a/server/active_runtime.cpp b/server/active_runtime.cpp index ecef0328..0a1aaf8a 100644 --- a/server/active_runtime.cpp +++ b/server/active_runtime.cpp @@ -22,7 +22,9 @@ #include "utils/xdg_base_directory.h" #include "wivrn_config.h" #include +#include #include +#include namespace wivrn { @@ -50,6 +52,13 @@ static std::filesystem::path backup_name(std::filesystem::path file) return file; } +static std::filesystem::path find_opencomposite() +{ + if (auto path = flatpak_key(flatpak::section::instance, "app-path")) + return *path + "/OpenComposite"; + return {}; +} + static void move_file(const std::filesystem::path & from, const std::filesystem::path & to) { if (not std::filesystem::exists(from)) @@ -73,13 +82,38 @@ active_runtime::active_runtime() : { std::cerr << "Cannot set active OpenXR runtime: " << e.what() << std::endl; } + + try + { + auto opencomposite = find_opencomposite(); + if (not opencomposite.empty()) + { + std::filesystem::path openvr_manifest = xdg_config_home() / "openvr/openvrpaths.vrpath"; + std::filesystem::create_directories(openvr_manifest.parent_path()); + move_file(openvr_manifest, backup_name(openvr_manifest)); + + nlohmann::json manifest; + manifest["runtime"] = {opencomposite.string()}; + manifest["version"] = 1; + std::ofstream manifest_file(openvr_manifest.c_str()); + manifest_file.exceptions(std::ofstream::failbit); + manifest_file << manifest; + this->openvr_manifest = openvr_manifest; + } + } + catch (std::exception & e) + { + std::cerr << "Cannot set active OpenXR runtime: " << e.what() << std::endl; + } } active_runtime::~active_runtime() { + if (pid != getpid()) + return; try { - if (pid == getpid() && to_be_deleted) + if (to_be_deleted) { std::filesystem::remove(active_runtime_json); move_file(backup_name(active_runtime_json), active_runtime_json); @@ -89,5 +123,18 @@ active_runtime::~active_runtime() { std::cerr << "Cannot unset active OpenXR runtime: " << e.what() << std::endl; } + + try + { + if (not openvr_manifest.empty()) + { + std::filesystem::remove(openvr_manifest); + move_file(backup_name(openvr_manifest), openvr_manifest); + } + } + catch (std::exception & e) + { + std::cerr << "Cannot unset active OpenVR runtime: " << e.what() << std::endl; + } } } // namespace wivrn diff --git a/server/active_runtime.h b/server/active_runtime.h index 813557f1..2f9e8e3d 100644 --- a/server/active_runtime.h +++ b/server/active_runtime.h @@ -28,6 +28,7 @@ class active_runtime { bool to_be_deleted = false; std::filesystem::path active_runtime_json; + std::filesystem::path openvr_manifest; pid_t pid; public: