diff --git a/modules/bar/Bar.qml b/modules/bar/Bar.qml index 1f468d4..c39e847 100644 --- a/modules/bar/Bar.qml +++ b/modules/bar/Bar.qml @@ -107,6 +107,8 @@ PanelWindow { Gpu {} + Power {} + Clock {} Notifications {} diff --git a/modules/bar/components/Power.qml b/modules/bar/components/Power.qml new file mode 100644 index 0000000..5cb6150 --- /dev/null +++ b/modules/bar/components/Power.qml @@ -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 +} diff --git a/services/PowerService.qml b/services/PowerService.qml new file mode 100644 index 0000000..09735ae --- /dev/null +++ b/services/PowerService.qml @@ -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) + +}