Rework stream tabs management

This commit is contained in:
Patrick Nicolas
2026-03-14 17:29:21 +01:00
parent 79df7370f3
commit 7d9031e843
7 changed files with 149 additions and 126 deletions
+35 -40
View File
@@ -759,26 +759,30 @@ void scenes::stream::update_gui_position(xr::spaces controller)
}
}
bool scenes::stream::is_gui_interactable() const
bool scenes::stream::is_interactable(stream_tab tab)
{
switch (gui_status)
switch (tab)
{
case gui_status::stats:
case gui_status::settings:
case gui_status::bitrate_settings:
case gui_status::foveation_settings:
case gui_status::applications:
case gui_status::application_launcher:
case stream_tab::stats:
case stream_tab::settings:
case stream_tab::bitrate_settings:
case stream_tab::foveation_settings:
case stream_tab::applications:
case stream_tab::application_launcher:
return true;
case gui_status::hidden:
case gui_status::overlay_only:
case gui_status::compact:
case stream_tab::hidden:
case stream_tab::overlay_only:
case stream_tab::compact:
return false;
}
spdlog::warn("Invalid tab value {}", int(tab));
return false;
}
assert(false);
__builtin_unreachable();
bool scenes::stream::is_gui_interactable() const
{
return is_interactable(gui_status);
}
void scenes::stream::render(const XrFrameState & frame_state)
@@ -808,7 +812,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
.variant = application::get_messages_info().variant,
});
gui_status = stream::gui_status::hidden;
next_gui_status = stream_tab::hidden;
application::pop_scene();
}
@@ -1044,17 +1048,17 @@ void scenes::stream::render(const XrFrameState & frame_state)
{
switch (gui_status)
{
case gui_status::hidden:
case gui_status::bitrate_settings:
case gui_status::foveation_settings:
case gui_status::compact:
case gui_status::overlay_only:
case stream_tab::hidden:
case stream_tab::bitrate_settings:
case stream_tab::foveation_settings:
case stream_tab::compact:
case stream_tab::overlay_only:
dimming = dimming - frame_state.predictedDisplayPeriod / (1e9 * constants::stream::fade_duration);
break;
case gui_status::stats:
case gui_status::settings:
case gui_status::applications:
case gui_status::application_launcher:
case stream_tab::stats:
case stream_tab::settings:
case stream_tab::applications:
case stream_tab::application_launcher:
dimming = dimming + frame_state.predictedDisplayPeriod / (1e9 * constants::stream::fade_duration);
break;
}
@@ -1135,23 +1139,14 @@ void scenes::stream::render(const XrFrameState & frame_state)
if (state_1.currentState and state_2.currentState and (state_1.changedSinceLastSync or state_2.changedSinceLastSync))
{
switch (gui_status)
{
case gui_status::hidden:
case gui_status::compact:
case gui_status::overlay_only:
gui_status = next_gui_status;
break;
case gui_status::stats:
case gui_status::settings:
case gui_status::bitrate_settings:
case gui_status::foveation_settings:
case gui_status::applications:
case gui_status::application_launcher:
gui_status = gui_status::hidden;
break;
}
// Arbitraty transitions can happen from network commands
// Ensure we can't have a set of 2 non interactable states
if (is_gui_interactable())
next_gui_status = stream_tab::hidden;
else if (is_interactable(stored_gui_status))
next_gui_status = stored_gui_status;
else
next_gui_status = stream_tab::applications;
}
}
+8 -16
View File
@@ -131,30 +131,21 @@ private:
uint32_t height;
std::optional<imgui_context> imgui_ctx;
enum class gui_status
{
hidden,
overlay_only,
compact,
stats,
settings,
bitrate_settings,
foveation_settings,
applications,
application_launcher,
};
struct gui_toast
{
std::string content;
bool is_urgent = false;
};
static bool is_interactable(stream_tab);
bool is_gui_interactable() const;
std::atomic<gui_status> gui_status = gui_status::hidden;
enum gui_status last_gui_status = gui_status::hidden;
enum gui_status next_gui_status = gui_status::applications;
// Tab currently being displayed
stream_tab gui_status = stream_tab::hidden;
// Tab that we will switch to if button is pressed
stream_tab stored_gui_status = stream_tab::applications;
// Tab that will be displayed on next render()
std::atomic<stream_tab> next_gui_status = stream_tab::hidden;
float dimming = 0;
thread_safe<std::optional<gui_toast>> gui_toast;
@@ -227,6 +218,7 @@ public:
void operator()(to_headset::audio_stream_description &&);
void operator()(to_headset::video_stream_description &&);
void operator()(to_headset::refresh_rate_change &&);
void operator()(to_headset::stream_tab_change &&);
void operator()(to_headset::application_list &&);
void operator()(to_headset::application_icon &&);
void operator()(to_headset::running_applications &&);
+71 -70
View File
@@ -462,7 +462,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
ImGui::SameLine(0.f, 10.f);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (size.y / 4.f) - style.FramePadding.y * 3.f);
if (ImGui::Button(fmt::format("{}Mbit/s", config.bitrate_bps / 1'000'000).c_str()))
gui_status = gui_status::bitrate_settings;
next_gui_status = stream_tab::bitrate_settings;
imgui_ctx->vibrate_on_hover();
if (ImGui::IsItemHovered())
imgui_ctx->tooltip(_("Click to adjust bitrate"));
@@ -554,7 +554,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
ImGui::SameLine();
if (ImGui::Button(_S("Change")))
gui_status = gui_status::foveation_settings;
next_gui_status = stream_tab::foveation_settings;
imgui_ctx->vibrate_on_hover();
ImGui::EndDisabled();
@@ -600,7 +600,7 @@ void scenes::stream::gui_bitrate_settings(float predicted_display_period)
if (ok)
{
config.save();
gui_status = gui_status::settings;
next_gui_status = stream_tab::settings;
}
send_settings_changed_packet(session, network_session.get(), application::get_config(), predicted_display_period);
@@ -629,7 +629,7 @@ void scenes::stream::gui_foveation_settings(float predicted_display_period)
if (ok)
{
gui_status = gui_status::settings;
next_gui_status = stream_tab::settings;
// Save settings
auto & config = application::get_config();
@@ -640,7 +640,7 @@ void scenes::stream::gui_foveation_settings(float predicted_display_period)
}
else if (cancel)
{
gui_status = gui_status::settings;
next_gui_status = stream_tab::settings;
// Restore settings
const auto & config = application::get_config();
@@ -744,25 +744,42 @@ void scenes::stream::gui_toasts()
void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period)
{
if (not(plots_toggle_1 and plots_toggle_2))
return;
if (auto new_status = next_gui_status.load(); new_status != gui_status)
{
stored_gui_status = gui_status;
gui_status = new_status;
gui_status_last_change = predicted_display_time;
// Override session state if the GUI is interactable
if (not is_gui_interactable())
network_session->send_control(from_headset::session_state_changed{
.state = application::get_session_state(),
});
else if (application::get_session_state() == XR_SESSION_STATE_FOCUSED)
network_session->send_control(from_headset::session_state_changed{
.state = XR_SESSION_STATE_VISIBLE,
});
network_session->send_control(from_headset::stream_tab_changed{.tab = new_status});
}
bool interactable = true;
XrSpace world_space = application::space(xr::spaces::world);
auto views = session.locate_views(viewconfig, predicted_display_time, world_space).second;
switch (gui_status)
{
case gui_status::hidden:
case gui_status::bitrate_settings:
case gui_status::foveation_settings:
case gui_status::overlay_only:
case gui_status::compact:
case stream_tab::hidden:
case stream_tab::bitrate_settings:
case stream_tab::foveation_settings:
case stream_tab::overlay_only:
case stream_tab::compact:
interactable = false;
break;
case gui_status::stats:
case gui_status::settings:
case gui_status::applications:
case gui_status::application_launcher:
case stream_tab::stats:
case stream_tab::settings:
case stream_tab::applications:
case stream_tab::application_launcher:
break;
}
imgui_ctx->set_controllers_enabled(interactable);
@@ -782,27 +799,9 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
right_hand.reset();
}
if (gui_status != last_gui_status)
{
last_gui_status = gui_status;
if (is_gui_interactable())
next_gui_status = gui_status;
gui_status_last_change = predicted_display_time;
// Override session state if the GUI is interactable
if (not is_gui_interactable())
network_session->send_control(from_headset::session_state_changed{
.state = application::get_session_state(),
});
else if (application::get_session_state() == XR_SESSION_STATE_FOCUSED)
network_session->send_control(from_headset::session_state_changed{
.state = XR_SESSION_STATE_VISIBLE,
});
}
float alpha = 1;
bool is_urgent = false;
if (gui_status == gui_status::hidden)
if (gui_status == stream_tab::hidden)
{
auto toast = gui_toast.lock();
if (toast->has_value())
@@ -827,24 +826,24 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
glm::mat3 M = glm::mat3_cast(head_position->second);
switch (gui_status)
{
case gui_status::bitrate_settings:
case gui_status::foveation_settings:
case stream_tab::bitrate_settings:
case stream_tab::foveation_settings:
imgui_ctx->layers()[0].orientation = head_position->second;
imgui_ctx->layers()[0].position = head_position->first + M * glm::vec3{0, override_foveation_distance * sin(override_foveation_pitch), -override_foveation_distance};
break;
case gui_status::hidden:
case stream_tab::hidden:
// Always use the same position for the GUI shortcut tip
imgui_ctx->layers()[0].orientation = head_position->second;
imgui_ctx->layers()[0].position = head_position->first + M * glm::vec3{0.0, -0.4, -1.0};
break;
case gui_status::overlay_only:
case gui_status::compact:
case gui_status::stats:
case gui_status::settings:
case gui_status::applications:
case gui_status::application_launcher:
case stream_tab::overlay_only:
case stream_tab::compact:
case stream_tab::stats:
case stream_tab::settings:
case stream_tab::applications:
case stream_tab::application_launcher:
imgui_ctx->layers()[0].orientation = head_position->second * head_gui_orientation;
imgui_ctx->layers()[0].position = head_position->first + M * head_gui_position;
break;
@@ -864,36 +863,36 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
bool display_tabs, always_auto_resize;
switch (gui_status)
{
case gui_status::overlay_only:
case stream_tab::overlay_only:
ImGui::SetNextWindowPos(content_center, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowSize(content_size);
always_auto_resize = false;
display_tabs = false;
break;
case gui_status::hidden:
case gui_status::bitrate_settings:
case gui_status::foveation_settings:
case stream_tab::hidden:
case stream_tab::bitrate_settings:
case stream_tab::foveation_settings:
ImGui::SetNextWindowPos(viewport_size / 2, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
always_auto_resize = true;
display_tabs = false;
break;
case gui_status::compact:
case stream_tab::compact:
ImGui::SetNextWindowPos(content_center, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
always_auto_resize = true;
display_tabs = false;
break;
case gui_status::stats:
case gui_status::settings:
case gui_status::applications:
case stream_tab::stats:
case stream_tab::settings:
case stream_tab::applications:
ImGui::SetNextWindowPos(margin_around_window);
ImGui::SetNextWindowSize(viewport_size - margin_around_window * 2);
always_auto_resize = false;
display_tabs = true;
break;
case gui_status::application_launcher:
case stream_tab::application_launcher:
ImGui::SetNextWindowPos(margin_around_window);
ImGui::SetNextWindowSize(viewport_size - margin_around_window * 2);
always_auto_resize = false;
@@ -930,53 +929,53 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
switch (gui_status)
{
case gui_status::hidden:
case stream_tab::hidden:
gui_toasts();
break;
case gui_status::overlay_only:
case stream_tab::overlay_only:
ImGui::SetCursorPos({20, 20});
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
gui_performance_metrics();
ImGui::EndChild();
break;
case gui_status::compact:
case stream_tab::compact:
gui_compact_view();
break;
case gui_status::stats:
case stream_tab::stats:
ImGui::SetCursorPos({tab_width + 20, 20});
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
gui_performance_metrics();
ImGui::EndChild();
break;
case gui_status::settings:
case stream_tab::settings:
ImGui::SetCursorPos({tab_width + 20, 20});
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
gui_settings(predicted_display_period * 1.e-9f);
ImGui::EndChild();
break;
case gui_status::bitrate_settings:
case stream_tab::bitrate_settings:
gui_bitrate_settings(predicted_display_period * 1.e-9f);
break;
case gui_status::foveation_settings:
case stream_tab::foveation_settings:
gui_foveation_settings(predicted_display_period * 1.e-9f);
break;
case gui_status::applications:
case stream_tab::applications:
ImGui::SetCursorPos({tab_width + 20, 20});
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
gui_applications();
ImGui::EndChild();
break;
case gui_status::application_launcher:
case stream_tab::application_launcher:
if (apps.draw_gui(*imgui_ctx, _("Cancel")) != app_launcher::None)
gui_status = gui_status::applications;
next_gui_status = stream_tab::applications;
}
ImGui::PopStyleVar(2); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_FrameRounding
@@ -990,10 +989,11 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10));
RadioButtonWithoutCheckBox(ICON_FA_LIST " " + _("Applications"), gui_status, gui_status::applications, {tab_width, 0});
auto target = gui_status;
RadioButtonWithoutCheckBox(ICON_FA_LIST " " + _("Applications"), target, stream_tab::applications, {tab_width, 0});
imgui_ctx->vibrate_on_hover();
if (RadioButtonWithoutCheckBox(ICON_FA_ROCKET " " + _("Start"), gui_status, gui_status::application_launcher, {tab_width, 0}))
if (RadioButtonWithoutCheckBox(ICON_FA_ROCKET " " + _("Start"), target, stream_tab::application_launcher, {tab_width, 0}))
{
apps.reset();
network_session->send_control(from_headset::get_application_list{
@@ -1004,22 +1004,22 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
}
imgui_ctx->vibrate_on_hover();
RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), gui_status, gui_status::settings, {tab_width, 0});
RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), target, stream_tab::settings, {tab_width, 0});
imgui_ctx->vibrate_on_hover();
RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " " + _("Stats"), gui_status, gui_status::stats, {tab_width, 0});
RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " " + _("Stats"), target, stream_tab::stats, {tab_width, 0});
imgui_ctx->vibrate_on_hover();
int n_items_at_end = 4;
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - n_items_at_end * ImGui::GetCurrentContext()->FontSize - (n_items_at_end * 2) * style.FramePadding.y - (n_items_at_end - 1) * style.ItemSpacing.y - style.WindowPadding.y);
RadioButtonWithoutCheckBox(ICON_FA_CHART_LINE " " + _("Statistics overlay"), gui_status, gui_status::overlay_only, {tab_width, 0});
RadioButtonWithoutCheckBox(ICON_FA_CHART_LINE " " + _("Statistics overlay"), target, stream_tab::overlay_only, {tab_width, 0});
imgui_ctx->vibrate_on_hover();
RadioButtonWithoutCheckBox(ICON_FA_MINIMIZE " " + _("Compact view"), gui_status, gui_status::compact, {tab_width, 0});
RadioButtonWithoutCheckBox(ICON_FA_MINIMIZE " " + _("Compact view"), target, stream_tab::compact, {tab_width, 0});
imgui_ctx->vibrate_on_hover();
RadioButtonWithoutCheckBox(ICON_FA_XMARK " " + _("Close"), gui_status, gui_status::hidden, {tab_width, 0});
RadioButtonWithoutCheckBox(ICON_FA_XMARK " " + _("Close"), target, stream_tab::hidden, {tab_width, 0});
imgui_ctx->vibrate_on_hover();
bool dummy = false;
@@ -1029,6 +1029,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding
ImGui::EndChild();
next_gui_status = target;
}
ImGui::PopStyleColor(); // ImGuiCol_ChildBg
}
+5
View File
@@ -117,6 +117,11 @@ void scenes::stream::operator()(to_headset::refresh_rate_change && rate)
video_stream_description->fps = rate.fps;
}
void scenes::stream::operator()(to_headset::stream_tab_change && tab)
{
next_gui_status = tab.tab;
}
void scenes::stream::operator()(to_headset::timesync_query && query)
{
network_session->send_stream(from_headset::timesync_response{
+25
View File
@@ -173,6 +173,19 @@ enum video_codec
raw,
};
enum class stream_tab : uint8_t
{
hidden,
overlay_only,
compact,
stats,
settings,
bitrate_settings,
foveation_settings,
applications,
application_launcher,
};
struct audio_data
{
XrTime timestamp;
@@ -512,6 +525,11 @@ struct user_presence_changed
bool present;
};
struct stream_tab_changed
{
stream_tab tab;
};
struct override_foveation_center
{
bool enabled;
@@ -565,6 +583,7 @@ using packets = std::variant<
refresh_rate_changed,
session_state_changed,
user_presence_changed,
stream_tab_changed,
override_foveation_center,
get_application_list,
start_app,
@@ -748,6 +767,11 @@ struct refresh_rate_change
float fps;
};
struct stream_tab_change
{
stream_tab tab;
};
struct application_list
{
std::string language;
@@ -794,6 +818,7 @@ using packets = std::variant<
tracking_control,
feature_control,
refresh_rate_change,
stream_tab_change,
application_list,
application_icon,
running_applications>;
+4
View File
@@ -833,6 +833,10 @@ void wivrn_session::operator()(from_headset::refresh_rate_changed && event)
});
}
void wivrn_session::operator()(from_headset::stream_tab_changed && event)
{
}
void wivrn_session::operator()(from_headset::get_application_list && request)
{
to_headset::application_list response{
+1
View File
@@ -178,6 +178,7 @@ public:
void operator()(from_headset::session_state_changed &&);
void operator()(from_headset::user_presence_changed &&);
void operator()(from_headset::refresh_rate_changed &&);
void operator()(from_headset::stream_tab_changed &&);
void operator()(from_headset::override_foveation_center &&);
void operator()(from_headset::get_application_list &&);
void operator()(const from_headset::start_app &);