55 lines
1.7 KiB
QML
55 lines
1.7 KiB
QML
// modules/MediaWidget.qml
|
|
// Mirrors waybar custom/spotify - uses MPRIS via Quickshell.Services.Mpris.
|
|
// Shows: artist - title + spotify icon. Click to play/pause, scroll to skip.
|
|
import QtQuick
|
|
import Quickshell.Services.Mpris
|
|
import ".."
|
|
|
|
Pill {
|
|
id: root
|
|
|
|
// Pick the first active player (prefer spotify)
|
|
property MprisPlayer activePlayer: {
|
|
var players = Mpris.players.values
|
|
for (var i = 0; i < players.length; i++)
|
|
if (players[i].identity.toLowerCase() === "spotify") return players[i]
|
|
return players.length > 0 ? players[0] : null
|
|
}
|
|
|
|
property string trackText: {
|
|
if (!activePlayer) return ""
|
|
var p = activePlayer
|
|
var info = ""
|
|
if (p.trackArtists && p.trackTitle)
|
|
info = p.trackArtists.join(", ") + " - " + p.trackTitle
|
|
else if (p.trackTitle)
|
|
info = p.trackTitle
|
|
if (info.length > 45) info = info.substring(0, 45) + "..."
|
|
if (p.playbackState !== MprisPlaybackState.Playing && info)
|
|
info = " " + info
|
|
return info + " " // trailing Nerd Font Spotify icon
|
|
}
|
|
|
|
visible: trackText !== ""
|
|
|
|
Text {
|
|
text: root.trackText
|
|
font { family: Theme.fontSans; pixelSize: Theme.fontSize }
|
|
color: Theme.foreground
|
|
elide: Text.ElideRight
|
|
maximumLineCount: 1
|
|
}
|
|
|
|
onClicked: (m) => {
|
|
if (!root.activePlayer) return
|
|
if (m.button === Qt.LeftButton)
|
|
root.activePlayer.togglePlaying()
|
|
}
|
|
|
|
onScrolled: (w) => {
|
|
if (!root.activePlayer) return
|
|
if (w.angleDelta.y > 0) root.activePlayer.next()
|
|
else root.activePlayer.previous()
|
|
}
|
|
}
|