94 lines
2.6 KiB
QML
94 lines
2.6 KiB
QML
import QtQuick
|
|
import Quickshell.Services.Pipewire
|
|
import Quickshell.Widgets
|
|
import QtQuick.Layouts
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
import "../../"
|
|
import "../settings/"
|
|
|
|
Item {
|
|
id: root
|
|
implicitWidth: styleLayout.implicitWidth
|
|
height: 34
|
|
property var sink: Pipewire.defaultAudioSink
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
cursorShape: Qt.PointingHandCursor
|
|
onClicked: mouse => {
|
|
if (mouse.button === Qt.LeftButton) {
|
|
pavu.startDetached();
|
|
}
|
|
}
|
|
}
|
|
Process {
|
|
id: pavu
|
|
command: ["pavucontrol"] // The command and args list
|
|
|
|
}
|
|
|
|
// 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-symbolic";
|
|
|
|
// If muted, show the hush icon
|
|
if (sink.audio.muted)
|
|
return "audio-volume-muted-symbolic";
|
|
|
|
// Volume is usually 0.0 to 1.0 (0% to 100%)
|
|
const vol = sink.audio.volume;
|
|
|
|
if (vol <= 0.25)
|
|
return "audio-volume-low-symbolic";
|
|
if (vol < 0.75)
|
|
return "audio-volume-medium-symbolic";
|
|
if (vol <= 1.00)
|
|
return "audio-volume-high-symbolic";
|
|
|
|
// If it's loud, prepare the ears!
|
|
return "audio-volume-high-danger-symbolic";
|
|
}
|
|
|
|
ColumnLayout {
|
|
id: styleLayout
|
|
anchors.centerIn: parent
|
|
spacing: 0
|
|
implicitWidth: topText.width
|
|
Row {
|
|
|
|
spacing: 5
|
|
Text {
|
|
id: topText
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
PwObjectTracker {
|
|
|
|
objects: Pipewire.ready ? root.sink : []
|
|
}
|
|
font.weight: 900
|
|
color: Colors.foreground
|
|
font.family: Settings.font
|
|
font.pixelSize: Settings.fontSize
|
|
text: Pipewire.ready ? root.sink.audio.volume.toFixed(2) + "%" : "0%"
|
|
onTextChanged: console.log(Quickshell.iconPath)
|
|
}
|
|
IconImage {
|
|
id: icon
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
implicitSize: 12
|
|
source: Quickshell.iconPath(root.getVolumeIcon())
|
|
}
|
|
}
|
|
Text {
|
|
id: botText
|
|
font.weight: 900
|
|
color: Colors.foreground
|
|
font.family: Settings.font
|
|
font.pixelSize: Settings.fontSize - 2
|
|
opacity: 0.7
|
|
text: Pipewire.ready ? Pipewire.defaultAudioSink.nickname : "failure"
|
|
}
|
|
}
|
|
}
|