From 1267081e5cc969843087161f8f3099129daf70f7 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Wed, 30 Mar 2022 21:18:00 -0300 Subject: [PATCH] linux-pipewire: Move fetching cursor mode to portal.c The portal.c file was introduced after the PipeWire code landed, and handles acquiring a D-Bus connection to the portal interface, and also has helpers to get properties from portals. The available cursor modes property fits nicely in portal.c. Move fetching the cursor mode to portal.c. --- plugins/linux-pipewire/pipewire.c | 36 +++++-------------------------- plugins/linux-pipewire/portal.c | 19 ++++++++++++++++ plugins/linux-pipewire/portal.h | 1 + 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/plugins/linux-pipewire/pipewire.c b/plugins/linux-pipewire/pipewire.c index 8e25acac4..284e4b738 100644 --- a/plugins/linux-pipewire/pipewire.c +++ b/plugins/linux-pipewire/pipewire.c @@ -71,8 +71,6 @@ struct _obs_pipewire_data { uint32_t pipewire_node; int pipewire_fd; - uint32_t available_cursor_modes; - obs_source_t *source; obs_data_t *settings; @@ -1211,6 +1209,7 @@ static void select_source(obs_pipewire_data *obs_pw) { struct dbus_call_data *call; GVariantBuilder builder; + uint32_t available_cursor_modes; char *request_token; char *request_path; @@ -1227,10 +1226,12 @@ static void select_source(obs_pipewire_data *obs_pw) g_variant_builder_add(&builder, "{sv}", "handle_token", g_variant_new_string(request_token)); - if (obs_pw->available_cursor_modes & 4) + available_cursor_modes = portal_get_available_cursor_modes(); + + if (available_cursor_modes & 4) g_variant_builder_add(&builder, "{sv}", "cursor_mode", g_variant_new_uint32(4)); - else if ((obs_pw->available_cursor_modes & 2) && obs_pw->cursor.visible) + else if ((available_cursor_modes & 2) && obs_pw->cursor.visible) g_variant_builder_add(&builder, "{sv}", "cursor_mode", g_variant_new_uint32(2)); else @@ -1346,31 +1347,6 @@ static void create_session(obs_pipewire_data *obs_pw) /* ------------------------------------------------- */ -static void update_available_cursor_modes(obs_pipewire_data *obs_pw, - GDBusProxy *proxy) -{ - g_autoptr(GVariant) cached_cursor_modes = NULL; - uint32_t available_cursor_modes; - - cached_cursor_modes = - g_dbus_proxy_get_cached_property(proxy, "AvailableCursorModes"); - available_cursor_modes = - cached_cursor_modes ? g_variant_get_uint32(cached_cursor_modes) - : 0; - - obs_pw->available_cursor_modes = available_cursor_modes; - - blog(LOG_INFO, "[pipewire] Available cursor modes:"); - if (available_cursor_modes & 4) - blog(LOG_INFO, "[pipewire] - Metadata"); - if (available_cursor_modes & 2) - blog(LOG_INFO, "[pipewire] - Always visible"); - if (available_cursor_modes & 1) - blog(LOG_INFO, "[pipewire] - Hidden"); -} - -/* ------------------------------------------------- */ - static gboolean init_obs_pipewire(obs_pipewire_data *obs_pw) { GDBusConnection *connection; @@ -1385,8 +1361,6 @@ static gboolean init_obs_pipewire(obs_pipewire_data *obs_pw) if (!proxy) return FALSE; - update_available_cursor_modes(obs_pw, proxy); - obs_pw->sender_name = bstrdup(g_dbus_connection_get_unique_name(connection) + 1); diff --git a/plugins/linux-pipewire/portal.c b/plugins/linux-pipewire/portal.c index f203470b6..b21ae6d27 100644 --- a/plugins/linux-pipewire/portal.c +++ b/plugins/linux-pipewire/portal.c @@ -73,6 +73,25 @@ uint32_t portal_get_available_capture_types(void) return available_source_types; } +uint32_t portal_get_available_cursor_modes(void) +{ + g_autoptr(GVariant) cached_cursor_modes = NULL; + uint32_t available_cursor_modes; + + ensure_proxy(); + + if (!proxy) + return 0; + + cached_cursor_modes = + g_dbus_proxy_get_cached_property(proxy, "AvailableCursorModes"); + available_cursor_modes = + cached_cursor_modes ? g_variant_get_uint32(cached_cursor_modes) + : 0; + + return available_cursor_modes; +} + uint32_t portal_get_screencast_version(void) { g_autoptr(GVariant) cached_version = NULL; diff --git a/plugins/linux-pipewire/portal.h b/plugins/linux-pipewire/portal.h index e26bdeabd..3badc5de8 100644 --- a/plugins/linux-pipewire/portal.h +++ b/plugins/linux-pipewire/portal.h @@ -24,6 +24,7 @@ #include uint32_t portal_get_available_capture_types(void); +uint32_t portal_get_available_cursor_modes(void); uint32_t portal_get_screencast_version(void); GDBusConnection *portal_get_dbus_connection(void);