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.config
|
||||||
|
import qs.services
|
||||||
import qs.widgets
|
import qs.widgets
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell.Services.Pipewire
|
|
||||||
|
|
||||||
StyledButton {
|
StyledButton {
|
||||||
id: button
|
id: root
|
||||||
|
|
||||||
property var sink: Pipewire.defaultAudioSink
|
|
||||||
|
|
||||||
PwObjectTracker {
|
|
||||||
id: bound
|
|
||||||
objects: [button.sink]
|
|
||||||
}
|
|
||||||
|
|
||||||
onClicked: mouse => {
|
onClicked: mouse => {
|
||||||
if (!sink) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mouse.button == Qt.LeftButton) {
|
if (mouse.button == Qt.LeftButton) {
|
||||||
sink.audio.muted = !sink?.audio.muted;
|
Pipewire.toggleMute();
|
||||||
} else if (mouse.button == Qt.RightButton)
|
} else if (mouse.button == Qt.RightButton) {
|
||||||
// show menu
|
popup.opened = !popup.opened;
|
||||||
{}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onWheel: event => {
|
onWheel: event => {
|
||||||
if (event.angleDelta.y > 0) {
|
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) {
|
} else if (event.angleDelta.y < 0) {
|
||||||
sink.audio.volume -= 0.02;
|
Pipewire.decrementVolume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "muted"
|
name: "muted"
|
||||||
when: button.sink?.audio.muted ?? false
|
when: Pipewire.muted
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
text {
|
root {
|
||||||
icon: " "
|
color: Theme.palette.error
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State {
|
|
||||||
name: "off"
|
|
||||||
when: button.sink?.audio.volume <= 0
|
|
||||||
PropertyChanges {
|
|
||||||
text {
|
|
||||||
icon: " "
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -55,9 +36,9 @@ StyledButton {
|
||||||
|
|
||||||
content: StyledText {
|
content: StyledText {
|
||||||
id: text
|
id: text
|
||||||
property string icon: " "
|
property string icon: Pipewire.muted ? " " : Pipewire.volume <= 0 ? " " : " "
|
||||||
text: `${icon} ${(button.sink?.audio.volume * 100).toFixed()}%`
|
text: `${icon} ${(Pipewire.volume * 100).toFixed()}%`
|
||||||
font.pixelSize: Dimensions.pipewire.fontSize
|
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