Fix volume scrolling

This commit is contained in:
ly-sec 2025-07-14 14:35:54 +02:00
parent 763cb4e148
commit bed4c3ca7a

View file

@ -24,14 +24,12 @@ Item {
} }
Connections { Connections {
target: shell ?? null target: shell && shell.defaultAudioSink && shell.defaultAudioSink.audio ? shell.defaultAudioSink.audio : null
function onVolumeChanged() { onVolumeChanged: {
if (shell && shell.volume !== volume) { volume = Math.round(shell.defaultAudioSink.audio.volume * 100);
volume = shell.volume pillIndicator.text = volume + "%";
pillIndicator.text = volume + "%" pillIndicator.icon = volume === 0 ? "volume_off" : (volume < 30 ? "volume_down" : "volume_up");
pillIndicator.icon = volume === 0 ? "volume_off" : (volume < 30 ? "volume_down" : "volume_up") pillIndicator.show();
pillIndicator.show()
}
} }
} }
@ -48,13 +46,15 @@ Item {
acceptedButtons: Qt.NoButton // Accept wheel events only acceptedButtons: Qt.NoButton // Accept wheel events only
propagateComposedEvents: true propagateComposedEvents: true
onWheel: { onWheel: {
if (!shell) return; if (!shell || !shell.defaultAudioSink || !shell.defaultAudioSink.audio) return;
let step = 5; let step = 0.05; // 5% as float
let newVolume = shell.defaultAudioSink.audio.volume;
if (wheel.angleDelta.y > 0) { if (wheel.angleDelta.y > 0) {
shell.volume = Math.min(100, shell.volume + step); newVolume = Math.min(1, newVolume + step);
} else if (wheel.angleDelta.y < 0) { } else if (wheel.angleDelta.y < 0) {
shell.volume = Math.max(0, shell.volume - step); newVolume = Math.max(0, newVolume - step);
} }
shell.defaultAudioSink.audio.volume = newVolume;
} }
} }
} }