From 6e20ac966ed1ab2b080a12023aa9482871919a09 Mon Sep 17 00:00:00 2001 From: Damocles Date: Sun, 12 Apr 2026 19:14:41 +0200 Subject: [PATCH] mpris: cava audio visualizer overlay on album art --- modules/Mpris.qml | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/modules/Mpris.qml b/modules/Mpris.qml index d596571..efb9f9f 100644 --- a/modules/Mpris.qml +++ b/modules/Mpris.qml @@ -1,5 +1,6 @@ import QtQuick import Quickshell +import Quickshell.Io import Quickshell.Wayland import Quickshell.Services.Mpris import "." as M @@ -33,6 +34,24 @@ M.BarSection { asynchronous: true } + // Cava visualizer — 16 bars, raw output mode + property var _cavaBars: Array(16).fill(0) + Process { + id: cavaProc + running: root.playing + command: ["sh", "-c", + "printf '[general]\\nbars=16\\nframerate=30\\n[output]\\nmethod=raw\\nraw_target=/dev/stdout\\ndata_format=ascii\\nascii_max_range=100\\n' | cava -p /dev/stdin 2>/dev/null" + ] + stdout: SplitParser { + splitMarker: "\n" + onRead: line => { + const vals = line.split(";").filter(s => s).map(Number); + if (vals.length >= 16) + root._cavaBars = vals.map(v => v / 100); + } + } + } + required property var bar property bool _panelHovered: false @@ -208,6 +227,31 @@ M.BarSection { } } + // Visualizer bars + Row { + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + height: parent.height * 0.6 + spacing: 2 + visible: root.playing + opacity: 0.5 + + Repeater { + model: 16 + Rectangle { + required property int index + width: (parent.width - 15 * parent.spacing) / 16 + height: parent.height * (root._cavaBars[index] ?? 0) + anchors.bottom: parent.bottom + color: M.Theme.base0E + radius: 1 + + Behavior on height { NumberAnimation { duration: 50 } } + } + } + } + Rectangle { anchors.left: parent.left anchors.right: parent.right