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
+82 -21
+82 -21
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: Theme.padding
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: if (root.mprisPlayer) root.mprisPlayer.next()
}
TapHandler {
acceptedButtons: Qt.LeftButton
onTapped: if (root.mprisPlayer) root.mprisPlayer.previous()
}
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 spacing: 4
Text { Text {
text: "Now Playing" Layout.fillWidth: true
text: root.mprisPlayer && root.mprisPlayer.playbackState === MprisPlaybackState.Playing
? "Now Playing"
: (root.mprisPlayer ? "Paused" : "Nothing playing")
color: Theme.fgAlt color: Theme.fgAlt
font: Theme.font font: Theme.font
elide: Text.ElideRight
} }
Text { Text {
id: mprisText id: mprisText
text: "Nothing playing" Layout.fillWidth: true
text: root.mprisPlayer && root.mprisPlayer.trackTitle !== ""
? root.mprisPlayer.trackTitle
: "No Track"
color: Theme.fg color: Theme.fg
font: Theme.fontBold font: Theme.fontBold
elide: Text.ElideRight elide: Text.ElideRight
width: parent.width
}
} }
Process { Text {
id: mprisProcess Layout.fillWidth: true
command: ["sh", "-c", "playerctl metadata --format '{{title}} - {{artist}}' || echo 'Nothing playing'"] text: root.mprisPlayer && root.mprisPlayer.trackArtist !== ""
stdout: StdioCollector { ? root.mprisPlayer.trackArtist
onStreamFinished: { : "Unknown Artist"
mprisText.text = text.trim() || "Nothing playing"; color: Theme.fgAlt
} font: Theme.font
} elide: Text.ElideRight
} }
Timer { Item { Layout.fillHeight: true } // spacer
interval: 2000
running: mprisPopup.visible Rectangle {
repeat: true Layout.fillWidth: true
triggeredOnStart: true Layout.preferredHeight: 4
onTriggered: mprisProcess.running = true 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
}
}
}
} }
} }
} }