quickshell/modules/bar/Mpris.qml

66 lines
2.1 KiB
QML
Raw Normal View History

import QtQuick
2026-02-01 23:59:09 +01:00
import QtQuick.Layouts
import Quickshell.Services.Mpris
import qs
import qs.settings
import qs.reusables
Rectangle {
id: container
2026-01-19 17:04:51 +01:00
visible: root.spotify != null
radius: implicitHeight / 2
2026-01-26 18:20:36 +01:00
color: clickHandler.containsMouse ? Colors.primaryContainer : Colors.surfaceContainer
implicitWidth: root.implicitWidth + 20
implicitHeight: Settings.config.barHeight - 10
Item {
id: root
2026-01-21 18:11:12 +01:00
anchors.centerIn: parent
property var spotify: root.getSpotify()
function getSpotify() {
for (let i = 0; i < Mpris.players.values.length; i++) {
2026-01-19 17:04:51 +01:00
if (Mpris.players.values[i].identity.toLowerCase() === "spotify") {
return Mpris.players.values[i];
}
}
return null;
}
2026-01-20 13:00:53 +01:00
implicitWidth: statusRow.implicitWidth
2026-01-21 18:11:12 +01:00
implicitHeight: statusRow.implicitHeight
2026-01-20 13:00:53 +01:00
2026-02-01 23:59:09 +01:00
RowLayout {
2026-01-21 15:38:17 +01:00
id: statusRow
spacing: 5
2026-01-21 18:11:12 +01:00
anchors.verticalCenter: parent.verticalCenter
property var combinedText: root.spotify != null ? root.spotify.trackArtist + " - " + root.spotify.trackTitle : ""
2026-01-21 15:38:17 +01:00
property var status: root.spotify != null ? !root.spotify.isPlaying ? "play_arrow" : "pause" : ""
CustomText {
id: mprisText
2026-02-01 23:59:09 +01:00
Layout.topMargin: 2
2026-01-21 15:38:17 +01:00
text: root.spotify != null ? parent.combinedText : ""
}
CustomIcon {
id: mprisStatus
2026-02-01 23:59:09 +01:00
Layout.topMargin: 2
2026-01-21 15:38:17 +01:00
text: root.spotify != null ? parent.status : ""
}
}
}
MouseArea {
id: clickHandler
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
cursorShape: Qt.PointingHandCursor
onDoubleClicked: mouse => {
if (mouse.button == Qt.LeftButton) {
root.spotify.next();
}
}
onClicked: mouse => {
if (mouse.button == Qt.RightButton) {
root.spotify.togglePlaying();
}
}
}
}