quickshell/modules/bar/Volume.qml

82 lines
2.2 KiB
QML
Raw Normal View History

2025-12-21 20:59:33 +01:00
import QtQuick
import Quickshell.Services.Pipewire
import Quickshell.Widgets
2025-12-28 17:36:11 +01:00
import QtQuick.Layouts
2025-12-21 21:24:03 +01:00
import Quickshell.Io
import "../../"
import "../settings/"
2025-12-21 20:59:33 +01:00
Item {
id: root
2025-12-21 21:24:03 +01:00
MouseArea {
2025-12-28 17:36:11 +01:00
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
2025-12-21 21:24:03 +01:00
onClicked: mouse => {
if (mouse.button === Qt.LeftButton) {
pavu.startDetached();
}
}
2025-12-28 17:36:11 +01:00
}
implicitWidth: styleLayout.implicitWidth + 10
implicitHeight: 34
property var sink: Pipewire.defaultAudioSink
Process {
id: pavu
command: ["pavucontrol"] // The command and args list
2025-12-21 21:24:03 +01:00
}
2025-12-21 20:59:33 +01:00
// Logic to pick the correct icon name
function getVolumeIcon() {
// Safety check: if Pipewire is dead or sink is missing
if (!sink)
return "audio-volume-muted-blocking";
// If muted, show the hush icon
if (sink.audio.muted)
return "audio-volume-muted";
// Volume is usually 0.0 to 1.0 (0% to 100%)
const vol = sink.audio.volume;
2025-12-31 15:59:41 +01:00
if (vol <= 0.25)
return "volume_mute";
if (vol < 0.75)
return "volume_down";
if (vol < 1.00)
return "volume_up";
2025-12-21 20:59:33 +01:00
// If it's loud, prepare the ears!
2025-12-31 15:59:41 +01:00
return "volume_up";
2025-12-21 20:59:33 +01:00
}
2025-12-28 17:36:11 +01:00
ColumnLayout {
id: styleLayout
2025-12-21 20:59:33 +01:00
anchors.centerIn: parent
2025-12-28 17:36:11 +01:00
spacing: 0
Row {
spacing: 10
Text {
PwObjectTracker {
objects: Pipewire.ready ? root.sink : []
}
font.weight: 900
color: Colors.foreground
font.family: Settings.font
font.pixelSize: Settings.fontSize
text: Pipewire.ready ? Math.round(root.sink.audio.volume * 100) + "%" : "0%"
}
2025-12-31 15:59:41 +01:00
Icons {
text: root.getVolumeIcon()
2025-12-28 17:36:11 +01:00
}
2025-12-21 20:59:33 +01:00
}
Text {
font.weight: 900
2025-12-21 20:59:33 +01:00
color: Colors.foreground
font.family: Settings.font
2025-12-28 17:36:11 +01:00
font.pixelSize: Settings.fontSize - 2
opacity: 0.7
text: Pipewire.ready ? Pipewire.defaultAudioSink.nickname : "failure"
2025-12-21 20:59:33 +01:00
}
}
}