diff --git a/src/bluealsactl/cmd-list-pcms.c b/src/bluealsactl/cmd-list-pcms.c index cac1a26ca..bd9889ee2 100644 --- a/src/bluealsactl/cmd-list-pcms.c +++ b/src/bluealsactl/cmd-list-pcms.c @@ -11,12 +11,21 @@ #include #include #include +#include #include #include "bluealsactl.h" #include "shared/dbus-client-pcm.h" +static int ba_pcm_cmp(const void *a, const void *b) { + const struct ba_pcm *pcm_a = a; + const struct ba_pcm *pcm_b = b; + if (pcm_a->sequence == pcm_b->sequence) + return strcmp(pcm_a->pcm_path, pcm_b->pcm_path); + return pcm_a->sequence - pcm_b->sequence; +} + static void usage(const char *command) { printf("List all BlueALSA PCM paths.\n\n"); bactl_print_usage("%s [OPTION]...", command); @@ -64,6 +73,9 @@ static int cmd_list_pcms_func(int argc, char *argv[]) { return EXIT_FAILURE; } + /* Sort PCMs from the oldest to the newest (most recently added). */ + qsort(pcms, pcms_count, sizeof(*pcms), ba_pcm_cmp); + for (size_t i = 0; i < pcms_count; i++) { printf("%s\n", pcms[i].pcm_path); if (config.verbose) {