58 lines
1.8 KiB
QML
58 lines
1.8 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Services.Mpris
|
|
import "." as M
|
|
|
|
M.BarSection {
|
|
id: root
|
|
spacing: M.Theme.moduleSpacing
|
|
opacity: M.Modules.mpris.enable && player !== null ? 1 : 0
|
|
visible: opacity > 0
|
|
tooltip: {
|
|
const p = root.player;
|
|
if (!p)
|
|
return "";
|
|
const parts = [];
|
|
if (p.trackTitle)
|
|
parts.push(p.trackTitle);
|
|
if (p.trackArtists?.length)
|
|
parts.push(Array.isArray(p.trackArtists) ? p.trackArtists.join(", ") : p.trackArtists);
|
|
if (p.trackAlbum)
|
|
parts.push(p.trackAlbum);
|
|
return parts.join("\n") || p.identity;
|
|
}
|
|
|
|
readonly property MprisPlayer player: Mpris.players.values[0] ?? null
|
|
readonly property bool playing: player?.playbackState === MprisPlaybackState.Playing
|
|
|
|
M.BarIcon {
|
|
icon: root.playing ? "\uF04B" : (root.player?.playbackState === MprisPlaybackState.Paused ? "\uDB80\uDFE4" : "\uDB81\uDCDB")
|
|
color: M.Theme.base0E
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
}
|
|
M.BarLabel {
|
|
label: root.player?.trackTitle || root.player?.identity || ""
|
|
color: M.Theme.base0E
|
|
elide: Text.ElideRight
|
|
width: Math.min(implicitWidth, 200)
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
}
|
|
|
|
required property var bar
|
|
|
|
TapHandler {
|
|
cursorShape: Qt.PointingHandCursor
|
|
onTapped: menuLoader.active = !menuLoader.active
|
|
}
|
|
|
|
Loader {
|
|
id: menuLoader
|
|
active: false
|
|
sourceComponent: M.MprisMenu {
|
|
player: root.player
|
|
screen: root.bar.screen
|
|
anchorX: root.mapToGlobal(root.width / 2, 0).x - (QsWindow.window?.screen?.x ?? 0)
|
|
onDismissed: menuLoader.active = false
|
|
}
|
|
}
|
|
}
|