From f179eb32587a6261ee196ccf3bf0030c4237dd6a Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Fri, 18 Apr 2025 22:48:43 -0500 Subject: fix bug where error msg always get sent when default sink is manually changed because the check of useridx != default_sink_index runs before the default sink callback is ran / finished running --- pavolctld.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pavolctld.c b/pavolctld.c index 6504f74..bb18d91 100644 --- a/pavolctld.c +++ b/pavolctld.c @@ -125,16 +125,18 @@ static void change_command_sink(pa_context *c, char *cmd) { } static void sink_info_change_default_sink_callback(pa_context *c, const pa_sink_info *i, int eol, void *userdata) { - int useridx = *(int *)userdata; + static int success = 0; // if the index passed to pa_context_get_sink_info_by_index is invalid, then eol is set immediately if (eol) { - if (useridx != default_sink_index) { - printf("e3,sink %d does not exist\n", useridx); // same as sink_info_change_command_sink_callback + if (!success) { + printf("e3,sink %d does not exist\n", *(int *)userdata); // same as sink_info_change_command_sink_callback fflush(stdout); } + success = 0; return; } + success = 1; pa_context_set_default_sink(c, i->name, NULL, NULL); } -- cgit v1.2.3