112 lines
3.0 KiB
QML
112 lines
3.0 KiB
QML
import QtQuick
|
|
import Quickshell.Io
|
|
import Quickshell.Services.Pipewire
|
|
import qs.Common
|
|
import qs.Services
|
|
|
|
Rectangle {
|
|
id: audioWidget
|
|
|
|
property string monitor: ""
|
|
property string icon: " "
|
|
property bool audioPipewireActive: Pipewire.defaultAudioSink ? true : false
|
|
property var sink: audioPipewireActive ? Pipewire.defaultAudioSink : null
|
|
property int volume: audioPipewireActive ? Math.round(sink.audio.volume * 100) : 30
|
|
|
|
implicitWidth: audioText.implicitWidth * 1.6
|
|
implicitHeight: Theme.heightGaps
|
|
color: Theme.backgroudColor
|
|
radius: 25
|
|
states: [
|
|
State {
|
|
name: "Mute"
|
|
when: audioWidget.volume == 0 || audioWidget.sink.audio.muted
|
|
|
|
PropertyChanges {
|
|
audioWidget.icon: " "
|
|
}
|
|
},
|
|
State {
|
|
name: "low volume"
|
|
when: audioWidget.volume <= 25
|
|
|
|
PropertyChanges {
|
|
audioWidget.icon: " "
|
|
}
|
|
},
|
|
State {
|
|
name: "high volume"
|
|
when: audioWidget.volume > 25
|
|
|
|
PropertyChanges {
|
|
audioWidget.icon: " "
|
|
}
|
|
}
|
|
]
|
|
|
|
PwObjectTracker {
|
|
objects: [Pipewire.defaultAudioSink]
|
|
}
|
|
|
|
Connections {
|
|
function onVolumeChanged() {
|
|
audioWidget.volume = Math.round(Pipewire.defaultAudioSink.audio.volume * 100);
|
|
}
|
|
|
|
target: audioWidget.audioPipewireActive ? Pipewire.defaultAudioSink.audio : null
|
|
}
|
|
|
|
Text {
|
|
id: audioText
|
|
|
|
property string audioTextText: audioWidget.audioPipewireActive ? audioWidget.icon + " " + Math.round(Pipewire.defaultAudioSink.audio.volume * 100).toString() + "%" : ""
|
|
|
|
anchors.centerIn: parent
|
|
text: audioTextText
|
|
font.bold: true
|
|
font.pixelSize: Theme.pixelSize
|
|
font.family: Theme.fontFamily
|
|
color: Theme.textColor
|
|
}
|
|
|
|
Process {
|
|
id: audioWidgetProcess
|
|
|
|
running: false
|
|
command: ["pavucontrol"]
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
hoverEnabled: true
|
|
onEntered: {
|
|
PopUpHover.start(audioWidget, "audio");
|
|
}
|
|
onExited: {
|
|
// PopUpHover.exit()
|
|
PopUpHover.exit();
|
|
}
|
|
onClicked: mouse => {
|
|
if (mouse.button === Qt.RightButton) {
|
|
parent.sink.audio.muted = !parent.sink.audio.muted;
|
|
} else if (mouse.button === Qt.LeftButton) {
|
|
audioWidgetProcess.startDetached();
|
|
}
|
|
}
|
|
onWheel: wheel => {
|
|
if (wheel.angleDelta.y > 0) {
|
|
if (0)
|
|
return;
|
|
|
|
Pipewire.defaultAudioSink.audio.volume = (audioWidget.volume + 5) / 100;
|
|
} else if (wheel.angleDelta.y < 0) {
|
|
if (0)
|
|
return;
|
|
|
|
Pipewire.defaultAudioSink.audio.volume = (audioWidget.volume - 5) / 100;
|
|
}
|
|
}
|
|
}
|
|
}
|