compat: update battery display to work with new version

This commit is contained in:
Kiana Sheibani 2026-01-30 14:16:42 -05:00
parent fb9ef6cd21
commit 20ac6d0315
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -1,6 +1,7 @@
import Quickshell import Quickshell
import Quickshell.Services.UPower import Quickshell.Services.UPower
import QtQuick import QtQuick
import QtQuick.Effects
import QtQuick.Layouts import QtQuick.Layouts
import qs.services import qs.services
import qs.config import qs.config
@ -84,7 +85,7 @@ Container {
} }
} }
MaterialIcon { Item {
id: battery id: battery
objectName: "battery" objectName: "battery"
@ -92,13 +93,20 @@ Container {
Layout.leftMargin: hasBattery ? -2 : 0 Layout.leftMargin: hasBattery ? -2 : 0
Layout.topMargin: hasBattery ? 0.5 : 2 Layout.topMargin: hasBattery ? 0.5 : 2
implicitWidth: batteryIcon.width
implicitHeight: batteryIcon.height
readonly property bool hasBattery: UPower.displayDevice.isLaptopBattery readonly property bool hasBattery: UPower.displayDevice.isLaptopBattery
readonly property real percentage: UPower.displayDevice.percentage readonly property real percentage: 0.5 // Power.displayDevice.percentage
readonly property bool charging: !UPower.onBattery && batteryText.text !== "100" readonly property bool charging: !UPower.onBattery && batteryText.text !== "100"
readonly property bool warning: UPower.onBattery && percentage < Config.services.batteryWarning + 0.01 readonly property bool warning: UPower.onBattery && percentage < Config.services.batteryWarning + 0.01
MaterialIcon {
id: batteryIcon
anchors.centerIn: parent
text: { text: {
if (!hasBattery) { if (!battery.hasBattery) {
if (PowerProfiles.profile === PowerProfile.PowerSaver) if (PowerProfiles.profile === PowerProfile.PowerSaver)
return "energy_savings_leaf"; return "energy_savings_leaf";
if (PowerProfiles.profile === PowerProfile.Performance) if (PowerProfiles.profile === PowerProfile.Performance)
@ -108,31 +116,43 @@ Container {
return `battery_android_full`; return `battery_android_full`;
} }
fill: 1 fill: 1
font.pointSize: hasBattery ? 18 : Config.font.size.normal font.pointSize: battery.hasBattery ? 18 : Config.font.size.normal
grade: 50 grade: 50
font.weight: 100 font.weight: 100
color: !hasBattery ? Config.colors.secondary : color: !battery.hasBattery ? Config.colors.secondary :
warning ? Config.colors.errorBg : battery.warning ? Config.colors.errorBg :
batteryText.text === "100" ? Config.colors.battery : batteryText.text === "100" ? Config.colors.battery :
Color.mute(Config.colors.battery, 0.6, 1.5) Color.mute(Config.colors.battery, 0.6, 1.5)
layer.enabled: true
}
Item {
id: meter
anchors.fill: batteryIcon
visible: false
CustomRect { CustomRect {
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.left: parent.left anchors.left: parent.left
anchors.topMargin: 9 width: battery.width * battery.percentage
anchors.bottomMargin: 9 color: battery.warning ? Config.colors.batteryWarning : Config.colors.battery
anchors.leftMargin: 3 }
width: (battery.width - 7) * battery.percentage }
radius: 2
MultiEffect {
anchors.fill: batteryIcon
visible: battery.hasBattery visible: battery.hasBattery
color: battery.warning ? Config.colors.batteryWarning : Config.colors.battery source: meter
maskEnabled: true
maskSource: batteryIcon
} }
Row { Row {
anchors.centerIn: parent anchors.centerIn: parent
anchors.horizontalCenterOffset: battery.charging ? width / 20 : -width / 15 anchors.horizontalCenterOffset: battery.charging ? 0 : -width / 10
visible: battery.hasBattery visible: battery.hasBattery
spacing: -1 spacing: -1
@ -155,7 +175,7 @@ Container {
visible: battery.charging visible: battery.charging
text: "bolt" text: "bolt"
fill: 1 fill: 1
color: Config.colors.bg color: battery.warning ? Config.colors.batteryWarning : Config.colors.bg
font.pointSize: 7 font.pointSize: 7
font.weight: 300 font.weight: 300
} }