diff options
Diffstat (limited to 'home-configuration/config/quickshell/modules/bar/Music.qml')
| -rw-r--r-- | home-configuration/config/quickshell/modules/bar/Music.qml | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/home-configuration/config/quickshell/modules/bar/Music.qml b/home-configuration/config/quickshell/modules/bar/Music.qml new file mode 100644 index 0000000..ec16fed --- /dev/null +++ b/home-configuration/config/quickshell/modules/bar/Music.qml @@ -0,0 +1,219 @@ +import QtQuick +import QtQuick.Layouts +import Quickshell +import Quickshell.Services.Mpris +import "../../config.js" as Config + +Rectangle { + id: musicBlock + + property var player: null + + implicitWidth: visible + ? Math.min(textMetrics.width + Config.blockPadding + 8, 400) + : 0 + + implicitHeight: Config.blockHeight + + radius: Config.blockRadius + + visible: player !== null && player.isPlaying + + function findFeishin() { + player = null + + for (var i = 0; i < Mpris.players.values.length; i++) { + var p = Mpris.players.values[i] + + console.log( + "MPRIS:", + "identity =", p.identity, + "desktopEntry =", p.desktopEntry + ) + + var identity = (p.identity || "").toLowerCase() + var desktopEntry = (p.desktopEntry || "").toLowerCase() + + if ( + identity === "feishin" || + desktopEntry === "feishin" + ) { + player = p + console.log("FEISHIN FOUND") + return + } + } + + console.log("FEISHIN NOT FOUND") + } + + function cleanTitle(title) { + if (!title) + return "" + + return title + .replace(/\s*[\(\[][^)\]]*\blive\b[^)\]]*[\)\]]/gi, "") + .replace(/\s*[-–—]\s*\blive\b.*$/i, "") + .trim() + } + + Component.onCompleted: { + findFeishin() + } + + Connections { + target: Mpris.players + + function onValuesChanged() { + findFeishin() + } + } + + gradient: Gradient { + GradientStop { + id: stop1 + position: 0.0 + color: Config.accentGreen + } + + GradientStop { + id: stop2 + position: 0.33 + color: Config.accentYellow + } + + GradientStop { + id: stop3 + position: 0.66 + color: Config.accentOrange + } + + GradientStop { + id: stop4 + position: 1.0 + color: Config.accentRed + } + } + + TextMetrics { + id: textMetrics + + font.family: Config.fontFamily + font.pixelSize: Config.fontSize + font.bold: true + + text: player + ? " " + player.trackArtist + " — " + cleanTitle(player.trackTitle) + : "" + } + + Text { + id: musicText + + anchors { + left: parent.left + right: parent.right + verticalCenter: parent.verticalCenter + } + + leftPadding: Config.blockPadding / 2 + rightPadding: Config.blockPadding / 2 + + text: player + ? " " + player.trackArtist + " — " + cleanTitle(player.trackTitle) + : "" + + color: Config.textDark + + font.family: Config.fontFamily + font.pixelSize: Config.fontSize + font.bold: true + + elide: Text.ElideRight + maximumLineCount: 1 + } + + MouseArea { + anchors.fill: parent + + cursorShape: Qt.PointingHandCursor + + onClicked: { + if (player && player.canRaise) + player.raise() + } + } + + SequentialAnimation { + running: true + loops: Animation.Infinite + + ParallelAnimation { + ColorAnimation { + target: stop1 + property: "color" + from: Config.accentGreen + to: Config.accentRed + duration: Config.gradientAnimationDuration + } + + ColorAnimation { + target: stop2 + property: "color" + from: Config.accentYellow + to: Config.accentGreen + duration: Config.gradientAnimationDuration + } + + ColorAnimation { + target: stop3 + property: "color" + from: Config.accentOrange + to: Config.accentYellow + duration: Config.gradientAnimationDuration + } + + ColorAnimation { + target: stop4 + property: "color" + from: Config.accentRed + to: Config.accentOrange + duration: Config.gradientAnimationDuration + } + } + + ParallelAnimation { + ColorAnimation { + target: stop1 + property: "color" + from: Config.accentRed + to: Config.accentGreen + duration: Config.gradientAnimationDuration + } + + ColorAnimation { + target: stop2 + property: "color" + from: Config.accentGreen + to: Config.accentYellow + duration: Config.gradientAnimationDuration + } + + ColorAnimation { + target: stop3 + property: "color" + from: Config.accentYellow + to: Config.accentOrange + duration: Config.gradientAnimationDuration + } + + ColorAnimation { + target: stop4 + property: "color" + from: Config.accentOrange + to: Config.accentRed + duration: Config.gradientAnimationDuration + } + } + } +} |
