From 44bbf00bf12df4d933c9bdb460bb684bb806add8 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 25 Jul 2025 21:05:50 +0200 Subject: [PATCH 01/10] Remove obsolete code --- common/utils/strings.cpp | 7 ------- common/utils/strings.h | 22 ---------------------- 2 files changed, 29 deletions(-) diff --git a/common/utils/strings.cpp b/common/utils/strings.cpp index 3f42671d..8d1d3646 100644 --- a/common/utils/strings.cpp +++ b/common/utils/strings.cpp @@ -19,13 +19,6 @@ #include "strings.h" -std::string utils::trim(std::string input) -{ - input.resize(input.find_last_not_of("\n ") + 1); - - return input; -} - std::vector utils::split(const std::string & s, const std::string & sep) { std::string::size_type i = 0; diff --git a/common/utils/strings.h b/common/utils/strings.h index f9aba057..e93b9fc4 100644 --- a/common/utils/strings.h +++ b/common/utils/strings.h @@ -19,32 +19,10 @@ #pragma once -#include #include #include namespace utils { -std::string trim(std::string input); - -template -std::string join(const std::vector & vec, const std::string & sep = ", ") -{ - std::stringstream s; - - if (!vec.empty()) - { - s << vec[0]; - - for (size_t i = 1, n = vec.size(); i < n; i++) - { - s << sep << vec[i]; - } - } - - return s.str(); -} - std::vector split(const std::string & s, const std::string & sep = "\n"); - } // namespace utils From fa6e76878388b7ea91a558f095aa72526bcf5a2c Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 25 Jul 2025 14:04:22 +0200 Subject: [PATCH 02/10] Cache is_flatpak result --- common/utils/flatpak.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/utils/flatpak.cpp b/common/utils/flatpak.cpp index 7a41fae6..ef8e2a6a 100644 --- a/common/utils/flatpak.cpp +++ b/common/utils/flatpak.cpp @@ -23,10 +23,11 @@ #include static const std::filesystem::path info_path = "/.flatpak-info"; +static const bool is_flatpak_v = std::filesystem::exists(info_path); bool wivrn::is_flatpak() { - return std::filesystem::exists(info_path); + return is_flatpak_v; } std::optional wivrn::flatpak_key(std::string section, std::string key) From b2d49dddb37351d5aa6e50d187e0397e3701fe2e Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 23 Jul 2025 14:27:14 +0200 Subject: [PATCH 03/10] WIP application enumeration --- common/CMakeLists.txt | 6 + common/application.cpp | 287 ++++++++++++++++++++++++++++++++++++ common/application.h | 37 +++++ common/test_application.cpp | 42 ++++++ 4 files changed, 372 insertions(+) create mode 100644 common/application.cpp create mode 100644 common/application.h create mode 100644 common/test_application.cpp diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 8726e359..9313a5e6 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -31,6 +31,7 @@ add_library(wivrn-common-base STATIC ) add_library(wivrn-common STATIC + application.cpp crypto.cpp smp.cpp secrets.cpp @@ -43,6 +44,11 @@ add_library(wivrn-common STATIC vk/vk_mem_alloc.cpp ) +add_executable(list-apps + test_application.cpp +) +target_link_libraries(list-apps wivrn-common) + if(ANDROID) # The Vulkan headers in Android do not include the C++ headers, download them # Minimum version is 1.3.256 diff --git a/common/application.cpp b/common/application.cpp new file mode 100644 index 00000000..caa610fb --- /dev/null +++ b/common/application.cpp @@ -0,0 +1,287 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 Guillaume Meunier + * Copyright (C) 2025 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "application.h" + +#include "utils/xdg_base_directory.h" + +#include + +#include +#include + +namespace wivrn +{ + +namespace +{ + +std::string read_file(const std::filesystem::path & path) +{ +#if 0 + if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk") + { + QProcess flatpak_spawn; + flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(vrmanifest)}); + flatpak_spawn.waitForFinished(); + return flatpak_spawn.readAllStandardOutput().toStdString(); + } + else +#endif + { + std::ifstream f(path); + std::istreambuf_iterator begin{f}, end; + + return {begin, end}; + } +} + +std::string read_vr_manifest() +{ + const char * home = getenv("HOME"); + + return read_file(std::string{home ? home : ""} + "/.steam/steam/config/steamapps.vrmanifest"); +} + +void read_steam_vr_apps(std::unordered_map & res) +{ + auto manifest = read_vr_manifest(); + if (manifest.empty()) + return; + nlohmann::json json = nlohmann::json::parse(manifest); + + for (auto & i: json["applications"]) + { + try + { + application app; + + std::string app_key = i["app_key"]; + for (auto [locale, items]: i["strings"].items()) + { + if (auto it = items.find("name"); it != items.end()) + app.name[locale] = *it; + } + + if (not app.name.contains("")) + { + auto it = app.name.find("en_us"); + if (it == app.name.end()) + it = app.name.begin(); + if (it != app.name.end()) + app.name[""] = it->second; + } + + if (i["launch_type"] == "url") + { + app.exec = "steam " + (std::string)i["url"]; + } + else if (i["launch_type"] == "binary") + { + const char prefix[] = "steam.app."; + if (app_key.starts_with(prefix)) + { + // ¯\_(ツ)_/¯ + uint64_t appkey = stoll(app_key.substr(strlen(prefix))); + app.exec = "steam steam://rungameid/" + std::to_string((appkey << 32) + 0x2000000); + } + } + + if (not app.exec.empty()) + res[app_key] = std::move(app); + } + catch (std::exception &) + { + } + } +} + +std::string unescape(std::string_view in) +{ + std::string out; + out.reserve(in.size()); + for (auto c = in.begin(); c != in.end(); ++c) + { + if (*c == '\\') + { + ++c; + if (c == in.end()) + break; + switch (*c) + { + case 's': + out += ' '; + break; + case 'n': + out += '\n'; + break; + case 't': + out += '\t'; + break; + case 'r': + out += '\r'; + break; + default: + out += *c; + } + } + else + { + out += *c; + } + } + return out; +} + +struct key_value +{ + std::string_view key; + std::string_view locale; + std::string_view value; + key_value(std::string_view l) + { + auto pos = l.find_first_of("[ ="); + if (pos == std::string_view::npos) + return; + key = l.substr(0, pos); + l = l.substr(pos); + if (l[0] == '[') + { + pos = l.find(']'); + if (pos == std::string_view::npos) + { + key = std::string_view(); + return; + } + locale = l.substr(1, pos - 1); + l = l.substr(pos + 1); + } + pos = l.find('='); + if (pos == std::string_view::npos) + { + key = std::string_view(); + locale = std::string_view(); + return; + } + l = l.substr(pos + 1); + pos = l.find_first_not_of(" "); + if (pos == std::string_view::npos) + { + key = std::string_view(); + locale = std::string_view(); + return; + } + value = l.substr(pos); + } +}; +std::optional do_desktop_entry(const std::filesystem::path & filename) +{ + auto data = read_file(filename); + std::optional res; + + // Most apps are not VR, don't bother parsing the rest + bool vr = false; + for (auto bounds: data | std::views::split('\n')) + { + std::string_view line(bounds.begin(), bounds.end()); + key_value items(line); + if (items.key == "X-WiVRn-VR") + vr = items.value == "true"; + } + if (not vr) + return res; + + res.emplace(); + for (auto bounds: data | std::views::split('\n')) + { + std::string_view line(bounds.begin(), bounds.end()); + if (line.empty()) + continue; + if (line.starts_with("#")) + continue; + + // Only process the main section + if (line.starts_with("[") and line != "[Desktop Entry]") + break; + + key_value items(line); + if (items.key == "Type" and items.value != "Application") + { + res.reset(); + return res; + } + if (items.key == "Name") + res->name.emplace(items.locale, unescape(items.value)); + if (items.key == "Exec") + res->exec = unescape(items.value); + if (items.key == "Path") + res->path = unescape(items.value); + } + + if (res->exec.empty() or not res->name.contains("")) + res.reset(); + + return res; +} + +void do_data_dir(std::filesystem::path dir, std::unordered_map & res) +{ + dir = dir / "applications"; + if (not std::filesystem::is_directory(dir)) + return; + for (const auto & entry: std::filesystem::recursive_directory_iterator(dir)) + { + if (entry.is_directory()) + continue; + + if (entry.path().extension() != ".desktop") + continue; + + // https://specifications.freedesktop.org/desktop-entry-spec/latest/file-naming.html#desktop-file-id + auto file_id = entry.path() + .lexically_relative(dir) + .replace_extension("") + .string(); + std::ranges::replace(file_id, '/', '-'); + + if (res.contains(file_id)) + continue; + + auto app = do_desktop_entry(entry.path()); + if (app) + res.emplace(std::move(file_id), std::move(*app)); + } +} +} // namespace + +std::unordered_map list_applications(bool include_steam) +{ + std::unordered_map res; + + if (include_steam) + read_steam_vr_apps(res); + + do_data_dir(xdg_data_home(), res); + for (auto && dir: xdg_data_dirs()) + do_data_dir(std::move(dir), res); + + return res; +} + +} // namespace wivrn diff --git a/common/application.h b/common/application.h new file mode 100644 index 00000000..33d97e8f --- /dev/null +++ b/common/application.h @@ -0,0 +1,37 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include + +namespace wivrn +{ + +struct application +{ + // localised names, with empty locale for default + std::unordered_map name; + std::string exec; + std::optional path; +}; + +std::unordered_map list_applications(bool include_steam = true); +} // namespace wivrn diff --git a/common/test_application.cpp b/common/test_application.cpp new file mode 100644 index 00000000..05e49335 --- /dev/null +++ b/common/test_application.cpp @@ -0,0 +1,42 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "application.h" + +#include + +int main() +{ + auto apps = wivrn::list_applications(); + + std::cout << "Parsed " << apps.size() << " applications" << std::endl; + for (const auto & [k, app]: apps) + { + std::cout << "======================" << std::endl; + std::cout << k << std::endl; + for (const auto & [locale, name]: app.name) + { + std::cout << "Name"; + if (not locale.empty()) + std::cout << "[" << locale << "]"; + std::cout << "=" << name << std::endl; + } + std::cout << "Exec=" << app.exec << std::endl; + if (app.path) + std::cout << "Path=" << *app.path << std::endl; + } +} From 8b42be80ee1aa43697851db5c555d35c925a004e Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 25 Jul 2025 14:04:39 +0200 Subject: [PATCH 04/10] Add flatpak permissions to enumerate applications --- common/application.cpp | 61 +++++++++++++++------------- flatpak/io.github.wivrn.wivrn.yml.in | 5 +++ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/common/application.cpp b/common/application.cpp index caa610fb..c55b381a 100644 --- a/common/application.cpp +++ b/common/application.cpp @@ -34,29 +34,21 @@ namespace std::string read_file(const std::filesystem::path & path) { -#if 0 - if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk") - { - QProcess flatpak_spawn; - flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(vrmanifest)}); - flatpak_spawn.waitForFinished(); - return flatpak_spawn.readAllStandardOutput().toStdString(); - } - else -#endif - { - std::ifstream f(path); - std::istreambuf_iterator begin{f}, end; + std::ifstream f(path); + std::istreambuf_iterator begin{f}, end; - return {begin, end}; - } + return {begin, end}; } std::string read_vr_manifest() { - const char * home = getenv("HOME"); - - return read_file(std::string{home ? home : ""} + "/.steam/steam/config/steamapps.vrmanifest"); + // try system Steam + auto manifest = read_file(xdg_data_home() / "Steam/config/steamapps.vrmanifest"); + if (not manifest.empty()) + return manifest; + // Flatpak Steam + auto home = std::getenv("HOME"); + return read_file(std::filesystem::path(home ? home : "") / ".var/app/com.valvesoftware.Steam/.steam/steam/config/steamapps.vrmanifest"); } void read_steam_vr_apps(std::unordered_map & res) @@ -190,6 +182,17 @@ struct key_value value = l.substr(pos); } }; + +bool contains(std::string_view entries, std::string_view val, char sep = ';') +{ + for (auto bounds: entries | std::views::split(sep)) + { + if (std::string_view(bounds.begin(), bounds.end()) == val) + return true; + } + return false; +} + std::optional do_desktop_entry(const std::filesystem::path & filename) { auto data = read_file(filename); @@ -200,9 +203,9 @@ std::optional do_desktop_entry(const std::filesystem::path & filena for (auto bounds: data | std::views::split('\n')) { std::string_view line(bounds.begin(), bounds.end()); - key_value items(line); - if (items.key == "X-WiVRn-VR") - vr = items.value == "true"; + key_value item(line); + if (item.key == "Categories") + vr = contains(item.value, "X-WiVRn-VR"); } if (not vr) return res; @@ -220,18 +223,18 @@ std::optional do_desktop_entry(const std::filesystem::path & filena if (line.starts_with("[") and line != "[Desktop Entry]") break; - key_value items(line); - if (items.key == "Type" and items.value != "Application") + key_value item(line); + if (item.key == "Type" and item.value != "Application") { res.reset(); return res; } - if (items.key == "Name") - res->name.emplace(items.locale, unescape(items.value)); - if (items.key == "Exec") - res->exec = unescape(items.value); - if (items.key == "Path") - res->path = unescape(items.value); + if (item.key == "Name") + res->name.emplace(item.locale, unescape(item.value)); + if (item.key == "Exec") + res->exec = unescape(item.value); + if (item.key == "Path") + res->path = unescape(item.value); } if (res->exec.empty() or not res->name.contains("")) diff --git a/flatpak/io.github.wivrn.wivrn.yml.in b/flatpak/io.github.wivrn.wivrn.yml.in index f0fcb9dc..a4ee6eef 100644 --- a/flatpak/io.github.wivrn.wivrn.yml.in +++ b/flatpak/io.github.wivrn.wivrn.yml.in @@ -23,6 +23,11 @@ finish-args: - --system-talk-name=org.freedesktop.Avahi # Allow getting the pretty hostname - --system-talk-name=org.freedesktop.hostname1 + # List applications from $XDG_DATA_DIRS + - --filesystem=host-os:ro + - --filesystem=xdg-data:ro + # List flatpak Steam games + - --filesystem=~/.var/app/com.valvesoftware.Steam:ro # Pipewire - --filesystem=xdg-run/pipewire-0 # Set the active OpenXR / OpenVR runtime From 74ea5cfe19da0965a03800593ca7e156bba17f13 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 25 Jul 2025 15:30:40 +0200 Subject: [PATCH 05/10] Support flatpak Steam --- common/application.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/common/application.cpp b/common/application.cpp index c55b381a..1097cee9 100644 --- a/common/application.cpp +++ b/common/application.cpp @@ -21,10 +21,10 @@ #include "utils/xdg_base_directory.h" -#include - #include #include +#include +#include namespace wivrn { @@ -40,20 +40,24 @@ std::string read_file(const std::filesystem::path & path) return {begin, end}; } -std::string read_vr_manifest() +std::pair read_vr_manifest() { - // try system Steam + // system Steam auto manifest = read_file(xdg_data_home() / "Steam/config/steamapps.vrmanifest"); if (not manifest.empty()) - return manifest; + return {"steam", manifest}; + // Flatpak Steam auto home = std::getenv("HOME"); - return read_file(std::filesystem::path(home ? home : "") / ".var/app/com.valvesoftware.Steam/.steam/steam/config/steamapps.vrmanifest"); + manifest = read_file(std::filesystem::path(home ? home : "") / ".var/app/com.valvesoftware.Steam/.steam/steam/config/steamapps.vrmanifest"); + if (not manifest.empty()) + return {"flatpak run com.valvesoftware.Steam", manifest}; + return {}; } void read_steam_vr_apps(std::unordered_map & res) { - auto manifest = read_vr_manifest(); + auto [command, manifest] = read_vr_manifest(); if (manifest.empty()) return; nlohmann::json json = nlohmann::json::parse(manifest); @@ -82,7 +86,7 @@ void read_steam_vr_apps(std::unordered_map & res) if (i["launch_type"] == "url") { - app.exec = "steam " + (std::string)i["url"]; + app.exec = command + " " + (std::string)i["url"]; } else if (i["launch_type"] == "binary") { @@ -91,15 +95,16 @@ void read_steam_vr_apps(std::unordered_map & res) { // ¯\_(ツ)_/¯ uint64_t appkey = stoll(app_key.substr(strlen(prefix))); - app.exec = "steam steam://rungameid/" + std::to_string((appkey << 32) + 0x2000000); + app.exec = command + " steam://rungameid/" + std::to_string((appkey << 32) + 0x2000000); } } if (not app.exec.empty()) res[app_key] = std::move(app); } - catch (std::exception &) + catch (std::exception & e) { + std::cerr << "Failed to parse Steam VR manifest: " << e.what() << std::endl; } } } From f0e625e095cddb7bed651aba6243123da160e0b8 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 25 Jul 2025 15:53:29 +0200 Subject: [PATCH 06/10] don't build application list binary --- common/CMakeLists.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 9313a5e6..75e0e464 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -24,14 +24,14 @@ endif() configure_file(wivrn_config.h.in wivrn_config.h) add_library(wivrn-common-base STATIC - utils/xdg_base_directory.cpp + application.cpp utils/flatpak.cpp utils/strings.cpp + utils/xdg_base_directory.cpp ${CMAKE_CURRENT_BINARY_DIR}/version.cpp ) add_library(wivrn-common STATIC - application.cpp crypto.cpp smp.cpp secrets.cpp @@ -44,10 +44,13 @@ add_library(wivrn-common STATIC vk/vk_mem_alloc.cpp ) -add_executable(list-apps - test_application.cpp -) -target_link_libraries(list-apps wivrn-common) +if (TEST_APPS) + add_executable(list-apps + test_application.cpp + ) + + target_link_libraries(list-apps wivrn-common-base) +endif() if(ANDROID) # The Vulkan headers in Android do not include the C++ headers, download them From 6f039a6bac38b376bd527fdd23d9943e7df9da2b Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 25 Jul 2025 15:54:41 +0200 Subject: [PATCH 07/10] Use common app list for dashboard --- dashboard/CMakeLists.txt | 2 +- dashboard/apps.cpp | 43 +++++++++++ dashboard/{steam_apps.h => apps.h} | 46 ++++-------- dashboard/qml/SelectGame.qml | 11 ++- dashboard/steam_apps.cpp | 112 ----------------------------- 5 files changed, 63 insertions(+), 151 deletions(-) create mode 100644 dashboard/apps.cpp rename dashboard/{steam_apps.h => apps.h} (63%) delete mode 100644 dashboard/steam_apps.cpp diff --git a/dashboard/CMakeLists.txt b/dashboard/CMakeLists.txt index bdb0bb9a..78d7e4b5 100644 --- a/dashboard/CMakeLists.txt +++ b/dashboard/CMakeLists.txt @@ -10,7 +10,7 @@ add_executable(wivrn-dashboard main.cpp wivrn_server.cpp wivrn_qdbus_types.cpp - steam_apps.cpp + apps.cpp escape_string.cpp settings.cpp rectangle_partitionner.cpp diff --git a/dashboard/apps.cpp b/dashboard/apps.cpp new file mode 100644 index 00000000..2ab62820 --- /dev/null +++ b/dashboard/apps.cpp @@ -0,0 +1,43 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 Guillaume Meunier + * Copyright (C) 2025 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "apps.h" + +#include "application.h" + +#include + +Apps::Apps(QObject * parent) +{ + auto apps = wivrn::list_applications(); + + for (const auto & [id, app]: apps) + { + m_apps.push_back( + vrApp( + QString::fromStdString(app.name.at("")), + QString::fromStdString(app.exec))); + } + + std::ranges::sort(m_apps, [](const vrApp & a, const vrApp & b) { + return a.name() < b.name(); + }); +} + +#include "moc_apps.cpp" diff --git a/dashboard/steam_apps.h b/dashboard/apps.h similarity index 63% rename from dashboard/steam_apps.h rename to dashboard/apps.h index 91e6b9ee..d62bcdaa 100644 --- a/dashboard/steam_apps.h +++ b/dashboard/apps.h @@ -1,6 +1,7 @@ /* * WiVRn VR streaming * Copyright (C) 2024 Guillaume Meunier + * Copyright (C) 2025 Patrick Nicolas * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,37 +22,30 @@ #include #include -class steamApp +class vrApp { Q_GADGET - QML_VALUE_TYPE(steamApp) + QML_VALUE_TYPE(vrApp) Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath) Q_PROPERTY(QString command READ command WRITE setCommand) QString m_name; - QString m_imagePath; QString m_command; public: - steamApp() = default; - steamApp(const steamApp &) = default; - steamApp(steamApp &&) = default; - steamApp & operator=(const steamApp &) = default; - steamApp & operator=(steamApp &&) = default; - steamApp(QString name, QString imagePath, QString command) : - m_name(name), m_imagePath(imagePath), m_command(command) {} + vrApp() = default; + vrApp(const vrApp &) = default; + vrApp(vrApp &&) = default; + vrApp & operator=(const vrApp &) = default; + vrApp & operator=(vrApp &&) = default; + vrApp(QString name, QString command) : + m_name(name), m_command(command) {} QString name() const { return m_name; } - QString imagePath() const - { - return m_imagePath; - } - QString command() const { return m_command; @@ -62,11 +56,6 @@ public: m_name = value; } - void setImagePath(QString value) - { - m_imagePath = value; - } - void setCommand(QString value) { m_command = value; @@ -77,30 +66,25 @@ public: m_name = QString::fromStdString(value); } - void setImagePath(const std::string & value) - { - m_imagePath = QString::fromStdString(value); - } - void setCommand(const std::string & value) { m_command = QString::fromStdString(value); } }; -class SteamApps : public QObject +class Apps : public QObject { Q_OBJECT QML_ELEMENT QML_SINGLETON - Q_PROPERTY(QList apps READ apps) - QList m_apps; + Q_PROPERTY(QList apps READ apps) + QList m_apps; public: - SteamApps(QObject * parent = nullptr); + Apps(QObject * parent = nullptr); - const QList & apps() const + const QList & apps() const { return m_apps; } diff --git a/dashboard/qml/SelectGame.qml b/dashboard/qml/SelectGame.qml index 36807b47..f3ad522d 100644 --- a/dashboard/qml/SelectGame.qml +++ b/dashboard/qml/SelectGame.qml @@ -12,24 +12,21 @@ ColumnLayout { Component.onCompleted: { apps.append({ "name": i18nc("don't start an application automatically", "None"), - "image_path": "", "command": "", "is_custom": false }); apps.append({ "name": i18nc("choose a custom application to start", "Custom"), - "image_path": "", "command": "", "is_custom": true }); - var steam_apps = SteamApps.apps; - for (var i = 0; i < steam_apps.length; i++) { + var vr_apps = Apps.apps; + for (var i = 0; i < vr_apps.length; i++) { apps.append({ - "name": steam_apps[i].name, - "image_path": steam_apps[i].imagePath, - "command": steam_apps[i].command, + "name": vr_apps[i].name, + "command": vr_apps[i].command, "is_custom": false }); } diff --git a/dashboard/steam_apps.cpp b/dashboard/steam_apps.cpp deleted file mode 100644 index 0fd18ed4..00000000 --- a/dashboard/steam_apps.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "steam_apps.h" -#include "escape_string.h" -#include "utils/flatpak.h" -#include -#include -#include -#include -#include - -namespace -{ -std::string read_vr_manifest() -{ - const char * home = getenv("HOME"); - - std::filesystem::path vrmanifest = std::string{home ? home : ""} + "/.steam/steam/config/steamapps.vrmanifest"; - - if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk") - { - QProcess flatpak_spawn; - flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(vrmanifest)}); - flatpak_spawn.waitForFinished(); - return flatpak_spawn.readAllStandardOutput().toStdString(); - } - else - { - std::ifstream f(vrmanifest); - std::istreambuf_iterator begin{f}, end; - - return {begin, end}; - } -} -} // namespace - -SteamApps::SteamApps(QObject * parent) -{ - auto manifest = read_vr_manifest(); - if (manifest.empty()) - { - return; - } - - nlohmann::json json; - try - { - json = nlohmann::json::parse(manifest); - } - catch (std::exception & e) - { - qWarning() << "Error parsing VR manifest: " << e.what(); - return; - } - - for (auto & i: json["applications"]) - { - try - { - steamApp app; - - app.setImagePath(i.value("image_path", "")); - app.setName(i["strings"]["en_us"]["name"]); - - if (i["launch_type"] == "url") - { - app.setCommand("steam " + (std::string)i["url"]); - } - else if (i["launch_type"] == "binary") - { - std::string app_key = i["app_key"]; - - const char prefix[] = "steam.app."; - if (app_key.starts_with(prefix)) - { - // ¯\_(ツ)_/¯ - uint64_t appkey = stoll(app_key.substr(strlen(prefix))); - app.setCommand("steam steam://rungameid/" + std::to_string((appkey << 32) + 0x2000000)); - } - } - - if (app.command() != "") - m_apps.push_back(app); - } - catch (std::exception & e) - { - qWarning() << "Error adding app from VR manifest: " << e.what(); - } - } - - std::ranges::sort(m_apps, [](const steamApp & a, const steamApp & b) { - return a.name() < b.name(); - }); -} - -#include "moc_steam_apps.cpp" From e414c82d6c492d17d290e5a2680e4004ba5680ee Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 25 Jul 2025 17:47:21 +0200 Subject: [PATCH 08/10] Access real .local/share from flatpak --- common/application.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/common/application.cpp b/common/application.cpp index 1097cee9..387196cf 100644 --- a/common/application.cpp +++ b/common/application.cpp @@ -40,6 +40,12 @@ std::string read_file(const std::filesystem::path & path) return {begin, end}; } +std::filesystem::path home() +{ + auto home = std::getenv("HOME"); + return home ? home : ""; +} + std::pair read_vr_manifest() { // system Steam @@ -47,9 +53,15 @@ std::pair read_vr_manifest() if (not manifest.empty()) return {"steam", manifest}; + auto h = home(); + + // system Steam (accessed from flatpak) + manifest = read_file(h / ".local/share/Steam/config/steamapps.vrmanifest"); + if (not manifest.empty()) + return {"steam", manifest}; + // Flatpak Steam - auto home = std::getenv("HOME"); - manifest = read_file(std::filesystem::path(home ? home : "") / ".var/app/com.valvesoftware.Steam/.steam/steam/config/steamapps.vrmanifest"); + manifest = read_file(h / ".var/app/com.valvesoftware.Steam/.steam/steam/config/steamapps.vrmanifest"); if (not manifest.empty()) return {"flatpak run com.valvesoftware.Steam", manifest}; return {}; From 62894b178ddc59044e9eaa2ffcf77f5982f675f6 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 25 Jul 2025 17:55:33 +0200 Subject: [PATCH 09/10] Read host /usr/share/applications in flatpak --- common/application.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/application.cpp b/common/application.cpp index 387196cf..ccd888e5 100644 --- a/common/application.cpp +++ b/common/application.cpp @@ -19,6 +19,7 @@ #include "application.h" +#include "utils/flatpak.h" #include "utils/xdg_base_directory.h" #include @@ -300,6 +301,11 @@ std::unordered_map list_applications(bool include_stea do_data_dir(xdg_data_home(), res); for (auto && dir: xdg_data_dirs()) do_data_dir(std::move(dir), res); + if (wivrn::is_flatpak()) + { + // Try to guess host data dirs + do_data_dir("/run/host/usr/share", res); + } return res; } From a69bd596d16d3cbc370ccd1523b9835308a6c744 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 25 Jul 2025 21:01:55 +0200 Subject: [PATCH 10/10] Add common-server CMake library --- CMakeLists.txt | 1 + common/CMakeLists.txt | 24 ++++++++++++++---------- dashboard/CMakeLists.txt | 1 + server/CMakeLists.txt | 1 + 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a576ba3..7ab8c54b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ option(WIVRN_BUILD_SERVER_LIBRARY "Build OpenXR library for WiVRn server" ${WIVR option(WIVRN_BUILD_DASHBOARD "Build WiVRn dashboard" OFF) option(WIVRN_BUILD_WIVRNCTL "Build wivrnctl" ON) option(WIVRN_BUILD_DISSECTOR "Build Wireshark dissector" OFF) +option(WIVRN_BUILD_TEST "Build test binaries" OFF) option(WIVRN_WERROR "Treat warnings as errors" OFF) option(WIVRN_USE_NVENC "Enable nvenc (Nvidia) hardware encoder" ON) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 75e0e464..a606adda 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -23,20 +23,17 @@ endif() configure_file(wivrn_config.h.in wivrn_config.h) -add_library(wivrn-common-base STATIC - application.cpp - utils/flatpak.cpp +add_library(wivrn-common-base STATIC EXCLUDE_FROM_ALL utils/strings.cpp utils/xdg_base_directory.cpp ${CMAKE_CURRENT_BINARY_DIR}/version.cpp ) -add_library(wivrn-common STATIC +add_library(wivrn-common STATIC EXCLUDE_FROM_ALL crypto.cpp smp.cpp secrets.cpp wivrn_sockets.cpp - utils/xdg_base_directory.cpp utils/strings.cpp vk/allocation.cpp vk/error_category.cpp @@ -44,12 +41,20 @@ add_library(wivrn-common STATIC vk/vk_mem_alloc.cpp ) -if (TEST_APPS) - add_executable(list-apps - test_application.cpp +if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER) + add_library(wivrn-common-server STATIC EXCLUDE_FROM_ALL + utils/flatpak.cpp + application.cpp ) + target_link_libraries(wivrn-common-server PRIVATE nlohmann_json::nlohmann_json PUBLIC wivrn-common-base) - target_link_libraries(list-apps wivrn-common-base) + if (WIVRN_BUILD_TEST) + add_executable(list-apps + test_application.cpp + ) + + target_link_libraries(list-apps wivrn-common-server) + endif() endif() if(ANDROID) @@ -122,5 +127,4 @@ endif() target_include_directories(wivrn-common-base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(wivrn-common PUBLIC Boost::pfr OpenSSL::Crypto wivrn-external wivrn-common-base) -target_compile_features(wivrn-common PRIVATE cxx_std_20) target_compile_definitions(wivrn-common PUBLIC VULKAN_HPP_NO_STRUCT_CONSTRUCTORS) diff --git a/dashboard/CMakeLists.txt b/dashboard/CMakeLists.txt index 78d7e4b5..b224366e 100644 --- a/dashboard/CMakeLists.txt +++ b/dashboard/CMakeLists.txt @@ -68,6 +68,7 @@ target_link_libraries(wivrn-dashboard QCoro::Network QCoro::Qml wivrn-common-base + wivrn-common-server wivrn-external ) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 3a9d83e9..09fa50f6 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -218,6 +218,7 @@ if (WIVRN_BUILD_SERVER) PkgConfig::AVAHI Eigen3::Eigen wivrn-common + wivrn-common-server wivrn-external nlohmann_json::nlohmann_json )