quickshell/modules/bar/Mpris.qml

63 lines
1.8 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 {
2026-02-12 19:21:28 +01:00
id: root
2026-01-19 17:04:51 +01:00
visible: root.spotify != null
radius: implicitHeight / 2
implicitHeight: Settings.config.barHeight - 10
2026-02-13 01:41:29 +01:00
color: clickHandler.containsMouse ? Colors.base01 : Colors.base00
2026-02-12 19:21:28 +01:00
implicitWidth: statusRow.width + 20
2026-02-12 19:00:34 +01:00
2026-02-12 19:21:28 +01:00
property var spotify: root.getSpotify()
function getSpotify() {
for (let i = 0; i < Mpris.players.values.length; i++) {
if (Mpris.players.values[i].identity.toLowerCase() === "spotify") {
return Mpris.players.values[i];
}
}
2026-02-12 19:21:28 +01:00
return null;
}
2026-01-20 13:00:53 +01:00
2026-02-12 19:21:28 +01:00
RowLayout {
id: statusRow
spacing: 5
anchors.centerIn: parent
property var combinedText: root.spotify != null ? root.spotify.trackArtist + " - " + root.spotify.trackTitle : ""
property var status: root.spotify != null ? !root.spotify.isPlaying ? "play_arrow" : "pause" : ""
CustomText {
id: mprisText
Layout.maximumWidth: 300
Layout.topMargin: 2
text: root.spotify != null ? parent.combinedText : ""
elide: Text.ElideRight
}
CustomIcon {
id: mprisStatus
Layout.topMargin: 2
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();
}
}
}
}