From 1b78180d734d5eb52276c0cea2e48d991f6befd6 Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Tue, 5 Aug 2025 21:33:19 +0200 Subject: [PATCH] Send app icons one by one --- client/scenes/lobby_gui.cpp | 6 ++-- client/scenes/stream.h | 11 +++++- client/scenes/stream_network.cpp | 20 ++++++++++- common/application.cpp | 59 +++++++++++++++----------------- common/application.h | 6 ++-- common/wivrn_packets.h | 12 +++++-- dashboard/apps.cpp | 2 +- server/driver/wivrn_session.cpp | 22 ++++++++++-- 8 files changed, 91 insertions(+), 47 deletions(-) diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 0036cbe1..eb4853c1 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -400,7 +400,7 @@ void scenes::lobby::gui_connected() auto apps = next_scene->get_applications(); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20}); - if (apps->applications.empty()) + if (apps->empty()) { CenterTextHV(_("Start an application on the server to start streaming.")); } @@ -426,7 +426,7 @@ void scenes::lobby::gui_connected() ImGui::Indent((usable_window_width - icon_line_width) / 2); auto t0 = std::chrono::steady_clock::now(); - for (const auto [index, app]: utils::enumerate(apps->applications)) + for (const auto [index, app]: utils::enumerate(*apps)) { ImTextureID texture = [&]() -> ImTextureID { if (app.image.empty()) @@ -470,7 +470,7 @@ void scenes::lobby::gui_connected() std::vector> to_be_removed; for (const auto & [app_id, app_icon]: app_icons) { - if (not std::ranges::contains(apps->applications, app_id, &to_headset::application_list::application::id)) + if (not std::ranges::contains(*apps, app_id, &scenes::stream::app::id)) to_be_removed.emplace_back(app_id, app_icon); } for (const auto & [app_id, app_icon]: to_be_removed) diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 6f506ab7..aa28435a 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -21,6 +21,7 @@ #include "audio/audio.h" #include "decoder/shard_accumulator.h" +#include "imgui.h" #include "render/imgui_impl.h" #include "scene.h" #include "scenes/input_profile.h" @@ -48,6 +49,13 @@ public: }; static const size_t image_buffer_size = 3; + struct app + { + std::string id; + std::string name; + std::vector image; + }; + private: static const size_t view_count = 2; @@ -176,7 +184,7 @@ private: std::vector> current_blit_handles; // Last application list received from server - thread_safe applications; + thread_safe> applications; stream(); @@ -202,6 +210,7 @@ public: void operator()(to_headset::video_stream_description &&); void operator()(to_headset::refresh_rate_change &&); void operator()(to_headset::application_list &&); + void operator()(to_headset::application_icon &&); void operator()(audio_data &&); void push_blit_handle(wivrn::shard_accumulator * decoder, std::shared_ptr handle); diff --git a/client/scenes/stream_network.cpp b/client/scenes/stream_network.cpp index cc8201d5..d93601d6 100644 --- a/client/scenes/stream_network.cpp +++ b/client/scenes/stream_network.cpp @@ -111,8 +111,26 @@ void scenes::stream::operator()(to_headset::application_list && apps) std::ranges::sort(apps.applications, [](auto & l, auto & r) { return una::casesens::collate_utf8(l.name, r.name) < 0; }); + auto locked = applications.lock(); - *locked = std::move(apps); + + locked->clear(); + locked->reserve(apps.applications.size()); + for (const auto & i: apps.applications) + { + locked->push_back(app{ + .id = std::move(i.id), + .name = std::move(i.name), + }); + } +} + +void scenes::stream::operator()(to_headset::application_icon && icon) +{ + auto locked = applications.lock(); + + if (auto it = std::ranges::find(*locked, icon.id, &app::id); it != locked->end()) + it->image = std::move(icon.image); } void scenes::stream::start_application(std::string appid) diff --git a/common/application.cpp b/common/application.cpp index c4b2bc6a..0e8f6e8c 100644 --- a/common/application.cpp +++ b/common/application.cpp @@ -20,7 +20,6 @@ #include "application.h" #include "utils/flatpak.h" -#include "utils/load_icon.h" #include "utils/steam_app_info.h" #include "utils/xdg_base_directory.h" #include "utils/xdg_icon_lookup.h" @@ -85,17 +84,17 @@ steam_app_info read_steam_app_info(const std::filesystem::path & root) return {}; } -std::vector load_steam_icon(const std::filesystem::path & root, int app_id, const steam_app_info & info) +std::filesystem::path find_steam_icon(const std::filesystem::path & root, int app_id, const steam_app_info & info) { const auto & app_info = info.get(app_id); try { std::string icon{std::get(app_info.at("common.clienticon"))}; + auto icon_path = root / "steam/games" / (icon + ".ico"); - auto image = load_icon(root / "steam/games" / (icon + ".ico"), 128); - if (not image.empty()) - return image; + if (std::filesystem::exists(icon_path)) + return icon_path; } catch (...) { @@ -105,9 +104,10 @@ std::vector load_steam_icon(const std::filesystem::path & root, int a { std::string icon{std::get(app_info.at("common.LinuxClientIcon"))}; - auto image = load_icon(root / "steam/games" / (icon + ".zip"), 128); - if (not image.empty()) - return image; + auto icon_path = root / "steam/games" / (icon + ".zip"); + + if (std::filesystem::exists(icon_path)) + return icon_path; } catch (...) { @@ -116,7 +116,7 @@ std::vector load_steam_icon(const std::filesystem::path & root, int a return {}; } -void read_steam_vr_apps(std::unordered_map & res, bool load_icons) +void read_steam_vr_apps(std::unordered_map & res) { auto [command, root] = find_steam(); if (not root) @@ -166,21 +166,18 @@ void read_steam_vr_apps(std::unordered_map & res, bool } } - if (load_icons) + try { - try - { - const char prefix[] = "steam.app."; - if (app_key.starts_with(prefix)) - { - uint32_t app_id = stoll(app_key.substr(strlen(prefix))); - app.image = load_steam_icon(*root, app_id, info); - } - } - catch (...) + const char prefix[] = "steam.app."; + if (app_key.starts_with(prefix)) { + uint32_t app_id = stoll(app_key.substr(strlen(prefix))); + app.icon_path = find_steam_icon(*root, app_id, info); } } + catch (...) + { + } if (not app.exec.empty()) res[app_key] = std::move(app); @@ -281,7 +278,7 @@ bool contains(std::string_view entries, std::string_view val, char sep = ';') return false; } -std::optional do_desktop_entry(const std::filesystem::path & filename, bool load_icons) +std::optional do_desktop_entry(const std::filesystem::path & filename) { auto data = read_file(filename); std::optional res; @@ -323,12 +320,11 @@ std::optional do_desktop_entry(const std::filesystem::path & filena res->exec = unescape(item.value); if (item.key == "Path") res->path = unescape(item.value); - if (item.key == "Icon" and load_icons) + if (item.key == "Icon") { try { - if (auto filename = xdg_icon_lookup(std::string{item.value}, 256)) - res->image = load_icon(*filename, 256); + res->icon_path = xdg_icon_lookup(std::string{item.value}, 256); } catch (...) {} @@ -341,7 +337,7 @@ std::optional do_desktop_entry(const std::filesystem::path & filena return res; } -void do_data_dir(std::filesystem::path dir, std::unordered_map & res, bool load_icons) +void do_data_dir(std::filesystem::path dir, std::unordered_map & res) { dir = dir / "applications"; if (not std::filesystem::is_directory(dir)) @@ -364,29 +360,28 @@ void do_data_dir(std::filesystem::path dir, std::unordered_map list_applications(bool include_steam, bool load_icons) +std::unordered_map list_applications() { std::unordered_map res; - if (include_steam) - read_steam_vr_apps(res, load_icons); + read_steam_vr_apps(res); - do_data_dir(xdg_data_home(), res, load_icons); + do_data_dir(xdg_data_home(), res); for (auto && dir: xdg_data_dirs()) - do_data_dir(std::move(dir), res, load_icons); + 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, load_icons); + do_data_dir("/run/host/usr/share", res); } return res; diff --git a/common/application.h b/common/application.h index 38961247..91c051fd 100644 --- a/common/application.h +++ b/common/application.h @@ -18,10 +18,10 @@ #pragma once +#include #include #include #include -#include namespace wivrn { @@ -31,9 +31,9 @@ struct application // localised names, with empty locale for default std::unordered_map name; std::string exec; - std::vector image; // In PNG + std::optional icon_path; std::optional path; }; -std::unordered_map list_applications(bool include_steam = true, bool load_icons = true); +std::unordered_map list_applications(); } // namespace wivrn diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 1c40219c..919d3b41 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -41,7 +41,7 @@ namespace wivrn // Default port for server to listen, both TCP and UDP static const int default_port = 9757; -static constexpr int protocol_revision = 2; +static constexpr int protocol_revision = 1; enum class device_id : uint8_t { @@ -675,11 +675,16 @@ struct application_list { std::string id; std::string name; - std::vector image; // In PNG }; std::vector applications; }; +struct application_icon +{ + std::string id; + std::vector image; // In PNG +}; + using packets = std::variant< crypto_handshake, pin_check_2, @@ -693,6 +698,7 @@ using packets = std::variant< timesync_query, tracking_control, refresh_rate_change, - application_list>; + application_list, + application_icon>; } // namespace to_headset } // namespace wivrn diff --git a/dashboard/apps.cpp b/dashboard/apps.cpp index fe24bfa9..2ab62820 100644 --- a/dashboard/apps.cpp +++ b/dashboard/apps.cpp @@ -25,7 +25,7 @@ Apps::Apps(QObject * parent) { - auto apps = wivrn::list_applications(true /* Include steam apps */, false /* Don't load icons */); + auto apps = wivrn::list_applications(); for (const auto & [id, app]: apps) { diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 6954eb45..45d21178 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -28,6 +28,7 @@ #include "util/u_builders.h" #include "util/u_logging.h" #include "util/u_system.h" +#include "utils/load_icon.h" #include "utils/scoped_lock.h" #include "audio/audio_setup.h" @@ -734,15 +735,30 @@ void wivrn_session::operator()(from_headset::get_application_list && request) .country = std::move(request.country), .variant = std::move(request.variant), }; - for (auto && [id, app]: list_applications()) + + auto apps = list_applications(); + + for (const auto & [id, app]: apps) { response.applications.emplace_back( std::move(id), // FIXME: use locale - app.name.at(""), - app.image); + app.name.at("")); } send_control(std::move(response)); + + for (const auto & [id, app]: apps) + { + if (app.icon_path) + { + auto icon = load_icon(*app.icon_path, 256); + + send_control(to_headset::application_icon{ + .id = id, + .image = std::move(icon), + }); + } + } } void wivrn_session::operator()(const from_headset::start_app & request)