143 lines
4.9 KiB
QML
143 lines
4.9 KiB
QML
import QtQuick
|
|
import QtQuick.Layouts
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
import Quickshell.Services.Mpris
|
|
import "../core"
|
|
|
|
ModuleContainer {
|
|
id: root
|
|
|
|
// Initial state
|
|
text: "00:00"
|
|
|
|
Timer {
|
|
interval: 1000
|
|
running: true
|
|
repeat: true
|
|
triggeredOnStart: true
|
|
onTriggered: {
|
|
var d = new Date();
|
|
var h = d.getHours().toString().padStart(2, '0');
|
|
var m = d.getMinutes().toString().padStart(2, '0');
|
|
root.text = h + ":" + m;
|
|
}
|
|
}
|
|
|
|
property MprisPlayer mprisPlayer: Mpris.players.values[0] || null
|
|
|
|
// Embed the MPRIS Popup natively into the pill's slot
|
|
popupItem: PopupWindow {
|
|
id: mprisPopup
|
|
implicitWidth: 320
|
|
implicitHeight: 90
|
|
|
|
anchor.item: root
|
|
anchor.edges: Edges.Bottom
|
|
anchor.gravity: Edges.Bottom
|
|
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
color: Theme.bg
|
|
radius: Theme.radius
|
|
border.color: Theme.bgAlt
|
|
border.width: 1
|
|
|
|
RowLayout {
|
|
anchors.fill: parent
|
|
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
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|