AudioCard/Panel: add one-shot timer to prevent 100% volume on startup

This commit is contained in:
Ly-sec
2025-11-11 15:16:32 +01:00
parent 3c8a49d7c0
commit bd0ddda7c6
2 changed files with 62 additions and 14 deletions
+31 -7
View File
@@ -39,15 +39,23 @@ SmartPanel {
} }
} }
// Timer to debounce volume changes // Debounce timers to avoid forcing PipeWire volume on startup
Timer { Timer {
id: outputDebounceTimer
interval: 100 interval: 100
running: true repeat: false
repeat: true
onTriggered: { onTriggered: {
if (Math.abs(localOutputVolume - AudioService.volume) >= 0.01) { if (Math.abs(localOutputVolume - AudioService.volume) >= 0.01) {
AudioService.setVolume(localOutputVolume) AudioService.setVolume(localOutputVolume)
} }
}
}
Timer {
id: inputDebounceTimer
interval: 100
repeat: false
onTriggered: {
if (Math.abs(localInputVolume - AudioService.inputVolume) >= 0.01) { if (Math.abs(localInputVolume - AudioService.inputVolume) >= 0.01) {
AudioService.setInputVolume(localInputVolume) AudioService.setInputVolume(localInputVolume)
} }
@@ -164,8 +172,16 @@ SmartPanel {
value: localOutputVolume value: localOutputVolume
stepSize: 0.01 stepSize: 0.01
heightRatio: 0.5 heightRatio: 0.5
onMoved: value => localOutputVolume = value onMoved: value => {
onPressedChanged: (pressed, value) => localOutputVolumeChanging = pressed localOutputVolume = value
outputDebounceTimer.restart()
}
onPressedChanged: (pressed, value) => {
localOutputVolumeChanging = pressed
if (!pressed) {
outputDebounceTimer.restart()
}
}
text: Math.round(localOutputVolume * 100) + "%" text: Math.round(localOutputVolume * 100) + "%"
Layout.bottomMargin: Style.marginM Layout.bottomMargin: Style.marginM
} }
@@ -221,8 +237,16 @@ SmartPanel {
value: localInputVolume value: localInputVolume
stepSize: 0.01 stepSize: 0.01
heightRatio: 0.5 heightRatio: 0.5
onMoved: value => localInputVolume = value onMoved: value => {
onPressedChanged: (pressed, value) => localInputVolumeChanging = pressed localInputVolume = value
inputDebounceTimer.restart()
}
onPressedChanged: (pressed, value) => {
localInputVolumeChanging = pressed
if (!pressed) {
inputDebounceTimer.restart()
}
}
text: Math.round(localInputVolume * 100) + "%" text: Math.round(localInputVolume * 100) + "%"
Layout.bottomMargin: Style.marginM Layout.bottomMargin: Style.marginM
} }
@@ -15,15 +15,23 @@ NBox {
property real localInputVolume: AudioService.inputVolume || 0 property real localInputVolume: AudioService.inputVolume || 0
property bool localInputVolumeChanging: false property bool localInputVolumeChanging: false
// Timer to debounce volume changes // Debounce timers to avoid spamming PipeWire on startup/idle
Timer { Timer {
id: outputDebounceTimer
interval: 100 interval: 100
running: true repeat: false
repeat: true
onTriggered: { onTriggered: {
if (Math.abs(localOutputVolume - AudioService.volume) >= 0.01) { if (Math.abs(localOutputVolume - AudioService.volume) >= 0.01) {
AudioService.setVolume(localOutputVolume) AudioService.setVolume(localOutputVolume)
} }
}
}
Timer {
id: inputDebounceTimer
interval: 100
repeat: false
onTriggered: {
if (Math.abs(localInputVolume - AudioService.inputVolume) >= 0.01) { if (Math.abs(localInputVolume - AudioService.inputVolume) >= 0.01) {
AudioService.setInputVolume(localInputVolume) AudioService.setInputVolume(localInputVolume)
} }
@@ -99,8 +107,16 @@ NBox {
value: localOutputVolume value: localOutputVolume
stepSize: 0.01 stepSize: 0.01
heightRatio: 0.5 heightRatio: 0.5
onMoved: localOutputVolume = value onMoved: {
onPressedChanged: localOutputVolumeChanging = pressed localOutputVolume = value
outputDebounceTimer.restart()
}
onPressedChanged: {
localOutputVolumeChanging = pressed
if (!pressed) {
outputDebounceTimer.restart()
}
}
tooltipText: `${Math.round(localOutputVolume * 100)}%` tooltipText: `${Math.round(localOutputVolume * 100)}%`
tooltipDirection: "bottom" tooltipDirection: "bottom"
} }
@@ -147,8 +163,16 @@ NBox {
value: localInputVolume value: localInputVolume
stepSize: 0.01 stepSize: 0.01
heightRatio: 0.5 heightRatio: 0.5
onMoved: localInputVolume = value onMoved: {
onPressedChanged: localInputVolumeChanging = pressed localInputVolume = value
inputDebounceTimer.restart()
}
onPressedChanged: {
localInputVolumeChanging = pressed
if (!pressed) {
inputDebounceTimer.restart()
}
}
tooltipText: `${Math.round(localInputVolume * 100)}%` tooltipText: `${Math.round(localInputVolume * 100)}%`
tooltipDirection: "bottom" tooltipDirection: "bottom"
} }