mirror of
https://github.com/pnx/dotfiles
synced 2026-11-04 05:06:46 +01:00
quickshell: volume control
This commit is contained in:
parent
abf8d7f57a
commit
32045a633a
2 changed files with 74 additions and 0 deletions
73
quickshell/components/Volume.qml
Normal file
73
quickshell/components/Volume.qml
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import Quickshell
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell.Services.Pipewire
|
||||
import Quickshell.Io
|
||||
|
||||
|
||||
Item {
|
||||
id: root
|
||||
readonly property PwNode sink: Pipewire.defaultAudioSink
|
||||
|
||||
SystemPalette { id: pal }
|
||||
|
||||
Process {
|
||||
id: pavucontrol
|
||||
command: ["pavucontrol"]
|
||||
}
|
||||
|
||||
implicitWidth: content.implicitWidth
|
||||
implicitHeight: content.implicitHeight
|
||||
|
||||
PwObjectTracker {
|
||||
objects: [root.sink]
|
||||
}
|
||||
|
||||
Row {
|
||||
id: content
|
||||
spacing: 6
|
||||
|
||||
Text {
|
||||
color: pal.text
|
||||
text: {
|
||||
if (!root.sink?.audio || root.sink.audio.muted)
|
||||
return "";
|
||||
|
||||
if (root.sink.audio.volume < 0.33)
|
||||
return "";
|
||||
|
||||
if (root.sink.audio.volume < 0.66)
|
||||
return "";
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
color: pal.text
|
||||
text: root.sink?.audio ? Math.round(root.sink.audio.volume * 100) + "%" : "--%"
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.LeftButton
|
||||
|
||||
onClicked: mouse => {
|
||||
if (mouse.button === Qt.RightButton) {
|
||||
pavucontrol.startDetached()
|
||||
} else if (mouse.button === Qt.LeftButton) {
|
||||
if (root.sink?.audio)
|
||||
root.sink.audio.muted = !root.sink.audio.muted
|
||||
}
|
||||
}
|
||||
|
||||
onWheel: event => {
|
||||
if (!root.sink?.audio)
|
||||
return;
|
||||
const delta = event.angleDelta.y > 0 ? 0.05 : -0.05;
|
||||
|
||||
root.sink.audio.volume = Math.max(0, Math.min(1, root.sink.audio.volume + delta));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,7 @@ Scope {
|
|||
|
||||
right: [
|
||||
Tray { },
|
||||
Volume { },
|
||||
Clock { }
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue