From 1293fe565bf02f7a74dff2514c2233b5d07c2fb2 Mon Sep 17 00:00:00 2001 From: Johannes Kresner Date: Sun, 23 Aug 2026 21:10:49 +0200 Subject: [PATCH] feat: add now playing to quickshell bar --- .../quickshell/components/Clock.qml | 125 +++++++++++++----- 1 file changed, 93 insertions(+), 32 deletions(-) diff --git a/mutable_config/quickshell/components/Clock.qml b/mutable_config/quickshell/components/Clock.qml index 74d5d2d..1aca6a1 100644 --- a/mutable_config/quickshell/components/Clock.qml +++ b/mutable_config/quickshell/components/Clock.qml @@ -1,6 +1,8 @@ import QtQuick +import QtQuick.Layouts import Quickshell import Quickshell.Io +import Quickshell.Services.Mpris import "../core" ModuleContainer { @@ -22,14 +24,17 @@ ModuleContainer { } } + property MprisPlayer mprisPlayer: Mpris.players.values[0] || null + // Embed the MPRIS Popup natively into the pill's slot popupItem: PopupWindow { id: mprisPopup - implicitWidth: 260 - implicitHeight: 80 + implicitWidth: 320 + implicitHeight: 90 anchor.item: root anchor.edges: Edges.Bottom + anchor.gravity: Edges.Bottom Rectangle { anchors.fill: parent @@ -38,43 +43,99 @@ ModuleContainer { border.color: Theme.bgAlt border.width: 1 - Column { + RowLayout { anchors.fill: parent anchors.margins: Theme.padding - spacing: 4 + spacing: Theme.padding - Text { - text: "Now Playing" - color: Theme.fgAlt - font: Theme.font + TapHandler { + acceptedButtons: Qt.RightButton + onTapped: if (root.mprisPlayer) root.mprisPlayer.next() } - - Text { - id: mprisText - text: "Nothing playing" - color: Theme.fg - font: Theme.fontBold - elide: Text.ElideRight - width: parent.width + + TapHandler { + acceptedButtons: Qt.LeftButton + onTapped: if (root.mprisPlayer) root.mprisPlayer.previous() } - } - - Process { - id: mprisProcess - command: ["sh", "-c", "playerctl metadata --format '{{title}} - {{artist}}' || echo 'Nothing playing'"] - stdout: StdioCollector { - onStreamFinished: { - mprisText.text = text.trim() || "Nothing playing"; + + Rectangle { + Layout.preferredWidth: 64 + Layout.preferredHeight: 64 + radius: Theme.radius + color: Theme.bgAlt + clip: true + + Image { + anchors.fill: parent + source: root.mprisPlayer && root.mprisPlayer.trackArtUrl ? root.mprisPlayer.trackArtUrl : "" + fillMode: Image.PreserveAspectCrop + visible: root.mprisPlayer && root.mprisPlayer.trackArtUrl !== "" + } + + // Fallback icon when no art + Text { + anchors.centerIn: parent + text: "♪" + font.pixelSize: 24 + visible: !root.mprisPlayer || !root.mprisPlayer.trackArtUrl || root.mprisPlayer.trackArtUrl === "" + } + } + + ColumnLayout { + Layout.fillWidth: true + Layout.fillHeight: true + spacing: 4 + + Text { + Layout.fillWidth: true + text: root.mprisPlayer && root.mprisPlayer.playbackState === MprisPlaybackState.Playing + ? "Now Playing" + : (root.mprisPlayer ? "Paused" : "Nothing playing") + color: Theme.fgAlt + font: Theme.font + elide: Text.ElideRight + } + + Text { + id: mprisText + Layout.fillWidth: true + text: root.mprisPlayer && root.mprisPlayer.trackTitle !== "" + ? root.mprisPlayer.trackTitle + : "No Track" + color: Theme.fg + font: Theme.fontBold + elide: Text.ElideRight + } + + Text { + Layout.fillWidth: true + text: root.mprisPlayer && root.mprisPlayer.trackArtist !== "" + ? root.mprisPlayer.trackArtist + : "Unknown Artist" + color: Theme.fgAlt + font: Theme.font + elide: Text.ElideRight + } + + Item { Layout.fillHeight: true } // spacer + + Rectangle { + Layout.fillWidth: true + Layout.preferredHeight: 4 + radius: 2 + color: Theme.bgAlt + visible: root.mprisPlayer && root.mprisPlayer.length > 0 + + Rectangle { + height: parent.height + radius: 2 + color: Theme.primary + width: root.mprisPlayer && root.mprisPlayer.length > 0 + ? parent.width * (root.mprisPlayer.position / root.mprisPlayer.length) + : 0 + } } } - } - - Timer { - interval: 2000 - running: mprisPopup.visible - repeat: true - triggeredOnStart: true - onTriggered: mprisProcess.running = true } } }