feat: add now playing to quickshell bar
This commit is contained in:
1 parent
452d7080f9
commit
1293fe565b
1 file changed
+90
-29
@@ -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
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
Rectangle {
|
||||||
id: mprisProcess
|
Layout.preferredWidth: 64
|
||||||
command: ["sh", "-c", "playerctl metadata --format '{{title}} - {{artist}}' || echo 'Nothing playing'"]
|
Layout.preferredHeight: 64
|
||||||
stdout: StdioCollector {
|
radius: Theme.radius
|
||||||
onStreamFinished: {
|
color: Theme.bgAlt
|
||||||
mprisText.text = text.trim() || "Nothing playing";
|
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 === ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
ColumnLayout {
|
||||||
interval: 2000
|
Layout.fillWidth: true
|
||||||
running: mprisPopup.visible
|
Layout.fillHeight: true
|
||||||
repeat: true
|
spacing: 4
|
||||||
triggeredOnStart: true
|
|
||||||
onTriggered: mprisProcess.running = true
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user