From f924dbfbbb8f1a0fe8c36ccca254063f1bbe0e1b Mon Sep 17 00:00:00 2001 From: Evertiro Date: Thu, 2 Apr 2026 23:32:00 -0500 Subject: [PATCH] feat: show battery status in Bluetooth popout (#1130) * Display bluetooth battery in popout when possible Signed-off-by: Dan Griffiths * Actually return the alert icon if battery status can't be determined Signed-off-by: Dan Griffiths * Fix lint error Signed-off-by: Dan Griffiths * move icon to right + static popout width --------- Signed-off-by: Dan Griffiths Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> --- modules/bar/popouts/Bluetooth.qml | 9 +++++++++ utils/Icons.qml | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/modules/bar/popouts/Bluetooth.qml b/modules/bar/popouts/Bluetooth.qml index 2e87270a..027b3d41 100644 --- a/modules/bar/popouts/Bluetooth.qml +++ b/modules/bar/popouts/Bluetooth.qml @@ -15,6 +15,7 @@ ColumnLayout { required property PopoutState popouts + width: 300 spacing: Appearance.spacing.small StyledText { @@ -99,6 +100,13 @@ ColumnLayout { Layout.rightMargin: Appearance.spacing.small / 2 Layout.fillWidth: true text: device.modelData.name + elide: Text.ElideRight + } + + MaterialIcon { + visible: device.modelData.state === BluetoothDeviceState.Connected // qmllint disable unresolved-type + text: Icons.getBatteryIcon(device.modelData.batteryAvailable ? device.modelData.battery * 100 : -1) + color: device.modelData.battery < 0.2 ? Colours.palette.m3error : Colours.palette.m3onSurfaceVariant } StyledRect { @@ -141,6 +149,7 @@ ColumnLayout { } Loader { + visible: status === Loader.Ready asynchronous: true active: device.modelData.bonded sourceComponent: Item { diff --git a/utils/Icons.qml b/utils/Icons.qml index 8a62f62d..aded0f4b 100644 --- a/utils/Icons.qml +++ b/utils/Icons.qml @@ -240,4 +240,24 @@ Singleton { } return icon; } + + function getBatteryIcon(charge: int): string { + if (charge > 0 && charge < 5) + return "battery_0_bar"; + if (charge >= 5 && charge < 20) + return "battery_1_bar"; + if (charge >= 20 && charge < 35) + return "battery_2_bar"; + if (charge >= 35 && charge < 50) + return "battery_3_bar"; + if (charge >= 50 && charge < 65) + return "battery_4_bar"; + if (charge >= 65 && charge < 80) + return "battery_5_bar"; + if (charge >= 80 && charge < 95) + return "battery_6_bar"; + if (charge >= 95) + return "battery_full"; + return "battery_alert"; + } }