global-proxy: Add collection-name property

Helper function to get the collection name of a global proxy easily. This
property can also be used in object interest constrains to select objects of
a particular collection.
This commit is contained in:
Julian Bouzas 2026-02-09 10:34:10 -05:00
parent e78a28f5b6
commit bf1d2c82b7
2 changed files with 41 additions and 0 deletions

View file

@ -7,6 +7,7 @@
*/
#include "global-proxy.h"
#include "collection-manager.h"
#include "private/registry.h"
#include "core.h"
#include "error.h"
@ -51,6 +52,7 @@ enum {
PROP_FACTORY_NAME,
PROP_GLOBAL_PROPERTIES,
PROP_PERMISSIONS,
PROP_COLLECTION_NAME,
};
G_DEFINE_TYPE_WITH_PRIVATE (WpGlobalProxy, wp_global_proxy, WP_TYPE_PROXY)
@ -125,6 +127,9 @@ wp_global_proxy_get_property (GObject * object, guint property_id,
case PROP_GLOBAL_PROPERTIES:
g_value_take_boxed (value, wp_global_proxy_get_global_properties (self));
break;
case PROP_COLLECTION_NAME:
g_value_set_string (value, wp_global_proxy_get_collection_name (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -308,6 +313,11 @@ wp_global_proxy_class_init (WpGlobalProxyClass * klass)
g_param_spec_uint ("permissions", "permissions",
"The pipewire global permissions", 0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_COLLECTION_NAME,
g_param_spec_string ("collection-name", "collection-name",
"The collection name this global proxy belongs to", NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
/*!
@ -376,6 +386,34 @@ wp_global_proxy_get_global_properties (WpGlobalProxy * self)
return NULL;
}
/*!
* \brief Gets the collection name of the pipewire global if it was collected
* into a collection.
* \ingroup wpglobalproxy
* \param self the pipewire global
* \returns (nullable): the collection name this pipewire global belongs to, or
* NULL if the pipewire global does not belong to any collection
*/
const gchar *
wp_global_proxy_get_collection_name (WpGlobalProxy * self)
{
g_autoptr (WpCore) core = NULL;
const gchar *collection_name = NULL;
core = wp_object_get_core (WP_OBJECT (self));
if (core) {
g_autoptr (WpCollectionManager) cm = NULL;
cm = wp_collection_manager_find (core, NULL);
if (cm) {
g_autoptr (WpCollection) c = NULL;
c = wp_collection_manager_get_global_collection (cm, self);
if (c)
collection_name = wp_collection_get_name (c);
}
}
return collection_name;
}
/*!
* \brief Binds to the global and creates the underlying `pw_proxy`.
*

View file

@ -41,6 +41,9 @@ WP_API
WpProperties * wp_global_proxy_get_global_properties (
WpGlobalProxy * self);
WP_API
const gchar * wp_global_proxy_get_collection_name (WpGlobalProxy * self);
WP_API
gboolean wp_global_proxy_bind (WpGlobalProxy * self);