quickshell/modules/bar/Volume.qml

79 lines
2.1 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-21 21:24:03 +01:00
import Quickshell.Io
import "../../"
import "../settings/"
2025-12-21 20:59:33 +01:00
Item {
id: root
implicitWidth: volRow.implicitWidth + 10
implicitHeight: volRow.implicitHeight
// grab the default speaker (Sink)
property var sink: Pipewire.defaultAudioSink
2025-12-21 21:24:03 +01:00
Process {
id: pavu
command: ["pavucontrol"] // The command and args list
2025-12-21 20:59:33 +01:00
2025-12-21 21:24:03 +01:00
}
MouseArea {
cursorShape: Qt.PointingHandCursor
2025-12-21 21:24:03 +01:00
onClicked: mouse => {
if (mouse.button === Qt.LeftButton) {
pavu.startDetached();
}
}
anchors.fill: parent
// Scroll to change volume (The fancy stuff!)
}
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;
if (vol <= 0.0)
return "audio-volume-low";
if (vol < 0.33)
return "audio-volume-low";
if (vol < 0.66)
return "audio-volume-medium";
// If it's loud, prepare the ears!
return "audio-volume-high";
}
Row {
id: volRow
anchors.centerIn: parent
spacing: 5
IconImage {
anchors.verticalCenter: parent.verticalCenter
width: 12
height: 12
2025-12-21 20:59:33 +01:00
source: "root:/icons/" + root.getVolumeIcon() + "-symbolic.svg"
}
Text {
PwObjectTracker {
objects: Pipewire.ready ? Pipewire.defaultAudioSink : []
2025-12-21 20:59:33 +01:00
}
2025-12-26 00:37:39 +01:00
width: 20
font.weight: 900
2025-12-21 20:59:33 +01:00
color: Colors.foreground
font.family: Settings.font
font.pixelSize: Settings.fontSize
text: Pipewire.ready ? Math.round(Pipewire.defaultAudioSink.audio.volume * 100) + "%" : "0%"
2025-12-21 20:59:33 +01:00
}
}
}