103 lines
2.8 KiB
QML
103 lines
2.8 KiB
QML
import Quickshell.Services.UPower
|
|
import Quickshell.Services.Pipewire
|
|
import Quickshell.Widgets
|
|
import QtQuick
|
|
import Qt5Compat.GraphicalEffects
|
|
import QtQuick.Layouts
|
|
import qs
|
|
import qs.settings
|
|
import qs.widgets
|
|
|
|
WrapperRectangle {
|
|
id: root
|
|
margin: Settings.config.barmargins
|
|
layer {
|
|
enabled: true
|
|
effect: DropShadow {
|
|
color: "#111111"
|
|
radius: 4
|
|
verticalOffset: 2
|
|
horizontalOffset: 2
|
|
samples: 18
|
|
}
|
|
}
|
|
color: Colors.base02
|
|
implicitWidth: iconLayout.implicitWidth + 14
|
|
implicitHeight: Settings.config.barHeight - margin * 2
|
|
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";
|
|
}
|
|
if (percentage <= 0.12) {
|
|
return "\uf251";
|
|
}
|
|
if (percentage <= 0.24) {
|
|
return "\uf257";
|
|
}
|
|
if (percentage <= 0.36) {
|
|
return "\uf256";
|
|
}
|
|
if (percentage <= 0.48) {
|
|
return "\uf255";
|
|
}
|
|
if (percentage <= 0.60) {
|
|
return "\uf254";
|
|
}
|
|
if (percentage <= 0.72) {
|
|
return "\uf253";
|
|
}
|
|
if (percentage <= 0.84) {
|
|
return "\uf252";
|
|
}
|
|
if (percentage >= 0.84) {
|
|
return "\uf24f";
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
function getVolumeIcon() {
|
|
if (audioMute) {
|
|
return "\ue04f";
|
|
}
|
|
if (audioPercentage <= 0.33) {
|
|
return "\ue04e";
|
|
}
|
|
if (audioPercentage <= 0.66) {
|
|
return "\ue04d";
|
|
}
|
|
if (audioPercentage >= 0.66) {
|
|
return "\ue050";
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
child: Item {
|
|
RowLayout {
|
|
id: iconLayout
|
|
anchors.centerIn: parent
|
|
CIcon {
|
|
id: batteryIcon
|
|
Layout.leftMargin: 2
|
|
text: root.getBatteryIcon()
|
|
}
|
|
CIcon {
|
|
id: volIcon
|
|
text: root.getVolumeIcon()
|
|
PwObjectTracker {
|
|
id: audioTracker
|
|
objects: Pipewire.ready ? Pipewire.defaultAudioSink : []
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|