51 lines
1.2 KiB
QML
51 lines
1.2 KiB
QML
import Quickshell.Services.UPower
|
|
import Quickshell
|
|
import Quickshell.Widgets
|
|
import QtQuick
|
|
import QtQuick.Layouts
|
|
import QtQuick.Effects
|
|
import qs
|
|
import qs.widgets
|
|
import qs.settings
|
|
|
|
BarComponent {
|
|
id: root
|
|
visible: UPower.displayDevice.isLaptopBattery
|
|
property double percent: UPower.displayDevice.percentage * 100
|
|
property bool hasBattery: UPower.displayDevice.isLaptopBattery
|
|
property bool charging: UPower.displayDevice.state === UPowerDeviceState.Charging
|
|
implicitWidth: batLayout.implicitWidth + 16
|
|
|
|
function batteryIcon(): string {
|
|
const level = root.percent;
|
|
const chg = root.charging;
|
|
const isFull = root.full;
|
|
|
|
if (chg) {
|
|
return "battery-charging";
|
|
}
|
|
if (level <= 25) {
|
|
return "battery-warning";
|
|
}
|
|
if (level <= 50) {
|
|
return "battery-medium";
|
|
}
|
|
if (level <= 75) {
|
|
return "battery-high";
|
|
}
|
|
if (level > 75) {
|
|
return "battery-full";
|
|
}
|
|
}
|
|
RowLayout {
|
|
id: batLayout
|
|
anchors.centerIn: root
|
|
StyledIcon {
|
|
iconName: root.batteryIcon()
|
|
}
|
|
|
|
StyledText {
|
|
text: Math.floor(root.percent) + "%"
|
|
}
|
|
}
|
|
}
|