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
|
2026-01-06 15:10:35 +01:00
|
|
|
import Quickshell
|
2025-12-21 21:24:03 +01:00
|
|
|
import Quickshell.Io
|
2025-12-28 01:45:57 +01:00
|
|
|
import "../../"
|
2025-12-28 13:25:31 +01:00
|
|
|
import "../settings/"
|
2025-12-21 20:59:33 +01:00
|
|
|
|
2025-12-31 17:08:56 +01:00
|
|
|
Item {
|
2025-12-21 20:59:33 +01:00
|
|
|
id: root
|
2025-12-31 17:08:56 +01:00
|
|
|
implicitWidth: styleLayout.implicitWidth
|
|
|
|
|
height: 34
|
|
|
|
|
property var sink: Pipewire.defaultAudioSink
|
2025-12-21 21:24:03 +01:00
|
|
|
MouseArea {
|
2025-12-28 17:36:11 +01:00
|
|
|
anchors.fill: parent
|
2025-12-28 01:45:57 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
Process {
|
|
|
|
|
id: pavu
|
|
|
|
|
command: ["pavucontrol"] // The command and args list
|
|
|
|
|
|
2025-12-21 21:24:03 +01:00
|
|
|
}
|
2026-01-06 15:10:35 +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)
|
2026-01-06 15:10:35 +01:00
|
|
|
return "audio-volume-muted-symbolic";
|
2025-12-21 20:59:33 +01:00
|
|
|
|
|
|
|
|
// If muted, show the hush icon
|
|
|
|
|
if (sink.audio.muted)
|
2026-01-06 15:10:35 +01:00
|
|
|
return "audio-volume-muted-symbolic";
|
2025-12-21 20:59:33 +01:00
|
|
|
|
|
|
|
|
// 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)
|
2026-01-06 15:10:35 +01:00
|
|
|
return "audio-volume-low-symbolic";
|
2025-12-31 15:59:41 +01:00
|
|
|
if (vol < 0.75)
|
2026-01-06 15:10:35 +01:00
|
|
|
return "audio-volume-medium-symbolic";
|
|
|
|
|
if (vol <= 1.00)
|
|
|
|
|
return "audio-volume-high-symbolic";
|
2025-12-21 20:59:33 +01:00
|
|
|
|
|
|
|
|
// If it's loud, prepare the ears!
|
2026-01-06 15:10:35 +01:00
|
|
|
return "audio-volume-high-danger-symbolic";
|
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
|
2025-12-31 17:04:35 +01:00
|
|
|
implicitWidth: botText.width
|
2025-12-28 17:36:11 +01:00
|
|
|
Row {
|
2026-01-06 15:10:35 +01:00
|
|
|
|
|
|
|
|
spacing: 5
|
2025-12-28 17:36:11 +01:00
|
|
|
Text {
|
2025-12-31 16:59:55 +01:00
|
|
|
id: topText
|
2026-01-06 15:10:35 +01:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2025-12-28 17:36:11 +01:00
|
|
|
PwObjectTracker {
|
2026-01-06 15:10:35 +01:00
|
|
|
|
2025-12-28 17:36:11 +01:00
|
|
|
objects: Pipewire.ready ? root.sink : []
|
|
|
|
|
}
|
|
|
|
|
font.weight: 900
|
|
|
|
|
color: Colors.foreground
|
|
|
|
|
font.family: Settings.font
|
|
|
|
|
font.pixelSize: Settings.fontSize
|
2026-01-03 20:16:51 +01:00
|
|
|
text: Pipewire.ready ? root.sink.audio.volume.toFixed(2) + "%" : "0%"
|
2026-01-06 15:10:35 +01:00
|
|
|
onTextChanged: console.log(Quickshell.iconPath)
|
2025-12-28 17:36:11 +01:00
|
|
|
}
|
2026-01-06 15:10:35 +01:00
|
|
|
IconImage {
|
2025-12-31 16:59:55 +01:00
|
|
|
id: icon
|
2026-01-06 15:10:35 +01:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
implicitSize: 12
|
|
|
|
|
source: Quickshell.iconPath(root.getVolumeIcon())
|
2025-12-28 17:36:11 +01:00
|
|
|
}
|
2025-12-21 20:59:33 +01:00
|
|
|
}
|
|
|
|
|
Text {
|
2025-12-31 17:04:35 +01:00
|
|
|
id: botText
|
2025-12-22 13:55:00 +01:00
|
|
|
font.weight: 900
|
2025-12-21 20:59:33 +01:00
|
|
|
color: Colors.foreground
|
2025-12-28 13:25:31 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|