diff --git a/client/scenes/stream_gui.cpp b/client/scenes/stream_gui.cpp index 2569d9fd..278eea94 100644 --- a/client/scenes/stream_gui.cpp +++ b/client/scenes/stream_gui.cpp @@ -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> & 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 diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 67a939bb..3591f9bc 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -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 diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 1adea093..2772db9a 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -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 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) diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 0eeffe47..6011738f 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -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 &&);