From 984a840a8dc191392cebb16d03a51fccbd520fc1 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sun, 25 Jan 2026 04:39:31 -0500 Subject: [PATCH] refactor: make battery indicator more consistent --- config/Config.qml | 2 ++ modules/bar/modules/StatusIcons.qml | 4 ++-- modules/bar/popouts/Battery.qml | 13 +++++++------ modules/bar/popouts/Content.qml | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/config/Config.qml b/config/Config.qml index d8b9e22..e2269aa 100644 --- a/config/Config.qml +++ b/config/Config.qml @@ -161,6 +161,8 @@ Singleton { } readonly property QtObject services: QtObject { + readonly property real batteryWarning: 0.15 + readonly property string weatherLocation: "" readonly property bool useFahrenheit: [Locale.ImperialUSSystem, Locale.ImperialSystem].includes(Qt.locale().measurementSystem) diff --git a/modules/bar/modules/StatusIcons.qml b/modules/bar/modules/StatusIcons.qml index 59a9c17..f5bff04 100644 --- a/modules/bar/modules/StatusIcons.qml +++ b/modules/bar/modules/StatusIcons.qml @@ -95,7 +95,7 @@ Container { readonly property bool hasBattery: UPower.displayDevice.isLaptopBattery readonly property real percentage: UPower.displayDevice.percentage readonly property bool charging: !UPower.onBattery && batteryText.text !== "100" - readonly property bool warning: UPower.onBattery && percentage < 0.15 + readonly property bool warning: UPower.onBattery && percentage < Config.services.batteryWarning + 0.01 text: { if (!hasBattery) { @@ -142,7 +142,7 @@ Container { anchors.verticalCenter: parent.verticalCenter anchors.verticalCenterOffset: 0.5 - text: Math.round(battery.percentage * 100) + text: Math.floor(battery.percentage * 100) color: battery.warning ? Config.colors.batteryWarning : Config.colors.bg font.family: Config.font.family.mono font.pointSize: 6 diff --git a/modules/bar/popouts/Battery.qml b/modules/bar/popouts/Battery.qml index 5553f32..ff1fafa 100644 --- a/modules/bar/popouts/Battery.qml +++ b/modules/bar/popouts/Battery.qml @@ -13,14 +13,15 @@ ColumnLayout { spacing: 4 - readonly property color color: UPower.onBattery && UPower.displayDevice.percentage < 0.15 ? - Config.colors.batteryWarning : - Config.colors.battery + readonly property bool hasBattery: UPower.displayDevice.isLaptopBattery + readonly property real percentage: UPower.displayDevice.percentage + readonly property bool warning: UPower.onBattery && percentage < Config.services.batteryWarning + 0.01 + readonly property color color: warning ? Config.colors.batteryWarning : Config.colors.battery Loader { Layout.alignment: Qt.AlignHCenter - active: UPower.displayDevice.isLaptopBattery + active: root.hasBattery asynchronous: true height: active ? (item?.implicitHeight ?? 0) : 0 @@ -76,7 +77,7 @@ ColumnLayout { radiusX: (meter.size + meter.thickness) / 2 + meter.padding radiusY: radiusX startAngle: -90 - meter.angle / 2 - sweepAngle: meter.angle * UPower.displayDevice.percentage + sweepAngle: meter.angle * root.percentage } Behavior on strokeColor { @@ -98,7 +99,7 @@ ColumnLayout { CustomText { anchors.horizontalCenter: parent.horizontalCenter - text: Math.round(UPower.displayDevice.percentage * 100) + "%" + text: Math.floor(root.percentage * 100) + "%" font.pointSize: Config.font.size.largest } diff --git a/modules/bar/popouts/Content.qml b/modules/bar/popouts/Content.qml index 1ab7152..18e50ae 100644 --- a/modules/bar/popouts/Content.qml +++ b/modules/bar/popouts/Content.qml @@ -67,7 +67,7 @@ Item { name: "battery" source: "Battery.qml" color: UPower.displayDevice.isLaptopBattery && - UPower.onBattery && UPower.displayDevice.percentage < 0.15 ? + UPower.onBattery && UPower.displayDevice.percentage < Config.services.batteryWarning + 0.01 ? Config.colors.batteryWarning : Config.colors.battery }