feat: add now playing to quickshell bar
This commit is contained in:
1 parent
452d7080f9
commit
1293fe565b
1 file changed
+93
-32
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user