Export current client tab on dbus

This commit is contained in:
Patrick Nicolas
2026-03-14 18:20:32 +01:00
parent 7d9031e843
commit 26f21348f3
8 changed files with 55 additions and 15 deletions
+3
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{
.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))
{
+1
View File
@@ -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;
+5
View File
@@ -73,6 +73,11 @@
<property name="PairingEnabled" 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">
<arg type="s" name="where"/>
<arg type="s" name="message"/>
+5 -14
View File
@@ -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)
{
+6
View File
@@ -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};
+1
View File
@@ -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()
{
+32
View File
@@ -34,6 +34,7 @@
#include <filesystem>
#include <iostream>
#include <libnotify/notification.h>
#include <magic_enum.hpp>
#include <memory>
#include <poll.h>
#include <random>
@@ -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<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)
{
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()
+2 -1
View File
@@ -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<stop, disconnect, set_bitrate>;
using packets = std::variant<stop, disconnect, set_bitrate, wivrn::to_headset::stream_tab_change>;
} // namespace to_monado
extern std::optional<wivrn::typed_socket<wivrn::UnixDatagram, to_monado::packets, from_monado::packets>> wivrn_ipc_socket_monado;