2025-12-31 15:59:41 +01:00
|
|
|
pragma ComponentBehavior: Bound
|
2025-12-21 20:59:33 +01:00
|
|
|
import Quickshell.Services.UPower
|
|
|
|
|
import QtQuick
|
|
|
|
|
import Quickshell.Widgets
|
2025-12-28 13:25:31 +01:00
|
|
|
import "../../"
|
|
|
|
|
import "../settings/"
|
2025-12-31 11:04:34 +01:00
|
|
|
import QtQuick.Layouts
|
2025-12-21 20:59:33 +01:00
|
|
|
|
2025-12-31 16:40:43 +01:00
|
|
|
Loader {
|
2025-12-21 20:59:33 +01:00
|
|
|
id: root
|
2025-12-31 11:04:34 +01:00
|
|
|
visible: UPower.displayDevice.isLaptopBattery
|
2025-12-31 16:40:43 +01:00
|
|
|
width: masterLayout.implicitWidth
|
|
|
|
|
height: 34
|
2025-12-31 11:04:34 +01:00
|
|
|
ColumnLayout {
|
|
|
|
|
id: masterLayout
|
2025-12-21 20:59:33 +01:00
|
|
|
anchors.centerIn: parent
|
2025-12-31 11:04:34 +01:00
|
|
|
spacing: 0
|
|
|
|
|
Row {
|
|
|
|
|
spacing: 5
|
|
|
|
|
Text {
|
|
|
|
|
id: topText
|
|
|
|
|
font.weight: 900
|
|
|
|
|
font.family: Settings.font
|
|
|
|
|
font.pixelSize: Settings.fontSize
|
|
|
|
|
text: Math.round(UPower.displayDevice.percentage * 100) + "%"
|
|
|
|
|
color: Colors.foreground
|
|
|
|
|
}
|
2025-12-31 15:59:41 +01:00
|
|
|
Icons {
|
2025-12-31 16:13:18 +01:00
|
|
|
property bool isCharging: UPower.displayDevice.state === UPowerDeviceState.Charging
|
2025-12-31 15:59:41 +01:00
|
|
|
function getBatteryIcon() {
|
2025-12-31 16:13:18 +01:00
|
|
|
if (isCharging) {
|
|
|
|
|
return "battery_android_frame_bolt";
|
2025-12-31 15:59:41 +01:00
|
|
|
}
|
2025-12-31 16:13:18 +01:00
|
|
|
if (UPower.displayDevice.percentage < 0.12) {
|
|
|
|
|
return "battery_android_frame_0";
|
2025-12-31 15:59:41 +01:00
|
|
|
}
|
2025-12-31 16:13:18 +01:00
|
|
|
if (UPower.displayDevice.percentage < 0.24) {
|
|
|
|
|
return "battery_android_frame_1";
|
2025-12-31 15:59:41 +01:00
|
|
|
}
|
2025-12-31 16:13:18 +01:00
|
|
|
if (UPower.displayDevice.percentage < 0.36) {
|
|
|
|
|
return "battery_android_frame_2";
|
2025-12-31 15:59:41 +01:00
|
|
|
}
|
2025-12-31 16:13:18 +01:00
|
|
|
if (UPower.displayDevice.percentage < 0.48) {
|
|
|
|
|
return "battery_android_frame_3";
|
2025-12-31 15:59:41 +01:00
|
|
|
}
|
2025-12-31 16:13:18 +01:00
|
|
|
if (UPower.displayDevice.percentage < 0.60) {
|
|
|
|
|
return "battery_android_frame_4";
|
2025-12-31 15:59:41 +01:00
|
|
|
}
|
2025-12-31 16:13:18 +01:00
|
|
|
if (UPower.displayDevice.percentage < 0.72) {
|
|
|
|
|
return "battery_android_frame_5";
|
2025-12-31 15:59:41 +01:00
|
|
|
}
|
2025-12-31 16:13:18 +01:00
|
|
|
if (UPower.displayDevice.percentage < 0.84) {
|
|
|
|
|
return "battery_android_frame_6";
|
|
|
|
|
}
|
|
|
|
|
if (UPower.displayDevice.percentage > 0.84) {
|
2025-12-31 15:59:41 +01:00
|
|
|
return "battery_android_full";
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-31 16:13:18 +01:00
|
|
|
text: getBatteryIcon()
|
2025-12-31 11:04:34 +01:00
|
|
|
}
|
2025-12-21 20:59:33 +01:00
|
|
|
}
|
|
|
|
|
Text {
|
2025-12-31 11:04:34 +01:00
|
|
|
id: botText
|
2025-12-31 11:15:59 +01:00
|
|
|
property var timeToEmpty: UPower.displayDevice.timeToEmpty / 60 / 60
|
2025-12-31 11:23:48 +01:00
|
|
|
property var timeToFull: UPower.displayDevice.timeToFull / 60 / 60
|
|
|
|
|
property bool isCharging: UPower.displayDevice.state === UPowerDeviceState.Charging
|
2025-12-31 11:15:59 +01:00
|
|
|
font.weight: 600
|
2025-12-28 13:25:31 +01:00
|
|
|
font.family: Settings.font
|
2025-12-31 11:15:59 +01:00
|
|
|
font.pixelSize: Settings.fontSize - 2
|
|
|
|
|
opacity: 0.7
|
2025-12-21 20:59:33 +01:00
|
|
|
color: Colors.foreground
|
2025-12-31 11:23:48 +01:00
|
|
|
text: isCharging ? timeToFull.toFixed(1) + "h to full" : timeToEmpty.toFixed(1) + "h left"
|
2025-12-31 16:13:18 +01:00
|
|
|
onTextChanged: console.log(UPower.displayDevice.percentage)
|
2025-12-21 20:59:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|