2026-01-15 15:14:29 +01:00
|
|
|
import Quickshell.Services.UPower
|
2026-02-01 23:59:09 +01:00
|
|
|
import QtQuick.Layouts
|
2026-01-15 15:14:29 +01:00
|
|
|
import QtQuick
|
2026-01-19 00:06:43 +01:00
|
|
|
import Quickshell.Widgets
|
|
|
|
|
import Qt5Compat.GraphicalEffects
|
|
|
|
|
import Quickshell
|
2026-01-19 12:45:35 +01:00
|
|
|
import qs
|
|
|
|
|
import qs.reusables
|
|
|
|
|
import qs.settings
|
2026-01-15 15:14:29 +01:00
|
|
|
|
2026-01-15 17:43:03 +01:00
|
|
|
Loader {
|
|
|
|
|
id: batLoader
|
|
|
|
|
active: UPower.displayDevice.isLaptopBattery
|
2026-01-15 15:14:29 +01:00
|
|
|
|
2026-01-18 23:18:42 +01:00
|
|
|
sourceComponent: Rectangle {
|
|
|
|
|
id: container
|
|
|
|
|
radius: implicitHeight / 2
|
2026-02-13 01:41:29 +01:00
|
|
|
color: Colors.base00
|
2026-01-18 23:18:42 +01:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2026-02-06 14:29:25 +01:00
|
|
|
implicitWidth: UPower.displayDevice.isLaptopBattery ? root.implicitWidth + 20 : 0
|
2026-01-18 23:18:42 +01:00
|
|
|
implicitHeight: Settings.config.barHeight - 10
|
|
|
|
|
Item {
|
|
|
|
|
id: root
|
2026-01-19 00:06:43 +01:00
|
|
|
anchors.centerIn: parent
|
2026-01-16 14:44:10 +01:00
|
|
|
|
2026-01-18 23:18:42 +01:00
|
|
|
property bool frame1: UPower.displayDevice.percentage <= 0.16
|
|
|
|
|
property bool frame2: UPower.displayDevice.percentage < 0.32
|
|
|
|
|
property bool frame3: UPower.displayDevice.percentage < 0.48
|
|
|
|
|
property bool frame4: UPower.displayDevice.percentage < 0.74
|
|
|
|
|
property bool frame5: UPower.displayDevice.percentage < 0.90
|
|
|
|
|
property bool frame6: UPower.displayDevice.percentage <= 1
|
2026-01-16 14:44:10 +01:00
|
|
|
|
2026-01-18 23:18:42 +01:00
|
|
|
function getBatteryIcon() {
|
|
|
|
|
if (UPower.displayDevice.state == UPowerDeviceState.Charging) {
|
|
|
|
|
return "battery_android_frame_bolt";
|
|
|
|
|
}
|
|
|
|
|
if (frame1) {
|
2026-01-22 00:10:11 +01:00
|
|
|
return "battery_android_frame_1";
|
2026-01-18 23:18:42 +01:00
|
|
|
}
|
|
|
|
|
if (frame2) {
|
2026-01-22 00:10:11 +01:00
|
|
|
return "battery_android_frame_2";
|
2026-01-18 23:18:42 +01:00
|
|
|
}
|
|
|
|
|
if (frame3) {
|
2026-01-22 00:10:11 +01:00
|
|
|
return "battery_android_frame_3";
|
2026-01-18 23:18:42 +01:00
|
|
|
}
|
|
|
|
|
if (frame4) {
|
2026-01-22 00:10:11 +01:00
|
|
|
return "battery_android_frame_4";
|
2026-01-18 23:18:42 +01:00
|
|
|
}
|
|
|
|
|
if (frame5) {
|
2026-01-22 00:10:11 +01:00
|
|
|
return "battery_android_frame_5";
|
2026-01-18 23:18:42 +01:00
|
|
|
}
|
|
|
|
|
if (frame6) {
|
2026-01-22 00:10:11 +01:00
|
|
|
return "battery_android_frame_full";
|
2026-01-18 23:18:42 +01:00
|
|
|
}
|
2026-01-16 14:44:10 +01:00
|
|
|
}
|
2026-01-19 00:06:43 +01:00
|
|
|
function getProfileIcon() {
|
|
|
|
|
if (PowerProfiles.profile.toString() == "2") {
|
|
|
|
|
return "power-profile-performance-symbolic";
|
|
|
|
|
}
|
|
|
|
|
if (PowerProfiles.profile.toString() == "1") {
|
|
|
|
|
return "power-profile-balanced-symbolic";
|
|
|
|
|
}
|
|
|
|
|
if (PowerProfiles.profile.toString() == "0") {
|
|
|
|
|
return "power-profile-power-saver-symbolic";
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-16 14:44:10 +01:00
|
|
|
|
2026-01-18 23:18:42 +01:00
|
|
|
implicitWidth: batRow.width
|
|
|
|
|
implicitHeight: Settings.config.barHeight
|
2026-01-15 15:14:29 +01:00
|
|
|
|
2026-02-01 23:59:09 +01:00
|
|
|
RowLayout {
|
2026-01-18 23:18:42 +01:00
|
|
|
id: batRow
|
2026-02-07 23:26:24 +01:00
|
|
|
anchors.centerIn: parent
|
|
|
|
|
height: parent.height
|
2026-01-18 23:18:42 +01:00
|
|
|
spacing: 5
|
|
|
|
|
CustomText {
|
|
|
|
|
id: batText
|
2026-02-01 23:59:09 +01:00
|
|
|
|
2026-01-18 23:18:42 +01:00
|
|
|
text: Math.round(UPower.displayDevice.percentage * 100) + "%"
|
|
|
|
|
}
|
|
|
|
|
CustomIcon {
|
|
|
|
|
id: batIcon
|
|
|
|
|
text: root.getBatteryIcon()
|
|
|
|
|
}
|
2026-01-15 17:43:03 +01:00
|
|
|
}
|
2026-01-15 15:14:29 +01:00
|
|
|
}
|
2026-01-16 15:15:44 +01:00
|
|
|
}
|
2026-01-15 15:14:29 +01:00
|
|
|
}
|