Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Vindicus999
2026-03-15 02:45:44 +00:00
13 changed files with 246 additions and 141 deletions
+38 -40
View File
@@ -322,6 +322,9 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
self->network_session->send_control(from_headset::session_state_changed{ self->network_session->send_control(from_headset::session_state_changed{
.state = application::get_session_state(), .state = application::get_session_state(),
}); });
self->network_session->send_control(from_headset::stream_tab_changed{
.tab = self->gui_status,
});
if (self->instance.has_extension(XR_KHR_VISIBILITY_MASK_EXTENSION_NAME)) if (self->instance.has_extension(XR_KHR_VISIBILITY_MASK_EXTENSION_NAME))
{ {
@@ -759,26 +762,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 stream_tab::stats:
case gui_status::settings: case stream_tab::settings:
case gui_status::bitrate_settings: case stream_tab::bitrate_settings:
case gui_status::foveation_settings: case stream_tab::foveation_settings:
case gui_status::applications: case stream_tab::applications:
case gui_status::application_launcher: case stream_tab::application_launcher:
return true; return true;
case gui_status::hidden: case stream_tab::hidden:
case gui_status::overlay_only: case stream_tab::overlay_only:
case gui_status::compact: case stream_tab::compact:
return false; return false;
} }
spdlog::warn("Invalid tab value {}", int(tab));
return false;
}
assert(false); bool scenes::stream::is_gui_interactable() const
__builtin_unreachable(); {
return is_interactable(gui_status);
} }
void scenes::stream::render(const XrFrameState & frame_state) void scenes::stream::render(const XrFrameState & frame_state)
@@ -808,7 +815,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
.variant = application::get_messages_info().variant, .variant = application::get_messages_info().variant,
}); });
gui_status = stream::gui_status::hidden; next_gui_status = stream_tab::hidden;
application::pop_scene(); application::pop_scene();
} }
@@ -1044,17 +1051,17 @@ void scenes::stream::render(const XrFrameState & frame_state)
{ {
switch (gui_status) switch (gui_status)
{ {
case gui_status::hidden: case stream_tab::hidden:
case gui_status::bitrate_settings: case stream_tab::bitrate_settings:
case gui_status::foveation_settings: case stream_tab::foveation_settings:
case gui_status::compact: case stream_tab::compact:
case gui_status::overlay_only: case stream_tab::overlay_only:
dimming = dimming - frame_state.predictedDisplayPeriod / (1e9 * constants::stream::fade_duration); dimming = dimming - frame_state.predictedDisplayPeriod / (1e9 * constants::stream::fade_duration);
break; break;
case gui_status::stats: case stream_tab::stats:
case gui_status::settings: case stream_tab::settings:
case gui_status::applications: case stream_tab::applications:
case gui_status::application_launcher: case stream_tab::application_launcher:
dimming = dimming + frame_state.predictedDisplayPeriod / (1e9 * constants::stream::fade_duration); dimming = dimming + frame_state.predictedDisplayPeriod / (1e9 * constants::stream::fade_duration);
break; break;
} }
@@ -1135,23 +1142,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)) if (state_1.currentState and state_2.currentState and (state_1.changedSinceLastSync or state_2.changedSinceLastSync))
{ {
switch (gui_status) // Arbitraty transitions can happen from network commands
{ // Ensure we can't have a set of 2 non interactable states
case gui_status::hidden: if (is_gui_interactable())
case gui_status::compact: next_gui_status = stream_tab::hidden;
case gui_status::overlay_only: else if (is_interactable(stored_gui_status))
gui_status = next_gui_status; next_gui_status = stored_gui_status;
break; else
next_gui_status = stream_tab::applications;
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;
}
} }
} }
+8 -16
View File
@@ -131,30 +131,21 @@ private:
uint32_t height; uint32_t height;
std::optional<imgui_context> imgui_ctx; 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 struct gui_toast
{ {
std::string content; std::string content;
bool is_urgent = false; bool is_urgent = false;
}; };
static bool is_interactable(stream_tab);
bool is_gui_interactable() const; bool is_gui_interactable() const;
std::atomic<gui_status> gui_status = gui_status::hidden; // Tab currently being displayed
enum gui_status last_gui_status = gui_status::hidden; stream_tab gui_status = stream_tab::hidden;
enum gui_status next_gui_status = gui_status::applications; // 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; float dimming = 0;
thread_safe<std::optional<gui_toast>> gui_toast; thread_safe<std::optional<gui_toast>> gui_toast;
@@ -227,6 +218,7 @@ public:
void operator()(to_headset::audio_stream_description &&); void operator()(to_headset::audio_stream_description &&);
void operator()(to_headset::video_stream_description &&); void operator()(to_headset::video_stream_description &&);
void operator()(to_headset::refresh_rate_change &&); 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_list &&);
void operator()(to_headset::application_icon &&); void operator()(to_headset::application_icon &&);
void operator()(to_headset::running_applications &&); void operator()(to_headset::running_applications &&);
+72 -70
View File
@@ -462,7 +462,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
ImGui::SameLine(0.f, 10.f); ImGui::SameLine(0.f, 10.f);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (size.y / 4.f) - style.FramePadding.y * 3.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())) 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(); imgui_ctx->vibrate_on_hover();
if (ImGui::IsItemHovered()) if (ImGui::IsItemHovered())
imgui_ctx->tooltip(_("Click to adjust bitrate")); imgui_ctx->tooltip(_("Click to adjust bitrate"));
@@ -554,7 +554,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button(_S("Change"))) if (ImGui::Button(_S("Change")))
gui_status = gui_status::foveation_settings; next_gui_status = stream_tab::foveation_settings;
imgui_ctx->vibrate_on_hover(); imgui_ctx->vibrate_on_hover();
ImGui::EndDisabled(); ImGui::EndDisabled();
@@ -600,7 +600,7 @@ void scenes::stream::gui_bitrate_settings(float predicted_display_period)
if (ok) if (ok)
{ {
config.save(); 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); 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) if (ok)
{ {
gui_status = gui_status::settings; next_gui_status = stream_tab::settings;
// Save settings // Save settings
auto & config = application::get_config(); auto & config = application::get_config();
@@ -640,7 +640,7 @@ void scenes::stream::gui_foveation_settings(float predicted_display_period)
} }
else if (cancel) else if (cancel)
{ {
gui_status = gui_status::settings; next_gui_status = stream_tab::settings;
// Restore settings // Restore settings
const auto & config = application::get_config(); const auto & config = application::get_config();
@@ -744,25 +744,43 @@ void scenes::stream::gui_toasts()
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 (auto new_status = next_gui_status.load(); new_status != gui_status)
return; {
spdlog::info("Switch tab from {} to {}", magic_enum::enum_name(gui_status), magic_enum::enum_name(new_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; bool interactable = true;
XrSpace world_space = application::space(xr::spaces::world); XrSpace world_space = application::space(xr::spaces::world);
auto views = session.locate_views(viewconfig, predicted_display_time, world_space).second; auto views = session.locate_views(viewconfig, predicted_display_time, world_space).second;
switch (gui_status) switch (gui_status)
{ {
case gui_status::hidden: case stream_tab::hidden:
case gui_status::bitrate_settings: case stream_tab::bitrate_settings:
case gui_status::foveation_settings: case stream_tab::foveation_settings:
case gui_status::overlay_only: case stream_tab::overlay_only:
case gui_status::compact: case stream_tab::compact:
interactable = false; interactable = false;
break; break;
case gui_status::stats: case stream_tab::stats:
case gui_status::settings: case stream_tab::settings:
case gui_status::applications: case stream_tab::applications:
case gui_status::application_launcher: case stream_tab::application_launcher:
break; break;
} }
imgui_ctx->set_controllers_enabled(interactable); imgui_ctx->set_controllers_enabled(interactable);
@@ -782,27 +800,9 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
right_hand.reset(); 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; float alpha = 1;
bool is_urgent = false; bool is_urgent = false;
if (gui_status == gui_status::hidden) if (gui_status == stream_tab::hidden)
{ {
auto toast = gui_toast.lock(); auto toast = gui_toast.lock();
if (toast->has_value()) if (toast->has_value())
@@ -827,24 +827,24 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
glm::mat3 M = glm::mat3_cast(head_position->second); glm::mat3 M = glm::mat3_cast(head_position->second);
switch (gui_status) switch (gui_status)
{ {
case gui_status::bitrate_settings: case stream_tab::bitrate_settings:
case gui_status::foveation_settings: case stream_tab::foveation_settings:
imgui_ctx->layers()[0].orientation = head_position->second; 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}; imgui_ctx->layers()[0].position = head_position->first + M * glm::vec3{0, override_foveation_distance * sin(override_foveation_pitch), -override_foveation_distance};
break; break;
case gui_status::hidden: case stream_tab::hidden:
// Always use the same position for the GUI shortcut tip // Always use the same position for the GUI shortcut tip
imgui_ctx->layers()[0].orientation = head_position->second; 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}; imgui_ctx->layers()[0].position = head_position->first + M * glm::vec3{0.0, -0.4, -1.0};
break; break;
case gui_status::overlay_only: case stream_tab::overlay_only:
case gui_status::compact: case stream_tab::compact:
case gui_status::stats: case stream_tab::stats:
case gui_status::settings: case stream_tab::settings:
case gui_status::applications: case stream_tab::applications:
case gui_status::application_launcher: case stream_tab::application_launcher:
imgui_ctx->layers()[0].orientation = head_position->second * head_gui_orientation; imgui_ctx->layers()[0].orientation = head_position->second * head_gui_orientation;
imgui_ctx->layers()[0].position = head_position->first + M * head_gui_position; imgui_ctx->layers()[0].position = head_position->first + M * head_gui_position;
break; break;
@@ -864,36 +864,36 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
bool display_tabs, always_auto_resize; bool display_tabs, always_auto_resize;
switch (gui_status) 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::SetNextWindowPos(content_center, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowSize(content_size); ImGui::SetNextWindowSize(content_size);
always_auto_resize = false; always_auto_resize = false;
display_tabs = false; display_tabs = false;
break; break;
case gui_status::hidden: case stream_tab::hidden:
case gui_status::bitrate_settings: case stream_tab::bitrate_settings:
case gui_status::foveation_settings: case stream_tab::foveation_settings:
ImGui::SetNextWindowPos(viewport_size / 2, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::SetNextWindowPos(viewport_size / 2, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
always_auto_resize = true; always_auto_resize = true;
display_tabs = false; display_tabs = false;
break; break;
case gui_status::compact: case stream_tab::compact:
ImGui::SetNextWindowPos(content_center, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::SetNextWindowPos(content_center, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
always_auto_resize = true; always_auto_resize = true;
display_tabs = false; display_tabs = false;
break; break;
case gui_status::stats: case stream_tab::stats:
case gui_status::settings: case stream_tab::settings:
case gui_status::applications: case stream_tab::applications:
ImGui::SetNextWindowPos(margin_around_window); ImGui::SetNextWindowPos(margin_around_window);
ImGui::SetNextWindowSize(viewport_size - margin_around_window * 2); ImGui::SetNextWindowSize(viewport_size - margin_around_window * 2);
always_auto_resize = false; always_auto_resize = false;
display_tabs = true; display_tabs = true;
break; break;
case gui_status::application_launcher: case stream_tab::application_launcher:
ImGui::SetNextWindowPos(margin_around_window); ImGui::SetNextWindowPos(margin_around_window);
ImGui::SetNextWindowSize(viewport_size - margin_around_window * 2); ImGui::SetNextWindowSize(viewport_size - margin_around_window * 2);
always_auto_resize = false; always_auto_resize = false;
@@ -930,53 +930,53 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
switch (gui_status) switch (gui_status)
{ {
case gui_status::hidden: case stream_tab::hidden:
gui_toasts(); gui_toasts();
break; break;
case gui_status::overlay_only: case stream_tab::overlay_only:
ImGui::SetCursorPos({20, 20}); ImGui::SetCursorPos({20, 20});
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0)); ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
gui_performance_metrics(); gui_performance_metrics();
ImGui::EndChild(); ImGui::EndChild();
break; break;
case gui_status::compact: case stream_tab::compact:
gui_compact_view(); gui_compact_view();
break; break;
case gui_status::stats: case stream_tab::stats:
ImGui::SetCursorPos({tab_width + 20, 20}); ImGui::SetCursorPos({tab_width + 20, 20});
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0)); ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
gui_performance_metrics(); gui_performance_metrics();
ImGui::EndChild(); ImGui::EndChild();
break; break;
case gui_status::settings: case stream_tab::settings:
ImGui::SetCursorPos({tab_width + 20, 20}); ImGui::SetCursorPos({tab_width + 20, 20});
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0)); ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
gui_settings(predicted_display_period * 1.e-9f); gui_settings(predicted_display_period * 1.e-9f);
ImGui::EndChild(); ImGui::EndChild();
break; break;
case gui_status::bitrate_settings: case stream_tab::bitrate_settings:
gui_bitrate_settings(predicted_display_period * 1.e-9f); gui_bitrate_settings(predicted_display_period * 1.e-9f);
break; break;
case gui_status::foveation_settings: case stream_tab::foveation_settings:
gui_foveation_settings(predicted_display_period * 1.e-9f); gui_foveation_settings(predicted_display_period * 1.e-9f);
break; break;
case gui_status::applications: case stream_tab::applications:
ImGui::SetCursorPos({tab_width + 20, 20}); ImGui::SetCursorPos({tab_width + 20, 20});
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0)); ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
gui_applications(); gui_applications();
ImGui::EndChild(); ImGui::EndChild();
break; break;
case gui_status::application_launcher: case stream_tab::application_launcher:
if (apps.draw_gui(*imgui_ctx, _("Cancel")) != app_launcher::None) 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 ImGui::PopStyleVar(2); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_FrameRounding
@@ -990,10 +990,11 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10)); 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(); 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(); apps.reset();
network_session->send_control(from_headset::get_application_list{ network_session->send_control(from_headset::get_application_list{
@@ -1004,22 +1005,22 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
} }
imgui_ctx->vibrate_on_hover(); 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(); 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(); imgui_ctx->vibrate_on_hover();
int n_items_at_end = 4; 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); 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(); 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(); 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(); imgui_ctx->vibrate_on_hover();
bool dummy = false; bool dummy = false;
@@ -1029,6 +1030,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding
ImGui::EndChild(); ImGui::EndChild();
next_gui_status = target;
} }
ImGui::PopStyleColor(); // ImGuiCol_ChildBg 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; 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) void scenes::stream::operator()(to_headset::timesync_query && query)
{ {
network_session->send_stream(from_headset::timesync_response{ network_session->send_stream(from_headset::timesync_response{
+25
View File
@@ -173,6 +173,19 @@ enum video_codec
raw, raw,
}; };
enum class stream_tab : uint8_t
{
hidden,
overlay_only,
compact,
stats,
settings,
bitrate_settings,
foveation_settings,
applications,
application_launcher,
};
struct audio_data struct audio_data
{ {
XrTime timestamp; XrTime timestamp;
@@ -512,6 +525,11 @@ struct user_presence_changed
bool present; bool present;
}; };
struct stream_tab_changed
{
stream_tab tab;
};
struct override_foveation_center struct override_foveation_center
{ {
bool enabled; bool enabled;
@@ -565,6 +583,7 @@ using packets = std::variant<
refresh_rate_changed, refresh_rate_changed,
session_state_changed, session_state_changed,
user_presence_changed, user_presence_changed,
stream_tab_changed,
override_foveation_center, override_foveation_center,
get_application_list, get_application_list,
start_app, start_app,
@@ -748,6 +767,11 @@ struct refresh_rate_change
float fps; float fps;
}; };
struct stream_tab_change
{
stream_tab tab;
};
struct application_list struct application_list
{ {
std::string language; std::string language;
@@ -794,6 +818,7 @@ using packets = std::variant<
tracking_control, tracking_control,
feature_control, feature_control,
refresh_rate_change, refresh_rate_change,
stream_tab_change,
application_list, application_list,
application_icon, application_icon,
running_applications>; running_applications>;
+5
View File
@@ -73,6 +73,11 @@
<property name="PairingEnabled" type="b" access="read"/> <property name="PairingEnabled" type="b" access="read"/>
<property name="EncryptionEnabled" type="b" access="read"/> <property name="EncryptionEnabled" type="b" access="read"/>
<property name="ClientTab" type="s" access="read"/>
<method name="SetClientTab">
<arg type="s" name="Tab"/>
</method>
<signal name="ServerError"> <signal name="ServerError">
<arg type="s" name="where"/> <arg type="s" name="where"/>
<arg type="s" name="message"/> <arg type="s" name="message"/>
+5 -14
View File
@@ -34,20 +34,11 @@
using namespace std::chrono_literals; using namespace std::chrono_literals;
static void handle_event_from_main_loop(to_monado::stop) // Ignored until connection is established
{ static void handle_event_from_main_loop(to_monado::stop) {}
// Ignore stop request when no headset is connected static void handle_event_from_main_loop(to_monado::disconnect) {}
} static void handle_event_from_main_loop(to_monado::set_bitrate) {}
static void handle_event_from_main_loop(wivrn::to_headset::stream_tab_change) {}
static void handle_event_from_main_loop(to_monado::disconnect)
{
// Ignore disconnect request when no headset is connected
}
static void handle_event_from_main_loop(to_monado::set_bitrate)
{
// Ignore bitrate request when no headset is connected
}
static std::string clean_key(std::string key) static std::string clean_key(std::string key)
{ {
+4
View File
@@ -36,6 +36,10 @@
#include "configuration.h" #include "configuration.h"
#ifndef NDEBUG
#include "math/m_api.h"
#endif
namespace wivrn namespace wivrn
{ {
+10
View File
@@ -833,6 +833,11 @@ void wivrn_session::operator()(from_headset::refresh_rate_changed && event)
}); });
} }
void wivrn_session::operator()(from_headset::stream_tab_changed && event)
{
send_to_main(std::move(event));
}
void wivrn_session::operator()(from_headset::get_application_list && request) void wivrn_session::operator()(from_headset::get_application_list && request)
{ {
to_headset::application_list response{ to_headset::application_list response{
@@ -975,6 +980,11 @@ void wivrn_session::operator()(to_monado::set_bitrate && data)
comp_target->set_bitrate(data.bitrate_bps); comp_target->set_bitrate(data.bitrate_bps);
} }
void wivrn_session::operator()(to_headset::stream_tab_change && data)
{
send_control(std::move(data));
}
struct refresh_rate_adjuster struct refresh_rate_adjuster
{ {
std::chrono::seconds period{10}; std::chrono::seconds period{10};
+2
View File
@@ -178,6 +178,7 @@ public:
void operator()(from_headset::session_state_changed &&); void operator()(from_headset::session_state_changed &&);
void operator()(from_headset::user_presence_changed &&); void operator()(from_headset::user_presence_changed &&);
void operator()(from_headset::refresh_rate_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::override_foveation_center &&);
void operator()(from_headset::get_application_list &&); void operator()(from_headset::get_application_list &&);
void operator()(const from_headset::start_app &); void operator()(const from_headset::start_app &);
@@ -189,6 +190,7 @@ public:
void operator()(to_monado::stop &&); void operator()(to_monado::stop &&);
void operator()(to_monado::disconnect &&); void operator()(to_monado::disconnect &&);
void operator()(to_monado::set_bitrate &&); void operator()(to_monado::set_bitrate &&);
void operator()(to_headset::stream_tab_change &&);
bool has_stream() bool has_stream()
{ {
+32
View File
@@ -34,6 +34,7 @@
#include <filesystem> #include <filesystem>
#include <iostream> #include <iostream>
#include <libnotify/notification.h> #include <libnotify/notification.h>
#include <magic_enum.hpp>
#include <memory> #include <memory>
#include <poll.h> #include <poll.h>
#include <random> #include <random>
@@ -537,6 +538,10 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
start_publishing(); start_publishing();
inhibitor.reset(); inhibitor.reset();
wivrn_server_set_headset_connected(dbus_server, false); wivrn_server_set_headset_connected(dbus_server, false);
wivrn_server_set_client_tab(dbus_server, "");
},
[&](const wivrn::from_headset::stream_tab_changed & event) {
wivrn_server_set_client_tab(dbus_server, magic_enum::enum_name(event.tab).data());
}, },
[&](const from_monado::server_error & e) { [&](const from_monado::server_error & e) {
wivrn_server_emit_server_error(dbus_server, e.where.c_str(), e.message.c_str()); wivrn_server_emit_server_error(dbus_server, e.where.c_str(), e.message.c_str());
@@ -694,6 +699,29 @@ gboolean on_handle_disable_pairing(WivrnServer * skeleton, GDBusMethodInvocation
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
} }
gboolean on_handle_set_client_tab(WivrnServer * skeleton, GDBusMethodInvocation * invocation, gpointer user_data)
{
GVariant * args = g_dbus_method_invocation_get_parameters(invocation);
char * c_tab;
g_variant_get_child(args, 0, "s", &c_tab);
std::string tab(c_tab);
g_free(c_tab);
for (auto [val, name]: magic_enum::enum_entries<stream_tab>())
{
if (tab == name)
{
wivrn_ipc_socket_main_loop->send(to_headset::stream_tab_change{.tab = val});
g_dbus_method_invocation_return_value(invocation, nullptr);
return G_SOURCE_CONTINUE;
}
}
std::cerr << "Invalid tab name " << tab << std::endl;
g_dbus_method_invocation_return_dbus_error(invocation, "io.github.wivrn.Server.InvalidTab", "invalid tab");
return G_SOURCE_CONTINUE;
}
void on_bitrate(WivrnServer * server, const GParamSpec * pspec, gpointer data) void on_bitrate(WivrnServer * server, const GParamSpec * pspec, gpointer data)
{ {
auto bitrate = wivrn_server_get_bitrate(server); auto bitrate = wivrn_server_get_bitrate(server);
@@ -841,6 +869,8 @@ void on_name_acquired(GDBusConnection * connection, const gchar * name, gpointer
NULL); NULL);
} }
g_signal_connect(dbus_server, "handle-set-client-tab", G_CALLBACK(on_handle_set_client_tab), NULL);
wivrn_server_set_steam_command(dbus_server, steam_command().c_str()); wivrn_server_set_steam_command(dbus_server, steam_command().c_str());
on_headset_info_packet({}); on_headset_info_packet({});
@@ -870,6 +900,8 @@ void on_name_acquired(GDBusConnection * connection, const gchar * name, gpointer
set_encryption_state(wivrn_connection::encryption_state::pairing); set_encryption_state(wivrn_connection::encryption_state::pairing);
else else
set_encryption_state(enc_state); set_encryption_state(enc_state);
wivrn_server_set_client_tab(dbus_server, "");
} }
auto create_dbus_connection() auto create_dbus_connection()
+2 -1
View File
@@ -52,6 +52,7 @@ using packets = std::variant<
wivrn::from_headset::headset_info_packet, wivrn::from_headset::headset_info_packet,
wivrn::from_headset::settings_changed, wivrn::from_headset::settings_changed,
wivrn::from_headset::start_app, wivrn::from_headset::start_app,
wivrn::from_headset::stream_tab_changed,
headset_connected, headset_connected,
headset_disconnected, headset_disconnected,
server_error>; server_error>;
@@ -70,7 +71,7 @@ struct set_bitrate
uint32_t bitrate_bps; uint32_t bitrate_bps;
}; };
using packets = std::variant<stop, disconnect, set_bitrate>; using packets = std::variant<stop, disconnect, set_bitrate, wivrn::to_headset::stream_tab_change>;
} // namespace to_monado } // namespace to_monado
extern std::optional<wivrn::typed_socket<wivrn::UnixDatagram, to_monado::packets, from_monado::packets>> wivrn_ipc_socket_monado; extern std::optional<wivrn::typed_socket<wivrn::UnixDatagram, to_monado::packets, from_monado::packets>> wivrn_ipc_socket_monado;
+38
View File
@@ -89,6 +89,22 @@ sd_bus_message_ptr get_property(const sd_bus_ptr & bus, const char * member, con
return sd_bus_message_ptr(msg); return sd_bus_message_ptr(msg);
} }
std::string get_property_string(const sd_bus_ptr & bus, const char * member)
{
sd_bus_error error = SD_BUS_ERROR_NULL;
char * val;
int ret = sd_bus_get_property_string(bus.get(), destination, path, interface, member, &error, &val);
if (ret < 0)
{
std::runtime_error e(std::string("read property ") + member + " failed: " + error.message);
sd_bus_error_free(&error);
throw e;
}
std::string res(val);
free(val);
return res;
}
template <typename... Args> template <typename... Args>
void set_property(const sd_bus_ptr & bus, const char * member, const char * signature, Args &&... args) void set_property(const sd_bus_ptr & bus, const char * member, const char * signature, Args &&... args)
{ {
@@ -218,6 +234,23 @@ void unpair(size_t headset_id)
call_method(bus, "RevokeKey", "s", values.at(headset_id - 1).public_key.c_str()); call_method(bus, "RevokeKey", "s", values.at(headset_id - 1).public_key.c_str());
} }
void tab(std::string tab_name)
{
auto bus = get_user_bus();
if (tab_name.empty())
{
auto val = get_property_string(bus, "ClientTab");
if (val.empty())
std::cout << "<No tab>" << std::endl;
else
std::cout << val << std::endl;
}
else
{
call_method(bus, "SetClientTab", "s", tab_name.c_str());
}
}
template <typename T, typename U> template <typename T, typename U>
auto member(T U::* x) auto member(T U::* x)
{ {
@@ -340,6 +373,11 @@ int main(int argc, char ** argv)
app.add_subcommand("disconnect", "Disconnect headset") app.add_subcommand("disconnect", "Disconnect headset")
->callback(disconnect); ->callback(disconnect);
std::string tab_name;
app.add_subcommand("tab", "Show or set current tab on headset")
->callback([&]() { return tab(tab_name); })
->add_option("[TAB]", tab_name, "Tab to select");
try try
{ {
CLI11_PARSE(app, argc, argv); CLI11_PARSE(app, argc, argv);