2026-03-09 10:02:44 +01:00
|
|
|
import Quickshell.Services.UPower
|
|
|
|
|
import Quickshell.Services.Pipewire
|
|
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Layouts
|
|
|
|
|
import qs
|
|
|
|
|
import qs.settings
|
|
|
|
|
import qs.widgets
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: root
|
2026-03-12 17:07:46 +01:00
|
|
|
color: Colors.surface_container_low
|
2026-03-09 10:02:44 +01:00
|
|
|
implicitWidth: iconLayout.implicitWidth + 14
|
2026-03-12 17:07:46 +01:00
|
|
|
implicitHeight: Settings.config.barHeight / 1.5
|
2026-03-09 10:02:44 +01:00
|
|
|
radius: Settings.config.rounding
|
|
|
|
|
property var battery: UPower.displayDevice
|
|
|
|
|
property var percentage: UPower.displayDevice.percentage
|
|
|
|
|
property bool charging: UPower.displayDevice.state == UPowerDeviceState.Charging
|
|
|
|
|
property bool hasBattery: UPower.displayDevice.isLaptopBattery
|
|
|
|
|
property var audio: Pipewire.ready ? Pipewire.defaultAudioSink : ""
|
|
|
|
|
property var audioPercentage: Pipewire.ready ? Pipewire.defaultAudioSink.audio.volume : 0
|
|
|
|
|
property bool audioMute: Pipewire.ready ? Pipewire.defaultAudioSink.audio.muted : false
|
|
|
|
|
|
|
|
|
|
function getBatteryIcon() {
|
|
|
|
|
if (charging) {
|
|
|
|
|
return "\uf250";
|
|
|
|
|
}
|
2026-03-09 10:45:56 +01:00
|
|
|
if (percentage <= 0.12) {
|
2026-03-09 10:57:04 +01:00
|
|
|
return "\uf251";
|
2026-03-09 10:02:44 +01:00
|
|
|
}
|
2026-03-09 10:45:56 +01:00
|
|
|
if (percentage <= 0.24) {
|
2026-03-09 10:02:44 +01:00
|
|
|
return "\uf257";
|
|
|
|
|
}
|
2026-03-09 10:45:56 +01:00
|
|
|
if (percentage <= 0.36) {
|
2026-03-09 10:02:44 +01:00
|
|
|
return "\uf256";
|
|
|
|
|
}
|
2026-03-09 10:45:56 +01:00
|
|
|
if (percentage <= 0.48) {
|
2026-03-09 10:02:44 +01:00
|
|
|
return "\uf255";
|
|
|
|
|
}
|
2026-03-09 10:45:56 +01:00
|
|
|
if (percentage <= 0.60) {
|
2026-03-09 10:02:44 +01:00
|
|
|
return "\uf254";
|
|
|
|
|
}
|
2026-03-09 10:45:56 +01:00
|
|
|
if (percentage <= 0.72) {
|
2026-03-09 10:02:44 +01:00
|
|
|
return "\uf253";
|
|
|
|
|
}
|
2026-03-09 10:45:56 +01:00
|
|
|
if (percentage <= 0.84) {
|
2026-03-09 10:02:44 +01:00
|
|
|
return "\uf252";
|
|
|
|
|
}
|
2026-03-09 10:45:56 +01:00
|
|
|
if (percentage >= 0.84) {
|
2026-03-09 10:02:44 +01:00
|
|
|
return "\uf24f";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function getVolumeIcon() {
|
|
|
|
|
if (audioMute) {
|
|
|
|
|
return "\ue04f";
|
|
|
|
|
}
|
2026-03-09 10:45:56 +01:00
|
|
|
if (audioPercentage <= 0.33) {
|
2026-03-09 10:02:44 +01:00
|
|
|
return "\ue04e";
|
|
|
|
|
}
|
2026-03-09 10:45:56 +01:00
|
|
|
if (audioPercentage <= 0.66) {
|
2026-03-09 10:02:44 +01:00
|
|
|
return "\ue04d";
|
|
|
|
|
}
|
2026-03-09 10:45:56 +01:00
|
|
|
if (audioPercentage >= 0.66) {
|
2026-03-09 10:02:44 +01:00
|
|
|
return "\ue050";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RowLayout {
|
|
|
|
|
id: iconLayout
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
CIcon {
|
|
|
|
|
id: batteryIcon
|
|
|
|
|
text: root.getBatteryIcon()
|
|
|
|
|
}
|
|
|
|
|
CIcon {
|
|
|
|
|
id: volIcon
|
|
|
|
|
text: root.getVolumeIcon()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
property var audioSink: Pipewire.defaultAudioSink
|
|
|
|
|
PwObjectTracker {
|
|
|
|
|
objects: Pipewire.ready ? Pipewire.defaultAudioSink : []
|
|
|
|
|
}
|
|
|
|
|
}
|