pipewire service
This commit is contained in:
parent
38fce255d8
commit
89cf6f315b
2 changed files with 62 additions and 33 deletions
|
|
@ -1,53 +1,34 @@
|
|||
import qs.config
|
||||
import qs.services
|
||||
import qs.widgets
|
||||
import QtQuick
|
||||
import Quickshell.Services.Pipewire
|
||||
|
||||
StyledButton {
|
||||
id: button
|
||||
|
||||
property var sink: Pipewire.defaultAudioSink
|
||||
|
||||
PwObjectTracker {
|
||||
id: bound
|
||||
objects: [button.sink]
|
||||
}
|
||||
id: root
|
||||
|
||||
onClicked: mouse => {
|
||||
if (!sink) {
|
||||
return;
|
||||
}
|
||||
if (mouse.button == Qt.LeftButton) {
|
||||
sink.audio.muted = !sink?.audio.muted;
|
||||
} else if (mouse.button == Qt.RightButton)
|
||||
// show menu
|
||||
{}
|
||||
Pipewire.toggleMute();
|
||||
} else if (mouse.button == Qt.RightButton) {
|
||||
popup.opened = !popup.opened;
|
||||
}
|
||||
}
|
||||
|
||||
onWheel: event => {
|
||||
if (event.angleDelta.y > 0) {
|
||||
sink.audio.volume = Math.min(sink.audio.volume + 0.02, 1.0);
|
||||
Pipewire.incrementVolume();
|
||||
} else if (event.angleDelta.y < 0) {
|
||||
sink.audio.volume -= 0.02;
|
||||
Pipewire.decrementVolume();
|
||||
}
|
||||
}
|
||||
|
||||
states: [
|
||||
State {
|
||||
name: "muted"
|
||||
when: button.sink?.audio.muted ?? false
|
||||
when: Pipewire.muted
|
||||
PropertyChanges {
|
||||
text {
|
||||
icon: " "
|
||||
}
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "off"
|
||||
when: button.sink?.audio.volume <= 0
|
||||
PropertyChanges {
|
||||
text {
|
||||
icon: " "
|
||||
root {
|
||||
color: Theme.palette.error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -55,9 +36,9 @@ StyledButton {
|
|||
|
||||
content: StyledText {
|
||||
id: text
|
||||
property string icon: " "
|
||||
text: `${icon} ${(button.sink?.audio.volume * 100).toFixed()}%`
|
||||
property string icon: Pipewire.muted ? " " : Pipewire.volume <= 0 ? " " : " "
|
||||
text: `${icon} ${(Pipewire.volume * 100).toFixed()}%`
|
||||
font.pixelSize: Dimensions.pipewire.fontSize
|
||||
color: button.containsMouse ? Theme.palette.base300 : Theme.palette.basecontent
|
||||
color: root.containsMouse || Pipewire.muted ? Theme.palette.base300 : Theme.palette.basecontent
|
||||
}
|
||||
}
|
||||
|
|
|
|||
48
services/Pipewire.qml
Normal file
48
services/Pipewire.qml
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Services.Pipewire
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
readonly property PwNode sink: Pipewire.defaultAudioSink
|
||||
readonly property PwNode source: Pipewire.defaultAudioSource
|
||||
|
||||
readonly property bool muted: sink?.audio?.muted ?? false
|
||||
readonly property real volume: sink?.audio?.volume ?? 0
|
||||
|
||||
function setVolume(volume: real): void {
|
||||
if (sink?.ready && sink?.audio) {
|
||||
sink.audio.muted = false;
|
||||
sink.audio.volume = volume;
|
||||
}
|
||||
}
|
||||
|
||||
function incrementVolume() {
|
||||
if (!sink?.ready || !sink?.audio) {
|
||||
return;
|
||||
}
|
||||
sink.audio.muted = false;
|
||||
sink.audio.volume = Math.min(sink.audio.volume + 0.02, 1.0);
|
||||
}
|
||||
|
||||
function decrementVolume() {
|
||||
if (!sink?.ready || !sink?.audio) {
|
||||
return;
|
||||
}
|
||||
sink.audio.volume -= 0.02;
|
||||
}
|
||||
|
||||
function toggleMute() {
|
||||
if (!sink?.ready || !sink?.audio) {
|
||||
return;
|
||||
}
|
||||
sink.audio.muted = !sink.audio.muted;
|
||||
}
|
||||
|
||||
PwObjectTracker {
|
||||
objects: [Pipewire.defaultAudioSink, Pipewire.defaultAudioSource]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue