104 lines
2.8 KiB
QML
104 lines
2.8 KiB
QML
pragma Singleton
|
|
|
|
import qs.Config
|
|
import Quickshell
|
|
import Quickshell.Services.Pipewire
|
|
import QtQuick
|
|
|
|
Singleton {
|
|
id: root
|
|
|
|
property string previousSinkName: ""
|
|
property string previousSourceName: ""
|
|
|
|
readonly property var nodes: Pipewire.nodes.values.reduce((acc, node) => {
|
|
if (!node.isStream) {
|
|
if (node.isSink)
|
|
acc.sinks.push(node);
|
|
else if (node.audio)
|
|
acc.sources.push(node);
|
|
}
|
|
return acc;
|
|
}, {
|
|
sources: [],
|
|
sinks: []
|
|
})
|
|
|
|
readonly property list<PwNode> sinks: nodes.sinks
|
|
readonly property list<PwNode> sources: nodes.sources
|
|
|
|
readonly property PwNode sink: Pipewire.defaultAudioSink
|
|
readonly property PwNode source: Pipewire.defaultAudioSource
|
|
|
|
readonly property bool muted: !!sink?.audio?.muted
|
|
readonly property real volume: sink?.audio?.volume ?? 0
|
|
|
|
readonly property bool sourceMuted: !!source?.audio?.muted
|
|
readonly property real sourceVolume: source?.audio?.volume ?? 0
|
|
|
|
function setVolume(newVolume: real): void {
|
|
if (sink?.ready && sink?.audio) {
|
|
sink.audio.muted = false;
|
|
sink.audio.volume = Math.max(0, Math.min(100, newVolume));
|
|
}
|
|
}
|
|
|
|
function incrementVolume(amount: real): void {
|
|
setVolume(volume + (amount || 5));
|
|
}
|
|
|
|
function decrementVolume(amount: real): void {
|
|
setVolume(volume - (amount || 5));
|
|
}
|
|
|
|
function setSourceVolume(newVolume: real): void {
|
|
if (source?.ready && source?.audio) {
|
|
source.audio.muted = false;
|
|
source.audio.volume = Math.max(0, Math.min(100, newVolume));
|
|
}
|
|
}
|
|
|
|
function incrementSourceVolume(amount: real): void {
|
|
setSourceVolume(sourceVolume + (amount || 5));
|
|
}
|
|
|
|
function decrementSourceVolume(amount: real): void {
|
|
setSourceVolume(sourceVolume - (amount || 5));
|
|
}
|
|
|
|
function setAudioSink(newSink: PwNode): void {
|
|
Pipewire.preferredDefaultAudioSink = newSink;
|
|
}
|
|
|
|
function setAudioSource(newSource: PwNode): void {
|
|
Pipewire.preferredDefaultAudioSource = newSource;
|
|
}
|
|
|
|
onSinkChanged: {
|
|
if (!sink?.ready)
|
|
return;
|
|
|
|
const newSinkName = sink.description || sink.name || qsTr("Unknown Device");
|
|
|
|
previousSinkName = newSinkName;
|
|
}
|
|
|
|
onSourceChanged: {
|
|
if (!source?.ready)
|
|
return;
|
|
|
|
const newSourceName = source.description || source.name || qsTr("Unknown Device");
|
|
|
|
previousSourceName = newSourceName;
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
previousSinkName = sink?.description || sink?.name || qsTr("Unknown Device");
|
|
previousSourceName = source?.description || source?.name || qsTr("Unknown Device");
|
|
}
|
|
|
|
PwObjectTracker {
|
|
objects: [...root.sinks, ...root.sources]
|
|
}
|
|
}
|