From 3ff724e4ea60ae411a48353e8b1fbd93376cb4ef Mon Sep 17 00:00:00 2001 From: bbedward Date: Mon, 12 Oct 2026 11:07:05 -0400 Subject: [PATCH] bluetooth: treat alias-is-address as the only unnamed case when sorting scan results fixes #3761 --- quickshell/Services/BluetoothService.qml | 11 +++++++++-- quickshell/tests/bluez-codec.test.mjs | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/quickshell/Services/BluetoothService.qml b/quickshell/Services/BluetoothService.qml index 69a4f66f3..d05924128 100644 --- a/quickshell/Services/BluetoothService.qml +++ b/quickshell/Services/BluetoothService.qml @@ -339,6 +339,13 @@ Singleton { }); } + function hasRealName(device) { + const name = device.name || device.deviceName || ""; + if (!name) + return false; + return name !== (device.address || "").replace(/:/g, "-"); + } + function sortDevices(devices) { return devices.sort((a, b) => { const aName = a.name || a.deviceName || ""; @@ -346,8 +353,8 @@ Singleton { const aAddr = a.address || ""; const bAddr = b.address || ""; - const aHasRealName = aName.includes(" ") && aName.length > 3; - const bHasRealName = bName.includes(" ") && bName.length > 3; + const aHasRealName = hasRealName(a); + const bHasRealName = hasRealName(b); if (aHasRealName && !bHasRealName) return -1; diff --git a/quickshell/tests/bluez-codec.test.mjs b/quickshell/tests/bluez-codec.test.mjs index 6969d958e..c2f21f983 100644 --- a/quickshell/tests/bluez-codec.test.mjs +++ b/quickshell/tests/bluez-codec.test.mjs @@ -446,3 +446,14 @@ test("LHDC codecs carry a name, description and category", () => { assert.equal(context.codecNameFromProfile("a2dp-sink"), ""); assert.equal(context.codecNameFromProfile("a2dp-sink-aac"), "AAC"); }); + +// BlueZ Alias falls back to the dashed address when a device sends no name. +test("scan list sorts named devices above alias-is-address devices", () => { + const context = methods(["hasRealName", "sortDevices"]); + const sorted = context.sortDevices([ + { name: "23-5F-24-05-F3-4A", address: "23:5F:24:05:F3:4A" }, + { name: "ATH-M20xBT", address: "AA:BB:CC:DD:EE:FF" }, + { name: "", deviceName: "", address: "01:02:03:04:05:06" } + ]); + assert.deepEqual(sorted.map(d => d.address), ["AA:BB:CC:DD:EE:FF", "01:02:03:04:05:06", "23:5F:24:05:F3:4A"]); +});