import QtQuick import "../../components" import "../../core" import "../../services" import "../../theme" // Output volume: scroll to adjust, click to mute, right-click for audio settings. GlassButton { id: root objectName: "volumePill" readonly property var audio: AudioService.sink ? AudioService.sink.audio : null readonly property bool muted: !!audio && audio.muted readonly property real level: audio ? audio.volume : 0 readonly property int step: ConfigService.ready ? ConfigService.data.osd.step : 5 readonly property string glyph: !audio ? "󰖁" : muted || level === 0 ? "󰖁" : level < 0.34 ? "󰕿" : level < 0.67 ? "󰖀" : "󰕾" enabled: !!audio accented: false implicitHeight: ModuleRegistry.pillHeight // Width comes from the texts directly; the value reserves room for "100%" // so the pill does not jitter while scrolling. TextMetrics { id: widest font: value.font text: "100%" } contentItem: Item { implicitWidth: icon.implicitWidth + 6 + valueWidth implicitHeight: Math.max(icon.implicitHeight, value.implicitHeight) readonly property real valueWidth: Math.max(widest.advanceWidth, value.implicitWidth) Text { id: icon anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter text: Icons.available ? root.glyph : (root.muted ? "×" : "♪") font.family: Icons.available ? Icons.family : "" font.pixelSize: 15 color: root.muted ? Theme.urgent : Theme.text } Text { id: value anchors.left: icon.right anchors.leftMargin: 6 anchors.verticalCenter: parent.verticalCenter text: !root.audio ? "—" : root.muted ? "Off" : Math.round(root.level * 100) + "%" font.pixelSize: 13 font.features: { "tnum": 1 } color: root.muted ? Theme.urgent : Theme.text } } implicitWidth: icon.implicitWidth + 6 + Math.max(widest.advanceWidth, value.implicitWidth) + 28 onClicked: AudioService.mute(false) WheelHandler { acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad onWheel: event => { if (!root.audio) return; const delta = (event.angleDelta.y || -event.angleDelta.x) > 0 ? 1 : -1; if (delta > 0) root.audio.muted = false; AudioService.volume(false, root.level + delta * root.step / 100); } } TapHandler { acceptedButtons: Qt.RightButton onTapped: ShellState.openSettings("audio") } Accessible.name: "Volume " + (muted ? "muted" : Math.round(level * 100) + "%") }