Files
Olympus/home-manager/users/nathan/dotfiles/quickshell/modules/Media.qml
2025-11-09 18:02:29 -06:00

72 lines
1.8 KiB
QML

import QtQuick // for Text
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell.Services.Mpris
import Quickshell.Widgets
Item {
id: media
width: 250 > 9 * button.text.length ? 250 : 9 * button.text.length
height: 30
ClippingWrapperRectangle {
radius: 5
anchors.fill: parent
Button {
id: button
property real offset: 0
text: {
let s = ''
let players = []
Mpris.players.values.forEach((p) => {
if(p.isPlaying) players.push(p)
})
if(players[0]?.trackTitle) {
s += players[0].trackTitle
}
if(players[0]?.trackAlbum) {
s += ' - ' + players[0].trackAlbum
}
if(players[0]?.trackArtist) {
s += ' - ' + players[0].trackArtist
}
let a = offset % s.length
let b = (offset + s.length - 1) % s.length
if(s == '')
media.visible = false
else
media.visible = true
if(b < a) {
return s.substring(a, s.length) + ' ' + s.substring(0, b)
} else {
return s.substring(a, b) + ' '
}
//return s
}
font.pointSize: 11
onClicked: {
timer.running = !timer.running
}
Timer {
id: timer
interval: 225
running: true
repeat: true
onTriggered: button.offset = (button.offset + 1) % (2 * button.text.length)
}
}
}
}