From c44940d0048aba9adeca13623662af5b9138d78a Mon Sep 17 00:00:00 2001 From: caszuu Date: Fri, 20 Feb 2026 16:22:31 +0100 Subject: [PATCH] add server messages (with toasts!) --- client/constants.h | 3 +++ client/scenes/stream.h | 12 +++++++++- client/scenes/stream_gui.cpp | 40 +++++++++++++++++++++++++++++--- client/scenes/stream_network.cpp | 14 +++++++++++ common/wivrn_packets.h | 13 +++++++++++ server/driver/wivrn_session.cpp | 7 +++++- 6 files changed, 84 insertions(+), 5 deletions(-) diff --git a/client/constants.h b/client/constants.h index 6b7ef91b..e4ed260e 100644 --- a/client/constants.h +++ b/client/constants.h @@ -117,6 +117,9 @@ namespace constants::stream constexpr float fade_delay = 3; constexpr float fade_duration = 0.25; +constexpr float urgent_fade_delay = 5; +constexpr ImVec4 urgent_border_color = {8.f, .6f, 0.f, .8f}; + // Dimming for the streamed video when the GUI is interactable constexpr float dimming_scale = 0.4; constexpr float dimming_bias = 0.01; diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 47e56a50..e83f1bc0 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -134,14 +134,22 @@ private: application_launcher, }; + struct gui_toast + { + std::string current_toast; + bool is_urgent = false; + }; + bool is_gui_interactable() const; std::atomic gui_status = gui_status::hidden; enum gui_status last_gui_status = gui_status::hidden; enum gui_status next_gui_status = gui_status::applications; - XrTime gui_status_last_change; float dimming = 0; + thread_safe> gui_toast; + std::atomic gui_status_last_change; + XrAction plots_toggle_1 = XR_NULL_HANDLE; XrAction plots_toggle_2 = XR_NULL_HANDLE; XrAction recenter_left = XR_NULL_HANDLE; @@ -198,6 +206,7 @@ public: void operator()(to_headset::pin_check_2 &&) {}; void operator()(to_headset::pin_check_4 &&) {}; void operator()(to_headset::handshake &&) {}; + void operator()(to_headset::server_message &&); void operator()(to_headset::video_stream_data_shard &&); void operator()(to_headset::haptics &&); void operator()(to_headset::timesync_query &&); @@ -312,6 +321,7 @@ private: void gui_bitrate_settings(float predicted_display_period); void gui_foveation_settings(float predicted_display_period); void gui_applications(); + void gui_toasts(); void draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period); }; } // namespace scenes diff --git a/client/scenes/stream_gui.cpp b/client/scenes/stream_gui.cpp index a3850c21..b4fa3477 100644 --- a/client/scenes/stream_gui.cpp +++ b/client/scenes/stream_gui.cpp @@ -729,6 +729,19 @@ void scenes::stream::gui_applications() ImGui::PopStyleVar(3); } +void scenes::stream::gui_toasts() +{ + auto toast = gui_toast.lock(); + + if (!toast->has_value()) + { + ImGui::Text("%s", _S("Press both thumbsticks to display the WiVRn window")); + return; + } + + ImGui::Text("%s", (*toast)->current_toast.c_str()); +} + void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period) { if (not(plots_toggle_1 and plots_toggle_2)) @@ -788,14 +801,23 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte } float alpha = 1; + bool is_urgent = false; if (gui_status == gui_status::hidden) { - float t = (predicted_display_time - gui_status_last_change) * 1.e-9f; + auto toast = gui_toast.lock(); + if (toast->has_value()) + is_urgent = (*toast)->is_urgent; - alpha = std::clamp(1 - (t - constants::stream::fade_delay) / constants::stream::fade_duration, 0, 1); + float t = (predicted_display_time - gui_status_last_change) * 1.e-9f; + float delay = is_urgent ? constants::stream::urgent_fade_delay : constants::stream::fade_delay; + + alpha = std::clamp(1 - (t - delay) / constants::stream::fade_duration, 0, 1); if (alpha == 0) + { + toast->reset(); return; + } } // Lock the GUI position to the head, do it before displaying the GUI to avoid being off by one frame when gui_status changes @@ -879,6 +901,12 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte break; } + if (is_urgent) + { + ImGui::PushStyleColor(ImGuiCol_Border, constants::stream::urgent_border_color); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 4); + } + ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0); if (always_auto_resize) { @@ -891,13 +919,19 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte ImGui::Begin("Stream settings", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove); } + if (is_urgent) + { + ImGui::PopStyleColor(1); + ImGui::PopStyleVar(1); + } + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {8, 8}); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10); switch (gui_status) { case gui_status::hidden: - ImGui::Text("%s", _S("Press both thumbsticks to display the WiVRn window")); + gui_toasts(); break; case gui_status::overlay_only: diff --git a/client/scenes/stream_network.cpp b/client/scenes/stream_network.cpp index 80662b5d..5f772879 100644 --- a/client/scenes/stream_network.cpp +++ b/client/scenes/stream_network.cpp @@ -47,6 +47,20 @@ void scenes::stream::process_packets() } } +void scenes::stream::operator()(to_headset::server_message && message) +{ + switch (message.kind) + { + case to_headset::server_message::kind::stream_toast: + case to_headset::server_message::kind::stream_toast_urgent: + auto toast = gui_toast.lock(); + toast->emplace(message.msg, message.kind == to_headset::server_message::kind::stream_toast_urgent); + + gui_status_last_change = instance.now(); + break; + } +} + void scenes::stream::operator()(to_headset::video_stream_data_shard && shard) { std::shared_lock lock(decoder_mutex); diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 1c1bd555..578ac5cc 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -608,6 +608,18 @@ struct handshake int stream_port; }; +struct server_message +{ + enum class kind : uint8_t + { + stream_toast, + stream_toast_urgent, + }; + + kind kind; + std::string msg; +}; + struct foveation_parameter { // The number of source pixels for each ratio, @@ -766,6 +778,7 @@ using packets = std::variant< pin_check_2, pin_check_4, handshake, + server_message, audio_stream_description, video_stream_description, audio_data, diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 0a1ca22e..f9e91709 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -1192,8 +1192,13 @@ void wivrn_session::reconnect(std::stop_token stop) if (warn_conn) { - // FIXME: show a warning pop-up on the client-side U_LOG_W("Session resumed with outdated settings. Restart the server for settings to apply."); + + // TODO: add server-side localization + send_control(to_headset::server_message{ + .kind = to_headset::server_message::kind::stream_toast_urgent, + .msg = "Stream resumed with outdated settings. Restart the server for settings to apply.", + }); } // update headset info