add battery for laptops

This commit is contained in:
Benjamin Palko 2025-09-03 12:00:54 -04:00
parent 9505748b32
commit d043f86269
3 changed files with 74 additions and 0 deletions

View file

@ -107,6 +107,8 @@ PanelWindow {
Gpu {} Gpu {}
Power {}
Clock {} Clock {}
Notifications {} Notifications {}

View file

@ -0,0 +1,60 @@
import qs.components
import qs.config
import qs.constants
import qs.widgets
import QtQuick
import QtQuick.Layouts
import Quickshell.Services.UPower
StyledButton {
id: root
property UPowerDevice laptopBattery: UPower.devices.values.find(device => device.isLaptopBattery)
property bool isCritical: laptopBattery.percentage < 0.10
contentItem: RowLayout {
spacing: 4
LucideIcon {
Layout.alignment: Qt.AlignVCenter
color: {
if (root.isCritical) {
return Theme.palette.error;
}
if (root.hovered) {
return Theme.palette.primarycontent;
}
return Theme.palette.basecontent;
}
font.pixelSize: 16
text: {
if (root.laptopBattery.state == UPowerDeviceState.Charging) {
return Icons.batteryCharging;
}
if (root.isCritical) {
return Icons.batteryWarning;
}
if (root.laptopBattery.percentage < 0.33) {
return Icons.batteryLow;
}
if (root.laptopBattery.percentage < 0.66) {
return Icons.batteryMedium;
}
return Icons.batteryFull;
}
}
StyledText {
Layout.alignment: Qt.AlignVCenter
color: {
if (root.isCritical) {
return Theme.palette.error;
}
if (root.hovered) {
return Theme.palette.primarycontent;
}
return Theme.palette.basecontent;
}
text: `${root.laptopBattery.percentage * 100}%`
}
}
visible: laptopBattery
}

12
services/PowerService.qml Normal file
View file

@ -0,0 +1,12 @@
pragma Singleton
import Quickshell
import Quickshell.Services.UPower
Singleton {
id: root
property bool onBattery: UPower.onBattery
property UPowerDevice laptopBattery: UPower.devices.values.find(device => device.isLaptopBattery)
}