add battery for laptops
This commit is contained in:
parent
9505748b32
commit
d043f86269
3 changed files with 74 additions and 0 deletions
|
|
@ -107,6 +107,8 @@ PanelWindow {
|
||||||
|
|
||||||
Gpu {}
|
Gpu {}
|
||||||
|
|
||||||
|
Power {}
|
||||||
|
|
||||||
Clock {}
|
Clock {}
|
||||||
|
|
||||||
Notifications {}
|
Notifications {}
|
||||||
|
|
|
||||||
60
modules/bar/components/Power.qml
Normal file
60
modules/bar/components/Power.qml
Normal 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
12
services/PowerService.qml
Normal 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)
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue