feat: add now playing to quickshell bar

This commit is contained in:
johannes committed 2026-08-23 21:10:49 +02:00
1 parent 452d7080f9
commit 1293fe565b
1 file changed
+93 -32
+93 -32
View File
@@ -1,6 +1,8 @@
import QtQuick import QtQuick
import QtQuick.Layouts
import Quickshell import Quickshell
import Quickshell.Io import Quickshell.Io
import Quickshell.Services.Mpris
import "../core" import "../core"
ModuleContainer { ModuleContainer {
@@ -22,14 +24,17 @@ ModuleContainer {
} }
} }
property MprisPlayer mprisPlayer: Mpris.players.values[0] || null
// Embed the MPRIS Popup natively into the pill's slot // Embed the MPRIS Popup natively into the pill's slot
popupItem: PopupWindow { popupItem: PopupWindow {
id: mprisPopup id: mprisPopup
implicitWidth: 260 implicitWidth: 320
implicitHeight: 80 implicitHeight: 90
anchor.item: root anchor.item: root
anchor.edges: Edges.Bottom anchor.edges: Edges.Bottom
anchor.gravity: Edges.Bottom
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
@@ -38,43 +43,99 @@ ModuleContainer {
border.color: Theme.bgAlt border.color: Theme.bgAlt
border.width: 1 border.width: 1
Column { RowLayout {
anchors.fill: parent anchors.fill: parent
anchors.margins: Theme.padding anchors.margins: Theme.padding
spacing: 4 spacing: Theme.padding
Text { TapHandler {
text: "Now Playing" acceptedButtons: Qt.RightButton
color: Theme.fgAlt onTapped: if (root.mprisPlayer) root.mprisPlayer.next()
font: Theme.font
} }
Text { TapHandler {
id: mprisText acceptedButtons: Qt.LeftButton
text: "Nothing playing" onTapped: if (root.mprisPlayer) root.mprisPlayer.previous()
color: Theme.fg
font: Theme.fontBold
elide: Text.ElideRight
width: parent.width
} }
}
Rectangle {
Process { Layout.preferredWidth: 64
id: mprisProcess Layout.preferredHeight: 64
command: ["sh", "-c", "playerctl metadata --format '{{title}} - {{artist}}' || echo 'Nothing playing'"] radius: Theme.radius
stdout: StdioCollector { color: Theme.bgAlt
onStreamFinished: { clip: true
mprisText.text = text.trim() || "Nothing playing";
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
} }
} }
} }