Select active application from stream GUI

This commit is contained in:
Patrick Nicolas
2025-09-27 10:08:51 +02:00
parent 7fb8f4c1a8
commit 6e64dd03b3
4 changed files with 47 additions and 7 deletions
+30 -5
View File
@@ -83,6 +83,15 @@ ImPlotPoint getter(int index, void * data_)
return ImPlotPoint(index, *(float *)(data.data + index * data.stride) * data.multiplier);
}
void CenterTextH(const std::string & text)
{
float win_width = ImGui::GetWindowSize().x;
float text_width = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((win_width - text_width) / 2);
ImGui::Text("%s", text.c_str());
}
} // namespace
void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std::vector<std::shared_ptr<shard_accumulator::blit_handle>> & blit_handles, const gpu_timestamps & timestamps)
@@ -605,17 +614,33 @@ void scenes::stream::gui_foveation_settings(float predicted_display_period)
void scenes::stream::gui_applications()
{
ImGui::Text("%s", _S("Running XR applications:"));
ImGui::PushFont(nullptr, constants::gui::font_size_large);
CenterTextH(_("Running XR applications:"));
ImGui::PopFont();
auto apps = running_applications.lock();
ImVec2 button_size(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0);
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32_BLACK_TRANS);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10));
for (const auto & app: apps->applications)
{
ImGui::Text("%s", app.name.c_str());
if (app.id == apps->active_id)
if (app.active or app.overlay)
{
ImGui::SameLine();
ImGui::Text("%s", _S("(focused)"));
ImGui::Text("%s", app.name.c_str());
if (app.active)
{
ImGui::SameLine();
ImGui::Text("%s", _S("(focused)"));
}
}
else
{
if (RadioButtonWithoutCheckBox(app.name, false, button_size))
network_session->send_control(from_headset::set_active_application{.id = app.id});
}
}
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();
}
// Return the vector v such that dot(v, x) > 0 iff x is on the side where the composition layer is visible
+7 -1
View File
@@ -465,6 +465,11 @@ struct start_app
struct get_running_applications
{};
struct set_active_application
{
uint32_t id;
};
using packets = std::variant<
crypto_handshake,
pin_check_1,
@@ -488,7 +493,8 @@ using packets = std::variant<
override_foveation_center,
get_application_list,
start_app,
get_running_applications>;
get_running_applications,
set_active_application>;
} // namespace from_headset
namespace to_headset
+9 -1
View File
@@ -789,7 +789,7 @@ void wivrn_session::operator()(const from_headset::get_running_applications &)
to_headset::running_applications msg{};
for (auto & t: inst.server->threads)
{
if (t.ics.server_thread_index < 0)
if (t.ics.server_thread_index < 0 or t.ics.xc == nullptr)
continue;
// nasty volatile
std::array<char, sizeof(t.ics.client_state.info.application_name)> tmp;
@@ -807,6 +807,14 @@ void wivrn_session::operator()(const from_headset::get_running_applications &)
connection->send_control(std::move(msg));
}
void wivrn_session::operator()(const from_headset::set_active_application & req)
{
ipc_server_set_active_client(inst.server, req.id);
ipc_server_update_state(inst.server);
// Send a refreshed application list
(*this)(from_headset::get_running_applications{});
}
void wivrn_session::operator()(audio_data && data)
{
if (audio_handle)
+1
View File
@@ -193,6 +193,7 @@ public:
void operator()(from_headset::get_application_list &&);
void operator()(const from_headset::start_app &);
void operator()(const from_headset::get_running_applications &);
void operator()(const from_headset::set_active_application &);
void operator()(audio_data &&);
void operator()(to_monado::disconnect &&);