pipewire-pulse: Expose bluetooth headset autoswitch config as a message

Makes it easier for libpulse-based clients to modify this setting if
they want.
This commit is contained in:
Arun Raghavan 2026-01-26 14:44:30 -08:00
parent 703380d62d
commit ed59342d28
4 changed files with 69 additions and 8 deletions

View file

@ -133,6 +133,48 @@ static int core_object_force_mono_output(struct client *client, const char *para
}
}
static int core_object_bluetooth_headset_autoswitch(struct client *client, const char *params, FILE *response)
{
if (!client->have_bluetooth_headset_autoswitch) {
/* Not supported, return a null value to indicate that */
fprintf(response, "null");
return 0;
}
if (!params || params[0] == '\0') {
/* No parameter => query the current value */
fprintf(response, "%s", client->bluetooth_headset_autoswitch ? "true" : "false");
return 0;
} else {
/* The caller is trying to set a value or clear with a null */
int ret;
if (spa_streq(params, "true")) {
ret = pw_manager_set_metadata(client->manager, client->metadata_sm_settings, PW_ID_CORE,
METADATA_BLUETOOTH_HEADSET_AUTOSWITCH, "Spa:String:JSON", "true");
client->bluetooth_headset_autoswitch = true;
} else if (spa_streq(params, "false")) {
ret = pw_manager_set_metadata(client->manager, client->metadata_sm_settings, PW_ID_CORE,
METADATA_BLUETOOTH_HEADSET_AUTOSWITCH, "Spa:String:JSON", "false");
client->bluetooth_headset_autoswitch = false;
} else if (spa_streq(params, "null")) {
ret = pw_manager_set_metadata(client->manager, client->metadata_sm_settings, PW_ID_CORE,
METADATA_BLUETOOTH_HEADSET_AUTOSWITCH, NULL, NULL);
client->bluetooth_headset_autoswitch = client->default_bluetooth_headset_autoswitch;
} else {
fprintf(response, "Value must be true, false, or clear");
return -EINVAL;
}
if (ret < 0)
fprintf(response, "Could not set metadata: %s", spa_strerror(ret));
else
fprintf(response, "%s", params);
return ret;
}
}
static int core_object_message_handler(struct client *client, struct pw_manager_object *o, const char *message, const char *params, FILE *response)
{
pw_log_debug(": core %p object message:'%s' params:'%s'", o, message, params);
@ -141,14 +183,15 @@ static int core_object_message_handler(struct client *client, struct pw_manager_
fprintf(response,
"/core <command> [<params>]\n"
"available commands:\n"
" help this help\n"
" list-handlers show available object handlers\n"
" pipewire-pulse:malloc-info show malloc_info\n"
" pipewire-pulse:malloc-trim run malloc_trim\n"
" pipewire-pulse:log-level update log level with <params>\n"
" pipewire-pulse:list-modules list all module names\n"
" pipewire-pulse:describe-module describe module info for <params>\n"
" pipewire-pulse:force-mono-output force mono mixdown on all hardware outputs"
" help this help\n"
" list-handlers show available object handlers\n"
" pipewire-pulse:malloc-info show malloc_info\n"
" pipewire-pulse:malloc-trim run malloc_trim\n"
" pipewire-pulse:log-level update log level with <params>\n"
" pipewire-pulse:list-modules list all module names\n"
" pipewire-pulse:describe-module describe module info for <params>\n"
" pipewire-pulse:force-mono-output force mono mixdown on all hardware outputs\n"
" pipewire-pulse:bluetooth-headset-autoswitch use bluetooth headset mic if available"
);
} else if (spa_streq(message, "list-handlers")) {
bool first = true;
@ -211,6 +254,8 @@ static int core_object_message_handler(struct client *client, struct pw_manager_
}
} else if (spa_streq(message, "pipewire-pulse:force-mono-output")) {
return core_object_force_mono_output(client, params, response);
} else if (spa_streq(message, "pipewire-pulse:bluetooth-headset-autoswitch")) {
return core_object_bluetooth_headset_autoswitch(client, params, response);
} else {
return -ENOSYS;
}