From 32045a633aa85385f06b61dc077f0314936fcffd Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 2 Nov 2026 17:49:33 +0100 Subject: [PATCH] quickshell: volume control --- quickshell/components/Volume.qml | 73 ++++++++++++++++++++++++++++++++ quickshell/shell.qml | 1 + 2 files changed, 74 insertions(+) create mode 100644 quickshell/components/Volume.qml diff --git a/quickshell/components/Volume.qml b/quickshell/components/Volume.qml new file mode 100644 index 0000000..35e2b39 --- /dev/null +++ b/quickshell/components/Volume.qml @@ -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)); + } + } +} diff --git a/quickshell/shell.qml b/quickshell/shell.qml index 3d2ed2e..19c34d5 100644 --- a/quickshell/shell.qml +++ b/quickshell/shell.qml @@ -39,6 +39,7 @@ Scope { right: [ Tray { }, + Volume { }, Clock { } ] }