add server messages (with toasts!)
This commit is contained in:
@@ -117,6 +117,9 @@ namespace constants::stream
|
|||||||
constexpr float fade_delay = 3;
|
constexpr float fade_delay = 3;
|
||||||
constexpr float fade_duration = 0.25;
|
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
|
// Dimming for the streamed video when the GUI is interactable
|
||||||
constexpr float dimming_scale = 0.4;
|
constexpr float dimming_scale = 0.4;
|
||||||
constexpr float dimming_bias = 0.01;
|
constexpr float dimming_bias = 0.01;
|
||||||
|
|||||||
+11
-1
@@ -134,14 +134,22 @@ private:
|
|||||||
application_launcher,
|
application_launcher,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct gui_toast
|
||||||
|
{
|
||||||
|
std::string current_toast;
|
||||||
|
bool is_urgent = false;
|
||||||
|
};
|
||||||
|
|
||||||
bool is_gui_interactable() const;
|
bool is_gui_interactable() const;
|
||||||
|
|
||||||
std::atomic<gui_status> gui_status = gui_status::hidden;
|
std::atomic<gui_status> gui_status = gui_status::hidden;
|
||||||
enum gui_status last_gui_status = gui_status::hidden;
|
enum gui_status last_gui_status = gui_status::hidden;
|
||||||
enum gui_status next_gui_status = gui_status::applications;
|
enum gui_status next_gui_status = gui_status::applications;
|
||||||
XrTime gui_status_last_change;
|
|
||||||
float dimming = 0;
|
float dimming = 0;
|
||||||
|
|
||||||
|
thread_safe<std::optional<gui_toast>> gui_toast;
|
||||||
|
std::atomic<XrTime> gui_status_last_change;
|
||||||
|
|
||||||
XrAction plots_toggle_1 = XR_NULL_HANDLE;
|
XrAction plots_toggle_1 = XR_NULL_HANDLE;
|
||||||
XrAction plots_toggle_2 = XR_NULL_HANDLE;
|
XrAction plots_toggle_2 = XR_NULL_HANDLE;
|
||||||
XrAction recenter_left = 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_2 &&) {};
|
||||||
void operator()(to_headset::pin_check_4 &&) {};
|
void operator()(to_headset::pin_check_4 &&) {};
|
||||||
void operator()(to_headset::handshake &&) {};
|
void operator()(to_headset::handshake &&) {};
|
||||||
|
void operator()(to_headset::server_message &&);
|
||||||
void operator()(to_headset::video_stream_data_shard &&);
|
void operator()(to_headset::video_stream_data_shard &&);
|
||||||
void operator()(to_headset::haptics &&);
|
void operator()(to_headset::haptics &&);
|
||||||
void operator()(to_headset::timesync_query &&);
|
void operator()(to_headset::timesync_query &&);
|
||||||
@@ -312,6 +321,7 @@ private:
|
|||||||
void gui_bitrate_settings(float predicted_display_period);
|
void gui_bitrate_settings(float predicted_display_period);
|
||||||
void gui_foveation_settings(float predicted_display_period);
|
void gui_foveation_settings(float predicted_display_period);
|
||||||
void gui_applications();
|
void gui_applications();
|
||||||
|
void gui_toasts();
|
||||||
void draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period);
|
void draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period);
|
||||||
};
|
};
|
||||||
} // namespace scenes
|
} // namespace scenes
|
||||||
|
|||||||
@@ -729,6 +729,19 @@ void scenes::stream::gui_applications()
|
|||||||
ImGui::PopStyleVar(3);
|
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)
|
void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period)
|
||||||
{
|
{
|
||||||
if (not(plots_toggle_1 and plots_toggle_2))
|
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;
|
float alpha = 1;
|
||||||
|
bool is_urgent = false;
|
||||||
if (gui_status == gui_status::hidden)
|
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<float>(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<float>(1 - (t - delay) / constants::stream::fade_duration, 0, 1);
|
||||||
|
|
||||||
if (alpha == 0)
|
if (alpha == 0)
|
||||||
|
{
|
||||||
|
toast->reset();
|
||||||
return;
|
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
|
// 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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_urgent)
|
||||||
|
{
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Border, constants::stream::urgent_border_color);
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 4);
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0);
|
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0);
|
||||||
if (always_auto_resize)
|
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);
|
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_WindowPadding, {8, 8});
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10);
|
||||||
|
|
||||||
switch (gui_status)
|
switch (gui_status)
|
||||||
{
|
{
|
||||||
case gui_status::hidden:
|
case gui_status::hidden:
|
||||||
ImGui::Text("%s", _S("Press both thumbsticks to display the WiVRn window"));
|
gui_toasts();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case gui_status::overlay_only:
|
case gui_status::overlay_only:
|
||||||
|
|||||||
@@ -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)
|
void scenes::stream::operator()(to_headset::video_stream_data_shard && shard)
|
||||||
{
|
{
|
||||||
std::shared_lock lock(decoder_mutex);
|
std::shared_lock lock(decoder_mutex);
|
||||||
|
|||||||
@@ -608,6 +608,18 @@ struct handshake
|
|||||||
int stream_port;
|
int stream_port;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct server_message
|
||||||
|
{
|
||||||
|
enum class kind : uint8_t
|
||||||
|
{
|
||||||
|
stream_toast,
|
||||||
|
stream_toast_urgent,
|
||||||
|
};
|
||||||
|
|
||||||
|
kind kind;
|
||||||
|
std::string msg;
|
||||||
|
};
|
||||||
|
|
||||||
struct foveation_parameter
|
struct foveation_parameter
|
||||||
{
|
{
|
||||||
// The number of source pixels for each ratio,
|
// The number of source pixels for each ratio,
|
||||||
@@ -766,6 +778,7 @@ using packets = std::variant<
|
|||||||
pin_check_2,
|
pin_check_2,
|
||||||
pin_check_4,
|
pin_check_4,
|
||||||
handshake,
|
handshake,
|
||||||
|
server_message,
|
||||||
audio_stream_description,
|
audio_stream_description,
|
||||||
video_stream_description,
|
video_stream_description,
|
||||||
audio_data,
|
audio_data,
|
||||||
|
|||||||
@@ -1192,8 +1192,13 @@ void wivrn_session::reconnect(std::stop_token stop)
|
|||||||
|
|
||||||
if (warn_conn)
|
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.");
|
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
|
// update headset info
|
||||||
|
|||||||
Reference in New Issue
Block a user