44 lines
1.3 KiB
QML
44 lines
1.3 KiB
QML
import QtQuick
|
|
import Quickshell.Services.Pipewire
|
|
import "../../config"
|
|
|
|
Item {
|
|
id: root
|
|
implicitWidth: label.implicitWidth + 4
|
|
implicitHeight: Appearance.barHeight
|
|
|
|
readonly property var sink: Pipewire.defaultAudioSink
|
|
readonly property real vol: (sink && sink.audio) ? sink.audio.volume : 0
|
|
readonly property bool muted: (sink && sink.audio) ? sink.audio.muted : false
|
|
|
|
PwObjectTracker { objects: root.sink ? [root.sink] : [] }
|
|
|
|
Text {
|
|
id: label
|
|
anchors.centerIn: parent
|
|
font.family: Appearance.iconFontFamily
|
|
font.variableAxes: Appearance.iconFontAxes
|
|
font.pixelSize: 16
|
|
color: Colors.foreground
|
|
text: {
|
|
if (root.muted || root.vol <= 0) return "volume_off"
|
|
if (root.vol < 0.5) return "volume_down"
|
|
return "volume_up"
|
|
}
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
cursorShape: Qt.PointingHandCursor
|
|
acceptedButtons: Qt.LeftButton
|
|
onClicked: if (root.sink && root.sink.audio) root.sink.audio.muted = !root.sink.audio.muted
|
|
|
|
onWheel: (wheel) => {
|
|
if (!root.sink || !root.sink.audio) return
|
|
const step = 0.05
|
|
const delta = wheel.angleDelta.y > 0 ? step : -step
|
|
root.sink.audio.volume = Math.max(0, Math.min(1, root.sink.audio.volume + delta))
|
|
}
|
|
}
|
|
}
|