quickshell/modules/Bar/StatusIcons.qml

103 lines
2.8 KiB
QML
Raw Normal View History

import Quickshell.Services.UPower
import Quickshell.Services.Pipewire
2026-03-20 10:34:10 +01:00
import Quickshell.Widgets
import QtQuick
2026-03-19 11:32:23 +01:00
import Qt5Compat.GraphicalEffects
import QtQuick.Layouts
import qs
import qs.settings
import qs.widgets
2026-03-20 10:34:10 +01:00
WrapperRectangle {
id: root
2026-03-20 10:34:10 +01:00
margin: Settings.config.barmargins
layer {
enabled: true
effect: DropShadow {
color: Colors.base01
radius: 4
verticalOffset: 2
horizontalOffset: 2
samples: 18
}
}
2026-03-19 11:32:23 +01:00
color: Colors.base02
implicitWidth: iconLayout.implicitWidth + 14
2026-03-20 10:34:10 +01:00
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";
}
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:45:56 +01:00
if (percentage <= 0.24) {
return "\uf257";
}
2026-03-09 10:45:56 +01:00
if (percentage <= 0.36) {
return "\uf256";
}
2026-03-09 10:45:56 +01:00
if (percentage <= 0.48) {
return "\uf255";
}
2026-03-09 10:45:56 +01:00
if (percentage <= 0.60) {
return "\uf254";
}
2026-03-09 10:45:56 +01:00
if (percentage <= 0.72) {
return "\uf253";
}
2026-03-09 10:45:56 +01:00
if (percentage <= 0.84) {
return "\uf252";
}
2026-03-09 10:45:56 +01:00
if (percentage >= 0.84) {
return "\uf24f";
2026-03-19 11:32:23 +01:00
} else {
return "";
}
}
function getVolumeIcon() {
if (audioMute) {
return "\ue04f";
}
2026-03-09 10:45:56 +01:00
if (audioPercentage <= 0.33) {
return "\ue04e";
}
2026-03-09 10:45:56 +01:00
if (audioPercentage <= 0.66) {
return "\ue04d";
}
2026-03-09 10:45:56 +01:00
if (audioPercentage >= 0.66) {
return "\ue050";
2026-03-19 11:32:23 +01:00
} else {
return "";
}
}
2026-03-20 10:34:10 +01:00
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 : []
}
}
}
}
}