Simplify volume service

This commit is contained in:
Sem
2026-07-12 16:15:07 +02:00
parent 80dbe763f8
commit ba1d3ba357
2 changed files with 50 additions and 50 deletions

View File

@@ -6,10 +6,10 @@ Item {
id: root
signal volumeChanged(int volume)
// process to get the volume level: first active playback stream, falling back to the sink
// process to get the volume level
Process {
id: audioVolumeProcess
command: ["sh", "-c", "vol=$(pactl list sink-inputs | grep -m1 'Volume:' | grep -oP '\\d+(?=%)' | head -1); [ -n \"$vol\" ] && echo \"$vol\" || wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{printf \"%d\", $2 * 100}'"]
command: ["sh", "-c", "wpctl get-volume @DEFAULT_AUDIO_SINK@ | cut -d. -f 2"]
stdout: StdioCollector {
onStreamFinished: {
if (this.text) {
@@ -22,12 +22,12 @@ Item {
Process {
id: volumeUpProcess
command: ["sh", "-c", "pactl list sink-inputs | awk '/^Sink Input #/{sub(/^Sink Input #/,x);id=$1;got=0} /^[[:space:]]+Volume:/ && id && !got{match($0,/[0-9]+%/);if(substr($0,RSTART,RLENGTH-1)+0<100)print id;got=1}' | xargs -r -I{} pactl set-sink-input-volume {} +1%"]
command: ["sh", "-c", "wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%+"]
}
Process {
id: volumeDownProcess
command: ["sh", "-c", "pactl list short sink-inputs | awk '{print $1}' | xargs -r -I{} pactl set-sink-input-volume {} -1%"]
command: ["sh", "-c", "wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%-"]
}
function volumeUp() {
@@ -49,4 +49,4 @@ Item {
}
Component.onCompleted: audioVolumeProcess.running = true
}
}