53 lines
1.3 KiB
QML
53 lines
1.3 KiB
QML
import QtQuick
|
|
import Quickshell.Io
|
|
|
|
// service to get the current volume and handle volume changes
|
|
Item {
|
|
id: root
|
|
signal volumeChanged(int volume)
|
|
|
|
// process to get the volume level
|
|
Process {
|
|
id: audioVolumeProcess
|
|
command: ["sh", "-c", "wpctl get-volume @DEFAULT_AUDIO_SINK@ | cut -d. -f 2"]
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
if (this.text) {
|
|
const volume = parseInt(this.text.trim());
|
|
root.volumeChanged(volume);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Process {
|
|
id: volumeUpProcess
|
|
command: ["sh", "-c", "wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%+"]
|
|
}
|
|
|
|
Process {
|
|
id: volumeDownProcess
|
|
command: ["sh", "-c", "wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%-"]
|
|
}
|
|
|
|
function volumeUp() {
|
|
volumeUpProcess.running = true;
|
|
audioVolumeProcess.running = true;
|
|
}
|
|
|
|
function volumeDown() {
|
|
volumeDownProcess.running = true;
|
|
audioVolumeProcess.running = true;
|
|
}
|
|
|
|
// timer to periodically check the volume level
|
|
Timer {
|
|
interval: 5000
|
|
running: true
|
|
repeat: true
|
|
onTriggered: audioVolumeProcess.running = true
|
|
}
|
|
|
|
Component.onCompleted: audioVolumeProcess.running = true
|
|
}
|