mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
pw-top: update name when it changes
Recalculate the display name for a given node after its properties change.
This commit is contained in:
parent
9a5609de2b
commit
9d439bac06
1 changed files with 32 additions and 13 deletions
|
|
@ -165,6 +165,31 @@ static const struct pw_proxy_events proxy_events = {
|
||||||
|
|
||||||
static void do_refresh(struct data *d, bool force_refresh);
|
static void do_refresh(struct data *d, bool force_refresh);
|
||||||
|
|
||||||
|
static const char *find_node_name(const struct spa_dict *props)
|
||||||
|
{
|
||||||
|
static const char * const name_keys[] = {
|
||||||
|
PW_KEY_NODE_NAME,
|
||||||
|
PW_KEY_NODE_DESCRIPTION,
|
||||||
|
PW_KEY_APP_NAME,
|
||||||
|
};
|
||||||
|
|
||||||
|
SPA_FOR_EACH_ELEMENT_VAR(name_keys, key) {
|
||||||
|
const char *name = spa_dict_lookup(props, *key);
|
||||||
|
if (name)
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_node_name(struct node *n, const char *name)
|
||||||
|
{
|
||||||
|
if (name)
|
||||||
|
snprintf(n->name, sizeof(n->name), "%s", name);
|
||||||
|
else
|
||||||
|
snprintf(n->name, sizeof(n->name), "%u", n->id);
|
||||||
|
}
|
||||||
|
|
||||||
static void node_info(void *data, const struct pw_node_info *info)
|
static void node_info(void *data, const struct pw_node_info *info)
|
||||||
{
|
{
|
||||||
struct node *n = data;
|
struct node *n = data;
|
||||||
|
|
@ -173,6 +198,9 @@ static void node_info(void *data, const struct pw_node_info *info)
|
||||||
n->state = info->state;
|
n->state = info->state;
|
||||||
do_refresh(n->data, !n->data->batch_mode);
|
do_refresh(n->data, !n->data->batch_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info->change_mask & PW_NODE_CHANGE_MASK_PROPS)
|
||||||
|
set_node_name(n, find_node_name(info->props));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void node_param(void *data, int seq,
|
static void node_param(void *data, int seq,
|
||||||
|
|
@ -294,13 +322,10 @@ static struct node *add_node(struct data *d, uint32_t id, const char *name)
|
||||||
if ((n = calloc(1, sizeof(*n))) == NULL)
|
if ((n = calloc(1, sizeof(*n))) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (name)
|
|
||||||
strncpy(n->name, name, MAX_NAME);
|
|
||||||
else
|
|
||||||
snprintf(n->name, sizeof(n->name), "%u", id);
|
|
||||||
n->data = d;
|
n->data = d;
|
||||||
n->id = id;
|
n->id = id;
|
||||||
n->driver = n;
|
n->driver = n;
|
||||||
|
|
||||||
n->proxy = pw_registry_bind(d->registry, id, PW_TYPE_INTERFACE_Node, PW_VERSION_NODE, 0);
|
n->proxy = pw_registry_bind(d->registry, id, PW_TYPE_INTERFACE_Node, PW_VERSION_NODE, 0);
|
||||||
if (n->proxy) {
|
if (n->proxy) {
|
||||||
uint32_t ids[1] = { SPA_PARAM_Format };
|
uint32_t ids[1] = { SPA_PARAM_Format };
|
||||||
|
|
@ -318,6 +343,8 @@ static struct node *add_node(struct data *d, uint32_t id, const char *name)
|
||||||
if (!d->batch_mode)
|
if (!d->batch_mode)
|
||||||
d->pending_refresh = true;
|
d->pending_refresh = true;
|
||||||
|
|
||||||
|
set_node_name(n, name);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -623,16 +650,8 @@ static void registry_event_global(void *data, uint32_t id,
|
||||||
struct pw_proxy *proxy;
|
struct pw_proxy *proxy;
|
||||||
|
|
||||||
if (spa_streq(type, PW_TYPE_INTERFACE_Node)) {
|
if (spa_streq(type, PW_TYPE_INTERFACE_Node)) {
|
||||||
const char *str;
|
if (add_node(d, id, find_node_name(props)) == NULL)
|
||||||
|
|
||||||
if ((str = spa_dict_lookup(props, PW_KEY_NODE_NAME)) == NULL &&
|
|
||||||
(str = spa_dict_lookup(props, PW_KEY_NODE_DESCRIPTION)) == NULL) {
|
|
||||||
str = spa_dict_lookup(props, PW_KEY_APP_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (add_node(d, id, str) == NULL) {
|
|
||||||
pw_log_warn("can add node %u: %m", id);
|
pw_log_warn("can add node %u: %m", id);
|
||||||
}
|
|
||||||
} else if (spa_streq(type, PW_TYPE_INTERFACE_Profiler)) {
|
} else if (spa_streq(type, PW_TYPE_INTERFACE_Profiler)) {
|
||||||
if (d->profiler != NULL) {
|
if (d->profiler != NULL) {
|
||||||
printf("Ignoring profiler %d: already attached\n", id);
|
printf("Ignoring profiler %d: already attached\n", id);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue