quickshell/modules/bar/Mpris.qml

111 lines
3.7 KiB
QML
Raw Normal View History

2025-12-26 00:37:39 +01:00
// ⚠️ Ensure Colors is imported
// import "../../"
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Services.Mpris
import Quickshell.Widgets
import "../settings/"
import "../../"
2025-12-26 00:37:39 +01:00
2025-12-28 17:36:11 +01:00
Item {
2025-12-26 00:37:39 +01:00
id: root
2025-12-28 17:36:11 +01:00
implicitWidth: mprisRepeater.implicitWidth + 10
implicitHeight: 34
2025-12-26 00:37:39 +01:00
// 1. Let Repeater loop through the ObjectModel for us
Repeater {
id: mprisRepeater
model: Mpris.players
2025-12-28 17:36:11 +01:00
delegate: Item {
2025-12-29 22:48:47 +01:00
id: delegateItem
2025-12-28 20:57:07 +01:00
2025-12-26 00:37:39 +01:00
required property var modelData
2025-12-28 17:36:11 +01:00
implicitHeight: 34
implicitWidth: delegateLayout.implicitWidth
MouseArea {
id: playbackControl
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: mouse => {
if (mouse.button == Qt.LeftButton) {
console.log("Left button press");
}
if (mouse.button == Qt.RightButton) {
parent.modelData.togglePlaying();
}
}
onDoubleClicked: mouse => {
if (mouse.button == Qt.LeftButton) {
parent.modelData.next();
}
}
}
RowLayout {
id: delegateLayout
2025-12-29 22:48:47 +01:00
anchors.centerIn: parent
2025-12-28 17:36:11 +01:00
// 2. 🕵️‍♀️ FILTER LOGIC
// Check if this specific player is Spotify.
// We verify 'modelData' exists and check the name.
2025-12-29 22:48:47 +01:00
property bool isSpotify: delegateItem.modelData && delegateItem.modelData.identity.toLowerCase().includes("spotify")
2025-12-28 17:36:11 +01:00
// 3. 👻 HIDE NON-SPOTIFY PLAYERS
visible: isSpotify
2025-12-26 00:37:39 +01:00
2025-12-28 17:36:11 +01:00
// If hidden, take up ZERO space
Layout.preferredWidth: isSpotify ? Math.min(implicitWidth, 400) : 0
Layout.fillHeight: true
2025-12-26 00:37:39 +01:00
2025-12-29 22:48:47 +01:00
property string title: delegateItem.modelData.trackTitle
property string artist: delegateItem.modelData.trackArtist
property string artUrl: delegateItem.modelData.trackArtUrl
property bool isPlaying: delegateItem.modelData.isPlaying
2025-12-26 00:37:39 +01:00
2025-12-28 17:36:11 +01:00
spacing: 10
2025-12-26 00:37:39 +01:00
2025-12-28 17:36:11 +01:00
// 🖼️ ALBUM ART
2025-12-26 00:37:39 +01:00
2025-12-28 17:36:11 +01:00
ClippingWrapperRectangle {
Layout.alignment: Qt.AlignVCenter
2025-12-26 00:37:39 +01:00
2025-12-28 17:36:11 +01:00
radius: 20
2025-12-26 00:37:39 +01:00
2025-12-28 17:36:11 +01:00
IconImage {
source: delegateLayout.artUrl // Access property from delegate
asynchronous: true
implicitSize: root.implicitHeight * 0.6
}
2025-12-26 00:37:39 +01:00
}
2025-12-28 17:36:11 +01:00
// 📝 TEXT INFO
ColumnLayout {
spacing: 0
visible: parent.visible
2025-12-26 00:37:39 +01:00
2025-12-28 17:36:11 +01:00
Text {
text: delegateLayout.title
color: Colors.foreground
font.bold: true
font.pixelSize: Settings.fontSize
font.family: Settings.font
elide: Text.ElideRight
Layout.preferredWidth: implicitWidth
}
2025-12-26 00:37:39 +01:00
2025-12-28 17:36:11 +01:00
Text {
font.pixelSize: Settings.fontSize - 2
font.family: Settings.font
text: delegateLayout.artist
color: Colors.foreground
opacity: 0.7
Layout.preferredWidth: implicitWidth
}
2025-12-26 00:37:39 +01:00
}
}
}
}
}