mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2025-12-06 06:36:15 +00:00
Audio Service: more abstraction
This commit is contained in:
@@ -10,10 +10,6 @@ Item {
|
||||
width: pill.width
|
||||
height: pill.height
|
||||
|
||||
Component.onCompleted: {
|
||||
console.log("[Volume] settingsPanel received:", !!settingsPanel)
|
||||
}
|
||||
|
||||
// Used to avoid opening the pill on Quickshell startup
|
||||
property bool firstVolumeReceived: false
|
||||
|
||||
@@ -50,9 +46,9 @@ Item {
|
||||
|
||||
onWheel: function (angle) {
|
||||
if (angle > 0) {
|
||||
Audio.volumeIncrement()
|
||||
Audio.increaseVolume()
|
||||
} else if (angle < 0) {
|
||||
Audio.volumeDecrement()
|
||||
Audio.decreaseVolume()
|
||||
}
|
||||
}
|
||||
onClicked: {
|
||||
|
||||
@@ -91,7 +91,7 @@ ColumnLayout {
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
if (Math.abs(localVolume - Audio.volume) >= 0.01) {
|
||||
Audio.volumeSet(localVolume)
|
||||
Audio.setVolume(localVolume)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,34 +34,7 @@ Singleton {
|
||||
readonly property alias muted: root._muted
|
||||
property bool _muted: !!sink?.audio?.muted
|
||||
|
||||
readonly property real step: 0.05
|
||||
|
||||
function volumeIncrement() {
|
||||
volumeSet(volume + step)
|
||||
}
|
||||
|
||||
function volumeDecrement() {
|
||||
volumeSet(volume - step)
|
||||
}
|
||||
|
||||
function volumeSet(newVolume) {
|
||||
if (sink?.ready && sink?.audio) {
|
||||
// Clamp it accordingly
|
||||
sink.audio.muted = false
|
||||
sink.audio.volume = Math.max(0, Math.min(1, newVolume))
|
||||
//console.log("[Audio] volumeSet", sink.audio.volume);
|
||||
} else {
|
||||
console.warn("[Audio] No sink available")
|
||||
}
|
||||
}
|
||||
|
||||
function setAudioSink(newSink: PwNode): void {
|
||||
Pipewire.preferredDefaultAudioSink = newSink
|
||||
}
|
||||
|
||||
function setAudioSource(newSource: PwNode): void {
|
||||
Pipewire.preferredDefaultAudioSource = newSource
|
||||
}
|
||||
readonly property real stepVolume: 0.05
|
||||
|
||||
PwObjectTracker {
|
||||
objects: [...root.sinks, ...root.sources]
|
||||
@@ -83,4 +56,39 @@ Singleton {
|
||||
console.log("[Audio] onMuteChanged:", root._muted)
|
||||
}
|
||||
}
|
||||
|
||||
function increaseVolume() {
|
||||
setVolume(volume + stepVolume)
|
||||
}
|
||||
|
||||
function decreaseVolume() {
|
||||
setVolume(volume - stepVolume)
|
||||
}
|
||||
|
||||
function setVolume(newVolume: real) {
|
||||
if (sink?.ready && sink?.audio) {
|
||||
// Clamp it accordingly
|
||||
sink.audio.muted = false
|
||||
sink.audio.volume = Math.max(0, Math.min(1, newVolume))
|
||||
//console.log("[Audio] setVolume", sink.audio.volume);
|
||||
} else {
|
||||
console.warn("[Audio] No sink available")
|
||||
}
|
||||
}
|
||||
|
||||
function setMuted(muted: bool) {
|
||||
if (sink?.ready && sink?.audio) {
|
||||
sink.audio.muted = muted
|
||||
} else {
|
||||
console.warn("[Audio] No sink available")
|
||||
}
|
||||
}
|
||||
|
||||
function setAudioSink(newSink: PwNode): void {
|
||||
Pipewire.preferredDefaultAudioSink = newSink
|
||||
}
|
||||
|
||||
function setAudioSource(newSource: PwNode): void {
|
||||
Pipewire.preferredDefaultAudioSource = newSource
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user