Skip to content

Commit afccf15

Browse files
committed
Sort PCM D-Bus paths from the oldest to the newest
1 parent 07a4be7 commit afccf15

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/bluealsactl/cmd-list-pcms.c

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
#include "bluealsactl.h"
1818
#include "shared/dbus-client-pcm.h"
1919

20+
static int ba_pcm_cmp(const void *a, const void *b) {
21+
const struct ba_pcm *pcm_a = a;
22+
const struct ba_pcm *pcm_b = b;
23+
if (pcm_a->sequence == pcm_b->sequence)
24+
return strcmp(pcm_a->pcm_path, pcm_b->pcm_path);
25+
return pcm_a->sequence - pcm_b->sequence;
26+
}
27+
2028
static void usage(const char *command) {
2129
printf("List all BlueALSA PCM paths.\n\n");
2230
bactl_print_usage("%s [OPTION]...", command);
@@ -64,6 +72,9 @@ static int cmd_list_pcms_func(int argc, char *argv[]) {
6472
return EXIT_FAILURE;
6573
}
6674

75+
/* Sort PCMs from the oldest to the newest (most recently added). */
76+
qsort(pcms, pcms_count, sizeof(*pcms), ba_pcm_cmp);
77+
6778
for (size_t i = 0; i < pcms_count; i++) {
6879
printf("%s\n", pcms[i].pcm_path);
6980
if (config.verbose) {

0 commit comments

Comments
 (0)