diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 7a8954e7..2486e4b7 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -322,6 +322,9 @@ std::shared_ptr scenes::stream::create(std::unique_ptrnetwork_session->send_control(from_headset::session_state_changed{ .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)) { diff --git a/client/scenes/stream_gui.cpp b/client/scenes/stream_gui.cpp index 1e21bfb9..53555fbc 100644 --- a/client/scenes/stream_gui.cpp +++ b/client/scenes/stream_gui.cpp @@ -746,6 +746,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte { if (auto new_status = next_gui_status.load(); new_status != gui_status) { + 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; diff --git a/dbus/io.github.wivrn.Server.xml b/dbus/io.github.wivrn.Server.xml index f37af7bd..59aa7e00 100644 --- a/dbus/io.github.wivrn.Server.xml +++ b/dbus/io.github.wivrn.Server.xml @@ -73,6 +73,11 @@ + + + + + diff --git a/server/driver/wivrn_connection.cpp b/server/driver/wivrn_connection.cpp index ea893f8d..64c7ff5b 100644 --- a/server/driver/wivrn_connection.cpp +++ b/server/driver/wivrn_connection.cpp @@ -34,20 +34,11 @@ using namespace std::chrono_literals; -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) -{ - // 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 -} +// Ignored until connection is established +static void handle_event_from_main_loop(to_monado::stop) {} +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 std::string clean_key(std::string key) { diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 81563396..f9258d6f 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -835,6 +835,7 @@ 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) @@ -979,6 +980,11 @@ void wivrn_session::operator()(to_monado::set_bitrate && data) 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 { std::chrono::seconds period{10}; diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 9539d0be..d2e6b934 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -190,6 +190,7 @@ public: void operator()(to_monado::stop &&); void operator()(to_monado::disconnect &&); void operator()(to_monado::set_bitrate &&); + void operator()(to_headset::stream_tab_change &&); bool has_stream() { diff --git a/server/main.cpp b/server/main.cpp index 8091deed..aa5a36b3 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -537,6 +538,10 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data) start_publishing(); inhibitor.reset(); 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) { 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; } +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()) + { + 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) { auto bitrate = wivrn_server_get_bitrate(server); @@ -841,6 +869,8 @@ void on_name_acquired(GDBusConnection * connection, const gchar * name, gpointer 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()); 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); else set_encryption_state(enc_state); + + wivrn_server_set_client_tab(dbus_server, ""); } auto create_dbus_connection() diff --git a/server/wivrn_ipc.h b/server/wivrn_ipc.h index 7dfb7e55..b92c2b84 100644 --- a/server/wivrn_ipc.h +++ b/server/wivrn_ipc.h @@ -52,6 +52,7 @@ using packets = std::variant< wivrn::from_headset::headset_info_packet, wivrn::from_headset::settings_changed, wivrn::from_headset::start_app, + wivrn::from_headset::stream_tab_changed, headset_connected, headset_disconnected, server_error>; @@ -70,7 +71,7 @@ struct set_bitrate uint32_t bitrate_bps; }; -using packets = std::variant; +using packets = std::variant; } // namespace to_monado extern std::optional> wivrn_ipc_socket_monado;