From 876cd21f0b3ca93a62c0dd8d05e58df8d946ce01 Mon Sep 17 00:00:00 2001 From: "Yamada.Kazuyoshi" Date: Wed, 25 Feb 2026 05:42:47 +0900 Subject: [PATCH] display battery consumption / charging W (#1814) --- .../Modules/DankBar/Popouts/BatteryPopout.qml | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/quickshell/Modules/DankBar/Popouts/BatteryPopout.qml b/quickshell/Modules/DankBar/Popouts/BatteryPopout.qml index 8da438dd..90fd940c 100644 --- a/quickshell/Modules/DankBar/Popouts/BatteryPopout.qml +++ b/quickshell/Modules/DankBar/Popouts/BatteryPopout.qml @@ -167,9 +167,22 @@ DankPopout { } Column { + id: headerInfoColumn spacing: Theme.spacingXS anchors.verticalCenter: parent.verticalCenter width: parent.width - Theme.iconSizeLarge - 32 - Theme.spacingM * 2 + readonly property string timeInfoText: { + if (!BatteryService.batteryAvailable) + return "Power profile management available"; + const time = BatteryService.formatTimeRemaining(); + if (time !== "Unknown") { + return BatteryService.isCharging ? `Time until full: ${time}` : `Time remaining: ${time}`; + } + return ""; + } + readonly property bool showPowerRate: BatteryService.batteryAvailable && Math.abs(BatteryService.changeRate) > 0.05 + readonly property bool isOnAC: BatteryService.batteryAvailable && (BatteryService.isCharging || BatteryService.isPluggedIn) + readonly property bool isDischarging: BatteryService.batteryAvailable && !BatteryService.isCharging && !BatteryService.isPluggedIn Row { spacing: Theme.spacingS @@ -207,21 +220,35 @@ DankPopout { } } - StyledText { - text: { - if (!BatteryService.batteryAvailable) - return "Power profile management available"; - const time = BatteryService.formatTimeRemaining(); - if (time !== "Unknown") { - return BatteryService.isCharging ? `Time until full: ${time}` : `Time remaining: ${time}`; - } - return ""; - } - font.pixelSize: Theme.fontSizeSmall - color: Theme.surfaceTextMedium - visible: text.length > 0 - elide: Text.ElideRight + Row { width: parent.width + spacing: Theme.spacingS + visible: headerInfoColumn.timeInfoText.length > 0 + + StyledText { + id: powerRateText + text: `${headerInfoColumn.isOnAC ? "+" : (headerInfoColumn.isDischarging ? "-" : "")}${Math.abs(BatteryService.changeRate).toFixed(1)}W` + font.pixelSize: Theme.fontSizeSmall + color: { + if (headerInfoColumn.isOnAC) { + return Theme.primary; + } + if (headerInfoColumn.isDischarging) { + return Theme.warning; + } + return Theme.surfaceTextMedium; + } + font.weight: Font.Medium + visible: headerInfoColumn.showPowerRate + } + + StyledText { + text: headerInfoColumn.timeInfoText + font.pixelSize: Theme.fontSizeSmall + color: Theme.surfaceTextMedium + elide: Text.ElideRight + width: parent.width - (powerRateText.visible ? (powerRateText.implicitWidth + parent.spacing) : 0) + } } }